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 2.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. def setup_method(self):
  29. """Create analyser."""
  30. self.profiler = PROFILER_DIR
  31. self.device_id = 0
  32. self._analyser = AnalyserFactory.instance().get_analyser(
  33. 'timeline', self.profiler, self.device_id)
  34. @pytest.mark.parametrize(
  35. "device_target, filename",
  36. [('gpu', 'gpu_timeline_display_{}.json'),
  37. ('ascend', 'ascend_timeline_display_{}.json')]
  38. )
  39. def test_get_display_timeline(self, device_target, filename):
  40. """Test the function of get timeline detail data for UI display."""
  41. file_path = os.path.join(
  42. self.profiler,
  43. filename.format(self.device_id)
  44. )
  45. result = self._analyser.get_display_timeline(device_target)
  46. compare_result_with_file(result, file_path)
  47. @pytest.mark.parametrize(
  48. "device_target, filename",
  49. [('gpu', 'gpu_timeline_summary_{}.json'),
  50. ('ascend', 'ascend_timeline_summary_{}.json')]
  51. )
  52. def test_get_timeline_summary(self, device_target, filename):
  53. """Test the function of get timeline summary data for UI display."""
  54. file_path = os.path.join(
  55. self.profiler,
  56. filename.format(self.device_id)
  57. )
  58. result = self._analyser.get_timeline_summary(device_target)
  59. compare_result_with_file(result, file_path)