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_op_analyser.py 7.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. Fuction:
  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.conftest import BASE_SUMMARY_DIR
  25. OP_GATHER_V2_INFO = {
  26. 'col_name': [
  27. 'op_name', 'op_type', 'avg_execution_time', 'subgraph', 'full_op_name', 'op_info'
  28. ],
  29. 'object': [
  30. [
  31. 'GatherV2-op55', 'GatherV2', 42.220212142857136, 'Default',
  32. 'Default/network-TrainStepWrap/network-VirtualDatasetCellTriple/'
  33. '_backbone-NetWithLossClass/network-WideDeepModel/GatherV2-op55',
  34. {
  35. 'input_0': {
  36. 'format': 'DefaultFormat',
  37. 'data_type': 'NUMBER_TYPE_FLOAT32',
  38. 'shape': '184696,8'
  39. },
  40. 'input_1': {
  41. 'format': 'DefaultFormat',
  42. 'data_type': 'NUMBER_TYPE_INT32',
  43. 'shape': '128000,39'
  44. },
  45. 'output_0': {
  46. 'format': 'DefaultFormat',
  47. 'data_type': 'NUMBER_TYPE_FLOAT32',
  48. 'shape': '128000,39,8'
  49. }
  50. }
  51. ],
  52. [
  53. 'GatherV2-op33', 'GatherV2', 0.9352293333333332, 'Default',
  54. 'Default/network-TrainStepWrap/network-VirtualDatasetCellTriple/'
  55. '_backbone-NetWithLossClass/network-WideDeepModel/GatherV2-op33',
  56. {
  57. 'input_0': {
  58. 'format': 'DefaultFormat',
  59. 'data_type': 'NUMBER_TYPE_FLOAT32',
  60. 'shape': '184696,1'
  61. },
  62. 'input_1': {
  63. 'format': 'DefaultFormat',
  64. 'data_type': 'NUMBER_TYPE_INT32',
  65. 'shape': '16000,39'
  66. },
  67. 'output_0': {
  68. 'format': 'DefaultFormat',
  69. 'data_type': 'NUMBER_TYPE_FLOAT32',
  70. 'shape': '16000,39,1'
  71. }
  72. }
  73. ]
  74. ],
  75. 'size': 2
  76. }
  77. class TestOpAnalyser:
  78. """Test AICORE and AICPU analyser module."""
  79. JOB_ID = 'JOB3'
  80. @classmethod
  81. def setup_class(cls):
  82. """Generate parsed files."""
  83. cls.summary_dir = os.path.join(BASE_SUMMARY_DIR, 'normal_run')
  84. cls.profiler = os.path.join(cls.summary_dir, 'profiler')
  85. def setup_method(self):
  86. """Create analyser."""
  87. self._analyser_aicore_type = AnalyserFactory.instance().get_analyser(
  88. 'aicore_type', self.profiler, '1')
  89. self._analyser_aicore_detail = AnalyserFactory.instance().get_analyser(
  90. 'aicore_detail', self.profiler, '1')
  91. @pytest.mark.level0
  92. @pytest.mark.env_single
  93. @pytest.mark.platform_x86_cpu
  94. @pytest.mark.platform_arm_ascend_training
  95. @pytest.mark.platform_x86_gpu_training
  96. @pytest.mark.platform_x86_ascend_training
  97. def test_query_aicore_type_1(self):
  98. """Test the function of querying AICORE operator type infomation."""
  99. expect_result = {
  100. 'col_name': ['op_type', 'execution_time', 'execution_frequency', 'percent'],
  101. 'object': [
  102. ['UnsortedSegmentSum', 44.607826, 2, 35.28],
  103. ['GatherV2', 43.155441, 2, 34.13],
  104. ['Slice', 20.376315, 16, 16.12],
  105. ['Concat', 5.808454, 4, 4.59],
  106. ['Split', 2.714277, 2, 2.15],
  107. ['MatMul', 1.936681, 15, 1.53],
  108. ['Mul', 1.902949, 32, 1.51],
  109. ['StridedSliceGrad', 1.506834, 2, 1.19],
  110. ['TransData', 1.115158, 30, 0.88],
  111. ['ReluGrad', 0.854069, 5, 0.68],
  112. ['Cast', 0.484685, 15, 0.38],
  113. ['ReLU', 0.483282, 5, 0.38],
  114. ['RealDiv', 0.422807, 15, 0.33],
  115. ['StridedSlice', 0.345569, 2, 0.27],
  116. ['Adam', 0.285936, 11, 0.23],
  117. ['BiasAdd', 0.189663, 5, 0.15],
  118. ['BiasAddGrad', 0.071681, 5, 0.06],
  119. ['Tile', 0.044158, 4, 0.03],
  120. ['ReduceSum', 0.030765, 5, 0.02],
  121. ['ApplyFtrl', 0.025454, 2, 0.02],
  122. ['AtomicAddrClean', 0.019369, 8, 0.02],
  123. ['AddN', 0.012836, 1, 0.01],
  124. ['Square', 0.009799, 1, 0.01],
  125. ['SigmoidCrossEntropyWithLogitsGrad', 0.009582, 2, 0.01],
  126. ['TensorAdd', 0.009218, 3, 0.01],
  127. ['SigmoidCrossEntropyWithLogits', 0.004809, 1, 0.0],
  128. ['ReduceMean', 0.004535, 1, 0.0],
  129. ['Assign', 0.002477, 2, 0.0],
  130. ['AssignAdd', 0.001688, 1, 0.0]
  131. ],
  132. 'size': 29
  133. }
  134. condition = {
  135. 'sort_condition': {
  136. 'name': 'execution_time',
  137. 'type': 'descending'
  138. }
  139. }
  140. result = self._analyser_aicore_type.query(condition)
  141. assert expect_result == result
  142. @pytest.mark.level0
  143. @pytest.mark.env_single
  144. @pytest.mark.platform_x86_cpu
  145. @pytest.mark.platform_arm_ascend_training
  146. @pytest.mark.platform_x86_gpu_training
  147. @pytest.mark.platform_x86_ascend_training
  148. def test_query_aicore_type_2(self):
  149. """Test the function of querying AICORE operator type infomation."""
  150. expect_result = {
  151. 'col_name': ['op_type', 'execution_time', 'execution_frequency', 'percent'],
  152. 'object': [
  153. ['MatMul', 1.936681, 15, 1.53],
  154. ['Mul', 1.902949, 32, 1.51]
  155. ],
  156. 'size': 2
  157. }
  158. condition = {
  159. 'filter_condition': {
  160. 'op_type': {
  161. 'partial_match_str_in': ['Mul']
  162. }
  163. },
  164. 'sort_condition': {
  165. 'name': 'execution_time',
  166. 'type': 'descending'
  167. }
  168. }
  169. result = self._analyser_aicore_type.query(condition)
  170. assert expect_result == result
  171. @pytest.mark.level0
  172. @pytest.mark.env_single
  173. @pytest.mark.platform_x86_cpu
  174. @pytest.mark.platform_arm_ascend_training
  175. @pytest.mark.platform_x86_gpu_training
  176. @pytest.mark.platform_x86_ascend_training
  177. def test_query_aicore_detail_1(self):
  178. """Test the function of querying AICORE operator detail infomation."""
  179. expect_result = OP_GATHER_V2_INFO
  180. condition = {
  181. 'filter_condition': {
  182. 'op_type': {
  183. 'in': ['GatherV2']
  184. }
  185. },
  186. 'sort_condition': {
  187. 'name': 'avg_execution_time',
  188. 'type': 'descending'
  189. },
  190. 'group_condition': {
  191. 'limit': 10,
  192. 'offset': 0
  193. }
  194. }
  195. result = self._analyser_aicore_detail.query(condition)
  196. assert expect_result == result