mindspore 2.6.0__cp39-cp39-win_amd64.whl → 2.7.0rc1__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 +1 -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 +40 -9
- mindspore/{_deprecated → _extends/optimize}/__init__.py +9 -3
- mindspore/_extends/optimize/cell_utils.py +96 -0
- mindspore/_extends/parse/__init__.py +2 -2
- mindspore/_extends/parse/compile_config.py +44 -22
- mindspore/_extends/parse/deprecated/deprecated_tensor_method.py +1 -1
- mindspore/_extends/parse/parser.py +36 -61
- mindspore/_extends/parse/resources.py +39 -0
- mindspore/_extends/parse/standard_method.py +32 -13
- mindspore/_extends/parse/trope.py +8 -1
- mindspore/_extends/pijit/__init__.py +1 -2
- mindspore/amp.py +4 -4
- 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/adasum.py +1 -1
- mindspore/boost/boost_cell_wrapper.py +4 -4
- mindspore/common/__init__.py +27 -2
- mindspore/common/_grad_function.py +2 -1
- mindspore/common/_pijit_context.py +28 -7
- mindspore/common/_stub_tensor.py +1 -209
- mindspore/common/_tensor_cpp_method.py +1 -1
- mindspore/common/_tensor_docs.py +76 -15
- mindspore/common/api.py +193 -112
- mindspore/common/dtype.py +21 -11
- mindspore/common/dump.py +10 -15
- mindspore/common/generator.py +2 -3
- mindspore/common/hook_handle.py +11 -2
- mindspore/common/jit_config.py +1 -1
- mindspore/common/jit_trace.py +84 -105
- mindspore/common/parameter.py +26 -12
- mindspore/common/recompute.py +3 -3
- mindspore/common/sparse_tensor.py +0 -3
- mindspore/common/symbol.py +0 -1
- mindspore/common/tensor.py +48 -83
- mindspore/communication/_comm_helper.py +46 -4
- mindspore/communication/management.py +79 -7
- mindspore/context.py +38 -23
- mindspore/dataset/core/config.py +3 -3
- mindspore/dataset/engine/datasets.py +20 -7
- mindspore/dataset/engine/datasets_user_defined.py +32 -2
- mindspore/dataset/engine/iterators.py +2 -2
- mindspore/dataset/engine/obs/config_loader.py +2 -2
- mindspore/dataset/engine/obs/obs_mindrecord_dataset.py +8 -0
- mindspore/dataset/transforms/py_transforms.py +7 -3
- mindspore/dataset/transforms/transforms.py +7 -3
- mindspore/dataset/vision/validators.py +1 -0
- mindspore/device_context/ascend/device.py +1 -1
- mindspore/device_context/gpu/__init__.py +2 -2
- mindspore/device_context/gpu/device.py +1 -1
- mindspore/device_context/gpu/op_precision.py +4 -2
- mindspore/device_context/gpu/op_tuning.py +6 -3
- mindspore/device_manager.py +16 -9
- mindspore/dnnl.dll +0 -0
- mindspore/experimental/llm_boost/ascend_native/llama_boost_ascend_native.py +3 -5
- mindspore/experimental/llm_boost/atb/boost_base.py +2 -3
- mindspore/experimental/optim/adadelta.py +13 -20
- mindspore/experimental/optim/adagrad.py +15 -22
- mindspore/experimental/optim/adam.py +17 -24
- mindspore/experimental/optim/adamax.py +14 -22
- mindspore/experimental/optim/adamw.py +28 -34
- mindspore/experimental/optim/asgd.py +15 -25
- mindspore/experimental/optim/lr_scheduler.py +27 -45
- mindspore/experimental/optim/nadam.py +14 -24
- mindspore/experimental/optim/optimizer.py +13 -23
- mindspore/experimental/optim/radam.py +18 -24
- mindspore/experimental/optim/rmsprop.py +14 -25
- mindspore/experimental/optim/rprop.py +15 -26
- mindspore/experimental/optim/sgd.py +9 -19
- mindspore/hal/__init__.py +4 -4
- mindspore/hal/contiguous_tensors_handle.py +2 -2
- mindspore/hal/memory.py +1 -0
- mindspore/include/api/cell.h +37 -1
- mindspore/include/api/delegate.h +10 -0
- mindspore/include/api/model.h +3 -0
- mindspore/include/api/types.h +2 -2
- mindspore/include/c_api/model_c.h +0 -58
- mindspore/include/c_api/tensor_c.h +0 -26
- mindspore/include/dataset/vision_ascend.h +1 -1
- mindspore/jpeg62.dll +0 -0
- mindspore/mindrecord/tools/cifar10.py +60 -11
- mindspore/mindrecord/tools/cifar10_to_mr.py +5 -0
- mindspore/mindspore_backend_common.dll +0 -0
- mindspore/mindspore_backend_manager.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_cpu_res_manager.dll +0 -0
- mindspore/mindspore_dump.dll +0 -0
- mindspore/mindspore_frontend.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_memory_pool.dll +0 -0
- mindspore/mindspore_ms_backend.dll +0 -0
- mindspore/mindspore_ops.dll +0 -0
- mindspore/mindspore_ops_host.dll +0 -0
- mindspore/mindspore_ops_kernel_common.dll +0 -0
- mindspore/mindspore_profiler.dll +0 -0
- mindspore/mindspore_pyboost.dll +0 -0
- mindspore/mindspore_pynative.dll +0 -0
- mindspore/mindspore_res_manager.dll +0 -0
- mindspore/mindspore_runtime_pipeline.dll +0 -0
- mindspore/mint/__init__.py +4 -44
- mindspore/mint/distributed/__init__.py +1 -0
- mindspore/mint/distributed/distributed.py +208 -5
- mindspore/mint/nn/__init__.py +1 -1
- mindspore/mint/nn/functional.py +53 -6
- mindspore/mint/nn/layer/_functions.py +164 -294
- mindspore/mint/nn/layer/activation.py +8 -6
- mindspore/mint/nn/layer/conv.py +122 -98
- mindspore/mint/nn/layer/normalization.py +8 -22
- mindspore/mint/optim/adam.py +19 -18
- mindspore/mint/optim/adamw.py +14 -8
- mindspore/mint/optim/sgd.py +5 -5
- mindspore/nn/cell.py +325 -499
- mindspore/nn/grad/cell_grad.py +11 -12
- mindspore/nn/layer/activation.py +32 -34
- mindspore/nn/layer/basic.py +67 -64
- mindspore/nn/layer/channel_shuffle.py +4 -4
- mindspore/nn/layer/combined.py +4 -2
- mindspore/nn/layer/conv.py +86 -85
- mindspore/nn/layer/dense.py +9 -7
- mindspore/nn/layer/embedding.py +50 -52
- mindspore/nn/layer/image.py +37 -39
- mindspore/nn/layer/math.py +111 -112
- mindspore/nn/layer/normalization.py +56 -44
- mindspore/nn/layer/pooling.py +58 -63
- mindspore/nn/layer/rnn_cells.py +33 -33
- mindspore/nn/layer/rnns.py +56 -56
- mindspore/nn/layer/thor_layer.py +74 -73
- mindspore/nn/layer/transformer.py +11 -1
- mindspore/nn/learning_rate_schedule.py +20 -20
- mindspore/nn/loss/loss.py +79 -81
- mindspore/nn/optim/adam.py +1 -1
- mindspore/nn/optim/adasum.py +2 -2
- mindspore/nn/optim/optimizer.py +1 -1
- mindspore/nn/optim/thor.py +2 -2
- mindspore/nn/probability/distribution/exponential.py +2 -1
- mindspore/nn/probability/distribution/poisson.py +2 -1
- mindspore/nn/sparse/sparse.py +3 -3
- mindspore/nn/wrap/cell_wrapper.py +34 -37
- mindspore/nn/wrap/grad_reducer.py +37 -37
- mindspore/nn/wrap/loss_scale.py +72 -74
- mindspore/numpy/array_creations.py +5 -5
- mindspore/numpy/fft.py +1 -1
- mindspore/numpy/math_ops.py +1 -1
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/_grad_experimental/grad_comm_ops.py +51 -13
- mindspore/ops/_grad_experimental/grad_debug_ops.py +14 -0
- mindspore/ops/_vmap/vmap_array_ops.py +6 -13
- mindspore/ops/_vmap/vmap_nn_ops.py +8 -16
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +17 -8
- mindspore/ops/auto_generate/gen_extend_func.py +1 -51
- mindspore/ops/auto_generate/gen_ops_def.py +463 -257
- mindspore/ops/auto_generate/gen_ops_prim.py +1127 -885
- mindspore/ops/auto_generate/pyboost_inner_prim.py +31 -1
- mindspore/ops/composite/__init__.py +10 -0
- mindspore/ops/composite/base.py +8 -4
- mindspore/ops/composite/multitype_ops/__init__.py +12 -1
- mindspore/ops/composite/multitype_ops/_compile_utils.py +132 -108
- mindspore/ops/composite/multitype_ops/add_impl.py +70 -2
- mindspore/ops/composite/multitype_ops/div_impl.py +49 -0
- mindspore/ops/composite/multitype_ops/floordiv_impl.py +29 -0
- mindspore/ops/composite/multitype_ops/getitem_impl.py +11 -0
- mindspore/ops/composite/multitype_ops/mod_impl.py +5 -3
- mindspore/ops/composite/multitype_ops/mul_impl.py +49 -0
- mindspore/ops/composite/multitype_ops/setitem_impl.py +57 -0
- mindspore/ops/composite/multitype_ops/sub_impl.py +34 -0
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +14 -0
- mindspore/ops/function/__init__.py +3 -1
- mindspore/ops/function/_add_attr_func.py +11 -6
- mindspore/ops/function/array_func.py +7 -94
- mindspore/ops/function/debug_func.py +4 -3
- mindspore/ops/function/grad/grad_func.py +1 -1
- mindspore/ops/function/math_func.py +21 -367
- mindspore/ops/function/nn_func.py +26 -41
- mindspore/ops/function/other_func.py +4 -1
- mindspore/ops/function/random_func.py +31 -4
- mindspore/ops/functional.py +0 -2
- mindspore/ops/functional_overload.py +463 -6
- mindspore/ops/op_info_register.py +21 -0
- mindspore/ops/operations/__init__.py +5 -2
- mindspore/ops/operations/_custom_ops_utils.py +675 -8
- mindspore/ops/operations/_inner_ops.py +3 -6
- mindspore/ops/operations/_sequence_ops.py +1 -1
- mindspore/ops/operations/comm_ops.py +185 -26
- mindspore/ops/operations/custom_ops.py +235 -172
- mindspore/ops/operations/debug_ops.py +55 -4
- mindspore/ops/operations/image_ops.py +13 -13
- mindspore/ops/operations/manually_defined/ops_def.py +15 -16
- mindspore/ops/operations/math_ops.py +3 -4
- mindspore/ops/operations/nn_ops.py +5 -6
- mindspore/ops/primitive.py +6 -10
- mindspore/ops/tensor_method.py +36 -4
- mindspore/ops_generate/api/cpp_create_prim_instance_helper_generator.py +1 -1
- mindspore/ops_generate/api/functional_map_cpp_generator.py +10 -9
- mindspore/ops_generate/api/functions_cc_generator.py +58 -10
- mindspore/ops_generate/api/tensor_func_reg_cpp_generator.py +1 -1
- mindspore/ops_generate/common/base_generator.py +14 -0
- mindspore/ops_generate/common/gen_constants.py +7 -2
- mindspore/ops_generate/common/gen_utils.py +0 -19
- mindspore/ops_generate/common/op_proto.py +11 -4
- mindspore/ops_generate/common/template.py +88 -11
- mindspore/ops_generate/gen_ops.py +1 -1
- mindspore/ops_generate/op_def/lite_ops_cpp_generator.py +4 -4
- mindspore/ops_generate/op_def/ops_name_h_generator.py +0 -3
- mindspore/ops_generate/op_def/ops_primitive_h_generator.py +0 -4
- mindspore/ops_generate/op_def_py/op_prim_py_generator.py +5 -2
- mindspore/ops_generate/pyboost/auto_grad_impl_cc_generator.py +49 -8
- mindspore/ops_generate/pyboost/auto_grad_reg_cc_generator.py +2 -2
- mindspore/ops_generate/pyboost/gen_pyboost_func.py +31 -0
- mindspore/ops_generate/pyboost/op_template_parser.py +98 -72
- mindspore/ops_generate/pyboost/pyboost_functions_cpp_generator.py +70 -273
- mindspore/ops_generate/pyboost/pyboost_functions_h_generator.py +14 -6
- mindspore/ops_generate/pyboost/pyboost_functions_impl_cpp_generator.py +316 -0
- mindspore/ops_generate/pyboost/pyboost_functions_py_generator.py +1 -1
- mindspore/ops_generate/pyboost/pyboost_grad_function_cpp_generator.py +5 -3
- mindspore/ops_generate/pyboost/pyboost_inner_prim_generator.py +1 -1
- mindspore/ops_generate/pyboost/pyboost_internal_functions_cpp_generator.py +76 -0
- mindspore/ops_generate/pyboost/pyboost_internal_functions_h_generator.py +76 -0
- mindspore/ops_generate/pyboost/pyboost_internal_kernel_info_adapter_generator.py +125 -0
- mindspore/ops_generate/pyboost/pyboost_native_grad_functions_generator.py +4 -3
- mindspore/ops_generate/pyboost/pyboost_op_cpp_code_generator.py +348 -61
- mindspore/ops_generate/pyboost/pyboost_overload_functions_cpp_generator.py +1 -1
- mindspore/ops_generate/pyboost/pyboost_utils.py +118 -9
- mindspore/ops_generate/tensor_py_cc_generator.py +1 -24
- mindspore/parallel/_auto_parallel_context.py +4 -2
- mindspore/parallel/_cell_wrapper.py +106 -40
- mindspore/parallel/_parallel_serialization.py +1 -1
- mindspore/parallel/_ps_context.py +4 -6
- mindspore/parallel/_tensor.py +167 -12
- mindspore/parallel/_transformer/moe.py +1 -1
- mindspore/parallel/_transformer/transformer.py +13 -8
- mindspore/parallel/auto_parallel.py +12 -5
- mindspore/parallel/checkpoint_convert.py +3 -3
- mindspore/parallel/checkpoint_transform.py +3 -1
- mindspore/parallel/cluster/process_entity/_api.py +84 -48
- mindspore/parallel/cluster/process_entity/_utils.py +95 -7
- mindspore/parallel/cluster/run.py +43 -4
- mindspore/parallel/function/__init__.py +8 -1
- mindspore/parallel/function/reshard_func.py +1 -1
- mindspore/parallel/nn/__init__.py +15 -2
- mindspore/parallel/nn/parallel_cell_wrapper.py +9 -10
- mindspore/parallel/nn/parallel_grad_reducer.py +7 -6
- mindspore/parallel/shard.py +2 -2
- mindspore/parallel/transform_safetensors.py +462 -174
- mindspore/profiler/__init__.py +2 -1
- mindspore/profiler/analysis/parser/timeline_assembly_factory/ascend_timeline_assembler.py +7 -7
- mindspore/profiler/analysis/parser/timeline_assembly_factory/base_timeline_assembler.py +3 -0
- mindspore/profiler/analysis/parser/timeline_assembly_factory/trace_view_container.py +3 -0
- mindspore/profiler/analysis/parser/timeline_creator/cpu_op_timeline_creator.py +3 -3
- mindspore/profiler/analysis/parser/timeline_creator/fwk_timeline_creator.py +3 -3
- mindspore/profiler/analysis/parser/timeline_creator/msprof_timeline_creator.py +4 -4
- mindspore/profiler/analysis/parser/timeline_creator/scope_layer_timeline_creator.py +3 -3
- mindspore/profiler/analysis/parser/timeline_event/fwk_event.py +4 -1
- mindspore/profiler/analysis/parser/timeline_event/timeline_event_pool.py +2 -1
- mindspore/profiler/analysis/task_manager.py +1 -1
- mindspore/profiler/analysis/viewer/ascend_communication_viewer.py +5 -1
- mindspore/profiler/analysis/viewer/ascend_integrate_viewer.py +2 -1
- mindspore/profiler/analysis/viewer/ascend_op_memory_viewer.py +42 -22
- mindspore/profiler/analysis/viewer/ascend_step_trace_time_viewer.py +3 -2
- mindspore/profiler/analysis/viewer/ms_minddata_viewer.py +9 -5
- mindspore/profiler/analysis/viewer/ms_operator_details_viewer.py +132 -0
- mindspore/profiler/common/constant.py +16 -0
- mindspore/profiler/common/profiler_context.py +25 -27
- mindspore/profiler/common/profiler_info.py +0 -16
- mindspore/profiler/common/profiler_op_analyse.py +235 -0
- mindspore/profiler/common/profiler_output_path.py +23 -8
- mindspore/profiler/common/profiler_parameters.py +128 -35
- mindspore/profiler/dynamic_profile/__init__.py +0 -0
- mindspore/profiler/dynamic_profile/dynamic_monitor_proxy.py +39 -0
- mindspore/profiler/dynamic_profile/dynamic_profiler_config_context.py +666 -0
- mindspore/profiler/dynamic_profile/dynamic_profiler_utils.py +62 -0
- mindspore/profiler/dynamic_profiler.py +305 -314
- mindspore/profiler/envprofiler.py +12 -7
- mindspore/profiler/experimental_config.py +96 -6
- mindspore/profiler/mstx.py +33 -12
- mindspore/profiler/platform/__init__.py +2 -3
- mindspore/profiler/platform/npu_profiler.py +29 -19
- mindspore/profiler/profiler.py +35 -19
- mindspore/profiler/profiler_action_controller.py +64 -76
- mindspore/profiler/schedule.py +10 -4
- mindspore/rewrite/common/config.py +1 -0
- mindspore/rewrite/common/namer.py +1 -0
- mindspore/rewrite/common/namespace.py +1 -0
- mindspore/rewrite/node/node.py +31 -11
- mindspore/rewrite/parsers/assign_parser.py +1 -1
- mindspore/rewrite/symbol_tree/symbol_tree.py +1 -1
- mindspore/run_check/_check_version.py +7 -10
- mindspore/runtime/__init__.py +5 -5
- mindspore/runtime/event.py +10 -4
- mindspore/runtime/executor.py +60 -45
- mindspore/runtime/memory.py +21 -30
- mindspore/runtime/thread_bind_core.py +298 -164
- mindspore/safeguard/rewrite_obfuscation.py +12 -13
- mindspore/swresample-4.dll +0 -0
- mindspore/swscale-6.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/_utils.py +6 -2
- mindspore/train/amp.py +43 -20
- mindspore/train/callback/__init__.py +5 -5
- mindspore/train/callback/_checkpoint.py +3 -6
- mindspore/train/callback/_flops_collector.py +1 -1
- mindspore/train/callback/_landscape.py +0 -1
- mindspore/train/callback/_train_fault_tolerance.py +71 -13
- mindspore/train/data_sink.py +11 -2
- mindspore/train/dataset_helper.py +9 -0
- mindspore/train/model.py +51 -33
- mindspore/train/serialization.py +133 -111
- mindspore/train/summary/summary_record.py +13 -2
- mindspore/turbojpeg.dll +0 -0
- mindspore/utils/__init__.py +3 -2
- mindspore/utils/dryrun.py +0 -6
- mindspore/utils/runtime_execution_order_check.py +162 -78
- mindspore/utils/sdc_detect.py +68 -0
- mindspore/utils/utils.py +6 -9
- mindspore/version.py +1 -1
- {mindspore-2.6.0.dist-info → mindspore-2.7.0rc1.dist-info}/METADATA +5 -4
- {mindspore-2.6.0.dist-info → mindspore-2.7.0rc1.dist-info}/RECORD +329 -367
- mindspore/_deprecated/jit.py +0 -198
- mindspore/experimental/es/__init__.py +0 -22
- mindspore/experimental/es/embedding_service.py +0 -891
- mindspore/experimental/es/embedding_service_layer.py +0 -581
- mindspore/profiler/parser/__init__.py +0 -14
- mindspore/profiler/parser/aicpu_data_parser.py +0 -272
- mindspore/profiler/parser/ascend_analysis/__init__.py +0 -14
- mindspore/profiler/parser/ascend_analysis/constant.py +0 -71
- mindspore/profiler/parser/ascend_analysis/file_manager.py +0 -180
- mindspore/profiler/parser/ascend_analysis/function_event.py +0 -185
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +0 -136
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +0 -131
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +0 -104
- mindspore/profiler/parser/ascend_analysis/path_manager.py +0 -313
- mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +0 -123
- mindspore/profiler/parser/ascend_analysis/tlv_decoder.py +0 -86
- mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +0 -75
- mindspore/profiler/parser/ascend_cluster_generator.py +0 -116
- mindspore/profiler/parser/ascend_communicate_generator.py +0 -314
- mindspore/profiler/parser/ascend_flops_generator.py +0 -116
- mindspore/profiler/parser/ascend_fpbp_generator.py +0 -82
- mindspore/profiler/parser/ascend_hccl_generator.py +0 -271
- mindspore/profiler/parser/ascend_integrate_generator.py +0 -42
- mindspore/profiler/parser/ascend_memory_generator.py +0 -185
- mindspore/profiler/parser/ascend_msprof_exporter.py +0 -282
- mindspore/profiler/parser/ascend_msprof_generator.py +0 -187
- mindspore/profiler/parser/ascend_op_generator.py +0 -334
- mindspore/profiler/parser/ascend_steptrace_generator.py +0 -94
- mindspore/profiler/parser/ascend_timeline_generator.py +0 -545
- mindspore/profiler/parser/base_timeline_generator.py +0 -483
- mindspore/profiler/parser/container.py +0 -229
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +0 -697
- mindspore/profiler/parser/flops_parser.py +0 -531
- mindspore/profiler/parser/framework_enum.py +0 -111
- mindspore/profiler/parser/framework_parser.py +0 -464
- mindspore/profiler/parser/framework_struct.py +0 -61
- mindspore/profiler/parser/gpu_analysis/__init__.py +0 -14
- mindspore/profiler/parser/gpu_analysis/function_event.py +0 -44
- mindspore/profiler/parser/gpu_analysis/fwk_file_parser.py +0 -89
- mindspore/profiler/parser/gpu_analysis/profiler_info_parser.py +0 -72
- mindspore/profiler/parser/hccl_parser.py +0 -573
- mindspore/profiler/parser/hwts_log_parser.py +0 -122
- mindspore/profiler/parser/integrator.py +0 -526
- mindspore/profiler/parser/memory_usage_parser.py +0 -277
- mindspore/profiler/parser/minddata_analyzer.py +0 -800
- mindspore/profiler/parser/minddata_parser.py +0 -186
- mindspore/profiler/parser/minddata_pipeline_parser.py +0 -299
- mindspore/profiler/parser/op_intermediate_parser.py +0 -149
- mindspore/profiler/parser/optime_parser.py +0 -250
- mindspore/profiler/parser/profiler_info.py +0 -213
- mindspore/profiler/parser/step_trace_parser.py +0 -666
- {mindspore-2.6.0.dist-info → mindspore-2.7.0rc1.dist-info}/WHEEL +0 -0
- {mindspore-2.6.0.dist-info → mindspore-2.7.0rc1.dist-info}/entry_points.txt +0 -0
- {mindspore-2.6.0.dist-info → mindspore-2.7.0rc1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# Copyright 2025 Huawei Technologies Co., Ltd
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ============================================================================
|
|
15
|
+
"""
|
|
16
|
+
This module defines the PyboostFunctionsGenerator class for generating C++ functions for PyBoost operations.
|
|
17
|
+
|
|
18
|
+
The generator processes operator prototypes and constructs the necessary function definitions, including
|
|
19
|
+
conversions for optional parameters and tensor arguments. It generates the registration code and includes
|
|
20
|
+
the necessary header files for the generated functions.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import os
|
|
24
|
+
|
|
25
|
+
import common.template as template
|
|
26
|
+
import common.gen_constants as K
|
|
27
|
+
from common.template import Template
|
|
28
|
+
from common.gen_utils import save_file
|
|
29
|
+
from common.op_proto import OpProto
|
|
30
|
+
from common.base_generator import BaseGenerator
|
|
31
|
+
from pyboost import pyboost_utils
|
|
32
|
+
from pyboost.pyboost_utils import get_convert_type_str, is_optional_param, get_input_args_type_str, \
|
|
33
|
+
is_tensor_list
|
|
34
|
+
from .op_template_parser import OpTemplateParser
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class PyboostFunctionsImplGenerator(BaseGenerator):
|
|
38
|
+
"""
|
|
39
|
+
Generates PyBoost functions based on operator prototypes.
|
|
40
|
+
|
|
41
|
+
This class processes operator prototypes (`op_protos`) to create the necessary C++ function definitions for
|
|
42
|
+
PyBoost operations. It constructs function bodies, handles optional value conversions, and generates
|
|
43
|
+
registration code and header inclusions.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self):
|
|
47
|
+
"""Initializes the PyboostFunctionsGenerator with the necessary templates."""
|
|
48
|
+
self.pyboost_func_include_header_template = Template(
|
|
49
|
+
f'#include "{K.MS_PYBOOST_BASE_PATH}/auto_generate/${{operator_name}}.h"\n'
|
|
50
|
+
)
|
|
51
|
+
self.convert_optional_to_value_template = Template(
|
|
52
|
+
"auto ${output} = PyNativeAlgo::PyBoost::OptionalToValue(${input});\n"
|
|
53
|
+
)
|
|
54
|
+
self.convert_to_tensor_template = Template(
|
|
55
|
+
'auto ${output} = PyNativeAlgo::Common::ConvertStubNodeToTensor(${input}, ${need_contiguous}, '
|
|
56
|
+
'op_run_info->requires_grad);\n'
|
|
57
|
+
)
|
|
58
|
+
self.convert_to_tensor_list_template = Template(
|
|
59
|
+
'auto ${output} = PyNativeAlgo::Common::ConvertStubNodeToValueTuple(${input}, ${need_contiguous}, '
|
|
60
|
+
'op_run_info->requires_grad);\n'
|
|
61
|
+
)
|
|
62
|
+
self.implicit_cast_template = Template(
|
|
63
|
+
'// Do mixed precision and implicit cast\n' \
|
|
64
|
+
'static const std::vector<std::vector<size_t>> same_type_table{${same_type}};\n' \
|
|
65
|
+
'auto [${cast_args}] =\n' \
|
|
66
|
+
' PyNativeAlgo::PyBoost::SetPyBoostCastForInputs<${type_num}>(op_run_info, "${class_name}", \
|
|
67
|
+
same_type_table, ${call_args});\n'
|
|
68
|
+
)
|
|
69
|
+
self.convert_template = Template("auto $arg_name = converter.${convert_func}(args, $arg_index);\n")
|
|
70
|
+
self.input_args_template = Template(" const ${arg_type}& ${arg_name},")
|
|
71
|
+
self.PYBOOST_CORE_CC_TEMPLATE = template.PYBOOST_CORE_CC_TEMPLATE
|
|
72
|
+
self.TENSOR_FUNC_CLASS_REG = template.TENSOR_FUNC_CLASS_REG
|
|
73
|
+
self.OP_DEF_INC_HEAD_TEMPLATE = template.OP_DEF_INC_HEAD_TEMPLATE
|
|
74
|
+
|
|
75
|
+
self.PYBOOST_CORE_BODY_TEMPLATE = template.PYBOOST_CORE_BODY_TEMPLATE
|
|
76
|
+
self.PYBOOST_CORE_BODY_COMM_TEMPLATE = template.PYBOOST_CORE_BODY_COMM_TEMPLATE
|
|
77
|
+
self.PYBOOST_CORE_BODY_SYNC_TEMPLATE = template.PYBOOST_CORE_BODY_SYNC_TEMPLATE
|
|
78
|
+
|
|
79
|
+
def generate(self, work_path, op_protos):
|
|
80
|
+
"""
|
|
81
|
+
Generates the C++ PyBoost functions and writes them to the specified files.
|
|
82
|
+
|
|
83
|
+
This method processes a list of operator prototypes (`op_protos`), extracting necessary information
|
|
84
|
+
such as operator names, arguments, and conversion types. It constructs the function definitions, includes,
|
|
85
|
+
and registration code. The generated content is saved to the specified path as a C++ source file.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
work_path (str): The file path where the generated files will be saved.
|
|
89
|
+
op_protos (list): A list of operator prototypes containing information about the operators to be processed.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
None
|
|
93
|
+
"""
|
|
94
|
+
pyboost_func_include_headers_str = ''
|
|
95
|
+
for op_proto in op_protos:
|
|
96
|
+
if op_proto.op_dispatch is None or not op_proto.op_dispatch.enable:
|
|
97
|
+
continue
|
|
98
|
+
|
|
99
|
+
if op_proto.op_dispatch.is_comm_op:
|
|
100
|
+
pyboost_func_include_headers_str += self.pyboost_func_include_header_template.replace(
|
|
101
|
+
operator_name=op_proto.op_name)
|
|
102
|
+
|
|
103
|
+
# generate pyboost core cc
|
|
104
|
+
pyboost_core_body_str = self._get_pyboost_core_body_all_str(op_protos)
|
|
105
|
+
pyboost_core_file \
|
|
106
|
+
= self.PYBOOST_CORE_CC_TEMPLATE.replace(include_op_header=pyboost_func_include_headers_str,
|
|
107
|
+
function_body=pyboost_core_body_str)
|
|
108
|
+
save_path = os.path.join(work_path, K.PIPELINE_PYBOOST_FUNC_GEN_PATH)
|
|
109
|
+
file_name = "pyboost_core.cc"
|
|
110
|
+
save_file(save_path, file_name, pyboost_core_file)
|
|
111
|
+
|
|
112
|
+
def _get_pyboost_core_body_all_str(self, op_protos):
|
|
113
|
+
"""
|
|
114
|
+
Generates pyboost functions implementation string for all operations.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
op_protos (list): A list of op prototypes.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
str: pyboost functions implementation string for all operations.
|
|
121
|
+
"""
|
|
122
|
+
pyboost_core_body_str = ''
|
|
123
|
+
for op_proto in op_protos:
|
|
124
|
+
if op_proto.op_dispatch is None or not op_proto.op_dispatch.enable:
|
|
125
|
+
continue
|
|
126
|
+
pyboost_core_body_str += self._get_pyboost_core_body_str(op_proto)
|
|
127
|
+
|
|
128
|
+
return pyboost_core_body_str
|
|
129
|
+
|
|
130
|
+
def _get_pyboost_core_body_str(self, op_proto):
|
|
131
|
+
"""
|
|
132
|
+
Generates pyboost functions implementation string for specific operator.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
op_proto (prototype): op prototype.
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
str: pyboost functions implementation string of specific operator.
|
|
139
|
+
"""
|
|
140
|
+
op_parser = OpTemplateParser(op_proto)
|
|
141
|
+
op_pyboost_func_name = op_parser.get_pyboost_func_name()
|
|
142
|
+
op_def_name_str = op_parser.get_op_def_name_str()
|
|
143
|
+
type_num, same_type = op_parser.gen_signature_same_type_table()
|
|
144
|
+
parser_body_str = self._generate_parser_func(op_proto)
|
|
145
|
+
op_args_str = [op_arg.arg_name for op_arg in op_proto.op_args]
|
|
146
|
+
convert_stub_str = self._get_convert_stub_str(op_proto)
|
|
147
|
+
call_args_str = self._get_call_args_str(op_proto)
|
|
148
|
+
cast_args_str = self._get_cast_to_value_str(op_proto)
|
|
149
|
+
op_input_args_str = self._get_input_args_str(op_proto)
|
|
150
|
+
output_num_str = len(op_proto.op_returns)
|
|
151
|
+
pyboost_core_body_tpl = self._get_pyboost_core_body_tpl(op_proto)
|
|
152
|
+
if op_proto.op_view:
|
|
153
|
+
implicit_cast_str = ''
|
|
154
|
+
cast_args_str = call_args_str
|
|
155
|
+
else:
|
|
156
|
+
implicit_cast_str = self.implicit_cast_template.replace(cast_args=cast_args_str,
|
|
157
|
+
type_num=type_num,
|
|
158
|
+
call_args=call_args_str,
|
|
159
|
+
same_type=same_type,
|
|
160
|
+
class_name=op_proto.op_class.name)
|
|
161
|
+
return pyboost_core_body_tpl.replace(func_name=op_pyboost_func_name,
|
|
162
|
+
op_def_name=op_def_name_str,
|
|
163
|
+
input_args=op_input_args_str,
|
|
164
|
+
parser_body=parser_body_str,
|
|
165
|
+
op_name=op_proto.op_class.name,
|
|
166
|
+
class_name=op_proto.op_class.name,
|
|
167
|
+
implicit_cast=implicit_cast_str,
|
|
168
|
+
op_args=op_args_str,
|
|
169
|
+
convert_stub=convert_stub_str,
|
|
170
|
+
call_args=call_args_str,
|
|
171
|
+
cast_args=cast_args_str,
|
|
172
|
+
output_num=output_num_str,
|
|
173
|
+
operator_name=op_proto.op_name)
|
|
174
|
+
|
|
175
|
+
def _generate_parser_func(self, op_proto: OpProto) -> str:
|
|
176
|
+
"""
|
|
177
|
+
Generates the parsing function for the operator's arguments.
|
|
178
|
+
|
|
179
|
+
This method constructs the code for converting each argument in the operator prototype to its appropriate
|
|
180
|
+
type, handling optional parameters as necessary.
|
|
181
|
+
|
|
182
|
+
Args:
|
|
183
|
+
op_proto (OpProto): The operator prototype containing the argument information.
|
|
184
|
+
|
|
185
|
+
Returns:
|
|
186
|
+
str: The generated parsing function code as a string.
|
|
187
|
+
"""
|
|
188
|
+
parser_func_str = ''
|
|
189
|
+
for index, op_arg in enumerate(op_proto.op_args):
|
|
190
|
+
is_optional = is_optional_param(op_arg)
|
|
191
|
+
if op_arg.is_type_id:
|
|
192
|
+
convert_type_str = get_convert_type_str('type', is_optional, op_proto.op_view)
|
|
193
|
+
else:
|
|
194
|
+
convert_type_str = get_convert_type_str(op_arg.arg_dtype, is_optional, op_proto.op_view)
|
|
195
|
+
|
|
196
|
+
parser_func_str += self.convert_template.replace(arg_name=op_arg.arg_name, convert_func=convert_type_str,
|
|
197
|
+
arg_index=pyboost_utils.get_index(index))
|
|
198
|
+
return parser_func_str
|
|
199
|
+
|
|
200
|
+
def _get_input_args_str(self, op_proto: OpProto) -> str:
|
|
201
|
+
"""
|
|
202
|
+
Generates the input arguments list for the pyboost operator.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
op_proto (OpProto): The operator prototype containing the argument information.
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
str: The generated input arguments list as a string.
|
|
209
|
+
"""
|
|
210
|
+
parser_func_str = ''
|
|
211
|
+
for _, op_arg in enumerate(op_proto.op_args):
|
|
212
|
+
is_optional = is_optional_param(op_arg)
|
|
213
|
+
if op_arg.is_type_id:
|
|
214
|
+
arg_type_str = get_input_args_type_str('type', is_optional, op_proto.op_view)
|
|
215
|
+
else:
|
|
216
|
+
arg_type_str = get_input_args_type_str(op_arg.arg_dtype, is_optional, op_proto.op_view)
|
|
217
|
+
parser_func_str += self.input_args_template.replace(arg_name=op_arg.arg_name, arg_type=arg_type_str)
|
|
218
|
+
return parser_func_str[:-1]
|
|
219
|
+
|
|
220
|
+
def _get_convert_stub_str(self, op_proto: OpProto):
|
|
221
|
+
"""
|
|
222
|
+
Generates the conversion stub code for the operator's arguments.
|
|
223
|
+
|
|
224
|
+
This method creates code for converting operator arguments to tensor format, depending on whether they
|
|
225
|
+
are view operations or standard tensor operations.
|
|
226
|
+
|
|
227
|
+
Args:
|
|
228
|
+
op_proto (OpProto): The operator prototype containing the argument information.
|
|
229
|
+
|
|
230
|
+
Returns:
|
|
231
|
+
str: The generated conversion stub code as a string.
|
|
232
|
+
"""
|
|
233
|
+
convert_stub_str = ''
|
|
234
|
+
need_contiguous = 'true'
|
|
235
|
+
if op_proto.op_view:
|
|
236
|
+
# View/ACLNN op does not need to convert to contiguous tensor.
|
|
237
|
+
need_contiguous = 'false'
|
|
238
|
+
for op_arg in op_proto.op_args:
|
|
239
|
+
if pyboost_utils.is_tensor(op_arg):
|
|
240
|
+
convert_stub_output_name = op_arg.arg_name + '_optional' if is_optional_param(op_arg) \
|
|
241
|
+
else op_arg.arg_name + "_tensor"
|
|
242
|
+
convert_stub_str += self.convert_to_tensor_template.replace(input=op_arg.arg_name,
|
|
243
|
+
output=convert_stub_output_name,
|
|
244
|
+
need_contiguous=need_contiguous)
|
|
245
|
+
elif pyboost_utils.is_tensor_list(op_arg):
|
|
246
|
+
# To adapt the cases where TensorList is optional.
|
|
247
|
+
convert_stub_output_name = op_arg.arg_name + '_optional' if is_optional_param(op_arg) \
|
|
248
|
+
else op_arg.arg_name + "_tensor_list"
|
|
249
|
+
convert_stub_str += self.convert_to_tensor_list_template.replace(input=op_arg.arg_name,
|
|
250
|
+
output=convert_stub_output_name,
|
|
251
|
+
need_contiguous=need_contiguous)
|
|
252
|
+
return convert_stub_str
|
|
253
|
+
|
|
254
|
+
def _get_call_args_str(self, op_proto: OpProto):
|
|
255
|
+
"""
|
|
256
|
+
Generates the list of call arguments for the operator.
|
|
257
|
+
|
|
258
|
+
This method constructs a list of argument names for the function call, adapting the names for
|
|
259
|
+
optional tensors and tensor lists as needed.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
op_proto (OpProto): The operator prototype containing the argument information.
|
|
263
|
+
|
|
264
|
+
Returns:
|
|
265
|
+
list: A list of formatted argument names for the function call.
|
|
266
|
+
"""
|
|
267
|
+
call_args_str = []
|
|
268
|
+
for op_arg in op_proto.op_args:
|
|
269
|
+
if pyboost_utils.is_tensor(op_arg):
|
|
270
|
+
convert_stub_output_name = op_arg.arg_name + '_optional' if is_optional_param(op_arg) \
|
|
271
|
+
else op_arg.arg_name + "_tensor"
|
|
272
|
+
call_arg = convert_stub_output_name
|
|
273
|
+
elif pyboost_utils.is_tensor_list(op_arg):
|
|
274
|
+
convert_stub_output_name = op_arg.arg_name + '_optional' if is_optional_param(op_arg) \
|
|
275
|
+
else op_arg.arg_name + "_tensor_list"
|
|
276
|
+
call_arg = convert_stub_output_name
|
|
277
|
+
else:
|
|
278
|
+
call_arg = op_arg.arg_name
|
|
279
|
+
call_args_str.append(call_arg)
|
|
280
|
+
return call_args_str
|
|
281
|
+
|
|
282
|
+
def _get_cast_to_value_str(self, op_proto: OpProto):
|
|
283
|
+
"""
|
|
284
|
+
Generates the list of cast arguments for the operator.
|
|
285
|
+
|
|
286
|
+
This method constructs a list of argument names that need to be cast to their corresponding types.
|
|
287
|
+
|
|
288
|
+
Args:
|
|
289
|
+
op_proto (OpProto): The operator prototype containing the argument information.
|
|
290
|
+
|
|
291
|
+
Returns:
|
|
292
|
+
list: A list of formatted cast argument names.
|
|
293
|
+
"""
|
|
294
|
+
cast_args_str = []
|
|
295
|
+
for op_arg in op_proto.op_args:
|
|
296
|
+
cast_str = 'cast_'
|
|
297
|
+
if pyboost_utils.is_tensor(op_arg):
|
|
298
|
+
convert_stub_output_name = op_arg.arg_name + '_optional' if is_optional_param(op_arg) \
|
|
299
|
+
else op_arg.arg_name + "_tensor"
|
|
300
|
+
cast_arg = cast_str + convert_stub_output_name
|
|
301
|
+
elif pyboost_utils.is_tensor_list(op_arg):
|
|
302
|
+
# To adapt the cases where TensorList is optional.
|
|
303
|
+
convert_stub_output_name = op_arg.arg_name + '_optional' if is_optional_param(op_arg) \
|
|
304
|
+
else op_arg.arg_name + "_tensor_list"
|
|
305
|
+
cast_arg = cast_str + convert_stub_output_name
|
|
306
|
+
else:
|
|
307
|
+
cast_arg = cast_str + op_arg.arg_name
|
|
308
|
+
cast_args_str.append(cast_arg)
|
|
309
|
+
return cast_args_str
|
|
310
|
+
|
|
311
|
+
def _get_pyboost_core_body_tpl(self, op_proto: OpProto):
|
|
312
|
+
if len(op_proto.op_returns) == 1 and is_tensor_list(op_proto.op_returns[0]):
|
|
313
|
+
# op output size is unknown
|
|
314
|
+
return self.PYBOOST_CORE_BODY_SYNC_TEMPLATE
|
|
315
|
+
return self.PYBOOST_CORE_BODY_COMM_TEMPLATE \
|
|
316
|
+
if op_proto.op_dispatch.is_comm_op else self.PYBOOST_CORE_BODY_TEMPLATE
|
|
@@ -115,7 +115,7 @@ class PyboostFunctionsPyGenerator(BaseGenerator):
|
|
|
115
115
|
arg_handler = op_arg.arg_handler
|
|
116
116
|
arg_name = op_arg.arg_name
|
|
117
117
|
input_arg = arg_name
|
|
118
|
-
if arg_handler
|
|
118
|
+
if arg_handler not in ('', 'dtype_to_type_id'):
|
|
119
119
|
input_arg = 'converted_' + arg_name
|
|
120
120
|
input_args.append(input_arg)
|
|
121
121
|
default_value = op_arg.default
|
|
@@ -69,7 +69,8 @@ class PyboostGradFunctionsGenerator(BaseGenerator):
|
|
|
69
69
|
pyboost_func_reg_def = ''
|
|
70
70
|
pyboost_func_include_headers_str = ''
|
|
71
71
|
for op_proto in op_protos:
|
|
72
|
-
if (op_proto.op_dispatch is None) or (not op_proto.op_dispatch.enable)
|
|
72
|
+
if (op_proto.op_dispatch is None) or (not op_proto.op_dispatch.enable) \
|
|
73
|
+
or op_proto.op_dispatch.is_comm_op:
|
|
73
74
|
continue
|
|
74
75
|
op_parser = OpTemplateParser(op_proto)
|
|
75
76
|
op_pyboost_func_name = op_parser.get_pyboost_func_name()
|
|
@@ -89,7 +90,8 @@ class PyboostGradFunctionsGenerator(BaseGenerator):
|
|
|
89
90
|
op_name=op_name_str,
|
|
90
91
|
op_args=op_args_str,
|
|
91
92
|
convert_body=convert_value_type_str,
|
|
92
|
-
call_args=call_args_str
|
|
93
|
+
call_args=call_args_str,
|
|
94
|
+
operator_name=op_proto.op_name)
|
|
93
95
|
pyboost_func_str = pyboost_func_str + template.NEW_LINE
|
|
94
96
|
pyboost_func_reg_def += template.REGISTER_PYBOOST_GRAD_DEFINE_TEMPLATE.replace(
|
|
95
97
|
pyboost_op_name=op_proto.op_class.name,
|
|
@@ -124,7 +126,7 @@ class PyboostGradFunctionsGenerator(BaseGenerator):
|
|
|
124
126
|
parser_func_str = ''
|
|
125
127
|
for index, arg in enumerate(op_proto.op_args):
|
|
126
128
|
is_optional = pyboost_utils.is_optional_param(arg)
|
|
127
|
-
convert_type_str = pyboost_utils.get_value_convert_type_str(arg.arg_dtype, is_optional)
|
|
129
|
+
convert_type_str = pyboost_utils.get_value_convert_type_str(arg.arg_dtype, is_optional, op_proto.op_view)
|
|
128
130
|
parser_func_str += convert_template.replace(arg_name=arg.arg_name, convert_func=convert_type_str,
|
|
129
131
|
arg_index=pyboost_utils.get_index(index))
|
|
130
132
|
return parser_func_str
|
|
@@ -122,7 +122,7 @@ class PyboostInnerPrimGenerator(BaseGenerator):
|
|
|
122
122
|
arg_name = arg.arg_name
|
|
123
123
|
arg_handler = arg.arg_handler
|
|
124
124
|
processed_arg = arg_name
|
|
125
|
-
if arg_handler
|
|
125
|
+
if arg_handler not in ('', 'dtype_to_type_id'):
|
|
126
126
|
process_func += \
|
|
127
127
|
f"""converted_{arg_name} = {arg_handler}('{operator_name}', '{arg_name}', {arg_name})\n"""
|
|
128
128
|
processed_arg = 'converted_' + arg_name
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Copyright 2025 Huawei Technologies Co., Ltd
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ============================================================================
|
|
15
|
+
"""
|
|
16
|
+
This module defines the `PyboostInternalFunctionsCppGenerator` class, which is used to generate the source file
|
|
17
|
+
(`functions.cc`) that contains function definitions for internal op in Pyboost.
|
|
18
|
+
|
|
19
|
+
The class uses templates and operation prototypes to create function definitions based on the
|
|
20
|
+
operation's primitive and arguments. The generated file is saved to the specified path.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import os
|
|
24
|
+
|
|
25
|
+
import common.template as template
|
|
26
|
+
import common.gen_constants as K
|
|
27
|
+
from common.gen_utils import save_file
|
|
28
|
+
from common.base_generator import BaseGenerator
|
|
29
|
+
|
|
30
|
+
from .op_template_parser import OpTemplateParser
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class PyboostInternalFunctionsCppGenerator(BaseGenerator):
|
|
34
|
+
"""
|
|
35
|
+
A class to generate the `functions.cc` source file, which contains internal op function definitions.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
def __init__(self):
|
|
39
|
+
"""Initializes the PyboostInternalFunctionsCppGenerator with the necessary templates."""
|
|
40
|
+
self.pyboost_internal_functions_source_template = template.PYBOOST_INTERNAL_FUNCTION_SOURCE_TEMPLATE
|
|
41
|
+
self.pyboost_internal_functions_template = template.PYBOOST_INTERNAL_FUNCTION_TEMPLATE
|
|
42
|
+
|
|
43
|
+
def generate(self, work_path, op_protos):
|
|
44
|
+
"""
|
|
45
|
+
Generates the Pyboost internal function source file (`functions.cc`).
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
work_path (str): The directory where the generated file will be saved.
|
|
49
|
+
op_protos (list): A list of operation prototypes to parse and convert into function definitions.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
None: The method writes the generated source file to the specified directory.
|
|
53
|
+
"""
|
|
54
|
+
func_list = []
|
|
55
|
+
for op_proto in op_protos:
|
|
56
|
+
if op_proto.op_dispatch is None or not op_proto.op_dispatch.enable:
|
|
57
|
+
continue
|
|
58
|
+
if getattr(op_proto.op_dispatch, 'internal_op_ascend') == 'None':
|
|
59
|
+
continue
|
|
60
|
+
operator_name = op_proto.op_name
|
|
61
|
+
op_name = op_proto.op_class.name
|
|
62
|
+
op_parser = OpTemplateParser(op_proto)
|
|
63
|
+
call_args_after_convert, _, _ = op_parser.op_args_converter()
|
|
64
|
+
call_args_with_type = op_parser.parse_call_args_with_types(is_convert=True)
|
|
65
|
+
func_list.append(template.NEW_LINE + self.pyboost_internal_functions_template.replace(
|
|
66
|
+
operator_name=operator_name,
|
|
67
|
+
op_name=op_name,
|
|
68
|
+
call_args_with_type=call_args_with_type,
|
|
69
|
+
call_args_after_convert=call_args_after_convert))
|
|
70
|
+
|
|
71
|
+
if not func_list:
|
|
72
|
+
return
|
|
73
|
+
pyboost_internal_op_functions_str = self.pyboost_internal_functions_source_template.replace(func_list=func_list)
|
|
74
|
+
save_path = os.path.join(work_path, K.MS_PYBOOST_INTERNAL_FUNCTIONS_AUTO_GEN_PATH)
|
|
75
|
+
file_name = "functions.cc"
|
|
76
|
+
save_file(save_path, file_name, pyboost_internal_op_functions_str)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Copyright 2025 Huawei Technologies Co., Ltd
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ============================================================================
|
|
15
|
+
"""
|
|
16
|
+
This module defines the `PyboostInternalFunctionsHeaderGenerator` class, which is used to generate the header file
|
|
17
|
+
(`functions.h`) that contains function declarations for internal op in Pyboost.
|
|
18
|
+
|
|
19
|
+
The class uses templates and operation prototypes to create function declarations based on the
|
|
20
|
+
operation's primitive and arguments. The generated file is saved to the specified path.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import os
|
|
24
|
+
|
|
25
|
+
import common.template as template
|
|
26
|
+
import common.gen_constants as K
|
|
27
|
+
from common.template import Template
|
|
28
|
+
from common.gen_utils import save_file
|
|
29
|
+
from common.base_generator import BaseGenerator
|
|
30
|
+
|
|
31
|
+
from .op_template_parser import OpTemplateParser
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class PyboostInternalFunctionsHeaderGenerator(BaseGenerator):
|
|
35
|
+
"""
|
|
36
|
+
A class to generate the `functions.h` header file, which contains internal op function declarations.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self):
|
|
40
|
+
"""Initializes the PyboostInternalFunctionsHeaderGenerator with the necessary templates."""
|
|
41
|
+
self.pyboost_internal_function_header_template = template.PYBOOST_INTERNAL_FUNCTION_HEADER_TEMPLATE
|
|
42
|
+
|
|
43
|
+
self.pyboost_internal_func_template = Template(
|
|
44
|
+
'void internal_${operator_name}(const std::shared_ptr<pyboost::OpRunner> &op, ${call_args_with_type});'
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def generate(self, work_path, op_protos):
|
|
48
|
+
"""
|
|
49
|
+
Generates the Pyboost internal function header file (`functions.h`).
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
work_path (str): The directory where the generated file will be saved.
|
|
53
|
+
op_protos (list): A list of operation prototypes to parse and convert into function declarations.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
None: The method writes the generated header file to the specified directory.
|
|
57
|
+
"""
|
|
58
|
+
func_list = []
|
|
59
|
+
for op_proto in op_protos:
|
|
60
|
+
if op_proto.op_dispatch is None or not op_proto.op_dispatch.enable:
|
|
61
|
+
continue
|
|
62
|
+
if getattr(op_proto.op_dispatch, 'internal_op_ascend') == 'None':
|
|
63
|
+
continue
|
|
64
|
+
operator_name = op_proto.op_name
|
|
65
|
+
op_parser = OpTemplateParser(op_proto)
|
|
66
|
+
call_args_with_types = op_parser.parse_call_args_with_types(is_convert=True)
|
|
67
|
+
func_list.append(self.pyboost_internal_func_template.replace(operator_name=operator_name,
|
|
68
|
+
call_args_with_type=call_args_with_types))
|
|
69
|
+
|
|
70
|
+
if not func_list:
|
|
71
|
+
return
|
|
72
|
+
pyboost_internal_func_h_str = \
|
|
73
|
+
self.pyboost_internal_function_header_template.replace(internal_func_list=func_list)
|
|
74
|
+
save_path = os.path.join(work_path, K.MS_PYBOOST_INTERNAL_FUNCTIONS_AUTO_GEN_PATH)
|
|
75
|
+
file_name = "functions.h"
|
|
76
|
+
save_file(save_path, file_name, pyboost_internal_func_h_str)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Copyright 2025 Huawei Technologies Co., Ltd
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ============================================================================
|
|
15
|
+
"""
|
|
16
|
+
This module defines the `PyboostKernelInfoAdapterGenerator` class, which is used to generate
|
|
17
|
+
files (`kernel_info_adapter.h`, `internal_kernel_info_adapter.h`, `internal_kernel_info_adapter.cc`)
|
|
18
|
+
that contains declarations and definitions for class 'InternalKernelInfoAdapter'.
|
|
19
|
+
|
|
20
|
+
The class uses templates and operation prototypes to create class declarations based on the
|
|
21
|
+
operation's primitive and arguments. The generated file is saved to the specified path.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import os
|
|
25
|
+
|
|
26
|
+
import common.template as template
|
|
27
|
+
from common.template import Template
|
|
28
|
+
import common.gen_constants as K
|
|
29
|
+
from common.gen_utils import save_file
|
|
30
|
+
from common.base_generator import BaseGenerator
|
|
31
|
+
|
|
32
|
+
from .op_template_parser import OpTemplateParser
|
|
33
|
+
|
|
34
|
+
KERNEL_INFO_ADAPTER_REGISTER = \
|
|
35
|
+
"MS_KERNEL_INFO_ADAPTER_REG(${op_name}, Internal${op_name}KernelInfoAdapter, ${op_name}KernelInfoAdapter);\n"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class PyboostKernelInfoAdapterGenerator(BaseGenerator):
|
|
39
|
+
"""
|
|
40
|
+
A class to generate `kernel_info_adapter.h`, `internal_kernel_info_adapter.h` and `internal_kernel_info_adapter.cc`
|
|
41
|
+
which contains class declarations and definitions for internal op in Pyboost.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(self):
|
|
45
|
+
"""Initializes the PyboostKernelInfoAdapterGenerator with the necessary templates."""
|
|
46
|
+
self.kernel_info_adapter_template = template.PYBOOST_KERNEL_INFO_ADAPTER_TEMPLATE
|
|
47
|
+
self.kernel_info_adapter_h_template = template.PYBOOST_KERNEL_INFO_ADAPTER_H_TEMPLATE
|
|
48
|
+
self.internal_kernel_info_adapter_template = template.PYBOOST_INTERNAL_KERNEL_INFO_ADAPTER_TEMPLATE
|
|
49
|
+
self.internal_kernel_info_adapter_h_template = template.PYBOOST_INTERNAL_KERNEL_INFO_ADAPTER_H_TEMPLATE
|
|
50
|
+
self.kernel_info_adapter_single_cpp_template = template.PYBOOST_INTERNAL_KERNEL_INFO_ADAPTER_SINGLE_CPP_TEMPLATE
|
|
51
|
+
self.kernel_info_adapter_cpp_template = template.PYBOOST_INTERNAL_KERNEL_INFO_ADAPTER_CPP_TEMPLATE
|
|
52
|
+
self.kernel_info_adapter_register_template = Template(KERNEL_INFO_ADAPTER_REGISTER)
|
|
53
|
+
self.merged_op_headers_template = Template(
|
|
54
|
+
"#include \"plugin/device/ascend/kernel/internal/pyboost/${operator_name}.h\"\n")
|
|
55
|
+
|
|
56
|
+
def generate(self, work_path, op_protos):
|
|
57
|
+
"""
|
|
58
|
+
Generates the class declarations and definitions for internal op in Pyboost (`kernel_info_adapter.h`,
|
|
59
|
+
`internal_kernel_info_adapter.h`, `internal_kernel_info_adapter.cc`).
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
work_path (str): The directory where the generated file will be saved.
|
|
63
|
+
op_protos (list): A list of operation prototypes to parse.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
None: The method writes the generated files to the specified directory.
|
|
67
|
+
"""
|
|
68
|
+
kernel_info_adapter_list = []
|
|
69
|
+
internal_kernel_info_adapter_list = []
|
|
70
|
+
kernel_info_adapter_cpp_list = []
|
|
71
|
+
kernel_info_adapter_register = []
|
|
72
|
+
merged_op_headers_list = []
|
|
73
|
+
for op_proto in op_protos:
|
|
74
|
+
if op_proto.op_dispatch is None or not op_proto.op_dispatch.enable:
|
|
75
|
+
continue
|
|
76
|
+
if getattr(op_proto.op_dispatch, 'internal_op_ascend') == 'None':
|
|
77
|
+
continue
|
|
78
|
+
op_parser = OpTemplateParser(op_proto)
|
|
79
|
+
call_args_after_convert, _, _ = op_parser.op_args_converter()
|
|
80
|
+
call_args_with_type = op_parser.parse_call_args_with_types(is_convert=True)
|
|
81
|
+
kernel_info_adapter_list.append(
|
|
82
|
+
self.kernel_info_adapter_template.replace(
|
|
83
|
+
op_name=op_proto.op_class.name,
|
|
84
|
+
call_args_with_type=call_args_with_type))
|
|
85
|
+
kernel_info_adapter_list.append(template.NEW_LINE)
|
|
86
|
+
internal_kernel_info_adapter_list.append(
|
|
87
|
+
self.internal_kernel_info_adapter_template.replace(
|
|
88
|
+
op_name=op_proto.op_class.name,
|
|
89
|
+
call_args_with_type=call_args_with_type))
|
|
90
|
+
internal_kernel_info_adapter_list.append(template.NEW_LINE)
|
|
91
|
+
kernel_info_adapter_cpp_list.append(
|
|
92
|
+
self.kernel_info_adapter_single_cpp_template.replace(
|
|
93
|
+
op_name=op_proto.op_class.name,
|
|
94
|
+
call_args_with_type=call_args_with_type,
|
|
95
|
+
call_args_after_convert=call_args_after_convert))
|
|
96
|
+
kernel_info_adapter_cpp_list.append(template.NEW_LINE)
|
|
97
|
+
kernel_info_adapter_register.append(
|
|
98
|
+
self.kernel_info_adapter_register_template.replace(op_name=op_proto.op_class.name))
|
|
99
|
+
merged_op_headers_list.append(self.merged_op_headers_template.replace(operator_name=op_proto.op_name))
|
|
100
|
+
|
|
101
|
+
if not kernel_info_adapter_list:
|
|
102
|
+
return
|
|
103
|
+
kernel_info_adapter_h_str = self.kernel_info_adapter_h_template.replace(
|
|
104
|
+
kernel_info_adapter_list=kernel_info_adapter_list)
|
|
105
|
+
internal_kernel_info_adapter_h_str = self.internal_kernel_info_adapter_h_template.replace(
|
|
106
|
+
internal_kernel_info_adapter_list=internal_kernel_info_adapter_list,
|
|
107
|
+
merged_op_headers=merged_op_headers_list
|
|
108
|
+
)
|
|
109
|
+
kernel_info_adapter_cpp_str = self.kernel_info_adapter_cpp_template.replace(
|
|
110
|
+
kernel_info_adapter_cpp_list=kernel_info_adapter_cpp_list,
|
|
111
|
+
kernel_info_adapter_register=kernel_info_adapter_register
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
self._save_files(work_path, kernel_info_adapter_h_str,
|
|
115
|
+
internal_kernel_info_adapter_h_str, kernel_info_adapter_cpp_str)
|
|
116
|
+
|
|
117
|
+
@staticmethod
|
|
118
|
+
def _save_files(work_path, kernel_info_adapter, kernel_info_adapter_h, kernel_info_adapter_cpp):
|
|
119
|
+
"""
|
|
120
|
+
Save the generated files.
|
|
121
|
+
"""
|
|
122
|
+
save_path = os.path.join(work_path, K.MS_INTERNAL_PYBOOST_GEN_PATH)
|
|
123
|
+
save_file(save_path, "kernel_info_adapter.h", kernel_info_adapter)
|
|
124
|
+
save_file(save_path, "internal_kernel_info_adapter.h", kernel_info_adapter_h)
|
|
125
|
+
save_file(save_path, "internal_kernel_info_adapter.cc", kernel_info_adapter_cpp)
|