You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_timeline_analyser.py 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """
  16. Function:
  17. Test profiler to watch the performance of training.
  18. Usage:
  19. pytest tests/st/func/profiler
  20. """
  21. import os
  22. import pytest
  23. from mindinsight.profiler.analyser.analyser_factory import AnalyserFactory
  24. from tests.st.func.profiler import PROFILER_DIR
  25. from tests.utils.tools import compare_result_with_file
  26. class TestTimelineAnalyser:
  27. """Test timeline analyser module."""
  28. @classmethod
  29. def setup_class(cls):
  30. """Generate parsed files."""
  31. cls.profiler = PROFILER_DIR
  32. cls.device_id = 0
  33. cls.ascend_display_filename = 'ascend_timeline_display_{}.json'
  34. cls.gpu_display_filename = 'gpu_timeline_display_{}.json'
  35. cls.ascend_timeline_summary_filename = 'ascend_timeline_summary_{}.json'
  36. cls.gpu_timeline_summary_filename = 'gpu_timeline_summary_{}.json'
  37. def setup_method(self):
  38. """Create analyser."""
  39. self._analyser = AnalyserFactory.instance().get_analyser(
  40. 'timeline', self.profiler, self.device_id)
  41. @pytest.mark.level0
  42. @pytest.mark.env_single
  43. @pytest.mark.platform_x86_cpu
  44. @pytest.mark.platform_arm_ascend_training
  45. @pytest.mark.platform_x86_gpu_training
  46. @pytest.mark.platform_x86_ascend_training
  47. def test_get_display_timeline(self):
  48. """Test the function of get timeline detail data for UI display."""
  49. gpu_file_path = os.path.join(
  50. self.profiler,
  51. self.gpu_display_filename.format(self.device_id)
  52. )
  53. ascend_file_path = os.path.join(
  54. self.profiler,
  55. self.ascend_display_filename.format(self.device_id)
  56. )
  57. result = self._analyser.get_display_timeline("gpu")
  58. compare_result_with_file(result, gpu_file_path)
  59. result = self._analyser.get_display_timeline("ascend")
  60. compare_result_with_file(result, ascend_file_path)
  61. @pytest.mark.level0
  62. @pytest.mark.env_single
  63. @pytest.mark.platform_x86_cpu
  64. @pytest.mark.platform_arm_ascend_training
  65. @pytest.mark.platform_x86_gpu_training
  66. @pytest.mark.platform_x86_ascend_training
  67. def test_get_timeline_summary(self):
  68. """Test the function of get timeline summary data for UI display."""
  69. gpu_file_path = os.path.join(
  70. self.profiler,
  71. self.gpu_timeline_summary_filename.format(self.device_id)
  72. )
  73. ascend_file_path = os.path.join(
  74. self.profiler,
  75. self.ascend_timeline_summary_filename.format(self.device_id)
  76. )
  77. result = self._analyser.get_timeline_summary("gpu")
  78. compare_result_with_file(result, gpu_file_path)
  79. result = self._analyser.get_timeline_summary("ascend")
  80. compare_result_with_file(result, ascend_file_path)
  81. @pytest.mark.level0
  82. @pytest.mark.env_single
  83. @pytest.mark.platform_x86_cpu
  84. @pytest.mark.platform_arm_ascend_training
  85. @pytest.mark.platform_x86_gpu_training
  86. @pytest.mark.platform_x86_ascend_training
  87. def test_timeline_file_not_exist(self):
  88. """Test the function of get timeline data for UI display."""
  89. device_id = 1
  90. analyser = AnalyserFactory.instance().get_analyser(
  91. 'timeline', self.profiler, device_id)
  92. analyser.get_timeline_summary("gpu")
  93. analyser.get_display_timeline("gpu")