mindspore 2.4.1__cp310-cp310-win_amd64.whl → 2.5.0__cp310-cp310-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 +8 -3
- mindspore/_c_dataengine.cp310-win_amd64.pyd +0 -0
- mindspore/_c_expression.cp310-win_amd64.pyd +0 -0
- mindspore/_c_mindrecord.cp310-win_amd64.pyd +0 -0
- mindspore/_checkparam.py +0 -5
- mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +1 -1
- mindspore/_extends/parse/compile_config.py +64 -0
- mindspore/_extends/parse/deprecated/__init__.py +0 -0
- mindspore/_extends/parse/deprecated/deprecated_tensor_method.py +375 -0
- mindspore/_extends/parse/parser.py +23 -5
- mindspore/_extends/parse/standard_method.py +123 -27
- mindspore/_extends/pijit/pijit_func_white_list.py +1 -1
- mindspore/amp.py +7 -1
- 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/boost/boost_cell_wrapper.py +136 -41
- mindspore/common/__init__.py +3 -1
- mindspore/common/_register_for_tensor.py +0 -1
- mindspore/common/_stub_tensor.py +25 -4
- mindspore/common/_tensor_cpp_method.py +17 -0
- mindspore/common/_tensor_docs.py +6132 -0
- mindspore/common/api.py +99 -25
- mindspore/common/dtype.py +34 -34
- mindspore/common/dump.py +2 -1
- mindspore/common/file_system.py +8 -1
- mindspore/common/generator.py +2 -0
- mindspore/common/hook_handle.py +3 -1
- mindspore/common/initializer.py +3 -4
- mindspore/common/lazy_inline.py +8 -2
- mindspore/common/mindir_util.py +10 -2
- mindspore/common/parameter.py +30 -27
- mindspore/common/tensor.py +713 -1337
- mindspore/communication/__init__.py +1 -1
- mindspore/communication/_comm_helper.py +10 -0
- mindspore/communication/comm_func.py +215 -173
- mindspore/communication/management.py +23 -20
- mindspore/context.py +292 -193
- mindspore/dataset/__init__.py +23 -19
- mindspore/dataset/callback/ds_callback.py +2 -1
- mindspore/dataset/core/config.py +84 -3
- mindspore/dataset/engine/cache_admin.py +3 -3
- mindspore/dataset/engine/cache_client.py +5 -4
- mindspore/dataset/engine/datasets.py +192 -149
- mindspore/dataset/engine/datasets_audio.py +14 -0
- mindspore/dataset/engine/datasets_standard_format.py +28 -11
- mindspore/dataset/engine/datasets_text.py +38 -1
- mindspore/dataset/engine/datasets_user_defined.py +125 -65
- mindspore/dataset/engine/datasets_vision.py +81 -8
- mindspore/dataset/engine/iterators.py +281 -63
- mindspore/dataset/engine/obs/util.py +8 -0
- mindspore/dataset/engine/queue.py +40 -0
- mindspore/dataset/engine/samplers.py +26 -2
- mindspore/dataset/engine/serializer_deserializer.py +1 -1
- mindspore/dataset/engine/validators.py +43 -11
- mindspore/dataset/transforms/py_transforms_util.py +17 -0
- mindspore/dataset/transforms/transforms.py +29 -12
- mindspore/dataset/vision/validators.py +1 -2
- mindspore/device_context/__init__.py +21 -0
- mindspore/device_context/ascend/__init__.py +25 -0
- mindspore/device_context/ascend/device.py +72 -0
- mindspore/device_context/ascend/op_debug.py +94 -0
- mindspore/device_context/ascend/op_precision.py +193 -0
- mindspore/device_context/ascend/op_tuning.py +127 -0
- mindspore/device_context/cpu/__init__.py +25 -0
- mindspore/device_context/cpu/device.py +62 -0
- mindspore/device_context/cpu/op_tuning.py +43 -0
- mindspore/device_context/gpu/__init__.py +21 -0
- mindspore/device_context/gpu/device.py +70 -0
- mindspore/device_context/gpu/op_precision.py +67 -0
- mindspore/device_context/gpu/op_tuning.py +175 -0
- mindspore/device_manager.py +134 -0
- mindspore/dnnl.dll +0 -0
- mindspore/experimental/llm_boost/__init__.py +3 -2
- mindspore/experimental/llm_boost/ascend_native/__init__.py +22 -0
- mindspore/experimental/llm_boost/ascend_native/llama_boost_ascend_native.py +211 -0
- mindspore/experimental/llm_boost/ascend_native/llm_boost.py +52 -0
- mindspore/experimental/llm_boost/atb/boost_base.py +239 -64
- mindspore/experimental/llm_boost/atb/llama_boost.py +52 -30
- mindspore/experimental/llm_boost/atb/qwen_boost.py +47 -24
- mindspore/experimental/llm_boost/register.py +1 -0
- mindspore/experimental/optim/adadelta.py +26 -22
- mindspore/experimental/optim/adam.py +3 -0
- mindspore/experimental/optim/lr_scheduler.py +33 -24
- mindspore/experimental/optim/radam.py +33 -30
- mindspore/hal/device.py +28 -0
- mindspore/hal/event.py +17 -0
- mindspore/hal/memory.py +94 -3
- mindspore/hal/stream.py +91 -6
- mindspore/include/api/context.h +1 -2
- mindspore/include/dataset/constants.h +2 -2
- mindspore/jpeg62.dll +0 -0
- mindspore/log.py +12 -0
- mindspore/mindrecord/__init__.py +1 -1
- mindspore/mindrecord/config.py +17 -316
- mindspore/mindrecord/filereader.py +1 -9
- mindspore/mindrecord/filewriter.py +5 -15
- mindspore/mindrecord/mindpage.py +1 -9
- 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_ops.dll +0 -0
- mindspore/mint/__init__.py +824 -218
- mindspore/mint/distributed/__init__.py +66 -4
- mindspore/mint/distributed/distributed.py +2594 -44
- mindspore/mint/linalg/__init__.py +6 -0
- mindspore/mint/nn/__init__.py +473 -14
- mindspore/mint/nn/functional.py +486 -11
- mindspore/mint/nn/layer/__init__.py +17 -4
- mindspore/mint/nn/layer/_functions.py +330 -0
- mindspore/mint/nn/layer/activation.py +169 -1
- mindspore/mint/nn/layer/basic.py +123 -0
- mindspore/mint/nn/layer/conv.py +727 -0
- mindspore/mint/nn/layer/normalization.py +215 -19
- mindspore/mint/nn/layer/padding.py +797 -0
- mindspore/mint/nn/layer/pooling.py +170 -0
- mindspore/mint/optim/__init__.py +2 -1
- mindspore/mint/optim/adam.py +223 -0
- mindspore/mint/optim/adamw.py +26 -19
- mindspore/mint/special/__init__.py +2 -1
- mindspore/multiprocessing/__init__.py +5 -0
- mindspore/nn/__init__.py +2 -0
- mindspore/nn/cell.py +142 -21
- mindspore/nn/dynamic_lr.py +2 -1
- mindspore/nn/layer/activation.py +6 -6
- mindspore/nn/layer/basic.py +35 -25
- mindspore/nn/layer/channel_shuffle.py +3 -3
- mindspore/nn/layer/conv.py +3 -0
- mindspore/nn/layer/embedding.py +3 -3
- mindspore/nn/layer/normalization.py +8 -7
- mindspore/nn/layer/padding.py +4 -3
- mindspore/nn/layer/pooling.py +55 -23
- mindspore/nn/layer/rnn_cells.py +1 -1
- mindspore/nn/layer/rnns.py +2 -1
- mindspore/nn/layer/timedistributed.py +5 -5
- mindspore/nn/layer/transformer.py +48 -26
- mindspore/nn/learning_rate_schedule.py +5 -3
- mindspore/nn/loss/loss.py +31 -36
- mindspore/nn/optim/ada_grad.py +1 -0
- mindspore/nn/optim/adadelta.py +2 -2
- mindspore/nn/optim/adam.py +1 -1
- mindspore/nn/optim/lars.py +1 -4
- mindspore/nn/optim/optimizer.py +1 -1
- mindspore/nn/optim/rprop.py +2 -2
- mindspore/nn/optim/thor.py +2 -1
- mindspore/nn/utils/__init__.py +22 -0
- mindspore/nn/utils/init.py +73 -0
- mindspore/nn/wrap/cell_wrapper.py +4 -6
- mindspore/nn/wrap/loss_scale.py +3 -4
- mindspore/numpy/array_creations.py +60 -62
- mindspore/numpy/array_ops.py +148 -143
- mindspore/numpy/logic_ops.py +41 -42
- mindspore/numpy/math_ops.py +361 -359
- mindspore/numpy/utils.py +16 -16
- 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 +2 -1
- mindspore/ops/_grad_experimental/grad_comm_ops.py +107 -8
- mindspore/ops/_grad_experimental/grad_debug_ops.py +6 -1
- mindspore/ops/_grad_experimental/grad_inner_ops.py +9 -0
- mindspore/ops/_grad_experimental/grad_math_ops.py +2 -1
- mindspore/ops/_op_impl/cpu/__init__.py +1 -0
- mindspore/ops/_op_impl/cpu/raise_op.py +28 -0
- mindspore/ops/_vmap/vmap_array_ops.py +20 -19
- mindspore/ops/_vmap/vmap_base.py +0 -2
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +19 -13
- mindspore/ops/_vmap/vmap_math_ops.py +11 -9
- mindspore/ops/_vmap/vmap_nn_ops.py +20 -34
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +149 -12
- mindspore/ops/auto_generate/gen_arg_handler.py +0 -61
- mindspore/ops/auto_generate/gen_extend_func.py +554 -60
- mindspore/ops/auto_generate/gen_ops_def.py +1621 -115
- mindspore/ops/auto_generate/gen_ops_prim.py +8027 -3411
- mindspore/ops/auto_generate/pyboost_inner_prim.py +183 -79
- mindspore/ops/composite/base.py +1 -1
- mindspore/ops/composite/multitype_ops/_compile_utils.py +229 -30
- mindspore/ops/composite/multitype_ops/pow_impl.py +0 -29
- mindspore/ops/function/__init__.py +12 -0
- mindspore/ops/function/array_func.py +561 -159
- mindspore/ops/function/clip_func.py +64 -0
- mindspore/ops/function/debug_func.py +28 -20
- mindspore/ops/function/image_func.py +1 -1
- mindspore/ops/function/linalg_func.py +5 -4
- mindspore/ops/function/math_func.py +1664 -294
- mindspore/ops/function/nn_func.py +988 -317
- mindspore/ops/function/parameter_func.py +3 -56
- mindspore/ops/function/random_func.py +243 -33
- mindspore/ops/function/sparse_unary_func.py +1 -1
- mindspore/ops/functional.py +18 -5
- mindspore/ops/functional_overload.py +897 -0
- mindspore/ops/operations/__init__.py +3 -2
- mindspore/ops/operations/_embedding_cache_ops.py +4 -4
- mindspore/ops/operations/_grad_ops.py +2 -34
- mindspore/ops/operations/_infer_ops.py +2 -1
- mindspore/ops/operations/_inner_ops.py +38 -8
- mindspore/ops/operations/array_ops.py +45 -303
- mindspore/ops/operations/comm_ops.py +23 -17
- mindspore/ops/operations/custom_ops.py +7 -49
- mindspore/ops/operations/debug_ops.py +42 -47
- mindspore/ops/operations/inner_ops.py +6 -4
- mindspore/ops/operations/linalg_ops.py +3 -2
- mindspore/ops/operations/manually_defined/ops_def.py +185 -104
- mindspore/ops/operations/math_ops.py +11 -216
- mindspore/ops/operations/nn_ops.py +153 -310
- mindspore/ops/primitive.py +23 -21
- mindspore/ops/tensor_method.py +1669 -0
- mindspore/ops_generate/aclnn_kernel_register_auto_cc_generator.py +110 -0
- mindspore/ops_generate/add_tensor_docs_generator.py +54 -0
- mindspore/ops_generate/arg_handler.py +0 -61
- mindspore/ops_generate/auto_grad_impl_cc_generator.py +135 -0
- mindspore/ops_generate/auto_grad_reg_cc_generator.py +93 -0
- mindspore/ops_generate/base_generator.py +11 -0
- mindspore/ops_generate/cpp_create_prim_instance_helper_generator.py +108 -0
- mindspore/ops_generate/functional_map_cpp_generator.py +491 -0
- mindspore/ops_generate/functional_overload_py_generator.py +110 -0
- mindspore/ops_generate/functions_cc_generator.py +233 -0
- mindspore/ops_generate/gen_aclnn_implement.py +110 -114
- mindspore/ops_generate/gen_constants.py +157 -3
- mindspore/ops_generate/gen_ops.py +245 -990
- mindspore/ops_generate/gen_pyboost_func.py +97 -998
- mindspore/ops_generate/gen_utils.py +119 -33
- mindspore/ops_generate/lite_ops_cpp_generator.py +155 -0
- mindspore/ops_generate/op_api_proto.py +206 -0
- mindspore/ops_generate/op_def_py_generator.py +131 -0
- mindspore/ops_generate/op_prim_py_generator.py +480 -0
- mindspore/ops_generate/op_proto.py +373 -108
- mindspore/ops_generate/op_template_parser.py +436 -0
- mindspore/ops_generate/ops_def_cc_generator.py +288 -0
- mindspore/ops_generate/ops_def_h_generator.py +74 -0
- mindspore/ops_generate/ops_name_h_generator.py +68 -0
- mindspore/ops_generate/ops_primitive_h_generator.py +81 -0
- mindspore/ops_generate/pyboost_functions_cpp_generator.py +370 -0
- mindspore/ops_generate/pyboost_functions_h_generator.py +68 -0
- mindspore/ops_generate/pyboost_functions_py_generator.py +148 -0
- mindspore/ops_generate/pyboost_grad_function_cpp_generator.py +154 -0
- mindspore/ops_generate/pyboost_inner_prim_generator.py +131 -0
- mindspore/ops_generate/pyboost_native_grad_functions_generator.py +268 -0
- mindspore/ops_generate/pyboost_op_cpp_code_generator.py +851 -0
- mindspore/ops_generate/pyboost_overload_functions_cpp_generator.py +344 -0
- mindspore/ops_generate/pyboost_utils.py +92 -33
- mindspore/ops_generate/template.py +294 -44
- mindspore/ops_generate/tensor_func_reg_cpp_generator.py +422 -0
- mindspore/parallel/__init__.py +3 -3
- mindspore/parallel/_auto_parallel_context.py +44 -34
- mindspore/parallel/_cell_wrapper.py +22 -3
- mindspore/parallel/_parallel_serialization.py +13 -2
- mindspore/parallel/_utils.py +4 -2
- mindspore/parallel/algo_parameter_config.py +1 -1
- mindspore/parallel/checkpoint_transform.py +44 -0
- mindspore/parallel/cluster/process_entity/_api.py +131 -37
- mindspore/parallel/cluster/process_entity/_utils.py +41 -6
- mindspore/parallel/cluster/run.py +20 -3
- mindspore/parallel/parameter_broadcast.py +1 -1
- mindspore/parallel/shard.py +3 -0
- mindspore/parallel/transform_safetensors.py +119 -253
- mindspore/profiler/__init__.py +17 -4
- mindspore/profiler/analysis/__init__.py +0 -0
- mindspore/profiler/analysis/parser/__init__.py +0 -0
- mindspore/profiler/analysis/parser/ascend_cann_parser.py +166 -0
- mindspore/profiler/analysis/parser/base_parser.py +158 -0
- mindspore/profiler/analysis/parser/framework_cann_relation_parser.py +45 -0
- mindspore/profiler/analysis/parser/ms_framework_parser.py +142 -0
- mindspore/profiler/analysis/parser/ms_minddata_parser.py +145 -0
- mindspore/profiler/analysis/parser/timeline_assembly_factory/__init__.py +0 -0
- mindspore/profiler/analysis/parser/timeline_assembly_factory/ascend_timeline_assembler.py +261 -0
- mindspore/profiler/analysis/parser/timeline_assembly_factory/base_timeline_assembler.py +40 -0
- mindspore/profiler/analysis/parser/timeline_assembly_factory/trace_view_container.py +84 -0
- mindspore/profiler/analysis/parser/timeline_creator/__init__.py +0 -0
- mindspore/profiler/analysis/parser/timeline_creator/base_timeline_creator.py +44 -0
- mindspore/profiler/analysis/parser/timeline_creator/cpu_op_timeline_creator.py +90 -0
- mindspore/profiler/analysis/parser/timeline_creator/fwk_timeline_creator.py +76 -0
- mindspore/profiler/analysis/parser/timeline_creator/msprof_timeline_creator.py +103 -0
- mindspore/profiler/analysis/parser/timeline_creator/scope_layer_timeline_creator.py +134 -0
- mindspore/profiler/analysis/parser/timeline_event/__init__.py +0 -0
- mindspore/profiler/analysis/parser/timeline_event/base_event.py +233 -0
- mindspore/profiler/analysis/parser/timeline_event/cpu_op_event.py +47 -0
- mindspore/profiler/analysis/parser/timeline_event/flow_event.py +36 -0
- mindspore/profiler/analysis/parser/timeline_event/fwk_event.py +260 -0
- mindspore/profiler/analysis/parser/timeline_event/msprof_event.py +73 -0
- mindspore/profiler/analysis/parser/timeline_event/scope_layer_event.py +53 -0
- mindspore/profiler/analysis/parser/timeline_event/timeline_event_pool.py +146 -0
- mindspore/profiler/analysis/task_manager.py +131 -0
- mindspore/profiler/analysis/time_converter.py +84 -0
- mindspore/profiler/analysis/viewer/__init__.py +0 -0
- mindspore/profiler/analysis/viewer/ascend_communication_viewer.py +333 -0
- mindspore/profiler/analysis/viewer/ascend_integrate_viewer.py +87 -0
- mindspore/profiler/analysis/viewer/ascend_kernel_details_viewer.py +252 -0
- mindspore/profiler/analysis/viewer/ascend_memory_viewer.py +313 -0
- mindspore/profiler/analysis/viewer/ascend_op_memory_viewer.py +322 -0
- mindspore/profiler/analysis/viewer/ascend_step_trace_time_viewer.py +265 -0
- mindspore/profiler/analysis/viewer/ascend_timeline_viewer.py +58 -0
- mindspore/profiler/analysis/viewer/base_viewer.py +26 -0
- mindspore/profiler/analysis/viewer/ms_dataset_viewer.py +97 -0
- mindspore/profiler/analysis/viewer/ms_minddata_viewer.py +581 -0
- mindspore/profiler/analysis/work_flow.py +73 -0
- mindspore/profiler/common/ascend_msprof_exporter.py +138 -0
- mindspore/profiler/common/command_executor.py +90 -0
- mindspore/profiler/common/constant.py +174 -3
- mindspore/profiler/common/file_manager.py +208 -0
- mindspore/profiler/common/log.py +130 -0
- mindspore/profiler/common/msprof_cmd_tool.py +202 -0
- mindspore/profiler/common/path_manager.py +371 -0
- mindspore/profiler/common/process_bar.py +168 -0
- mindspore/profiler/common/process_pool.py +9 -3
- mindspore/profiler/common/profiler_context.py +476 -0
- mindspore/profiler/common/profiler_info.py +304 -0
- mindspore/profiler/common/profiler_output_path.py +284 -0
- mindspore/profiler/common/profiler_parameters.py +210 -0
- mindspore/profiler/common/profiler_path_manager.py +120 -0
- mindspore/profiler/common/record_function.py +76 -0
- mindspore/profiler/common/tlv_decoder.py +76 -0
- mindspore/profiler/common/util.py +75 -2
- mindspore/profiler/dynamic_profiler.py +270 -37
- mindspore/profiler/envprofiler.py +138 -0
- mindspore/profiler/mstx.py +199 -0
- mindspore/profiler/platform/__init__.py +21 -0
- mindspore/profiler/platform/base_profiler.py +40 -0
- mindspore/profiler/platform/cpu_profiler.py +124 -0
- mindspore/profiler/platform/gpu_profiler.py +74 -0
- mindspore/profiler/platform/npu_profiler.py +309 -0
- mindspore/profiler/profiler.py +580 -93
- mindspore/profiler/profiler_action_controller.py +187 -0
- mindspore/profiler/profiler_interface.py +114 -0
- mindspore/profiler/schedule.py +208 -0
- mindspore/rewrite/api/symbol_tree.py +1 -2
- mindspore/run_check/_check_version.py +18 -13
- mindspore/runtime/__init__.py +37 -0
- mindspore/runtime/device.py +27 -0
- mindspore/runtime/event.py +209 -0
- mindspore/runtime/executor.py +148 -0
- mindspore/runtime/memory.py +392 -0
- mindspore/runtime/stream.py +460 -0
- mindspore/runtime/thread_bind_core.py +401 -0
- mindspore/swresample-4.dll +0 -0
- mindspore/swscale-6.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/__init__.py +2 -2
- mindspore/train/_utils.py +53 -18
- mindspore/train/amp.py +8 -4
- mindspore/train/callback/_checkpoint.py +32 -18
- mindspore/train/callback/_early_stop.py +1 -1
- mindspore/train/callback/_flops_collector.py +105 -69
- mindspore/train/callback/_history.py +1 -1
- mindspore/train/callback/_summary_collector.py +44 -6
- mindspore/train/callback/_tft_register.py +37 -15
- mindspore/train/dataset_helper.py +11 -11
- mindspore/train/metrics/precision.py +4 -5
- mindspore/train/mind_ir_pb2.py +167 -46
- mindspore/train/model.py +13 -14
- mindspore/train/serialization.py +461 -72
- mindspore/train/summary/summary_record.py +1 -2
- mindspore/train/train_thor/model_thor.py +1 -1
- mindspore/turbojpeg.dll +0 -0
- mindspore/utils/__init__.py +4 -2
- mindspore/utils/dryrun.py +138 -0
- mindspore/utils/runtime_execution_order_check.py +550 -0
- mindspore/version.py +1 -1
- {mindspore-2.4.1.dist-info → mindspore-2.5.0.dist-info}/METADATA +3 -4
- {mindspore-2.4.1.dist-info → mindspore-2.5.0.dist-info}/RECORD +368 -242
- {mindspore-2.4.1.dist-info → mindspore-2.5.0.dist-info}/entry_points.txt +1 -1
- mindspore/common/_tensor_overload.py +0 -139
- mindspore/mindspore_np_dtype.dll +0 -0
- mindspore/profiler/envprofiling.py +0 -254
- mindspore/profiler/profiling.py +0 -1926
- {mindspore-2.4.1.dist-info → mindspore-2.5.0.dist-info}/WHEEL +0 -0
- {mindspore-2.4.1.dist-info → mindspore-2.5.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,260 @@
|
|
|
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
|
+
"""Framework event classes for timeline analysis."""
|
|
16
|
+
from enum import Enum
|
|
17
|
+
from decimal import Decimal
|
|
18
|
+
from typing import Dict, Optional, List, Tuple
|
|
19
|
+
|
|
20
|
+
from mindspore.profiler.common.constant import EventConstant, FileConstant
|
|
21
|
+
from mindspore.profiler.analysis.time_converter import TimeConverter
|
|
22
|
+
from mindspore.profiler.analysis.parser.timeline_event.base_event import (
|
|
23
|
+
BaseEvent,
|
|
24
|
+
CompleteEvent,
|
|
25
|
+
MetaEvent,
|
|
26
|
+
InstantEvent
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class FwkFixSizeFormat:
|
|
31
|
+
"""Format definition for framework fixed-size data."""
|
|
32
|
+
|
|
33
|
+
# Fixed size data format: 3 long long (q) + 6 unsigned long long (Q) + bool (?) + padding (b)
|
|
34
|
+
OpRangeStruct = "<3q6Qb?"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class OpRangeStructField(Enum):
|
|
38
|
+
"""Field indices in operator range structure fixed-size data."""
|
|
39
|
+
START_NS = 0
|
|
40
|
+
END_NS = 1
|
|
41
|
+
SEQUENCE_NUMBER = 2
|
|
42
|
+
PROCESS_ID = 3
|
|
43
|
+
START_THREAD_ID = 4
|
|
44
|
+
END_THREAD_ID = 5
|
|
45
|
+
FORWARD_THREAD_ID = 6
|
|
46
|
+
ID = 7
|
|
47
|
+
STEP_ID = 8
|
|
48
|
+
LEVEL = 9
|
|
49
|
+
IS_ASYNC = 10
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class FwkArgsDecoder:
|
|
53
|
+
"""Decoder for framework event arguments in TLV (Type-Length-Value) format."""
|
|
54
|
+
TLV_TYPES = {
|
|
55
|
+
EventConstant.OP_NAME: 3,
|
|
56
|
+
EventConstant.INPUT_SHAPES: 5,
|
|
57
|
+
EventConstant.INPUT_DTYPES: 4,
|
|
58
|
+
EventConstant.CALL_STACK: 6,
|
|
59
|
+
EventConstant.MODULE_HIERARCHY: 7,
|
|
60
|
+
EventConstant.FLOPS: 8,
|
|
61
|
+
EventConstant.CUSTOM_INFO: 9
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
def decode(cls, origin_data: Dict, fix_size_data: Tuple) -> Dict:
|
|
66
|
+
"""Decode event arguments from raw data."""
|
|
67
|
+
args = {
|
|
68
|
+
EventConstant.SEQUENCE_NUMBER: int(fix_size_data[OpRangeStructField.SEQUENCE_NUMBER.value]),
|
|
69
|
+
EventConstant.FORWARD_THREAD_ID: int(fix_size_data[OpRangeStructField.FORWARD_THREAD_ID.value])
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for field_name, type_id in cls.TLV_TYPES.items():
|
|
73
|
+
if field_name == EventConstant.OP_NAME or type_id not in origin_data:
|
|
74
|
+
continue
|
|
75
|
+
value = origin_data.get(type_id)
|
|
76
|
+
if field_name in {EventConstant.INPUT_SHAPES, EventConstant.INPUT_DTYPES, EventConstant.CALL_STACK}:
|
|
77
|
+
args[field_name] = value.replace("|", "\r\n")
|
|
78
|
+
elif field_name == EventConstant.CUSTOM_INFO and value:
|
|
79
|
+
pairs = [pair.split(':') for pair in value.split(';') if pair]
|
|
80
|
+
info_dict = {k: v for k, v in pairs[0:2] if len(pairs) >= 2}
|
|
81
|
+
args[field_name] = info_dict
|
|
82
|
+
else:
|
|
83
|
+
args[field_name] = value
|
|
84
|
+
|
|
85
|
+
return args
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class FwkCompleteEvent(CompleteEvent):
|
|
89
|
+
"""Framework complete event with duration."""
|
|
90
|
+
_args_decoder = FwkArgsDecoder()
|
|
91
|
+
|
|
92
|
+
def __init__(self, data: Dict):
|
|
93
|
+
"""Initialize framework complete event."""
|
|
94
|
+
super().__init__(data)
|
|
95
|
+
self.fix_size_data = self._origin_data[FileConstant.FIX_SIZE_DATA]
|
|
96
|
+
self._ts_cache = None
|
|
97
|
+
self._te_cache = None
|
|
98
|
+
self._dur_cache = None
|
|
99
|
+
self._args_cache = {}
|
|
100
|
+
self._parent: Optional[BaseEvent] = None
|
|
101
|
+
self._children: List[BaseEvent] = []
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def parent(self) -> BaseEvent:
|
|
105
|
+
"""Get parent event."""
|
|
106
|
+
return self._parent
|
|
107
|
+
|
|
108
|
+
@parent.setter
|
|
109
|
+
def parent(self, event: BaseEvent) -> None:
|
|
110
|
+
"""Set parent event."""
|
|
111
|
+
self._parent = event
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def children(self) -> List[BaseEvent]:
|
|
115
|
+
"""Get child events."""
|
|
116
|
+
return self._children
|
|
117
|
+
|
|
118
|
+
@property
|
|
119
|
+
def ts_raw(self) -> int:
|
|
120
|
+
"""Get raw start timestamp."""
|
|
121
|
+
return self.fix_size_data[OpRangeStructField.START_NS.value]
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def ts(self) -> Decimal:
|
|
125
|
+
"""Get start time in us."""
|
|
126
|
+
if not self._ts_cache:
|
|
127
|
+
self._ts_cache = TimeConverter.convert_syscnt_to_timestamp_us(
|
|
128
|
+
self.fix_size_data[OpRangeStructField.START_NS.value]
|
|
129
|
+
)
|
|
130
|
+
return self._ts_cache
|
|
131
|
+
|
|
132
|
+
@property
|
|
133
|
+
def te(self) -> Decimal:
|
|
134
|
+
"""Get end time in us."""
|
|
135
|
+
if not self._te_cache:
|
|
136
|
+
self._te_cache = TimeConverter.convert_syscnt_to_timestamp_us(
|
|
137
|
+
self.fix_size_data[OpRangeStructField.END_NS.value]
|
|
138
|
+
)
|
|
139
|
+
return self._te_cache
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def dur(self) -> Decimal:
|
|
143
|
+
"""Get duration in us."""
|
|
144
|
+
if not self._dur_cache:
|
|
145
|
+
self._dur_cache = self.te - self.ts
|
|
146
|
+
return self._dur_cache
|
|
147
|
+
|
|
148
|
+
@property
|
|
149
|
+
def pid(self) -> int:
|
|
150
|
+
"""Get process ID."""
|
|
151
|
+
return int(EventConstant.MINDSPORE_PID)
|
|
152
|
+
|
|
153
|
+
@property
|
|
154
|
+
def tid(self) -> int:
|
|
155
|
+
"""Get thread ID."""
|
|
156
|
+
return int(self.fix_size_data[OpRangeStructField.START_THREAD_ID.value])
|
|
157
|
+
|
|
158
|
+
@property
|
|
159
|
+
def id(self) -> int:
|
|
160
|
+
"""Get event ID."""
|
|
161
|
+
return int(self.fix_size_data[OpRangeStructField.ID.value])
|
|
162
|
+
|
|
163
|
+
@property
|
|
164
|
+
def name(self) -> str:
|
|
165
|
+
"""Get operator name."""
|
|
166
|
+
return str(self._origin_data.get(self._args_decoder.TLV_TYPES.get(EventConstant.OP_NAME), ""))
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def step(self) -> int:
|
|
170
|
+
"""Get step ID."""
|
|
171
|
+
return int(self.fix_size_data[OpRangeStructField.STEP_ID.value])
|
|
172
|
+
|
|
173
|
+
@property
|
|
174
|
+
def level(self) -> int:
|
|
175
|
+
"""Get event level."""
|
|
176
|
+
return int(self.fix_size_data[OpRangeStructField.LEVEL.value])
|
|
177
|
+
|
|
178
|
+
@property
|
|
179
|
+
def args(self) -> Dict:
|
|
180
|
+
"""Get decoded event arguments."""
|
|
181
|
+
if not self._args_cache:
|
|
182
|
+
self._args_cache = self._args_decoder.decode(self._origin_data, self.fix_size_data)
|
|
183
|
+
return self._args_cache
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def custom_info(self) -> str:
|
|
187
|
+
"""Get custom information."""
|
|
188
|
+
return str(self.args.get(EventConstant.CUSTOM_INFO, ''))
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class FwkInstantEvent(InstantEvent):
|
|
192
|
+
"""Framework instant event without duration."""
|
|
193
|
+
_args_decoder = FwkArgsDecoder()
|
|
194
|
+
|
|
195
|
+
def __init__(self, data: Dict):
|
|
196
|
+
"""Initialize framework instant event."""
|
|
197
|
+
super().__init__(data)
|
|
198
|
+
self.fix_size_data = self._origin_data[FileConstant.FIX_SIZE_DATA]
|
|
199
|
+
self._ts_cache = None
|
|
200
|
+
self._args_cache = {}
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def ts_raw(self) -> int:
|
|
204
|
+
"""Get raw start timestamp."""
|
|
205
|
+
return self.fix_size_data[OpRangeStructField.START_NS.value]
|
|
206
|
+
|
|
207
|
+
@property
|
|
208
|
+
def ts(self) -> Decimal:
|
|
209
|
+
"""Get time in us."""
|
|
210
|
+
if not self._ts_cache:
|
|
211
|
+
self._ts_cache = TimeConverter.convert_syscnt_to_timestamp_us(
|
|
212
|
+
self.fix_size_data[OpRangeStructField.START_NS.value]
|
|
213
|
+
)
|
|
214
|
+
return self._ts_cache
|
|
215
|
+
|
|
216
|
+
@property
|
|
217
|
+
def pid(self) -> int:
|
|
218
|
+
"""Get process ID."""
|
|
219
|
+
return int(EventConstant.MINDSPORE_PID)
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def tid(self) -> int:
|
|
223
|
+
"""Get thread ID."""
|
|
224
|
+
return int(self.fix_size_data[OpRangeStructField.START_THREAD_ID.value])
|
|
225
|
+
|
|
226
|
+
@property
|
|
227
|
+
def name(self) -> str:
|
|
228
|
+
"""Get operator name."""
|
|
229
|
+
return str(self._origin_data.get(self._args_decoder.TLV_TYPES.get(EventConstant.OP_NAME), ""))
|
|
230
|
+
|
|
231
|
+
@property
|
|
232
|
+
def step(self) -> int:
|
|
233
|
+
"""Get step ID."""
|
|
234
|
+
return int(self.fix_size_data[OpRangeStructField.STEP_ID.value])
|
|
235
|
+
|
|
236
|
+
@property
|
|
237
|
+
def level(self) -> int:
|
|
238
|
+
"""Get event level."""
|
|
239
|
+
return int(self.fix_size_data[OpRangeStructField.LEVEL.value])
|
|
240
|
+
|
|
241
|
+
@property
|
|
242
|
+
def args(self) -> Dict:
|
|
243
|
+
"""Get decoded event arguments."""
|
|
244
|
+
if not self._args_cache:
|
|
245
|
+
self._args_cache = self._args_decoder.decode(self._origin_data, self.fix_size_data)
|
|
246
|
+
return self._args_cache
|
|
247
|
+
|
|
248
|
+
@property
|
|
249
|
+
def custom_info(self) -> str:
|
|
250
|
+
"""Get custom information."""
|
|
251
|
+
return str(self.args.get(EventConstant.CUSTOM_INFO, ''))
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
class FwkMetaEvent(MetaEvent):
|
|
255
|
+
"""Framework metadata event."""
|
|
256
|
+
|
|
257
|
+
@property
|
|
258
|
+
def pid(self) -> int:
|
|
259
|
+
"""Get framework process ID."""
|
|
260
|
+
return int(EventConstant.MINDSPORE_PID)
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
"""Msprof event classes for MindSpore profiling data."""
|
|
16
|
+
|
|
17
|
+
from typing import Dict, List, Optional
|
|
18
|
+
from mindspore.profiler.analysis.parser.timeline_event.base_event import (
|
|
19
|
+
BaseEvent,
|
|
20
|
+
MetaEvent,
|
|
21
|
+
InstantEvent,
|
|
22
|
+
CompleteEvent,
|
|
23
|
+
CounterEvent
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class MsprofCompleteEvent(CompleteEvent):
|
|
28
|
+
"""Msprof Complete event class for representing complete operations with duration."""
|
|
29
|
+
_MINDSPORE_OP_KEY = "mindspore_op"
|
|
30
|
+
|
|
31
|
+
def __init__(self, data: Dict):
|
|
32
|
+
"""Initialize complete event with data and empty event references."""
|
|
33
|
+
super().__init__(data)
|
|
34
|
+
self._parent: Optional[BaseEvent] = None
|
|
35
|
+
self._children: List[BaseEvent] = []
|
|
36
|
+
self._step_id = None
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def parent(self) -> BaseEvent:
|
|
40
|
+
"""Get parent event reference."""
|
|
41
|
+
return self._parent
|
|
42
|
+
|
|
43
|
+
@parent.setter
|
|
44
|
+
def parent(self, event: BaseEvent) -> None:
|
|
45
|
+
"""Set parent event and update mindspore_op argument."""
|
|
46
|
+
self._parent = event
|
|
47
|
+
self.args.update({self._MINDSPORE_OP_KEY: event.name})
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def children(self) -> List[BaseEvent]:
|
|
51
|
+
"""Get list of children event references."""
|
|
52
|
+
return self._children
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def step_id(self) -> str:
|
|
56
|
+
"""Get parent event reference."""
|
|
57
|
+
return self._step_id
|
|
58
|
+
|
|
59
|
+
@step_id.setter
|
|
60
|
+
def step_id(self, value):
|
|
61
|
+
self._step_id = value
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class MsprofInstantEvent(InstantEvent):
|
|
65
|
+
"""Msprof Instant event class for representing instantaneous operations."""
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class MsprofMetaEvent(MetaEvent):
|
|
69
|
+
"""Msprof Meta event class for representing metadata information."""
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class MsprofCounterEvent(CounterEvent):
|
|
73
|
+
"""Msprof Counter event class for representing counter-based metrics."""
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
"""Scope event class for representing scope layer operations in profiling data."""
|
|
16
|
+
|
|
17
|
+
from decimal import Decimal
|
|
18
|
+
|
|
19
|
+
from mindspore.profiler.common.constant import EventConstant
|
|
20
|
+
from mindspore.profiler.analysis.parser.timeline_event.base_event import CompleteEvent, MetaEvent
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ScopeLayerCompleteEvent(CompleteEvent):
|
|
24
|
+
"""Scope layer complete event class for representing scope operations with duration."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, data: dict):
|
|
27
|
+
"""Initialize scope layer event with data and duration."""
|
|
28
|
+
super().__init__(data)
|
|
29
|
+
self._dur = Decimal(data.get('dur', 0))
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def dur(self) -> Decimal:
|
|
33
|
+
"""Get scope operation duration."""
|
|
34
|
+
return self._dur
|
|
35
|
+
|
|
36
|
+
@dur.setter
|
|
37
|
+
def dur(self, value: Decimal):
|
|
38
|
+
"""Set scope operation duration."""
|
|
39
|
+
self._dur = value
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def pid(self) -> int:
|
|
43
|
+
"""Get scope layer process ID."""
|
|
44
|
+
return int(EventConstant.SCOPE_LAYER_PID)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ScopeLayerMetaEvent(MetaEvent):
|
|
48
|
+
"""Scope layer meta event class for scope layer metadata."""
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def pid(self) -> int:
|
|
52
|
+
"""Get scope layer process ID."""
|
|
53
|
+
return int(EventConstant.SCOPE_LAYER_PID)
|
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
"""Timeline event pool for managing and categorizing events."""
|
|
16
|
+
from typing import Dict, List, Set
|
|
17
|
+
from collections import defaultdict
|
|
18
|
+
|
|
19
|
+
from mindspore.profiler.common.constant import EventConstant
|
|
20
|
+
from mindspore.profiler.analysis.parser.timeline_event.base_event import (
|
|
21
|
+
BaseEvent,
|
|
22
|
+
MetaEvent,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TimelineEventPool:
|
|
27
|
+
"""A container class that manages and categorizes events within a specific timeline lane (process).
|
|
28
|
+
|
|
29
|
+
This class is responsible for:
|
|
30
|
+
1. Storing and categorizing different types of events (complete, instant, counter, meta) by thread ID
|
|
31
|
+
2. Managing timeline connection events within the same process
|
|
32
|
+
3. Providing event indexing capabilities by thread ID or thread name
|
|
33
|
+
4. Maintaining thread name mappings for the process
|
|
34
|
+
|
|
35
|
+
Note:
|
|
36
|
+
This class only handles runtime events, offline events are managed separately.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self, pid):
|
|
40
|
+
# process ID
|
|
41
|
+
self.pid = pid
|
|
42
|
+
self.name = ""
|
|
43
|
+
# Event storage by phase
|
|
44
|
+
self.complete_event: Dict[int, List[BaseEvent]] = defaultdict(list)
|
|
45
|
+
self.instance_event: Dict[int, List[BaseEvent]] = defaultdict(list)
|
|
46
|
+
self.counter_event: Dict[int, List[BaseEvent]] = defaultdict(list)
|
|
47
|
+
self.meta_event: List[BaseEvent] = []
|
|
48
|
+
# Store start/end events for timeline connections
|
|
49
|
+
self.start_to_end_events_pairs: Dict[str, Dict[str, List[BaseEvent]]] = {}
|
|
50
|
+
# Thread mappings
|
|
51
|
+
self.tid_to_name: Dict[int, str] = {}
|
|
52
|
+
self.name_to_tid: Dict[str, int] = {}
|
|
53
|
+
|
|
54
|
+
def add_event(self, event: BaseEvent) -> None:
|
|
55
|
+
"""Add event to timeline based on its phase type."""
|
|
56
|
+
if event.ph == EventConstant.COMPLETE_EVENT:
|
|
57
|
+
self.complete_event[event.tid].append(event)
|
|
58
|
+
elif event.ph == EventConstant.INSTANT_EVENT:
|
|
59
|
+
self.instance_event[event.tid].append(event)
|
|
60
|
+
elif event.ph == EventConstant.COUNTER_EVENT:
|
|
61
|
+
self.counter_event[event.tid].append(event)
|
|
62
|
+
elif event.ph == EventConstant.META_EVENT:
|
|
63
|
+
self.meta_event.append(event)
|
|
64
|
+
self._handle_meta_event(event)
|
|
65
|
+
|
|
66
|
+
def _handle_meta_event(self, event: MetaEvent) -> None:
|
|
67
|
+
"""Update process and thread mappings from meta event."""
|
|
68
|
+
if event.name == EventConstant.PROCESS_NAME:
|
|
69
|
+
self.name = event.args.get("name", "")
|
|
70
|
+
elif event.name == EventConstant.THREAD_NAME:
|
|
71
|
+
tid = event.tid
|
|
72
|
+
thread_name = event.args.get("name", "")
|
|
73
|
+
if tid is not None and thread_name:
|
|
74
|
+
self.tid_to_name[tid] = thread_name
|
|
75
|
+
self.name_to_tid[thread_name] = tid
|
|
76
|
+
|
|
77
|
+
def add_start_event(self, flow_key: str, event: BaseEvent) -> None:
|
|
78
|
+
"""Add start event for timeline connection."""
|
|
79
|
+
if flow_key not in self.start_to_end_events_pairs:
|
|
80
|
+
self.start_to_end_events_pairs[flow_key] = {"start": [], "end": []}
|
|
81
|
+
self.start_to_end_events_pairs[flow_key]["start"].append(event)
|
|
82
|
+
|
|
83
|
+
def add_end_event(self, flow_key: str, event: BaseEvent) -> None:
|
|
84
|
+
"""Add end event for timeline connection."""
|
|
85
|
+
if flow_key not in self.start_to_end_events_pairs:
|
|
86
|
+
self.start_to_end_events_pairs[flow_key] = {"start": [], "end": []}
|
|
87
|
+
self.start_to_end_events_pairs[flow_key]["end"].append(event)
|
|
88
|
+
|
|
89
|
+
def _get_events(self, event_dict: dict) -> List[BaseEvent]:
|
|
90
|
+
"""Helper function to get events from a dictionary."""
|
|
91
|
+
events = []
|
|
92
|
+
for event_list in event_dict.values():
|
|
93
|
+
events.extend(event_list)
|
|
94
|
+
return events
|
|
95
|
+
|
|
96
|
+
def get_complete_events(self) -> List[BaseEvent]:
|
|
97
|
+
"""Get all complete events."""
|
|
98
|
+
return self._get_events(self.complete_event)
|
|
99
|
+
|
|
100
|
+
def get_instant_events(self) -> List[BaseEvent]:
|
|
101
|
+
"""Get all instant events."""
|
|
102
|
+
return self._get_events(self.instance_event)
|
|
103
|
+
|
|
104
|
+
def get_counter_events(self) -> List[BaseEvent]:
|
|
105
|
+
"""Get all counter events."""
|
|
106
|
+
return self._get_events(self.counter_event)
|
|
107
|
+
|
|
108
|
+
def get_all_events(self) -> List[BaseEvent]:
|
|
109
|
+
"""Get all events in order: meta events first, followed by complete, instant and counter events."""
|
|
110
|
+
all_events = []
|
|
111
|
+
all_events.extend(self.meta_event)
|
|
112
|
+
all_events.extend(self.get_complete_events())
|
|
113
|
+
all_events.extend(self.get_instant_events())
|
|
114
|
+
all_events.extend(self.get_counter_events())
|
|
115
|
+
return all_events
|
|
116
|
+
|
|
117
|
+
def get_start_to_end_flow_pairs(self) -> Dict[str, Dict[str, List[BaseEvent]]]:
|
|
118
|
+
"""Get all start/end events for timeline connections."""
|
|
119
|
+
return self.start_to_end_events_pairs
|
|
120
|
+
|
|
121
|
+
def get_events_by_tid(self, tid: int) -> List[BaseEvent]:
|
|
122
|
+
"""Get all events for specified thread ID."""
|
|
123
|
+
events = []
|
|
124
|
+
events.extend(self.complete_event.get(tid, []))
|
|
125
|
+
events.extend(self.instance_event.get(tid, []))
|
|
126
|
+
events.extend(self.counter_event.get(tid, []))
|
|
127
|
+
return events
|
|
128
|
+
|
|
129
|
+
def get_events_by_name(self, name: str) -> List[BaseEvent]:
|
|
130
|
+
"""Get all events for specified thread name."""
|
|
131
|
+
tid = self.name_to_tid.get(name)
|
|
132
|
+
if tid is None:
|
|
133
|
+
return []
|
|
134
|
+
return self.get_events_by_tid(tid)
|
|
135
|
+
|
|
136
|
+
def get_all_tids(self) -> Set[int]:
|
|
137
|
+
"""Get set of all thread IDs."""
|
|
138
|
+
tids = set()
|
|
139
|
+
tids.update(self.complete_event.keys())
|
|
140
|
+
tids.update(self.instance_event.keys())
|
|
141
|
+
tids.update(self.counter_event.keys())
|
|
142
|
+
return tids
|
|
143
|
+
|
|
144
|
+
def get_all_events_with_trace_format(self) -> List[Dict]:
|
|
145
|
+
"""Convert and return all events in Chrome trace format."""
|
|
146
|
+
return [event.to_trace_format() for event in self.get_all_events()]
|
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
"""Task manager"""
|
|
16
|
+
import time
|
|
17
|
+
from typing import Dict, Any
|
|
18
|
+
from collections import defaultdict
|
|
19
|
+
from multiprocessing import Manager
|
|
20
|
+
from multiprocessing import Process
|
|
21
|
+
|
|
22
|
+
from mindspore import log as logger
|
|
23
|
+
from mindspore.profiler.common.process_bar import ProcessBar
|
|
24
|
+
from mindspore.profiler.analysis.parser.base_parser import BaseParser
|
|
25
|
+
from mindspore.profiler.analysis.work_flow import WorkFlow
|
|
26
|
+
from mindspore.profiler.common.log import ProfilerLogger
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TaskManager:
|
|
30
|
+
"""
|
|
31
|
+
Manages the execution of workflows consisting of multiple parsers.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
ROUND_DECIMAL = 2
|
|
35
|
+
|
|
36
|
+
def __init__(self):
|
|
37
|
+
"""
|
|
38
|
+
Initialize the TaskManager with empty workflows and cost time tracking.
|
|
39
|
+
"""
|
|
40
|
+
self.workflows: Dict[str, WorkFlow] = defaultdict(WorkFlow)
|
|
41
|
+
self.show_process: Dict[str, bool] = defaultdict(bool)
|
|
42
|
+
self.flows_cost_time: Dict[str, Dict[str, Any]] = Manager().dict()
|
|
43
|
+
self._logger = ProfilerLogger.get_instance()
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def cost_time(self) -> Dict[str, Dict[str, Any]]:
|
|
47
|
+
# convert Manager().dict() to dict for json serialization
|
|
48
|
+
return dict(self.flows_cost_time)
|
|
49
|
+
|
|
50
|
+
def create_flow(self, *parsers: BaseParser, flow_name: str, show_process: bool = False) -> None:
|
|
51
|
+
"""
|
|
52
|
+
Create a workflow with a list of parsers.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
*parsers (BaseParser): The parsers to be executed in the workflow.
|
|
56
|
+
flow_name (str): The name of the workflow.
|
|
57
|
+
show_process (bool): Whether to show the process bar of the workflow.
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
ValueError: If any of the provided parsers is not an instance of BaseParser.
|
|
61
|
+
"""
|
|
62
|
+
if not parsers:
|
|
63
|
+
logger.error("No parsers provided")
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
workflow = WorkFlow()
|
|
67
|
+
for parser in parsers:
|
|
68
|
+
if not isinstance(parser, BaseParser):
|
|
69
|
+
raise ValueError(
|
|
70
|
+
f"parser {parser.__class__.__name__} must be a BaseParser"
|
|
71
|
+
)
|
|
72
|
+
workflow.add_parser(parser)
|
|
73
|
+
|
|
74
|
+
self.workflows[flow_name] = workflow
|
|
75
|
+
self.show_process[flow_name] = show_process
|
|
76
|
+
|
|
77
|
+
def run(self) -> None:
|
|
78
|
+
"""
|
|
79
|
+
Run all workflows with the given data using a ProcessPoolExecutor.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
data (Any): The data to be processed by the workflows.
|
|
83
|
+
"""
|
|
84
|
+
processes = []
|
|
85
|
+
for flow_name, workflow in self.workflows.items():
|
|
86
|
+
p = Process(target=self._run_flow, args=(flow_name, workflow))
|
|
87
|
+
processes.append((p, flow_name))
|
|
88
|
+
p.start()
|
|
89
|
+
self._logger.info("TaskManager run flow [%s] [pid: %s] start", flow_name, p.pid)
|
|
90
|
+
|
|
91
|
+
for p, flow_name in processes:
|
|
92
|
+
p.join()
|
|
93
|
+
self._logger.info("TaskManager flow [%s] [pid: %s] join", flow_name, p.pid)
|
|
94
|
+
|
|
95
|
+
def _run_flow(self, flow_name: str, workflow: WorkFlow) -> None:
|
|
96
|
+
"""
|
|
97
|
+
Run a single workflow with the given data.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
flow_name (str): The name of the workflow.
|
|
101
|
+
workflow (WorkFlow): The workflow to be executed.
|
|
102
|
+
data (Any): The data to be processed by the workflow.
|
|
103
|
+
"""
|
|
104
|
+
start_time = time.perf_counter()
|
|
105
|
+
parser_cost_time = defaultdict(float)
|
|
106
|
+
|
|
107
|
+
parsers = (
|
|
108
|
+
ProcessBar(workflow, desc="Parsing")
|
|
109
|
+
if self.show_process[flow_name]
|
|
110
|
+
else workflow
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
data = {}
|
|
115
|
+
for parser in parsers:
|
|
116
|
+
parser_start_time = time.perf_counter()
|
|
117
|
+
data = parser.parse(data)
|
|
118
|
+
parser_end_time = time.perf_counter()
|
|
119
|
+
parser_cost_time[parser.__class__.__name__] = round(
|
|
120
|
+
parser_end_time - parser_start_time, self.ROUND_DECIMAL
|
|
121
|
+
)
|
|
122
|
+
except Exception as e: # pylint: disable=W0703
|
|
123
|
+
logger.error("Parser %s error: %s", parser.__class__.__name__, str(e))
|
|
124
|
+
self._logger.error("TaskManager run [%s] error: %s", flow_name, str(e), exc_info=True)
|
|
125
|
+
|
|
126
|
+
end_time = time.perf_counter()
|
|
127
|
+
# Record the cost time of the workflow
|
|
128
|
+
self.flows_cost_time[flow_name] = {
|
|
129
|
+
"total_time_seconds": round(end_time - start_time, self.ROUND_DECIMAL),
|
|
130
|
+
"parser_times_seconds": parser_cost_time,
|
|
131
|
+
}
|