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_aicpu_parser.py 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. """Test the aicpu parser."""
  16. import os
  17. import tempfile
  18. import shutil
  19. from mindspore.profiler.parser.aicpu_data_parser import DataPreProcessParser
  20. class TestAicpuParser:
  21. """Test the class of Aicpu Parser."""
  22. def setup_class(self):
  23. """Initialization before test case execution."""
  24. def teardown_method(self) -> None:
  25. """Clear output file."""
  26. if os.path.exists(self.output_path):
  27. shutil.rmtree(self.output_path)
  28. def test_aicpu_parser_binary(self):
  29. """Test the class of aicpu binary data Parser."""
  30. self.profiling_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
  31. '../../../data/profiler_data/'
  32. 'JOB_AICPU/data'))
  33. self.expect_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
  34. '../../../data/profiler_data/'
  35. 'JOB_AICPU/expect'))
  36. self.output_path = tempfile.mkdtemp(prefix='output_data_preprocess_aicpu_')
  37. self.output_file = os.path.join(self.output_path, 'output_data_preprocess_aicpu_0.txt')
  38. self.expect_file = os.path.join(self.expect_dir, 'output_data_preprocess_aicpu_0.txt')
  39. self.op_task_dict = {
  40. "22_2": "Default/network-_VirtualDatasetCell/_backbone-WithLossCell/_backbone-AlexNet/dropout-Dropout/"
  41. "DropoutGenMask-op281",
  42. "22_4": "Default/network-_VirtualDatasetCell/_backbone-WithLossCell/_backbone-AlexNet/dropout-Dropout/"
  43. "DropoutGenMask-op280"
  44. }
  45. data = DataPreProcessParser(self.profiling_dir, self.output_file, self.op_task_dict)
  46. data.execute()
  47. with open(self.expect_file, 'r') as fp:
  48. expect_result = fp.read()
  49. with open(self.output_file, 'r') as fp:
  50. result = fp.read()
  51. assert expect_result == result
  52. def test_aicpu_parser_txt(self):
  53. """Test the class of aicpu txt data Parser."""
  54. self.profiling_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
  55. '../../../data/profiler_data/'
  56. 'JOB_AICPU/data_txt'))
  57. self.expect_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
  58. '../../../data/profiler_data/'
  59. 'JOB_AICPU/expect_txt'))
  60. self.output_path = tempfile.mkdtemp(prefix='output_data_preprocess_aicpu_')
  61. self.output_file = os.path.join(self.output_path, 'output_data_preprocess_aicpu_0.txt')
  62. self.expect_file = os.path.join(self.expect_dir, 'output_data_preprocess_aicpu_0.txt')
  63. data = DataPreProcessParser(self.profiling_dir, self.output_file, None)
  64. data.execute()
  65. with open(self.expect_file, 'r') as fp:
  66. expect_result = fp.read()
  67. with open(self.output_file, 'r') as fp:
  68. result = fp.read()
  69. assert expect_result == result