mindspore 2.3.0__cp39-cp39-win_amd64.whl → 2.4.0__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/__init__.py +3 -1
- mindspore/_c_dataengine.cp39-win_amd64.pyd +0 -0
- mindspore/_c_expression.cp39-win_amd64.pyd +0 -0
- mindspore/_c_mindrecord.cp39-win_amd64.pyd +0 -0
- mindspore/_checkparam.py +50 -9
- mindspore/_extends/parse/compile_config.py +41 -0
- mindspore/_extends/parse/parser.py +9 -7
- mindspore/_extends/parse/standard_method.py +52 -14
- mindspore/_extends/pijit/pijit_func_white_list.py +350 -24
- mindspore/amp.py +24 -10
- mindspore/avcodec-59.dll +0 -0
- mindspore/avdevice-59.dll +0 -0
- mindspore/avfilter-8.dll +0 -0
- mindspore/avformat-59.dll +0 -0
- mindspore/avutil-57.dll +0 -0
- mindspore/common/__init__.py +6 -4
- mindspore/common/_pijit_context.py +190 -0
- mindspore/common/_register_for_tensor.py +2 -1
- mindspore/common/_tensor_overload.py +139 -0
- mindspore/common/api.py +102 -87
- mindspore/common/dump.py +5 -6
- mindspore/common/generator.py +1 -7
- mindspore/common/hook_handle.py +14 -26
- mindspore/common/mindir_util.py +2 -2
- mindspore/common/parameter.py +46 -13
- mindspore/common/recompute.py +39 -9
- mindspore/common/sparse_tensor.py +7 -3
- mindspore/common/tensor.py +209 -29
- mindspore/communication/__init__.py +1 -1
- mindspore/communication/_comm_helper.py +38 -3
- mindspore/communication/comm_func.py +310 -55
- mindspore/communication/management.py +14 -14
- mindspore/context.py +123 -22
- mindspore/dataset/__init__.py +1 -1
- mindspore/dataset/audio/__init__.py +1 -1
- mindspore/dataset/core/config.py +7 -0
- mindspore/dataset/core/validator_helpers.py +7 -0
- mindspore/dataset/engine/cache_client.py +1 -1
- mindspore/dataset/engine/datasets.py +72 -44
- mindspore/dataset/engine/datasets_audio.py +7 -7
- mindspore/dataset/engine/datasets_standard_format.py +53 -3
- mindspore/dataset/engine/datasets_text.py +20 -20
- mindspore/dataset/engine/datasets_user_defined.py +174 -104
- mindspore/dataset/engine/datasets_vision.py +33 -33
- mindspore/dataset/engine/iterators.py +29 -0
- mindspore/dataset/engine/obs/util.py +7 -0
- mindspore/dataset/engine/queue.py +114 -60
- mindspore/dataset/engine/serializer_deserializer.py +2 -2
- mindspore/dataset/engine/validators.py +34 -14
- mindspore/dataset/text/__init__.py +1 -4
- mindspore/dataset/transforms/__init__.py +0 -3
- mindspore/dataset/utils/line_reader.py +2 -0
- mindspore/dataset/vision/__init__.py +1 -4
- mindspore/dataset/vision/utils.py +1 -1
- mindspore/dataset/vision/validators.py +2 -1
- mindspore/dnnl.dll +0 -0
- mindspore/{nn/extend → experimental/es}/__init__.py +4 -11
- mindspore/experimental/es/embedding_service.py +883 -0
- mindspore/{nn/layer → experimental/es}/embedding_service_layer.py +218 -30
- mindspore/experimental/llm_boost/__init__.py +21 -0
- mindspore/{nn/extend/layer → experimental/llm_boost/atb}/__init__.py +4 -8
- mindspore/experimental/llm_boost/atb/boost_base.py +211 -0
- mindspore/experimental/llm_boost/atb/llama_boost.py +115 -0
- mindspore/experimental/llm_boost/atb/qwen_boost.py +101 -0
- mindspore/experimental/llm_boost/register.py +129 -0
- mindspore/experimental/llm_boost/utils.py +31 -0
- mindspore/experimental/optim/adamw.py +85 -0
- mindspore/experimental/optim/optimizer.py +3 -0
- mindspore/hal/__init__.py +3 -3
- mindspore/hal/contiguous_tensors_handle.py +175 -0
- mindspore/hal/stream.py +18 -0
- mindspore/include/api/model_group.h +13 -1
- mindspore/include/api/types.h +10 -10
- mindspore/include/dataset/config.h +2 -2
- mindspore/include/dataset/constants.h +2 -2
- mindspore/include/dataset/execute.h +2 -2
- mindspore/include/dataset/vision.h +4 -0
- mindspore/jpeg62.dll +0 -0
- mindspore/log.py +1 -1
- mindspore/mindrecord/filewriter.py +68 -51
- mindspore/mindspore_backend.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_np_dtype.dll +0 -0
- mindspore/mindspore_ops.dll +0 -0
- mindspore/mint/__init__.py +495 -46
- mindspore/mint/distributed/__init__.py +31 -0
- mindspore/mint/distributed/distributed.py +254 -0
- mindspore/mint/nn/__init__.py +266 -21
- mindspore/mint/nn/functional.py +125 -19
- mindspore/mint/nn/layer/__init__.py +39 -0
- mindspore/mint/nn/layer/activation.py +133 -0
- mindspore/mint/nn/layer/normalization.py +477 -0
- mindspore/mint/nn/layer/pooling.py +110 -0
- mindspore/mint/optim/adamw.py +28 -7
- mindspore/mint/special/__init__.py +63 -0
- mindspore/multiprocessing/__init__.py +2 -1
- mindspore/nn/__init__.py +0 -1
- mindspore/nn/cell.py +275 -93
- mindspore/nn/layer/activation.py +211 -44
- mindspore/nn/layer/basic.py +113 -3
- mindspore/nn/layer/embedding.py +120 -2
- mindspore/nn/layer/normalization.py +101 -5
- mindspore/nn/layer/padding.py +34 -48
- mindspore/nn/layer/pooling.py +161 -7
- mindspore/nn/layer/transformer.py +3 -3
- mindspore/nn/loss/__init__.py +2 -2
- mindspore/nn/loss/loss.py +84 -6
- mindspore/nn/optim/__init__.py +2 -1
- mindspore/nn/optim/adadelta.py +1 -1
- mindspore/nn/optim/adam.py +1 -1
- mindspore/nn/optim/lamb.py +1 -1
- mindspore/nn/optim/tft_wrapper.py +127 -0
- mindspore/nn/wrap/cell_wrapper.py +12 -23
- mindspore/nn/wrap/grad_reducer.py +5 -5
- mindspore/nn/wrap/loss_scale.py +17 -3
- mindspore/numpy/__init__.py +1 -1
- mindspore/numpy/array_creations.py +65 -68
- mindspore/numpy/array_ops.py +64 -60
- mindspore/numpy/fft.py +610 -75
- mindspore/numpy/logic_ops.py +11 -10
- mindspore/numpy/math_ops.py +85 -84
- mindspore/numpy/utils_const.py +4 -4
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/__init__.py +6 -4
- mindspore/ops/_grad_experimental/grad_comm_ops.py +47 -3
- mindspore/ops/_grad_experimental/grad_math_ops.py +0 -22
- mindspore/ops/_vmap/vmap_array_ops.py +2 -4
- mindspore/ops/_vmap/vmap_math_ops.py +17 -1
- mindspore/ops/_vmap/vmap_nn_ops.py +43 -2
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +85 -7
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +2 -0
- mindspore/ops/auto_generate/gen_extend_func.py +734 -13
- mindspore/ops/auto_generate/gen_ops_def.py +2420 -381
- mindspore/ops/auto_generate/gen_ops_prim.py +5196 -1659
- mindspore/ops/auto_generate/pyboost_inner_prim.py +176 -56
- mindspore/ops/composite/base.py +85 -48
- mindspore/ops/composite/multitype_ops/_compile_utils.py +1 -0
- mindspore/ops/composite/multitype_ops/not_in_impl.py +2 -2
- mindspore/ops/function/__init__.py +22 -0
- mindspore/ops/function/array_func.py +490 -153
- mindspore/ops/function/debug_func.py +113 -1
- mindspore/ops/function/fft_func.py +15 -2
- mindspore/ops/function/grad/grad_func.py +3 -2
- mindspore/ops/function/math_func.py +558 -207
- mindspore/ops/function/nn_func.py +817 -383
- mindspore/ops/function/other_func.py +3 -2
- mindspore/ops/function/random_func.py +184 -8
- mindspore/ops/function/reshard_func.py +13 -11
- mindspore/ops/function/sparse_unary_func.py +1 -1
- mindspore/ops/function/vmap_func.py +3 -2
- mindspore/ops/functional.py +24 -14
- mindspore/ops/op_info_register.py +3 -3
- mindspore/ops/operations/__init__.py +6 -1
- mindspore/ops/operations/_grad_ops.py +2 -76
- mindspore/ops/operations/_infer_ops.py +1 -1
- mindspore/ops/operations/_inner_ops.py +71 -94
- mindspore/ops/operations/array_ops.py +12 -146
- mindspore/ops/operations/comm_ops.py +42 -53
- mindspore/ops/operations/custom_ops.py +83 -19
- mindspore/ops/operations/debug_ops.py +42 -10
- mindspore/ops/operations/manually_defined/_inner.py +12 -0
- mindspore/ops/operations/manually_defined/ops_def.py +265 -10
- mindspore/ops/operations/math_ops.py +12 -223
- mindspore/ops/operations/nn_ops.py +20 -114
- mindspore/ops/operations/other_ops.py +7 -4
- mindspore/ops/operations/random_ops.py +46 -1
- mindspore/ops/primitive.py +18 -6
- mindspore/ops_generate/arg_dtype_cast.py +2 -0
- mindspore/ops_generate/gen_aclnn_implement.py +11 -11
- mindspore/ops_generate/gen_constants.py +36 -0
- mindspore/ops_generate/gen_ops.py +67 -52
- mindspore/ops_generate/gen_ops_inner_prim.py +1 -1
- mindspore/ops_generate/gen_pyboost_func.py +131 -47
- mindspore/ops_generate/op_proto.py +10 -3
- mindspore/ops_generate/pyboost_utils.py +14 -1
- mindspore/ops_generate/template.py +43 -21
- mindspore/parallel/__init__.py +3 -1
- mindspore/parallel/_auto_parallel_context.py +28 -8
- mindspore/parallel/_cell_wrapper.py +83 -0
- mindspore/parallel/_parallel_serialization.py +47 -19
- mindspore/parallel/_tensor.py +81 -11
- mindspore/parallel/_utils.py +13 -1
- mindspore/parallel/algo_parameter_config.py +5 -5
- mindspore/parallel/checkpoint_transform.py +46 -39
- mindspore/parallel/cluster/process_entity/__init__.py +1 -1
- mindspore/parallel/cluster/process_entity/_api.py +31 -23
- mindspore/parallel/cluster/process_entity/_utils.py +2 -27
- mindspore/parallel/parameter_broadcast.py +3 -4
- mindspore/parallel/shard.py +162 -31
- mindspore/parallel/transform_safetensors.py +993 -0
- mindspore/profiler/__init__.py +2 -1
- mindspore/profiler/common/constant.py +29 -0
- mindspore/profiler/common/registry.py +47 -0
- mindspore/profiler/common/util.py +28 -0
- mindspore/profiler/dynamic_profiler.py +694 -0
- mindspore/profiler/envprofiling.py +17 -19
- mindspore/profiler/parser/ascend_analysis/constant.py +18 -0
- mindspore/profiler/parser/ascend_analysis/file_manager.py +25 -4
- mindspore/profiler/parser/ascend_analysis/function_event.py +43 -19
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +31 -26
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +56 -10
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +55 -8
- mindspore/profiler/parser/ascend_analysis/path_manager.py +313 -0
- mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +27 -20
- mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +9 -2
- mindspore/profiler/parser/ascend_msprof_exporter.py +5 -4
- mindspore/profiler/parser/ascend_timeline_generator.py +27 -25
- mindspore/profiler/parser/base_timeline_generator.py +19 -25
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +25 -12
- mindspore/profiler/parser/framework_parser.py +1 -391
- mindspore/profiler/parser/gpu_analysis/__init__.py +14 -0
- mindspore/profiler/parser/gpu_analysis/function_event.py +44 -0
- mindspore/profiler/parser/gpu_analysis/fwk_file_parser.py +89 -0
- mindspore/profiler/parser/gpu_analysis/profiler_info_parser.py +72 -0
- mindspore/profiler/parser/memory_usage_parser.py +0 -154
- mindspore/profiler/parser/profiler_info.py +78 -6
- mindspore/profiler/profiler.py +153 -0
- mindspore/profiler/profiling.py +280 -412
- mindspore/rewrite/__init__.py +1 -2
- mindspore/rewrite/common/namespace.py +4 -4
- mindspore/rewrite/symbol_tree/symbol_tree.py +3 -3
- mindspore/run_check/_check_version.py +36 -103
- mindspore/safeguard/rewrite_obfuscation.py +591 -247
- mindspore/swresample-4.dll +0 -0
- mindspore/swscale-6.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/__init__.py +4 -3
- mindspore/train/_utils.py +28 -2
- mindspore/train/amp.py +171 -53
- mindspore/train/callback/__init__.py +2 -2
- mindspore/train/callback/_callback.py +4 -4
- mindspore/train/callback/_checkpoint.py +85 -22
- mindspore/train/callback/_cluster_monitor.py +1 -1
- mindspore/train/callback/_flops_collector.py +1 -0
- mindspore/train/callback/_loss_monitor.py +3 -3
- mindspore/train/callback/_on_request_exit.py +134 -31
- mindspore/train/callback/_summary_collector.py +5 -5
- mindspore/train/callback/_tft_register.py +352 -0
- mindspore/train/dataset_helper.py +7 -3
- mindspore/train/metrics/metric.py +3 -3
- mindspore/train/metrics/roc.py +4 -4
- mindspore/train/mind_ir_pb2.py +44 -39
- mindspore/train/model.py +134 -58
- mindspore/train/serialization.py +336 -112
- mindspore/turbojpeg.dll +0 -0
- mindspore/utils/__init__.py +21 -0
- mindspore/utils/utils.py +60 -0
- mindspore/version.py +1 -1
- {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/METADATA +6 -2
- {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/RECORD +258 -252
- mindspore/include/c_api/ms/abstract.h +0 -67
- mindspore/include/c_api/ms/attribute.h +0 -197
- mindspore/include/c_api/ms/base/handle_types.h +0 -43
- mindspore/include/c_api/ms/base/macros.h +0 -32
- mindspore/include/c_api/ms/base/status.h +0 -33
- mindspore/include/c_api/ms/base/types.h +0 -283
- mindspore/include/c_api/ms/context.h +0 -102
- mindspore/include/c_api/ms/graph.h +0 -160
- mindspore/include/c_api/ms/node.h +0 -606
- mindspore/include/c_api/ms/tensor.h +0 -161
- mindspore/include/c_api/ms/value.h +0 -84
- mindspore/mindspore_shared_lib.dll +0 -0
- mindspore/nn/extend/basic.py +0 -140
- mindspore/nn/extend/embedding.py +0 -143
- mindspore/nn/extend/layer/normalization.py +0 -109
- mindspore/nn/extend/pooling.py +0 -117
- mindspore/nn/layer/embedding_service.py +0 -531
- mindspore/ops/_op_impl/aicpu/strided_slice_v2.py +0 -93
- mindspore/ops/_op_impl/aicpu/strided_slice_v2_grad.py +0 -66
- mindspore/ops/extend/__init__.py +0 -53
- mindspore/ops/extend/array_func.py +0 -218
- mindspore/ops/extend/math_func.py +0 -76
- mindspore/ops/extend/nn_func.py +0 -308
- mindspore/ops/silent_check.py +0 -162
- mindspore/profiler/parser/msadvisor_analyzer.py +0 -82
- mindspore/profiler/parser/msadvisor_parser.py +0 -240
- mindspore/train/callback/_mindio_ttp.py +0 -443
- {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/WHEEL +0 -0
- {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/entry_points.txt +0 -0
- {mindspore-2.3.0.dist-info → mindspore-2.4.0.dist-info}/top_level.txt +0 -0
|
@@ -91,7 +91,7 @@ class BaseTimelineGenerator:
|
|
|
91
91
|
_framework_dir = "FRAMEWORK"
|
|
92
92
|
_op_range_name = "op_range_{}"
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
_col_names = ['op_name', 'stream_id', 'start_time', 'duration']
|
|
95
95
|
|
|
96
96
|
def __init__(self, device_target, model):
|
|
97
97
|
self._tid_dict = {
|
|
@@ -149,7 +149,8 @@ class BaseTimelineGenerator:
|
|
|
149
149
|
"""Get process and thread config."""
|
|
150
150
|
device_process_label = self._get_device_process_label()
|
|
151
151
|
return [
|
|
152
|
-
{"name": "process_labels", "ph": "M", "pid": self._device_id
|
|
152
|
+
{"name": "process_labels", "ph": "M", "pid": f'2{self._device_id}',
|
|
153
|
+
"args": {"labels": device_process_label}},
|
|
153
154
|
{"name": "process_labels", "ph": "M", "pid": self._AI_CPU_PID, "args": {"labels": self._aicpu_op_label}},
|
|
154
155
|
{"name": "process_labels", "ph": "M", "pid": self._COMMUNICATION_OP_PID,
|
|
155
156
|
"args": {"labels": "Communication Op"}},
|
|
@@ -160,7 +161,7 @@ class BaseTimelineGenerator:
|
|
|
160
161
|
{"name": "process_labels", "ph": "M", "pid": self._OP_GPU_ACTIVITY_PID,
|
|
161
162
|
"args": {"labels": "Activity Op"}},
|
|
162
163
|
|
|
163
|
-
{"name": "process_sort_index", "ph": "M", "pid": self._device_id, "args": {"sort_index":
|
|
164
|
+
{"name": "process_sort_index", "ph": "M", "pid": f'2{self._device_id}', "args": {"sort_index": 2}},
|
|
164
165
|
{"name": "process_sort_index", "ph": "M", "pid": self._AI_CPU_PID, "args": {"sort_index": 10}},
|
|
165
166
|
{"name": "process_sort_index", "ph": "M", "pid": self._COMMUNICATION_OP_PID, "args": {"sort_index": 20}},
|
|
166
167
|
{"name": "process_sort_index", "ph": "M", "pid": self._HOST_CPU_PID, "args": {"sort_index": 30}},
|
|
@@ -176,9 +177,9 @@ class BaseTimelineGenerator:
|
|
|
176
177
|
"args": {"name": "Merged Communication Op"}},
|
|
177
178
|
{"name": "thread_name", "ph": "M", "pid": self._OP_OVERLAP_PID, "tid": self._FREE_TIME_TID,
|
|
178
179
|
"args": {"name": "Free Time"}},
|
|
179
|
-
{"name": "thread_name", "ph": "M", "pid": self._device_id, "tid": self._STEPS_TID,
|
|
180
|
+
{"name": "thread_name", "ph": "M", "pid": f'2{self._device_id}', "tid": self._STEPS_TID,
|
|
180
181
|
"args": {"name": "Steps"}},
|
|
181
|
-
{"name": "thread_name", "ph": "M", "pid": self._device_id, "tid": self._SINGLE_TID,
|
|
182
|
+
{"name": "thread_name", "ph": "M", "pid": f'2{self._device_id}', "tid": self._SINGLE_TID,
|
|
182
183
|
"args": {"name": "Ops"}},
|
|
183
184
|
|
|
184
185
|
{"name": "thread_sort_index", "ph": "M", "pid": self._OP_OVERLAP_PID, "tid": self._MERGED_COMPUTATION_TID,
|
|
@@ -189,19 +190,19 @@ class BaseTimelineGenerator:
|
|
|
189
190
|
"args": {"sort_index": self._MERGED_COMMUNICATION_TID}},
|
|
190
191
|
{"name": "thread_sort_index", "ph": "M", "pid": self._OP_OVERLAP_PID, "tid": self._FREE_TIME_TID,
|
|
191
192
|
"args": {"sort_index": self._FREE_TIME_TID}},
|
|
192
|
-
{"name": "thread_sort_index", "ph": "M", "pid": self._device_id, "tid": self._STEPS_TID,
|
|
193
|
+
{"name": "thread_sort_index", "ph": "M", "pid": f'2{self._device_id}', "tid": self._STEPS_TID,
|
|
193
194
|
"args": {"sort_index": self._STEPS_SORT_INDEX}},
|
|
194
195
|
]
|
|
195
196
|
|
|
196
|
-
def write_timeline(self
|
|
197
|
+
def write_timeline(self):
|
|
197
198
|
"""Load data according to the parsed profiling files."""
|
|
198
199
|
# Write timeline to file.
|
|
199
200
|
logger.info('Writing timeline file...')
|
|
200
|
-
timeline_meta = self.write_timeline_to_json_by_limitation(
|
|
201
|
+
timeline_meta = self.write_timeline_to_json_by_limitation()
|
|
201
202
|
logger.info('Finished file writing!')
|
|
202
203
|
return timeline_meta
|
|
203
204
|
|
|
204
|
-
def write_timeline_to_json_by_limitation(self
|
|
205
|
+
def write_timeline_to_json_by_limitation(self):
|
|
205
206
|
"""Write timeline to json by limitation."""
|
|
206
207
|
display_file_path = os.path.join(
|
|
207
208
|
self._profiling_dir,
|
|
@@ -210,22 +211,15 @@ class BaseTimelineGenerator:
|
|
|
210
211
|
display_file_path = validate_and_normalize_path(display_file_path)
|
|
211
212
|
|
|
212
213
|
try:
|
|
214
|
+
timeline_data = self.get_thread_label_name()
|
|
215
|
+
for data in self._timeline_meta:
|
|
216
|
+
timeline_data.append(data)
|
|
217
|
+
if "scope_level" in data.keys():
|
|
218
|
+
self._max_scope_name_num = max(
|
|
219
|
+
self._max_scope_name_num, data["scope_level"] + 1)
|
|
220
|
+
|
|
213
221
|
with os.fdopen(os.open(display_file_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), 'w') as json_file:
|
|
214
|
-
json_file.
|
|
215
|
-
for _, item in enumerate(self._timeline_meta):
|
|
216
|
-
item_json = json.dumps([item], indent=self.indent)
|
|
217
|
-
item_json = item_json.lstrip('[').rstrip('\n]')
|
|
218
|
-
json_file.write(item_json)
|
|
219
|
-
if "scope_level" in item.keys():
|
|
220
|
-
self._max_scope_name_num = max(
|
|
221
|
-
self._max_scope_name_num, item["scope_level"] + 1)
|
|
222
|
-
file_size = os.path.getsize(display_file_path)
|
|
223
|
-
json_file.write(',')
|
|
224
|
-
if file_size > size_limit:
|
|
225
|
-
break
|
|
226
|
-
label_name_json = json.dumps(self.get_thread_label_name(), indent=self.indent)
|
|
227
|
-
label_name_json = label_name_json.lstrip('[')
|
|
228
|
-
json_file.write(label_name_json)
|
|
222
|
+
json.dump(timeline_data, json_file, indent=self.indent)
|
|
229
223
|
os.chmod(display_file_path, stat.S_IREAD | stat.S_IWRITE)
|
|
230
224
|
return self._timeline_meta
|
|
231
225
|
except (IOError, OSError) as err:
|
|
@@ -317,7 +311,7 @@ class BaseTimelineGenerator:
|
|
|
317
311
|
"""Update format meta data which control the display arrange and map the thread name."""
|
|
318
312
|
thread_name_meta_data = {
|
|
319
313
|
"name": "thread_name",
|
|
320
|
-
"pid": int(self._device_id),
|
|
314
|
+
"pid": int(f'2{self._device_id}'),
|
|
321
315
|
"tid": 100000,
|
|
322
316
|
"ts": 0,
|
|
323
317
|
"ph": "M",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
# ============================================================================
|
|
15
15
|
"""The integrator for integrating parsed profiling files."""
|
|
16
|
+
import json
|
|
16
17
|
import os
|
|
17
18
|
import csv
|
|
18
19
|
|
|
@@ -23,6 +24,7 @@ from mindspore.profiler.parser.container import TimelineContainer
|
|
|
23
24
|
from mindspore.profiler.parser.base_timeline_generator import BaseTimelineGenerator
|
|
24
25
|
from mindspore.profiler.parser.integrator import DeviceTarget
|
|
25
26
|
from mindspore.profiler.common.validator.validate_path import validate_and_normalize_path
|
|
27
|
+
from mindspore.profiler.parser.gpu_analysis.fwk_file_parser import GPUFwkFileParser
|
|
26
28
|
|
|
27
29
|
|
|
28
30
|
class GpuTimelineGenerator(BaseTimelineGenerator):
|
|
@@ -65,10 +67,6 @@ class GpuTimelineGenerator(BaseTimelineGenerator):
|
|
|
65
67
|
if len(timeline) == 4:
|
|
66
68
|
self._update_num_of_streams(timeline, stream_count_dict)
|
|
67
69
|
|
|
68
|
-
# Add format thread meta data.
|
|
69
|
-
self._format_meta_data_list.extend(self._timeline_meta)
|
|
70
|
-
self._timeline_meta = self._format_meta_data_list
|
|
71
|
-
|
|
72
70
|
# Update timeline summary info
|
|
73
71
|
self._timeline_summary['num_of_streams'] += len(stream_count_dict)
|
|
74
72
|
|
|
@@ -109,6 +107,26 @@ class GpuTimelineGenerator(BaseTimelineGenerator):
|
|
|
109
107
|
logger.warning('No step trace data exists.')
|
|
110
108
|
return False
|
|
111
109
|
|
|
110
|
+
def parse_fwk_data(self):
|
|
111
|
+
"""
|
|
112
|
+
Get framework op range trace data
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
fwk_parser = GPUFwkFileParser(self._profiling_dir, self._device_id)
|
|
116
|
+
fwk_data = fwk_parser.get_op_range_data()
|
|
117
|
+
self._fwk_json = fwk_parser.get_fwk_trace_data(fwk_data)
|
|
118
|
+
|
|
119
|
+
def write_fwk_timeline(self):
|
|
120
|
+
display_file_path = os.path.join(self._profiling_dir, self._display_filename)
|
|
121
|
+
timeline_data = self._fwk_json
|
|
122
|
+
if os.path.exists(display_file_path):
|
|
123
|
+
with os.fdopen(os.open(display_file_path, os.O_RDONLY, 0o600), 'r') as fr:
|
|
124
|
+
device_data = fr.read()
|
|
125
|
+
timeline_data.extend(json.loads(device_data))
|
|
126
|
+
|
|
127
|
+
with os.fdopen(os.open(display_file_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), 'w') as fw:
|
|
128
|
+
json.dump(timeline_data, fw)
|
|
129
|
+
|
|
112
130
|
def _get_and_validate_path(self, file_name):
|
|
113
131
|
"""Generate op or activity file path from file name, and validate this path."""
|
|
114
132
|
file_path = os.path.join(
|
|
@@ -133,9 +151,9 @@ class GpuTimelineGenerator(BaseTimelineGenerator):
|
|
|
133
151
|
timeline_dict['tid'] = op_meta.stream_id
|
|
134
152
|
timeline_dict['ts'] = (op_meta.start_time - min_cycle_counter) / factor
|
|
135
153
|
dur = op_meta.duration
|
|
136
|
-
timeline_dict['dur'] = dur
|
|
154
|
+
timeline_dict['dur'] = dur # unit is us
|
|
137
155
|
if op_meta.pid is None:
|
|
138
|
-
timeline_dict['pid'] = int(self._device_id)
|
|
156
|
+
timeline_dict['pid'] = int(f'2{self._device_id}')
|
|
139
157
|
else:
|
|
140
158
|
timeline_dict['pid'] = op_meta.pid
|
|
141
159
|
if op_meta.stream_id == "Scope Name":
|
|
@@ -555,17 +573,12 @@ class CpuTimelineGenerator(GpuTimelineGenerator):
|
|
|
555
573
|
if len(timeline) == 4:
|
|
556
574
|
self._update_num_of_streams(timeline, stream_count_dict)
|
|
557
575
|
|
|
558
|
-
# Add format thread meta data.
|
|
559
|
-
self._format_meta_data_list.extend(self._timeline_meta)
|
|
560
|
-
self._timeline_meta = self._format_meta_data_list
|
|
561
|
-
|
|
562
576
|
# Update timeline summary info
|
|
563
577
|
self._timeline_summary['num_of_streams'] += len(stream_count_dict.keys())
|
|
564
578
|
|
|
565
579
|
def load_cpu_op_data(self):
|
|
566
580
|
"""Load cpu operator data from file"""
|
|
567
|
-
op_file_path = self._get_and_validate_path(
|
|
568
|
-
self._output_op_execute_time_file_path)
|
|
581
|
+
op_file_path = self._get_and_validate_path(self._output_op_execute_time_file_path)
|
|
569
582
|
timeline_list = []
|
|
570
583
|
if not os.path.exists(op_file_path):
|
|
571
584
|
logger.info("No cpu operator info.")
|
|
@@ -13,30 +13,17 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
# ============================================================================
|
|
15
15
|
"""The parser for parsing framework files."""
|
|
16
|
-
import csv
|
|
17
16
|
import glob
|
|
18
17
|
import json
|
|
19
18
|
import os
|
|
20
19
|
import stat
|
|
21
|
-
import re
|
|
22
|
-
import struct
|
|
23
20
|
from collections import defaultdict
|
|
24
21
|
from collections import namedtuple
|
|
25
|
-
from pathlib import Path
|
|
26
|
-
from typing import List
|
|
27
22
|
|
|
28
23
|
import numpy as np
|
|
29
|
-
from mindspore import log as logger
|
|
30
|
-
from mindspore.profiler.common.exceptions.exceptions import ProfilerDirNotFoundException
|
|
31
|
-
from mindspore.profiler.common.exceptions.exceptions import ProfilerFileNotFoundException
|
|
32
|
-
from mindspore.profiler.common.exceptions.exceptions import ProfilerParamValueErrorException
|
|
33
|
-
from mindspore.profiler.common.struct_type import StructType
|
|
34
|
-
from mindspore.profiler.common.util import combine_stream_task_id
|
|
35
24
|
from mindspore.profiler.common.validator.validate_path import validate_and_normalize_path
|
|
36
|
-
from mindspore.profiler.parser.framework_enum import
|
|
37
|
-
from mindspore.profiler.parser.framework_enum import VmDataType, VmFormat, FileDataType, MSPROF_DIFFERENCE
|
|
25
|
+
from mindspore.profiler.parser.framework_enum import FileDataType
|
|
38
26
|
from mindspore.profiler.parser.framework_struct import TASK_DESC_STRUCT, TENSOR_DATA_STRUCT, STEP_INFO_STRUCT
|
|
39
|
-
from mindspore.profiler.parser.profiler_info import ProfilerInfo
|
|
40
27
|
|
|
41
28
|
FILE_DATA_STRUCT_DICT = {
|
|
42
29
|
FileDataType.STEP_INFO.value: STEP_INFO_STRUCT,
|
|
@@ -60,383 +47,6 @@ COL_NAMES = [
|
|
|
60
47
|
OpData = namedtuple('OpData', field_names=COL_NAMES)
|
|
61
48
|
|
|
62
49
|
|
|
63
|
-
class FrameworkParser:
|
|
64
|
-
"""
|
|
65
|
-
The parser for parsing framework files.
|
|
66
|
-
|
|
67
|
-
Args:
|
|
68
|
-
profiling_path (str): The profiling path which should contain CANN profiling data.
|
|
69
|
-
rank_id (str): The rank ID.
|
|
70
|
-
output_path (str): The directory of the parsed file. Default: `./`.
|
|
71
|
-
"""
|
|
72
|
-
_regex_framework = r'Framework\.(?P<data_type>.+)\.(?P<device_id>\d).+'
|
|
73
|
-
_host_regex_framework = r'Framework\.(?P<data_type>.+)\.+'
|
|
74
|
-
_match_framework_file = r'Framework*[0-9]'
|
|
75
|
-
_graph_attr_name = [
|
|
76
|
-
'input_format', 'input_data_type', 'input_shape', 'output_format',
|
|
77
|
-
'output_data_type', 'output_shape'
|
|
78
|
-
]
|
|
79
|
-
output_file_format = 'framework_raw_{rank_id}.csv'
|
|
80
|
-
|
|
81
|
-
def __init__(self, profiling_path, rank_id, output_path='./'):
|
|
82
|
-
self._profiling_path = profiling_path
|
|
83
|
-
self._output_path = output_path
|
|
84
|
-
self._rank_id = rank_id
|
|
85
|
-
|
|
86
|
-
self._hash_dict = {}
|
|
87
|
-
self._task_id_full_op_name_dict = {}
|
|
88
|
-
self._point_info = {}
|
|
89
|
-
|
|
90
|
-
@property
|
|
91
|
-
def save_path(self):
|
|
92
|
-
"""
|
|
93
|
-
The property of save path.
|
|
94
|
-
|
|
95
|
-
Returns:
|
|
96
|
-
str, the save path.
|
|
97
|
-
"""
|
|
98
|
-
return os.path.realpath(os.path.join(self._output_path, self.output_file_format.format(rank_id=self._rank_id)))
|
|
99
|
-
|
|
100
|
-
@property
|
|
101
|
-
def point_info(self):
|
|
102
|
-
"""
|
|
103
|
-
The property of the framework point information.
|
|
104
|
-
|
|
105
|
-
Returns:
|
|
106
|
-
dict, the framework point information, key is tag, value is op name.
|
|
107
|
-
"""
|
|
108
|
-
# Note: In the multi-subgraph or multi-tag scenario, op name is overwritten.
|
|
109
|
-
return self._point_info
|
|
110
|
-
|
|
111
|
-
@staticmethod
|
|
112
|
-
def _check_output_path(path):
|
|
113
|
-
if not os.path.exists(path) or not os.path.isdir(path):
|
|
114
|
-
raise ProfilerDirNotFoundException(path)
|
|
115
|
-
|
|
116
|
-
@staticmethod
|
|
117
|
-
def _parse_hash_dic(framework_path_dict):
|
|
118
|
-
"""Parse the hash dic files, and return a hash value map op name dict."""
|
|
119
|
-
hash_op_dict = {}
|
|
120
|
-
for path in framework_path_dict[FileDataType.HASH_DIC.value]:
|
|
121
|
-
with open(path, 'r') as file:
|
|
122
|
-
for hash_str in file:
|
|
123
|
-
hash_value, op_name = hash_str.strip().split(':')
|
|
124
|
-
hash_op_dict[hash_value] = op_name
|
|
125
|
-
return hash_op_dict
|
|
126
|
-
|
|
127
|
-
@staticmethod
|
|
128
|
-
def _special_process_tensor_data(item_binary_data, data_type, tensor_num):
|
|
129
|
-
"""The tensor data depends tensor num, so need to special process."""
|
|
130
|
-
start = 0
|
|
131
|
-
op_attr_struct = data_type[0]
|
|
132
|
-
op_attr_size = StructType.sizeof(op_attr_struct)
|
|
133
|
-
unpack_data = []
|
|
134
|
-
|
|
135
|
-
for _ in range(tensor_num):
|
|
136
|
-
buffer = item_binary_data[start:start + op_attr_size]
|
|
137
|
-
values = struct.unpack(StructType.format(op_attr_struct), buffer)
|
|
138
|
-
one_data = dict(
|
|
139
|
-
tensorType=values[0],
|
|
140
|
-
format=values[1],
|
|
141
|
-
dataType=values[2],
|
|
142
|
-
shape=list(filter(lambda x: x != 0, values[3:]))
|
|
143
|
-
)
|
|
144
|
-
unpack_data.append(one_data)
|
|
145
|
-
start += op_attr_size
|
|
146
|
-
|
|
147
|
-
return unpack_data
|
|
148
|
-
|
|
149
|
-
@staticmethod
|
|
150
|
-
def _special_process_tensor_num(item_binary_data, data_type):
|
|
151
|
-
"""The memory of tensorNum is aligned, so here need to special process"""
|
|
152
|
-
cursor = 0
|
|
153
|
-
tensor_num_struct = data_type[0]
|
|
154
|
-
size = StructType.sizeof(tensor_num_struct)
|
|
155
|
-
unpack_data = struct.unpack(tensor_num_struct.value, item_binary_data[cursor:cursor + size])[0]
|
|
156
|
-
return unpack_data
|
|
157
|
-
|
|
158
|
-
@staticmethod
|
|
159
|
-
def _construct_task_id_full_op_name_dict(task_desc_info):
|
|
160
|
-
"""The task desc info is a list[task_desc], task_desc is a dict, key is same as TASK_DESC_STRUCT."""
|
|
161
|
-
task_id_full_op_name = {}
|
|
162
|
-
for task_desc in task_desc_info:
|
|
163
|
-
task_id = combine_stream_task_id(task_desc['streamId'], task_desc['taskId'])
|
|
164
|
-
task_id_full_op_name[task_id] = task_desc['opName']
|
|
165
|
-
return task_id_full_op_name
|
|
166
|
-
|
|
167
|
-
@staticmethod
|
|
168
|
-
def _construct_point_info(task_id_full_op_name_dict, step_point_data):
|
|
169
|
-
"""step_point_data is a list[step_data], step data is a dict, key is same as STEP_INFO_STRUCT."""
|
|
170
|
-
point_info = {}
|
|
171
|
-
for step_point in step_point_data:
|
|
172
|
-
task_id = combine_stream_task_id(step_point['streamId'], step_point['taskId'])
|
|
173
|
-
tag = step_point['tag']
|
|
174
|
-
full_op_name = task_id_full_op_name_dict[task_id]
|
|
175
|
-
point_info[tag] = full_op_name
|
|
176
|
-
return point_info
|
|
177
|
-
|
|
178
|
-
@staticmethod
|
|
179
|
-
def _get_vm_data_type(msprof_data_type):
|
|
180
|
-
"""Get the mapped vm data type of msprof."""
|
|
181
|
-
if msprof_data_type >= MSPROF_DIFFERENCE:
|
|
182
|
-
return msprof_data_type - MSPROF_DIFFERENCE
|
|
183
|
-
return msprof_data_type
|
|
184
|
-
|
|
185
|
-
@staticmethod
|
|
186
|
-
def _get_vm_op_format(msprof_op_format):
|
|
187
|
-
"""Get the mapped op format type of msprof."""
|
|
188
|
-
if msprof_op_format >= MSPROF_DIFFERENCE:
|
|
189
|
-
return msprof_op_format - MSPROF_DIFFERENCE
|
|
190
|
-
return msprof_op_format
|
|
191
|
-
|
|
192
|
-
@staticmethod
|
|
193
|
-
def _construct_task_id_op_attr_dict(prof_tensor_data):
|
|
194
|
-
"""prof_tensor_data is a list[tensor_data], tensor_data is a dict, key is same as TENSOR_DATA_STRUCT."""
|
|
195
|
-
task_id_op_attr_dict = defaultdict(list)
|
|
196
|
-
for tensor_data in prof_tensor_data:
|
|
197
|
-
task_id = combine_stream_task_id(tensor_data['streamId'], tensor_data['taskId'])
|
|
198
|
-
for tensor_attr in tensor_data['tensorData']:
|
|
199
|
-
tensor_type = 'input' if tensor_attr['tensorType'] == 0 else 'output'
|
|
200
|
-
tensor_format = VmFormat.get_format_name(FrameworkParser._get_vm_data_type(tensor_attr['format']))
|
|
201
|
-
op_attr = dict(
|
|
202
|
-
tensor_type=tensor_type,
|
|
203
|
-
format=tensor_format,
|
|
204
|
-
data_type=VmDataType.get_data_type_name(FrameworkParser._get_vm_op_format(tensor_attr['dataType'])),
|
|
205
|
-
shape=tensor_attr['shape']
|
|
206
|
-
)
|
|
207
|
-
task_id_op_attr_dict[task_id].append(op_attr)
|
|
208
|
-
|
|
209
|
-
for task_id, op_attrs in task_id_op_attr_dict.items():
|
|
210
|
-
input_count = 0
|
|
211
|
-
output_count = 0
|
|
212
|
-
new_op_attr = {}
|
|
213
|
-
for op_attr in op_attrs:
|
|
214
|
-
if op_attr['tensor_type'] == 'input':
|
|
215
|
-
op_attr.pop('tensor_type')
|
|
216
|
-
new_op_attr[f'input_{input_count}'] = op_attr
|
|
217
|
-
input_count += 1
|
|
218
|
-
else:
|
|
219
|
-
op_attr.pop('tensor_type')
|
|
220
|
-
new_op_attr[f'output_{output_count}'] = op_attr
|
|
221
|
-
output_count += 1
|
|
222
|
-
task_id_op_attr_dict[task_id] = new_op_attr
|
|
223
|
-
|
|
224
|
-
return task_id_op_attr_dict
|
|
225
|
-
|
|
226
|
-
@staticmethod
|
|
227
|
-
def _write_framework_to_file(all_op_data: List[OpData], output_file):
|
|
228
|
-
with os.fdopen(os.open(output_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), 'w') as file_handler:
|
|
229
|
-
csv_writer = csv.writer(file_handler)
|
|
230
|
-
csv_writer.writerow(COL_NAMES)
|
|
231
|
-
csv_writer.writerows(all_op_data)
|
|
232
|
-
os.chmod(output_file, stat.S_IREAD | stat.S_IWRITE)
|
|
233
|
-
|
|
234
|
-
@staticmethod
|
|
235
|
-
def _get_subgraph_name(full_op_name):
|
|
236
|
-
"""
|
|
237
|
-
Get subgraph name.
|
|
238
|
-
|
|
239
|
-
Args:
|
|
240
|
-
full_op_name (str): The full operator name.
|
|
241
|
-
|
|
242
|
-
Returns:
|
|
243
|
-
str, the subgraph name.
|
|
244
|
-
"""
|
|
245
|
-
subgraph_name = full_op_name.split('/', 1)[0]
|
|
246
|
-
if subgraph_name in ['Default', 'Gradients']:
|
|
247
|
-
return subgraph_name
|
|
248
|
-
return None
|
|
249
|
-
|
|
250
|
-
def check_op_name(self, op_name, is_prefix=True):
|
|
251
|
-
"""
|
|
252
|
-
Check whether the operator name exists.
|
|
253
|
-
|
|
254
|
-
Args:
|
|
255
|
-
op_name (str): The operator name or operator name prefix.
|
|
256
|
-
is_prefix (bool): `True` if the op_name is prefix, else `False`.
|
|
257
|
-
Default: ``True``.
|
|
258
|
-
|
|
259
|
-
Returns:
|
|
260
|
-
bool, `True` if the operator name does exist in framework file, else
|
|
261
|
-
`False`.
|
|
262
|
-
"""
|
|
263
|
-
if not op_name:
|
|
264
|
-
raise ProfilerParamValueErrorException('The op_name should exist.')
|
|
265
|
-
for full_op_name in self._task_id_full_op_name_dict.values():
|
|
266
|
-
if full_op_name:
|
|
267
|
-
if is_prefix and full_op_name.startswith(op_name):
|
|
268
|
-
return True
|
|
269
|
-
if not is_prefix and op_name == full_op_name:
|
|
270
|
-
return True
|
|
271
|
-
return False
|
|
272
|
-
|
|
273
|
-
def to_task_id_full_op_name_dict(self):
|
|
274
|
-
"""
|
|
275
|
-
Get the task id and full operator name dict.
|
|
276
|
-
|
|
277
|
-
Returns:
|
|
278
|
-
dict, the task id and full operator name dict.
|
|
279
|
-
"""
|
|
280
|
-
return self._task_id_full_op_name_dict
|
|
281
|
-
|
|
282
|
-
def parse(self):
|
|
283
|
-
"""Parse the framework files."""
|
|
284
|
-
framework_path_dict = self._search_file(self._profiling_path)
|
|
285
|
-
self._hash_dict = self._parse_hash_dic(framework_path_dict)
|
|
286
|
-
|
|
287
|
-
all_file_data = self._parse_binary_data(framework_path_dict)
|
|
288
|
-
task_id_full_op_name_dict = self._construct_task_id_full_op_name_dict(
|
|
289
|
-
all_file_data[FileDataType.TASK_DESC_INFO.value])
|
|
290
|
-
point_info = self._construct_point_info(task_id_full_op_name_dict, all_file_data[FileDataType.STEP_INFO.value])
|
|
291
|
-
task_id_op_attr_dict = self._construct_task_id_op_attr_dict(all_file_data[FileDataType.TENSOR_DATA_INFO.value])
|
|
292
|
-
|
|
293
|
-
self._point_info = point_info
|
|
294
|
-
self._task_id_full_op_name_dict = task_id_full_op_name_dict
|
|
295
|
-
|
|
296
|
-
all_op_data = self._construct_op_data_to_file(all_file_data[FileDataType.TASK_DESC_INFO.value],
|
|
297
|
-
task_id_op_attr_dict)
|
|
298
|
-
|
|
299
|
-
self._write_framework_to_file(all_op_data, output_file=self.save_path)
|
|
300
|
-
|
|
301
|
-
def _search_file(self, profiling_path):
|
|
302
|
-
"""
|
|
303
|
-
Search all framework files in raw profiling path.
|
|
304
|
-
|
|
305
|
-
Args:
|
|
306
|
-
profiling_path (str): This profiling path should contain data dir.
|
|
307
|
-
|
|
308
|
-
Return:
|
|
309
|
-
dict, return a dict container all framework file paths. Format is {FileDataType: [file paths]}.
|
|
310
|
-
|
|
311
|
-
Raises:
|
|
312
|
-
ProfilerFileNotFoundException: If the framework files are not found.
|
|
313
|
-
"""
|
|
314
|
-
data_dir = os.path.join(profiling_path, 'data')
|
|
315
|
-
host_data_dir = os.path.join(profiling_path, '../host/data')
|
|
316
|
-
if not os.path.isdir(data_dir) and not os.path.isdir(host_data_dir):
|
|
317
|
-
raise ProfilerDirNotFoundException(data_dir)
|
|
318
|
-
|
|
319
|
-
framework_path_dict = defaultdict(list)
|
|
320
|
-
file_list = [f for f in Path(data_dir).glob(self._match_framework_file)]
|
|
321
|
-
if not file_list:
|
|
322
|
-
file_list = [f for f in Path(host_data_dir).glob(self._match_framework_file)]
|
|
323
|
-
|
|
324
|
-
for file in file_list:
|
|
325
|
-
file_name = file.name
|
|
326
|
-
|
|
327
|
-
match = re.search(self._regex_framework, file_name)
|
|
328
|
-
if match is None:
|
|
329
|
-
match = re.search(self._host_regex_framework, file_name)
|
|
330
|
-
if match is None:
|
|
331
|
-
logger.warning("Profiler does not support to analyse file(%s), this file name format is not %s, "
|
|
332
|
-
"skip this file.", file.resolve(), self._regex_framework)
|
|
333
|
-
continue
|
|
334
|
-
|
|
335
|
-
if match['data_type'] not in FileDataType.members():
|
|
336
|
-
logger.warning("Profiler does not support to analyse file(%s), this file data type is %s, "
|
|
337
|
-
"skip this file.", file.resolve(), match['data_type'])
|
|
338
|
-
if match['data_type'].startswith('vm'):
|
|
339
|
-
raise RuntimeError("The current profiler file is generated by MindSpore 1.5 or earlier. Use "
|
|
340
|
-
"MindSpore 1.5 or the matching MindSpore version to parse the profiler file.")
|
|
341
|
-
continue
|
|
342
|
-
|
|
343
|
-
framework_path_dict[match['data_type']].append(file.resolve())
|
|
344
|
-
|
|
345
|
-
empty_files = [data_type for data_type, files in framework_path_dict.items() if not files]
|
|
346
|
-
if not framework_path_dict or empty_files:
|
|
347
|
-
if empty_files:
|
|
348
|
-
logger.error("Can not find %s files when parse profiler framework file.", ','.join(empty_files))
|
|
349
|
-
raise ProfilerFileNotFoundException('Framework')
|
|
350
|
-
|
|
351
|
-
for data_type in FileDataType.members():
|
|
352
|
-
if data_type not in framework_path_dict:
|
|
353
|
-
logger.warning("Can not find %s file when parse profiler framework file.", data_type)
|
|
354
|
-
continue
|
|
355
|
-
framework_path_dict[data_type].sort()
|
|
356
|
-
|
|
357
|
-
return framework_path_dict
|
|
358
|
-
|
|
359
|
-
def _parse_binary_data(self, framework_path_dict):
|
|
360
|
-
"""Parse binary data in the FILE_DATA_STRUCT_DICT from given files, such as task data, step point data"""
|
|
361
|
-
all_file_data = defaultdict(list)
|
|
362
|
-
for file_data_type, data_struct in FILE_DATA_STRUCT_DICT.items():
|
|
363
|
-
line_size = StructType.sizeof(data_struct.values())
|
|
364
|
-
for path in framework_path_dict[file_data_type]:
|
|
365
|
-
with open(path, 'rb') as file_handler:
|
|
366
|
-
while True:
|
|
367
|
-
binary_data = file_handler.read(line_size)
|
|
368
|
-
if len(binary_data) < line_size:
|
|
369
|
-
break
|
|
370
|
-
line_data = StructType.unpack_binary_data(data_struct, binary_data,
|
|
371
|
-
self._special_process_binary_data)
|
|
372
|
-
all_file_data[file_data_type].append(line_data)
|
|
373
|
-
return all_file_data
|
|
374
|
-
|
|
375
|
-
def _special_process_binary_data(self, item_binary_data, data_name, data_type, unpacked_data):
|
|
376
|
-
"""Specially processes binary data."""
|
|
377
|
-
unpack_data = None
|
|
378
|
-
success = False
|
|
379
|
-
if isinstance(data_type, list):
|
|
380
|
-
if data_name in ('opName', 'opType'):
|
|
381
|
-
unpack_data = self._special_process_mixed_data(item_binary_data)
|
|
382
|
-
elif data_name == 'tensorData':
|
|
383
|
-
tensor_num = unpacked_data['tensorNum']
|
|
384
|
-
unpack_data = self._special_process_tensor_data(item_binary_data, data_type, tensor_num)
|
|
385
|
-
elif data_name == 'tensorNum':
|
|
386
|
-
unpack_data = self._special_process_tensor_num(item_binary_data, data_type)
|
|
387
|
-
else:
|
|
388
|
-
# skip reserve data
|
|
389
|
-
unpack_data = None
|
|
390
|
-
success = True
|
|
391
|
-
return unpack_data, success
|
|
392
|
-
|
|
393
|
-
def _special_process_mixed_data(self, item_binary_data):
|
|
394
|
-
"""Specially processes mixed data, for example, opName and opType"""
|
|
395
|
-
# The first byte is type flag, 0 means data is string, 1 means data is hash value
|
|
396
|
-
cursor = 0
|
|
397
|
-
data_size = len(item_binary_data)
|
|
398
|
-
flag = struct.unpack(StructType.UINT8.value, item_binary_data[cursor:cursor + 1])[0]
|
|
399
|
-
|
|
400
|
-
# skip rsv data, rsv has 7 bytes
|
|
401
|
-
skip_size = 8
|
|
402
|
-
remain_size = data_size - skip_size
|
|
403
|
-
if flag == MSPROF_MIX_DATA_STRING:
|
|
404
|
-
unpack_data = struct.unpack(StructType.CHAR.value * remain_size,
|
|
405
|
-
item_binary_data[cursor + skip_size:cursor + data_size])
|
|
406
|
-
unpack_data = ''.join(list(map(lambda c: c.decode(), filter(lambda c: c != b'\x00', unpack_data))))
|
|
407
|
-
else:
|
|
408
|
-
size = StructType.sizeof(StructType.UINT64) + skip_size
|
|
409
|
-
hash_value = struct.unpack(StructType.UINT64.value,
|
|
410
|
-
item_binary_data[cursor + skip_size:cursor + size])[0]
|
|
411
|
-
unpack_data = self._hash_dict[str(hash_value)]
|
|
412
|
-
return unpack_data
|
|
413
|
-
|
|
414
|
-
def _construct_op_data_to_file(self, task_desc_info, task_id_op_attr_dict):
|
|
415
|
-
"""Build data written to a file."""
|
|
416
|
-
all_op_data = []
|
|
417
|
-
graph_ids = set()
|
|
418
|
-
for task_desc in task_desc_info:
|
|
419
|
-
task_id = task_desc['taskId']
|
|
420
|
-
full_op_name = task_desc['opName']
|
|
421
|
-
subgraph = self._get_subgraph_name(full_op_name)
|
|
422
|
-
combined_task_id = combine_stream_task_id(task_desc['streamId'], task_id)
|
|
423
|
-
op_data = OpData(task_id=task_id,
|
|
424
|
-
stream_id=task_desc['streamId'],
|
|
425
|
-
block_dim=task_desc['blockDims'],
|
|
426
|
-
full_op_name=full_op_name,
|
|
427
|
-
op_name=full_op_name.split('/')[-1],
|
|
428
|
-
op_type=task_desc['opType'],
|
|
429
|
-
subgraph=subgraph,
|
|
430
|
-
op_info=json.dumps(task_id_op_attr_dict.get(combined_task_id, {})),
|
|
431
|
-
graph_id=task_desc['modelId'],
|
|
432
|
-
kernel_type=TASK_TYPE_TO_KERNEL_TYPE.get(task_desc.get('taskType')))
|
|
433
|
-
if not task_desc['opType'].startswith("InitDataSetQueue") and not task_desc['opType'].startswith("GetNext"):
|
|
434
|
-
graph_ids.add(task_desc['modelId'])
|
|
435
|
-
all_op_data.append(op_data)
|
|
436
|
-
ProfilerInfo.set_graph_ids(list(graph_ids))
|
|
437
|
-
return all_op_data
|
|
438
|
-
|
|
439
|
-
|
|
440
50
|
class GpuFrameWorkParser:
|
|
441
51
|
"""
|
|
442
52
|
The parser for parsing framework files.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright 2024 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
|
+
# ============================================================================
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright 2024 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
|
+
"""Function event data struct."""
|
|
16
|
+
import struct
|
|
17
|
+
|
|
18
|
+
from mindspore.profiler.parser.ascend_analysis.constant import Constant
|
|
19
|
+
from mindspore.profiler.parser.ascend_analysis.function_event import MindSporeOpEnum, MindSporeOpEvent
|
|
20
|
+
from mindspore.profiler.parser.gpu_analysis.profiler_info_parser import GPUProfilerInfoParser
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class GPUMindSporeOpEvent(MindSporeOpEvent):
|
|
24
|
+
"""
|
|
25
|
+
Function event collected on the mindspore frame side.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
data(Dict): The mindspore frame side data decoded by TLVDecoder.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def _init_params(self):
|
|
32
|
+
"""Initialize the attribute value of MindSporeOpEvent."""
|
|
33
|
+
fix_size_data = struct.unpack(self._fix_data_format, self._orig_data.get(Constant.FIX_SIZE_BYTES))
|
|
34
|
+
self.pid = Constant.MINDSPORE
|
|
35
|
+
self.tid = int(fix_size_data[MindSporeOpEnum.START_THREAD_ID.value])
|
|
36
|
+
self.name = str(self._orig_data.get(self._tlv_type_dict.get(Constant.OP_NAME), ""))
|
|
37
|
+
self.ts = GPUProfilerInfoParser.get_local_time(fix_size_data[MindSporeOpEnum.START_NS.value]) # unit is us
|
|
38
|
+
self.es = GPUProfilerInfoParser.get_local_time(fix_size_data[MindSporeOpEnum.END_NS.value]) # unit is us
|
|
39
|
+
self.dur = self.es - self.ts
|
|
40
|
+
self.flow_id = int(fix_size_data[MindSporeOpEnum.FLOW_ID.value])
|
|
41
|
+
self.step = int(fix_size_data[MindSporeOpEnum.STEP_ID.value])
|
|
42
|
+
self.level = int(fix_size_data[MindSporeOpEnum.LEVEL.value])
|
|
43
|
+
self.custom_info = ""
|
|
44
|
+
self.args = super()._get_args(fix_size_data)
|