From e95bc1b18fda52f69a4ed23c8d52e5df674e005c Mon Sep 17 00:00:00 2001 From: yanghaoran Date: Sat, 28 Nov 2020 17:42:59 +0800 Subject: [PATCH] Synchronize with latest Ascend software suite 28 Nov 2020 --- CMakeLists.txt | 4 +- inc/common/util/error_manager/error_manager.h | 23 + inc/external/ge/ge_api.h | 34 + inc/external/ge/ge_api_error_codes.h | 55 ++ inc/external/ge/ge_api_types.h | 54 +- inc/external/ge/ge_error_codes.h | 58 ++ inc/external/ge/ge_ir_build.h | 15 +- inc/external/graph/ascend_string.h | 16 +- inc/external/graph/attr_value.h | 3 + inc/external/graph/ge_error_codes.h | 6 + inc/external/graph/gnode.h | 90 +- inc/external/graph/graph.h | 26 +- inc/external/graph/inference_context.h | 6 + inc/external/graph/operator.h | 183 +++- inc/external/graph/operator_factory.h | 18 + inc/external/graph/operator_reg.h | 342 +++---- inc/external/graph/tensor.h | 10 + inc/external/register/register.h | 27 + inc/external/register/register_types.h | 6 +- .../scope/scope_fusion_pass_register.h | 75 +- inc/framework/common/debug/ge_log.h | 100 ++- inc/framework/common/ge_compiler_options.h | 32 + inc/framework/common/ge_types.h | 1 + inc/framework/common/string_util.h | 1 + inc/framework/common/types.h | 6 +- inc/framework/omg/omg_inner_types.h | 4 + inc/graph/anchor.h | 4 +- inc/graph/attr_value_serializable.h | 7 +- inc/graph/compiler_options.h | 32 + inc/graph/debug/ge_attr_define.h | 7 + inc/graph/detail/any_map.h | 4 +- inc/graph/op_desc.h | 4 + inc/graph/operator_factory_impl.h | 3 + inc/graph/opsproto_manager.h | 2 - inc/graph/ref_relation.h | 2 +- inc/graph/shape_refiner.h | 2 + inc/graph/tuning_utils.h | 6 +- src/common/graph/CMakeLists.txt | 7 +- src/common/graph/ascend_string.cc | 4 + src/common/graph/attr_value.cc | 10 + src/common/graph/compute_graph.cc | 4 +- src/common/graph/debug/ge_op_types.h | 4 +- src/common/graph/ge_attr_define.cc | 7 + src/common/graph/gnode.cc | 70 +- src/common/graph/graph.cc | 108 ++- src/common/graph/graph.mk | 17 +- src/common/graph/inference_context.cc | 17 + src/common/graph/model.cc | 27 +- src/common/graph/op_desc.cc | 17 +- src/common/graph/op_imp.cc | 1 + src/common/graph/operator.cc | 836 ++++++++++++++++-- src/common/graph/operator_factory.cc | 63 ++ src/common/graph/operator_factory_impl.cc | 39 +- src/common/graph/opsproto/opsproto_manager.cc | 45 +- src/common/graph/shape_refiner.cc | 178 ++-- src/common/graph/tensor.cc | 144 ++- src/common/graph/transformer/inc/axis_util.h | 35 + .../inc/transfer_shape_according_to_format.h | 3 + src/common/graph/transformer/src/axis_util.cc | 106 ++- .../src/transfer_shape_according_to_format.cc | 14 + src/common/graph/utils/ge_ir_utils.cc | 16 +- src/common/graph/utils/graph_utils.cc | 50 +- src/common/graph/utils/op_desc_utils.cc | 2 +- src/common/graph/utils/string_utils.h | 1 + src/common/graph/utils/tensor_utils.cc | 6 +- src/common/graph/utils/transformer_utils.cc | 15 +- src/common/graph/utils/transformer_utils.h | 2 - src/common/graph/utils/tuning_utils.cc | 18 +- src/ge/CMakeLists.txt | 10 + src/ge/client/ge_api.cc | 119 ++- src/ge/common/CMakeLists.txt | 3 + src/ge/common/auth/file_saver.cc | 12 +- src/ge/common/cust_aicpu_kernel_store.cc | 4 +- src/ge/common/debug/memory_dumper.cc | 27 +- .../format_transfer_nchw_fz_c04.cc | 16 +- src/ge/common/ge/op_tiling_manager.cc | 27 +- src/ge/common/ge/plugin_manager.cc | 63 +- src/ge/common/ge/plugin_manager.h | 12 +- src/ge/common/ge/tbe_plugin_manager.cc | 50 +- src/ge/common/ge/tbe_plugin_manager.h | 1 - src/ge/common/ge_common.mk | 18 +- src/ge/common/helper/model_cache_helper.cc | 6 +- src/ge/common/helper/model_helper.cc | 57 +- src/ge/common/helper/om_file_helper.cc | 31 +- src/ge/common/kernel_store.cc | 4 +- src/ge/common/model_parser/base.cc | 31 +- src/ge/common/model_saver.cc | 14 +- src/ge/common/profiling/profiling_manager.cc | 28 +- src/ge/common/properties_manager.h | 9 +- src/ge/common/types.cc | 3 + src/ge/common/util.cc | 78 +- src/ge/engine_manager/dnnengine_manager.cc | 2 +- src/ge/executor/CMakeLists.txt | 0 src/ge/executor/ge_executor.cc | 292 +++--- src/ge/executor/module.mk | 9 +- src/ge/ge_inference.mk | 4 +- .../ge_local_engine/engine/host_cpu_engine.cc | 7 +- src/ge/ge_local_engine/module.mk | 19 + .../ge_local_ops_kernel_builder.cc | 4 +- .../ops_kernel_store/op/no_op.cc | 2 +- src/ge/ge_runner.mk | 2 +- src/ge/ge_runtime/runtime_model.cc | 2 +- src/ge/ge_runtime/task/hccl_task.cc | 3 +- src/ge/generator/ge_generator.cc | 10 +- src/ge/graph/build/graph_builder.cc | 8 +- src/ge/graph/build/label_allocator.cc | 2 +- .../graph/build/logical_stream_allocator.cc | 20 +- src/ge/graph/build/logical_stream_allocator.h | 9 +- .../build/memory/binary_block_mem_assigner.cc | 4 +- .../graph/build/memory/block_mem_assigner.cc | 19 +- .../graph/build/memory/graph_mem_assigner.cc | 195 ++-- .../graph/build/memory/hybrid_mem_assigner.cc | 4 +- src/ge/graph/build/model_builder.cc | 9 +- src/ge/graph/build/run_context.cc | 12 +- src/ge/graph/build/stream_allocator.cc | 13 +- src/ge/graph/build/stream_graph_optimizer.cc | 10 +- src/ge/graph/build/task_generator.cc | 11 +- src/ge/graph/execute/graph_execute.cc | 4 +- src/ge/graph/load/graph_loader.cc | 6 +- .../new_model_manager/cpu_queue_schedule.cc | 2 +- .../load/new_model_manager/data_dumper.cc | 18 +- .../load/new_model_manager/davinci_model.cc | 481 +++++++--- .../load/new_model_manager/davinci_model.h | 21 +- .../load/new_model_manager/model_manager.cc | 124 ++- .../load/new_model_manager/model_manager.h | 13 +- .../load/new_model_manager/model_utils.cc | 10 +- .../task_info/event_record_task_info.cc | 9 +- .../task_info/event_wait_task_info.cc | 10 +- .../task_info/kernel_ex_task_info.cc | 4 +- .../task_info/kernel_task_info.cc | 86 +- .../task_info/super_kernel/super_kernel.cc | 2 +- .../super_kernel/super_kernel_factory.cc | 16 +- .../super_kernel/super_kernel_factory.h | 6 +- .../new_model_manager/zero_copy_offset.cc | 44 +- .../load/new_model_manager/zero_copy_offset.h | 3 +- .../load/new_model_manager/zero_copy_task.cc | 7 +- src/ge/graph/manager/graph_manager.cc | 295 ++++-- src/ge/graph/manager/graph_manager.h | 15 +- src/ge/graph/manager/graph_manager_utils.h | 3 + src/ge/graph/manager/graph_var_manager.cc | 20 +- src/ge/graph/manager/trans_var_data_utils.cc | 10 +- src/ge/graph/manager/util/debug.cc | 7 +- src/ge/graph/manager/util/debug.h | 2 - src/ge/graph/optimize/graph_optimize.cc | 7 +- .../optimize/mem_rw_conflict_optimize.cc | 51 +- .../optimizer/allreduce_fusion_pass.cc | 397 --------- .../optimizer/allreduce_fusion_pass.h | 55 -- src/ge/graph/partition/engine_place.cc | 4 +- src/ge/graph/partition/graph_partition.cc | 27 +- src/ge/graph/passes/atomic_addr_clean_pass.cc | 86 +- src/ge/graph/passes/atomic_addr_clean_pass.h | 6 +- src/ge/graph/passes/compile_nodes_pass.cc | 34 +- src/ge/graph/passes/cond_remove_pass.cc | 2 +- src/ge/graph/passes/data_pass.cc | 148 +++- src/ge/graph/passes/data_pass.h | 3 + src/ge/graph/passes/flow_ctrl_pass.cc | 5 +- src/ge/graph/passes/mark_agnostic_pass.cc | 11 + .../passes/mark_graph_unknown_status_pass.cc | 9 + src/ge/graph/passes/memcpy_addr_async_pass.cc | 4 +- src/ge/graph/passes/merge_pass.cc | 33 + src/ge/graph/passes/merge_pass.h | 1 + src/ge/graph/passes/multi_batch_clone_pass.cc | 15 +- src/ge/graph/passes/multi_batch_pass.cc | 4 +- .../passes/set_input_output_offset_pass.cc | 4 +- src/ge/graph/preprocess/graph_preprocess.cc | 31 +- src/ge/graph/preprocess/graph_preprocess.h | 1 + .../preprocess/multi_batch_copy_graph.cc | 710 +++++++++++---- .../graph/preprocess/multi_batch_copy_graph.h | 35 +- .../graph/preprocess/multi_batch_options.cc | 276 ++++++ src/ge/graph/preprocess/multi_batch_options.h | 15 + src/ge/host_cpu_engine/module.mk | 20 + src/ge/host_kernels/empty_kernel.cc | 2 +- src/ge/host_kernels/fill_kernel.cc | 4 +- src/ge/host_kernels/floordiv_kernel.cc | 4 +- src/ge/host_kernels/strided_slice_kernel.cc | 46 +- src/ge/host_kernels/strided_slice_kernel.h | 3 + .../executor/hybrid_execution_context.h | 20 +- .../executor/hybrid_model_async_executor.cc | 8 +- src/ge/hybrid/executor/rt_callback_manager.cc | 3 +- src/ge/hybrid/executor/subgraph_executor.cc | 2 +- .../executor/worker/shape_inference_engine.cc | 3 +- src/ge/hybrid/model/hybrid_model_builder.cc | 18 +- .../aicore/aicore_node_executor.cc | 3 + .../node_executor/aicpu/aicpu_ext_info.cc | 36 + .../node_executor/aicpu/aicpu_ext_info.h | 8 + .../aicpu/aicpu_node_executor.cc | 44 +- .../node_executor/aicpu/aicpu_node_executor.h | 2 +- src/ge/hybrid/node_executor/node_executor.cc | 21 +- src/ge/init/gelib.cc | 10 +- src/ge/ir_build/atc_ir_common.cc | 2 +- src/ge/ir_build/ge_ir_build.cc | 69 +- src/ge/omm/csa_interact.cc | 16 +- .../opskernel_manager/ops_kernel_manager.cc | 4 +- src/ge/session/inner_session.cc | 18 + src/ge/session/inner_session.h | 4 + src/ge/session/session_manager.cc | 48 +- src/ge/session/session_manager.h | 3 + src/ge/single_op/single_op.cc | 70 +- src/ge/single_op/single_op.h | 4 - src/ge/single_op/single_op_manager.cc | 16 +- src/ge/single_op/single_op_model.cc | 89 +- src/ge/single_op/single_op_model.h | 4 +- src/ge/single_op/stream_resource.cc | 4 +- .../task/aicpu_kernel_task_builder.cc | 16 +- .../task/aicpu_kernel_task_builder.h | 2 +- src/ge/single_op/task/aicpu_task_builder.cc | 44 +- src/ge/single_op/task/aicpu_task_builder.h | 2 +- src/ge/single_op/task/op_task.cc | 14 +- src/ge/single_op/task/op_task.h | 2 +- src/ge/single_op/task/tbe_task_builder.cc | 49 +- third_party/fwkacllib/inc/cce/aicpu_engine.h | 15 +- .../fwkacllib/inc/cce/aicpu_engine_struct.h | 6 + .../fwkacllib/inc/cce/fwk_adpt_struct.h | 4 +- third_party/fwkacllib/inc/hccl/hcom.h | 17 +- .../fwkacllib/inc/register/op_registry.h | 8 + .../fwkacllib/inc/register/op_tiling.h | 113 +-- .../inc/register/op_tiling_registry.h | 153 ++++ .../register/ops_kernel_builder_registry.h | 2 + third_party/fwkacllib/inc/runtime/base.h | 11 +- third_party/fwkacllib/inc/runtime/config.h | 8 + third_party/fwkacllib/inc/runtime/dev.h | 4 +- third_party/fwkacllib/inc/runtime/rt.h | 2 +- third_party/fwkacllib/inc/tdt/status.h | 7 + 223 files changed, 6164 insertions(+), 2544 deletions(-) create mode 100644 inc/external/ge/ge_error_codes.h create mode 100644 inc/framework/common/ge_compiler_options.h create mode 100644 inc/graph/compiler_options.h mode change 100755 => 100644 src/ge/executor/CMakeLists.txt delete mode 100644 src/ge/graph/optimize/optimizer/allreduce_fusion_pass.cc delete mode 100644 src/ge/graph/optimize/optimizer/allreduce_fusion_pass.h create mode 100644 third_party/fwkacllib/inc/register/op_tiling_registry.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 92727a24..3793dada 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ elseif(DEFINED ENV{D_LINK_PATH}) endif() set(GE_LIB_PATH ${GE_LIB_PATH}/${GE_SYS_ARCH}) find_library(slog libslog.so ${GE_LIB_PATH}) - find_library(mmpa libmmpa.so ${GE_LIB_PATH}) + find_library(mmpa libmmpa.a ${GE_LIB_PATH}) find_library(runtime libruntime.so ${GE_LIB_PATH}) find_library(msprof libmsprofiler.a ${GE_LIB_PATH}) find_library(register libregister.so ${GE_LIB_PATH}) @@ -84,7 +84,7 @@ else() set(ASCEND_DRIVER_DIR ${ASCEND_DIR}/driver/lib64/common ${ASCEND_DIR}/driver/lib64) set(ASCEND_RUNTIME_DIR ${ASCEND_DIR}/fwkacllib/lib64 ${ASCEND_DIR}/acllib/lib64 ${ASCEND_DIR}/atc/lib64) find_library(slog libslog.so ${ASCEND_DRIVER_DIR}) - find_library(mmpa libmmpa.so ${ASCEND_DRIVER_DIR}) + find_library(mmpa libmmpa.a ${ASCEND_RUNTIME_DIR}) find_library(msprof libmsprofiler.a ${ASCEND_RUNTIME_DIR}) find_library(hccl libhccl.so ${ASCEND_RUNTIME_DIR}) diff --git a/inc/common/util/error_manager/error_manager.h b/inc/common/util/error_manager/error_manager.h index 185f84cc..53644b5b 100644 --- a/inc/common/util/error_manager/error_manager.h +++ b/inc/common/util/error_manager/error_manager.h @@ -67,6 +67,28 @@ class ErrorManager { void ATCReportErrMessage(std::string error_code, const std::vector &key = {}, const std::vector &value = {}); + /// + /// @brief report graph compile failed message such as error code and op_name in mstune case + /// @param [in] msg: failed message map, key is error code, value is op_name + /// @return int 0(success) -1(fail) + /// + int ReportMstuneCompileFailedMsg(const std::map &msg); + + /// + /// @brief save graph compile failed message from thread local map to global map + /// @param [in] graph_name: graph name + /// + void SaveMstuneCompileFailedMsg(const std::string &graph_name); + + /// + /// @brief get graph compile failed message in mstune case + /// @param [in] graph_name: graph name + /// @param [out] msg_map: failed message map, key is error code, value is op_name list + /// @return int 0(success) -1(fail) + /// + int GetMstuneCompileFailedMsg(const std::string &graph_name, + std::map> &msg_map); + private: struct ErrorInfo { std::string error_id; @@ -91,6 +113,7 @@ class ErrorManager { std::map error_map_; std::vector error_messages_; std::vector warning_messages_; + std::map>> compile_failed_msg_map_; }; #endif // ERROR_MANAGER_H_ diff --git a/inc/external/ge/ge_api.h b/inc/external/ge/ge_api.h index 8fd4b944..9c26ebf8 100644 --- a/inc/external/ge/ge_api.h +++ b/inc/external/ge/ge_api.h @@ -29,16 +29,26 @@ namespace ge { typedef uint32_t (*pCallBackFunc)(uint32_t graph_id, const std::map ¶ms_list); +namespace session { +typedef uint32_t (*pCallBackFunc)(uint32_t graph_id, const std::map ¶ms_list); +} + // Initialize GE +ATTRIBUTED_DEPRECATED(Status GEInitialize(const std::map &)) Status GEInitialize(const std::map &options); +Status GEInitialize(const std::map &options); + // Finalize GE, release all resources Status GEFinalize(); class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Session { public: + ATTRIBUTED_DEPRECATED(Session(const std::map &)) explicit Session(const std::map &options); + explicit Session(const std::map &options); + ~Session(); /// @@ -57,8 +67,19 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Session { /// @param [in] options graph options /// @return Status result of function /// + ATTRIBUTED_DEPRECATED(Status AddGraph(uint32_t, const Graph &, const std::map &)) Status AddGraph(uint32_t graphId, const Graph &graph, const std::map &options); + /// + /// @ingroup client + /// @brief add a graph with a specific graphId and graphOptions + /// @param [in] graphId graph id + /// @param [in] graph the graph + /// @param [in] options graph options + /// @return Status result of function + /// + Status AddGraph(uint32_t graphId, const Graph &graph, const std::map &options); + /// /// @ingroup client /// @brief add a copy graph with a specific graphId @@ -124,8 +145,18 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Session { /// @param [out] var_values: variable values /// @return Status result of function /// + ATTRIBUTED_DEPRECATED(Status GetVariables(const std::vector &, std::vector &)) Status GetVariables(const std::vector &var_names, std::vector &var_values); + /// + /// @ingroup ge_graph + /// @brief get variables in the session with specific session id + /// @param [in] var_names: variable names + /// @param [out] var_values: variable values + /// @return Status result of function + /// + Status GetVariables(const std::vector &var_names, std::vector &var_values); + /// /// @ingroup ge_graph /// @brief register callback func with specific summary or checkpoint by users @@ -135,8 +166,11 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Session { /// Please ensure that the implementation of the function is trusted. /// @return Status result of function /// + ATTRIBUTED_DEPRECATED(Status RegisterCallBackFunc(const char *, const session::pCallBackFunc &)) Status RegisterCallBackFunc(const std::string &key, const pCallBackFunc &callback); + Status RegisterCallBackFunc(const char *key, const session::pCallBackFunc &callback); + bool IsGraphNeedRebuild(uint32_t graphId); private: diff --git a/inc/external/ge/ge_api_error_codes.h b/inc/external/ge/ge_api_error_codes.h index e7f52724..18cfa3eb 100644 --- a/inc/external/ge/ge_api_error_codes.h +++ b/inc/external/ge/ge_api_error_codes.h @@ -19,8 +19,15 @@ #include #include +#include "ge_error_codes.h" namespace ge { +#ifdef __GNUC__ +#define ATTRIBUTED_DEPRECATED(replacement) __attribute__((deprecated("Please use " #replacement " instead."))) +#else +#define ATTRIBUTED_DEPRECATED(replacement) __declspec(deprecated("Please use " #replacement " instead.")) +#endif + class StatusFactory { public: static StatusFactory *Instance() { @@ -36,6 +43,17 @@ class StatusFactory { err_desc_[err] = desc; } + void RegisterErrorNo(uint32_t err, const char *desc) { + if (desc == nullptr) { + return; + } + std::string error_desc = desc; + if (err_desc_.find(err) != err_desc_.end()) { + return; + } + err_desc_[err] = error_desc; + } + std::string GetErrDesc(uint32_t err) { auto iter_find = err_desc_.find(err); if (iter_find == err_desc_.end()) { @@ -55,6 +73,7 @@ class StatusFactory { class ErrorNoRegisterar { public: ErrorNoRegisterar(uint32_t err, const std::string &desc) { StatusFactory::Instance()->RegisterErrorNo(err, desc); } + ErrorNoRegisterar(uint32_t err, const char *desc) { StatusFactory::Instance()->RegisterErrorNo(err, desc); } ~ErrorNoRegisterar() {} }; @@ -66,11 +85,47 @@ class ErrorNoRegisterar { ((0xFF & (static_cast(modid))) << 12) | (0x0FFF & (static_cast(value))); \ const ErrorNoRegisterar g_##name##_errorno(name, desc); +#define GE_ERRORNO_EXTERNAL(name, desc) const ErrorNoRegisterar g_##name##_errorno(name, desc); + using Status = uint32_t; // General error code GE_ERRORNO(0, 0, 0, 0, 0, SUCCESS, 0, "success"); GE_ERRORNO(0b11, 0b11, 0b111, 0xFF, 0b11111, FAILED, 0xFFF, "failed"); + +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_PARAM_INVALID, "Parameter invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_NOT_INIT, "GE executor not initialized yet."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID, "Model file path invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, "Model id invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_KEY_PATH_INVALID, "Model key path invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_NOT_SUPPORT_ENCRYPTION, "Model does not support encryption."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "Data size of model invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID, "Model addr invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID, "Queue id of model invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_LOAD_MODEL_REPEATED, "The model loaded repeatedly."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_MODEL_PARTITION_NUM_INVALID, "Model partition num invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, "Dynamic input addr invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, "Dynamic input size invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, "Dynamic batch size invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_AIPP_BATCH_EMPTY, "AIPP batch parameter empty."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_AIPP_NOT_EXIST, "AIPP parameter not exist."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_AIPP_MODE_INVALID, "AIPP mode invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_OP_TASK_TYPE_INVALID, "Task type invalid."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID, "Kernel type invalid."); + +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_MEMORY_ALLOCATION, "Memory allocation error."); + +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_INTERNAL_ERROR, "Internal error."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_LOAD_MODEL, "Load model error."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_LOAD_MODEL_PARTITION_FAILED, "Failed to load model partition."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED, "Failed to load weight partition."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED, "Failed to load task partition."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_LOAD_KERNEL_PARTITION_FAILED, "Failed to load op kernel partition."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_EXEC_RELEASE_MODEL_DATA, "Failed to release the model data."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_COMMAND_HANDLE, "Command handle error."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_GET_TENSOR_INFO, "Get tensor info error."); +GE_ERRORNO_EXTERNAL(ACL_ERROR_GE_UNLOAD_MODEL, "Load model error."); + } // namespace ge #endif // INC_EXTERNAL_GE_GE_API_ERROR_CODES_H_ diff --git a/inc/external/ge/ge_api_types.h b/inc/external/ge/ge_api_types.h index 37e2dccf..c439a8bf 100644 --- a/inc/external/ge/ge_api_types.h +++ b/inc/external/ge/ge_api_types.h @@ -65,7 +65,47 @@ const char *const OPTION_EXEC_ENABLE_TAILING_OPTIMIZATION = "ge.exec.isTailingOp // Option key: memory init const char *const GRAPH_MEMORY_MAX_SIZE = "ge.graphMemoryMaxSize"; const char *const VARIABLE_MEMORY_MAX_SIZE = "ge.variableMemoryMaxSize"; - +namespace configure_option { +const char *const STREAM_NUM = "ge.streamNum"; +const char *const HEAD_STREAM = "ge.headStream"; +const char *const PERF_LEVEL = "ge.perfLevel"; +const char *const ENCRYPT_MODE = "ge.encryptMode"; +const char *const EK_FILE = "ge.ekFile"; +const char *const CERT_FILE = "ge.certFile"; +const char *const HW_KEY_FILE = "ge.hwKeyFile"; +const char *const PRIVATE_KEY_FILE = "ge.privateKeyFile"; +const char *const FRAMEWORK_TYPE = "ge.frameworkType"; +const char *const CALIBRATION_CONF_FILE = "ge.calibrationConfFile"; +const char *const INSERT_OP_FILE = "ge.insertOpFile"; +const char *const OUTPUT_NODE_NAME = "ge.outputNodeName"; +const char *const COMPRESS_FLAG = "ge.compressFlag"; +const char *const PRECISION_MODE = "ge.exec.precision_mode"; +const char *const SINGLE_OP_FLAG = "ge.exec.single_op"; +const char *const TRAIN_FLAG = "ge.trainFlag"; +const char *const RUN_FLAG = "ge.runFlag"; +const char *const LOCAL_FMKOP_FLAG = "ge.enabledLocalFmkop"; +const char *const TBE_PLUGIN_PATH_FLAG = "ge.TBE_plugin_path"; +const char *const DDK_VERSION_FLAG = "ge.DDK_version"; +const char *const GE_FE_FLAG = "ge.feFlag"; +const char *const STREAM_MAX_PARALLEL_NUM = "ge.streamMaxParallelNum"; +const char *const OUTPUT_DATATYPE = "ge.outputDatatype"; +const char *const OP_SELECT_IMPL_MODE = "ge.opSelectImplmode"; +const char *const OPTYPELIST_FOR_IMPLMODE = "ge.optypelistForImplmode"; +const char *const HCOM_PARALLEL = "ge.hcomParallel"; +const char *const AUTO_TUNE_MODE = "ge.autoTuneMode"; +const char *const SOC_VERSION = "ge.socVersion"; +const char *const CORE_TYPE = "ge.engineType"; +const char *const AICORE_NUM = "ge.aicoreNum"; +const char *const L1_FUSION = "ge.l1Fusion"; +const char *const BUFFER_OPTIMIZE = "ge.bufferOptimize"; +const char *const ENABLE_SMALL_CHANNEL = "ge.enableSmallChannel"; +const char *const ENABLE_COMPRESS_WEIGHT = "ge.enableCompressWeight"; +const char *const FUSION_SWITCH_FILE = "ge.fusionSwitchFile"; +const char *const SAVE_ORIGINAL_MODEL = "ge.saveOriginalModel"; +const char *const ORIGINAL_MODEL_FILE = "ge.originalModelFile"; +const char *const INPUT_FP16_NODES = "ge.INPUT_NODES_SET_FP16"; +const char *const OP_DEBUG_LEVEL = "ge.opDebugLevel"; +} // namespace configure_option // Configure stream num by Session constructor options param, // its value should be int32_t type, default value is "1" const std::string STREAM_NUM = "ge.streamNum"; @@ -174,6 +214,9 @@ const std::string HCOM_PARALLEL = "ge.hcomParallel"; // configure whether to use dynamic batch size const char *const kDynamicBatchSize = "ge.dynamicBatchSize"; +const std::string INPUT_SHAPE = "ge.inputShape"; + +const std::string DYNAMIC_NODE_TYPE = "ge.dynamicNodeType"; // configure whether to use dynamic image size const char *const kDynamicImageSize = "ge.dynamicImageSize"; @@ -323,6 +366,7 @@ static const char *const OP_COMPILER_CACHE_DIR = ge::OP_COMPILER_CACHE_DIR; static const char *const OP_COMPILER_CACHE_MODE = ge::OP_COMPILER_CACHE_MODE; static const char *const MDL_BANK_PATH_FLAG = ge::MDL_BANK_PATH_FLAG.c_str(); static const char *const OP_BANK_PATH_FLAG = ge::OP_BANK_PATH_FLAG.c_str(); +static const char *const OP_DEBUG_LEVEL = ge::OP_DEBUG_LEVEL.c_str(); // for interface: aclgrphBuildModel const std::set ir_builder_suppported_options = {INPUT_FORMAT, @@ -342,7 +386,9 @@ const std::set ir_builder_suppported_options = {INPUT_FORMAT, OP_DEBUG_LEVEL, DEBUG_DIR, OP_COMPILER_CACHE_DIR, - OP_COMPILER_CACHE_MODE}; + OP_COMPILER_CACHE_MODE, + MDL_BANK_PATH_FLAG, + OP_BANK_PATH_FLAG}; // for interface: aclgrphParse const std::set ir_parser_suppported_options = {INPUT_FORMAT, @@ -357,9 +403,7 @@ const std::set ir_parser_suppported_options = {INPUT_FORMAT, OUT_NODES, COMPRESS_WEIGHT_CONF, ENABLE_SCOPE_FUSION_PASSES, - LOG_LEVEL, - MDL_BANK_PATH_FLAG, - OP_BANK_PATH_FLAG}; + LOG_LEVEL}; // for interface: aclgrphBuildInitialize const std::set global_options = {CORE_TYPE, diff --git a/inc/external/ge/ge_error_codes.h b/inc/external/ge/ge_error_codes.h new file mode 100644 index 00000000..30631d8b --- /dev/null +++ b/inc/external/ge/ge_error_codes.h @@ -0,0 +1,58 @@ +/** + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INC_EXTERNAL_GE_GE_ERROR_CODES_H_ +#define INC_EXTERNAL_GE_GE_ERROR_CODES_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif +static const uint32_t ACL_ERROR_GE_PARAM_INVALID = 145000; +static const uint32_t ACL_ERROR_GE_EXEC_NOT_INIT = 145001; +static const uint32_t ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID = 145002; +static const uint32_t ACL_ERROR_GE_EXEC_MODEL_ID_INVALID = 145003; +static const uint32_t ACL_ERROR_GE_EXEC_MODEL_KEY_PATH_INVALID = 145004; +static const uint32_t ACL_ERROR_GE_EXEC_MODEL_NOT_SUPPORT_ENCRYPTION = 145005; +static const uint32_t ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID = 145006; +static const uint32_t ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID = 145007; +static const uint32_t ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID = 145008; +static const uint32_t ACL_ERROR_GE_EXEC_LOAD_MODEL_REPEATED = 145009; +static const uint32_t ACL_ERROR_GE_EXEC_MODEL_PARTITION_NUM_INVALID = 145010; +static const uint32_t ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID = 145011; +static const uint32_t ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID = 145012; +static const uint32_t ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID = 145013; +static const uint32_t ACL_ERROR_GE_AIPP_BATCH_EMPTY = 145014; +static const uint32_t ACL_ERROR_GE_AIPP_NOT_EXIST = 145015; +static const uint32_t ACL_ERROR_GE_AIPP_MODE_INVALID = 145016; +static const uint32_t ACL_ERROR_GE_OP_TASK_TYPE_INVALID = 145017; +static const uint32_t ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID = 145018; +static const uint32_t ACL_ERROR_GE_MEMORY_ALLOCATION = 245000; +static const uint32_t ACL_ERROR_GE_INTERNAL_ERROR = 545000; +static const uint32_t ACL_ERROR_GE_LOAD_MODEL = 545001; +static const uint32_t ACL_ERROR_GE_EXEC_LOAD_MODEL_PARTITION_FAILED = 545002; +static const uint32_t ACL_ERROR_GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED = 545003; +static const uint32_t ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED = 545004; +static const uint32_t ACL_ERROR_GE_EXEC_LOAD_KERNEL_PARTITION_FAILED = 545005; +static const uint32_t ACL_ERROR_GE_EXEC_RELEASE_MODEL_DATA = 545006; +static const uint32_t ACL_ERROR_GE_COMMAND_HANDLE = 545007; +static const uint32_t ACL_ERROR_GE_GET_TENSOR_INFO = 545008; +static const uint32_t ACL_ERROR_GE_UNLOAD_MODEL = 545009; +#ifdef __cplusplus +} // namespace ge +#endif +#endif // INC_EXTERNAL_GE_GE_ERROR_CODES_H_ diff --git a/inc/external/ge/ge_ir_build.h b/inc/external/ge/ge_ir_build.h index f3b3a3a3..4364acf3 100644 --- a/inc/external/ge/ge_ir_build.h +++ b/inc/external/ge/ge_ir_build.h @@ -44,8 +44,11 @@ struct ModelBufferData { * @retval GRAPH_SUCCESS The function is successfully executed. * @retval OtherValues Failure */ +ATTRIBUTED_DEPRECATED(graphStatus aclgrphBuildInitialize(std::map &)) graphStatus aclgrphBuildInitialize(std::map global_options); +graphStatus aclgrphBuildInitialize(std::map &global_options); + /** * @ingroup AscendCL * @brief build model.Notice the model is stored in buffer @@ -63,9 +66,14 @@ void aclgrphBuildFinalize(); * @retval GRAPH_SUCCESS The function is successfully executed. * @retval OtherValues Failure */ +ATTRIBUTED_DEPRECATED(graphStatus aclgrphBuildModel(const ge::Graph &, const std::map &, + ModelBufferData &)) graphStatus aclgrphBuildModel(const ge::Graph &graph, const std::map &build_options, ModelBufferData &model); +graphStatus aclgrphBuildModel(const ge::Graph &graph, const std::map &build_options, + ModelBufferData &model); + /** * @ingroup AscendCL * @brief save model buffer to file @@ -75,8 +83,11 @@ graphStatus aclgrphBuildModel(const ge::Graph &graph, const std::map #include +#include namespace ge { class AscendString { @@ -27,7 +28,7 @@ class AscendString { ~AscendString() = default; - explicit AscendString(const char* name); + AscendString(const char* name); const char* GetString() const; @@ -47,4 +48,17 @@ class AscendString { std::shared_ptr name_; }; } // namespace ge + +namespace std { +template <> +struct hash { + size_t operator()(const ge::AscendString& name) const { + std::string str_name; + if (name.GetString() != nullptr) { + str_name = name.GetString(); + } + return hash()(str_name); + } +}; +} // namespace std #endif // INC_EXTERNAL_GRAPH_ASCEND_STRING_H_ diff --git a/inc/external/graph/attr_value.h b/inc/external/graph/attr_value.h index 32fce04c..cf3a14ce 100644 --- a/inc/external/graph/attr_value.h +++ b/inc/external/graph/attr_value.h @@ -23,6 +23,7 @@ #include #include "./ge_error_codes.h" +#include "ascend_string.h" using std::make_shared; using std::map; @@ -60,6 +61,8 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY AttrValue { return val; } + graphStatus GetValue(AscendString &val); + std::shared_ptr impl; private: diff --git a/inc/external/graph/ge_error_codes.h b/inc/external/graph/ge_error_codes.h index 26e0d70b..ca2a40f6 100644 --- a/inc/external/graph/ge_error_codes.h +++ b/inc/external/graph/ge_error_codes.h @@ -28,10 +28,16 @@ namespace ge { #else #define GE_FUNC_DEV_VISIBILITY #endif +#ifdef __GNUC__ +#define ATTRIBUTED_DEPRECATED(replacement) __attribute__((deprecated("Please use " #replacement " instead."))) +#else +#define ATTRIBUTED_DEPRECATED(replacement) __declspec(deprecated("Please use " #replacement " instead.")) +#endif using graphStatus = uint32_t; const graphStatus GRAPH_FAILED = 0xFFFFFFFF; const graphStatus GRAPH_SUCCESS = 0; +const graphStatus GRAPH_NOT_CHANGED = 1343242304; const graphStatus GRAPH_PARAM_INVALID = 50331649; const graphStatus GRAPH_NODE_WITHOUT_CONST_INPUT = 50331648; } // namespace ge diff --git a/inc/external/graph/gnode.h b/inc/external/graph/gnode.h index 14fb604c..cbf8bfb3 100644 --- a/inc/external/graph/gnode.h +++ b/inc/external/graph/gnode.h @@ -44,9 +44,9 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GNode { ~GNode() = default; - graphStatus GetType(ge::AscendString &type) const; + graphStatus GetType(AscendString &type) const; - graphStatus GetName(ge::AscendString &name) const; + graphStatus GetName(AscendString &name) const; std::pair GetInDataNodesAndPortIndexs(const int32_t index) const; @@ -58,9 +58,9 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GNode { graphStatus GetInputConstData(const int32_t index, Tensor &data) const; - graphStatus GetInputIndexByName(const ge::AscendString &name, int32_t &index); + graphStatus GetInputIndexByName(const AscendString &name, int32_t &index); - graphStatus GetOutputIndexByName(const ge::AscendString &name, int32_t &index); + graphStatus GetOutputIndexByName(const AscendString &name, int32_t &index); size_t GetInputsSize() const; @@ -74,47 +74,47 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GNode { graphStatus UpdateOutputDesc(const int32_t index, const TensorDesc &tensor_desc); - graphStatus GetAttr(const ge::AscendString &name, int64_t &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, int32_t &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, uint32_t &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, float &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, ge::AscendString &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, bool &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, Tensor &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, std::vector &attr_values) const; - graphStatus GetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, OpBytes &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, std::vector> &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, ge::DataType &attr_value) const; - graphStatus GetAttr(const ge::AscendString &name, AttrValue &attr_value) const; - - graphStatus SetAttr(const ge::AscendString &name, int64_t &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, int32_t &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, uint32_t &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, float &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, ge::AscendString &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, bool &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, Tensor &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, std::vector &attr_values) const; - graphStatus SetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, OpBytes &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, std::vector> &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, std::vector &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, ge::DataType &attr_value) const; - graphStatus SetAttr(const ge::AscendString &name, AttrValue &attr_value) const; - - bool HasAttr(const ge::AscendString &name); + graphStatus GetAttr(const AscendString &name, int64_t &attr_value) const; + graphStatus GetAttr(const AscendString &name, int32_t &attr_value) const; + graphStatus GetAttr(const AscendString &name, uint32_t &attr_value) const; + graphStatus GetAttr(const AscendString &name, float &attr_value) const; + graphStatus GetAttr(const AscendString &name, AscendString &attr_value) const; + graphStatus GetAttr(const AscendString &name, bool &attr_value) const; + graphStatus GetAttr(const AscendString &name, Tensor &attr_value) const; + graphStatus GetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus GetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus GetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus GetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus GetAttr(const AscendString &name, std::vector &attr_values) const; + graphStatus GetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus GetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus GetAttr(const AscendString &name, OpBytes &attr_value) const; + graphStatus GetAttr(const AscendString &name, std::vector> &attr_value) const; + graphStatus GetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus GetAttr(const AscendString &name, ge::DataType &attr_value) const; + graphStatus GetAttr(const AscendString &name, AttrValue &attr_value) const; + + graphStatus SetAttr(const AscendString &name, int64_t &attr_value) const; + graphStatus SetAttr(const AscendString &name, int32_t &attr_value) const; + graphStatus SetAttr(const AscendString &name, uint32_t &attr_value) const; + graphStatus SetAttr(const AscendString &name, float &attr_value) const; + graphStatus SetAttr(const AscendString &name, AscendString &attr_value) const; + graphStatus SetAttr(const AscendString &name, bool &attr_value) const; + graphStatus SetAttr(const AscendString &name, Tensor &attr_value) const; + graphStatus SetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus SetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus SetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus SetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus SetAttr(const AscendString &name, std::vector &attr_values) const; + graphStatus SetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus SetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus SetAttr(const AscendString &name, OpBytes &attr_value) const; + graphStatus SetAttr(const AscendString &name, std::vector> &attr_value) const; + graphStatus SetAttr(const AscendString &name, std::vector &attr_value) const; + graphStatus SetAttr(const AscendString &name, ge::DataType &attr_value) const; + graphStatus SetAttr(const AscendString &name, AttrValue &attr_value) const; + + bool HasAttr(const AscendString &name); graphStatus GetSubgraph(uint32_t index, GraphPtr &graph) const; diff --git a/inc/external/graph/graph.h b/inc/external/graph/graph.h index c6d1346b..07a6bcb8 100644 --- a/inc/external/graph/graph.h +++ b/inc/external/graph/graph.h @@ -36,8 +36,11 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Graph { friend class GraphUtils; public: + ATTRIBUTED_DEPRECATED(Graph(const char *)) explicit Graph(const std::string &name); + explicit Graph(const char *name); + Graph() = default; ~Graph() = default; @@ -48,26 +51,47 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Graph { Graph &SetOutputs(const std::vector>> &output_indexs); + ATTRIBUTED_DEPRECATED(Graph &SetOutputs(const std::vector < std::pair < ge::Operator, AscendString) &) Graph &SetOutputs(const std::vector> &outputs); + Graph &SetOutputs(const std::vector> &outputs); + Graph &SetTargets(const std::vector &targets); bool IsValid() const; graphStatus AddOp(const ge::Operator &op); + ATTRIBUTED_DEPRECATED(graphStatus FindOpByName(const char *, ge::Operator &)) graphStatus FindOpByName(const std::string &name, ge::Operator &op) const; + graphStatus FindOpByName(const char *name, ge::Operator &op) const; + + ATTRIBUTED_DEPRECATED(graphStatus FindOpByType(const char *, std::vector &)) graphStatus FindOpByType(const std::string &type, std::vector &ops) const; + graphStatus FindOpByType(const char *type, std::vector &ops) const; + + ATTRIBUTED_DEPRECATED(graphStatus GetAllOpName(std::vector &) const) graphStatus GetAllOpName(std::vector &op_name) const; + graphStatus GetAllOpName(std::vector &names) const; + + ATTRIBUTED_DEPRECATED(graphStatus SaveToFile(const char *file_name) const) graphStatus SaveToFile(const std::string &file_name) const; + graphStatus SaveToFile(const char *file_name) const; + + ATTRIBUTED_DEPRECATED(graphStatus LoadFromFile(const char *)) graphStatus LoadFromFile(const std::string &file_name); + graphStatus LoadFromFile(const char *file_name); + + ATTRIBUTED_DEPRECATED(graphStatus GetName(AscendString &) const) const std::string &GetName() const; + graphStatus GetName(AscendString &name) const; + /// /// Set is need train iteration. /// If set true, it means this graph need to be run iteration some @@ -90,7 +114,7 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Graph { graphStatus AddControlEdge(GNode &src_node, GNode &dst_node); - static GraphPtr ConstructFromInputs(const std::vector &inputs, const ge::AscendString &name); + static GraphPtr ConstructFromInputs(const std::vector &inputs, const AscendString &name); private: GraphImplPtr impl_{nullptr}; diff --git a/inc/external/graph/inference_context.h b/inc/external/graph/inference_context.h index 69079142..7c2cac2e 100644 --- a/inc/external/graph/inference_context.h +++ b/inc/external/graph/inference_context.h @@ -23,6 +23,7 @@ #include "./tensor.h" #include "./types.h" +#include "ascend_string.h" namespace ge { class InferenceContext; @@ -63,8 +64,13 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InferenceContext { void SetOutputHandleShapesAndTypes(const std::vector> &shapes_and_types); void SetOutputHandleShapesAndTypes(std::vector> &&shapes_and_types); + ATTRIBUTED_DEPRECATED(void SetMarks(const std::vector &)) void SetMarks(const std::vector &marks); + void SetMarks(const std::vector &marks); + + ATTRIBUTED_DEPRECATED(void GetMarks(std::vector &) const) const std::vector &GetMarks() const; + void GetMarks(std::vector &marks) const; static std::unique_ptr Create(); diff --git a/inc/external/graph/operator.h b/inc/external/graph/operator.h index 042898c0..63959a8e 100644 --- a/inc/external/graph/operator.h +++ b/inc/external/graph/operator.h @@ -72,6 +72,7 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Operator { using OpInt = int64_t; using OpFloat = float; using OpString = string; + using OpAscendString = AscendString; using OpBool = bool; using OpTensor = Tensor; using OpType = ge::DataType; @@ -79,6 +80,7 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Operator { using OpListInt = std::vector; using OpListFloat = std::vector; using OpListString = std::vector; + using OpListAcendString = std::vector; using OpListBool = std::vector; using OpListTensor = std::vector; using OpBytes = std::vector; @@ -87,56 +89,114 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Operator { using OpListNamedAttrs = std::vector; Operator() {} - + ATTRIBUTED_DEPRECATED(Operator(const char *)) explicit Operator(const string &type); + explicit Operator(const char *type); + + ATTRIBUTED_DEPRECATED(Operator(const AscendString &, const AscendString &)) Operator(const string &name, const string &type); + Operator(const AscendString &name, const AscendString &type); + + Operator(const char *name, const char *type); + virtual ~Operator() = default; bool IsEmpty() const; + ATTRIBUTED_DEPRECATED(graphStatus GetName(AscendString &) const) string GetName() const; + graphStatus GetName(AscendString &name) const; + + ATTRIBUTED_DEPRECATED(graphStatus GetOpType(AscendString &) const) string GetOpType() const; + graphStatus GetOpType(AscendString &type) const; + // Only has one output index = 0 + ATTRIBUTED_DEPRECATED(Operator &SetInput(const char *, const Operator &)) Operator &SetInput(const string &dst_name, const Operator &src_oprt); + Operator &SetInput(const char *dst_name, const Operator &src_oprt); + + ATTRIBUTED_DEPRECATED(Operator &SetInput(const char *, const Operator &, const char *)) Operator &SetInput(const string &dst_name, const Operator &src_oprt, const string &name); + Operator &SetInput(const char *dst_name, const Operator &src_oprt, const char *name); + + ATTRIBUTED_DEPRECATED(Operator &SetInput(const char *, const Operator &, uint32_t)) Operator &SetInput(const string &dst_name, const Operator &src_oprt, uint32_t index); + Operator &SetInput(const char *dst_name, const Operator &src_oprt, uint32_t index); + Operator &AddControlInput(const Operator &src_oprt); + ATTRIBUTED_DEPRECATED(graphStatus GetInputConstData(const char *, Tensor &) const) graphStatus GetInputConstData(const string &dst_name, Tensor &data) const; + graphStatus GetInputConstData(const char *dst_name, Tensor &data) const; + + ATTRIBUTED_DEPRECATED(TensorDesc GetInputDesc(const char *, uint32_t len) const) TensorDesc GetInputDesc(const string &name) const; + TensorDesc GetInputDesc(const char *name, uint32_t len) const; + TensorDesc GetInputDesc(uint32_t index) const; + ATTRIBUTED_DEPRECATED(int GetDynamicOutputNum(const char *) const) int GetDynamicOutputNum(const string &name) const; + int GetDynamicOutputNum(const char *name) const; + + ATTRIBUTED_DEPRECATED(int GetDynamicInputNum(const char *)) int GetDynamicInputNum(const string &name) const; + int GetDynamicInputNum(const char *name) const; + + ATTRIBUTED_DEPRECATED(graphStatus TryGetInputDesc(const char *, TensorDesc &) const) graphStatus TryGetInputDesc(const string &name, TensorDesc &tensor_desc) const; + graphStatus TryGetInputDesc(const char *name, TensorDesc &tensor_desc) const; + + ATTRIBUTED_DEPRECATED(graphStatus UpdateInputDesc(const char *, const TensorDesc &)) graphStatus UpdateInputDesc(const string &name, const TensorDesc &tensor_desc); + graphStatus UpdateInputDesc(const char *name, const TensorDesc &tensor_desc); + + ATTRIBUTED_DEPRECATED(TensorDesc GetOutputDesc(const char *, uint32_t len) const) TensorDesc GetOutputDesc(const string &name) const; + TensorDesc GetOutputDesc(const char *name, uint32_t len) const; + TensorDesc GetOutputDesc(uint32_t index) const; + ATTRIBUTED_DEPRECATED(graphStatus UpdateOutputDesc(const char *, const TensorDesc &tensor_desc)) graphStatus UpdateOutputDesc(const string &name, const TensorDesc &tensor_desc); + graphStatus UpdateOutputDesc(const char *name, const TensorDesc &tensor_desc); + + ATTRIBUTED_DEPRECATED(TensorDesc GetDynamicInputDesc(const char *, uint32_t) const) TensorDesc GetDynamicInputDesc(const string &name, uint32_t index) const; + TensorDesc GetDynamicInputDesc(const char *name, uint32_t index) const; + + ATTRIBUTED_DEPRECATED(graphStatus UpdateDynamicInputDesc(const char *, uint32_t, const TensorDesc &)) graphStatus UpdateDynamicInputDesc(const string &name, uint32_t index, const TensorDesc &tensor_desc); + graphStatus UpdateDynamicInputDesc(const char *name, uint32_t index, const TensorDesc &tensor_desc); + + ATTRIBUTED_DEPRECATED(TensorDesc GetDynamicOutputDesc(const char *, uint32_t) const) TensorDesc GetDynamicOutputDesc(const string &name, uint32_t index) const; + TensorDesc GetDynamicOutputDesc(const char *name, uint32_t index) const; + + ATTRIBUTED_DEPRECATED(graphStatus UpdateDynamicOutputDesc(const char *, uint32_t, const TensorDesc &)) graphStatus UpdateDynamicOutputDesc(const string &name, uint32_t index, const TensorDesc &tensor_desc); + graphStatus UpdateDynamicOutputDesc(const char *name, uint32_t index, const TensorDesc &tensor_desc); + graphStatus InferShapeAndType(); void SetInferenceContext(const InferenceContextPtr &inference_context); @@ -148,72 +208,178 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Operator { size_t GetOutputsSize() const; + ATTRIBUTED_DEPRECATED(graphStatus GetAllAttrNamesAndTypes(std::map &) const) const std::map GetAllAttrNamesAndTypes() const; + graphStatus GetAllAttrNamesAndTypes(std::map &attr_name_types) const; + + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, int64_t)) Operator &SetAttr(const string &name, int64_t attr_value); + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, int32_t)) Operator &SetAttr(const string &name, int32_t attr_value); + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, uint32_t)) Operator &SetAttr(const string &name, uint32_t attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, int64_t &) const) graphStatus GetAttr(const string &name, int64_t &attr_value) const; + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, int32_t &) const) graphStatus GetAttr(const string &name, int32_t &attr_value) const; + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, uint32_t &) const) graphStatus GetAttr(const string &name, uint32_t &attr_value) const; + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const std::vector &)) Operator &SetAttr(const string &name, const std::vector &attr_value); + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const std::vector &)) Operator &SetAttr(const string &name, const std::vector &attr_value); + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const std::vector &)) Operator &SetAttr(const string &name, const std::vector &attr_value); + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, std::initializer_list &&)) Operator &SetAttr(const string &name, std::initializer_list &&attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *name, std::vector &) const) graphStatus GetAttr(const string &name, std::vector &attr_value) const; + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *name, std::vector &) const) graphStatus GetAttr(const string &name, std::vector &attr_value) const; + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const string &, std::vector &) const) graphStatus GetAttr(const string &name, std::vector &attr_value) const; - + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, float attr_value)) Operator &SetAttr(const string &name, float attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, float &) const) graphStatus GetAttr(const string &name, float &attr_value) const; + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const std::vector &)) Operator &SetAttr(const string &name, const std::vector &attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, std::vector &) const) graphStatus GetAttr(const string &name, std::vector &attr_value) const; + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, AttrValue &&)) Operator &SetAttr(const string &name, AttrValue &&attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, AttrValue &) const) graphStatus GetAttr(const string &name, AttrValue &attr_value) const; - + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const AscendString &)) Operator &SetAttr(const string &name, const string &attr_value); + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const string &)) graphStatus GetAttr(const string &name, string &attr_value) const; + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const std::vector &)) Operator &SetAttr(const string &name, const std::vector &attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const string &, std::vector &) const) graphStatus GetAttr(const string &name, std::vector &attr_value) const; - + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, bool)) Operator &SetAttr(const string &name, bool attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, bool &) const) graphStatus GetAttr(const string &name, bool &attr_value) const; + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const std::vector &)) Operator &SetAttr(const string &name, const std::vector &attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, std::vector &) const) graphStatus GetAttr(const string &name, std::vector &attr_value) const; - + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const Tensor &)) Operator &SetAttr(const string &name, const Tensor &attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, Tensor &) const) graphStatus GetAttr(const string &name, Tensor &attr_value) const; + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const std::vector &)) Operator &SetAttr(const string &name, const std::vector &attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, std::vector &) const) graphStatus GetAttr(const string &name, std::vector &attr_value) const; // Bytes type + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const OpBytes &)) Operator &SetAttr(const string &name, const OpBytes &attr_value); // Bytes type + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, OpBytes &) const) graphStatus GetAttr(const string &name, OpBytes &attr_value) const; - + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const std::vector> &)) Operator &SetAttr(const string &name, const std::vector> &attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, std::vector> &) const) graphStatus GetAttr(const string &name, std::vector> &attr_value) const; - + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const std::vector &)) Operator &SetAttr(const string &name, const std::vector &attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, std::vector &) const) graphStatus GetAttr(const string &name, std::vector &attr_value) const; - + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const ge::DataType &)) Operator &SetAttr(const string &name, const ge::DataType &attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, ge::DataType &) const) graphStatus GetAttr(const string &name, ge::DataType &attr_value) const; // func type + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const ge::NamedAttrs &)) Operator &SetAttr(const string &name, const ge::NamedAttrs &attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, ge::NamedAttrs &) const) graphStatus GetAttr(const string &name, ge::NamedAttrs &attr_value) const; + ATTRIBUTED_DEPRECATED(Operator &SetAttr(const char *, const std::vector &)) Operator &SetAttr(const string &name, const std::vector &attr_value); + ATTRIBUTED_DEPRECATED(graphStatus GetAttr(const char *, std::vector &) const) graphStatus GetAttr(const string &name, std::vector &attr_value) const; + Operator &SetAttr(const char *name, int64_t attr_value); + Operator &SetAttr(const char *name, int32_t attr_value); + Operator &SetAttr(const char *name, uint32_t attr_value); + graphStatus GetAttr(const char *name, int64_t &attr_value) const; + graphStatus GetAttr(const char *name, int32_t &attr_value) const; + graphStatus GetAttr(const char *name, uint32_t &attr_value) const; + Operator &SetAttr(const char *name, const std::vector &attr_value); + Operator &SetAttr(const char *name, const std::vector &attr_value); + Operator &SetAttr(const char *name, const std::vector &attr_value); + Operator &SetAttr(const char *name, std::initializer_list &&attr_value); + graphStatus GetAttr(const char *name, std::vector &attr_value) const; + graphStatus GetAttr(const char *name, std::vector &attr_value) const; + graphStatus GetAttr(const char *name, std::vector &attr_value) const; + + Operator &SetAttr(const char *name, float attr_value); + graphStatus GetAttr(const char *name, float &attr_value) const; + Operator &SetAttr(const char *name, const std::vector &attr_value); + graphStatus GetAttr(const char *name, std::vector &attr_value) const; + Operator &SetAttr(const char *name, AttrValue &&attr_value); + graphStatus GetAttr(const char *name, AttrValue &attr_value) const; + + Operator &SetAttr(const char *name, const char *attr_value); + Operator &SetAttr(const char *name, const AscendString &attr_value); + graphStatus GetAttr(const char *name, AscendString &attr_value) const; + Operator &SetAttr(const char *name, const std::vector &attr_values); + graphStatus GetAttr(const char *name, std::vector &attr_values) const; + + Operator &SetAttr(const char *name, bool attr_value); + graphStatus GetAttr(const char *name, bool &attr_value) const; + Operator &SetAttr(const char *name, const std::vector &attr_value); + graphStatus GetAttr(const char *name, std::vector &attr_value) const; + + Operator &SetAttr(const char *name, const Tensor &attr_value); + graphStatus GetAttr(const char *name, Tensor &attr_value) const; + Operator &SetAttr(const char *name, const std::vector &attr_value); + graphStatus GetAttr(const char *name, std::vector &attr_value) const; + + // Bytes type + Operator &SetAttr(const char *name, const OpBytes &attr_value); + // Bytes type + graphStatus GetAttr(const char *name, OpBytes &attr_value) const; + + Operator &SetAttr(const char *name, const std::vector> &attr_value); + graphStatus GetAttr(const char *name, std::vector> &attr_value) const; + + Operator &SetAttr(const char *name, const std::vector &attr_value); + graphStatus GetAttr(const char *name, std::vector &attr_value) const; + + Operator &SetAttr(const char *name, const ge::DataType &attr_value); + graphStatus GetAttr(const char *name, ge::DataType &attr_value) const; + + // func type + Operator &SetAttr(const char *name, const ge::NamedAttrs &attr_value); + graphStatus GetAttr(const char *name, ge::NamedAttrs &attr_value) const; + Operator &SetAttr(const char *name, const std::vector &attr_value); + graphStatus GetAttr(const char *name, std::vector &attr_value) const; + void BreakConnect() const; size_t GetSubgraphNamesCount() const; + ATTRIBUTED_DEPRECATED(graphStatus GetSubgraphNames(std::vector &) const) std::vector GetSubgraphNames() const; + graphStatus GetSubgraphNames(std::vector &names) const; + ATTRIBUTED_DEPRECATED(SubgraphBuilder GetSubgraphBuilder(const char *) const) SubgraphBuilder GetSubgraphBuilder(const string &name) const; + SubgraphBuilder GetSubgraphBuilder(const char *name) const; + ATTRIBUTED_DEPRECATED(Graph GetSubgraph(const char *) const) Graph GetSubgraph(const string &name) const; + Graph GetSubgraph(const char *name) const; + ATTRIBUTED_DEPRECATED(SubgraphBuilder GetDynamicSubgraphBuilder(const char *, uint32_t) const) SubgraphBuilder GetDynamicSubgraphBuilder(const string &name, uint32_t index) const; + SubgraphBuilder GetDynamicSubgraphBuilder(const char *name, uint32_t index) const; + ATTRIBUTED_DEPRECATED(Graph GetDynamicSubgraph(const char *, uint32_t) const) Graph GetDynamicSubgraph(const string &name, uint32_t index) const; + Graph GetDynamicSubgraph(const char *name, uint32_t index) const; protected: void AttrRegister(const string &name, float attr_value); @@ -265,6 +431,7 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Operator { void SubgraphRegister(const string &ir_name, bool dynamic); void SubgraphCountRegister(const string &ir_name, uint32_t count); void SetSubgraphBuilder(const string &ir_name, uint32_t index, const SubgraphBuilder &builder); + Graph GetSubgraphImpl(const string &name) const; private: Operator &SetInput(const string &dst_name, const OutHandler &out_handler); diff --git a/inc/external/graph/operator_factory.h b/inc/external/graph/operator_factory.h index f9ec7669..82326572 100644 --- a/inc/external/graph/operator_factory.h +++ b/inc/external/graph/operator_factory.h @@ -27,40 +27,58 @@ namespace ge { using OpCreator = std::function; +using OpCreatorV2 = std::function; using InferShapeFunc = std::function; using InferFormatFunc = std::function; using VerifyFunc = std::function; class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OperatorFactory { public: + ATTRIBUTED_DEPRECATED(static Operator CreateOperator(const char *, const char *)) static Operator CreateOperator(const std::string &operator_name, const std::string &operator_type); + static Operator CreateOperator(const char *operator_name, const char *operator_type); + + ATTRIBUTED_DEPRECATED(graphStatus GetOpsTypeList(std::vector &)) static graphStatus GetOpsTypeList(std::vector &all_ops); + static graphStatus GetOpsTypeList(std::vector &all_ops); + + ATTRIBUTED_DEPRECATED(bool IsExistOp(const char *)) static bool IsExistOp(const string &operator_type); + + static bool IsExistOp(const char *operator_type); }; class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OperatorCreatorRegister { public: + ATTRIBUTED_DEPRECATED(OperatorCreatorRegister(const char *, OpCreatorV2 const &)) OperatorCreatorRegister(const string &operator_type, OpCreator const &op_creator); + OperatorCreatorRegister(const char *operator_type, OpCreatorV2 const &op_creator); ~OperatorCreatorRegister() = default; }; class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InferShapeFuncRegister { public: + ATTRIBUTED_DEPRECATED(InferShapeFuncRegister(const char *, const InferShapeFunc &)) InferShapeFuncRegister(const std::string &operator_type, const InferShapeFunc &infer_shape_func); + InferShapeFuncRegister(const char *operator_type, const InferShapeFunc &infer_shape_func); ~InferShapeFuncRegister() = default; }; class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InferFormatFuncRegister { public: + ATTRIBUTED_DEPRECATED(InferFormatFuncRegister(const char *, const InferFormatFunc &)) InferFormatFuncRegister(const std::string &operator_type, const InferFormatFunc &infer_format_func); + InferFormatFuncRegister(const char *operator_type, const InferFormatFunc &infer_format_func); ~InferFormatFuncRegister() = default; }; class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY VerifyFuncRegister { public: + ATTRIBUTED_DEPRECATED(VerifyFuncRegister(const char *, const VerifyFunc &)) VerifyFuncRegister(const std::string &operator_type, const VerifyFunc &verify_func); + VerifyFuncRegister(const char *operator_type, const VerifyFunc &verify_func); ~VerifyFuncRegister() = default; }; } // namespace ge diff --git a/inc/external/graph/operator_reg.h b/inc/external/graph/operator_reg.h index 759c70f2..b87b0e35 100644 --- a/inc/external/graph/operator_reg.h +++ b/inc/external/graph/operator_reg.h @@ -54,144 +54,167 @@ class OpReg { OpReg &INFER_SHAPE_AND_TYPE() { return *this; } }; -#define REG_OP(x) \ - namespace op { \ - class x : public Operator { \ - typedef x _THIS_TYPE; \ - \ - public: \ - explicit x(const string &name) : Operator(name, #x) { __##x(); } \ - x() : Operator(#x) { __##x(); } \ - \ - private: \ - void __##x() { \ +#define REG_OP(x) \ + namespace op { \ + class x : public Operator { \ + typedef x _THIS_TYPE; \ + \ + public: \ + ATTRIBUTED_DEPRECATED(x(const AscendString &)) \ + explicit x(const string &name) : Operator(name, #x) { __##x(); } \ + explicit x(const char *name) : Operator(name, #x) { __##x(); } \ + explicit x(const AscendString &name) : Operator(name, #x) { __##x(); } \ + x() : Operator(#x) { __##x(); } \ + \ + private: \ + void __##x() { \ OpReg() -#define ATTR(x, Type, ...) \ - N(); \ - __attr_##x(); \ - } \ - \ - public: \ - static const string name_attr_##x() { return #x; } \ - Op##Type get_attr_##x() const { \ - Op##Type ret = __VA_ARGS__; \ - if (Operator::GetAttr(#x, ret) == GRAPH_FAILED) { \ - return ret; \ - } \ - return ret; \ - } \ - _THIS_TYPE &set_attr_##x(const Op##Type &v) { \ - Operator::SetAttr(#x, v); \ - return *this; \ - } \ - _THIS_TYPE &set_attr_##x(const function &v) { return *this; } \ - \ - private: \ - void __attr_##x() { \ - Operator::AttrRegister(#x, Op##Type(__VA_ARGS__)); \ - string attr_name(#x); \ +#define ATTR(x, Type, ...) \ + N(); \ + __attr_##x(); \ + } \ + \ + public: \ + ATTRIBUTED_DEPRECATED(static const void name_attr_##x(AscendString &)) \ + static const string name_attr_##x() { return #x; } \ + static const void name_attr_##x(AscendString &attr) { attr = AscendString(#x); } \ + Op##Type get_attr_##x() const { \ + Op##Type ret = __VA_ARGS__; \ + if (Operator::GetAttr(#x, ret) == GRAPH_FAILED) { \ + return ret; \ + } \ + return ret; \ + } \ + _THIS_TYPE &set_attr_##x(const Op##Type &v) { \ + Operator::SetAttr(#x, v); \ + return *this; \ + } \ + _THIS_TYPE &set_attr_##x(const function &v) { return *this; } \ + \ + private: \ + void __attr_##x() { \ + Operator::AttrRegister(#x, Op##Type(__VA_ARGS__)); \ + string attr_name(#x); \ (void)OpReg() -#define REQUIRED_ATTR(x, Type) \ - N(); \ - __required_attr_##x(); \ - } \ - \ - public: \ - static const string name_attr_##x() { return #x; } \ - Op##Type get_attr_##x() const { \ - Op##Type ret; \ - if (Operator::GetAttr(#x, ret) == GRAPH_FAILED) { \ - return ret; \ - } \ - return ret; \ - } \ - _THIS_TYPE &set_attr_##x(const Op##Type &v) { \ - Operator::SetAttr(#x, v); \ - return *this; \ - } \ - _THIS_TYPE &set_attr_##x(const function &v) { return *this; } \ - \ - private: \ - void __required_attr_##x() { \ - Operator::RequiredAttrRegister(#x); \ - string attr_name(#x); \ +#define REQUIRED_ATTR(x, Type) \ + N(); \ + __required_attr_##x(); \ + } \ + \ + public: \ + ATTRIBUTED_DEPRECATED(static const void name_attr_##x(AscendString &)) \ + static const string name_attr_##x() { return #x; } \ + static const void name_attr_##x(AscendString &attr_name) { attr_name = AscendString(#x); } \ + Op##Type get_attr_##x() const { \ + Op##Type ret; \ + if (Operator::GetAttr(#x, ret) == GRAPH_FAILED) { \ + return ret; \ + } \ + return ret; \ + } \ + _THIS_TYPE &set_attr_##x(const Op##Type &v) { \ + Operator::SetAttr(#x, v); \ + return *this; \ + } \ + _THIS_TYPE &set_attr_##x(const function &v) { return *this; } \ + \ + private: \ + void __required_attr_##x() { \ + Operator::RequiredAttrRegister(#x); \ + string attr_name(#x); \ (void)OpReg() -#define INPUT(x, t) \ - N(); \ - __input_##x(); \ - } \ - \ - public: \ - static const string name_in_##x() { return #x; } \ - _THIS_TYPE &set_input_##x(Operator &v, const string &srcName) { \ - Operator::SetInput(#x, v, srcName); \ - return *this; \ - } \ - _THIS_TYPE &set_input_##x(Operator &v, uint32_t index) { \ - Operator::SetInput(#x, v, index); \ - return *this; \ - } \ - _THIS_TYPE &set_input_##x(Operator &v) { \ - Operator::SetInput(#x, v); \ - return *this; \ - } \ - TensorDesc get_input_desc_##x() const { return Operator::GetInputDesc(#x); } \ - graphStatus update_input_desc_##x(const TensorDesc &tensorDesc) { \ - return Operator::UpdateInputDesc(#x, tensorDesc); \ - } \ - \ - private: \ - void __input_##x() { \ - Operator::InputRegister(#x); \ +#define INPUT(x, t) \ + N(); \ + __input_##x(); \ + } \ + \ + public: \ + ATTRIBUTED_DEPRECATED(static const void name_in_##x(AscendString &)) \ + static const string name_in_##x() { return #x; } \ + static const void name_in_##x(AscendString &name) { name = AscendString(#x); } \ + ATTRIBUTED_DEPRECATED(_THIS_TYPE &set_input_##x(Operator &, const char *)) \ + _THIS_TYPE &set_input_##x(Operator &v, const string &srcName) { \ + Operator::SetInput(#x, v, srcName); \ + return *this; \ + } \ + _THIS_TYPE &set_input_##x(Operator &v, const char *srcName) { \ + Operator::SetInput(#x, v, srcName); \ + return *this; \ + } \ + _THIS_TYPE &set_input_##x(Operator &v, uint32_t index) { \ + Operator::SetInput(#x, v, index); \ + return *this; \ + } \ + _THIS_TYPE &set_input_##x(Operator &v) { \ + Operator::SetInput(#x, v); \ + return *this; \ + } \ + TensorDesc get_input_desc_##x() const { return Operator::GetInputDesc(#x, 0); } \ + graphStatus update_input_desc_##x(const TensorDesc &tensorDesc) { \ + return Operator::UpdateInputDesc(#x, tensorDesc); \ + } \ + \ + private: \ + void __input_##x() { \ + Operator::InputRegister(#x); \ (void)OpReg() -#define OPTIONAL_INPUT(x, t) \ - N(); \ - __optional_input_##x(); \ - } \ - \ - public: \ - static const string name_in_##x() { return #x; } \ - _THIS_TYPE &set_input_##x(Operator &v) { \ - Operator::SetInput(#x, v); \ - return *this; \ - } \ - _THIS_TYPE &set_input_##x(Operator &v, const string &srcName) { \ - Operator::SetInput(#x, v, srcName); \ - return *this; \ - } \ - _THIS_TYPE &set_input_##x(Operator &v, uint32_t index) { \ - Operator::SetInput(#x, v, index); \ - return *this; \ - } \ - TensorDesc get_input_desc_##x() const { return Operator::GetInputDesc(#x); } \ - graphStatus update_input_desc_##x(const TensorDesc &tensorDesc) { \ - return Operator::UpdateInputDesc(#x, tensorDesc); \ - } \ - \ - private: \ - void __optional_input_##x() { \ - Operator::OptionalInputRegister(#x); \ +#define OPTIONAL_INPUT(x, t) \ + N(); \ + __optional_input_##x(); \ + } \ + \ + public: \ + ATTRIBUTED_DEPRECATED(static const void name_in_##x(AscendString &)) \ + static const string name_in_##x() { return #x; } \ + static const void name_in_##x(AscendString &name) { name = AscendString(#x); } \ + _THIS_TYPE &set_input_##x(Operator &v) { \ + Operator::SetInput(#x, v); \ + return *this; \ + } \ + ATTRIBUTED_DEPRECATED(_THIS_TYPE &set_input_##x(Operator &, const char *)) \ + _THIS_TYPE &set_input_##x(Operator &v, const string &srcName) { \ + Operator::SetInput(#x, v, srcName); \ + return *this; \ + } \ + _THIS_TYPE &set_input_##x(Operator &v, const char *srcName) { \ + Operator::SetInput(#x, v, srcName); \ + return *this; \ + } \ + _THIS_TYPE &set_input_##x(Operator &v, uint32_t index) { \ + Operator::SetInput(#x, v, index); \ + return *this; \ + } \ + TensorDesc get_input_desc_##x() const { return Operator::GetInputDesc(#x, 0); } \ + graphStatus update_input_desc_##x(const TensorDesc &tensorDesc) { \ + return Operator::UpdateInputDesc(#x, tensorDesc); \ + } \ + \ + private: \ + void __optional_input_##x() { \ + Operator::OptionalInputRegister(#x); \ (void)OpReg() -#define OUTPUT(x, t) \ - N(); \ - __out_##x(); \ - } \ - \ - public: \ - static const string name_out_##x() { return #x; } \ - TensorDesc get_output_desc_##x() const { return Operator::GetOutputDesc(#x); } \ - graphStatus update_output_desc_##x(const TensorDesc &tensorDesc) { \ - return Operator::UpdateOutputDesc(#x, tensorDesc); \ - } \ - \ - private: \ - void __out_##x() { \ - Operator::OutputRegister(#x); \ +#define OUTPUT(x, t) \ + N(); \ + __out_##x(); \ + } \ + \ + public: \ + ATTRIBUTED_DEPRECATED(static const void name_out_##x(AscendString &)) \ + static const string name_out_##x() { return #x; } \ + static const void name_out_##x(AscendString &name) { name = AscendString(#x); } \ + TensorDesc get_output_desc_##x() const { return Operator::GetOutputDesc(#x, 0); } \ + graphStatus update_output_desc_##x(const TensorDesc &tensorDesc) { \ + return Operator::UpdateOutputDesc(#x, tensorDesc); \ + } \ + \ + private: \ + void __out_##x() { \ + Operator::OutputRegister(#x); \ (void)OpReg() #define DYNAMIC_INPUT(x, t) \ @@ -216,9 +239,14 @@ class OpReg { Operator::SetInput(#x, dstIndex, v); \ return *this; \ } \ + ATTRIBUTED_DEPRECATED(_THIS_TYPE &set_dynamic_input_##x(uint32_t, Operator &, const char *)) \ _THIS_TYPE &set_dynamic_input_##x(uint32_t dstIndex, Operator &v, const string &srcName) { \ Operator::SetInput(#x, dstIndex, v, srcName); \ return *this; \ + } \ + _THIS_TYPE &set_dynamic_input_##x(uint32_t dstIndex, Operator &v, const char *srcName) { \ + Operator::SetInput(#x, dstIndex, v, srcName); \ + return *this; \ } \ \ private: \ @@ -252,7 +280,9 @@ class OpReg { } \ \ public: \ + ATTRIBUTED_DEPRECATED(static const void name_graph_##x(AscendString &)) \ static const string name_graph_##x() { return #x; } \ + static const void name_graph_##x(AscendString &name) { name = AscendString(#x); } \ SubgraphBuilder get_subgraph_builder_##x() const { return Operator::GetSubgraphBuilder(#x); } \ _THIS_TYPE &set_subgraph_builder_##x(const SubgraphBuilder &v) { \ Operator::SetSubgraphBuilder(#x, 0, v); \ @@ -272,7 +302,9 @@ class OpReg { } \ \ public: \ + ATTRIBUTED_DEPRECATED(static const void name_graph_##x(AscendString &)) \ static const string name_graph_##x() { return #x; } \ + static const void name_graph_##x(AscendString &name) { name = AscendString(#x); } \ _THIS_TYPE &create_dynamic_subgraph_##x(uint32_t num) { \ Operator::SubgraphCountRegister(#x, num); \ return *this; \ @@ -292,15 +324,15 @@ class OpReg { (void)OpReg() #define PASTE(g_register, y) g_register##y -#define __OP_END_IMPL__(x, y) \ - N(); \ - } \ - static_assert( \ - std::is_same::value, \ - "The class name entered into the OP_END_FACTORY_REG needs to be the same as the operator name you define."); \ - } \ - ; \ - static const OperatorCreatorRegister PASTE(g_register, y)(#x, [](const std::string &name) { return x(name); }); \ +#define __OP_END_IMPL__(x, y) \ + N(); \ + } \ + static_assert( \ + std::is_same::value, \ + "The class name entered into the OP_END_FACTORY_REG needs to be the same as the operator name you define."); \ + } \ + ; \ + static const OperatorCreatorRegister PASTE(g_register, y)(#x, [](const AscendString &name) { return x(name); }); \ } #define OP_END_FACTORY_REG(x) __OP_END_IMPL__(x, __COUNTER__) @@ -347,30 +379,30 @@ class OpReg { // Common shape inferencer -#define ELMTWISE_INFER_SHAPEANDTYPE(in_name, out_name) \ - [](Operator op) -> graphStatus { \ - auto x_shape = op.GetInputDesc(in_name).GetShape().GetDims(); \ - auto x_type = op.GetInputDesc(in_name).GetDataType(); \ - TensorDesc op_output_desc = op.GetOutputDesc(out_name); \ - op_output_desc.SetShape(ge::Shape(x_shape)); \ - op_output_desc.SetOriginShape(ge::Shape(x_shape)); \ - op_output_desc.SetDataType(x_type); \ - return op.UpdateOutputDesc(out_name, op_output_desc); \ +#define ELMTWISE_INFER_SHAPEANDTYPE(in_name, out_name) \ + [](Operator op) -> graphStatus { \ + auto x_shape = op.GetInputDesc(in_name, 0).GetShape().GetDims(); \ + auto x_type = op.GetInputDesc(in_name, 0).GetDataType(); \ + TensorDesc op_output_desc = op.GetOutputDesc(out_name, 0); \ + op_output_desc.SetShape(ge::Shape(x_shape)); \ + op_output_desc.SetOriginShape(ge::Shape(x_shape)); \ + op_output_desc.SetDataType(x_type); \ + return op.UpdateOutputDesc(out_name, op_output_desc); \ } graphStatus BroadCastInfer(const function()> &get_in1_shape, const function()> &get_in2_shape, const function &y_shape)> &set_out_shape); -#define BROADCAST_INFER(in1_name, in2_name, out_name) \ - [](Operator op) -> graphStatus { \ - return BroadCastInfer([&]() { return op.GetInputDesc(in1_name).GetShape().GetDims(); }, \ - [&]() { return op.GetInputDesc(in2_name).GetShape().GetDims(); }, \ - [&](const vector &y_shape) { \ - TensorDesc op_output_desc = op.GetOutputDesc(out_name); \ - op_output_desc.SetShape(ge::Shape(y_shape)); \ - (void)op.UpdateOutputDesc(out_name, op_output_desc); \ - }); \ +#define BROADCAST_INFER(in1_name, in2_name, out_name) \ + [](Operator op) -> graphStatus { \ + return BroadCastInfer([&]() { return op.GetInputDesc(in1_name, 0).GetShape().GetDims(); }, \ + [&]() { return op.GetInputDesc(in2_name, 0).GetShape().GetDims(); }, \ + [&](const vector &y_shape) { \ + TensorDesc op_output_desc = op.GetOutputDesc(out_name, 0); \ + op_output_desc.SetShape(ge::Shape(y_shape)); \ + (void)op.UpdateOutputDesc(out_name, op_output_desc); \ + }); \ } } // namespace ge #endif // INC_EXTERNAL_GRAPH_OPERATOR_REG_H_ diff --git a/inc/external/graph/tensor.h b/inc/external/graph/tensor.h index 5174c248..e199fb6a 100644 --- a/inc/external/graph/tensor.h +++ b/inc/external/graph/tensor.h @@ -25,6 +25,7 @@ #include "./ge_error_codes.h" #include "./types.h" +#include "ascend_string.h" namespace ge { class ShapeImpl; @@ -81,8 +82,13 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY TensorDesc { DataType GetDataType() const; void SetDataType(DataType dt); + ATTRIBUTED_DEPRECATED(graphStatus GetName(AscendString &)) std::string GetName() const; + graphStatus GetName(AscendString &name); + + ATTRIBUTED_DEPRECATED(void SetName(const char *)) void SetName(const std::string &name); + void SetName(const char *name); // Attr acess void SetSize(int64_t size); @@ -115,8 +121,12 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Tensor { graphStatus SetData(std::vector &&data); graphStatus SetData(const std::vector &data); graphStatus SetData(const uint8_t *data, size_t size); + ATTRIBUTED_DEPRECATED(graphStatus SetData(const char *data)) graphStatus SetData(const std::string &data); + graphStatus SetData(const char *data); + ATTRIBUTED_DEPRECATED(graphStatus SetData(const std::vector &)) graphStatus SetData(const std::vector &data); + graphStatus SetData(const std::vector &datas); graphStatus IsValid(); Tensor Clone() const; diff --git a/inc/external/register/register.h b/inc/external/register/register.h index 74b282c7..96202ae1 100644 --- a/inc/external/register/register.h +++ b/inc/external/register/register.h @@ -76,7 +76,10 @@ struct DynamicInputOutputInfo { Status AutoMappingByOpFn(const ge::Operator &op_src, ge::Operator &op); Status AutoMappingByOpFnDynamic(const ge::Operator &op_src, ge::Operator &op, const vector &dynamic_name_attr_value); +ATTRIBUTED_DEPRECATED(Status AutoMappingByOpFn(const ge::Operator &, ge::Operator &)) Status AutoMappingFn(const google::protobuf::Message *op_src, ge::Operator &op); +ATTRIBUTED_DEPRECATED(Status AutoMappingByOpFnDynamic(const ge::Operator &, ge::Operator &, + const vector &)) Status AutoMappingFnDynamic(const google::protobuf::Message *op_src, ge::Operator &op, std::map> dynamic_name_attr_value, int in_pos = -1, int out_pos = -1); @@ -95,19 +98,29 @@ using FusionParseParamFunc = using FusionParseParamByOpFunc = std::function &, ge::Operator &)>; using ParseSubgraphFunc = std::function; using ParseOpToGraphFunc = std::function; +using ParseSubgraphFuncV2 = std::function; class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistrationData { public: + ATTRIBUTED_DEPRECATED(OpRegistrationData(const char *)) OpRegistrationData(const std::string &om_optype); + OpRegistrationData(const char *om_optype); + ~OpRegistrationData(); OpRegistrationData &FrameworkType(const domi::FrameworkType &fmk_type); + ATTRIBUTED_DEPRECATED(OpRegistrationData &OriginOpType(const std::vector &)) OpRegistrationData &OriginOpType(const std::initializer_list &ori_optype_list); + OpRegistrationData &OriginOpType(const std::vector &ori_op_type_list); + + ATTRIBUTED_DEPRECATED(OpRegistrationData &OriginOpType(const char *)) OpRegistrationData &OriginOpType(const std::string &ori_optype); + OpRegistrationData &OriginOpType(const char *ori_op_type); + OpRegistrationData &ParseParamsFn(const ParseParamFunc &parseParamFn); OpRegistrationData &ParseParamsByOperatorFn(const ParseParamByOpFunc &parse_param_by_op_fn); @@ -116,21 +129,34 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistrationData { OpRegistrationData &FusionParseParamsFn(const FusionParseParamByOpFunc &fusion_parse_param_fn); + ATTRIBUTED_DEPRECATED(OpRegistrationData &ParseSubgraphPostFn(const ParseSubgraphFuncV2 &)) OpRegistrationData &ParseSubgraphPostFn(const ParseSubgraphFunc &subgraph_post_fn); + OpRegistrationData &ParseSubgraphPostFn(const ParseSubgraphFuncV2 &subgraph_post_fn); + OpRegistrationData &ImplyType(const domi::ImplyType &imply_type); + ATTRIBUTED_DEPRECATED(OpRegistrationData &DelInputWithCond(int, const char *, bool)) OpRegistrationData &DelInputWithCond(int inputIdx, const std::string &attrName, bool attrValue); + OpRegistrationData &DelInputWithCond(int input_idx, const char *attr_name, bool attr_value); + + ATTRIBUTED_DEPRECATED(OpRegistrationData &DelInputWithOriginalType(int, const char *)) OpRegistrationData &DelInputWithOriginalType(int input_idx, const std::string &ori_type); + OpRegistrationData &DelInputWithOriginalType(int input_idx, const char *ori_type); + OpRegistrationData &InputReorderVector(const vector &input_order); OpRegistrationData &ParseOpToGraphFn(const ParseOpToGraphFunc &parse_op_to_graph_fn); domi::ImplyType GetImplyType() const; + ATTRIBUTED_DEPRECATED(Status GetOmOptype(ge::AscendString &) const) std::string GetOmOptype() const; + Status GetOmOptype(ge::AscendString &om_op_type) const; + ATTRIBUTED_DEPRECATED(GetOriginOpTypeSet(std::set &) const) std::set GetOriginOpTypeSet() const; + Status GetOriginOpTypeSet(std::set &ori_op_type) const; domi::FrameworkType GetFrameworkType() const; ParseParamFunc GetParseParamFn() const; ParseParamByOpFunc GetParseParamByOperatorFn() const; @@ -138,6 +164,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistrationData { FusionParseParamByOpFunc GetFusionParseParamByOpFn() const; ParseSubgraphFunc GetParseSubgraphPostFn() const; ParseOpToGraphFunc GetParseOpToGraphFn() const; + Status GetParseSubgraphPostFn(ParseSubgraphFuncV2 &func) const; private: std::shared_ptr impl_; diff --git a/inc/external/register/register_types.h b/inc/external/register/register_types.h index 08d72713..cc0da7b2 100644 --- a/inc/external/register/register_types.h +++ b/inc/external/register/register_types.h @@ -28,7 +28,11 @@ namespace domi { #else #define FMK_FUNC_DEV_VISIBILITY #endif - +#ifdef __GNUC__ +#define ATTRIBUTED_DEPRECATED(replacement) __attribute__((deprecated("Please use " #replacement " instead."))) +#else +#define ATTRIBUTED_DEPRECATED(replacement) __declspec(deprecated("Please use " #replacement " instead.")) +#endif /// CCE defined constant /// diff --git a/inc/external/register/scope/scope_fusion_pass_register.h b/inc/external/register/scope/scope_fusion_pass_register.h index c2905927..089635af 100644 --- a/inc/external/register/scope/scope_fusion_pass_register.h +++ b/inc/external/register/scope/scope_fusion_pass_register.h @@ -54,14 +54,25 @@ class ScopePassManager; class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY Scope { public: Scope(); + ATTRIBUTED_DEPRECATED(Status Init(const char *, const char *, Scope *)) Status Init(const std::string &name, const std::string &sub_type = "", Scope *father_scope = nullptr); + Status Init(const char *name, const char *sub_type, Scope *father_scope = nullptr); ~Scope(); - + ATTRIBUTED_DEPRECATED(Status Name(AscendString &) const) const std::string &Name() const; + Status Name(AscendString &name) const; + ATTRIBUTED_DEPRECATED(Status SubType(AscendString &) const) const std::string &SubType() const; + Status SubType(AscendString &sub_type) const; + ATTRIBUTED_DEPRECATED(Status AllNodesMap(std::unordered_map &) const) const std::unordered_map &AllNodesMap() const; + Status AllNodesMap(std::unordered_map &node_map) const; + ATTRIBUTED_DEPRECATED(Scope *GetSubScope(const char *scope_name) const) Scope *GetSubScope(const std::string &scope_name) const; + Scope *GetSubScope(const char *scope_name) const; + ATTRIBUTED_DEPRECATED(Status LastName(AscendString &) const) const std::string LastName() const; + Status LastName(AscendString &name) const; const std::vector &GetAllSubScopes() const; const Scope *GetFatherScope() const; @@ -80,45 +91,85 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY FusionScopesResult { FusionScopesResult(); Status Init(); ~FusionScopesResult(); + ATTRIBUTED_DEPRECATED(void SetName(const char *)) void SetName(const std::string &name); + void SetName(const char *name); + ATTRIBUTED_DEPRECATED(void SetType(const char *)) void SetType(const std::string &type); + void SetType(const char *type); + ATTRIBUTED_DEPRECATED(void SetDescription(const char *)) void SetDescription(const std::string &description); + void SetDescription(const char *description); + ATTRIBUTED_DEPRECATED(const Status Name(AscendString &) const) const std::string &Name() const; + const Status Name(AscendString &name) const; const std::vector &Nodes() const; + ATTRIBUTED_DEPRECATED(void InsertInputs(const char *, const std::vector &)) void InsertInputs(const std::string &inner_op_name, const std::vector &index_map); + void InsertInputs(const char *inner_op_name, const std::vector &index_map); + ATTRIBUTED_DEPRECATED(void InsertOutputs(const char *, const std::vector &)) void InsertOutputs(const std::string &inner_op_name, const std::vector &index_map); + void InsertOutputs(const char *inner_op_name, const std::vector &index_map); class InnerNodeInfo { public: + ATTRIBUTED_DEPRECATED(InnerNodeInfo(const char *)) explicit InnerNodeInfo(const std::string &fusion_node_name); + explicit InnerNodeInfo(const char *fusion_node_name); + ATTRIBUTED_DEPRECATED(InnerNodeInfo(const char *, const char *, const char *)) InnerNodeInfo(const std::string &fusion_node_name, const std::string &name, const std::string &type); + InnerNodeInfo(const char *fusion_node_name, const char *name, const char *type); InnerNodeInfo(InnerNodeInfo &&other) noexcept; InnerNodeInfo &operator=(InnerNodeInfo &&other) noexcept; InnerNodeInfo(const InnerNodeInfo &) = delete; InnerNodeInfo &operator=(const InnerNodeInfo &) = delete; ~InnerNodeInfo(); + ATTRIBUTED_DEPRECATED(InnerNodeInfo &SetName(const char *)) InnerNodeInfo &SetName(const std::string &name); + InnerNodeInfo &SetName(const char *name); + ATTRIBUTED_DEPRECATED(InnerNodeInfo &SetType(const char *)) InnerNodeInfo &SetType(const std::string &type); + InnerNodeInfo &SetType(const char *type); + ATTRIBUTED_DEPRECATED(InnerNodeInfo &InsertInput(const char *, int32_t)) InnerNodeInfo &InsertInput(const std::string &input_node, int32_t peer_out_idx); + InnerNodeInfo &InsertInput(const char *input_node, int32_t peer_out_idx); + ATTRIBUTED_DEPRECATED(InnerNodeInfo &InsertOutput(const char *, int32_t)) InnerNodeInfo &InsertOutput(const std::string &output_node, int32_t peer_in_idx); + InnerNodeInfo &InsertOutput(const char *output_node, int32_t peer_in_idx); ge::graphStatus BuildInnerNode(); + ATTRIBUTED_DEPRECATED(ge::graphStatus SetInputFormat(const char *, const char *)) ge::graphStatus SetInputFormat(const std::string &input_name, const std::string &format); + ge::graphStatus SetInputFormat(const char *input_name, const char *format); + ATTRIBUTED_DEPRECATED(ge::graphStatus SetOutputFormat(const char *, const char *)) ge::graphStatus SetOutputFormat(const std::string &output_name, const std::string &format); + ge::graphStatus SetOutputFormat(const char *output_name, const char *format); + ATTRIBUTED_DEPRECATED(ge::graphStatus SetDynamicInputFormat(const char *, uint32_t index, const char *)) ge::graphStatus SetDynamicInputFormat(const std::string &input_name, uint32_t index, const std::string &format); + ge::graphStatus SetDynamicInputFormat(const char *input_name, uint32_t index, const char *format); + ATTRIBUTED_DEPRECATED(ge::graphStatus SetDynamicOutputFormat(const char *, uint32_t, const char *)) ge::graphStatus SetDynamicOutputFormat(const std::string &output_name, uint32_t index, const std::string &format); + ge::graphStatus SetDynamicOutputFormat(const char *output_name, uint32_t index, const char *format); ge::Operator *MutableOperator(); - + ATTRIBUTED_DEPRECATED(ge::graphStatus GetName(AscendString &) const) std::string GetName() const; + ge::graphStatus GetName(AscendString &name) const; + ATTRIBUTED_DEPRECATED(ge::graphStatus GetType(AscendString &) const) std::string GetType() const; + ge::graphStatus GetType(AscendString &type) const; + ATTRIBUTED_DEPRECATED(ge::graphStatus GetInputs(std::vector> &) const) std::vector> GetInputs() const; + ge::graphStatus GetInputs(std::vector> &inputs) const; + ATTRIBUTED_DEPRECATED(ge::graphStatus GetOutputs(std::vector> &) const) std::vector> GetOutputs() const; + ge::graphStatus GetOutputs(std::vector> &outputs) const; private: class InnerNodeInfoImpl; std::unique_ptr impl_; }; - + ATTRIBUTED_DEPRECATED(InnerNodeInfo *AddInnerNode(const char *, const char *)) InnerNodeInfo *AddInnerNode(const std::string &name, const std::string &type); + InnerNodeInfo *AddInnerNode(const char *name, const char *type); InnerNodeInfo *MutableRecentInnerNode(); InnerNodeInfo *MutableInnerNode(uint32_t index); ge::graphStatus CheckInnerNodesInfo(); @@ -157,7 +208,9 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY ScopeGraph { ~ScopeGraph(); const ScopeTree *GetScopeTree() const; + ATTRIBUTED_DEPRECATED(Status GetNodesMap(std::unordered_map &) const) const std::unordered_map &GetNodesMap() const; + Status GetNodesMap(std::unordered_map &nodes_map) const; private: class ScopeGraphImpl; @@ -176,7 +229,9 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY ScopeAttrValue { void SetIntValue(int64_t value); void SetFloatValue(float value); + ATTRIBUTED_DEPRECATED(void SetStringValue(const char *)) void SetStringValue(std::string value); + void SetStringValue(const char *value); void SetBoolValue(bool value); private: @@ -193,7 +248,9 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY ScopeBaseFeature { class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY NodeOpTypeFeature : ScopeBaseFeature { public: + ATTRIBUTED_DEPRECATED(NodeOpTypeFeature(const char *, int, int)) NodeOpTypeFeature(std::string nodeType, int num, int step = 0); + NodeOpTypeFeature(const char *node_type, int num, int step = 0); NodeOpTypeFeature(NodeOpTypeFeature const &feature); NodeOpTypeFeature &operator=(NodeOpTypeFeature const &feature); ~NodeOpTypeFeature(); @@ -206,7 +263,9 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY NodeOpTypeFeature : ScopeBa class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY NodeAttrFeature : ScopeBaseFeature { public: + ATTRIBUTED_DEPRECATED(NodeAttrFeature(const char *, const char *, ge::DataType, ScopeAttrValue &)) NodeAttrFeature(std::string nodeType, std::string attr_name, ge::DataType datatype, ScopeAttrValue &attr_value); + NodeAttrFeature(const char *node_type, const char *attr_name, ge::DataType datatype, ScopeAttrValue &attr_value); NodeAttrFeature(NodeAttrFeature const &feature); NodeAttrFeature &operator=(NodeAttrFeature const &feature); ~NodeAttrFeature(); @@ -219,8 +278,10 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY NodeAttrFeature : ScopeBase class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY ScopeFeature : ScopeBaseFeature { public: + ATTRIBUTED_DEPRECATED(ScopeFeature(const char *, int32_t, const char *, const char *, int)) ScopeFeature(std::string sub_type, int32_t num, std::string suffix = "", std::string sub_scope_mask = "", int step = 0); + ScopeFeature(const char *sub_type, int32_t num, const char *suffix, const char *sub_scope_mask, int step = 0); ScopeFeature(ScopeFeature const &feature); ScopeFeature &operator=(ScopeFeature const &feature); ~ScopeFeature(); @@ -235,8 +296,9 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY ScopePattern { public: ScopePattern(); ~ScopePattern(); - + ATTRIBUTED_DEPRECATED(ScopePattern &SetSubType(const char *)) ScopePattern &SetSubType(const std::string &sub_type); + ScopePattern &SetSubType(const char *sub_type); ScopePattern &AddNodeOpTypeFeature(NodeOpTypeFeature feature); ScopePattern &AddNodeAttrFeature(NodeAttrFeature feature); ScopePattern &AddScopeFeature(ScopeFeature feature); @@ -296,8 +358,11 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY ScopeFusionPassRegistry { return instance; } + ATTRIBUTED_DEPRECATED(void RegisterScopeFusionPass(const char *, CreateFn, bool)) void RegisterScopeFusionPass(const std::string &pass_name, CreateFn create_fn, bool is_general); + void RegisterScopeFusionPass(const char *pass_name, CreateFn create_fn, bool is_general); + private: ScopeFusionPassRegistry(); class ScopeFusionPassRegistryImpl; @@ -307,7 +372,9 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY ScopeFusionPassRegistry { class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY ScopeUtil { public: + ATTRIBUTED_DEPRECATED(static AscendString StringReplaceAll(const char *, const char *, const char *)) static std::string StringReplaceAll(std::string str, const std::string &old_value, const std::string &new_value); + static AscendString StringReplaceAll(const char *str, const char *old_value, const char *new_value); static void FreeScopePatterns(ScopeFusionPatterns &patterns); static void FreeOneBatchPattern(std::vector &one_batch_pattern); }; diff --git a/inc/framework/common/debug/ge_log.h b/inc/framework/common/debug/ge_log.h index 6ac00037..a27c8d7a 100644 --- a/inc/framework/common/debug/ge_log.h +++ b/inc/framework/common/debug/ge_log.h @@ -18,24 +18,39 @@ #define INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_ #include -#include -#include #include "framework/common/ge_inner_error_codes.h" #include "toolchain/slog.h" +#ifdef __GNUC__ +#include +#include +#else +#include "mmpa/mmpa_api.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif #define GE_MODULE_NAME static_cast(GE) // trace status of log enum TraceStatus { TRACE_INIT = 0, TRACE_RUNNING, TRACE_WAITING, TRACE_STOP }; -#define GELOGE(ERROR_CODE, ...) GE_LOG_ERROR(GE_MODULE_NAME, ERROR_CODE, __VA_ARGS__) -#define GELOGW(...) GE_LOG_WARN(GE_MODULE_NAME, __VA_ARGS__) -#define GELOGI(...) GE_LOG_INFO(GE_MODULE_NAME, __VA_ARGS__) -#define GELOGD(...) GE_LOG_DEBUG(GE_MODULE_NAME, __VA_ARGS__) -#define GEEVENT(...) GE_LOG_EVENT(GE_MODULE_NAME, __VA_ARGS__) -#define GELOGO(...) GE_LOG_OPLOG(GE_MODULE_NAME, __VA_ARGS__) -#define GELOGT(VALUE, ...) GE_LOG_TRACE(GE_MODULE_NAME, VALUE, __VA_ARGS__) +class GeLog { + public: +#ifdef __GNUC__ + static pid_t GetTid() { + thread_local static pid_t tid = syscall(__NR_gettid); + return tid; + } +#else + static int GetTid() { + thread_local static int tid = static_cast(GetCurrentThreadId()); + return tid; + } +#endif +}; inline bool IsLogEnable(int module_name, int log_level) { int32_t enable = CheckLogLevel(module_name, log_level); @@ -46,33 +61,57 @@ inline bool IsLogEnable(int module_name, int log_level) { return false; } -inline pid_t GetTid() { - thread_local static pid_t tid = syscall(__NR_gettid); - return tid; -} +#define GELOGE(ERROR_CODE, fmt, ...) \ + dlog_error(GE_MODULE_NAME, "%lu %s: ErrorNo: %d(%s) " fmt, GeLog::GetTid(), __FUNCTION__, ERROR_CODE, \ + ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ##__VA_ARGS__) +#define GELOGW(fmt, ...) \ + if (IsLogEnable(GE_MODULE_NAME, DLOG_WARN)) \ + dlog_warn(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) +#define GELOGI(fmt, ...) \ + if (IsLogEnable(GE_MODULE_NAME, DLOG_INFO)) \ + dlog_info(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) +#define GELOGD(fmt, ...) \ + if (IsLogEnable(GE_MODULE_NAME, DLOG_DEBUG)) \ + dlog_debug(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) +#define GEEVENT(fmt, ...) dlog_event(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) +#define GELOGO(fmt, ...) Dlog(GE_MODULE_NAME, DLOG_OPLOG, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) +#define GELOGT(VALUE, fmt, ...) \ + do { \ + TraceStatus stat = VALUE; \ + const char *const TraceStatStr[] = {"INIT", "RUNNING", "WAITING", "STOP"}; \ + int idx = static_cast(stat); \ + char *k = const_cast("status"); \ + char *v = const_cast(TraceStatStr[idx]); \ + KeyValue kv = {k, v}; \ + DlogWithKV(static_cast(GE_MODULE_NAME), DLOG_TRACE, &kv, 1, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, \ + ##__VA_ARGS__); \ + } while (0) -#define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \ - dlog_error(MOD_NAME, "%lu %s: ErrorNo: %d(%s) " fmt, GetTid(), __FUNCTION__, ERROR_CODE, \ +#define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \ + dlog_error(MOD_NAME, "%lu %s: ErrorNo: %d(%s) " fmt, GeLog::GetTid(), __FUNCTION__, ERROR_CODE, \ ((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ##__VA_ARGS__) #define GE_LOG_WARN(MOD_NAME, fmt, ...) \ - if (IsLogEnable(MOD_NAME, DLOG_WARN)) dlog_warn(MOD_NAME, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__) + if (IsLogEnable(MOD_NAME, DLOG_WARN)) dlog_warn(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) #define GE_LOG_INFO(MOD_NAME, fmt, ...) \ - if (IsLogEnable(MOD_NAME, DLOG_INFO)) dlog_info(MOD_NAME, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__) + if (IsLogEnable(MOD_NAME, DLOG_INFO)) dlog_info(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) #define GE_LOG_DEBUG(MOD_NAME, fmt, ...) \ - if (IsLogEnable(MOD_NAME, DLOG_DEBUG)) dlog_debug(MOD_NAME, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__) -#define GE_LOG_EVENT(MOD_NAME, fmt, ...) dlog_event(MOD_NAME, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__) + if (IsLogEnable(MOD_NAME, DLOG_DEBUG)) \ + dlog_debug(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) +#define GE_LOG_EVENT(MOD_NAME, fmt, ...) \ + dlog_event(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) #define GE_LOG_OPLOG(MOD_NAME, fmt, ...) \ - Dlog(MOD_NAME, DLOG_OPLOG, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__) + Dlog(MOD_NAME, DLOG_OPLOG, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) -#define GE_LOG_TRACE(MOD_NAME, value, fmt, ...) \ - do { \ - TraceStatus stat = value; \ - const char *const TraceStatStr[] = {"INIT", "RUNNING", "WAITING", "STOP"}; \ - int idx = static_cast(stat); \ - char *k = const_cast("status"); \ - char *v = const_cast(TraceStatStr[idx]); \ - KeyValue kv = {k, v}; \ - DlogWithKV(static_cast(MOD_NAME), DLOG_TRACE, &kv, 1, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__); \ +#define GE_LOG_TRACE(MOD_NAME, value, fmt, ...) \ + do { \ + TraceStatus stat = value; \ + const char *const TraceStatStr[] = {"INIT", "RUNNING", "WAITING", "STOP"}; \ + int idx = static_cast(stat); \ + char *k = const_cast("status"); \ + char *v = const_cast(TraceStatStr[idx]); \ + KeyValue kv = {k, v}; \ + DlogWithKV(static_cast(MOD_NAME), DLOG_TRACE, &kv, 1, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, \ + ##__VA_ARGS__); \ } while (0) // print memory when it is greater than 1KB. @@ -82,4 +121,7 @@ inline pid_t GetTid() { GELOGI("MallocMemory, func=%s, size=%zu, purpose=%s", (#FUNC), static_cast(SIZE), (PURPOSE)); \ } \ } while (0); +#ifdef __cplusplus +} +#endif #endif // INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_ diff --git a/inc/framework/common/ge_compiler_options.h b/inc/framework/common/ge_compiler_options.h new file mode 100644 index 00000000..6876740e --- /dev/null +++ b/inc/framework/common/ge_compiler_options.h @@ -0,0 +1,32 @@ +/** + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INC_FRAMEWORK_COMMON_GE_COMPILER_OPTIONS_H_ +#define INC_FRAMEWORK_COMMON_GE_COMPILER_OPTIONS_H_ + +namespace ge { +#ifdef __GNUC__ +#define GE_ATTRIBUTE_UNUSED __attribute__((unused)) +#define GE_FUNCTION_IDENTIFIER __PRETTY_FUNCTION__ +#define GE_BUILTIN_PREFETCH(args_addr) __builtin_prefetch(args_addr) +#else +#define GE_ATTRIBUTE_UNUSED +#define GE_FUNCTION_IDENTIFIER __FUNCSIG__ +#define GE_BUILTIN_PREFETCH(args_addr) +#endif +} // namespace ge + +#endif // INC_FRAMEWORK_COMMON_GE_COMPILER_OPTIONS_H_ \ No newline at end of file diff --git a/inc/framework/common/ge_types.h b/inc/framework/common/ge_types.h index 6033521c..fb1f0be1 100644 --- a/inc/framework/common/ge_types.h +++ b/inc/framework/common/ge_types.h @@ -105,6 +105,7 @@ struct ShapeDescription { int64_t height = 0; int64_t width = 0; std::vector dims; + std::vector> shape_ranges; }; // Definition of input and output description information diff --git a/inc/framework/common/string_util.h b/inc/framework/common/string_util.h index b74eddcf..f78b194e 100644 --- a/inc/framework/common/string_util.h +++ b/inc/framework/common/string_util.h @@ -17,6 +17,7 @@ #ifndef INC_FRAMEWORK_COMMON_STRING_UTIL_H_ #define INC_FRAMEWORK_COMMON_STRING_UTIL_H_ +#include #include #include diff --git a/inc/framework/common/types.h b/inc/framework/common/types.h index 038b1cf6..af2edbcc 100644 --- a/inc/framework/common/types.h +++ b/inc/framework/common/types.h @@ -18,7 +18,6 @@ #define INC_FRAMEWORK_COMMON_TYPES_H_ #include -#include #include #include #include @@ -526,7 +525,10 @@ REGISTER_OPTYPE_DECLARE(HVDCALLBACKALLGATHER, "HorovodAllgather"); REGISTER_OPTYPE_DECLARE(HVDCALLBACKBROADCAST, "HorovodBroadcast"); REGISTER_OPTYPE_DECLARE(HVDWAIT, "HorovodWait"); -enum InputMode { INPUT = 0, CONST }; +// aicpu op for online_infer dynamic_dims +REGISTER_OPTYPE_DECLARE(GETDYNAMICDIMS, "GetDynamicDims"); + +enum InputMode { INPUT = 0, CONST_INPUT }; // Definition of the processing status enum of the process module enum ModelProcessState { diff --git a/inc/framework/omg/omg_inner_types.h b/inc/framework/omg/omg_inner_types.h index 6cc4afd3..454890aa 100644 --- a/inc/framework/omg/omg_inner_types.h +++ b/inc/framework/omg/omg_inner_types.h @@ -115,6 +115,10 @@ struct OmgContext { std::string dynamic_batch_size; std::string dynamic_image_size; std::string dynamic_dims; + std::string dynamic_node_type; + std::vector> user_real_input_dims; + std::vector cur_dynamic_dims; + bool need_multi_batch = false; }; } // namespace ge diff --git a/inc/graph/anchor.h b/inc/graph/anchor.h index 565f0843..b042a463 100644 --- a/inc/graph/anchor.h +++ b/inc/graph/anchor.h @@ -17,6 +17,8 @@ #ifndef INC_GRAPH_ANCHOR_H_ #define INC_GRAPH_ANCHOR_H_ +#include "graph/compiler_options.h" + #include #include #include @@ -128,7 +130,7 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Anchor : public std::enable template static Anchor::TYPE TypeOf() { static_assert(std::is_base_of::value, "T must be a Anchor!"); - return __PRETTY_FUNCTION__; + return METADEF_FUNCTION_IDENTIFIER; } public: diff --git a/inc/graph/attr_value_serializable.h b/inc/graph/attr_value_serializable.h index a69beb96..349e35c8 100644 --- a/inc/graph/attr_value_serializable.h +++ b/inc/graph/attr_value_serializable.h @@ -20,6 +20,7 @@ #include #include #include "graph/ge_attr_value.h" +#include "graph/compiler_options.h" namespace ge { @@ -92,7 +93,7 @@ class _GeSerializable { SaveItem(namedAttrs, args...); } - static void SaveItem(GeAttrValue::NAMED_ATTRS &namedAttrs __attribute__((__unused__))) {} + static void SaveItem(GeAttrValue::NAMED_ATTRS &namedAttrs METADEF_ATTRIBUTE_UNUSED) {} template static graphStatus LoadItem(GeAttrValue::NAMED_ATTRS &namedAttrs, string itemName, T &item, Args &... args) { @@ -104,9 +105,7 @@ class _GeSerializable { return LoadItem(namedAttrs, args...); } - static graphStatus LoadItem(GeAttrValue::NAMED_ATTRS &namedAttrs __attribute__((__unused__))) { - return GRAPH_SUCCESS; - } + static graphStatus LoadItem(GeAttrValue::NAMED_ATTRS &namedAttrs METADEF_ATTRIBUTE_UNUSED) { return GRAPH_SUCCESS; } }; #define _GE_FI(a) #a, a diff --git a/inc/graph/compiler_options.h b/inc/graph/compiler_options.h new file mode 100644 index 00000000..33bd4183 --- /dev/null +++ b/inc/graph/compiler_options.h @@ -0,0 +1,32 @@ +/** + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INC_GRAPH_COMPILER_OPTIONS_H_ +#define INC_GRAPH_COMPILER_OPTIONS_H_ + +namespace ge { +#ifdef __GNUC__ +#define METADEF_ATTRIBUTE_UNUSED __attribute__((unused)) +#define METADEF_FUNCTION_IDENTIFIER __PRETTY_FUNCTION__ +#define METADEF_BUILTIN_PREFETCH(args_addr) __builtin_prefetch(args_addr) +#else +#define METADEF_ATTRIBUTE_UNUSED +#define METADEF_FUNCTION_IDENTIFIER __FUNCSIG__ +#define METADEF_BUILTIN_PREFETCH(args_addr) +#endif +} // namespace ge + +#endif // INC_GRAPH_COMPILER_OPTIONS_H_ \ No newline at end of file diff --git a/inc/graph/debug/ge_attr_define.h b/inc/graph/debug/ge_attr_define.h index b85844d6..097e7b90 100644 --- a/inc/graph/debug/ge_attr_define.h +++ b/inc/graph/debug/ge_attr_define.h @@ -1139,6 +1139,13 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_ZER // The processing mode of INF and NAN during floating-point number calculation. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_FP_CEILING_MODE; +// count of data from getnext_sink +GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_GETNEXT_SINK_DATA_COUNT; +GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_GETNEXT_SINK_SHAPE_INFO; + +// getnext_sink marked on NetOutput +GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_GETNEXT_SINK_DYNMAIC; +GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_ALL_GEARS_INFO; } // namespace ge #endif // INC_GRAPH_DEBUG_GE_ATTR_DEFINE_H_ diff --git a/inc/graph/detail/any_map.h b/inc/graph/detail/any_map.h index 21eb08b0..863f97ea 100644 --- a/inc/graph/detail/any_map.h +++ b/inc/graph/detail/any_map.h @@ -22,6 +22,8 @@ #include #include +#include "graph/compiler_options.h" + namespace ge { using std::shared_ptr; using std::string; @@ -30,7 +32,7 @@ class TypeID { public: template static TypeID Of() { - return TypeID(__PRETTY_FUNCTION__); + return TypeID(METADEF_FUNCTION_IDENTIFIER); } ~TypeID() = default; diff --git a/inc/graph/op_desc.h b/inc/graph/op_desc.h index 2e3009b3..66930c02 100644 --- a/inc/graph/op_desc.h +++ b/inc/graph/op_desc.h @@ -164,6 +164,10 @@ class OpDesc : public std::enable_shared_from_this, public AttrHolder { std::map GetAllOutputName(); + std::map &MutableAllInputName(); + + std::map &MutableAllOutputName(); + bool UpdateInputName(std::map inputNameIdx); bool UpdateOutputName(std::map outputNameIdx); diff --git a/inc/graph/operator_factory_impl.h b/inc/graph/operator_factory_impl.h index aaa9b2c7..5d56b1d0 100644 --- a/inc/graph/operator_factory_impl.h +++ b/inc/graph/operator_factory_impl.h @@ -43,6 +43,8 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OperatorFactoryImpl { static graphStatus RegisterOperatorCreator(const std::string &operator_type, OpCreator const &op_creator); + static graphStatus RegisterOperatorCreator(const std::string &operator_type, OpCreatorV2 const &op_creator); + static graphStatus RegisterInferShapeFunc(const std::string &operator_type, InferShapeFunc const infer_shape_func); static graphStatus RegisterInferFormatFunc(const std::string &operator_type, InferFormatFunc const infer_format_func); @@ -53,6 +55,7 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OperatorFactoryImpl { InferDataSliceFunc const infer_data_slice_func); static shared_ptr> operator_creators_; + static shared_ptr> operator_creators_v2_; static shared_ptr> operator_infershape_funcs_; static shared_ptr> operator_inferformat_funcs_; static shared_ptr> operator_verify_funcs_; diff --git a/inc/graph/opsproto_manager.h b/inc/graph/opsproto_manager.h index 06846573..92d49bca 100644 --- a/inc/graph/opsproto_manager.h +++ b/inc/graph/opsproto_manager.h @@ -17,8 +17,6 @@ #ifndef INC_GRAPH_OPSPROTO_MANAGER_H_ #define INC_GRAPH_OPSPROTO_MANAGER_H_ -#include -#include #include #include #include diff --git a/inc/graph/ref_relation.h b/inc/graph/ref_relation.h index 71457916..363a026c 100644 --- a/inc/graph/ref_relation.h +++ b/inc/graph/ref_relation.h @@ -55,7 +55,7 @@ struct RefCell { struct RefCellHash { size_t operator()(const RefCell &c) const { - unsigned long number = reinterpret_cast(reinterpret_cast(c.node.get())); + unsigned long number = static_cast(reinterpret_cast(c.node.get())); string tmp = c.node_name + std::to_string(c.in_out) + std::to_string(c.in_out_idx) + std::to_string(number); return std::hash()(tmp); } diff --git a/inc/graph/shape_refiner.h b/inc/graph/shape_refiner.h index 4f8783a3..e9518042 100644 --- a/inc/graph/shape_refiner.h +++ b/inc/graph/shape_refiner.h @@ -31,6 +31,8 @@ class ShapeRefiner { static graphStatus InferShapeAndType(const NodePtr &node, bool before_subgraph); static graphStatus InferShapeAndType(const NodePtr &node); static graphStatus InferShapeAndType(const ConstNodePtr &node, Operator &op); + static graphStatus InferShapeAndTypeForRunning(const ConstNodePtr &node, Operator &op, bool before_subgraph); + static graphStatus InferShapeAndTypeForRunning(const NodePtr &node, bool before_subgraph); static void ClearContextMap(); private: diff --git a/inc/graph/tuning_utils.h b/inc/graph/tuning_utils.h index 98262a23..bbd9860a 100644 --- a/inc/graph/tuning_utils.h +++ b/inc/graph/tuning_utils.h @@ -71,7 +71,7 @@ const std::set build_step_options = {BUILD_STEP_BEFORE_UB_MATCH, BU using SubgraphCreateOutNode = std::unordered_map; using NodetoNodeMap = std::unordered_map; -using NodeSet = std::set; +using NodeVec = std::vector; using NodeNametoNodeNameMap = std::unordered_map; using NodetoNodeNameMap = std::unordered_map; class TuningUtils { @@ -119,8 +119,8 @@ class TuningUtils { static NodeNametoNodeNameMap data_2_netoutput_; static NodetoNodeNameMap data_node_2_netoutput_; static NodetoNodeMap data_node_2_netoutput_node_; - static NodeSet netoutput_nodes_; - static NodeSet merged_graph_nodes_; + static NodeVec netoutput_nodes_; + static NodeVec merged_graph_nodes_; static std::mutex mutex_; // for debug static std::string PrintCheckLog(); diff --git a/src/common/graph/CMakeLists.txt b/src/common/graph/CMakeLists.txt index 5c6149fe..074597b1 100644 --- a/src/common/graph/CMakeLists.txt +++ b/src/common/graph/CMakeLists.txt @@ -67,12 +67,15 @@ include_directories(${GE_SOURCE_DIR}/build) ######### libgraph.so ############# add_library(graph SHARED ${SRC_LIST} ${PROTO_SRCS} ${PROTO_ONNX_SRCS}) target_compile_definitions(graph PRIVATE - DAVINCI_CLOUD - Werror) + DAVINCI_CLOUD) +target_compile_options(graph PRIVATE + -Werror + -Wno-deprecated-declarations) target_link_libraries(graph PRIVATE ${PROTOBUF_LIBRARY} ${c_sec} ${slog} ${error_manager} + ${mmpa} rt dl) diff --git a/src/common/graph/ascend_string.cc b/src/common/graph/ascend_string.cc index b1616856..1fccc976 100644 --- a/src/common/graph/ascend_string.cc +++ b/src/common/graph/ascend_string.cc @@ -15,11 +15,15 @@ */ #include "external/graph/ascend_string.h" +#include "debug/ge_log.h" namespace ge { AscendString::AscendString(const char* name) { if (name != nullptr) { name_ = std::shared_ptr(new (std::nothrow) std::string(name)); + if (name_ == nullptr) { + GELOGE(FAILED, "AscendString[%s] make shared failed.", name); + } } } diff --git a/src/common/graph/attr_value.cc b/src/common/graph/attr_value.cc index 066767c2..e6f04b0e 100644 --- a/src/common/graph/attr_value.cc +++ b/src/common/graph/attr_value.cc @@ -35,4 +35,14 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY AttrValue::AttrValue() { impl = C ATTR_VALUE_SET_GET_IMP(AttrValue::STR) ATTR_VALUE_SET_GET_IMP(AttrValue::INT) ATTR_VALUE_SET_GET_IMP(AttrValue::FLOAT) + +graphStatus AttrValue::GetValue(AscendString &val) { + std::string val_get; + auto status = GetValue(val_get); + if (status != GRAPH_SUCCESS) { + return status; + } + val = AscendString(val_get.c_str()); + return GRAPH_SUCCESS; +} } // namespace ge diff --git a/src/common/graph/compute_graph.cc b/src/common/graph/compute_graph.cc index e62cba69..986d2bf9 100644 --- a/src/common/graph/compute_graph.cc +++ b/src/common/graph/compute_graph.cc @@ -729,7 +729,7 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus ComputeGraph::InsertE graphStatus ComputeGraph::DFSTopologicalSorting(std::vector &node_vec, std::map &map_in_edge_num, std::vector &stack, bool reverse) { - GELOGI("Runing_Dfs_Sort: %s", name_.c_str()); + GELOGD("Runing_Dfs_Sort: %s", name_.c_str()); // Record the number of non data nodes but no input nodes GE_CHK_BOOL_EXEC(SortNodes(stack, map_in_edge_num) == GRAPH_SUCCESS, return GRAPH_FAILED, "sort nodes failed"); std::vector out_nodes; @@ -1031,7 +1031,7 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool ComputeGraph::IsValid() cons GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void ComputeGraph::Dump() const { GELOGI("graph name = %s.", GetName().c_str()); for (const auto &node : GetAllNodes()) { - GELOGI("node name = %s.", node->GetName().c_str()); + GELOGD("node name = %s.", node->GetName().c_str()); for (const auto &anchor : node->GetAllOutDataAnchors()) { for (const auto &peer_in_anchor : anchor->GetPeerInDataAnchors()) { GE_IF_BOOL_EXEC(peer_in_anchor != nullptr && peer_in_anchor->GetOwnerNode() != nullptr, diff --git a/src/common/graph/debug/ge_op_types.h b/src/common/graph/debug/ge_op_types.h index dff87331..647b2b9c 100644 --- a/src/common/graph/debug/ge_op_types.h +++ b/src/common/graph/debug/ge_op_types.h @@ -17,8 +17,10 @@ #ifndef COMMON_GRAPH_DEBUG_GE_OP_TYPES_H_ #define COMMON_GRAPH_DEBUG_GE_OP_TYPES_H_ +#include "graph/compiler_options.h" + namespace ge { -#define GE_REGISTER_OPTYPE(var_name, str_name) static const char *var_name __attribute__((unused)) = str_name +#define GE_REGISTER_OPTYPE(var_name, str_name) static const char *var_name METADEF_ATTRIBUTE_UNUSED = str_name GE_REGISTER_OPTYPE(DATA, "Data"); GE_REGISTER_OPTYPE(AIPPDATA, "AippData"); diff --git a/src/common/graph/ge_attr_define.cc b/src/common/graph/ge_attr_define.cc index bb4be1e1..d40c7b94 100644 --- a/src/common/graph/ge_attr_define.cc +++ b/src/common/graph/ge_attr_define.cc @@ -1102,4 +1102,11 @@ const std::string ATTR_ZERO_COPY_RELATIVE_OFFSET = "_zero_copy_relative_offset"; // The processing mode of INF and NAN during floating-point number calculation. const std::string ATTR_FP_CEILING_MODE = "_fp_ceiling_mode"; +// count of data from getnext_sink +const std::string ATTR_GETNEXT_SINK_DATA_COUNT = "N"; +const std::string ATTR_GETNEXT_SINK_SHAPE_INFO = "shape_info"; + +// getnext_sink marked on NetOutput +const std::string ATTR_GETNEXT_SINK_DYNMAIC = "getnext_sink_dynamic"; +const std::string ATTR_ALL_GEARS_INFO = "all_gears_info"; } // namespace ge diff --git a/src/common/graph/gnode.cc b/src/common/graph/gnode.cc index 9c9fa195..9ee9b730 100644 --- a/src/common/graph/gnode.cc +++ b/src/common/graph/gnode.cc @@ -89,7 +89,7 @@ GNodePtr NodeAdapter::Node2GNodePtr(const ge::NodePtr &node) { GNode::GNode() { impl_ = ComGraphMakeShared(); } -graphStatus GNode::GetType(ge::AscendString &type) const { +graphStatus GNode::GetType(AscendString &type) const { if (impl_ == nullptr) { GELOGE(GRAPH_FAILED, "GetType: node impl is nullptr."); return GRAPH_FAILED; @@ -107,7 +107,7 @@ graphStatus GNode::GetType(ge::AscendString &type) const { return GRAPH_SUCCESS; } -graphStatus GNode::GetName(ge::AscendString &name) const { +graphStatus GNode::GetName(AscendString &name) const { if (impl_ == nullptr) { GELOGE(GRAPH_FAILED, "GetName: node impl is nullptr."); return GRAPH_FAILED; @@ -295,7 +295,7 @@ graphStatus GNode::GetInputConstData(const int32_t index, Tensor &data) const { return GRAPH_NODE_WITHOUT_CONST_INPUT; } -graphStatus GNode::GetInputIndexByName(const ge::AscendString &name, int32_t &index) { +graphStatus GNode::GetInputIndexByName(const AscendString &name, int32_t &index) { const char *ascend_name = name.GetString(); if (ascend_name == nullptr) { GELOGE(GRAPH_PARAM_INVALID, "GetInputIndexByName: ascend string error."); @@ -325,7 +325,7 @@ graphStatus GNode::GetInputIndexByName(const ge::AscendString &name, int32_t &in return GRAPH_SUCCESS; } -graphStatus GNode::GetOutputIndexByName(const ge::AscendString &name, int32_t &index) { +graphStatus GNode::GetOutputIndexByName(const AscendString &name, int32_t &index) { const char *ascend_name = name.GetString(); if (ascend_name == nullptr) { GELOGE(GRAPH_PARAM_INVALID, "GetOutputIndexByName: ascend string error."); @@ -528,7 +528,7 @@ graphStatus GNode::UpdateOutputDesc(const int32_t index, const TensorDesc &tenso } #define NODE_ATTR_GET_IMP(ArgType) \ - graphStatus GNode::GetAttr(const ge::AscendString &name, ArgType &attr_value) const { \ + graphStatus GNode::GetAttr(const AscendString &name, ArgType &attr_value) const { \ const char *ascend_name = name.GetString(); \ if (ascend_name == nullptr) { \ GELOGE(GRAPH_PARAM_INVALID, "GetAttr: ascend string error."); \ @@ -556,29 +556,29 @@ graphStatus GNode::UpdateOutputDesc(const int32_t index, const TensorDesc &tenso return GRAPH_SUCCESS; \ } -#define NODE_ATTR_SET_IMP(ArgType) \ - graphStatus GNode::SetAttr(const ge::AscendString &name, ArgType &attr_value) const { \ - const char *ascend_name = name.GetString(); \ - if (ascend_name == nullptr) { \ - GELOGE(GRAPH_PARAM_INVALID, "SetAttr: ascend string error."); \ - return GRAPH_PARAM_INVALID; \ - } \ - \ - if (impl_ == nullptr) { \ - GELOGE(GRAPH_FAILED, "SetAttr: node impl is nullptr."); \ - return GRAPH_FAILED; \ - } \ - \ - std::shared_ptr node_ptr = impl_->node_ptr_.lock(); \ - if (node_ptr == nullptr) { \ - GELOGE(GRAPH_FAILED, "SetAttr: the shared ptr is not valid."); \ - return GRAPH_FAILED; \ - } \ - \ - std::string node_name = ascend_name; \ - Operator op = OpDescUtils::CreateOperatorFromNode(node_ptr); \ - (void)op.SetAttr(node_name, attr_value); \ - return GRAPH_SUCCESS; \ +#define NODE_ATTR_SET_IMP(ArgType) \ + graphStatus GNode::SetAttr(const AscendString &name, ArgType &attr_value) const { \ + const char *ascend_name = name.GetString(); \ + if (ascend_name == nullptr) { \ + GELOGE(GRAPH_PARAM_INVALID, "SetAttr: ascend string error."); \ + return GRAPH_PARAM_INVALID; \ + } \ + \ + if (impl_ == nullptr) { \ + GELOGE(GRAPH_FAILED, "SetAttr: node impl is nullptr."); \ + return GRAPH_FAILED; \ + } \ + \ + std::shared_ptr node_ptr = impl_->node_ptr_.lock(); \ + if (node_ptr == nullptr) { \ + GELOGE(GRAPH_FAILED, "SetAttr: the shared ptr is not valid."); \ + return GRAPH_FAILED; \ + } \ + \ + std::string node_name = ascend_name; \ + Operator op = OpDescUtils::CreateOperatorFromNode(node_ptr); \ + (void)op.SetAttr(node_name, attr_value); \ + return GRAPH_SUCCESS; \ } NODE_ATTR_GET_IMP(int64_t) @@ -616,7 +616,7 @@ NODE_ATTR_SET_IMP(std::vector>) NODE_ATTR_SET_IMP(std::vector) NODE_ATTR_SET_IMP(ge::DataType) -graphStatus GNode::SetAttr(const ge::AscendString &name, AttrValue &attr_value) const { +graphStatus GNode::SetAttr(const AscendString &name, AttrValue &attr_value) const { const char *ascend_name = name.GetString(); if (ascend_name == nullptr) { GELOGE(GRAPH_PARAM_INVALID, "SetAttr: ascend string error."); @@ -640,7 +640,7 @@ graphStatus GNode::SetAttr(const ge::AscendString &name, AttrValue &attr_value) return GRAPH_SUCCESS; } -graphStatus GNode::SetAttr(const ge::AscendString &name, ge::AscendString &attr_value) const { +graphStatus GNode::SetAttr(const AscendString &name, AscendString &attr_value) const { const char *ascend_name = name.GetString(); if (ascend_name == nullptr) { GELOGE(GRAPH_PARAM_INVALID, "SetAttr: name ascend string error."); @@ -671,7 +671,7 @@ graphStatus GNode::SetAttr(const ge::AscendString &name, ge::AscendString &attr_ return GRAPH_SUCCESS; } -graphStatus GNode::SetAttr(const ge::AscendString &name, std::vector &attr_values) const { +graphStatus GNode::SetAttr(const AscendString &name, std::vector &attr_values) const { const char *ascend_name = name.GetString(); if (ascend_name == nullptr) { GELOGE(GRAPH_PARAM_INVALID, "SetAttr: name ascend string error."); @@ -710,7 +710,7 @@ graphStatus GNode::SetAttr(const ge::AscendString &name, std::vector &attr_values) const { +graphStatus GNode::GetAttr(const AscendString &name, std::vector &attr_values) const { const char *ascend_name = name.GetString(); if (ascend_name == nullptr) { GELOGE(GRAPH_PARAM_INVALID, "GetAttr: name ascend string error."); @@ -776,7 +776,7 @@ graphStatus GNode::GetAttr(const ge::AscendString &name, std::vector(graph_name); + if (impl_ == nullptr) { + GELOGW("GraphImpl make shared failed, impl_ is nullptr."); + } + } else { + GELOGW("Graph name is nullptr."); + } +} + graphStatus Graph::AddOp(const ge::Operator &op) { GE_CHK_BOOL_EXEC(impl_ != nullptr, return GRAPH_FAILED, "AddOp failed: graph can not be used, impl is nullptr."); return impl_->AddOp(op); @@ -319,6 +331,22 @@ graphStatus Graph::GetAllOpName(std::vector &op_name) const { return impl_->GetAllOpName(op_name); } +graphStatus Graph::GetAllOpName(std::vector &names) const { + GE_CHK_BOOL_EXEC(impl_ != nullptr, return GRAPH_FAILED, + "GetAllOpName failed: graph can not be used, impl is nullptr."); + std::vector op_names; + if (impl_->GetAllOpName(op_names) != GRAPH_SUCCESS) { + GELOGE(GRAPH_FAILED, "Get all op name failed."); + return GRAPH_FAILED; + } + + for (auto &op_name : op_names) { + names.emplace_back(op_name.c_str()); + } + + return GRAPH_SUCCESS; +} + graphStatus Graph::FindOpByName(const std::string &name, Operator &op) const { Operator op_find_op_def("NULL"); op = op_find_op_def; @@ -327,11 +355,34 @@ graphStatus Graph::FindOpByName(const std::string &name, Operator &op) const { return impl_->FindOpByName(name, op); } +graphStatus Graph::FindOpByName(const char *name, Operator &op) const { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "FindOpByName: name is nullptr."); + return GRAPH_FAILED; + } + Operator op_find_op_def("NULL"); + op = op_find_op_def; + GE_CHK_BOOL_EXEC(impl_ != nullptr, return GRAPH_FAILED, + "FindOpByName failed: graph can not be used, impl is nullptr."); + std::string op_name = name; + return impl_->FindOpByName(op_name, op); +} + graphStatus Graph::FindOpByType(const string &type, std::vector &ops) const { GE_CHECK_NOTNULL(impl_); return impl_->FindOpByType(type, ops); } +graphStatus Graph::FindOpByType(const char *type, std::vector &ops) const { + if (type == nullptr) { + GELOGE(GRAPH_FAILED, "FindOpByType: name is nullptr."); + return GRAPH_FAILED; + } + GE_CHECK_NOTNULL(impl_); + std::string op_type = type; + return impl_->FindOpByType(op_type, ops); +} + Graph &Graph::SetInputs(const vector &inputs) { GE_CHK_BOOL_EXEC(impl_ != nullptr, return *this, "SetInputs failed: graph can not be used, impl is nullptr.") GE_CHK_BOOL_EXEC(inputs.size() > 0, return *this, "SetInputs failed: input operator size can not be 0."); @@ -363,6 +414,23 @@ Graph &Graph::SetOutputs(const std::vector> &outputs) { return *this; } +Graph &Graph::SetOutputs(const std::vector> &outputs) { + GE_CHK_BOOL_EXEC(impl_ != nullptr, return *this, "SetOutputs failed: graph can not be used, impl is nullptr.") + vector> graph_outputs; + for (auto &item : outputs) { + const char *name = item.second.GetString(); + if (name != nullptr) { + string output_name = name; + graph_outputs.emplace_back((std::pair(item.first, name))); + } else { + GELOGW("Output name is nullptr."); + } + } + + (void)impl_->SetOutputs(graph_outputs); + return *this; +} + Graph &Graph::SetTargets(const vector &targets) { if (impl_ == nullptr) { GELOGE(GRAPH_FAILED, "SetTargets failed: graph can not be used, impl is nullptr."); @@ -604,7 +672,7 @@ graphStatus Graph::AddControlEdge(GNode &src_node, GNode &dst_node) { return SUCCESS; } -GraphPtr Graph::ConstructFromInputs(const std::vector &inputs, const ge::AscendString &name) { +GraphPtr Graph::ConstructFromInputs(const std::vector &inputs, const AscendString &name) { const char *ascend_name = name.GetString(); if (ascend_name == nullptr) { GELOGE(GRAPH_PARAM_INVALID, "ConstructFromInputs: ascend string error."); @@ -644,6 +712,18 @@ graphStatus Graph::SaveToFile(const string &file_name) const { return model.SaveToFile(file_name); } +graphStatus Graph::SaveToFile(const char *file_name) const { + if (file_name == nullptr) { + GELOGE(GRAPH_FAILED, "SaveToFile: file name is nullptr."); + return GRAPH_FAILED; + } + + Model model = Model(); + model.SetGraph(*this); + std::string file = file_name; + return model.SaveToFile(file); +} + graphStatus Graph::LoadFromFile(const string &file_name) { Model model = Model(); graphStatus ret = model.LoadFromFile(file_name); @@ -654,8 +734,34 @@ graphStatus Graph::LoadFromFile(const string &file_name) { return GRAPH_SUCCESS; } +graphStatus Graph::LoadFromFile(const char *file_name) { + if (file_name == nullptr) { + GELOGE(GRAPH_FAILED, "SaveToFile: file name is nullptr."); + return GRAPH_FAILED; + } + + Model model = Model(); + std::string file = file_name; + graphStatus ret = model.LoadFromFile(file); + if (ret != GRAPH_SUCCESS) { + return ret; + } + *this = model.GetGraph(); + return GRAPH_SUCCESS; +} + GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY const std::string &Graph::GetName() const { return impl_->GetName(); } +graphStatus Graph::GetName(AscendString &name) const { + if (impl_ == nullptr) { + GELOGE(GRAPH_FAILED, "GetName: impl is nullptr."); + return GRAPH_FAILED; + } + std::string graph_name = impl_->GetName(); + name = AscendString(graph_name.c_str()); + return GRAPH_SUCCESS; +} + GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Graph GraphUtils::CreateGraphFromComputeGraph(const ge::ComputeGraphPtr compute_graph) { GE_CHK_BOOL_EXEC_NOLOG(compute_graph != nullptr, return Graph("")); diff --git a/src/common/graph/graph.mk b/src/common/graph/graph.mk index 14d05ee8..14f49889 100644 --- a/src/common/graph/graph.mk +++ b/src/common/graph/graph.mk @@ -83,7 +83,7 @@ COMMON_LOCAL_C_INCLUDES := \ include $(CLEAR_VARS) LOCAL_MODULE := libgraph -LOCAL_CFLAGS += -DFMK_SUPPORT_DUMP -O2 -Dgoogle=ascend_private +LOCAL_CFLAGS += -DFMK_SUPPORT_DUMP -O2 -Dgoogle=ascend_private -Wno-deprecated-declarations LOCAL_CPPFLAGS += -fexceptions LOCAL_C_INCLUDES := $(COMMON_LOCAL_C_INCLUDES) @@ -95,6 +95,9 @@ LOCAL_SHARED_LIBRARIES := \ libslog \ liberror_manager \ +LOCAL_STATIC_LIBRARIES := \ + libmmpa \ + LOCAL_LDFLAGS := -lrt -ldl LOCAL_MULTILIB := 64 @@ -106,7 +109,7 @@ include $(BUILD_HOST_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := stub/libgraph -LOCAL_CFLAGS += -DFMK_SUPPORT_DUMP -O2 +LOCAL_CFLAGS += -DFMK_SUPPORT_DUMP -O2 -Wno-deprecated-declarations LOCAL_CPPFLAGS += -fexceptions LOCAL_C_INCLUDES := $(COMMON_LOCAL_C_INCLUDES) @@ -132,7 +135,7 @@ include $(BUILD_HOST_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := fwk_stub/libgraph -LOCAL_CFLAGS += -DFMK_SUPPORT_DUMP -O2 +LOCAL_CFLAGS += -DFMK_SUPPORT_DUMP -O2 -Wno-deprecated-declarations LOCAL_CPPFLAGS += -fexceptions LOCAL_C_INCLUDES := $(COMMON_LOCAL_C_INCLUDES) @@ -159,7 +162,7 @@ include $(BUILD_HOST_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libgraph -LOCAL_CFLAGS += -O2 -Dgoogle=ascend_private +LOCAL_CFLAGS += -O2 -Dgoogle=ascend_private -Wno-deprecated-declarations LOCAL_C_INCLUDES := $(COMMON_LOCAL_C_INCLUDES) LOCAL_SRC_FILES := $(COMMON_LOCAL_SRC_FILES) @@ -170,6 +173,9 @@ LOCAL_SHARED_LIBRARIES := \ libslog \ liberror_manager \ +LOCAL_STATIC_LIBRARIES := \ + libmmpa \ + LOCAL_LDFLAGS := -lrt -ldl ifeq ($(device_os),android) @@ -256,6 +262,9 @@ LOCAL_SHARED_LIBRARIES := \ libslog \ liberror_manager \ +LOCAL_STATIC_LIBRARIES := \ + libmmpa \ + LOCAL_LDFLAGS := -lrt -ldl LOCAL_MULTILIB := 64 diff --git a/src/common/graph/inference_context.cc b/src/common/graph/inference_context.cc index ed8193dc..29a30781 100644 --- a/src/common/graph/inference_context.cc +++ b/src/common/graph/inference_context.cc @@ -108,5 +108,22 @@ void InferenceContext::SetOutputHandleShapesAndTypes(std::vector &marks) { inference_context_impl_->marks_ = marks; } +void InferenceContext::SetMarks(const std::vector &marks) { + std::vector impl_marks; + for (const auto &mark : marks) { + if (mark.GetString() != nullptr) { + impl_marks.emplace_back(mark.GetString()); + } + } + inference_context_impl_->marks_ = impl_marks; +} + const std::vector &InferenceContext::GetMarks() const { return inference_context_impl_->marks_; } + +void InferenceContext::GetMarks(std::vector &marks) const { + std::vector str_marks = inference_context_impl_->marks_; + for (auto &str_mark : str_marks) { + marks.emplace_back(str_mark.c_str()); + } +} } // namespace ge diff --git a/src/common/graph/model.cc b/src/common/graph/model.cc index b42d8ce3..2991a8b0 100644 --- a/src/common/graph/model.cc +++ b/src/common/graph/model.cc @@ -15,14 +15,12 @@ */ #include "graph/model.h" -#include #include #include #include #include #include #include -#include #include #include #include @@ -31,9 +29,10 @@ #include "debug/ge_util.h" #include "framework/common/debug/ge_log.h" #include "graph/model_serialize.h" -#include "proto/ge_ir.pb.h" +#include "mmpa/mmpa_api.h" #include "utils/attr_utils.h" #include "utils/ge_ir_utils.h" +#include "proto/ge_ir.pb.h" using google::protobuf::io::FileInputStream; using google::protobuf::io::FileOutputStream; @@ -106,14 +105,15 @@ graphStatus Model::SaveToFile(const string &file_name) const { if (!ge_proto.ParseFromString(str)) { return GRAPH_FAILED; } - char real_path[PATH_MAX] = {0x00}; - if (strlen(file_name.c_str()) >= PATH_MAX) { + char real_path[MMPA_MAX_PATH] = {0x00}; + if (strlen(file_name.c_str()) >= MMPA_MAX_PATH) { return GRAPH_FAILED; } - if (realpath(file_name.c_str(), real_path) == nullptr) { + INT32 result = mmRealPath(file_name.c_str(), real_path, MMPA_MAX_PATH); + if (result != EN_OK) { GELOGI("file %s does not exit, it will be created.", file_name.c_str()); } - int fd = open(real_path, O_WRONLY | O_CREAT | O_TRUNC, ACCESS_PERMISSION_BITS); + int fd = mmOpen2(real_path, M_WRONLY | M_CREAT | O_TRUNC, ACCESS_PERMISSION_BITS); if (fd < 0) { GELOGE(GRAPH_FAILED, "open file failed, file path [%s], %s ", real_path, strerror(errno)); return GRAPH_FAILED; @@ -148,15 +148,16 @@ graphStatus Model::Load(ge::proto::ModelDef &model_def) { bool Model::IsValid() const { return graph_.IsValid(); } graphStatus Model::LoadFromFile(const string &file_name) { - char real_path[PATH_MAX] = {0x00}; - if (strlen(file_name.c_str()) >= PATH_MAX) { + char real_path[MMPA_MAX_PATH] = {0x00}; + if (strlen(file_name.c_str()) >= MMPA_MAX_PATH) { return GRAPH_FAILED; } - if (realpath(file_name.c_str(), real_path) == nullptr) { + INT32 result = mmRealPath(file_name.c_str(), real_path, MMPA_MAX_PATH); + if (result != EN_OK) { GELOGE(GRAPH_FAILED, "file %s does not exit, can not load.", file_name.c_str()); return GRAPH_FAILED; } - int fd = open(real_path, O_RDONLY); + int fd = mmOpen(real_path, M_RDONLY); if (fd < 0) { GELOGE(GRAPH_FAILED, "open file failed, %s", strerror(errno)); return GRAPH_FAILED; @@ -166,13 +167,13 @@ graphStatus Model::LoadFromFile(const string &file_name) { bool ret = model_def.ParseFromFileDescriptor(fd); if (!ret) { GELOGE(GRAPH_FAILED, "ParseFromFileDescriptor failed"); - if (close(fd) != 0) { + if (mmClose(fd) != 0) { GELOGE(GRAPH_FAILED, "close file descriptor fail."); return GRAPH_FAILED; } return GRAPH_FAILED; } - if (close(fd) != 0) { + if (mmClose(fd) != 0) { GELOGE(GRAPH_FAILED, "close file descriptor fail."); return GRAPH_FAILED; } diff --git a/src/common/graph/op_desc.cc b/src/common/graph/op_desc.cc index 8202736d..e290d529 100644 --- a/src/common/graph/op_desc.cc +++ b/src/common/graph/op_desc.cc @@ -66,6 +66,8 @@ const std::string ATTR_NAME_IS_INPUT_CONST = "is_input_const"; const std::string ATTR_NAME_OP_INFER_DEPENDS = "_op_infer_depends"; +const std::string ATTR_NAME_OP_KERNEL_LIB_NAME = "_ge_attr_op_kernel_lib_name"; + GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OpDesc::OpDesc() { op_def_.InitDefault(); if (op_def_.GetProtoMsg() != nullptr) { @@ -522,10 +524,19 @@ GE_FUNC_HOST_VISIBILITY OpDesc::Vistor OpDesc::GetAllInputNames() const GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void OpDesc::SetOpKernelLibName(const std::string &name) { op_kernel_lib_name_ = name; + auto ret = AttrUtils::SetStr(this, ATTR_NAME_OP_KERNEL_LIB_NAME, name); + if (ret != true) { + GELOGE(GRAPH_FAILED, "set op kernel lib name failed."); + } } GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY std::string OpDesc::GetOpKernelLibName() const { - return op_kernel_lib_name_; + if (!op_kernel_lib_name_.empty()) { + return op_kernel_lib_name_; + } + string op_kernel_lib_name; + (void)AttrUtils::GetStr(this, ATTR_NAME_OP_KERNEL_LIB_NAME, op_kernel_lib_name); + return op_kernel_lib_name; } GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void OpDesc::SetOpEngineName(const std::string &name) { @@ -765,6 +776,10 @@ std::map OpDesc::GetAllInputName() const { return input_name_i std::map OpDesc::GetAllOutputName() { return output_name_idx_; } +std::map &OpDesc::MutableAllInputName() { return input_name_idx_; } + +std::map &OpDesc::MutableAllOutputName() { return output_name_idx_; } + bool OpDesc::UpdateInputName(std::map input_name_idx) { bool ret = true; // Use inputDesc_.size() to contain the InValid OptionInput.GetInputsSize() will remove default OptionInput name. diff --git a/src/common/graph/op_imp.cc b/src/common/graph/op_imp.cc index 9abf242b..ad508797 100644 --- a/src/common/graph/op_imp.cc +++ b/src/common/graph/op_imp.cc @@ -16,6 +16,7 @@ #include #include +#include #include #include "debug/ge_log.h" #include "debug/ge_util.h" diff --git a/src/common/graph/operator.cc b/src/common/graph/operator.cc index b449725c..6432c245 100644 --- a/src/common/graph/operator.cc +++ b/src/common/graph/operator.cc @@ -21,7 +21,7 @@ #include #include #include -#include "./array_ops.h" +#include "array_ops.h" #include "debug/ge_log.h" #include "debug/ge_op_types.h" #include "debug/ge_util.h" @@ -235,6 +235,77 @@ class OperatorImpl : public std::enable_shared_from_this { return GRAPH_SUCCESS; } + graphStatus GetInputConstData(const string &dst_name, Tensor &data) { + auto node_ptr = GetNode(); + if (node_ptr != nullptr) { + // For inner compute graph + auto op_desc = node_ptr->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + auto index = op_desc->GetInputIndexByName(dst_name); + auto in_data_anchor = node_ptr->GetInDataAnchor(index); + GE_CHECK_NOTNULL(in_data_anchor); + auto out_data_anchor = in_data_anchor->GetPeerOutAnchor(); + GE_CHECK_NOTNULL(out_data_anchor); + auto peer_node = out_data_anchor->GetOwnerNode(); + GE_CHECK_NOTNULL(peer_node); + auto peer_op_desc = peer_node->GetOpDesc(); + GE_CHECK_NOTNULL(peer_op_desc); + auto peer_op_type = peer_op_desc->GetType(); + if (peer_op_type == CONSTANTOP || peer_op_type == CONSTANT) { + auto const_op_impl = ComGraphMakeShared(peer_node); + GE_CHECK_NOTNULL(const_op_impl); + Operator const_op(std::move(const_op_impl)); + return const_op.GetAttr(ATTR_NAME_WEIGHTS, data); + } else if (peer_op_type == DATA) { + auto parent_node = NodeUtils::GetParentInput(peer_node); + while ((parent_node != nullptr) && (parent_node->GetType() == DATA)) { + parent_node = NodeUtils::GetParentInput(parent_node); + } + if ((parent_node != nullptr) && + ((parent_node->GetType() == CONSTANT) || (parent_node->GetType() == CONSTANTOP))) { + auto const_op_impl = ComGraphMakeShared(parent_node); + GE_CHECK_NOTNULL(const_op_impl); + Operator const_op(std::move(const_op_impl)); + return const_op.GetAttr(ATTR_NAME_WEIGHTS, data); + } + } + // Try get from runtime inference context + auto session_id = std::to_string(GetContext().SessionId()); + RuntimeInferenceContext *runtime_infer_ctx = nullptr; + if (RuntimeInferenceContext::GetContext(session_id, &runtime_infer_ctx) == GRAPH_SUCCESS) { + GELOGD("To get constant from runtime inference context. session_id = %s", session_id.c_str()); + auto ret = runtime_infer_ctx->GetTensor(peer_node->GetOpDesc()->GetId(), out_data_anchor->GetIdx(), data); + if (ret == GRAPH_SUCCESS) { + return GRAPH_SUCCESS; + } + } + } else { + // For outer graph + return GetInputConstDataOut(dst_name, data); + } + auto op_name = GetName(); + GELOGW("node[%s]'s input[%s]'s peer node is not const", op_name.c_str(), dst_name.c_str()); + return GRAPH_FAILED; + } + + graphStatus GetInputConstDataOut(const string &dst_name, Tensor &data) { + ge::OpIO out_handle("", 0, nullptr); + if (GetInputImpl(dst_name, out_handle) != GRAPH_SUCCESS) { + GELOGE(FAILED, "%s get input impl failed", dst_name.c_str()); + return GRAPH_FAILED; + } + if (out_handle.GetOwner() != nullptr && out_handle.GetOwner()->GetOpDescImpl() != nullptr) { + Operator const_op(out_handle.GetOwner()); + const auto &op_desc_impl_type = out_handle.GetOwner()->GetOpDescImpl()->GetType(); + if (op_desc_impl_type == CONSTANTOP) { + return const_op.GetAttr(op::Constant::name_attr_value(), data); + } else if (op_desc_impl_type == CONSTANT) { + return const_op.GetAttr(op::Const::name_attr_value(), data); + } + } + return GRAPH_FAILED; + } + bool InputIsSet(const string &name) { GE_CHK_BOOL_EXEC(op_desc_ != nullptr, return false, "op_desc_ is nullptr."); return op_desc_->InputIsSet(name); @@ -493,6 +564,21 @@ Operator::Operator(const std::string &type) { OperatorKeeper::GetInstance().CheckInOperator(operator_impl_); } +Operator::Operator(const char *type) { + if (type != nullptr) { + std::string op_type = type; + static uint32_t index = 0; + string name = op_type + "_" + std::to_string(index++); + operator_impl_ = ComGraphMakeShared(name, op_type); + if (operator_impl_ == nullptr) { + GELOGW("OperatorImpl make shared failed"); + } + OperatorKeeper::GetInstance().CheckInOperator(operator_impl_); + } else { + GELOGW("Operator type is nullptr."); + } +} + GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Operator OpDescUtils::CreateOperatorFromOpDesc(OpDescPtr op_desc) { shared_ptr operator_impl_ptr; operator_impl_ptr = ComGraphMakeShared(op_desc); @@ -517,6 +603,36 @@ GE_FUNC_HOST_VISIBILITY Operator::Operator(const string &name, const string &typ OperatorKeeper::GetInstance().CheckInOperator(operator_impl_); } +GE_FUNC_HOST_VISIBILITY Operator::Operator(const AscendString &name, const AscendString &type) { + if ((name.GetString() != nullptr) && (type.GetString() != nullptr)) { + string op_name = name.GetString(); + string op_type = type.GetString(); + operator_impl_ = ComGraphMakeShared(op_name, op_type); + if (operator_impl_ == nullptr) { + GELOGE(GRAPH_FAILED, "OperatorImpl make shared failed"); + return; + } + OperatorKeeper::GetInstance().CheckInOperator(operator_impl_); + } else { + GELOGW("Operator input parameter is nullptr."); + } +} + +GE_FUNC_HOST_VISIBILITY Operator::Operator(const char *name, const char *type) { + if ((name != nullptr) && (type != nullptr)) { + string op_name = name; + string op_type = type; + operator_impl_ = ComGraphMakeShared(op_name, op_type); + if (operator_impl_ == nullptr) { + GELOGE(GRAPH_FAILED, "OperatorImpl make shared failed"); + return; + } + OperatorKeeper::GetInstance().CheckInOperator(operator_impl_); + } else { + GELOGW("Operator input parameter is nullptr."); + } +} + Operator::Operator(ge::OperatorImplPtr &&op_impl) { operator_impl_ = std::move(op_impl); } bool Operator::IsEmpty() const { @@ -533,6 +649,14 @@ string Operator::GetName() const { return ""; } +graphStatus Operator::GetName(AscendString &name) const { + if (operator_impl_ != nullptr) { + string op_name = operator_impl_->GetName(); + name = op_name.c_str(); + } + return GRAPH_SUCCESS; +} + GE_FUNC_HOST_VISIBILITY Operator &Operator::SetInput(const string &dst_name, const ge::Operator &src_oprt) { // Describe the connection relationship between operators, no create action GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return *this, "operator impl is nullptr."); @@ -540,6 +664,15 @@ GE_FUNC_HOST_VISIBILITY Operator &Operator::SetInput(const string &dst_name, con return *this; } +GE_FUNC_HOST_VISIBILITY Operator &Operator::SetInput(const char *dst_name, const ge::Operator &src_oprt) { + GE_CHK_BOOL_EXEC(dst_name != nullptr, return *this, "Operator dst name is nullptr."); + // Describe the connection relationship between operators, no create action + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return *this, "Operator impl is nullptr."); + std::string dst_op_name = dst_name; + operator_impl_->SetInputImpl(dst_op_name, src_oprt); + return *this; +} + Operator &Operator::SetInput(const string &dst_name, const ge::OutHandler &out_handler) { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return *this, "operator impl is nullptr."); operator_impl_->SetInputImpl(dst_name, out_handler); @@ -553,6 +686,17 @@ Operator &Operator::SetInput(const std::string &dst_name, const ge::Operator &sr return *this; } +Operator &Operator::SetInput(const char *dst_name, const ge::Operator &src_oprt, const char *name) { + GE_CHK_BOOL_EXEC(dst_name != nullptr, return *this, "Dst name is nullptr."); + GE_CHK_BOOL_EXEC(name != nullptr, return *this, "Name is nullptr."); + std::string op_name = name; + std::string dst_op_name = dst_name; + auto out_handler = src_oprt.GetOutput(op_name); + GE_CHK_BOOL_EXEC(out_handler != nullptr, return *this, "Out_handler is nullptr."); + (void)SetInput(dst_op_name, out_handler); + return *this; +} + Operator &Operator::SetInput(const std::string &dst_name, const ge::Operator &src_oprt, uint32_t index) { auto out_handler = src_oprt.GetOutput(index); GE_CHK_BOOL_EXEC(out_handler != nullptr, return *this, "out_handler is nullptr."); @@ -560,6 +704,15 @@ Operator &Operator::SetInput(const std::string &dst_name, const ge::Operator &sr return *this; } +Operator &Operator::SetInput(const char *dst_name, const ge::Operator &src_oprt, uint32_t index) { + GE_CHK_BOOL_EXEC(dst_name != nullptr, return *this, "Dst name is nullptr."); + auto out_handler = src_oprt.GetOutput(index); + GE_CHK_BOOL_EXEC(out_handler != nullptr, return *this, "out_handler is nullptr."); + std::string op_dst_name = dst_name; + (void)SetInput(dst_name, out_handler); + return *this; +} + Operator &Operator::AddControlInput(const Operator &src_oprt) { if (operator_impl_ == nullptr) { GELOGE(GRAPH_FAILED, "operator impl is nullptr."); @@ -571,74 +724,31 @@ Operator &Operator::AddControlInput(const Operator &src_oprt) { graphStatus Operator::GetInputConstData(const string &dst_name, Tensor &data) const { GE_CHECK_NOTNULL(operator_impl_); - auto node_ptr = operator_impl_->GetNode(); - if (node_ptr != nullptr) { - // For inner compute graph - auto op_desc = node_ptr->GetOpDesc(); - GE_CHECK_NOTNULL(op_desc); - auto index = op_desc->GetInputIndexByName(dst_name); - auto in_data_anchor = node_ptr->GetInDataAnchor(index); - GE_CHECK_NOTNULL(in_data_anchor); - auto out_data_anchor = in_data_anchor->GetPeerOutAnchor(); - GE_CHECK_NOTNULL(out_data_anchor); - auto peer_node = out_data_anchor->GetOwnerNode(); - GE_CHECK_NOTNULL(peer_node); - auto peer_op_desc = peer_node->GetOpDesc(); - GE_CHECK_NOTNULL(peer_op_desc); - auto peer_op_type = peer_op_desc->GetType(); - if (peer_op_type == CONSTANTOP || peer_op_type == CONSTANT) { - auto const_op_impl = ComGraphMakeShared(peer_node); - GE_CHECK_NOTNULL(const_op_impl); - Operator const_op(std::move(const_op_impl)); - return const_op.GetAttr(ATTR_NAME_WEIGHTS, data); - } else if (peer_op_type == DATA) { - auto parent_node = NodeUtils::GetParentInput(peer_node); - while ((parent_node != nullptr) && (parent_node->GetType() == DATA)) { - parent_node = NodeUtils::GetParentInput(parent_node); - } - if ((parent_node != nullptr) && - ((parent_node->GetType() == CONSTANT) || (parent_node->GetType() == CONSTANTOP))) { - auto const_op_impl = ComGraphMakeShared(parent_node); - GE_CHECK_NOTNULL(const_op_impl); - Operator const_op(std::move(const_op_impl)); - return const_op.GetAttr(ATTR_NAME_WEIGHTS, data); - } - } - // Try get from runtime inference context - auto session_id = std::to_string(GetContext().SessionId()); - RuntimeInferenceContext *runtime_infer_ctx = nullptr; - if (RuntimeInferenceContext::GetContext(session_id, &runtime_infer_ctx) == GRAPH_SUCCESS) { - GELOGD("To get constant from runtime inference context. session_id = %s", session_id.c_str()); - auto ret = runtime_infer_ctx->GetTensor(peer_node->GetOpDesc()->GetId(), out_data_anchor->GetIdx(), data); - if (ret == GRAPH_SUCCESS) { - return GRAPH_SUCCESS; - } - } - } else { - // For outer graph - return GetInputConstDataOut(dst_name, data); + if (operator_impl_->GetInputConstData(dst_name, data) != GRAPH_SUCCESS) { + GELOGE(GRAPH_FAILED, "%s get input const data failed", dst_name.c_str()); + return GRAPH_FAILED; } - auto op_name = operator_impl_->GetName(); - GELOGW("node[%s]'s input[%s]'s peer node is not const", op_name.c_str(), dst_name.c_str()); - return GRAPH_FAILED; + return GRAPH_SUCCESS; } -graphStatus Operator::GetInputConstDataOut(const string &dst_name, Tensor &data) const { - ge::OpIO out_handle("", 0, nullptr); + +graphStatus Operator::GetInputConstData(const char *dst_name, Tensor &data) const { + GE_CHECK_NOTNULL(dst_name); GE_CHECK_NOTNULL(operator_impl_); - if (operator_impl_->GetInputImpl(dst_name, out_handle) != GRAPH_SUCCESS) { - GELOGE(FAILED, "%s get input impl failed", dst_name.c_str()); + std::string op_dst_name = dst_name; + if (operator_impl_->GetInputConstData(op_dst_name, data) != GRAPH_SUCCESS) { + GELOGE(GRAPH_FAILED, "%s get input const data failed", op_dst_name.c_str()); return GRAPH_FAILED; } - if (out_handle.GetOwner() != nullptr && out_handle.GetOwner()->GetOpDescImpl() != nullptr) { - Operator const_op(out_handle.GetOwner()); - const auto &op_desc_impl_type = out_handle.GetOwner()->GetOpDescImpl()->GetType(); - if (op_desc_impl_type == CONSTANTOP) { - return const_op.GetAttr(op::Constant::name_attr_value(), data); - } else if (op_desc_impl_type == CONSTANT) { - return const_op.GetAttr(op::Const::name_attr_value(), data); - } + return GRAPH_SUCCESS; +} + +graphStatus Operator::GetInputConstDataOut(const string &dst_name, Tensor &data) const { + GE_CHECK_NOTNULL(operator_impl_); + if (operator_impl_->GetInputConstDataOut(dst_name, data) != GRAPH_SUCCESS) { + GELOGE(GRAPH_FAILED, "%s get input const data out failed", dst_name.c_str()); + return GRAPH_FAILED; } - return GRAPH_FAILED; + return GRAPH_SUCCESS; } std::shared_ptr Operator::GetNode() const { @@ -651,6 +761,13 @@ TensorDesc Operator::GetInputDesc(const std::string &name) const { return TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetInputDesc(name)); } +TensorDesc Operator::GetInputDesc(const char *name, uint32_t len) const { + GE_CHK_BOOL_EXEC(name != nullptr, return TensorDesc(), "Operator name is nullptr."); + std::string op_name = name; + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return TensorDesc(), "Operator impl is nullptr."); + return TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetInputDesc(op_name)); +} + void Operator::SetInferenceContext(const InferenceContextPtr &inference_context) { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return, "operator impl is nullptr."); operator_impl_->SetInferenceContext(inference_context); @@ -660,6 +777,7 @@ InferenceContextPtr Operator::GetInferenceContext() const { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return nullptr, "operator impl is nullptr."); return operator_impl_->GetInferenceContext(); } + TensorDesc Operator::GetInputDesc(uint32_t index) const { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return TensorDesc(), "operator impl is nullptr."); return TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetInputDesc(index)); @@ -672,11 +790,27 @@ graphStatus Operator::TryGetInputDesc(const string &name, TensorDesc &tensor_des return check ? GRAPH_SUCCESS : GRAPH_FAILED; } +graphStatus Operator::TryGetInputDesc(const char *name, TensorDesc &tensor_desc) const { + GE_CHK_BOOL_EXEC(name != nullptr, return GRAPH_FAILED, "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "Operator impl is nullptr."); + std::string op_name = name; + auto check = operator_impl_->InputIsSet(op_name); + if (check) tensor_desc = TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetInputDesc(op_name)); + return check ? GRAPH_SUCCESS : GRAPH_FAILED; +} + graphStatus Operator::UpdateInputDesc(const std::string &name, const ge::TensorDesc &tensor_desc) { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "operator impl is nullptr."); return operator_impl_->UpdateInputDesc(name, TensorAdapter::TensorDesc2GeTensorDesc(tensor_desc)); } +graphStatus Operator::UpdateInputDesc(const char *name, const ge::TensorDesc &tensor_desc) { + GE_CHK_BOOL_EXEC(name != nullptr, return GRAPH_FAILED, "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "Operator impl is nullptr."); + std::string op_name = name; + return operator_impl_->UpdateInputDesc(op_name, TensorAdapter::TensorDesc2GeTensorDesc(tensor_desc)); +} + OutHandler Operator::GetOutput(const string &name) const { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return nullptr, "operator impl is nullptr."); return operator_impl_->GetOutput(name); @@ -692,6 +826,13 @@ TensorDesc Operator::GetOutputDesc(const std::string &name) const { return TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetOutputDesc(name)); } +TensorDesc Operator::GetOutputDesc(const char *name, uint32_t len) const { + GE_CHK_BOOL_EXEC(name != nullptr, return TensorDesc(), "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return TensorDesc(), "Operator impl is nullptr."); + std::string op_name = name; + return TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetOutputDesc(op_name)); +} + TensorDesc Operator::GetOutputDesc(uint32_t index) const { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return TensorDesc(), "operator impl is nullptr."); return TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetOutputDesc(index)); @@ -702,28 +843,64 @@ graphStatus Operator::UpdateOutputDesc(const std::string &name, const ge::Tensor return operator_impl_->UpdateOutputDesc(name, TensorAdapter::TensorDesc2GeTensorDesc(tensor_desc)); } +graphStatus Operator::UpdateOutputDesc(const char *name, const ge::TensorDesc &tensor_desc) { + GE_CHK_BOOL_EXEC(name != nullptr, return GRAPH_FAILED, "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "Operator impl is nullptr."); + std::string op_name = name; + return operator_impl_->UpdateOutputDesc(op_name, TensorAdapter::TensorDesc2GeTensorDesc(tensor_desc)); +} + TensorDesc Operator::GetDynamicInputDesc(const string &name, uint32_t index) const { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return TensorDesc(), "operator impl is nullptr."); return TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetInputDesc(name + std::to_string(index))); } +TensorDesc Operator::GetDynamicInputDesc(const char *name, uint32_t index) const { + GE_CHK_BOOL_EXEC(name != nullptr, return TensorDesc(), "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return TensorDesc(), "Operator impl is nullptr."); + std::string op_name = name; + return TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetInputDesc(op_name + std::to_string(index))); +} + graphStatus Operator::UpdateDynamicInputDesc(const string &name, uint32_t index, const TensorDesc &tensor_desc) { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "operator impl is nullptr."); return operator_impl_->UpdateInputDesc(name + std::to_string(index), TensorAdapter::TensorDesc2GeTensorDesc(tensor_desc)); } +graphStatus Operator::UpdateDynamicInputDesc(const char *name, uint32_t index, const TensorDesc &tensor_desc) { + GE_CHK_BOOL_EXEC(name != nullptr, return GRAPH_FAILED, "Operator name is nullptr."); + std::string op_name = name; + return operator_impl_->UpdateInputDesc(op_name + std::to_string(index), + TensorAdapter::TensorDesc2GeTensorDesc(tensor_desc)); +} + TensorDesc Operator::GetDynamicOutputDesc(const string &name, uint32_t index) const { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return TensorDesc(), "operator impl is nullptr."); return TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetOutputDesc(name + std::to_string(index))); } +TensorDesc Operator::GetDynamicOutputDesc(const char *name, uint32_t index) const { + GE_CHK_BOOL_EXEC(name != nullptr, return TensorDesc(), "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return TensorDesc(), "Operator impl is nullptr."); + std::string op_name = name; + return TensorAdapter::GeTensorDesc2TensorDesc(operator_impl_->GetOutputDesc(op_name + std::to_string(index))); +} + graphStatus Operator::UpdateDynamicOutputDesc(const string &name, uint32_t index, const TensorDesc &tensor_desc) { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "operator impl is nullptr."); return operator_impl_->UpdateOutputDesc(name + std::to_string(index), TensorAdapter::TensorDesc2GeTensorDesc(tensor_desc)); } +graphStatus Operator::UpdateDynamicOutputDesc(const char *name, uint32_t index, const TensorDesc &tensor_desc) { + GE_CHK_BOOL_EXEC(name != nullptr, return GRAPH_FAILED, "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "Operator impl is nullptr."); + std::string op_name = name; + return operator_impl_->UpdateOutputDesc(op_name + std::to_string(index), + TensorAdapter::TensorDesc2GeTensorDesc(tensor_desc)); +} + graphStatus Operator::InferShapeAndType() { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "operator impl is nullptr."); GE_CHK_BOOL_EXEC(operator_impl_->GetOpDescImpl() != nullptr, return GRAPH_FAILED, "GetOpDescImpl is nullptr."); @@ -803,6 +980,28 @@ const std::map Operator::GetAllAttrNamesAndTypes() con return attr_types; } +graphStatus Operator::GetAllAttrNamesAndTypes(std::map &attr_name_types) const { + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "Operator impl is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_->GetOpDescImpl() != nullptr, return GRAPH_FAILED, "GetOpDescImpl is nullptr."); + std::map attr_map = operator_impl_->GetOpDescImpl()->GetAllAttrs(); + + map::iterator iter; + for (iter = attr_map.begin(); iter != attr_map.end(); ++iter) { + string name = iter->first; + GeAttrValue attr_value = iter->second; + + GeAttrValue::ValueType type = attr_value.GetValueType(); + + auto iter2 = kAttrTypesMap.find(type); + if (iter2 != kAttrTypesMap.end()) { + AscendString temp(name.c_str()); + attr_name_types[temp] = AscendString(iter2->second.c_str()); + } + } + + return GRAPH_SUCCESS; +} + void Operator::InputRegister(const string &name) { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return, "operator impl is nullptr."); GE_CHK_BOOL_EXEC(operator_impl_->GetOpDescImpl() != nullptr, return, "GetOpDescImpl is nullptr."); @@ -868,6 +1067,17 @@ int Operator::GetDynamicInputNum(const string &name) const { return num; } +int Operator::GetDynamicInputNum(const char *name) const { + GE_CHK_BOOL_EXEC(name != nullptr, return 0, "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return 0, "Operator impl is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_->GetOpDescImpl() != nullptr, return 0, "GetOpDescImpl is nullptr."); + string op_name = name; + int num = 0; + GE_CHK_BOOL_EXEC(AttrUtils::GetInt(operator_impl_->GetOpDescImpl(), DYNAMIC_INPUT_TD_NUM(op_name), num), return num, + "Get %s int failed", op_name.c_str()); + return num; +} + void Operator::DynamicOutputRegister(const string &name, const unsigned int num, bool is_push_back) { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return, "operator impl is nullptr."); GE_CHK_BOOL_EXEC(operator_impl_->GetOpDescImpl() != nullptr, return, "GetOpDescImpl is nullptr."); @@ -885,6 +1095,17 @@ int Operator::GetDynamicOutputNum(const string &name) const { return num; } +int Operator::GetDynamicOutputNum(const char *name) const { + GE_CHK_BOOL_EXEC(name != nullptr, return 0, "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return 0, "Operator impl is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_->GetOpDescImpl() != nullptr, return 0, "GetOpDescImpl is nullptr."); + std::string op_name = name; + int num = 0; + GE_CHK_BOOL_EXEC(AttrUtils::GetInt(operator_impl_->GetOpDescImpl(), DYNAMIC_OUTPUT_TD_NUM(op_name), num), return num, + "Get %s int failed", op_name.c_str()); + return num; +} + void Operator::RequiredAttrRegister(const string &name) { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return, "operator impl is nullptr."); GE_CHK_BOOL_EXEC(operator_impl_->GetOpDescImpl() != nullptr, return, "GetOpDescImpl is nullptr."); @@ -920,6 +1141,13 @@ string Operator::GetOpType() const { return OperatorImpl::GetOpDesc(*this)->GetType(); } +graphStatus Operator::GetOpType(AscendString &type) const { + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "Operator impl is nullptr."); + std::string op_type = OperatorImpl::GetOpDesc(*this)->GetType(); + type = op_type.c_str(); + return GRAPH_SUCCESS; +} + Operator &Operator::SetInput(const std::string &dst_name, uint32_t dst_index, const ge::Operator &src_oprt) { string dynamic_dst_name = DYNAMIN_INPUT_NAME(dst_name, dst_index); return SetInput(dynamic_dst_name, src_oprt); @@ -933,29 +1161,60 @@ Operator &Operator::SetInput(const std::string &dst_name, uint32_t dst_index, co OperatorImplPtr Operator::GetOperatorImplPtr() const { return operator_impl_; } -#define OP_ATTR_SET_IMP(ArgType, AttrUtilsFun) \ - Operator &Operator::SetAttr(const string &name, ArgType attr_value) { \ - if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { \ - GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); \ - return *this; \ - } \ - if (!AttrUtils::Set##AttrUtilsFun(operator_impl_->GetOpDescImpl(), name, attr_value)) { \ - GELOGW("set attr name %s failed.", name.c_str()); \ - } \ - return *this; \ - } - -#define OP_ATTR_GET_IMP(ArgType, AttrUtilsFun) \ - graphStatus Operator::GetAttr(const string &name, ArgType attr_value) const { \ - if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { \ - GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); \ - return GRAPH_FAILED; \ - } \ - if (!AttrUtils::Get##AttrUtilsFun(operator_impl_->GetOpDescImpl(), name, attr_value)) { \ - GELOGW("get attr name %s failed.", name.c_str()); \ - return GRAPH_FAILED; \ - } \ - return GRAPH_SUCCESS; \ +#define OP_ATTR_SET_IMP(ArgType, AttrUtilsFun) \ + Operator &Operator::SetAttr(const string &name, ArgType attr_value) { \ + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { \ + GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); \ + return *this; \ + } \ + if (!AttrUtils::Set##AttrUtilsFun(operator_impl_->GetOpDescImpl(), name, attr_value)) { \ + GELOGW("set attr name %s failed.", name.c_str()); \ + } \ + return *this; \ + } \ + Operator &Operator::SetAttr(const char *name, ArgType attr_value) { \ + if (name == nullptr) { \ + GELOGE(GRAPH_FAILED, "operator attr name is nullptr."); \ + return *this; \ + } \ + std::string op_name = name; \ + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { \ + GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", op_name.c_str()); \ + return *this; \ + } \ + if (!AttrUtils::Set##AttrUtilsFun(operator_impl_->GetOpDescImpl(), op_name, attr_value)) { \ + GELOGW("set attr name %s failed.", op_name.c_str()); \ + } \ + return *this; \ + } + +#define OP_ATTR_GET_IMP(ArgType, AttrUtilsFun) \ + graphStatus Operator::GetAttr(const string &name, ArgType attr_value) const { \ + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { \ + GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); \ + return GRAPH_FAILED; \ + } \ + if (!AttrUtils::Get##AttrUtilsFun(operator_impl_->GetOpDescImpl(), name, attr_value)) { \ + GELOGW("get attr name %s failed.", name.c_str()); \ + return GRAPH_FAILED; \ + } \ + return GRAPH_SUCCESS; \ + } \ + graphStatus Operator::GetAttr(const char *name, ArgType attr_value) const { \ + if (name == nullptr) { \ + GELOGE(GRAPH_FAILED, "operator attr name is nullptr."); \ + return GRAPH_FAILED; \ + } \ + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { \ + GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name); \ + return GRAPH_FAILED; \ + } \ + std::string op_name = name; \ + if (!AttrUtils::Get##AttrUtilsFun(operator_impl_->GetOpDescImpl(), op_name, attr_value)) { \ + GELOGW("get attr name %s failed.", op_name.c_str()); \ + return GRAPH_FAILED; \ + } \ + return GRAPH_SUCCESS; \ } void Operator::BreakConnect() const { @@ -1005,11 +1264,6 @@ OP_ATTR_GET_IMP(bool &, Bool) OP_ATTR_SET_IMP(const vector &, ListBool) OP_ATTR_GET_IMP(vector &, ListBool) -OP_ATTR_SET_IMP(const string &, Str) -OP_ATTR_GET_IMP(string &, Str) -OP_ATTR_SET_IMP(const vector &, ListStr) -OP_ATTR_GET_IMP(vector &, ListStr) - OP_ATTR_SET_IMP(const GeAttrValue::NAMED_ATTRS &, NamedAttrs) OP_ATTR_GET_IMP(GeAttrValue::NAMED_ATTRS &, NamedAttrs) OP_ATTR_SET_IMP(const vector &, ListNamedAttrs) @@ -1031,6 +1285,151 @@ OP_ATTR_REG_IMP(const vector &, ListNamedAttrs) #undef OP_ATTR_GET_IMP #undef OP_ATTR_REG_IMP +Operator &Operator::SetAttr(const string &name, const string &attr_value) { + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name.c_str()); + return *this; + } + if (!AttrUtils::SetStr(operator_impl_->GetOpDescImpl(), name, attr_value)) { + GELOGW("Set attr name %s failed.", name.c_str()); + } + return *this; +} + +graphStatus Operator::GetAttr(const string &name, string &attr_value) const { + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name.c_str()); + return GRAPH_FAILED; + } + if (!AttrUtils::GetStr(operator_impl_->GetOpDescImpl(), name, attr_value)) { + GELOGW("Get attr name %s failed.", name.c_str()); + return GRAPH_FAILED; + } + return GRAPH_SUCCESS; +} + +Operator &Operator::SetAttr(const string &name, const std::vector &attr_value) { + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name.c_str()); + return *this; + } + if (!AttrUtils::SetListStr(operator_impl_->GetOpDescImpl(), name, attr_value)) { + GELOGW("Set attr name %s failed.", name.c_str()); + } + return *this; +} + +graphStatus Operator::GetAttr(const string &name, std::vector &attr_value) const { + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name.c_str()); + return GRAPH_FAILED; + } + if (!AttrUtils::GetListStr(operator_impl_->GetOpDescImpl(), name, attr_value)) { + GELOGW("Get attr name %s failed.", name.c_str()); + return GRAPH_FAILED; + } + return GRAPH_SUCCESS; +} + +Operator &Operator::SetAttr(const char *name, const char *attr_value) { + if (name == nullptr || attr_value == nullptr) { + GELOGE(GRAPH_FAILED, "Operator input parameters is nullptr."); + return *this; + } + + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return *this; + } + std::string op_name = name; + std::string op_attr_value = attr_value; + if (!AttrUtils::SetStr(operator_impl_->GetOpDescImpl(), op_name, op_attr_value)) { + GELOGW("Set attr name %s failed.", op_name.c_str()); + } + return *this; +} + +Operator &Operator::SetAttr(const char *name, const AscendString &attr_value) { + if (name == nullptr || attr_value.GetString() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator input parameters is nullptr."); + return *this; + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return *this; + } + std::string op_name = name; + std::string op_attr_value = attr_value.GetString(); + if (!AttrUtils::SetStr(operator_impl_->GetOpDescImpl(), op_name, op_attr_value)) { + GELOGW("Set attr name %s failed.", op_name.c_str()); + } + return *this; +} + +graphStatus Operator::GetAttr(const char *name, AscendString &attr_value) const { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator input parameters is nullptr."); + return GRAPH_FAILED; + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return GRAPH_FAILED; + } + std::string op_name = name; + std::string op_attr_value; + if (!AttrUtils::GetStr(operator_impl_->GetOpDescImpl(), op_name, op_attr_value)) { + GELOGW("Get attr name %s failed.", op_name.c_str()); + return GRAPH_FAILED; + } + attr_value = AscendString(op_attr_value.c_str()); + return GRAPH_SUCCESS; +} + +Operator &Operator::SetAttr(const char *name, const std::vector &attr_values) { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return *this; + } + std::vector op_attr_values; + for (auto &attr_value : attr_values) { + if (attr_value.GetString() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator ascend string name is nullptr."); + return *this; + } + op_attr_values.emplace_back(attr_value.GetString()); + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return *this; + } + std::string op_name = name; + if (!AttrUtils::SetListStr(operator_impl_->GetOpDescImpl(), op_name, op_attr_values)) { + GELOGW("Set attr name %s failed.", op_name.c_str()); + } + return *this; +} + +graphStatus Operator::GetAttr(const char *name, std::vector &attr_value) const { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return GRAPH_FAILED; + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return GRAPH_FAILED; + } + std::string op_name = name; + std::vector op_attr_values; + if (!AttrUtils::GetListStr(operator_impl_->GetOpDescImpl(), op_name, op_attr_values)) { + GELOGW("Get attr name %s failed.", op_name.c_str()); + return GRAPH_FAILED; + } + for (auto &op_attr_value : op_attr_values) { + attr_value.emplace_back(AscendString(op_attr_value.c_str())); + } + return GRAPH_SUCCESS; +} + Operator &Operator::SetAttr(const string &name, const Tensor &attr_value) { if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); @@ -1043,6 +1442,23 @@ Operator &Operator::SetAttr(const string &name, const Tensor &attr_value) { return *this; } +Operator &Operator::SetAttr(const char *name, const Tensor &attr_value) { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return *this; + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name); + return *this; + } + std::string op_name = name; + GeTensor tensor = TensorAdapter::AsGeTensor(attr_value); + if (!AttrUtils::SetTensor(operator_impl_->GetOpDescImpl(), op_name, tensor)) { + GELOGW("set attr name %s failed.", op_name.c_str()); + } + return *this; +} + Operator &Operator::SetAttr(const string &name, const vector &attr_value) { if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); @@ -1059,6 +1475,27 @@ Operator &Operator::SetAttr(const string &name, const vector &attr_value return *this; } +Operator &Operator::SetAttr(const char *name, const vector &attr_value) { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return *this; + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return *this; + } + std::string op_name = name; + vector val_list; + for (const auto &item : attr_value) { + auto tensor = TensorAdapter::AsGeTensor(item); + val_list.push_back(tensor); + } + if (!AttrUtils::SetListTensor(operator_impl_->GetOpDescImpl(), op_name, val_list)) { + GELOGW("Set attr name %s failed.", op_name.c_str()); + } + return *this; +} + graphStatus Operator::GetAttr(const string &name, Tensor &attr_value) const { if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); @@ -1073,6 +1510,25 @@ graphStatus Operator::GetAttr(const string &name, Tensor &attr_value) const { return GRAPH_SUCCESS; } +graphStatus Operator::GetAttr(const char *name, Tensor &attr_value) const { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return GRAPH_FAILED; + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name); + return GRAPH_FAILED; + } + std::string op_name = name; + ConstGeTensorPtr tensor; + if (!AttrUtils::GetTensor(operator_impl_->GetOpDescImpl(), op_name, tensor)) { + GELOGW("get attr name %s failed.", op_name.c_str()); + return GRAPH_FAILED; + } + attr_value = TensorAdapter::GeTensor2Tensor(tensor); + return GRAPH_SUCCESS; +} + graphStatus Operator::GetAttr(const string &name, vector &attr_value) const { attr_value.clear(); if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { @@ -1090,6 +1546,28 @@ graphStatus Operator::GetAttr(const string &name, vector &attr_value) co return GRAPH_SUCCESS; } +graphStatus Operator::GetAttr(const char *name, vector &attr_value) const { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return GRAPH_FAILED; + } + attr_value.clear(); + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return GRAPH_FAILED; + } + std::string op_name = name; + vector val_list; + if (!AttrUtils::GetListTensor(operator_impl_->GetOpDescImpl(), op_name, val_list)) { + GELOGW("get attr name %s failed.", op_name.c_str()); + return GRAPH_FAILED; + } + for (auto &tensor : val_list) { + attr_value.push_back(TensorAdapter::GeTensor2Tensor(tensor)); + } + return GRAPH_SUCCESS; +} + Operator &Operator::SetAttr(const string &name, const OpBytes &attr_value) { if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); @@ -1102,6 +1580,23 @@ Operator &Operator::SetAttr(const string &name, const OpBytes &attr_value) { return *this; } +Operator &Operator::SetAttr(const char *name, const OpBytes &attr_value) { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return *this; + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return *this; + } + std::string op_name = name; + if (!AttrUtils::SetZeroCopyBytes(operator_impl_->GetOpDescImpl(), op_name, + Buffer::CopyFrom(attr_value.data(), attr_value.size()))) { + GELOGW("Set attr name %s failed.", op_name.c_str()); + } + return *this; +} + graphStatus Operator::GetAttr(const string &name, OpBytes &attr_value) const { if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); @@ -1121,17 +1616,56 @@ graphStatus Operator::GetAttr(const string &name, OpBytes &attr_value) const { return GRAPH_SUCCESS; } +graphStatus Operator::GetAttr(const char *name, OpBytes &attr_value) const { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return GRAPH_FAILED; + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return GRAPH_FAILED; + } + std::string op_name = name; + Buffer buffer; + if (!AttrUtils::GetZeroCopyBytes(operator_impl_->GetOpDescImpl(), op_name, buffer)) { + GELOGW("Get attr name %s failed.", op_name.c_str()); + return GRAPH_FAILED; + } + attr_value.clear(); + if (buffer.data() == nullptr) { + GELOGE(GRAPH_FAILED, "Buffer data is null."); + return GRAPH_FAILED; + } + attr_value.assign(buffer.data(), buffer.data() + buffer.size()); + return GRAPH_SUCCESS; +} + Operator &Operator::SetAttr(const string &name, ge::AttrValue &&attrValue) { - GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return *this, "operator impl is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return *this, "Operator impl is nullptr."); (void)operator_impl_->SetAttr(name, std::move(attrValue.impl->geAttrValue_)); return *this; } +Operator &Operator::SetAttr(const char *name, ge::AttrValue &&attrValue) { + GE_CHK_BOOL_EXEC(name != nullptr, return *this, "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return *this, "Operator impl is nullptr."); + std::string op_name = name; + (void)operator_impl_->SetAttr(op_name, std::move(attrValue.impl->geAttrValue_)); + return *this; +} + graphStatus Operator::GetAttr(const string &name, ge::AttrValue &attrValue) const { GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "operator impl is nullptr."); return operator_impl_->GetAttr(name, attrValue.impl->geAttrValue_); } +graphStatus Operator::GetAttr(const char *name, ge::AttrValue &attrValue) const { + GE_CHK_BOOL_EXEC(name != nullptr, return GRAPH_FAILED, "Operator name is nullptr."); + GE_CHK_BOOL_EXEC(operator_impl_ != nullptr, return GRAPH_FAILED, "Operator impl is nullptr."); + std::string op_name = name; + return operator_impl_->GetAttr(op_name, attrValue.impl->geAttrValue_); +} + Operator &Operator::SetAttr(const string &name, const std::vector &attr_value) { if (operator_impl_ == nullptr || !operator_impl_->GetOpDescImpl()) { GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); @@ -1143,6 +1677,22 @@ Operator &Operator::SetAttr(const string &name, const std::vector return *this; } +Operator &Operator::SetAttr(const char *name, const std::vector &attr_value) { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return *this; + } + if (operator_impl_ == nullptr || !operator_impl_->GetOpDescImpl()) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return *this; + } + std::string op_name = name; + if (!AttrUtils::SetListDataType(operator_impl_->GetOpDescImpl(), op_name, attr_value)) { + GELOGW("Set attr name %s failed.", op_name.c_str()); + } + return *this; +} + graphStatus Operator::GetAttr(const string &name, std::vector &attr_value) const { attr_value.clear(); if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { @@ -1156,6 +1706,24 @@ graphStatus Operator::GetAttr(const string &name, std::vector &att return GRAPH_SUCCESS; } +graphStatus Operator::GetAttr(const char *name, std::vector &attr_value) const { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return GRAPH_FAILED; + } + attr_value.clear(); + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return GRAPH_FAILED; + } + std::string op_name = name; + if (!AttrUtils::GetListDataType(operator_impl_->GetOpDescImpl(), op_name, attr_value)) { + GELOGW("Get attr name %s failed.", op_name.c_str()); + return GRAPH_FAILED; + } + return GRAPH_SUCCESS; +} + Operator &Operator::SetAttr(const string &name, const ge::DataType &attr_value) { if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); @@ -1167,6 +1735,22 @@ Operator &Operator::SetAttr(const string &name, const ge::DataType &attr_value) return *this; } +Operator &Operator::SetAttr(const char *name, const ge::DataType &attr_value) { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return *this; + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return *this; + } + std::string op_name = name; + if (!AttrUtils::SetDataType(operator_impl_->GetOpDescImpl(), op_name, attr_value)) { + GELOGW("Set attr name %s failed.", op_name.c_str()); + } + return *this; +} + graphStatus Operator::GetAttr(const string &name, ge::DataType &attr_value) const { if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); @@ -1179,6 +1763,23 @@ graphStatus Operator::GetAttr(const string &name, ge::DataType &attr_value) cons return GRAPH_SUCCESS; } +graphStatus Operator::GetAttr(const char *name, ge::DataType &attr_value) const { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return GRAPH_FAILED; + } + if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr, name %s.", name); + return GRAPH_FAILED; + } + std::string op_name = name; + if (!AttrUtils::GetDataType(operator_impl_->GetOpDescImpl(), op_name, attr_value)) { + GELOGW("Get attr name %s failed.", op_name.c_str()); + return GRAPH_FAILED; + } + return GRAPH_SUCCESS; +} + void Operator::AttrRegister(const string &name, const std::vector &attr_value) { if (operator_impl_ == nullptr || operator_impl_->GetOpDescImpl() == nullptr) { GELOGE(GRAPH_FAILED, "operator impl is nullptr, name %s.", name.c_str()); @@ -1261,6 +1862,14 @@ void Operator::SetSubgraphBuilder(const std::string &ir_name, uint32_t index, co std::vector Operator::GetSubgraphNames() const { return operator_impl_->GetSubgraphNames(); } +graphStatus Operator::GetSubgraphNames(std::vector &names) const { + std::vector subgraph_names = operator_impl_->GetSubgraphNames(); + for (auto &subgraph_name : subgraph_names) { + names.emplace_back(subgraph_name.c_str()); + } + return GRAPH_SUCCESS; +} + SubgraphBuilder Operator::GetDynamicSubgraphBuilder(const string &ir_name, uint32_t index) const { if (operator_impl_ == nullptr) { GELOGE(GRAPH_FAILED, "operator impl is nullptr."); @@ -1269,11 +1878,32 @@ SubgraphBuilder Operator::GetDynamicSubgraphBuilder(const string &ir_name, uint3 return operator_impl_->GetSubgraphBuilder(ir_name, index); } +SubgraphBuilder Operator::GetDynamicSubgraphBuilder(const char *ir_name, uint32_t index) const { + if (operator_impl_ == nullptr) { + GELOGE(GRAPH_FAILED, "Operator impl is nullptr."); + return nullptr; + } + if (ir_name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return nullptr; + } + std::string op_ir_name = ir_name; + return operator_impl_->GetSubgraphBuilder(op_ir_name, index); +} + SubgraphBuilder Operator::GetSubgraphBuilder(const string &ir_name) const { return GetDynamicSubgraphBuilder(ir_name, 0); } -Graph Operator::GetSubgraph(const string &name) const { +SubgraphBuilder Operator::GetSubgraphBuilder(const char *ir_name) const { + std::string graph_ir_name; + if (ir_name != nullptr) { + graph_ir_name = ir_name; + } + return GetDynamicSubgraphBuilder(graph_ir_name, 0); +} + +Graph Operator::GetSubgraphImpl(const string &name) const { if (operator_impl_ == nullptr) { GE_LOGE("Failed to get subgraph %s, the operator impl is null", name.c_str()); return Graph(""); @@ -1314,10 +1944,30 @@ Graph Operator::GetSubgraph(const string &name) const { return GraphUtils::CreateGraphFromComputeGraph(subgraph); } +Graph Operator::GetSubgraph(const string &name) const { return GetSubgraphImpl(name); } + +Graph Operator::GetSubgraph(const char *name) const { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Get subgraph failed, name is nullptr."); + return Graph(""); + } + std::string op_name = name; + return GetSubgraphImpl(op_name); +} + Graph Operator::GetDynamicSubgraph(const string &name, uint32_t index) const { return GetSubgraph(name + std::to_string(index)); } +Graph Operator::GetDynamicSubgraph(const char *name, uint32_t index) const { + if (name == nullptr) { + GELOGE(GRAPH_FAILED, "Operator name is nullptr."); + return Graph(""); + } + std::string op_name = name; + return GetSubgraph(op_name + std::to_string(index)); +} + size_t Operator::GetSubgraphNamesCount() const { if (operator_impl_ == nullptr) { GE_LOGE("Failed to get subgraph names count, the operator impl is null"); diff --git a/src/common/graph/operator_factory.cc b/src/common/graph/operator_factory.cc index 43d61a7c..5f8b1c68 100644 --- a/src/common/graph/operator_factory.cc +++ b/src/common/graph/operator_factory.cc @@ -22,27 +22,90 @@ Operator OperatorFactory::CreateOperator(const std::string &operator_name, const return OperatorFactoryImpl::CreateOperator(operator_name, operator_type); } +Operator OperatorFactory::CreateOperator(const char *operator_name, const char *operator_type) { + if (operator_name == nullptr || operator_type == nullptr) { + GELOGE(GRAPH_FAILED, "Create Operator input parameter is nullptr."); + return Operator(); + } + std::string op_name = operator_name; + std::string op_type = operator_type; + return OperatorFactoryImpl::CreateOperator(op_name, op_type); +} + graphStatus OperatorFactory::GetOpsTypeList(std::vector &all_ops) { return OperatorFactoryImpl::GetOpsTypeList(all_ops); } +graphStatus OperatorFactory::GetOpsTypeList(std::vector &all_ops) { + std::vector all_op_types; + if (OperatorFactoryImpl::GetOpsTypeList(all_op_types) != GRAPH_SUCCESS) { + GELOGE(GRAPH_FAILED, "Get ops type list failed."); + return GRAPH_FAILED; + } + for (auto &op_type : all_op_types) { + all_ops.emplace_back(op_type.c_str()); + } + return GRAPH_SUCCESS; +} + bool OperatorFactory::IsExistOp(const string &operator_type) { return OperatorFactoryImpl::IsExistOp(operator_type); } +bool OperatorFactory::IsExistOp(const char *operator_type) { + if (operator_type == nullptr) { + GELOGE(GRAPH_FAILED, "Operator type is nullptr."); + return false; + } + std::string op_type = operator_type; + return OperatorFactoryImpl::IsExistOp(op_type); +} + OperatorCreatorRegister::OperatorCreatorRegister(const string &operator_type, OpCreator const &op_creator) { (void)OperatorFactoryImpl::RegisterOperatorCreator(operator_type, op_creator); } +OperatorCreatorRegister::OperatorCreatorRegister(const char *operator_type, OpCreatorV2 const &op_creator) { + std::string op_type; + if (operator_type != nullptr) { + op_type = operator_type; + } + (void)OperatorFactoryImpl::RegisterOperatorCreator(op_type, op_creator); +} + InferShapeFuncRegister::InferShapeFuncRegister(const std::string &operator_type, const InferShapeFunc &infer_shape_func) { (void)OperatorFactoryImpl::RegisterInferShapeFunc(operator_type, infer_shape_func); } +InferShapeFuncRegister::InferShapeFuncRegister(const char *operator_type, const InferShapeFunc &infer_shape_func) { + std::string op_type; + if (operator_type != nullptr) { + op_type = operator_type; + } + (void)OperatorFactoryImpl::RegisterInferShapeFunc(op_type, infer_shape_func); +} + InferFormatFuncRegister::InferFormatFuncRegister(const std::string &operator_type, const InferFormatFunc &infer_format_func) { (void)OperatorFactoryImpl::RegisterInferFormatFunc(operator_type, infer_format_func); } +InferFormatFuncRegister::InferFormatFuncRegister(const char *operator_type, const InferFormatFunc &infer_format_func) { + std::string op_type; + if (operator_type != nullptr) { + op_type = operator_type; + } + (void)OperatorFactoryImpl::RegisterInferFormatFunc(op_type, infer_format_func); +} + VerifyFuncRegister::VerifyFuncRegister(const std::string &operator_type, const VerifyFunc &verify_func) { (void)OperatorFactoryImpl::RegisterVerifyFunc(operator_type, verify_func); } + +VerifyFuncRegister::VerifyFuncRegister(const char *operator_type, const VerifyFunc &verify_func) { + std::string op_type; + if (operator_type != nullptr) { + op_type = operator_type; + } + (void)OperatorFactoryImpl::RegisterVerifyFunc(op_type, verify_func); +} } // namespace ge diff --git a/src/common/graph/operator_factory_impl.cc b/src/common/graph/operator_factory_impl.cc index 8927f496..84242f2d 100644 --- a/src/common/graph/operator_factory_impl.cc +++ b/src/common/graph/operator_factory_impl.cc @@ -20,18 +20,27 @@ namespace ge { shared_ptr> OperatorFactoryImpl::operator_creators_; +shared_ptr> OperatorFactoryImpl::operator_creators_v2_; shared_ptr> OperatorFactoryImpl::operator_infershape_funcs_; shared_ptr> OperatorFactoryImpl::operator_inferformat_funcs_; shared_ptr> OperatorFactoryImpl::operator_verify_funcs_; shared_ptr> OperatorFactoryImpl::operator_infer_data_slice_funcs_; Operator OperatorFactoryImpl::CreateOperator(const std::string &operator_name, const std::string &operator_type) { + if (operator_creators_v2_ != nullptr) { + auto it_v2 = operator_creators_v2_->find(operator_type); + if (it_v2 != operator_creators_v2_->end()) { + return it_v2->second(operator_name.c_str()); + } else { + GELOGW("No OpProto of [%s] registered by AscendString.", operator_type.c_str()); + } + } if (operator_creators_ == nullptr) { return Operator(); } auto it = operator_creators_->find(operator_type); if (it == operator_creators_->end()) { - GELOGW("no OpProto of [%s] registered", operator_type.c_str()); + GELOGW("no OpProto of [%s] registered by string.", operator_type.c_str()); return Operator(); } return it->second(operator_name); @@ -39,6 +48,15 @@ Operator OperatorFactoryImpl::CreateOperator(const std::string &operator_name, c graphStatus OperatorFactoryImpl::GetOpsTypeList(std::vector &all_ops) { all_ops.clear(); + if (operator_creators_v2_ != nullptr) { + for (auto it_v2 = operator_creators_v2_->begin(); it_v2 != operator_creators_v2_->end(); ++it_v2) { + all_ops.emplace_back(it_v2->first); + } + return GRAPH_SUCCESS; + } else { + GELOGW("Ops not registered by AscendString."); + } + if (operator_creators_ != nullptr) { for (auto it = operator_creators_->begin(); it != operator_creators_->end(); ++it) { all_ops.emplace_back(it->first); @@ -51,6 +69,13 @@ graphStatus OperatorFactoryImpl::GetOpsTypeList(std::vector &all_op } bool OperatorFactoryImpl::IsExistOp(const string &operator_type) { + if (operator_creators_v2_ != nullptr) { + auto it_v2 = operator_creators_v2_->find(operator_type); + if (it_v2 != operator_creators_v2_->end()) { + return true; + } + } + if (operator_creators_ == nullptr) { return false; } @@ -118,6 +143,18 @@ graphStatus OperatorFactoryImpl::RegisterOperatorCreator(const string &operator_ return GRAPH_SUCCESS; } +graphStatus OperatorFactoryImpl::RegisterOperatorCreator(const string &operator_type, OpCreatorV2 const &op_creator) { + if (operator_creators_v2_ == nullptr) { + operator_creators_v2_.reset(new (std::nothrow) std::map()); + } + auto it = operator_creators_v2_->find(operator_type); + if (it != operator_creators_v2_->end()) { + return GRAPH_FAILED; + } + (void)operator_creators_v2_->emplace(operator_type, op_creator); + return GRAPH_SUCCESS; +} + graphStatus OperatorFactoryImpl::RegisterInferShapeFunc(const std::string &operator_type, InferShapeFunc const infer_shape_func) { if (operator_infershape_funcs_ == nullptr) { diff --git a/src/common/graph/opsproto/opsproto_manager.cc b/src/common/graph/opsproto/opsproto_manager.cc index 397e02cd..39239899 100644 --- a/src/common/graph/opsproto/opsproto_manager.cc +++ b/src/common/graph/opsproto/opsproto_manager.cc @@ -23,6 +23,7 @@ #include "debug/ge_util.h" #include "framework/common/debug/ge_log.h" #include "graph/debug/ge_log.h" +#include "mmpa/mmpa_api.h" namespace ge { OpsProtoManager *OpsProtoManager::Instance() { @@ -62,8 +63,10 @@ void OpsProtoManager::Finalize() { for (auto handle : handles_) { if (handle != nullptr) { - if (dlclose(handle) != 0) { - GELOGW("failed to close handle, message: %s", dlerror()); + if (mmDlclose(handle) != 0) { + const char *error = mmDlerror(); + error = (error == nullptr) ? "" : error; + GELOGW("failed to close handle, message: %s", error); continue; } GELOGI("close opsprotomanager handler success"); @@ -103,42 +106,48 @@ static void FindParserSo(const std::string &path, std::vector &file GELOGI("realPath is empty"); return; } - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path.size() >= PATH_MAX, return, "path is invalid"); + GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path.size() >= MMPA_MAX_PATH, return, "path is invalid"); - char resolved_path[PATH_MAX] = {0}; + char resolved_path[MMPA_MAX_PATH] = {0}; // Nullptr is returned when the path does not exist or there is no permission // Return absolute path when path is accessible - if (realpath(path.c_str(), resolved_path) == nullptr) { + INT32 result = mmRealPath(path.c_str(), resolved_path, MMPA_MAX_PATH); + if (result != EN_OK) { GELOGW("the path [%s] not exsit.", path.c_str()); return; } - struct dirent *dent = nullptr; - DIR *dir = opendir(resolved_path); + INT32 is_dir = mmIsDir(resolved_path); // Lib plugin path not exist - if (dir == nullptr) { + if (is_dir != EN_OK) { GELOGW("Open directory %s failed,maybe it is not exit or not a dir", resolved_path); return; } - while ((dent = readdir(dir)) != nullptr) { - if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) { + mmDirent **entries = nullptr; + auto ret = mmScandir(resolved_path, &entries, nullptr, nullptr); + if (ret < EN_OK) { + GELOGW("scan dir failed. path = %s, ret = %d", resolved_path, ret); + return; + } + for (int i = 0; i < ret; ++i) { + mmDirent *dir_ent = entries[i]; + std::string name = std::string(dir_ent->d_name); + if (strcmp(name.c_str(), ".") == 0 || strcmp(name.c_str(), "..") == 0) { continue; } - std::string name = dent->d_name; std::string full_name = path + "/" + name; const std::string so_suff = ".so"; - if (dent->d_type != DT_DIR && name.size() >= so_suff.size() && + if (dir_ent->d_type != DT_DIR && name.size() >= so_suff.size() && name.compare(name.size() - so_suff.size(), so_suff.size(), so_suff) == 0) { file_list.push_back(full_name); GELOGI("OpsProtoManager Parse full name = %s \n", full_name.c_str()); } } - if (closedir(dir) != 0) { - GELOGW("close dir fail."); - } + mmScandirFree(entries, ret); + GELOGI("Found %d libs.", ret); } static void GetPluginSoFileList(const std::string &path, std::vector &file_list) { @@ -171,9 +180,11 @@ void OpsProtoManager::LoadOpsProtoPluginSo(std::string &path) { // Load .so file for (auto elem : file_list) { - void *handle = dlopen(elem.c_str(), RTLD_NOW | RTLD_GLOBAL); + void *handle = mmDlopen(elem.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); if (handle == nullptr) { - GELOGW("OpsProtoManager dlopen failed, plugin name:%s. Message(%s).", elem.c_str(), dlerror()); + const char *error = mmDlerror(); + error = (error == nullptr) ? "" : error; + GELOGW("OpsProtoManager dlopen failed, plugin name:%s. Message(%s).", elem.c_str(), error); continue; } else { // Close dl when the program exist, not close here diff --git a/src/common/graph/shape_refiner.cc b/src/common/graph/shape_refiner.cc index 30cf8383..047d0a30 100644 --- a/src/common/graph/shape_refiner.cc +++ b/src/common/graph/shape_refiner.cc @@ -31,6 +31,7 @@ #include "external/graph/operator_factory.h" #include "framework/common/debug/ge_log.h" #include "graph/compute_graph.h" +#include "graph/operator_factory_impl.h" #include "utils/node_utils.h" #include "utils/op_desc_utils.h" #include "utils/tensor_utils.h" @@ -76,7 +77,6 @@ graphStatus UpdataOutputForMultiBatcch(const ConstNodePtr &node, int64_t max_size = 0; size_t max_shape_index = 0; auto &ref_out_tensor = ref_out_tensors[i].at(0); - const auto &ref_out_tensor_shape = ref_out_tensor.MutableShape(); for (size_t j = 0; j < ref_out_tensors[i].size(); ++j) { auto &tensor = ref_out_tensors[i].at(j); if (ref_out_tensor.GetDataType() != tensor.GetDataType()) { @@ -85,12 +85,6 @@ graphStatus UpdataOutputForMultiBatcch(const ConstNodePtr &node, } auto shape = tensor.MutableShape(); - if (shape.GetDims().size() != ref_out_tensor_shape.GetDims().size()) { - GELOGE(GRAPH_FAILED, "node is %s, i : %d, shape size: %lu, ref_out_tensor_shape size: %lu", - node->GetName().c_str(), i, shape.GetShapeSize(), ref_out_tensor_shape.GetShapeSize()); - return GRAPH_FAILED; - } - int64_t size = 1; for (auto dim : shape.GetDims()) { if (INT64_MAX / dim < size) { @@ -510,63 +504,6 @@ void ShapeRefiner::PrintInOutTensorShape(const ge::NodePtr &node, const std::str GELOGD("Shape dump [%s], Node name: [%s]. %s", phase.c_str(), node->GetName().c_str(), str.c_str()); } -graphStatus ShapeRefiner::InferShapeAndType(const ConstNodePtr &node, Operator &op) { - return InferShapeAndType(node, op, true); -} -graphStatus ShapeRefiner::InferShapeAndType(const ConstNodePtr &node, Operator &op, bool before_subgraph) { - auto op_desc = node->GetOpDesc(); - const auto &op_type = op_desc->GetType(); - - graphStatus ret; - if (before_subgraph) { - ret = UpdateSubGraphDataNodes(node); - if (ret != GRAPH_SUCCESS) { - return ret; - } - } - // Get infer func and execute - ret = op_desc->CallInferFunc(op); - if (ret == GRAPH_PARAM_INVALID) { - // Op ir no infer func, try to get infer func from operator factory - auto node_op = ge::OperatorFactory::CreateOperator("node_op", op_desc->GetType()); - if (node_op.IsEmpty()) { - GELOGW("get op from OperatorFactory fail. opType: %s", op_type.c_str()); - return ret; - } - - GELOGD("get op from OperatorFactory success. opType: %s", op_type.c_str()); - auto temp_op_desc = ge::OpDescUtils::GetOpDescFromOperator(node_op); - node_op.BreakConnect(); - if (temp_op_desc == nullptr) { - GELOGE(GRAPH_FAILED, "temp op desc is null"); - return GRAPH_FAILED; - } - if (!op_desc->UpdateInputName(temp_op_desc->GetAllInputName())) { - GELOGW("InferShapeAndType UpdateInputName failed"); - for (const auto &out_desc : op_desc->GetAllOutputsDescPtr()) { - if (out_desc != nullptr && out_desc->GetShape().GetDims().empty()) { - break; - } - return GRAPH_SUCCESS; - } - } - if (!op_desc->UpdateOutputName(temp_op_desc->GetAllOutputName())) { - GELOGW("InferShapeAndType UpdateOutputName failed"); - } - op_desc->AddInferFunc(temp_op_desc->GetInferFunc()); - ret = op_desc->CallInferFunc(op); - GELOGI("op CallInferFunc second. ret: %u", ret); - } - if (ret != GRAPH_SUCCESS) { - return ret; - } - - if (!before_subgraph) { - return UpdateParentNodeOutTensor(node); - } - return GRAPH_SUCCESS; -} - InferenceContextPtr CreateInferenceContext(const std::unordered_map &context_map, const NodePtr &node) { if (node == nullptr) { @@ -633,9 +570,122 @@ thread_local std::unordered_map context_map; GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void ShapeRefiner::ClearContextMap() { context_map.clear(); } +graphStatus ShapeRefiner::InferShapeAndType(const ConstNodePtr &node, Operator &op) { + return InferShapeAndType(node, op, true); +} + +graphStatus ShapeRefiner::InferShapeAndType(const ConstNodePtr &node, Operator &op, bool before_subgraph) { + auto op_desc = node->GetOpDesc(); + const auto &op_type = op_desc->GetType(); + + graphStatus ret; + if (before_subgraph) { + ret = UpdateSubGraphDataNodes(node); + if (ret != GRAPH_SUCCESS) { + return ret; + } + } + // Get infer func and execute + ret = op_desc->CallInferFunc(op); + if (ret == GRAPH_PARAM_INVALID) { + // Op ir no infer func, try to get infer func from operator factory + auto node_op = ge::OperatorFactory::CreateOperator("node_op", op_desc->GetType()); + if (node_op.IsEmpty()) { + GELOGW("get op from OperatorFactory fail. opType: %s", op_type.c_str()); + return ret; + } + + GELOGD("get op from OperatorFactory success. opType: %s", op_type.c_str()); + auto temp_op_desc = ge::OpDescUtils::GetOpDescFromOperator(node_op); + node_op.BreakConnect(); + if (temp_op_desc == nullptr) { + GELOGE(GRAPH_FAILED, "temp op desc is null"); + return GRAPH_FAILED; + } + if (!op_desc->UpdateInputName(temp_op_desc->GetAllInputName())) { + GELOGW("InferShapeAndType UpdateInputName failed"); + for (const auto &out_desc : op_desc->GetAllOutputsDescPtr()) { + if (out_desc != nullptr && out_desc->GetShape().GetDims().empty()) { + break; + } + return GRAPH_SUCCESS; + } + } + if (!op_desc->UpdateOutputName(temp_op_desc->GetAllOutputName())) { + GELOGW("InferShapeAndType UpdateOutputName failed"); + } + op_desc->AddInferFunc(temp_op_desc->GetInferFunc()); + ret = op_desc->CallInferFunc(op); + GELOGI("op CallInferFunc second. ret: %u", ret); + } + if (ret != GRAPH_SUCCESS) { + return ret; + } + + if (!before_subgraph) { + return UpdateParentNodeOutTensor(node); + } + return GRAPH_SUCCESS; +} + +graphStatus ShapeRefiner::InferShapeAndTypeForRunning(const ConstNodePtr &node, Operator &op, bool before_subgraph) { + auto op_desc = node->GetOpDesc(); + const auto &op_type = op_desc->GetType(); + + graphStatus ret; + if (before_subgraph) { + ret = UpdateSubGraphDataNodes(node); + if (ret != GRAPH_SUCCESS) { + return ret; + } + } + // Get infer func and execute + ret = op_desc->CallInferFunc(op); + if (ret == GRAPH_PARAM_INVALID) { + GELOGD("NodeUtils::GetNodeType return value is: [%s]", NodeUtils::GetNodeType(*node).c_str()); + auto origin_type = NodeUtils::GetNodeType(*node); + auto infer_func = ge::OperatorFactoryImpl::GetInferShapeFunc(origin_type); + if (infer_func == nullptr) { + GELOGE(GRAPH_FAILED, "Failed to Get InferFunc.type is %s", origin_type.c_str()); + return GRAPH_FAILED; + } + op_desc->AddInferFunc(infer_func); + ret = op_desc->CallInferFunc(op); + GELOGI("op CallInferFunc second. ret: %u", ret); + } + if (ret != GRAPH_SUCCESS) { + return ret; + } + + if (!before_subgraph) { + return UpdateParentNodeOutTensor(node); + } + return GRAPH_SUCCESS; +} + GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus ShapeRefiner::InferShapeAndType(const NodePtr &node) { return InferShapeAndType(node, true); } + +GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus +ShapeRefiner::InferShapeAndTypeForRunning(const NodePtr &node, bool before_subgraph) { + GE_IF_BOOL_EXEC(node == nullptr, GELOGE(GRAPH_FAILED, "node is null."); return GRAPH_FAILED); + auto opdesc = node->GetOpDesc(); + GE_IF_BOOL_EXEC(opdesc == nullptr, GELOGE(GRAPH_FAILED, "op_desc is null."); return GRAPH_FAILED); + + PrintInOutTensorShape(node, "before_infershape when running"); + Operator op = OpDescUtils::CreateOperatorFromNode(node); + + graphStatus status = InferShapeAndTypeForRunning(node, op, before_subgraph); + if (status == GRAPH_PARAM_INVALID || status == GRAPH_SUCCESS) { + PrintInOutTensorShape(node, "after_infershape when running"); + return GRAPH_SUCCESS; + } else { + GELOGE(GRAPH_FAILED, "%s call infer function failed.", node->GetName().c_str()); + return GRAPH_FAILED; + } +} + GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus ShapeRefiner::InferShapeAndType(const NodePtr &node, bool before_subgraph) { GE_IF_BOOL_EXEC(node == nullptr, GELOGE(GRAPH_FAILED, "node is null."); return GRAPH_FAILED); diff --git a/src/common/graph/tensor.cc b/src/common/graph/tensor.cc index 0d511645..753dfbe0 100644 --- a/src/common/graph/tensor.cc +++ b/src/common/graph/tensor.cc @@ -89,6 +89,65 @@ class TensorImpl { TensorImpl(TensorDesc &&tensor_desc, std::vector &&data) : ge_tensor(TensorAdapter::TensorDesc2GeTensorDesc(tensor_desc), std::move(data)) {} + graphStatus SetData(const std::string &data) { + if (!data.empty()) { + /// Extra 8 bytes store pointer of string + /// Extra 1 byte store '\0' + size_t total_size = data.size() + EXTRA_STORE_POINTER_FOR_STRING_AND_END_SYMBOL; + std::unique_ptr buff(new (std::nothrow) char[total_size]()); + if (buff == nullptr) { + GELOGE(GRAPH_FAILED, "allocate string raw data buff failed"); + return GRAPH_FAILED; + } + uint64_t *p = reinterpret_cast(buff.get()); + // Front 8 bytes store pointer of string + char *raw_data = buff.get() + EXTRA_STORE_POINTER_FOR_STRING; + p[0] = reinterpret_cast(raw_data); + int32_t memcpy_ret = + memcpy_s(raw_data, total_size - EXTRA_STORE_POINTER_FOR_STRING, data.c_str(), data.size() + 1); + GE_CHK_BOOL_RET_STATUS(memcpy_ret == EOK, GRAPH_FAILED, "copy data failed"); + (void)ge_tensor.SetData(reinterpret_cast(buff.get()), total_size); + return GRAPH_SUCCESS; + } + return GRAPH_FAILED; + } + + graphStatus SetData(const std::vector &data) { + if (data.empty()) { + GELOGE(GRAPH_FAILED, "there is no data, please check the input variable"); + return GRAPH_FAILED; + } + size_t total_size = 0; + for (auto str : data) { + /// Extra 8 bytes store pointer of each string + /// Extra 1 byte store '\0' + total_size += (str.size() + EXTRA_STORE_POINTER_FOR_STRING_AND_END_SYMBOL); + } + std::unique_ptr buff(new (std::nothrow) char[total_size]); + if (buff == nullptr) { + GELOGE(GRAPH_FAILED, "allocate string raw data buff failed"); + return GRAPH_FAILED; + } + uint64_t *p = reinterpret_cast(buff.get()); + // Front some bytes store pointer of each string + char *raw_data = buff.get() + data.size() * sizeof(uint64_t); + uint64_t ptr_size = data.size() * sizeof(uint64_t); + for (size_t i = 0; i < data.size(); ++i) { + p[i] = reinterpret_cast(raw_data); + if (total_size < ptr_size) { + GELOGE(GRAPH_FAILED, "Subtraction invalid, total_size: %zu, ptr_size: %lu", total_size, ptr_size); + return GRAPH_FAILED; + } + int32_t memcpy_ret = memcpy_s(raw_data, total_size - ptr_size, data[i].c_str(), data[i].size() + 1); + GE_CHK_BOOL_RET_STATUS(memcpy_ret == EOK, GRAPH_FAILED, "copy data failed"); + raw_data += (data[i].size() + 1); + ptr_size += (data[i].size() + 1); + } + + (void)ge_tensor.SetData(reinterpret_cast(buff.get()), total_size); + return GRAPH_SUCCESS; + } + GeTensor ge_tensor; }; @@ -356,6 +415,20 @@ void TensorDesc::SetName(const std::string &name) { } } +graphStatus TensorDesc::GetName(AscendString &name) { + if (impl != nullptr) { + name = AscendString(impl->name_.c_str()); + return GRAPH_SUCCESS; + } + return GRAPH_FAILED; +} + +void TensorDesc::SetName(const char *name) { + if (impl != nullptr && name != nullptr) { + impl->name_ = name; + } +} + Tensor::Tensor() { impl = ComGraphMakeShared(); } Tensor::Tensor(const TensorDesc &tensor_desc) { impl = ComGraphMakeShared(tensor_desc); } @@ -489,60 +562,53 @@ graphStatus Tensor::SetData(const uint8_t *data, size_t size) { } graphStatus Tensor::SetData(const std::string &data) { - if (impl != nullptr && (!data.empty())) { - /// Extra 8 bytes store pointer of string - /// Extra 1 byte store '\0' - size_t total_size = data.size() + EXTRA_STORE_POINTER_FOR_STRING_AND_END_SYMBOL; - std::unique_ptr buff(new (std::nothrow) char[total_size]()); - if (buff == nullptr) { - GELOGE(GRAPH_FAILED, "allocate string raw data buff failed"); + if (impl != nullptr) { + if (impl->SetData(data) != GRAPH_SUCCESS) { + GELOGE(GRAPH_FAILED, "Tensor set data failed."); return GRAPH_FAILED; } - uint64_t *p = reinterpret_cast(buff.get()); - // Front 8 bytes store pointer of string - char *raw_data = buff.get() + EXTRA_STORE_POINTER_FOR_STRING; - p[0] = reinterpret_cast(raw_data); - int32_t memcpy_ret = memcpy_s(raw_data, total_size - EXTRA_STORE_POINTER_FOR_STRING, data.c_str(), data.size() + 1); - GE_CHK_BOOL_RET_STATUS(memcpy_ret == EOK, GRAPH_FAILED, "copy data failed"); - (void)impl->ge_tensor.SetData(reinterpret_cast(buff.get()), total_size); return GRAPH_SUCCESS; } return GRAPH_FAILED; } + graphStatus Tensor::SetData(const std::vector &data) { if (impl != nullptr) { - if (data.empty()) { - GELOGE(GRAPH_FAILED, "there is no data, please check the input variable"); + if (impl->SetData(data) != GRAPH_SUCCESS) { + GELOGE(GRAPH_FAILED, "Tensor set vector data failed."); return GRAPH_FAILED; } - size_t total_size = 0; - for (auto str : data) { - /// Extra 8 bytes store pointer of each string - /// Extra 1 byte store '\0' - total_size += (str.size() + EXTRA_STORE_POINTER_FOR_STRING_AND_END_SYMBOL); - } - std::unique_ptr buff(new (std::nothrow) char[total_size]); - if (buff == nullptr) { - GELOGE(GRAPH_FAILED, "allocate string raw data buff failed"); + return GRAPH_SUCCESS; + } + return GRAPH_FAILED; +} + +graphStatus Tensor::SetData(const char *data) { + if (impl != nullptr && data != nullptr) { + std::string tensor_data = data; + if (impl->SetData(tensor_data) != GRAPH_SUCCESS) { + GELOGE(GRAPH_FAILED, "Tensor set data failed."); return GRAPH_FAILED; } - uint64_t *p = reinterpret_cast(buff.get()); - // Front some bytes store pointer of each string - char *raw_data = buff.get() + data.size() * sizeof(uint64_t); - uint64_t ptr_size = data.size() * sizeof(uint64_t); - for (size_t i = 0; i < data.size(); ++i) { - p[i] = reinterpret_cast(raw_data); - if (total_size < ptr_size) { - GELOGE(GRAPH_FAILED, "Subtraction invalid, total_size: %zu, ptr_size: %lu", total_size, ptr_size); + return GRAPH_SUCCESS; + } + return GRAPH_FAILED; +} + +graphStatus Tensor::SetData(const std::vector &datas) { + if (impl != nullptr) { + std::vector tensor_data; + for (auto &data : datas) { + if (data.GetString() == nullptr) { + GELOGE(GRAPH_FAILED, "Data is nullptr."); return GRAPH_FAILED; } - int32_t memcpy_ret = memcpy_s(raw_data, total_size - ptr_size, data[i].c_str(), data[i].size() + 1); - GE_CHK_BOOL_RET_STATUS(memcpy_ret == EOK, GRAPH_FAILED, "copy data failed"); - raw_data += (data[i].size() + 1); - ptr_size += (data[i].size() + 1); + tensor_data.emplace_back(data.GetString()); + } + if (impl->SetData(tensor_data) != GRAPH_SUCCESS) { + GELOGE(GRAPH_FAILED, "Tensor set vector data failed."); + return GRAPH_FAILED; } - - (void)impl->ge_tensor.SetData(reinterpret_cast(buff.get()), total_size); return GRAPH_SUCCESS; } return GRAPH_FAILED; diff --git a/src/common/graph/transformer/inc/axis_util.h b/src/common/graph/transformer/inc/axis_util.h index c18c199a..d9359365 100644 --- a/src/common/graph/transformer/inc/axis_util.h +++ b/src/common/graph/transformer/inc/axis_util.h @@ -63,6 +63,30 @@ const int32_t AXIS_C1HWNCoC0_DIM_N = 3; const int32_t AXIS_C1HWNCoC0_DIM_Co = 4; const int32_t AXIS_C1HWNCoC0_DIM_C0 = 5; +const int32_t NDHWC_DIM_N = 0; +const int32_t NDHWC_DIM_D = 1; +const int32_t NDHWC_DIM_H = 2; +const int32_t NDHWC_DIM_W = 3; +const int32_t NDHWC_DIM_C = 4; + +const int32_t NCDHW_DIM_N = 0; +const int32_t NCDHW_DIM_C = 1; +const int32_t NCDHW_DIM_D = 2; +const int32_t NCDHW_DIM_H = 3; +const int32_t NCDHW_DIM_W = 4; + +const int32_t DHWCN_DIM_D = 0; +const int32_t DHWCN_DIM_H = 1; +const int32_t DHWCN_DIM_W = 2; +const int32_t DHWCN_DIM_C = 3; +const int32_t DHWCN_DIM_N = 4; + +const int32_t DHWNC_DIM_D = 0; +const int32_t DHWNC_DIM_H = 1; +const int32_t DHWNC_DIM_W = 2; +const int32_t DHWNC_DIM_N = 3; +const int32_t DHWNC_DIM_C = 4; + #define CHECK_NOTNULL(val) \ do { \ if ((val) == nullptr) { \ @@ -134,6 +158,17 @@ class AxisUtil { static bool GetAxisValueByC1HWNCoC0(const std::vector& originalDimVec, const uint32_t& c0, std::vector& axisValue, std::vector& ndValue); + static bool GetAxisValueByNDHWC(const std::vector& original_dim_vec, const uint32_t& c0, + std::vector& axis_value, std::vector& nd_value); + + static bool GetAxisValueByNCDHW(const std::vector& original_dim_vec, const uint32_t& c0, + std::vector& axis_value, std::vector& nd_value); + + static bool GetAxisValueByDHWCN(const std::vector& original_dim_vec, const uint32_t& c0, + std::vector& axis_value, std::vector& nd_value); + + static bool GetAxisValueByDHWNC(const std::vector& original_dim_vec, const uint32_t& c0, + std::vector& axis_value, std::vector& nd_value); /* map of GetAxisValueInfoByFormat, get axis value by different original * formats. */ std::map getAxisValueFuncMap; diff --git a/src/common/graph/transformer/inc/transfer_shape_according_to_format.h b/src/common/graph/transformer/inc/transfer_shape_according_to_format.h index 7fd81476..ad1c0a95 100644 --- a/src/common/graph/transformer/inc/transfer_shape_according_to_format.h +++ b/src/common/graph/transformer/inc/transfer_shape_according_to_format.h @@ -89,6 +89,9 @@ class ShapeTransferAccordingToFormat { bool GetShapeAccordingToFormat(ShapeAndFormat &inputAndOutputInfo, int64_t *c = nullptr); /* ----------Below is the function of getting new shape---------------------- */ + static bool GetNDC1HWC0ShapeByAxisValue(vector &new_shape, const int64_t &impl_type, + const std::vector &axis_value, const vector &nd_value); + static bool GetNCHWShapeByAxisValue(vector &newShape, const int64_t &implType, const vector &axisValue, const vector &ndValue); diff --git a/src/common/graph/transformer/src/axis_util.cc b/src/common/graph/transformer/src/axis_util.cc index 6f9a4d42..0eaef219 100644 --- a/src/common/graph/transformer/src/axis_util.cc +++ b/src/common/graph/transformer/src/axis_util.cc @@ -32,7 +32,11 @@ AxisUtil::AxisUtil() { {FORMAT_NC1HWC0, std::make_shared(GetAxisValueByNC1HWC0)}, {FORMAT_HWCN, std::make_shared(GetAxisValueByHWCN)}, {FORMAT_ND, std::make_shared(GetAxisValueByND)}, - {FORMAT_C1HWNCoC0, std::make_shared(GetAxisValueByC1HWNCoC0)}}; + {FORMAT_C1HWNCoC0, std::make_shared(GetAxisValueByC1HWNCoC0)}, + {FORMAT_NDHWC, std::make_shared(GetAxisValueByNDHWC)}, + {FORMAT_NCDHW, std::make_shared(GetAxisValueByNCDHW)}, + {FORMAT_DHWCN, std::make_shared(GetAxisValueByDHWCN)}, + {FORMAT_DHWNC, std::make_shared(GetAxisValueByDHWNC)}}; } int64_t DivisionCeiling(int64_t dividend, int64_t divisor) { @@ -105,8 +109,9 @@ bool AxisUtil::GetAxisValueByNCHW(const vector &originalDimVec, const u CHECK(originalDimVec.empty(), GELOGI("Original dim vector is empty!"), return true); /* C0 Must be set for case ND or 2D-NCHW to NZ */ axisValue[AXIS_C0] = c0; - CHECK(CheckParams(originalDimVec, c0, axisValue, ndValue) != true, - GELOGE(GRAPH_FAILED, "[ERROR]Parameter is invalid!"), return false); + // TODO: temporarily modified to warning level.If modified normally, it needs complementary dimension for origin shape + CHECK(CheckParams(originalDimVec, c0, axisValue, ndValue) != true, GELOGW("[WARNING]Parameter is invalid!"), + return false); axisValue[AXIS_N] = originalDimVec[AXIS_NCHW_DIM_N]; axisValue[AXIS_C] = originalDimVec[AXIS_NCHW_DIM_C]; @@ -123,8 +128,9 @@ bool AxisUtil::GetAxisValueByNHWC(const vector &originalDimVec, const u CHECK(originalDimVec.empty(), GELOGI("Original dim vector is empty!"), return true); /* C0 Must be set for case ND or 2D-NHWC to NZ */ axisValue[AXIS_C0] = c0; - CHECK(CheckParams(originalDimVec, c0, axisValue, ndValue) != true, - GELOGE(GRAPH_FAILED, "[ERROR]Parameter is invalid!"), return false); + // TODO: temporarily modified to warning level.If modified normally, it needs complementary dimension for origin shape + CHECK(CheckParams(originalDimVec, c0, axisValue, ndValue) != true, GELOGW("[WARNING]Parameter is invalid!"), + return false); axisValue[AXIS_N] = originalDimVec[AXIS_NHWC_DIM_N]; axisValue[AXIS_C] = originalDimVec[AXIS_NHWC_DIM_C]; @@ -165,8 +171,10 @@ bool AxisUtil::GetAxisValueByHWCN(const vector &originalDimVec, const u CHECK(originalDimVec.empty(), GELOGI("Original dim vector is empty!"), return true); /* C0 Must be set for case ND or 2D-NHWC to NZ */ axisValue[AXIS_C0] = c0; - CHECK(CheckParams(originalDimVec, c0, axisValue, ndValue) != true, - GELOGE(GRAPH_FAILED, "[ERROR]Parameter is invalid!"), return false); + // TODO: temporarily modified to warning level. If modified normally, it needs complementary dimension for origin + // shape + CHECK(CheckParams(originalDimVec, c0, axisValue, ndValue) != true, GELOGW("[WARNING]Parameter is invalid!"), + return false); axisValue[AXIS_N] = originalDimVec[AXIS_HWCN_DIM_N]; axisValue[AXIS_C] = originalDimVec[AXIS_HWCN_DIM_C]; @@ -194,5 +202,89 @@ bool AxisUtil::GetAxisValueByC1HWNCoC0(const vector &originalDimVec, co axisValue[AXIS_Co] = originalDimVec[AXIS_C1HWNCoC0_DIM_Co]; return true; } + +bool AxisUtil::GetAxisValueByNDHWC(const std::vector &original_dim_vec, const uint32_t &c0, + std::vector &axis_value, std::vector &nd_value) { + CHECK(axis_value.empty(), GELOGI("AxisValue is empty!"), return true); + CHECK(original_dim_vec.empty(), GELOGI("Original dim vector is empty!"), return true); + + axis_value[AXIS_C0] = c0; + nd_value = original_dim_vec; + + axis_value[AXIS_N] = original_dim_vec[NDHWC_DIM_N]; + int64_t axis_c_val = original_dim_vec[NDHWC_DIM_C]; + + axis_value[AXIS_C] = axis_c_val; + axis_value[AXIS_H] = original_dim_vec[NDHWC_DIM_H]; + axis_value[AXIS_W] = original_dim_vec[NDHWC_DIM_W]; + axis_value[AXIS_C1] = DivisionCeiling(axis_c_val, c0); + axis_value[AXIS_C0] = c0; + axis_value[AXIS_Co] = c0; + axis_value[AXIS_D] = original_dim_vec[NDHWC_DIM_D]; + return true; +} + +bool AxisUtil::GetAxisValueByNCDHW(const std::vector &original_dim_vec, const uint32_t &c0, + std::vector &axis_value, std::vector &nd_value) { + CHECK(axis_value.empty(), GELOGI("AxisValue is empty!"), return true); + CHECK(original_dim_vec.empty(), GELOGI("Original dim vector is empty!"), return true); + + axis_value[AXIS_C0] = c0; + nd_value = original_dim_vec; + + axis_value[AXIS_N] = original_dim_vec[NCDHW_DIM_N]; + int64_t axis_c_val = original_dim_vec[NCDHW_DIM_C]; + + axis_value[AXIS_C] = axis_c_val; + axis_value[AXIS_H] = original_dim_vec[NCDHW_DIM_H]; + axis_value[AXIS_W] = original_dim_vec[NCDHW_DIM_W]; + axis_value[AXIS_C1] = DivisionCeiling(axis_c_val, c0); + axis_value[AXIS_C0] = c0; + axis_value[AXIS_Co] = c0; + axis_value[AXIS_D] = original_dim_vec[NCDHW_DIM_D]; + return true; +} + +bool AxisUtil::GetAxisValueByDHWCN(const std::vector &original_dim_vec, const uint32_t &c0, + std::vector &axis_value, std::vector &nd_value) { + CHECK(axis_value.empty(), GELOGI("AxisValue is empty!"), return true); + CHECK(original_dim_vec.empty(), GELOGI("Original dim vector is empty!"), return true); + + axis_value[AXIS_C0] = c0; + nd_value = original_dim_vec; + + axis_value[AXIS_N] = original_dim_vec[DHWCN_DIM_N]; + int64_t axis_c_val = original_dim_vec[DHWCN_DIM_C]; + + axis_value[AXIS_C] = axis_c_val; + axis_value[AXIS_H] = original_dim_vec[DHWCN_DIM_H]; + axis_value[AXIS_W] = original_dim_vec[DHWCN_DIM_W]; + axis_value[AXIS_C1] = DivisionCeiling(axis_c_val, c0); + axis_value[AXIS_C0] = c0; + axis_value[AXIS_Co] = c0; + axis_value[AXIS_D] = original_dim_vec[DHWCN_DIM_D]; + return true; +} + +bool AxisUtil::GetAxisValueByDHWNC(const std::vector &original_dim_vec, const uint32_t &c0, + std::vector &axis_value, std::vector &nd_value) { + CHECK(axis_value.empty(), GELOGI("AxisValue is empty!"), return true); + CHECK(original_dim_vec.empty(), GELOGI("Original dim vector is empty!"), return true); + + axis_value[AXIS_C0] = c0; + nd_value = original_dim_vec; + + axis_value[AXIS_N] = original_dim_vec[DHWNC_DIM_N]; + int64_t axis_c_val = original_dim_vec[DHWNC_DIM_C]; + + axis_value[AXIS_C] = axis_c_val; + axis_value[AXIS_H] = original_dim_vec[DHWNC_DIM_H]; + axis_value[AXIS_W] = original_dim_vec[DHWNC_DIM_W]; + axis_value[AXIS_C1] = DivisionCeiling(axis_c_val, c0); + axis_value[AXIS_C0] = c0; + axis_value[AXIS_Co] = c0; + axis_value[AXIS_D] = original_dim_vec[DHWNC_DIM_D]; + return true; +} } // namespace transformer } // namespace common diff --git a/src/common/graph/transformer/src/transfer_shape_according_to_format.cc b/src/common/graph/transformer/src/transfer_shape_according_to_format.cc index 470d4848..73193b09 100644 --- a/src/common/graph/transformer/src/transfer_shape_according_to_format.cc +++ b/src/common/graph/transformer/src/transfer_shape_according_to_format.cc @@ -30,6 +30,7 @@ ShapeTransferAccordingToFormat::ShapeTransferAccordingToFormat(void) { {ge::FORMAT_NCHW, std::make_shared(GetNCHWShapeByAxisValue)}, {ge::FORMAT_NHWC, std::make_shared(GetNHWCShapeByAxisValue)}, {ge::FORMAT_NC1HWC0, std::make_shared(GetNC1HWC0ShapeByAxisValue)}, + {ge::FORMAT_NDC1HWC0, std::make_shared(GetNDC1HWC0ShapeByAxisValue)}, {ge::FORMAT_FRACTAL_Z, std::make_shared(GetFzShapeByAxisValue)}, {ge::FORMAT_HWCN, std::make_shared(GetHWCNShapeByAxisValue)}, {ge::FORMAT_C1HWNCoC0, std::make_shared(GetC1HWNCoC0ShapeByAxisValue)}, @@ -42,6 +43,19 @@ ShapeTransferAccordingToFormat::ShapeTransferAccordingToFormat(void) { {ge::DT_UINT64, SHAPE_NUMBER_16}, {ge::DT_BOOL, SHAPE_NUMBER_16}}; } +bool ShapeTransferAccordingToFormat::GetNDC1HWC0ShapeByAxisValue(vector& new_shape, const int64_t& impl_type, + const std::vector& axis_value, + const vector& nd_value) { + CHECK(axis_value.empty(), GELOGD("AxisValue is empty!"), return true); + new_shape.push_back(axis_value[AXIS_N]); + new_shape.push_back(axis_value[AXIS_D]); + new_shape.push_back(axis_value[AXIS_C1]); + new_shape.push_back(axis_value[AXIS_H]); + new_shape.push_back(axis_value[AXIS_W]); + new_shape.push_back(axis_value[AXIS_C0]); + return true; +} + bool ShapeTransferAccordingToFormat::GetNCHWShapeByAxisValue(vector& newShape, const int64_t& implType, const vector& axisValue, const vector& ndValue) { diff --git a/src/common/graph/utils/ge_ir_utils.cc b/src/common/graph/utils/ge_ir_utils.cc index f238c6e8..4e66271f 100644 --- a/src/common/graph/utils/ge_ir_utils.cc +++ b/src/common/graph/utils/ge_ir_utils.cc @@ -17,6 +17,7 @@ #include "graph/utils/ge_ir_utils.h" #include #include "framework/common/debug/ge_log.h" +#include "mmpa/mmpa_api.h" namespace { const char *const kControlAnchorIndex = ":-1"; @@ -25,8 +26,10 @@ const char *const kPrefixForInputDesc = "input_desc_attr_"; const char *const kPrefixForOutputDesc = "output_desc_attr_"; const char *const kDumpGEGraph = "DUMP_GE_GRAPH"; const int8_t kMaxRecursionDepth = 10; -const char *const kDumpGeGraph = std::getenv(kDumpGEGraph); -const int64_t kDumpLevel = (kDumpGeGraph != nullptr) ? std::strtol(kDumpGeGraph, nullptr, 10) : ge::OnnxUtils::NO_DUMP; +char kDumpGeGraph[MMPA_MAX_PATH] = {0x00}; +const int64_t kDumpLevel = (mmGetEnv(kDumpGEGraph, kDumpGeGraph, MMPA_MAX_PATH) == EN_OK) + ? std::strtol(kDumpGeGraph, nullptr, 10) + : ge::OnnxUtils::NO_DUMP; const int64_t kInputPrefixLength = 5; const int64_t kOutputPrefixLength = 6; using AttrDefPair = ::google::protobuf::MapPair; @@ -43,6 +46,12 @@ static const std::map kGeDataTypeToOnn {DT_DOUBLE, onnx::TensorProto_DataType_DOUBLE}, {DT_BOOL, onnx::TensorProto_DataType_BOOL}, }; +struct AttrNameComp { + inline bool operator()(const onnx::AttributeProto &lsh, const onnx::AttributeProto &rsh) { + return lsh.name() < rsh.name(); + } +}; + onnx::TensorProto_DataType OnnxUtils::EncodeDataType(DataType data_type) { auto it = kGeDataTypeToOnnxMap.find(data_type); if (it != kGeDataTypeToOnnxMap.end()) { @@ -547,6 +556,9 @@ bool OnnxUtils::EncodeNodeDesc(const NodePtr &node, onnx::NodeProto *node_proto) } // 3.Encode ge::Node members to AttributeProto AddAttrProtoFromNodeMembers(node, node_proto); + + // 4. Sort node attributes by name. + std::sort(node_proto->mutable_attribute()->begin(), node_proto->mutable_attribute()->end(), AttrNameComp()); return true; } diff --git a/src/common/graph/utils/graph_utils.cc b/src/common/graph/utils/graph_utils.cc index 86c71f23..18d6ca67 100644 --- a/src/common/graph/utils/graph_utils.cc +++ b/src/common/graph/utils/graph_utils.cc @@ -20,10 +20,8 @@ #include #include -#include #include #include -#include #include #include #include @@ -43,6 +41,7 @@ #include "graph/debug/ge_attr_define.h" #include "graph/utils/op_desc_utils.h" #include "graph/utils/tensor_utils.h" +#include "mmpa/mmpa_api.h" using google::protobuf::io::FileOutputStream; @@ -68,6 +67,7 @@ const char *const kDumpStrPartition = "partition"; const char *const kDumpStrOptimizeSubgraph = "OptimizeSubGraph"; const char *const kDumpStrSubgraphFunc = "sub_graph"; const char *const kDumpStrAicpu = "Aicpu"; +const int32_t kNameMax = 255; }; // namespace GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus GraphUtils::AddEdge(const OutDataAnchorPtr &src, @@ -538,9 +538,9 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void GraphUtils::RecordOriginalNa } GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool GraphUtils::MatchDumpStr(const std::string &suffix) { - char *dump_level = std::getenv(kDumpGraphLevel); - int64_t dump_graph_level = - (dump_level != nullptr) ? std::strtol(dump_level, nullptr, kBaseOfIntegerValue) : kDumpLevel2; + char dump_level[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv(kDumpGraphLevel, dump_level, MMPA_MAX_PATH); + int64_t dump_graph_level = (res == EN_OK) ? std::strtol(dump_level, nullptr, kBaseOfIntegerValue) : kDumpLevel2; if (dump_graph_level == kDumpLevel1) { return false; @@ -565,8 +565,9 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void GraphUtils::DumpGEGraph(cons bool is_always_dump, const std::string &user_graph_name) { #ifdef FMK_SUPPORT_DUMP - char *dump_ge_graph = std::getenv(kDumpGeGraph); - GE_IF_BOOL_EXEC(dump_ge_graph == nullptr && !is_always_dump, return;); + char dump_ge_graph[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv(kDumpGeGraph, dump_ge_graph, MMPA_MAX_PATH); + GE_IF_BOOL_EXEC(res != EN_OK && !is_always_dump, return;); // dump the graph according to different graph level if (GraphUtils::MatchDumpStr(suffix)) { @@ -615,9 +616,9 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void GraphUtils::DumpGEGraph(cons GELOGE(GRAPH_FAILED, "parse from string failed."); return; } - char real_path[PATH_MAX] = {0x00}; - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(proto_file.c_str()) >= PATH_MAX, return, "file path is too longer!"); - GE_IF_BOOL_EXEC(realpath(proto_file.c_str(), real_path) == nullptr, + char real_path[MMPA_MAX_PATH] = {0x00}; + GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(proto_file.c_str()) >= MMPA_MAX_PATH, return, "file path is too longer!"); + GE_IF_BOOL_EXEC(mmRealPath(proto_file.c_str(), real_path, MMPA_MAX_PATH) != EN_OK, GELOGI("file %s does not exist, it will be created.", proto_file.c_str())); GraphUtils::WriteProtoToTextFile(ge_proto, real_path); @@ -730,7 +731,7 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void GraphUtils::WriteProtoToText const google::protobuf::Message &proto, const char *real_path) { #ifdef FMK_SUPPORT_DUMP const int FILE_AUTHORITY = 0600; - int fd = open(real_path, O_WRONLY | O_CREAT | O_TRUNC, FILE_AUTHORITY); + int fd = mmOpen2(real_path, M_WRONLY | M_CREAT | O_TRUNC, FILE_AUTHORITY); if (fd < 0) { GELOGE(GRAPH_FAILED, "fail to open the file: %s, %s", real_path, strerror(errno)); return; @@ -738,7 +739,7 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void GraphUtils::WriteProtoToText google::protobuf::io::FileOutputStream *output = new (std::nothrow) FileOutputStream(fd); if (output == nullptr) { GELOGE(GRAPH_FAILED, "Output is nullptr"); - if (close(fd) != 0) { + if (mmClose(fd) != 0) { GELOGE(GRAPH_FAILED, "Close fileoutputstream failed"); } return; @@ -748,12 +749,12 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void GraphUtils::WriteProtoToText GELOGE(GRAPH_FAILED, "Fail to write the file: %s", real_path); delete output; output = nullptr; - GE_CHK_BOOL_EXEC(close(fd) == 0, return, "Close fileoutputstream failed"); + GE_CHK_BOOL_EXEC(mmClose(fd) == 0, return, "Close fileoutputstream failed"); return; } delete output; output = nullptr; - GE_CHK_BOOL_EXEC(close(fd) == 0, return, "Close fileoutputstream failed"); + GE_CHK_BOOL_EXEC(mmClose(fd) == 0, return, "Close fileoutputstream failed"); FILE *file = fopen(real_path, "rb"); if (file == nullptr) { @@ -770,7 +771,7 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void GraphUtils::WriteProtoToText } if (max_dump_file_size != 0 && fileSize != -1 && fileSize > max_dump_file_size) { GELOGW("dump graph file size > maxDumpFileSize, maxDumpFileSize=%ld.", max_dump_file_size); - GE_IF_BOOL_EXEC(std::remove(real_path) != 0, GELOGW("remove %s failed", real_path)); + GE_IF_BOOL_EXEC(remove(real_path) != 0, GELOGW("remove %s failed", real_path)); GE_CHK_BOOL_EXEC(fclose(file) == 0, return, "Fclose %s failed", real_path); return; } @@ -804,9 +805,10 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool GraphUtils::ReadProtoFromTex GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void GraphUtils::DumpGEGraphToOnnx(const ge::ComputeGraph &compute_graph, const std::string &suffix) { #ifdef FMK_SUPPORT_DUMP - char *dump_ge_graph = std::getenv(kDumpGeGraph); + char dump_ge_graph[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv(kDumpGeGraph, dump_ge_graph, MMPA_MAX_PATH); int64_t dump_ge_graph_level = - (dump_ge_graph != nullptr) ? std::strtol(dump_ge_graph, nullptr, kBaseOfIntegerValue) : OnnxUtils::NO_DUMP; + (res == EN_OK) ? std::strtol(dump_ge_graph, nullptr, kBaseOfIntegerValue) : OnnxUtils::NO_DUMP; if ((dump_ge_graph_level == OnnxUtils::NO_DUMP) || (dump_ge_graph_level >= OnnxUtils::DUMP_LEVEL_END)) { GELOGD("Skip DumpGEGraphToOnnx with dump_ge_graph_level %ld.", dump_ge_graph_level); return; @@ -853,24 +855,26 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void GraphUtils::DumpGEGraphToOnn stream_file_name << "_graph_" << compute_graph.GetGraphID(); stream_file_name << "_" << suffix << ".pbtxt"; std::string proto_file = stream_file_name.str(); - if ((proto_file.length()) >= NAME_MAX) { + if ((proto_file.length()) >= kNameMax) { GELOGE(GRAPH_FAILED, "File name is too longer!"); return; } - std::unique_ptr real_path(new (std::nothrow) char[PATH_MAX]{0}); + std::unique_ptr real_path(new (std::nothrow) char[MMPA_MAX_PATH]{0}); if (real_path == nullptr) { GELOGE(GRAPH_FAILED, "New real_path failed."); return; } /// Returning nullptr means 3 case as follows: - /// a.path is PATH_MAX chars or more + /// a.path is MMPA_MAX_PATH chars or more /// b.the file does not exist /// c.the path has no permissions /// Distinguish between last the two cases in the function WriteProtoToTextFile call open() - if (realpath(proto_file.c_str(), real_path.get()) == nullptr) { + if (mmRealPath(proto_file.c_str(), real_path.get(), MMPA_MAX_PATH) != EN_OK) { // For case a - if (errno == ENAMETOOLONG) { - GELOGE(GRAPH_FAILED, "Call realpath failed: path is PATH_MAX chars or more."); + int err_num = errno; + // linux: ENAMETOOLONG windows: ERANGE + if (err_num == ENAMETOOLONG || err_num == ERANGE) { + GELOGE(GRAPH_FAILED, "Call realpath failed: path is MMPA_MAX_PATH chars or more."); return; } } diff --git a/src/common/graph/utils/op_desc_utils.cc b/src/common/graph/utils/op_desc_utils.cc index f9cfb901..f060b143 100644 --- a/src/common/graph/utils/op_desc_utils.cc +++ b/src/common/graph/utils/op_desc_utils.cc @@ -619,7 +619,7 @@ OpDescPtr OpDescUtils::CreateConstOp(const GeTensorPtr &tensor_ptr) { const_opdesc->SetType(CONSTANT); thread_local int64_t const_count = 0; - const_opdesc->SetName("dynamic_const_" + std::to_string(GetTid()) + "_" + std::to_string(const_count)); + const_opdesc->SetName("dynamic_const_" + std::to_string(GeLog::GetTid()) + "_" + std::to_string(const_count)); GELOGI("add const op: %s", const_opdesc->GetName().c_str()); ++const_count; diff --git a/src/common/graph/utils/string_utils.h b/src/common/graph/utils/string_utils.h index a9700469..e82afb1a 100644 --- a/src/common/graph/utils/string_utils.h +++ b/src/common/graph/utils/string_utils.h @@ -18,6 +18,7 @@ #define COMMON_GRAPH_UTILS_STRING_UTILS_H_ #include +#include #include #include #include diff --git a/src/common/graph/utils/tensor_utils.cc b/src/common/graph/utils/tensor_utils.cc index dba3e4c5..ec9ccf18 100644 --- a/src/common/graph/utils/tensor_utils.cc +++ b/src/common/graph/utils/tensor_utils.cc @@ -23,6 +23,7 @@ #include "graph/ge_tensor.h" #include "graph/types.h" #include "graph/utils/type_utils.h" +#include "mmpa/mmpa_api.h" namespace ge { namespace { @@ -181,8 +182,9 @@ static graphStatus CalcElementCntOfNc1hwc0(const std::vector &dims, Dat /// static graphStatus CalcElementCntOfFractalZ(const std::vector &dims, DataType data_type, int64_t &element_cnt) { - static char *parser_priority = std::getenv("PARSER_PRIORITY"); - if (parser_priority != nullptr && string(parser_priority) == "cce") { + static char parser_priority[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv("PARSER_PRIORITY", parser_priority, MMPA_MAX_PATH); + if (res == EN_OK && string(parser_priority) == "cce") { if (dims.size() != kDimSize4d) { GELOGE(GRAPH_FAILED, "CalcElementCntOfFractalZ failed as dims.size=%zu is not %u.", dims.size(), kDimSize4d); return GRAPH_FAILED; diff --git a/src/common/graph/utils/transformer_utils.cc b/src/common/graph/utils/transformer_utils.cc index f31ad69d..5daaec8c 100644 --- a/src/common/graph/utils/transformer_utils.cc +++ b/src/common/graph/utils/transformer_utils.cc @@ -22,10 +22,10 @@ namespace ge { bool NodeShapeTransUtils::CatchFormatAndShape() { - inputs_ = op_desc_->GetAllInputName(); - outputs_ = op_desc_->GetAllOutputName(); + auto inputs = op_desc_->MutableAllInputName(); + auto outputs = op_desc_->MutableAllOutputName(); - for (auto &ele : inputs_) { + for (auto &ele : inputs) { auto tensor_desc_input = op_desc_->MutableInputDesc(ele.first); if (tensor_desc_input == nullptr) { continue; @@ -45,7 +45,7 @@ bool NodeShapeTransUtils::CatchFormatAndShape() { tensor_desc_input->SetShape(tensor_desc_input->GetOriginShape()); } - for (auto &ele : outputs_) { + for (auto &ele : outputs) { auto tensor_desc_output = op_desc_->MutableOutputDesc(ele.first); if (tensor_desc_output == nullptr) { continue; @@ -72,7 +72,10 @@ bool NodeShapeTransUtils::CatchFormatAndShape() { } bool NodeShapeTransUtils::UpdateFormatAndShape() { - for (auto &ele : inputs_) { + auto inputs = op_desc_->MutableAllInputName(); + auto outputs = op_desc_->MutableAllOutputName(); + + for (auto &ele : inputs) { auto tensor_desc_input = op_desc_->MutableInputDesc(ele.first); if (tensor_desc_input == nullptr) { continue; @@ -107,7 +110,7 @@ bool NodeShapeTransUtils::UpdateFormatAndShape() { tensor_desc_input->SetShape(GeShape(out_dims)); } - for (auto &ele : outputs_) { + for (auto &ele : outputs) { auto tensor_desc_output = op_desc_->MutableOutputDesc(ele.first); if (tensor_desc_output == nullptr) { continue; diff --git a/src/common/graph/utils/transformer_utils.h b/src/common/graph/utils/transformer_utils.h index 6595eeed..24a13ef3 100644 --- a/src/common/graph/utils/transformer_utils.h +++ b/src/common/graph/utils/transformer_utils.h @@ -41,8 +41,6 @@ class NodeShapeTransUtils { std::map map_format_out_; std::map map_ori_format_out_; std::map map_dtype_out_; - std::map inputs_; - std::map outputs_; OpDescPtr op_desc_; }; diff --git a/src/common/graph/utils/tuning_utils.cc b/src/common/graph/utils/tuning_utils.cc index 26b03f56..09ed332e 100644 --- a/src/common/graph/utils/tuning_utils.cc +++ b/src/common/graph/utils/tuning_utils.cc @@ -34,8 +34,8 @@ const std::set kExeTypes = {DATA, NETOUTPUT}; NodeNametoNodeNameMap TuningUtils::data_2_netoutput_; NodetoNodeNameMap TuningUtils::data_node_2_netoutput_; NodetoNodeMap TuningUtils::data_node_2_netoutput_node_; -NodeSet TuningUtils::netoutput_nodes_; -NodeSet TuningUtils::merged_graph_nodes_; +NodeVec TuningUtils::netoutput_nodes_; +NodeVec TuningUtils::merged_graph_nodes_; SubgraphCreateOutNode TuningUtils::create_output_; std::mutex TuningUtils::mutex_; @@ -592,12 +592,12 @@ graphStatus TuningUtils::MergeSubGraph(ComputeGraphPtr &subgraph) { (AttrUtils::GetListStr(op_desc, alias_name_attr, out_alias_name)) && (!out_alias_name.empty()); if (has_valid_str) { std::lock_guard lock(mutex_); - netoutput_nodes_.insert(node); + netoutput_nodes_.emplace_back(node); } } { std::lock_guard lock(mutex_); - merged_graph_nodes_.emplace(node); + merged_graph_nodes_.emplace_back(node); } GELOGD("TUU:subgraph %s add node %s success", subgraph->GetName().c_str(), node->GetName().c_str()); } @@ -627,13 +627,7 @@ graphStatus TuningUtils::RemoveDataNetoutputEdge(ComputeGraphPtr &graph) { return FAILED; } // 3. relink - if (GraphUtils::RemoveEdge(src_out_anchor, net_output_in_anchor) != GRAPH_SUCCESS) { - GELOGE(FAILED, "TUU:remove edge from %s(%d) to %s(%d) failed. node_name:(data:%s;netoutput:%s), graph_name:%s", - GetNodeNameByAnchor(src_out_anchor.get()).c_str(), src_out_anchor->GetIdx(), - GetNodeNameByAnchor(net_output_in_anchor.get()).c_str(), net_output_in_anchor->GetIdx(), - data_node->GetName().c_str(), netoutput_node->GetName().c_str(), graph->GetName().c_str()); - return FAILED; - } + // unlink netoutput_node with it's input in stage 4 GE_CHECK_NOTNULL(data_out_anchor); for (const auto &peer_in_anchor : data_out_anchor->GetPeerAnchors()) { if (GraphUtils::RemoveEdge(data_out_anchor, peer_in_anchor) != GRAPH_SUCCESS) { @@ -704,4 +698,4 @@ graphStatus TuningUtils::GetInAndOutAnchorPair(NodePtr &data_node, NodePtr &out_ return SUCCESS; } -} // namespace ge \ No newline at end of file +} // namespace ge diff --git a/src/ge/CMakeLists.txt b/src/ge/CMakeLists.txt index 4faba8db..bce5816e 100755 --- a/src/ge/CMakeLists.txt +++ b/src/ge/CMakeLists.txt @@ -220,6 +220,11 @@ if (NOT ENABLE_ACL) DAVINCI_SUPPORT_PROFILING REUSE_MEMORY=1 DAVINCI_CLOUD) + target_compile_options(ge_runner PRIVATE + -Werror + -Wno-deprecated-declarations + -Wno-unused-function + -Wno-maybe-uninitialized) target_link_libraries(ge_runner graph ge_common @@ -374,6 +379,11 @@ target_compile_definitions(ge_compiler PRIVATE FMK_SUPPORT_DUMP COMPILE_OMG_PACKAGE REUSE_MEMORY=1) +target_compile_options(ge_compiler PRIVATE + -Werror + -Wno-deprecated-declarations + -Wno-unused-function + -Wno-maybe-uninitialized) target_link_libraries(ge_compiler graph ge_common diff --git a/src/ge/client/ge_api.cc b/src/ge/client/ge_api.cc index a0cf22e7..d2a98066 100644 --- a/src/ge/client/ge_api.cc +++ b/src/ge/client/ge_api.cc @@ -76,7 +76,7 @@ Status CheckOptionsValid(const std::map &options) { } // Initialize GE, prepare for execution, call GELib::Initialize -Status GEInitialize(const std::map &options) { +Status GEInitializeImpl(const std::map &options) { GELOGT(TRACE_INIT, "GEInitialize start"); // 0.check init status if (g_ge_initialized) { @@ -127,6 +127,23 @@ Status GEInitialize(const std::map &options) { return ret; } +// Initialize GE, prepare for execution, call GELib::Initialize +Status GEInitialize(const std::map &options) { return GEInitializeImpl(options); } + +Status GEInitialize(const std::map &options) { + std::map str_options; + for (auto &option : options) { + if (option.first.GetString() == nullptr || option.second.GetString() == nullptr) { + GELOGE(FAILED, "GEInitialize options is nullptr."); + return FAILED; + } + std::string key = option.first.GetString(); + std::string val = option.second.GetString(); + str_options[key] = val; + } + return GEInitializeImpl(str_options); +} + // GE finalize, releasing all resources Status GEFinalize() { GELOGT(TRACE_INIT, "GEFinalize start"); @@ -177,7 +194,7 @@ Session::Session(const std::map &options) { // check init status sessionId_ = 0; if (!g_ge_initialized) { - GELOGE(GE_CLI_GE_NOT_INITIALIZED); + GELOGE(GE_CLI_GE_NOT_INITIALIZED, "GE is not initialized."); return; } // call Initialize @@ -202,6 +219,46 @@ Session::Session(const std::map &options) { GELOGT(TRACE_STOP, "Session Constructor finished"); } +Session::Session(const std::map &options) { + GELOGT(TRACE_INIT, "Session Constructor start"); + // check init status + sessionId_ = 0; + if (!g_ge_initialized) { + GELOGE(GE_CLI_GE_NOT_INITIALIZED, "GE is not initialized."); + return; + } + // call Initialize + std::shared_ptr instance_ptr = ge::GELib::GetInstance(); + if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { + GELOGE(GE_CLI_GE_NOT_INITIALIZED, "Session Constructor failed"); + return; + } + + GELOGT(TRACE_RUNNING, "Creating session"); + std::map str_options; + for (auto &option : options) { + if (option.first.GetString() == nullptr || option.second.GetString() == nullptr) { + GELOGE(FAILED, "Session options is nullptr."); + return; + } + std::string key = option.first.GetString(); + std::string val = option.second.GetString(); + str_options[key] = val; + } + uint64_t session_id = 0; + Status ret = instance_ptr->SessionManagerObj().CreateSession(str_options, session_id); + GELOGT(TRACE_RUNNING, "Session id is %lu", session_id); + + // check return status, return, update session id if success + if (ret == SUCCESS) { + sessionId_ = session_id; + } else { + GELOGE(ret, "Session constructor failed, session Id not initialized"); + return; + } + GELOGT(TRACE_STOP, "Session Constructor finished"); +} + // session destructor Session::~Session() { GELOGT(TRACE_INIT, "Session Destructor start"); @@ -260,6 +317,33 @@ Status Session::AddGraph(uint32_t graph_id, const Graph &graph, const std::map &options) { + GELOGT(TRACE_INIT, "Start to add graph in Session. graph_id: %u, session_id: %lu.", graph_id, sessionId_); + std::shared_ptr instance_ptr = ge::GELib::GetInstance(); + if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { + GELOGE(GE_CLI_GE_NOT_INITIALIZED, "AddGraph failed in Session."); + return FAILED; + } + GELOGD("Adding graph to session"); + std::map str_options; + for (auto &option : options) { + if (option.first.GetString() == nullptr || option.second.GetString() == nullptr) { + GELOGE(FAILED, "AddGraph options is nullptr."); + return FAILED; + } + std::string key = option.first.GetString(); + std::string val = option.second.GetString(); + str_options[key] = val; + } + Status ret = instance_ptr->SessionManagerObj().AddGraph(sessionId_, graph_id, graph, str_options); + if (ret != SUCCESS) { + GELOGE(ret, "AddGraph failed in Session."); + return FAILED; + } + GELOGD("AddGraph finished in Session."); + return ret; +} + Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph) { std::map options; return AddGraphWithCopy(graph_id, graph, options); @@ -387,6 +471,14 @@ Status Session::RegisterCallBackFunc(const std::string &key, const pCallBackFunc return ge::GELib::GetInstance()->SessionManagerObj().RegisterCallBackFunc(sessionId_, key, callback); } +Status Session::RegisterCallBackFunc(const char *key, const session::pCallBackFunc &callback) { + std::string str_key; + if (key != nullptr) { + str_key = key; + } + return ge::GELib::GetInstance()->SessionManagerObj().RegisterCallBackFunc(sessionId_, str_key, callback); +} + Status Session::BuildGraph(uint32_t graph_id, const std::vector &inputs) { std::shared_ptr instance_ptr = ge::GELib::GetInstance(); if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { @@ -436,6 +528,29 @@ Status Session::GetVariables(const std::vector &var_names, std::vec return SUCCESS; } +Status Session::GetVariables(const std::vector &var_names, std::vector &var_values) { + auto instance_ptr = ge::GELib::GetInstance(); + if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { + GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed"); + return FAILED; + } + GELOGT(TRACE_RUNNING, "Get Variables"); + std::vector str_var_names; + for (auto &var_name : var_names) { + if (var_name.GetString() == nullptr) { + GELOGE(FAILED, "GetVariables name is nullptr."); + return FAILED; + } + str_var_names.emplace_back(var_name.GetString()); + } + Status ret = ge::GELib::GetInstance()->SessionManagerObj().GetVariables(sessionId_, str_var_names, var_values); + if (ret != SUCCESS) { + GELOGE(ret, "SessionManager RunGraphAsync failed"); + return FAILED; + } + return SUCCESS; +} + bool Session::IsGraphNeedRebuild(uint32_t graph_id) { return ge::GELib::GetInstance()->SessionManagerObj().IsGraphNeedRebuild(sessionId_, graph_id); } diff --git a/src/ge/common/CMakeLists.txt b/src/ge/common/CMakeLists.txt index f6c75f87..40818d42 100755 --- a/src/ge/common/CMakeLists.txt +++ b/src/ge/common/CMakeLists.txt @@ -90,6 +90,9 @@ target_compile_definitions(ge_common PUBLIC PROTOBUF_INLINE_NOT_IN_HEADERS=0 HOST_VISIBILITY OS_CENTOS) +target_compile_options(ge_common PRIVATE + -Werror + -Wno-deprecated-declarations) target_link_libraries(ge_common graph ${PROTOBUF_LIBRARY} diff --git a/src/ge/common/auth/file_saver.cc b/src/ge/common/auth/file_saver.cc index a044e56f..99a94538 100644 --- a/src/ge/common/auth/file_saver.cc +++ b/src/ge/common/auth/file_saver.cc @@ -16,9 +16,7 @@ #include "common/auth/file_saver.h" -#include #include -#include #include #include #include @@ -39,12 +37,12 @@ Status FileSaver::OpenFile(int32_t &fd, const std::string &file_path) { return FAILED; } - char real_path[PATH_MAX] = {0}; - GE_IF_BOOL_EXEC(realpath(file_path.c_str(), real_path) == nullptr, + char real_path[MMPA_MAX_PATH] = {0}; + GE_IF_BOOL_EXEC(mmRealPath(file_path.c_str(), real_path, MMPA_MAX_PATH) != EN_OK, GELOGI("File %s is not exist, it will be created.", file_path.c_str())); // Open file - mode_t mode = S_IRUSR | S_IWUSR; - fd = mmOpen2(real_path, O_RDWR | O_CREAT | O_TRUNC, mode); + mmMode_t mode = M_IRUSR | M_IWUSR; + fd = mmOpen2(real_path, M_RDWR | M_CREAT | O_TRUNC, mode); if (fd == EN_INVALID_PARAM || fd == EN_ERROR) { // -1: Failed to open file; - 2: Illegal parameter GELOGE(FAILED, "Open file failed. mmpa_errno = %d, %s", fd, strerror(errno)); @@ -193,7 +191,7 @@ Status FileSaver::SaveToBuffWithFileHeader(const ModelFileHeader &file_header, FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status FileSaver::CheckPath(const std::string &file_path) { // Determine file path length - if (file_path.size() >= PATH_MAX) { + if (file_path.size() >= MMPA_MAX_PATH) { GELOGE(FAILED, "Path is too long:%zu", file_path.size()); return FAILED; } diff --git a/src/ge/common/cust_aicpu_kernel_store.cc b/src/ge/common/cust_aicpu_kernel_store.cc index 46eb484b..3ce22cdf 100644 --- a/src/ge/common/cust_aicpu_kernel_store.cc +++ b/src/ge/common/cust_aicpu_kernel_store.cc @@ -23,7 +23,7 @@ CustAICPUKernelStore::CustAICPUKernelStore() {} void CustAICPUKernelStore::AddCustAICPUKernel(const CustAICPUKernelPtr &kernel) { AddKernel(kernel); } void CustAICPUKernelStore::LoadCustAICPUKernelBinToOpDesc(const std::shared_ptr &op_desc) const { - GELOGI("LoadCustAICPUKernelBinToOpDesc in"); + GELOGD("LoadCustAICPUKernelBinToOpDesc in"); if (op_desc != nullptr) { auto kernel_bin = FindKernel(op_desc->GetName()); if (kernel_bin != nullptr) { @@ -32,6 +32,6 @@ void CustAICPUKernelStore::LoadCustAICPUKernelBinToOpDesc(const std::shared_ptr< GELOGI("Load cust aicpu kernel:%s, %zu", kernel_bin->GetName().c_str(), kernel_bin->GetBinDataSize()); } } - GELOGI("LoadCustAICPUKernelBinToOpDesc success"); + GELOGD("LoadCustAICPUKernelBinToOpDesc success"); } } // namespace ge diff --git a/src/ge/common/debug/memory_dumper.cc b/src/ge/common/debug/memory_dumper.cc index 1a7d9db8..ad0507ab 100644 --- a/src/ge/common/debug/memory_dumper.cc +++ b/src/ge/common/debug/memory_dumper.cc @@ -16,9 +16,6 @@ #include "common/debug/memory_dumper.h" -#include - -#include #include #include "framework/common/debug/log.h" @@ -138,26 +135,26 @@ int MemoryDumper::OpenFile(const char *filename) { } // Get the absolute path string real_path; - char tmp_path[PATH_MAX] = {0}; - GE_IF_BOOL_EXEC( - -1 != path_split_pos, string prefix_path = std::string(filename).substr(0, path_split_pos); - string last_path = std::string(filename).substr(path_split_pos, strlen(filename) - 1); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(prefix_path.length() >= PATH_MAX, return kInvalidFd, "Prefix path is too long!"); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(realpath(prefix_path.c_str(), tmp_path) == nullptr, return kInvalidFd, - "Dir %s does not exit.", prefix_path.c_str()); - real_path = std::string(tmp_path) + last_path;) + char tmp_path[MMPA_MAX_PATH] = {0}; + GE_IF_BOOL_EXEC(-1 != path_split_pos, string prefix_path = std::string(filename).substr(0, path_split_pos); + string last_path = std::string(filename).substr(path_split_pos, strlen(filename) - 1); + GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(prefix_path.length() >= MMPA_MAX_PATH, return kInvalidFd, + "Prefix path is too long!"); + GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(mmRealPath(prefix_path.c_str(), tmp_path, MMPA_MAX_PATH) != EN_OK, + return kInvalidFd, "Dir %s does not exit.", prefix_path.c_str()); + real_path = std::string(tmp_path) + last_path;) GE_IF_BOOL_EXEC( path_split_pos == -1 || path_split_pos == 0, - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(filename) >= PATH_MAX, return kInvalidFd, "Prefix path is too long!"); - GE_IF_BOOL_EXEC(realpath(filename, tmp_path) == nullptr, + GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(filename) >= MMPA_MAX_PATH, return kInvalidFd, "Prefix path is too long!"); + GE_IF_BOOL_EXEC(mmRealPath(filename, tmp_path, MMPA_MAX_PATH) != EN_OK, GELOGI("File %s does not exit, it will be created.", filename)); real_path = std::string(tmp_path);) // Open file, only the current user can read and write, to avoid malicious application access // Using the O_EXCL, if the file already exists,return failed to avoid privilege escalation vulnerability. - mode_t mode = S_IRUSR | S_IWUSR; + mmMode_t mode = M_IRUSR | M_IWUSR; - int32_t fd = mmOpen2(real_path.c_str(), O_RDWR | O_CREAT | O_APPEND, mode); + int32_t fd = mmOpen2(real_path.c_str(), M_RDWR | M_CREAT | O_TRUNC, mode); if (fd == EN_ERROR || fd == EN_INVALID_PARAM) { GELOGE(kInvalidFd, "open file failed. errno = %d, %s", fd, strerror(errno)); return kInvalidFd; diff --git a/src/ge/common/formats/format_transfers/format_transfer_nchw_fz_c04.cc b/src/ge/common/formats/format_transfers/format_transfer_nchw_fz_c04.cc index ef4fe714..6740049b 100644 --- a/src/ge/common/formats/format_transfers/format_transfer_nchw_fz_c04.cc +++ b/src/ge/common/formats/format_transfers/format_transfer_nchw_fz_c04.cc @@ -118,19 +118,19 @@ Status TransFormatFromNchwToFzC04(const TransArgs &args, TransResult &result) { // data overflow check totally GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(h_o, w_o), - GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", h_o, w_o); + GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", h_o, w_o); return INTERNAL_ERROR); GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(n_o, c_o), - GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", n_o, c_o); + GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", n_o, c_o); return INTERNAL_ERROR); auto t1 = h_o * w_o; auto t2 = n_o * c_o; - GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(t1, t2), GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", t1, t2); + GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(t1, t2), GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", t1, t2); return INTERNAL_ERROR); int64_t total_ele_cnt = n_o * c_o * h_o * w_o; GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(total_ele_cnt, size), - GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", total_ele_cnt, size); + GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%d]", total_ele_cnt, size); return INTERNAL_ERROR); int64_t dst_size = total_ele_cnt * size; if (dst_size == 0) { @@ -205,20 +205,20 @@ Status PaddingNC(const TransArgs &args, TransArgs &args_tmp, std::shared_ptr #include -#include #include #include #include @@ -38,8 +36,10 @@ const char *const kExt = ".so"; // supported extension of shared obje namespace ge { void PluginManager::ClearHandles_() noexcept { for (const auto &handle : handles_) { - if (dlclose(handle.second) != 0) { - GELOGW("Failed to close handle of %s: %s", handle.first.c_str(), dlerror()); + if (mmDlclose(handle.second) != 0) { + const char *error = mmDlerror(); + GE_IF_BOOL_EXEC(error == nullptr, error = ""); + GELOGW("Failed to close handle of %s: %s", handle.first.c_str(), error); } } handles_.clear(); @@ -48,18 +48,18 @@ void PluginManager::ClearHandles_() noexcept { PluginManager::~PluginManager() { ClearHandles_(); } string PluginManager::GetPath() { - Dl_info dl_info; - if (dladdr(reinterpret_cast(&PluginManager::GetPath), &dl_info) == 0) { + mmDlInfo dl_info; + if (mmDladdr(reinterpret_cast(&PluginManager::GetPath), &dl_info) != EN_OK) { GELOGW("Failed to read the shared library file path!"); return string(); } else { std::string so_path = dl_info.dli_fname; - char path[PATH_MAX] = {0}; - if (so_path.length() >= PATH_MAX) { + char path[MMPA_MAX_PATH] = {0}; + if (so_path.length() >= MMPA_MAX_PATH) { GELOGW("The shared library file path is too long!"); return string(); } - if (realpath(so_path.c_str(), path) == nullptr) { + if (mmRealPath(so_path.c_str(), path, MMPA_MAX_PATH) != EN_OK) { GELOGW("Failed to get realpath of %s", so_path.c_str()); return string(); } @@ -93,7 +93,7 @@ Status PluginManager::LoadSo(const string &path, const vector &func_chec std::vector path_vec; SplitPath(path, path_vec); for (const auto &single_path : path_vec) { - GE_IF_BOOL_EXEC(single_path.length() >= PATH_MAX, + GE_IF_BOOL_EXEC(single_path.length() >= MMPA_MAX_PATH, GELOGE(GE_PLGMGR_PATH_INVALID, "The shared library file path is too long!"); continue); // load break when number of loaded so reach maximum @@ -121,16 +121,18 @@ Status PluginManager::LoadSo(const string &path, const vector &func_chec GELOGI("dlopen the shared library path name: %s.", file_path_dlopen.c_str()); // load continue when dlopen is failed - auto handle = dlopen(file_path_dlopen.c_str(), RTLD_NOW | RTLD_GLOBAL); + auto handle = mmDlopen(file_path_dlopen.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); if (handle == nullptr) { - GELOGE(GE_PLGMGR_PATH_INVALID, "Failed to dlopen %s!", dlerror()); + const char *error = mmDlerror(); + GE_IF_BOOL_EXEC(error == nullptr, error = ""); + GELOGE(GE_PLGMGR_PATH_INVALID, "Failed to dlopen %s!", error); continue; } // load continue when so is invalid bool is_valid = true; for (const auto &func_name : func_check_list) { - auto real_fn = (void (*)())dlsym(handle, func_name.c_str()); + auto real_fn = (void (*)())mmDlsym(handle, const_cast(func_name.c_str())); if (real_fn == nullptr) { GELOGE(GE_PLGMGR_PATH_INVALID, "%s is skipped since function %s is not existed!", func_name.c_str(), func_name.c_str()); @@ -139,7 +141,7 @@ Status PluginManager::LoadSo(const string &path, const vector &func_chec } } if (!is_valid) { - GE_LOGE_IF(dlclose(handle), "Failed to dlclose."); + GE_LOGE_IF(mmDlclose(handle), "Failed to dlclose."); continue; } @@ -199,22 +201,29 @@ Status PluginManager::Load(const string &path, const vector &func_check_ so_list_.clear(); ClearHandles_(); - char canonical_path[PATH_MAX] = {0}; - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path.length() >= PATH_MAX, GELOGW("File path is too long!"); + char canonical_path[MMPA_MAX_PATH] = {0}; + GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path.length() >= MMPA_MAX_PATH, GELOGW("File path is too long!"); return FAILED, "File path is too long!"); - if (realpath(path.c_str(), canonical_path) == nullptr) { + if (mmRealPath(path.c_str(), canonical_path, MMPA_MAX_PATH) != EN_OK) { GELOGW("Failed to get realpath of %s", path.c_str()); return SUCCESS; } - DIR *dir = opendir(canonical_path); - if (dir == nullptr) { + INT32 is_dir = mmIsDir(canonical_path); + // Lib plugin path not exist + if (is_dir != EN_OK) { GELOGW("Invalid path for load: %s", path.c_str()); return SUCCESS; } - struct dirent *entry = nullptr; - while ((entry = readdir(dir)) != nullptr) { + mmDirent **entries = nullptr; + auto ret = mmScandir(canonical_path, &entries, nullptr, nullptr); + if (ret < EN_OK) { + GELOGW("scan dir failed. path = %s, ret = %d", canonical_path, ret); + return FAILED; + } + for (int i = 0; i < ret; ++i) { + mmDirent *entry = entries[i]; // read fileName and fileType std::string file_name = entry->d_name; unsigned char file_type = entry->d_type; @@ -254,9 +263,11 @@ Status PluginManager::Load(const string &path, const vector &func_check_ GELOGI("Dlopen so path name: %s. ", file_path_dlopen.c_str()); // load continue when dlopen is failed - auto handle = dlopen(file_path_dlopen.c_str(), RTLD_NOW | RTLD_GLOBAL); + auto handle = mmDlopen(file_path_dlopen.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); if (handle == nullptr) { - GELOGW("Failed in dlopen %s!", dlerror()); + const char *error = mmDlerror(); + GE_IF_BOOL_EXEC(error == nullptr, error = ""); + GELOGW("Failed in dlopen %s!", error); continue; } @@ -265,7 +276,7 @@ Status PluginManager::Load(const string &path, const vector &func_check_ // load continue when so is invalid bool is_valid = true; for (const auto &func_name : func_check_list) { - auto real_fn = (void (*)())dlsym(handle, func_name.c_str()); + auto real_fn = (void (*)())mmDlsym(handle, const_cast(func_name.c_str())); if (real_fn == nullptr) { GELOGW("The %s is skipped since function %s is not existed!", file_name.c_str(), func_name.c_str()); is_valid = false; @@ -273,7 +284,7 @@ Status PluginManager::Load(const string &path, const vector &func_check_ } } if (!is_valid) { - GE_LOGE_IF(dlclose(handle), "Failed to dlclose."); + GE_LOGE_IF(mmDlclose(handle), "Failed to dlclose."); continue; } @@ -283,7 +294,7 @@ Status PluginManager::Load(const string &path, const vector &func_check_ handles_[string(file_name)] = handle; num_of_loaded_so++; } - closedir(dir); + mmScandirFree(entries, ret); if (num_of_loaded_so == 0) { GELOGW("No loadable shared library found in the path: %s", path.c_str()); return SUCCESS; diff --git a/src/ge/common/ge/plugin_manager.h b/src/ge/common/ge/plugin_manager.h index b35a631a..b734ce42 100644 --- a/src/ge/common/ge/plugin_manager.h +++ b/src/ge/common/ge/plugin_manager.h @@ -17,7 +17,6 @@ #ifndef GE_COMMON_GE_PLUGIN_MANAGER_H_ #define GE_COMMON_GE_PLUGIN_MANAGER_H_ -#include #include #include #include @@ -30,6 +29,7 @@ #include "common/ge_inner_error_codes.h" #include "engine/dnnengine.h" #include "framework/common/debug/ge_log.h" +#include "mmpa/mmpa_api.h" namespace ge { using SoToHandleMap = std::map; @@ -57,7 +57,7 @@ class PluginManager { template Status GetAllFunctions(const string &func_name, map> &funcs) { for (const auto &handle : handles_) { - auto real_fn = (R(*)(Types...))dlsym(handle.second, func_name.c_str()); + auto real_fn = (R(*)(Types...))mmDlsym(handle.second, const_cast(func_name.c_str())); if (real_fn == nullptr) { GELOGW("Failed to get function %s in %s!", func_name.c_str(), handle.first.c_str()); return GE_PLGMGR_FUNC_NOT_EXIST; @@ -72,7 +72,7 @@ class PluginManager { Status InvokeAll(const string &func_name, Types... args) { for (const auto &handle : handles_) { // If the funcName is existed, signature of realFn can be casted to any type - auto real_fn = (void (*)(Types...))dlsym(handle.second, func_name.c_str()); + auto real_fn = (void (*)(Types...))mmDlsym(handle.second, const_cast(func_name.c_str())); if (real_fn == nullptr) { GELOGW("Failed to invoke function %s in %s!", func_name.c_str(), handle.first.c_str()); return GE_PLGMGR_INVOKE_FAILED; @@ -87,7 +87,7 @@ class PluginManager { Status InvokeAll(const string &func_name, T arg) { for (const auto &handle : handles_) { // If the funcName is existed, signature of realFn can be casted to any type - auto real_fn = (void (*)(T))dlsym(handle.second, func_name.c_str()); + auto real_fn = (void (*)(T))mmDlsym(handle.second, const_cast(func_name.c_str())); if (real_fn == nullptr) { GELOGW("Failed to invoke function %s in %s!", func_name.c_str(), handle.first.c_str()); return GE_PLGMGR_INVOKE_FAILED; @@ -112,7 +112,7 @@ class PluginManager { Status InvokeAll(const string &func_name, T1 arg) { for (const auto &handle : handles_) { // If the funcName is existed, signature of realFn can be casted to any type - auto real_fn = (T2(*)(T1))dlsym(handle.second, func_name.c_str()); + auto real_fn = (T2(*)(T1))mmDlsym(handle.second, const_cast(func_name.c_str())); if (real_fn == nullptr) { GELOGW("Failed to invoke function %s in %s!", func_name.c_str(), handle.first.c_str()); return GE_PLGMGR_INVOKE_FAILED; @@ -130,7 +130,7 @@ class PluginManager { Status InvokeAll(const string &func_name) { for (const auto &handle : handles_) { // If the funcName is existed, signature of realFn can be casted to any type - auto real_fn = (T(*)())dlsym(handle.second, func_name.c_str()); + auto real_fn = (T(*)())mmDlsym(handle.second, const_cast(func_name.c_str())); if (real_fn == nullptr) { GELOGW("Failed to invoke function %s in %s!", func_name.c_str(), handle.first.c_str()); return GE_PLGMGR_INVOKE_FAILED; diff --git a/src/ge/common/ge/tbe_plugin_manager.cc b/src/ge/common/ge/tbe_plugin_manager.cc index 731d7bb0..35bb4d8a 100644 --- a/src/ge/common/ge/tbe_plugin_manager.cc +++ b/src/ge/common/ge/tbe_plugin_manager.cc @@ -16,8 +16,6 @@ #include "common/ge/tbe_plugin_manager.h" -#include -#include #include #include #include @@ -50,9 +48,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY TBEPluginManager &TBEPluginMana Status TBEPluginManager::ClearHandles_() { Status ret = SUCCESS; for (const auto &handle : handles_vec_) { - if (dlclose(handle) != 0) { + if (mmDlclose(handle) != 0) { ret = FAILED; - GELOGW("Failed to close handle: %s", dlerror()); + const char *error = mmDlerror(); + GE_IF_BOOL_EXEC(error == nullptr, error = ""); + GELOGW("Failed to close handle: %s", error); } } handles_vec_.clear(); @@ -65,18 +65,18 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status TBEPluginManager::Finali } string TBEPluginManager::GetPath() { - Dl_info dl_info; - if (dladdr(reinterpret_cast(&TBEPluginManager::GetPath), &dl_info) == 0) { + mmDlInfo dl_info; + if (mmDladdr(reinterpret_cast(&TBEPluginManager::GetPath), &dl_info) != EN_OK) { GELOGW("Failed to read so path!"); return string(); } else { string so_path = dl_info.dli_fname; - char path[PATH_MAX] = {0}; - if (so_path.length() >= PATH_MAX) { + char path[MMPA_MAX_PATH] = {0}; + if (so_path.length() >= MMPA_MAX_PATH) { GELOGW("File path is too long!"); return string(); } - if (realpath(so_path.c_str(), path) == nullptr) { + if (mmRealPath(so_path.c_str(), path, MMPA_MAX_PATH) != EN_OK) { GELOGW("Failed to get realpath of %s", so_path.c_str()); return string(); } @@ -108,20 +108,21 @@ void TBEPluginManager::FindParserSo(const string &path, vector &file_lis GELOGW("RealPath is empty."); return; } - struct stat stat_buf; - if ((stat(real_path.c_str(), &stat_buf) != 0) || (!S_ISDIR(stat_buf.st_mode))) { + INT32 is_dir = mmIsDir(real_path.c_str()); + // Lib plugin path not exist + if (is_dir != EN_OK) { GELOGW("%s is not a dir.", real_path.c_str()); return; } - struct dirent *dent(0); - DIR *dir = opendir(real_path.c_str()); - // Plugin path does not exist - if (dir == nullptr) { - GELOGW("Open directory %s failed.", real_path.c_str()); + + mmDirent **entries = nullptr; + auto ret = mmScandir(real_path.c_str(), &entries, nullptr, nullptr); + if (ret < EN_OK) { + GELOGW("scan dir failed. path = %s, ret = %d", real_path.c_str(), ret); return; } - - while ((dent = readdir(dir)) != nullptr) { + for (int i = 0; i < ret; ++i) { + mmDirent *dent = entries[i]; if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) continue; string name = dent->d_name; string full_name = real_path + "/" + name; @@ -136,7 +137,7 @@ void TBEPluginManager::FindParserSo(const string &path, vector &file_lis FindParserSo(full_name, file_list, caffe_parser_path); } } - closedir(dir); + mmScandirFree(entries, ret); } void TBEPluginManager::GetPluginSoFileList(const string &path, vector &file_list, string &caffe_parser_path) { @@ -159,8 +160,9 @@ void TBEPluginManager::GetCustomOpPath(std::string &customop_path) { fmk_type = ge::TypeUtils::FmkTypeToSerialString(type); GELOGI("Framework type is %s.", fmk_type.c_str()); - const char *path_env = std::getenv("ASCEND_OPP_PATH"); - if (path_env != nullptr) { + char path_env[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv("ASCEND_OPP_PATH", path_env, MMPA_MAX_PATH); + if (res == EN_OK) { std::string path = path_env; customop_path = (path + "/framework/custom" + "/:") + (path + "/framework/built-in/" + fmk_type); GELOGI("Get custom so path from env : %s", path_env); @@ -210,9 +212,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void TBEPluginManager::LoadPlug for (auto elem : file_list) { StringUtils::Trim(elem); - void *handle = dlopen(elem.c_str(), RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); + void *handle = mmDlopen(elem.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL | MMPA_RTLD_NODELETE); if (handle == nullptr) { - GELOGW("dlopen failed, plugin name:%s. Message(%s).", elem.c_str(), dlerror()); + const char *error = mmDlerror(); + GE_IF_BOOL_EXEC(error == nullptr, error = ""); + GELOGW("dlopen failed, plugin name:%s. Message(%s).", elem.c_str(), error); } else if (find(handles_vec_.begin(), handles_vec_.end(), handle) == handles_vec_.end()) { // Close dl when the program exist, not close here GELOGI("Plugin load %s success.", elem.c_str()); diff --git a/src/ge/common/ge/tbe_plugin_manager.h b/src/ge/common/ge/tbe_plugin_manager.h index 4430d4aa..30edc2ce 100644 --- a/src/ge/common/ge/tbe_plugin_manager.h +++ b/src/ge/common/ge/tbe_plugin_manager.h @@ -17,7 +17,6 @@ #ifndef GE_COMMON_GE_TBE_PLUGIN_MANAGER_H_ #define GE_COMMON_GE_TBE_PLUGIN_MANAGER_H_ -#include #include #include #include diff --git a/src/ge/common/ge_common.mk b/src/ge/common/ge_common.mk index 28536195..3fffd203 100644 --- a/src/ge/common/ge_common.mk +++ b/src/ge/common/ge_common.mk @@ -82,8 +82,9 @@ include $(CLEAR_VARS) LOCAL_MODULE := libge_common -LOCAL_CFLAGS += -Werror -DFMK_SUPPORT_DUMP +LOCAL_CFLAGS += -Werror -DFMK_SUPPORT_DUMP -Wno-deprecated-declarations LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -O2 -Dgoogle=ascend_private + ifeq ($(DEBUG), 1) LOCAL_CFLAGS += -g -O0 else @@ -109,11 +110,12 @@ LOCAL_SHARED_LIBRARIES := \ libascend_protobuf \ libc_sec \ libslog \ - libmmpa \ libgraph \ libregister \ liberror_manager \ +LOCAL_STATIC_LIBRARIES += libmmpa + LOCAL_LDFLAGS := -lrt -ldl include $(BUILD_HOST_SHARED_LIBRARY) @@ -123,8 +125,9 @@ include $(CLEAR_VARS) LOCAL_MODULE := libge_common -LOCAL_CFLAGS += -Werror -DFMK_SUPPORT_DUMP +LOCAL_CFLAGS += -Werror -DFMK_SUPPORT_DUMP -Wno-deprecated-declarations LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -O2 -Dgoogle=ascend_private + ifeq ($(DEBUG), 1) LOCAL_CFLAGS += -g -O0 else @@ -150,11 +153,12 @@ LOCAL_SHARED_LIBRARIES := \ libascend_protobuf \ libc_sec \ libslog \ - libmmpa \ libgraph \ libregister \ liberror_manager \ +LOCAL_STATIC_LIBRARIES += libmmpa + ifeq ($(device_os),android) LOCAL_LDFLAGS += -ldl LOCAL_LDLIBS += -L$(PWD)/prebuilts/clang/linux-x86/aarch64/android-ndk-r21/sysroot/usr/lib/aarch64-linux-android/29 -llog @@ -169,8 +173,9 @@ include $(CLEAR_VARS) LOCAL_MODULE := libge_common -LOCAL_CFLAGS += -Werror -DFMK_SUPPORT_DUMP +LOCAL_CFLAGS += -Werror -DFMK_SUPPORT_DUMP -Wno-deprecated-declarations LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -O2 -Dgoogle=ascend_private + ifeq ($(DEBUG), 1) LOCAL_CFLAGS += -g -O0 endif @@ -211,8 +216,9 @@ include $(CLEAR_VARS) LOCAL_MODULE := libge_common -LOCAL_CFLAGS += -Werror -DFMK_SUPPORT_DUMP +LOCAL_CFLAGS += -Werror -DFMK_SUPPORT_DUMP -Wno-deprecated-declarations LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -O2 -Dgoogle=ascend_private + ifeq ($(DEBUG), 1) LOCAL_CFLAGS += -g -O0 endif diff --git a/src/ge/common/helper/model_cache_helper.cc b/src/ge/common/helper/model_cache_helper.cc index 0c8fddda..7d2d20fe 100644 --- a/src/ge/common/helper/model_cache_helper.cc +++ b/src/ge/common/helper/model_cache_helper.cc @@ -14,8 +14,6 @@ * limitations under the License. */ -#include -#include #include #include #include @@ -448,12 +446,12 @@ Status ModelCacheHelper::SaveJsonToFile(const string &file_name, const Json &jso } const string path = cache_path_ + file_name; const int FILE_AUTHORITY = 0600; - int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, FILE_AUTHORITY); + int fd = mmOpen2(path.c_str(), M_WRONLY | M_CREAT | O_TRUNC, FILE_AUTHORITY); if (fd < 0) { GELOGW("Fail to open the file: %s.", path.c_str()); return INTERNAL_ERROR; } - if (close(fd) != 0) { + if (mmClose(fd) != 0) { GELOGW("Fail to close the file: %s.", path.c_str()); return INTERNAL_ERROR; } diff --git a/src/ge/common/helper/model_helper.cc b/src/ge/common/helper/model_helper.cc index 15683257..8fb915cd 100644 --- a/src/ge/common/helper/model_helper.cc +++ b/src/ge/common/helper/model_helper.cc @@ -97,7 +97,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod ge::Buffer model_buffer; (void)model_tmp->Save(model_buffer); - GELOGI("MODEL_DEF size is %zu", model_buffer.GetSize()); + GELOGD("MODEL_DEF size is %zu", model_buffer.GetSize()); if (model_buffer.GetSize() > 0) { if (SaveModelPartition(om_file_save_helper, ModelPartitionType::MODEL_DEF, model_buffer.GetData(), model_buffer.GetSize()) != SUCCESS) { @@ -106,7 +106,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod } } auto ge_model_weight = ge_model->GetWeight(); - GELOGI("WEIGHTS_DATA size is %zu, %p", ge_model_weight.GetSize(), ge_model_weight.GetData()); + GELOGD("WEIGHTS_DATA size is %zu, %p", ge_model_weight.GetSize(), ge_model_weight.GetData()); // weight is not necessary if (ge_model_weight.GetSize() > 0) { GE_CHK_STATUS_RET(SaveModelPartition(om_file_save_helper, ModelPartitionType::WEIGHTS_DATA, @@ -115,7 +115,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod } TBEKernelStore tbe_kernel_store = ge_model->GetTBEKernelStore(); - GELOGI("TBE_KERNELS size is %zu", tbe_kernel_store.DataSize()); + GELOGD("TBE_KERNELS size is %zu", tbe_kernel_store.DataSize()); if (tbe_kernel_store.DataSize() > 0) { GE_CHK_STATUS_RET(SaveModelPartition(om_file_save_helper, ModelPartitionType::TBE_KERNELS, tbe_kernel_store.Data(), tbe_kernel_store.DataSize()), @@ -126,7 +126,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod (void)tbe_kernel_store.Load(tbe_kernel_store.Data(), tbe_kernel_store.DataSize()); CustAICPUKernelStore cust_aicpu_kernel_store = ge_model->GetCustAICPUKernelStore(); - GELOGI("cust aicpu kernels size is %zu", cust_aicpu_kernel_store.DataSize()); + GELOGD("cust aicpu kernels size is %zu", cust_aicpu_kernel_store.DataSize()); if (cust_aicpu_kernel_store.DataSize() > 0) { GE_CHK_STATUS_RET(SaveModelPartition(om_file_save_helper, ModelPartitionType::CUST_AICPU_KERNELS, cust_aicpu_kernel_store.Data(), cust_aicpu_kernel_store.DataSize()), @@ -150,8 +150,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod } (void)model_task_def->SerializePartialToArray(task_buffer.GetData(), static_cast(partition_task_size)); - GELOGI("TASK_INFO op_size:%d, stream_num:%u", model_task_def->op().size(), model_task_def->stream_num()); - GELOGI("TASK_INFO size is %zu", partition_task_size); + GELOGD("TASK_INFO op_size:%d, stream_num:%u", model_task_def->op().size(), model_task_def->stream_num()); + GELOGD("TASK_INFO size is %zu", partition_task_size); if (SaveModelPartition(om_file_save_helper, ModelPartitionType::TASK_INFO, task_buffer.GetData(), partition_task_size) != SUCCESS) { @@ -163,7 +163,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod model_header.platform_type = ge_model->GetPlatformType(); model_header.om_ir_version = ge_model->GetVersion(); std::string platform_version = ge_model->GetPlatformVersion(); - GELOGI("Platform version save: %s", platform_version.c_str()); errno_t err; err = memcpy_s(model_header.platform_version, PLATFORM_VERSION_LEN, platform_version.c_str(), @@ -173,7 +172,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod return MEMALLOC_FAILED; } string version = reinterpret_cast(model_header.platform_version); - GELOGI("Platform version save: %s", version.c_str()); + GELOGD("Platform version save: %s", version.c_str()); size_t name_size = ge_model->GetName().size(); name_size = name_size > (MODEL_NAME_LENGTH - 1) ? (MODEL_NAME_LENGTH - 1) : name_size; @@ -183,7 +182,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod return MEMALLOC_FAILED; } string model_name = reinterpret_cast(model_header.name); - GELOGI("Model name save:%s", model_name.c_str()); + GELOGD("Model name save:%s", model_name.c_str()); Status ret = om_file_save_helper->SaveModel(save_param, output_file.c_str(), model, is_offline_); if (ret != SUCCESS) { @@ -263,18 +262,18 @@ ModelHelper::SaveOriginalGraphToOmModel(const ge::Graph &graph, const std::strin FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadModel(const ge::ModelData &model_data) { if (model_data.model_data == nullptr || model_data.model_len == 0) { - GELOGE(GE_EXEC_MODEL_DATA_SIZE_INVALID, "Model_data is nullptr, or model_data_size is 0"); - return GE_EXEC_MODEL_DATA_SIZE_INVALID; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "Model_data is nullptr, or model_data_size is 0"); + return ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID; } if (is_assign_model_) { - GELOGE(GE_EXEC_LOAD_MODEL_REPEATED, "Model helper has already loaded!"); - return GE_EXEC_LOAD_MODEL_REPEATED; + GELOGE(ACL_ERROR_GE_EXEC_LOAD_MODEL_REPEATED, "Model helper has already loaded!"); + return ACL_ERROR_GE_EXEC_LOAD_MODEL_REPEATED; } if (ReleaseLocalModelData() != SUCCESS) { - GELOGE(INTERNAL_ERROR, "ReleaseLocalModelData failed."); - return INTERNAL_ERROR; + GELOGE(ACL_ERROR_GE_EXEC_RELEASE_MODEL_DATA, "ReleaseLocalModelData failed."); + return ACL_ERROR_GE_EXEC_RELEASE_MODEL_DATA; } Status status = ge::DavinciModelParser::ParseModelContent(model_data, model_addr_tmp_, model_len_tmp_); @@ -295,8 +294,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadModel(c auto partition_table = reinterpret_cast(model_addr_tmp_); if (partition_table->num == kOriginalOmPartitionNum) { model_addr_tmp_ = nullptr; - GELOGE(GE_EXEC_MODEL_PARTITION_NUM_INVALID, "om model is error,please use executable om model"); - return GE_EXEC_MODEL_PARTITION_NUM_INVALID; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_PARTITION_NUM_INVALID, "om model is error,please use executable om model"); + return ACL_ERROR_GE_EXEC_MODEL_PARTITION_NUM_INVALID; } // Encrypt model need to del temp model/no encrypt model don't need to del model model_addr_tmp_ = nullptr; @@ -316,23 +315,23 @@ Status ModelHelper::GenerateGeModel(OmFileLoadHelper &om_load_helper) { GE_CHECK_NOTNULL(model_); Status ret = LoadModelData(om_load_helper); if (ret != SUCCESS) { - return GE_EXEC_LOAD_MODEL_PARTITION_FAILED; + return ACL_ERROR_GE_EXEC_LOAD_MODEL_PARTITION_FAILED; } ret = LoadWeights(om_load_helper); if (ret != SUCCESS) { - return GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED; + return ACL_ERROR_GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED; } ret = LoadTask(om_load_helper); if (ret != SUCCESS) { - return GE_EXEC_LOAD_TASK_PARTITION_FAILED; + return ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED; } ret = LoadTBEKernelStore(om_load_helper); if (ret != SUCCESS) { - return GE_EXEC_LOAD_KERNEL_PARTITION_FAILED; + return ACL_ERROR_GE_EXEC_LOAD_KERNEL_PARTITION_FAILED; } ret = LoadCustAICPUKernelStore(om_load_helper); if (ret != SUCCESS) { - return GE_EXEC_LOAD_KERNEL_PARTITION_FAILED; + return ACL_ERROR_GE_EXEC_LOAD_KERNEL_PARTITION_FAILED; } return SUCCESS; } @@ -341,7 +340,7 @@ Status ModelHelper::LoadModelData(OmFileLoadHelper &om_load_helper) { ModelPartition partition_model_def; // no need to check value, DATA->NetOutput om_load_helper.GetModelPartition(ModelPartitionType::MODEL_DEF, partition_model_def); - GELOGI("Model_def partition addr:%p,size:%u", partition_model_def.data, partition_model_def.size); + GELOGD("Model_def partition addr:%p,size:%u", partition_model_def.data, partition_model_def.size); ge::Model model; if (ge::Model::Load(partition_model_def.data, partition_model_def.size, model) != SUCCESS) { @@ -371,7 +370,7 @@ Status ModelHelper::LoadWeights(OmFileLoadHelper &om_load_helper) { ge::Buffer weight = ge::Buffer::CopyFrom(partition.data, partition.size); model_->SetWeight(weight); - GELOGI("GetWeight size:%u", partition.size); + GELOGD("GetWeight size:%u", partition.size); return SUCCESS; } @@ -388,7 +387,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadTask(Om GELOGE(INTERNAL_ERROR, "ReadProtoFromArray failed."); return INTERNAL_ERROR; } - GELOGI("TASK_INFO op_size:%zu, stream_num:%u", task->op().size(), task->stream_num()); + GELOGD("TASK_INFO op_size:%d, stream_num:%u", task->op().size(), task->stream_num()); } model_->SetModelTaskDef(task); return SUCCESS; @@ -399,9 +398,9 @@ Status ModelHelper::LoadTBEKernelStore(OmFileLoadHelper &om_load_helper) { ModelPartition partition_kernel_def; TBEKernelStore kernel_store; if (om_load_helper.GetModelPartition(ModelPartitionType::TBE_KERNELS, partition_kernel_def) == SUCCESS) { - GELOGI("Kernels partition size:%u", partition_kernel_def.size); + GELOGD("Kernels partition size:%u", partition_kernel_def.size); if (kernel_store.Load(partition_kernel_def.data, partition_kernel_def.size)) { - GELOGI("Load tbe kernels success"); + GELOGD("Load tbe kernels success"); } else { GELOGW("Load tbe kernels failed"); } @@ -415,11 +414,9 @@ Status ModelHelper::LoadCustAICPUKernelStore(OmFileLoadHelper &om_load_helper) { ModelPartition partition_kernel_def; CustAICPUKernelStore kernel_store; if (om_load_helper.GetModelPartition(ModelPartitionType::CUST_AICPU_KERNELS, partition_kernel_def) == SUCCESS) { - GELOGI("Kernels partition size:%u", partition_kernel_def.size); + GELOGD("Kernels partition size:%u", partition_kernel_def.size); if (kernel_store.Load(partition_kernel_def.data, partition_kernel_def.size)) { GELOGI("Load cust aicpu kernels success"); - } else { - GELOGW("Load cust aicpu kernels failed"); } } model_->SetCustAICPUKernelStore(kernel_store); diff --git a/src/ge/common/helper/om_file_helper.cc b/src/ge/common/helper/om_file_helper.cc index ca506731..485849b2 100644 --- a/src/ge/common/helper/om_file_helper.cc +++ b/src/ge/common/helper/om_file_helper.cc @@ -110,8 +110,8 @@ Status OmFileLoadHelper::CheckModelValid(const ge::ModelData &model) const { Status OmFileLoadHelper::LoadModelPartitionTable(uint8_t *model_data, const uint32_t model_data_size) { if (model_data == nullptr) { - GELOGE(PARAM_INVALID, "Param model_data must not be null!"); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID, "Param model_data must not be null!"); + return ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID; } // Init partition table auto partition_table = reinterpret_cast(model_data); @@ -119,16 +119,16 @@ Status OmFileLoadHelper::LoadModelPartitionTable(uint8_t *model_data, const uint // Original model partition include graph-info if ((partition_table->num != PARTITION_SIZE) && (partition_table->num != (PARTITION_SIZE - 1)) && (partition_table->num != (PARTITION_SIZE - kOptionalNum)) && (partition_table->num != 1)) { - GELOGE(GE_EXEC_MODEL_PARTITION_NUM_INVALID, "Invalid partition_table->num:%u", partition_table->num); - return GE_EXEC_MODEL_PARTITION_NUM_INVALID; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_PARTITION_NUM_INVALID, "Invalid partition_table->num:%u", partition_table->num); + return ACL_ERROR_GE_EXEC_MODEL_PARTITION_NUM_INVALID; } size_t mem_offset = SIZE_OF_MODEL_PARTITION_TABLE(*partition_table); - GELOGI("ModelPartitionTable num :%u, ModelFileHeader length :%zu, ModelPartitionTable length :%zu", + GELOGD("ModelPartitionTable num :%u, ModelFileHeader length :%zu, ModelPartitionTable length :%zu", partition_table->num, sizeof(ModelFileHeader), mem_offset); if (model_data_size <= mem_offset) { - GELOGE(GE_EXEC_MODEL_DATA_SIZE_INVALID, "invalid model data, partition_table->num:%u, model data size %u", + GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "invalid model data, partition_table->num:%u, model data size %u", partition_table->num, model_data_size); - return GE_EXEC_MODEL_DATA_SIZE_INVALID; + return ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID; } for (uint32_t i = 0; i < partition_table->num; i++) { ModelPartition partition; @@ -138,12 +138,13 @@ Status OmFileLoadHelper::LoadModelPartitionTable(uint8_t *model_data, const uint context_.partition_datas_.push_back(partition); if (partition.size > model_data_size || mem_offset > model_data_size - partition.size) { - GELOGE(GE_EXEC_MODEL_DATA_SIZE_INVALID, "The partition size %zu is greater than the model data size %u.", - partition.size + mem_offset, model_data_size); - return GE_EXEC_MODEL_DATA_SIZE_INVALID; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, + "The partition size %zu is greater than the model data size %u.", partition.size + mem_offset, + model_data_size); + return ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID; } mem_offset += partition.size; - GELOGI("Partition, type:%d, size:%u", static_cast(partition.type), partition.size); + GELOGD("Partition, type:%d, size:%u", static_cast(partition.type), partition.size); } return SUCCESS; } @@ -167,7 +168,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelPartitionTable *OmFileSave ModelPartition partition = context_.partition_datas_[i]; partition_table->partition[i] = {partition.type, mem_offset, partition.size}; mem_offset += partition.size; - GELOGI("Partition, type:%d, size:%u", static_cast(partition.type), partition.size); + GELOGD("Partition, type:%d, size:%u", static_cast(partition.type), partition.size); } return partition_table; } @@ -191,7 +192,7 @@ Status OmFileSaveHelper::SaveModel(const SaveParam &save_param, const char *outp (void)save_param.pri_key_file; Status ret = SaveModelToFile(output_file, model, is_offline); if (ret == SUCCESS) { - GELOGI("Generate model with encrypt."); + GELOGD("Generate model with encrypt."); } return ret; } @@ -213,7 +214,7 @@ Status OmFileSaveHelper::SaveModelToFile(const char *output_file, ModelBufferDat FMK_UINT32_ADDCHECK(size_of_table, model_data_len) model_header_.length = size_of_table + model_data_len; - GELOGI("Sizeof(ModelFileHeader):%zu,sizeof(ModelPartitionTable):%u, model_data_len:%u, model_total_len:%zu", + GELOGD("Sizeof(ModelFileHeader):%zu,sizeof(ModelPartitionTable):%u, model_data_len:%u, model_total_len:%zu", sizeof(ModelFileHeader), size_of_table, model_data_len, model_header_.length + sizeof(ModelFileHeader)); std::vector partition_datas = context_.partition_datas_; @@ -224,7 +225,7 @@ Status OmFileSaveHelper::SaveModelToFile(const char *output_file, ModelBufferDat ret = FileSaver::SaveToBuffWithFileHeader(model_header_, *partition_table, partition_datas, model); } if (ret == SUCCESS) { - GELOGI("Save model success without encrypt."); + GELOGD("Save model success without encrypt."); } return ret; #else diff --git a/src/ge/common/kernel_store.cc b/src/ge/common/kernel_store.cc index e465d184..e7773fa6 100644 --- a/src/ge/common/kernel_store.cc +++ b/src/ge/common/kernel_store.cc @@ -51,7 +51,7 @@ bool KernelStore::Build() { kernel_head.name_len = static_cast(kernel->GetName().length()); kernel_head.bin_len = static_cast(kernel->GetBinDataSize()); - GELOGI("get kernel bin name %s, addr %p, size %u", kernel->GetName().c_str(), kernel->GetBinData(), + GELOGD("get kernel bin name %s, addr %p, size %u", kernel->GetName().c_str(), kernel->GetBinData(), kernel->GetBinDataSize()); mem_ret = memcpy_s(next_buffer, remain_len, &kernel_head, sizeof(kernel_head)); GE_CHK_BOOL_EXEC_NOLOG(mem_ret == EOK, return false); @@ -95,7 +95,7 @@ bool KernelStore::Load(const uint8_t *data, const size_t &len) { std::string name(next_buffer, kernel_head->name_len); next_buffer += kernel_head->name_len; - GELOGI("Load kernel from om:%s,%u,%u", name.c_str(), kernel_head->name_len, kernel_head->bin_len); + GELOGD("Load kernel from om:%s,%u,%u", name.c_str(), kernel_head->name_len, kernel_head->bin_len); std::vector kernel_bin(next_buffer, next_buffer + kernel_head->bin_len); KernelBinPtr teb_kernel_ptr = ge::MakeShared(name, std::move(kernel_bin)); if (teb_kernel_ptr != nullptr) { diff --git a/src/ge/common/model_parser/base.cc b/src/ge/common/model_parser/base.cc index 3b6b9407..73dabf2e 100644 --- a/src/ge/common/model_parser/base.cc +++ b/src/ge/common/model_parser/base.cc @@ -17,7 +17,6 @@ #include "common/model_parser/base.h" #include "common/helper/model_helper.h" #include -#include #include #include #include @@ -36,15 +35,19 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelParserBase::LoadFro std::string real_path = RealPath(model_path); if (real_path.empty()) { GELOGE(GE_EXEC_MODEL_PATH_INVALID, "Model file path '%s' is invalid", model_path); - return GE_EXEC_MODEL_PATH_INVALID; + return ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID; } - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(GetFileLength(model_path) == -1, return GE_EXEC_READ_MODEL_FILE_FAILED, - "File size not valid."); + if (GetFileLength(model_path) == -1) { + GELOGE(ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID, "File size not valid, file: %s.", model_path); + return ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID; + } std::ifstream fs(real_path.c_str(), std::ifstream::binary); - - GE_CHK_BOOL_RET_STATUS(fs.is_open(), GE_EXEC_READ_MODEL_FILE_FAILED, "Open file failed! path:%s", model_path); + if (!fs.is_open()) { + GELOGE(ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID, "Open file: %s failed, error: %s", model_path, strerror(errno)); + return ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID; + } // get length of file: (void)fs.seekg(0, std::ifstream::end); @@ -56,8 +59,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelParserBase::LoadFro char *data = new (std::nothrow) char[len]; if (data == nullptr) { - GELOGE(MEMALLOC_FAILED, "Load model From file failed, bad memory allocation occur. (need:%u)", len); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Load model From file failed, bad memory allocation occur. (need:%u)", len); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } // read data as a block: @@ -80,7 +83,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelParserBase::ParseMo GE_CHECK_NOTNULL(model.model_data); // Model length too small - GE_CHK_BOOL_RET_STATUS(model.model_len >= sizeof(ModelFileHeader), GE_EXEC_MODEL_DATA_SIZE_INVALID, + GE_CHK_BOOL_RET_STATUS(model.model_len >= sizeof(ModelFileHeader), ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "Invalid model. Model data size %u must be greater than or equal to %zu.", model.model_len, sizeof(ModelFileHeader)); // Get file header @@ -88,7 +91,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelParserBase::ParseMo // Determine whether the file length and magic number match GE_CHK_BOOL_RET_STATUS( file_header->length == model.model_len - sizeof(ModelFileHeader) && file_header->magic == MODEL_FILE_MAGIC_NUM, - GE_EXEC_MODEL_DATA_SIZE_INVALID, + ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "Invalid model. file_header->length[%u] + sizeof(ModelFileHeader)[%zu] != model->model_len[%u] || " "MODEL_FILE_MAGIC_NUM[%u] != file_header->magic[%u]", file_header->length, sizeof(ModelFileHeader), model.model_len, MODEL_FILE_MAGIC_NUM, file_header->magic); @@ -98,15 +101,15 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelParserBase::ParseMo // Get data address uint8_t *data = reinterpret_cast(model.model_data) + sizeof(ModelFileHeader); if (file_header->is_encrypt == ModelEncryptType::UNENCRYPTED) { // Unencrypted model - GE_CHK_BOOL_RET_STATUS(model.key.empty(), GE_EXEC_MODEL_NOT_SUPPORT_ENCRYPTION, + GE_CHK_BOOL_RET_STATUS(model.key.empty(), ACL_ERROR_GE_EXEC_MODEL_NOT_SUPPORT_ENCRYPTION, "Invalid param. model is unencrypted, but key is not empty."); model_data = data; model_len = file_header->length; - GELOGI("Model_len is %u, model_file_head_len is %zu.", model_len, sizeof(ModelFileHeader)); + GELOGD("Model_len is %u, model_file_head_len is %zu.", model_len, sizeof(ModelFileHeader)); } else { - GELOGE(GE_EXEC_MODEL_NOT_SUPPORT_ENCRYPTION, "Invalid model. ModelEncryptType not supported."); - res = GE_EXEC_MODEL_NOT_SUPPORT_ENCRYPTION; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_NOT_SUPPORT_ENCRYPTION, "Invalid model. ModelEncryptType not supported."); + res = ACL_ERROR_GE_EXEC_MODEL_NOT_SUPPORT_ENCRYPTION; } return res; diff --git a/src/ge/common/model_saver.cc b/src/ge/common/model_saver.cc index 821fde60..3e916f12 100644 --- a/src/ge/common/model_saver.cc +++ b/src/ge/common/model_saver.cc @@ -16,9 +16,7 @@ #include "common/model_saver.h" -#include #include -#include #include #include #include @@ -51,14 +49,14 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelSaver::SaveJsonToFi return FAILED; } - char real_path[PATH_MAX] = {0}; - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(file_path) >= PATH_MAX, return FAILED, "file path is too long!"); - GE_IF_BOOL_EXEC(realpath(file_path, real_path) == nullptr, + char real_path[MMPA_MAX_PATH] = {0}; + GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(file_path) >= MMPA_MAX_PATH, return FAILED, "file path is too long!"); + GE_IF_BOOL_EXEC(mmRealPath(file_path, real_path, MMPA_MAX_PATH) != EN_OK, GELOGI("File %s does not exit, it will be created.", file_path)); // Open file - mode_t mode = S_IRUSR | S_IWUSR; - int32_t fd = mmOpen2(real_path, O_RDWR | O_CREAT | O_TRUNC, mode); + mmMode_t mode = M_IRUSR | M_IWUSR; + int32_t fd = mmOpen2(real_path, M_RDWR | M_CREAT | O_TRUNC, mode); if (fd == EN_ERROR || fd == EN_INVALID_PARAM) { ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {file_path, strerror(errno)}); GELOGE(FAILED, "Open file[%s] failed. %s", file_path, strerror(errno)); @@ -71,7 +69,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelSaver::SaveJsonToFi if (mmpa_ret == EN_ERROR || mmpa_ret == EN_INVALID_PARAM) { ErrorManager::GetInstance().ATCReportErrMessage("E19004", {"file", "errmsg"}, {file_path, strerror(errno)}); // Need to both print the error info of mmWrite and mmClose, so return ret after mmClose - GELOGE(FAILED, "Write to file failed. errno = %d, %s", mmpa_ret, strerror(errno)); + GELOGE(FAILED, "Write to file failed. errno = %ld, %s", mmpa_ret, strerror(errno)); ret = FAILED; } // Close file diff --git a/src/ge/common/profiling/profiling_manager.cc b/src/ge/common/profiling/profiling_manager.cc index dfdb1196..463348f1 100644 --- a/src/ge/common/profiling/profiling_manager.cc +++ b/src/ge/common/profiling/profiling_manager.cc @@ -212,8 +212,12 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::Pa FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::InitFromOptions(const Options &options) { #ifdef DAVINCI_SUPPORT_PROFILING // enable profiling support two ways: env and front end - const char *profiling_mode = std::getenv("PROFILING_MODE"); - const char *prof_options = std::getenv("PROFILING_OPTIONS"); + char profiling_mode_temp[MMPA_MAX_PATH] = {0x00}; + char prof_options_temp[MMPA_MAX_PATH] = {0x00}; + (void)mmGetEnv("PROFILING_MODE", profiling_mode_temp, MMPA_MAX_PATH); + (void)mmGetEnv("PROFILING_OPTIONS", prof_options_temp, MMPA_MAX_PATH); + const char *profiling_mode = profiling_mode_temp; + const char *prof_options = prof_options_temp; if ((profiling_mode == nullptr) || (strcmp("true", profiling_mode) != 0) || (prof_options == nullptr)) { is_load_profiling_ = false; is_execute_profiling_ = false; @@ -553,7 +557,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ReportPr GELOGE(rt_ret, "runtime get logic_device_id failed, current logic_device_id:%d", logic_device_id); return; } - GELOGI("current logic_device_id:%d", logic_device_id); + GELOGD("current logic_device_id:%d", logic_device_id); if (check_device) { auto ret = std::find(device_id_.begin(), device_id_.end(), logic_device_id); if (ret == device_id_.end()) { @@ -561,11 +565,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ReportPr return; } } - GELOGI("start ProfilingTaskDescInfo."); + GELOGD("start ProfilingTaskDescInfo."); ProfilingTaskDescInfo(model_id, task_desc_info, logic_device_id); - GELOGI("start ProfilingGraphDescInfo."); + GELOGD("start ProfilingGraphDescInfo."); ProfilingGraphDescInfo(model_id, compute_graph_desc_info, logic_device_id); - GELOGI("Report profiling data for GE end."); + GELOGD("Report profiling data for GE end."); #endif } @@ -844,7 +848,7 @@ ProfilingManager::ProfStartProfiling(uint64_t module, const std::map(device_list[i]); } - GELOGI("Runtime config param: 0x%llx, device num: %d.", module, device_num); + GELOGD("Runtime config param: 0x%llx, device num: %d.", module, device_num); rtError_t rt_ret = rtProfilerStart(module, device_num, device_id_ptr.get()); if (rt_ret != RT_ERROR_NONE) { @@ -863,7 +867,7 @@ ProfilingManager::ProfStartProfiling(uint64_t module, const std::map(device_list[i]); } - GELOGI("Prof stop: runtime config param: 0x%llx, device num: %d", module, device_num); + GELOGD("Prof stop: runtime config param: 0x%llx, device num: %d", module, device_num); rtError_t rt_ret = rtProfilerStop(module, device_num, device_id_ptr.get()); if (rt_ret != RT_ERROR_NONE) { GELOGE(FAILED, "Prof stop: runtime profiler config proc failed."); @@ -906,7 +910,7 @@ ProfilingManager::ProfStopProfiling(uint64_t module, const std::map #include - +#ifdef __GNUC__ #include -#include +#else +#include +#endif #include #include #include @@ -207,18 +208,18 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadBytesFromBinaryFile(co FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY int CreateDirectory(const std::string &directory_path) { GE_CHK_BOOL_EXEC(!directory_path.empty(), return -1, "directory path is empty."); auto dir_path_len = directory_path.length(); - if (dir_path_len >= PATH_MAX) { + if (dir_path_len >= MMPA_MAX_PATH) { ErrorManager::GetInstance().ATCReportErrMessage("E19002", {"filepath", "size"}, - {directory_path, std::to_string(PATH_MAX)}); - GELOGW("Path[%s] len is too long, it must be less than %d", directory_path.c_str(), PATH_MAX); + {directory_path, std::to_string(MMPA_MAX_PATH)}); + GELOGW("Path[%s] len is too long, it must be less than %d", directory_path.c_str(), MMPA_MAX_PATH); return -1; } - char tmp_dir_path[PATH_MAX] = {0}; + char tmp_dir_path[MMPA_MAX_PATH] = {0}; for (size_t i = 0; i < dir_path_len; i++) { tmp_dir_path[i] = directory_path[i]; if ((tmp_dir_path[i] == '\\') || (tmp_dir_path[i] == '/')) { - if (access(tmp_dir_path, F_OK) != 0) { - int32_t ret = mmMkdir(tmp_dir_path, S_IRUSR | S_IWUSR | S_IXUSR); // 700 + if (mmAccess2(tmp_dir_path, M_F_OK) != EN_OK) { + int32_t ret = mmMkdir(tmp_dir_path, M_IRUSR | M_IWUSR | M_IXUSR); // 700 if (ret != 0) { if (errno != EEXIST) { ErrorManager::GetInstance().ATCReportErrMessage("E19006", {"path"}, {directory_path}); @@ -229,7 +230,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY int CreateDirectory(const std:: } } } - int32_t ret = mmMkdir(const_cast(directory_path.c_str()), S_IRUSR | S_IWUSR | S_IXUSR); // 700 + int32_t ret = mmMkdir(const_cast(directory_path.c_str()), M_IRUSR | M_IWUSR | M_IXUSR); // 700 if (ret != 0) { if (errno != EEXIST) { ErrorManager::GetInstance().ATCReportErrMessage("E19006", {"path"}, {directory_path}); @@ -304,9 +305,9 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromMem(const cha } FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY uint64_t GetCurrentTimestamp() { - struct timeval tv {}; - int ret = gettimeofday(&tv, nullptr); - GE_LOGE_IF(ret != 0, "Func gettimeofday may failed: ret=%d", ret); + mmTimeval tv{}; + int ret = mmGetTimeOfDay(&tv, nullptr); + GE_LOGE_IF(ret != EN_OK, "Func gettimeofday may failed: ret=%d", ret); auto total_use_time = tv.tv_usec + tv.tv_sec * 1000000; // 1000000: seconds to microseconds return static_cast(total_use_time); } @@ -346,16 +347,16 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInt64MulOverflow(int6 FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY std::string RealPath(const char *path) { GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path == nullptr, return "", "path pointer is NULL."); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - strlen(path) >= PATH_MAX, - ErrorManager::GetInstance().ATCReportErrMessage("E19002", {"filepath", "size"}, {path, std::to_string(PATH_MAX)}); - return "", "Path[%s] len is too long, it must be less than %d", path, PATH_MAX); + GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(path) >= MMPA_MAX_PATH, + ErrorManager::GetInstance().ATCReportErrMessage("E19002", {"filepath", "size"}, + {path, std::to_string(MMPA_MAX_PATH)}); + return "", "Path[%s] len is too long, it must be less than %d", path, MMPA_MAX_PATH); // Nullptr is returned when the path does not exist or there is no permission // Return absolute path when path is accessible std::string res; - char resolved_path[PATH_MAX] = {0}; - if (realpath(path, resolved_path) != nullptr) { + char resolved_path[MMPA_MAX_PATH] = {0}; + if (mmRealPath(path, resolved_path, MMPA_MAX_PATH) == EN_OK) { res = resolved_path; } @@ -382,7 +383,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInputPathValid(const // A regular matching expression to verify the validity of the input file path // Path section: Support upper and lower case letters, numbers dots(.) chinese and underscores // File name section: Support upper and lower case letters, numbers, underscores chinese and dots(.) +#ifdef __GNUC__ std::string mode = "^[\u4e00-\u9fa5A-Za-z0-9./_-]+$"; +#else + std::string mode = "^[a-zA-Z]:([\\\\/][^\\s\\\\/:*?<>\"|][^\\\\/:*?<>\"|]*)*([/\\\\][^\\s\\\\/:*?<>\"|])?$"; +#endif GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( !ValidateStr(real_path, mode), @@ -391,7 +396,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInputPathValid(const return false, "Invalid value for %s[%s], %s.", atc_param.c_str(), real_path.c_str(), kPathValidReason); // The absolute path points to a file that is not readable - if (access(real_path.c_str(), R_OK) != 0) { + if (mmAccess2(real_path.c_str(), M_R_OK) != EN_OK) { ErrorManager::GetInstance().ATCReportErrMessage("E19003", {"file", "errmsg"}, {file_path.c_str(), strerror(errno)}); GELOGW("Read file[%s] failed, errmsg[%s]", file_path.c_str(), strerror(errno)); return false; @@ -409,15 +414,20 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const return false; } - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( - strlen(file_path.c_str()) >= PATH_MAX, ErrorManager::GetInstance().ATCReportErrMessage( - "E19002", {"filepath", "size"}, {file_path, std::to_string(PATH_MAX)}); - return "", "Path[%s] len is too long, it must be less than %d", file_path.c_str(), PATH_MAX); + GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(file_path.c_str()) >= MMPA_MAX_PATH, + ErrorManager::GetInstance().ATCReportErrMessage( + "E19002", {"filepath", "size"}, {file_path, std::to_string(MMPA_MAX_PATH)}); + return "", "Path[%s] len is too long, it must be less than %d", file_path.c_str(), + MMPA_MAX_PATH); // A regular matching expression to verify the validity of the input file path // Path section: Support upper and lower case letters, numbers dots(.) chinese and underscores // File name section: Support upper and lower case letters, numbers, underscores chinese and dots(.) +#ifdef __GNUC__ std::string mode = "^[\u4e00-\u9fa5A-Za-z0-9./_-]+$"; +#else + std::string mode = "^[a-zA-Z]:([\\\\/][^\\s\\\\/:*?<>\"|][^\\\\/:*?<>\"|]*)*([/\\\\][^\\s\\\\/:*?<>\"|])?$"; +#endif GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( !ValidateStr(file_path, mode), @@ -429,7 +439,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const // Can get absolute path (file exists) if (!real_path.empty()) { // File is not readable or writable - if (access(real_path.c_str(), W_OK | F_OK) != 0) { + if (mmAccess2(real_path.c_str(), M_W_OK | M_F_OK) != EN_OK) { ErrorManager::GetInstance().ATCReportErrMessage("E19004", {"file", "errmsg"}, {real_path, strerror(errno)}); GELOGW("Write file[%s] failed, errmsg[%s]", real_path.c_str(), strerror(errno)); return false; @@ -460,6 +470,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const } FMK_FUNC_HOST_VISIBILITY bool ValidateStr(const std::string &str, const std::string &mode) { +#ifdef __GNUC__ char ebuff[kMaxBuffSize]; regex_t reg; int cflags = REG_EXTENDED | REG_NOSUB; @@ -481,6 +492,23 @@ FMK_FUNC_HOST_VISIBILITY bool ValidateStr(const std::string &str, const std::str regfree(®); return true; +#else + std::wstring wstr(str.begin(), str.end()); + std::wstring wmode(mode.begin(), mode.end()); + std::wsmatch match; + bool res = false; + + try { + std::wregex reg(wmode, std::regex::icase); + // Matching string part + res = regex_match(wstr, match, reg); + res = regex_search(str, std::regex("[`!@#$%^&*()|{}';',<>?]")); + } catch (std::exception &ex) { + GELOGW("The directory %s is invalid, error: %s.", str.c_str(), ex.what()); + return false; + } + return !(res) && (str.size() == match.str().size()); +#endif } FMK_FUNC_HOST_VISIBILITY bool IsValidFile(const char *file_path) { diff --git a/src/ge/engine_manager/dnnengine_manager.cc b/src/ge/engine_manager/dnnengine_manager.cc index 0c1ba4e3..597b2776 100644 --- a/src/ge/engine_manager/dnnengine_manager.cc +++ b/src/ge/engine_manager/dnnengine_manager.cc @@ -434,7 +434,7 @@ Status DNNEngineManager::ReadJsonFile(const std::string &file_path, JsonHandle h return FAILED; } const char *file = file_path.data(); - if ((access(file, F_OK)) == -1) { + if ((mmAccess2(file, M_F_OK)) != EN_OK) { if (engines_map_.size() != 0) { GELOGE(FAILED, "The json file %s is not exist, %s", file_path.c_str(), strerror(errno)); return FAILED; diff --git a/src/ge/executor/CMakeLists.txt b/src/ge/executor/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/src/ge/executor/ge_executor.cc b/src/ge/executor/ge_executor.cc index b1675f52..dcbde49c 100644 --- a/src/ge/executor/ge_executor.cc +++ b/src/ge/executor/ge_executor.cc @@ -50,19 +50,6 @@ const size_t kDynamicImageSizeVecSize = 2; const size_t kDynamicImageSizeInputSize = 2; const char *const kBatchLabel = "Batch_"; -ge::Status TransferDomiErrorCode(const uint32_t errorCode) { - switch (errorCode) { - case ge::PARAM_INVALID: - case domi::PARAM_INVALID: - return ge::PARAM_INVALID; - case ge::INTERNAL_ERROR: - case domi::INTERNAL_ERROR: - return ge::INTERNAL_ERROR; - default: - return ge::FAILED; - } -} - void GetGeTensorDescFromDomiInfo(std::vector &ge_descs, const std::vector &domi_descs, const std::vector &formats) { @@ -79,6 +66,7 @@ void GetGeTensorDescFromDomiInfo(std::vector &ge_descs, ge::Shape ge_shape(shape_dims); ge_desc.SetShape(ge_shape); ge_desc.SetSize(desc_item.size); + ge_desc.SetShapeRange(desc_item.shape_info.shape_ranges); ge_descs.emplace_back(ge_desc); ++idx; } @@ -285,14 +273,14 @@ Status GeExecutor::Finalize() { Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length, uint64_t batch_size) { if (dynamic_input_addr == nullptr) { - GELOGE(PARAM_INVALID, "Dynamic input addr is nullptr!"); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, "Dynamic input addr is nullptr!"); + return ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID; } uint64_t size = sizeof(uint32_t); if (length < size) { - GELOGE(PARAM_INVALID, "Dynamic input size [%lu] is less than [%lu]!", length, size); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, "Dynamic input size [%lu] is less than [%lu]!", length, size); + return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } if (length >= sizeof(uint64_t)) { size = sizeof(uint64_t); @@ -309,8 +297,8 @@ Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_ad } if (!IsDynamicBatchSizeMatchModel(batch_size, batch_info)) { - GELOGE(PARAM_INVALID, "The current dynamic input does not match the gear of the model."); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, "The current dynamic input does not match the gear of the model."); + return ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID; } ret = GraphExecutor::SetDynamicSize(model_id, batch_num, static_cast(DYNAMIC_BATCH)); @@ -321,7 +309,7 @@ Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_ad // memcpy dynamic_batch_size from host to device rtError_t rt_ret = rtMemcpy(dynamic_input_addr, length, &batch_size, size, RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "memcpy dynamic batch input data failed! ret: 0x%X", rt_ret); + GELOGE(rt_ret, "memcpy dynamic batch input data failed! ret: 0x%X", rt_ret); return RT_ERROR_TO_GE_STATUS(rt_ret); } return SUCCESS; @@ -330,14 +318,15 @@ Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_ad Status GeExecutor::SetDynamicImageSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length, uint64_t image_height, uint64_t image_width) { if (dynamic_input_addr == nullptr) { - GELOGE(PARAM_INVALID, "Dynamic input addr is nullptr!"); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, "Dynamic input addr is nullptr!"); + return ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID; } uint64_t dynamic_input_size = kDynamicImageSizeInputSize * sizeof(uint32_t); if (length < dynamic_input_size) { - GELOGE(PARAM_INVALID, "Dynamic input size [%lu] is less than [%lu]!", length, dynamic_input_size); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, "Dynamic input size [%lu] is less than [%lu]!", length, + dynamic_input_size); + return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } uint64_t size = sizeof(uint32_t); if (length >= kDynamicImageSizeInputSize * sizeof(uint64_t)) { @@ -354,8 +343,8 @@ Status GeExecutor::SetDynamicImageSize(uint32_t model_id, void *dynamic_input_ad } if (!IsDynamicImageSizeMatchModel(image_height, image_width, batch_info)) { - GELOGE(PARAM_INVALID, "The current dynamic input does not match the gear of the model."); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, "The current dynamic input does not match the gear of the model."); + return ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID; } ret = GraphExecutor::SetDynamicSize(model_id, batch_num, static_cast(DYNAMIC_IMAGE)); @@ -367,16 +356,17 @@ Status GeExecutor::SetDynamicImageSize(uint32_t model_id, void *dynamic_input_ad // Memcpy dynamic resolution height from host to device rtError_t rt_ret = rtMemcpy(dynamic_input_addr, size, &image_height, size, RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "memcpy dynamic resolution input data failed! ret: 0x%X", rt_ret); + GELOGE(rt_ret, "memcpy dynamic resolution input data failed! ret: 0x%X", rt_ret); return RT_ERROR_TO_GE_STATUS(rt_ret); } uint64_t remain_size = length - size; // Memcpy dynamic resolution width from host to device - if (rtMemcpy(reinterpret_cast(reinterpret_cast(dynamic_input_addr) + size), remain_size, - &image_width, size, RT_MEMCPY_HOST_TO_DEVICE) != RT_ERROR_NONE) { - GELOGE(FAILED, "memcpy dynamic resolution input data failed!"); - return FAILED; + rt_ret = rtMemcpy(reinterpret_cast(reinterpret_cast(dynamic_input_addr) + size), remain_size, + &image_width, size, RT_MEMCPY_HOST_TO_DEVICE); + if (rt_ret != RT_ERROR_NONE) { + GELOGE(rt_ret, "memcpy dynamic resolution input data failed!"); + return RT_ERROR_TO_GE_STATUS(rt_ret); } return SUCCESS; } @@ -384,15 +374,15 @@ Status GeExecutor::SetDynamicImageSize(uint32_t model_id, void *dynamic_input_ad Status GeExecutor::SetDynamicDims(uint32_t model_id, void *dynamic_input_addr, uint64_t length, const vector &dynamic_dims) { if (dynamic_input_addr == nullptr) { - GELOGE(FAILED, "Dynamic input addr is nullptr!"); - return FAILED; + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, "Dynamic input addr is nullptr!"); + return ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID; } vector cur_dynamic_dims; Status ret = GetCurDynamicDims(model_id, dynamic_dims, cur_dynamic_dims); if (ret != SUCCESS) { - GELOGE(FAILED, "Set cur gear dynamic dims failed"); - return FAILED; + GELOGE(ret, "Set cur gear dynamic dims failed"); + return ret; } std::vector> batch_info; int32_t dynamic_type = static_cast(FIXED); @@ -403,32 +393,35 @@ Status GeExecutor::SetDynamicDims(uint32_t model_id, void *dynamic_input_addr, u } if (!IsDynmaicDimsSizeMatchModel(cur_dynamic_dims, batch_info)) { - GELOGE(PARAM_INVALID, "The current dynamic input does not match the gear of the model."); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID, "The current dynamic input does not match the gear of the model."); + return ACL_ERROR_GE_DYNAMIC_BATCH_SIZE_INVALID; } ret = GraphExecutor::SetDynamicSize(model_id, cur_dynamic_dims, static_cast(DYNAMIC_DIMS)); if (ret != SUCCESS) { - GELOGE(FAILED, "Set dynamic size failed"); - return FAILED; + GELOGE(ret, "Set dynamic size failed"); + return ret; } size_t dynamic_dim_num = cur_dynamic_dims.size(); uint64_t dynamic_input_size = static_cast(dynamic_dim_num * sizeof(uint32_t)); if (length < dynamic_input_size) { - GELOGE(FAILED, "Dynamic input size [%lu] is less than [%lu]!", length, dynamic_input_size); - return FAILED; + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, "Dynamic input size [%lu] is less than [%lu]!", length, + dynamic_input_size); + return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } uint64_t size = sizeof(uint32_t); if (length >= dynamic_dim_num * sizeof(uint64_t)) { size = sizeof(uint64_t); } + rtError_t rt_ret; for (uint32_t i = 0; i < dynamic_dim_num; ++i) { // Memcpy dynamic dim[i] from host to device - if (rtMemcpy(reinterpret_cast(reinterpret_cast(dynamic_input_addr) + size * i), - length - size * i, &cur_dynamic_dims[i], size, RT_MEMCPY_HOST_TO_DEVICE) != RT_ERROR_NONE) { - GELOGE(FAILED, "memcpy dynamic resolution input data failed!"); - return FAILED; + rt_ret = rtMemcpy(reinterpret_cast(reinterpret_cast(dynamic_input_addr) + size * i), + length - size * i, &cur_dynamic_dims[i], size, RT_MEMCPY_HOST_TO_DEVICE); + if (rt_ret != RT_ERROR_NONE) { + GELOGE(rt_ret, "memcpy dynamic resolution input data failed!"); + return RT_ERROR_TO_GE_STATUS(rt_ret); } } return SUCCESS; @@ -441,15 +434,15 @@ Status GeExecutor::GetCurDynamicDims(uint32_t model_id, const vector & vector output_desc; auto ret = GetModelDescInfo(model_id, input_desc, output_desc); if (ret != ge::SUCCESS) { - GELOGE(FAILED, "GetModelDescInfo failed."); - return FAILED; + GELOGE(ret, "GetModelDescInfo failed."); + return ret; } vector user_designate_shape_order; vector all_data_dims; ret = GetUserDesignateShapeOrder(model_id, user_designate_shape_order); if (ret != ge::SUCCESS) { - GELOGE(FAILED, "GetUserDesignateShapeOrder failed."); - return FAILED; + GELOGE(ret, "GetUserDesignateShapeOrder failed."); + return ret; } for (auto &data_name : user_designate_shape_order) { for (auto &desc : input_desc) { @@ -462,17 +455,18 @@ Status GeExecutor::GetCurDynamicDims(uint32_t model_id, const vector & } } if (dynamic_dims.size() != all_data_dims.size()) { - GELOGE(FAILED, "Dynamic input size [%lu] is not equal with all data dims size [%lu]!", dynamic_dims.size(), + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, + "Dynamic input size [%lu] is not equal with all data dims size [%lu]!", dynamic_dims.size(), all_data_dims.size()); - return FAILED; + return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } for (std::size_t i = 0; i < all_data_dims.size(); ++i) { if (all_data_dims[i] < 0) { cur_dynamic_dims.push_back(dynamic_dims[i]); } else if (static_cast(all_data_dims[i]) != dynamic_dims[i]) { - GELOGE(PARAM_INVALID, "Static dims should be same, index: %zu value: %d should be %d", i, dynamic_dims[i], - all_data_dims[i]); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, "Static dims should be same, index: %zu value: %d should be %d", + i, dynamic_dims[i], all_data_dims[i]); + return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } } return SUCCESS; @@ -481,8 +475,8 @@ Status GeExecutor::GetCurDynamicDims(uint32_t model_id, const vector & Status GeExecutor::GetCurShape(const uint32_t model_id, std::vector &batch_info, int32_t &dynamic_type) { GELOGI("Begin to get current shape"); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetCurShape(model_id, batch_info, dynamic_type); if (ret != SUCCESS) { @@ -497,12 +491,12 @@ Status GeExecutor::SetDynamicAippData(uint32_t model_id, void *dynamic_input_add const kAippDynamicPara &aippParms) { GELOGI("Enter to SetDynamicAippData."); if (dynamic_input_addr == nullptr) { - GELOGE(PARAM_INVALID, "Dynamic aipp input addr is nullptr!"); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID, "Dynamic aipp input addr is nullptr!"); + return ACL_ERROR_GE_DYNAMIC_INPUT_ADDR_INVALID; } if (aippBatchPara.empty()) { - GELOGE(PARAM_INVALID, "aippBatchPara is empty."); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_AIPP_BATCH_EMPTY, "aippBatchPara is empty."); + return ACL_ERROR_GE_AIPP_BATCH_EMPTY; } uint64_t batch_num = aippBatchPara.size(); uint64_t real_aippParms_size = sizeof(kAippDynamicPara) - sizeof(kAippDynamicBatchPara); @@ -512,13 +506,14 @@ Status GeExecutor::SetDynamicAippData(uint32_t model_id, void *dynamic_input_add "batch num is %lu, struct_len is %lu", model_id, length, batch_num, struct_len); if (struct_len > length) { - GELOGE(PARAM_INVALID, "input dynamic aipp param len [%lu] is larger than aipp_data size [%lu]", struct_len, length); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, + "input dynamic aipp param len [%lu] is larger than aipp_data size [%lu]", struct_len, length); + return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; } // Memcpy real kAippDynamicBatchPara from host to device rtError_t rt_ret = rtMemcpy(dynamic_input_addr, length, &aippParms, real_aippParms_size, RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "memcpy real_aippParms_size failed! ret: 0x%X", rt_ret); + GELOGE(rt_ret, "memcpy real_aippParms_size failed! ret: 0x%X", rt_ret); return RT_ERROR_TO_GE_STATUS(rt_ret); } uint64_t remain_len = length - real_aippParms_size; @@ -529,7 +524,7 @@ Status GeExecutor::SetDynamicAippData(uint32_t model_id, void *dynamic_input_add (remain_len - i * sizeof(kAippDynamicBatchPara)), &(aippBatchPara[i]), sizeof(kAippDynamicBatchPara), RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "memcpy kAippDynamicBatchPara input data failed! ret: 0x%X", rt_ret); + GELOGE(rt_ret, "memcpy kAippDynamicBatchPara input data failed! ret: 0x%X", rt_ret); return RT_ERROR_TO_GE_STATUS(rt_ret); } } @@ -541,27 +536,28 @@ Status GeExecutor::LoadModelOffline(uint32_t &model_id, const std::string &path, int32_t priority, std::shared_ptr listener) { GELOGI("load model offline begin."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } string filePath = RealPath(path.c_str()); if (filePath.empty()) { - GELOGE(ge::FAILED, "File path is invalid. please check your text file '%s'.", path.c_str()); - return ge::FAILED; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID, "File path is invalid. please check your text file '%s'.", + path.c_str()); + return ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID; } std::shared_ptr listener_adapter = MakeShared(); if (listener_adapter == nullptr) { - GELOGE(MEMALLOC_FAILED, "ModelListenerAdapter make shared failed!"); - return ge::FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "ModelListenerAdapter make shared failed!"); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } listener_adapter->listener = listener; Status ret = GraphLoader::LoadModelFromFile(path, key, priority, listener_adapter, model_id); if (ret != SUCCESS) { GELOGE(ret, "[GeExecutor] LoadModelFromFile failed"); - return TransferDomiErrorCode(ret); + return ACL_ERROR_GE_LOAD_MODEL; } return SUCCESS; } @@ -570,35 +566,35 @@ Status GeExecutor::LoadModel(uint32_t &model_id, const ModelData &model_data, std::shared_ptr listener) { GELOGI("Load model begin."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } std::shared_ptr listener_adapter = MakeShared(); if (listener_adapter == nullptr) { - GELOGE(MEMALLOC_FAILED, "ModelListenerAdapter make shared failed!"); - return ge::FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "ModelListenerAdapter make shared failed!"); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } listener_adapter->listener = listener; Status ret = GraphLoader::LoadModel(model_data, listener_adapter, model_id); if (ret != SUCCESS) { GELOGE(ret, "[GeExecutor] LoadModel failed."); - return TransferDomiErrorCode(ret); + return ACL_ERROR_GE_LOAD_MODEL; } return ret; } Status GeExecutor::UnloadModel(uint32_t model_id) { - GELOGI("unload model %u begin.", model_id); + GELOGD("unload model %u begin.", model_id); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphLoader::DestroyAicpuSessionForInfer(model_id); if (ret != SUCCESS) { GELOGE(ret, "[GraphLoader] DestroyAicpuSessionForInfer failed. model id: %u", model_id); - return FAILED; + return ACL_ERROR_GE_INTERNAL_ERROR; } std::shared_ptr davinci_model = ModelManager::GetInstance()->GetModel(model_id); @@ -606,14 +602,19 @@ Status GeExecutor::UnloadModel(uint32_t model_id) { uint64_t session_id = davinci_model->GetSessionId(); VarManagerPool::Instance().RemoveVarManager(session_id); } - return GraphLoader::UnloadModel(model_id); + ret = GraphLoader::UnloadModel(model_id); + if (ret != SUCCESS) { + GELOGE(ret, "[GraphLoader] DestroyAicpuSessionForInfer failed. model id: %u", model_id); + return ACL_ERROR_GE_UNLOAD_MODEL; + } + return SUCCESS; } Status GeExecutor::RunModel(const ge::RunModelData &input_data, ge::RunModelData &output_data) { GELOGI("run model begin."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } InputData inputs; @@ -627,10 +628,9 @@ Status GeExecutor::RunModel(const ge::RunModelData &input_data, ge::RunModelData // Get input and output descriptor Status GeExecutor::GetModelDescInfo(uint32_t model_id, std::vector &input_desc, std::vector &output_desc, bool new_model_desc) { - GELOGI("get model desc info begin."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } std::vector input_desc_infos; @@ -642,26 +642,25 @@ Status GeExecutor::GetModelDescInfo(uint32_t model_id, std::vector> &batch_info, int32_t &dynamic_type) { - GELOGI("Begin to get dynamic batch info."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetDynamicBatchInfo(model_id, batch_info, dynamic_type); @@ -686,8 +684,6 @@ Status GeExecutor::GetDynamicBatchInfo(uint32_t model_id, std::vector> &batch_info) { GELOGI("Begin to get combined dynamic dims info."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetCombinedDynamicDims(model_id, batch_info); @@ -723,10 +719,9 @@ Status GeExecutor::GetCombinedDynamicDims(uint32_t model_id, vector &user_designate_shape_order) { - GELOGI("Begin to get user designate shape info."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetUserDesignateShapeOrder(model_id, user_designate_shape_order); @@ -735,7 +730,6 @@ Status GeExecutor::GetUserDesignateShapeOrder(uint32_t model_id, vector return ret; } - GELOGI("Get user designate shape order succ."); return SUCCESS; } @@ -750,8 +744,8 @@ Status GeExecutor::GetUserDesignateShapeOrder(uint32_t model_id, vector Status GeExecutor::GetAIPPInfo(uint32_t model_id, uint32_t index, AippConfigInfo &aipp_info) { GELOGI("Begin to GetAIPPInfo."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "not inited yet!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetAIPPInfo(model_id, index, aipp_info); if (ret != SUCCESS) { @@ -765,8 +759,8 @@ Status GeExecutor::GetAIPPInfo(uint32_t model_id, uint32_t index, AippConfigInfo Status GeExecutor::GetAippType(uint32_t model_id, uint32_t index, InputAippType &type, size_t &aipp_index) { GELOGI("Begin to get aipp type."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "not inited yet!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetAippType(model_id, index, type, aipp_index); if (ret != SUCCESS) { @@ -778,18 +772,15 @@ Status GeExecutor::GetAippType(uint32_t model_id, uint32_t index, InputAippType } Status GeExecutor::GetModelAttr(uint32_t model_id, std::vector &dynamic_output_shape_info) { - GELOGI("Begin to get dynamic batch output shape info"); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "not inited yet!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetModelAttr(model_id, dynamic_output_shape_info); if (ret != SUCCESS) { GELOGE(ret, "Get dynamic batch output shape info failed."); return ret; } - - GELOGI("Get dynamic batch output shape info succ."); return SUCCESS; } @@ -797,8 +788,8 @@ Status GeExecutor::GetModelDescInfoForZeroCopy(uint32_t model_id, std::vector &output_desc) { GELOGI("get model desc info for zero copy begin."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } std::vector input_desc_infos; @@ -810,17 +801,17 @@ Status GeExecutor::GetModelDescInfoForZeroCopy(uint32_t model_id, std::vector &output_queue_ids) { GELOGI("Load model with queue begin."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } return GraphLoader::LoadModelWithQ(model_id, model_data, input_queue_ids, output_queue_ids); } @@ -940,10 +929,9 @@ Status GeExecutor::LoadModelWithQ(uint32_t &model_id, const ModelData &model_dat */ Status GeExecutor::ExecModel(uint32_t model_id, void *stream, const ge::RunModelData &run_input_data, ge::RunModelData &run_output_data, bool async_mode) { - GELOGI("Execute model begin."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } InputData input_data; @@ -979,8 +967,8 @@ Status GeExecutor::ExecModel(uint32_t model_id, void *stream, const ge::RunModel Status GeExecutor::GetMemAndWeightSize(const std::string &path, size_t &mem_size, size_t &weight_size) { GELOGI("Get memory and weight size from file begin."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } ModelData model; @@ -1012,13 +1000,13 @@ Status GeExecutor::GetMemAndWeightSize(const void *model_data, size_t model_size size_t &weight_size) { GELOGI("Get memory and weight size from data begin."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } if (model_data == nullptr) { - GELOGE(PARAM_INVALID, "invalid model data!"); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID, "invalid model data!"); + return ACL_ERROR_GE_EXEC_MODEL_ADDR_INVALID; } ModelData model; @@ -1041,8 +1029,8 @@ Status GeExecutor::LoadDynamicSingleOp(const std::string &model_name, const ge:: Status GeExecutor::ExecuteAsync(SingleOp *executor, const std::vector &inputs, std::vector &outputs) { if (executor == nullptr) { - GELOGE(PARAM_INVALID, "param is NULL"); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "param is NULL"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } return executor->ExecuteAsync(inputs, outputs); @@ -1065,8 +1053,8 @@ Status GeExecutor::GetDeviceIdByModelId(uint32_t model_id, uint32_t &device_id) GE_CHECK_NOTNULL(model_manager); auto davinci_model = model_manager->GetModel(model_id); if (davinci_model == nullptr) { - GELOGE(FAILED, "Model id: %d is invaild or model is not loaded.", model_id); - return FAILED; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, "Model id: %d is invaild or model is not loaded.", model_id); + return ACL_ERROR_GE_EXEC_MODEL_ID_INVALID; } device_id = davinci_model->GetDeviceId(); @@ -1092,8 +1080,8 @@ Status GeExecutor::GetBatchInfoSize(uint32_t model_id, size_t &shape_count) { Status GeExecutor::GetOrigInputInfo(uint32_t model_id, uint32_t index, OriginInputInfo &orig_input_info) { GELOGI("Begin to GetOrigInputInfo."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "not inited yet!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetOrigInputInfo(model_id, index, orig_input_info); @@ -1111,8 +1099,8 @@ Status GeExecutor::GetAllAippInputOutputDims(uint32_t model_id, uint32_t index, std::vector &output_dims) { GELOGI("Begin to GetAllAippInputOutputDims."); if (!isInit_) { - GELOGE(GE_EXEC_NOT_INIT, "not inited yet!"); - return GE_EXEC_NOT_INIT; + GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); + return ACL_ERROR_GE_EXEC_NOT_INIT; } Status ret = GraphExecutor::GetAllAippInputOutputDims(model_id, index, input_dims, output_dims); diff --git a/src/ge/executor/module.mk b/src/ge/executor/module.mk index 4244ea92..4a0188be 100644 --- a/src/ge/executor/module.mk +++ b/src/ge/executor/module.mk @@ -63,6 +63,7 @@ local_ge_executor_src_files := \ ../single_op/task/aicpu_kernel_task_builder.cc \ ../hybrid/hybrid_davinci_model_stub.cc\ ../hybrid/node_executor/aicpu/aicpu_ext_info.cc \ + ../graph/common/local_context.cc \ local_ge_executor_c_include := \ proto/insert_op.proto \ @@ -104,7 +105,7 @@ local_ge_executor_ldflags := -lrt -ldl \ include $(CLEAR_VARS) LOCAL_MODULE := libge_executor -LOCAL_CFLAGS += -Werror +LOCAL_CFLAGS += -Werror -Wno-deprecated-declarations LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -O2 -DDAVINCI_SUPPORT_PROFILING -Dgoogle=ascend_private LOCAL_SRC_FILES := $(local_ge_executor_src_files) @@ -130,7 +131,7 @@ include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libge_executor -LOCAL_CFLAGS += -Werror +LOCAL_CFLAGS += -Werror -Wno-deprecated-declarations LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -DDAVINCI_SUPPORT_PROFILING -Dgoogle=ascend_private ifeq ($(DEBUG), 1) LOCAL_CFLAGS += -g -O0 @@ -166,7 +167,7 @@ include $(BUILD_HOST_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libge_executor -LOCAL_CFLAGS += -Werror +LOCAL_CFLAGS += -Werror -Wno-deprecated-declarations LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -DDAVINCI_SUPPORT_PROFILING -Dgoogle=ascend_private ifeq ($(DEBUG), 1) LOCAL_CFLAGS += -g -O0 @@ -199,7 +200,7 @@ include $(BUILD_HOST_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libge_executor -LOCAL_CFLAGS += -Werror +LOCAL_CFLAGS += -Werror -Wno-deprecated-declarations LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -DDAVINCI_SUPPORT_PROFILING -Dgoogle=ascend_private ifeq ($(DEBUG), 1) LOCAL_CFLAGS += -g -O0 diff --git a/src/ge/ge_inference.mk b/src/ge/ge_inference.mk index 3b1dba01..0987f148 100644 --- a/src/ge/ge_inference.mk +++ b/src/ge/ge_inference.mk @@ -387,12 +387,12 @@ LOCAL_SRC_FILES += $(BUILER_SRC_FILES) LOCAL_SRC_FILES += $(ANALYZER_SRC_FILES) LOCAL_STATIC_LIBRARIES := libge_memory \ + libmmpa \ LOCAL_SHARED_LIBRARIES := \ libc_sec \ libascend_protobuf \ libslog \ - libmmpa \ libgraph \ libregister \ libge_common \ @@ -451,12 +451,12 @@ LOCAL_C_INCLUDES := $(DEVICE_LOCAL_C_INCLUDES) LOCAL_C_INCLUDES += $(ANALYZER_LOCAL_INCLUDES) LOCAL_STATIC_LIBRARIES := libge_memory \ + libmmpa \ LOCAL_SHARED_LIBRARIES := \ libc_sec \ libascend_protobuf \ libslog \ - libmmpa \ libgraph \ libregister \ libresource \ diff --git a/src/ge/ge_local_engine/engine/host_cpu_engine.cc b/src/ge/ge_local_engine/engine/host_cpu_engine.cc index 2a3a9a61..c09ccead 100644 --- a/src/ge/ge_local_engine/engine/host_cpu_engine.cc +++ b/src/ge/ge_local_engine/engine/host_cpu_engine.cc @@ -200,9 +200,8 @@ Status HostCpuEngine::PrepareOutputs(const ge::ConstOpDescPtr &op_desc, vectorGetName().c_str(), ret); + GELOGW("Failed to compute host cpu op. node = %s", op_desc->GetName().c_str()); return FAILED; } op.BreakConnect(); diff --git a/src/ge/ge_local_engine/module.mk b/src/ge/ge_local_engine/module.mk index a3c571d9..c7a18721 100644 --- a/src/ge/ge_local_engine/module.mk +++ b/src/ge/ge_local_engine/module.mk @@ -88,6 +88,25 @@ LOCAL_C_INCLUDES := $(local_lib_inc_path) include ${BUILD_HOST_SHARED_LIBRARY} +#compiler for device libge_local_opskernel_builder.so +include $(CLEAR_VARS) +LOCAL_MODULE := libge_local_opskernel_builder +LOCAL_CFLAGS += -Werror +LOCAL_CFLAGS += -std=c++11 -Dgoogle=ascend_private +LOCAL_LDFLAGS := + +LOCAL_STATIC_LIBRARIES := +LOCAL_SHARED_LIBRARIES := libascend_protobuf \ + libc_sec \ + libslog \ + libregister \ + libgraph + +LOCAL_SRC_FILES := $(ops_kernel_builder_src_files) + +LOCAL_C_INCLUDES := $(local_lib_inc_path) + +include ${BUILD_SHARED_LIBRARY} #compiler for libge_local_opskernel_builder.so in atc include $(CLEAR_VARS) diff --git a/src/ge/ge_local_engine/ops_kernel_store/ge_local_ops_kernel_builder.cc b/src/ge/ge_local_engine/ops_kernel_store/ge_local_ops_kernel_builder.cc index ef59d71b..499bb254 100644 --- a/src/ge/ge_local_engine/ops_kernel_store/ge_local_ops_kernel_builder.cc +++ b/src/ge/ge_local_engine/ops_kernel_store/ge_local_ops_kernel_builder.cc @@ -105,7 +105,7 @@ Status GeLocalOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) { TypeUtils::DataTypeToSerialString(data_type).c_str(), output_mem_size); return FAILED; } - GELOGI( + GELOGD( "Calc op[%s:%s] out[%zu] mem size is %ld," " format=%s, data_type=%s.", node_name.c_str(), node_type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(), @@ -167,7 +167,7 @@ Status GeLocalOpsKernelBuilder::GenerateTask(const Node &node, RunContext &conte GELOGE(ret, "Node:%s(%s) op run failed.", name.c_str(), type.c_str()); return ret; } - GELOGI("Ge local generate task for node:%s(%s) end, tasks.size()=%zu.", name.c_str(), type.c_str(), tasks.size()); + GELOGD("Ge local generate task for node:%s(%s) end, tasks.size()=%zu.", name.c_str(), type.c_str(), tasks.size()); return ret; } } // namespace ge_local diff --git a/src/ge/ge_local_engine/ops_kernel_store/op/no_op.cc b/src/ge/ge_local_engine/ops_kernel_store/op/no_op.cc index 62fe1b5d..4d8d8bfb 100644 --- a/src/ge/ge_local_engine/ops_kernel_store/op/no_op.cc +++ b/src/ge/ge_local_engine/ops_kernel_store/op/no_op.cc @@ -24,7 +24,7 @@ namespace ge_local { NoOp::NoOp(const Node &node, RunContext &run_context) : Op(node, run_context) {} Status NoOp::Run() { - GELOGI("Node:%s type is %s, no need generate task.", name_.c_str(), type_.c_str()); + GELOGD("Node:%s type is %s, no need generate task.", name_.c_str(), type_.c_str()); // Do nothing return SUCCESS; } diff --git a/src/ge/ge_runner.mk b/src/ge/ge_runner.mk index c9be823f..a2679ed1 100644 --- a/src/ge/ge_runner.mk +++ b/src/ge/ge_runner.mk @@ -372,12 +372,12 @@ LOCAL_SRC_FILES += $(LIBCLIENT_LOCAL_SRC_FILES) LOCAL_STATIC_LIBRARIES := libge_memory \ libadump_server \ libmsprofiler \ + libmmpa \ LOCAL_SHARED_LIBRARIES := \ libc_sec \ libascend_protobuf \ libslog \ - libmmpa \ libgraph \ libregister \ libge_common \ diff --git a/src/ge/ge_runtime/runtime_model.cc b/src/ge/ge_runtime/runtime_model.cc index 9f549313..35342988 100644 --- a/src/ge/ge_runtime/runtime_model.cc +++ b/src/ge/ge_runtime/runtime_model.cc @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0s * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/ge/ge_runtime/task/hccl_task.cc b/src/ge/ge_runtime/task/hccl_task.cc index dfeda94b..4d76e492 100644 --- a/src/ge/ge_runtime/task/hccl_task.cc +++ b/src/ge/ge_runtime/task/hccl_task.cc @@ -140,7 +140,8 @@ bool HcclTask::SetSecondaryStream() { std::map>> &master_secondary_stream_map = model_stream_mapping_.at(rt_model_handle_); - if (auto iter = master_secondary_stream_map.find(master_stream_id); iter != master_secondary_stream_map.end()) { + auto iter = master_secondary_stream_map.find(master_stream_id); + if (iter != master_secondary_stream_map.end()) { std::vector> &secondary_stream_vec = iter->second; auto lock_weak_ptr = [&secondary_stream_vec, this](int64_t index) -> bool { auto stream = secondary_stream_vec[index].lock(); diff --git a/src/ge/generator/ge_generator.cc b/src/ge/generator/ge_generator.cc index c19cb35d..36fd7dc2 100644 --- a/src/ge/generator/ge_generator.cc +++ b/src/ge/generator/ge_generator.cc @@ -200,7 +200,6 @@ static Status AddOutputs(const ComputeGraphPtr &graph, const NodePtr &node, cons } static void GetOpsProtoPath(string &opsproto_path) { - GELOGI("Start to get ops proto path schedule."); const char *path_env = std::getenv("ASCEND_OPP_PATH"); if (path_env != nullptr) { string path = path_env; @@ -381,7 +380,6 @@ bool GeGenerator::Impl::ParseVersion(const std::string &line, std::string &versi } version = temp.substr(pos + flag.size()); - GELOGI("Version=%s", version.c_str()); return true; } @@ -423,7 +421,6 @@ bool GeGenerator::Impl::SetAtcVersionInfo(AttrHolder &obj) { path_base = path_base.substr(0, path_base.rfind('/') + 1); std::string version_path = path_base + "version.info"; - GELOGI("version_path is %s", version_path.c_str()); std::string version; if (!GetVersionFromPath(version_path, version)) { GELOGW("Get atc version information failed!"); @@ -434,7 +431,6 @@ bool GeGenerator::Impl::SetAtcVersionInfo(AttrHolder &obj) { GELOGW("Ge model set atc version failed!"); return false; } - GELOGI("Ge model set atc version information success."); return true; } @@ -447,7 +443,6 @@ bool GeGenerator::Impl::SetOppVersionInfo(AttrHolder &obj) { } std::string version_path = path_env; version_path += "/version.info"; - GELOGI("version_path is %s", version_path.c_str()); std::string version; if (!GetVersionFromPath(version_path, version)) { GELOGW("Get opp version information failed!"); @@ -458,7 +453,6 @@ bool GeGenerator::Impl::SetOppVersionInfo(AttrHolder &obj) { GELOGW("Ge model set opp version failed!"); return false; } - GELOGI("Ge Model set opp version information success."); return true; } @@ -467,7 +461,7 @@ Status GeGenerator::GenerateModel(const Graph &graph, const string &file_name_pr rtContext_t ctx = nullptr; auto rt = rtCtxGetCurrent(&ctx); if (rt != RT_ERROR_NONE) { - GELOGW("Current ctx is null."); + GELOGD("Current ctx is null."); ctx = nullptr; } @@ -520,7 +514,6 @@ Status GeGenerator::GenerateModel(const Graph &graph, const string &file_name_pr (void)rtCtxSetCurrent(ctx); } - GELOGI("GenerateOfflineModel success."); return SUCCESS; } @@ -708,7 +701,6 @@ Status GeGenerator::Impl::BuildModel(const Graph &graph, const vector return GE_GENERATOR_GRAPH_MANAGER_ADD_GRAPH_FAILED; } - GELOGI("Model inputs size is %zu", inputs.size()); graph_manager_.SetOptionsRunGraphFlag(false); static std::atomic atomic_session_id(0); diff --git a/src/ge/graph/build/graph_builder.cc b/src/ge/graph/build/graph_builder.cc index 480f20c4..ae9cb2ef 100644 --- a/src/ge/graph/build/graph_builder.cc +++ b/src/ge/graph/build/graph_builder.cc @@ -102,7 +102,6 @@ void GraphBuilder::SetOptions(const ge::GraphManagerOptions &options) { } Status GraphBuilder::CalcOpParam(const ge::ComputeGraphPtr &graph) { - GELOGI("Begin to calculate op running param."); GE_CHECK_NOTNULL(graph); auto instance_ptr = ge::GELib::GetInstance(); if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { @@ -140,7 +139,6 @@ Status GraphBuilder::CalcOpParam(const ge::ComputeGraphPtr &graph) { auto parent_node = graph->GetParentNode(); if (parent_node == nullptr) { - GELOGI("Graph[%s] do not have parent node, no need update parent node output size.", graph->GetName().c_str()); return SUCCESS; } @@ -189,7 +187,6 @@ Status GraphBuilder::UpdateParentNodeOutputSize(const ge::ComputeGraphPtr &graph Status GraphBuilder::Build(ComputeGraphPtr &comp_graph, std::vector &subgraph_ptr_list, GeRootModelPtr &ge_root_model_ptr, uint64_t session_id) { - GELOGI("Start to build model."); if (comp_graph == nullptr) { GELOGE(GE_GRAPH_PARAM_NULLPTR, "Graph build comp_graph is null."); return GE_GRAPH_PARAM_NULLPTR; @@ -267,7 +264,7 @@ Status GraphBuilder::BuildForKnownShapeGraph(ComputeGraphPtr &comp_graph, std::v } GE_CHK_STATUS_RET(builder.SaveDataToModel(*model_ptr, *ge_model_ptr), "Graph[%s] builder SaveDataToModel() return fail.", comp_graph->GetName().c_str()); - GELOGI("Success to build graph[%s] model.", comp_graph->GetName().c_str()); + GELOGD("Success to build graph[%s] model.", comp_graph->GetName().c_str()); GE_TIMESTAMP_END(BuildSubgraph, "GraphBuilder::Build"); return SUCCESS; } @@ -306,7 +303,7 @@ Status GraphBuilder::BuildForUnknownShapeGraph(ComputeGraphPtr &comp_graph, GeMo } GE_CHK_STATUS_RET(builder.SaveDataToModel(*model_ptr, *ge_model_ptr), "Graph[%s] builder SaveDataToModel() return fail.", comp_graph->GetName().c_str()); - GELOGI("Success to build graph[%s] model.", comp_graph->GetName().c_str()); + GELOGD("Success to build graph[%s] model.", comp_graph->GetName().c_str()); return SUCCESS; } @@ -542,7 +539,6 @@ Status GraphBuilder::CalcDynShapeRootGraphDataSize(const ge::OpDescPtr &op_desc) } Status GraphBuilder::SecondPartition(ge::ComputeGraphPtr &comp_graph, vector &subgraph_ptr_list) { - GELOGI("[SecondPartition] second partition."); GE_TIMESTAMP_START(GraphPartition2); auto ret = graph_partitioner_.Partition(comp_graph, GraphPartitioner::kSecondPartitioning); if (ret != SUCCESS) { diff --git a/src/ge/graph/build/label_allocator.cc b/src/ge/graph/build/label_allocator.cc index dd9f1560..4138e697 100644 --- a/src/ge/graph/build/label_allocator.cc +++ b/src/ge/graph/build/label_allocator.cc @@ -33,7 +33,7 @@ Status LabelAllocator::AssignFunctionalLabels() { } // Add label task for sub graph. - GELOGI("AssignFunctionalLabels start: %s.", compute_graph_->GetName().c_str()); + GELOGD("AssignFunctionalLabels start: %s.", compute_graph_->GetName().c_str()); std::set functional_nodes; for (auto graph : compute_graph_->GetAllSubgraphs()) { if (!CollectFunctionalNode(graph, functional_nodes)) { diff --git a/src/ge/graph/build/logical_stream_allocator.cc b/src/ge/graph/build/logical_stream_allocator.cc index 9c1c3b93..7cc497fb 100644 --- a/src/ge/graph/build/logical_stream_allocator.cc +++ b/src/ge/graph/build/logical_stream_allocator.cc @@ -363,13 +363,10 @@ Status NodeStreamUpdatePass::Run(ComputeGraphPtr graph, const vector stream_ids; for (const auto &in_node : node->GetInAllNodes()) { @@ -398,8 +395,7 @@ int64_t NodeStreamUpdatePass::GetSingleInoutStream(const NodePtr &node) const { return kInvalidStream; } -Status NodeStreamUpdatePass::UpdateForSkippedEngine(const ComputeGraphPtr &graph, - const vector &subgraphs) { +Status UpdateForSkippedEnginePass::Run(ComputeGraphPtr graph, const vector &subgraphs, Context &context) { set ops_without_label; // Check if subgraph is engine skipped and without stream label or not @@ -441,7 +437,7 @@ Status NodeStreamUpdatePass::UpdateForSkippedEngine(const ComputeGraphPtr &graph return SUCCESS; } -bool NodeStreamUpdatePass::AreAllPredStreamsInvalid(const NodePtr &node) const { +bool UpdateForSkippedEnginePass::AreAllPredStreamsInvalid(const NodePtr &node) const { for (const auto &pre_node : node->GetInAllNodes()) { auto pre_node_desc = pre_node->GetOpDesc(); if (pre_node_desc != nullptr) { @@ -599,10 +595,10 @@ Status LogicalStreamAllocator::DoAssign(const ComputeGraphPtr &graph, const Grap return status; } - GELOGI("Subgraphs of graph %s:", graph->GetName().c_str()); + GELOGD("Subgraphs of graph %s:", graph->GetName().c_str()); for (const auto &subgraph : subgraphs) { if (subgraph != nullptr) { - GELOGI("subgraph: %s", subgraph->name.c_str()); + GELOGD("subgraph: %s", subgraph->name.c_str()); } } @@ -651,12 +647,14 @@ Status LogicalStreamAllocator::RunPasses(const ComputeGraphPtr &graph, const vec if (context_.enable_single_stream) { passes.emplace_back(MakeShared()); passes.emplace_back(MakeShared()); + passes.emplace_back(MakeShared()); } else { passes.emplace_back(MakeShared()); passes.emplace_back(MakeShared()); passes.emplace_back(MakeShared()); passes.emplace_back(MakeShared()); passes.emplace_back(MakeShared()); + passes.emplace_back(MakeShared()); } for (auto &pass : passes) { @@ -664,9 +662,9 @@ Status LogicalStreamAllocator::RunPasses(const ComputeGraphPtr &graph, const vec Status status = pass->Run(graph, subgraphs, context_); if (status == SUCCESS) { - GELOGI("Stream pass %s return SUCCESS.", pass->GetName().c_str()); + GELOGD("Stream pass %s return SUCCESS.", pass->GetName().c_str()); } else if (status == NOT_CHANGED) { - GELOGI("Stream pass %s return NOT_CHANGED.", pass->GetName().c_str()); + GELOGD("Stream pass %s return NOT_CHANGED.", pass->GetName().c_str()); } else { GELOGE(status, "Stream pass %s failed.", pass->GetName().c_str()); return status; diff --git a/src/ge/graph/build/logical_stream_allocator.h b/src/ge/graph/build/logical_stream_allocator.h index d8f677f8..f4a00f55 100644 --- a/src/ge/graph/build/logical_stream_allocator.h +++ b/src/ge/graph/build/logical_stream_allocator.h @@ -147,15 +147,20 @@ class NodeStreamUpdatePass : public LogicalStreamPass { public: STREAM_PASS_DEFAULT_FUNC(NodeStreamUpdatePass); Status Run(ComputeGraphPtr graph, const std::vector &subgraphs, Context &context) override; +}; - private: +// Update the stream of subgraphs to nodes. +class UpdateForSkippedEnginePass : public LogicalStreamPass { + public: + STREAM_PASS_DEFAULT_FUNC(UpdateForSkippedEnginePass); /// Optimize for case like: /// NodeA(stream1) -> Const(stream2) -> NodeB(stream1) /// To case: /// NodeA(stream1) -> Const(stream1) -> NodeB(stream1) /// Which could reduce event number (Const could be other type which belong to skipped engine subgraph) - Status UpdateForSkippedEngine(const ComputeGraphPtr &graph, const std::vector &subgraphs); + Status Run(ComputeGraphPtr graph, const std::vector &subgraphs, Context &context) override; + private: int64_t GetSingleInoutStream(const NodePtr &node) const; // Judge if all predecessors' streams of node are kInvalidStream bool AreAllPredStreamsInvalid(const NodePtr &node) const; diff --git a/src/ge/graph/build/memory/binary_block_mem_assigner.cc b/src/ge/graph/build/memory/binary_block_mem_assigner.cc index 8668e81e..41841b85 100644 --- a/src/ge/graph/build/memory/binary_block_mem_assigner.cc +++ b/src/ge/graph/build/memory/binary_block_mem_assigner.cc @@ -77,7 +77,7 @@ Status BinaryBlockMemAssigner::GetMemoryRanges(vector &range_ceils) { auto range_number = static_cast( ceil(log(all_memory_size.back() / static_cast(all_memory_size.front())) / log(kLogBase))); range_number = (range_number == 0) ? 1 : range_number; - GELOGI("Range number: %zu", range_number); + GELOGD("Range number: %zu", range_number); vector> ranges(range_number); GE_CHK_BOOL_EXEC((range_number != 0), return PARAM_INVALID, "range_number can't be 0."); @@ -115,7 +115,7 @@ Status BinaryBlockMemAssigner::GetMemoryRanges(vector &range_ceils) { range_ceils.push_back(range.back()); } } - GELOGI("Range ceils: %s", ToString(range_ceils).c_str()); + GELOGD("Range ceils: %s", ToString(range_ceils).c_str()); return SUCCESS; } diff --git a/src/ge/graph/build/memory/block_mem_assigner.cc b/src/ge/graph/build/memory/block_mem_assigner.cc index db7b6854..d8ac1e7f 100644 --- a/src/ge/graph/build/memory/block_mem_assigner.cc +++ b/src/ge/graph/build/memory/block_mem_assigner.cc @@ -461,12 +461,11 @@ void BlockMemAssigner::GetOutAndWorkSpaceMem(vector &all_memory_size) { GetNodeWorkSpaceSize(n, temp); all_memory_size.insert(all_memory_size.end(), temp.begin(), temp.end()); } - GELOGI("The last atomic_addr_clean node id: %ld", atomic_addr_clean_id_); for (const auto &pair : symbol_size_) { all_memory_size.emplace_back(pair.second); } sort(all_memory_size.begin(), all_memory_size.end()); - GELOGI("All memory size: %s", ToString(all_memory_size).c_str()); + GELOGD("All memory size: %s", ToString(all_memory_size).c_str()); for (auto iter = all_memory_size.begin(); iter != all_memory_size.end();) { if (*iter == 0) { @@ -501,7 +500,7 @@ size_t GetBlockSize(size_t size, const vector &ranges) { bool IsDirectOutputNode(const NodePtr &node, int idx) { if ((node != nullptr) && (node->GetOpDesc() != nullptr) && (node->GetOpDesc()->GetType() == NETOUTPUT)) { - GELOGI("This is netoutput node, the input node mem can not be reused"); + GELOGD("This is netoutput node, the input node mem can not be reused"); return true; } return false; @@ -1107,7 +1106,7 @@ bool IsAtomicOutputMemory(const ge::NodePtr &node, uint32_t output_index, bool i if (static_cast(index) == output_index) { if (node->GetOwnerComputeGraph() != nullptr) { string graph_name = node->GetOwnerComputeGraph()->GetName(); - GELOGD("[IMAS]Atomic no assign %s name[%s] output[%d] streamid[%ld].", graph_name.c_str(), + GELOGD("[IMAS]Atomic no assign %s name[%s] output[%ld] streamid[%ld].", graph_name.c_str(), op_desc->GetName().c_str(), index, op_desc->GetStreamId()); } return true; @@ -1224,7 +1223,7 @@ Status BlockMemAssigner::AssignOutputMemoryWithReuse(const NodePtr &node, vector int64_t stream_id = op_desc->GetStreamId(); vector memorys_type; bool has_mem_type_attr = ge::AttrUtils::GetListInt(op_desc, ATTR_NAME_OUTPUT_MEM_TYPE_LIST, memorys_type); - GELOGI("Assign memory node[%s], output size[%d], output memory type size[%d]", op_desc->GetName().c_str(), + GELOGD("Assign memory node[%s], output size[%zu], output memory type size[%zu]", op_desc->GetName().c_str(), op_desc->GetOutputsSize(), memorys_type.size()); if (has_mem_type_attr && (memorys_type.size() != op_desc->GetOutputsSize())) { GELOGE(INTERNAL_ERROR, "fusion: node[%s], output memory size err[outputsize:%zu, memorysize:%zu]", @@ -1263,7 +1262,7 @@ Status BlockMemAssigner::AssignOutputMemoryWithReuse(const NodePtr &node, vector // fusion: other type's size not means malloc HBM memory bool l1_flag = has_mem_type_attr && memorys_type[i] == RT_MEMORY_L1; if (l1_flag) { - GELOGI("fusion: node[%s], output[%s], output memory type [%d]", op_desc->GetName().c_str(), + GELOGI("fusion: node[%s], output[%s], output memory type [%ld]", op_desc->GetName().c_str(), op_desc->GetOutputNameByIndex(i).c_str(), memorys_type[i]); size = 0; } @@ -1316,7 +1315,7 @@ Status BlockMemAssigner::AssignOutputMemoryWithReuse(const NodePtr &node, vector /// void BlockMemAssigner::AssignMemoryWithReuse(vector &ranges) { (void)ge::GetContext().GetOption(OPTION_EXEC_DISABLE_REUSED_MEMORY, ge_disable_reuse_mem_env_); - GEEVENT("Reuse memory %s", ge_disable_reuse_mem_env_ == "1" ? "close" : "open"); + GELOGD("Reuse memory %s", ge_disable_reuse_mem_env_ == "1" ? "close" : "open"); string op_no_reuse_mem_str; const char *op_no_reuse_mem = std::getenv(OP_NO_REUSE_MEM); GE_IF_BOOL_EXEC(op_no_reuse_mem != nullptr, op_no_reuse_mem_str = string(op_no_reuse_mem); @@ -1342,7 +1341,7 @@ void BlockMemAssigner::AssignMemoryWithReuse(vector &ranges) { vector workspace_reuse_flag; GE_IF_BOOL_EXEC(!ge::AttrUtils::GetListBool(node_op_desc, kAttrNameWorkspaceReuseFlag, workspace_reuse_flag), GELOGD("OP %s get workspace_reuse_flag attr failed", node_op_desc->GetName().c_str())); - GELOGI("Assign memory node[%s], size [temp:%zu, memory type size:%zu]", node_op_desc->GetName().c_str(), + GELOGD("Assign memory node[%s], size [temp:%zu, memory type size:%zu]", node_op_desc->GetName().c_str(), temp.size(), tvm_workspace_memory_type.size()); if (has_tvm_workspace_mem_type_attr && (temp.size() != tvm_workspace_memory_type.size())) { @@ -1355,7 +1354,7 @@ void BlockMemAssigner::AssignMemoryWithReuse(vector &ranges) { bool workspace_skip_flag = false; if (has_tvm_workspace_mem_type_attr && tvm_workspace_memory_type[i] == RT_MEMORY_L1) { GELOGI( - "fusion: node[%s]workspace index[%d] is not hbm type, add to zero_memory_list, workspace memory type [%ld]", + "fusion: node[%s]workspace index[%zu] is not hbm type, add to zero_memory_list, workspace memory type [%ld]", node_op_desc->GetName().c_str(), i, tvm_workspace_memory_type[i]); workspace_skip_flag = true; } @@ -1631,7 +1630,7 @@ void BlockMemAssigner::ResizeMemoryBlocks() { memory_block->SetTailOffset(p2p_mem_offset_ - 1); } } - GELOGI("mem_offset_ exclude zero_copy_memory is %zu, p2p_mem_offset_ exclude zero_copy_memory is %zu.", mem_offset_, + GELOGD("mem_offset_ exclude zero_copy_memory is %zu, p2p_mem_offset_ exclude zero_copy_memory is %zu.", mem_offset_, p2p_mem_offset_); } diff --git a/src/ge/graph/build/memory/graph_mem_assigner.cc b/src/ge/graph/build/memory/graph_mem_assigner.cc index fbed5c77..6e5dd183 100644 --- a/src/ge/graph/build/memory/graph_mem_assigner.cc +++ b/src/ge/graph/build/memory/graph_mem_assigner.cc @@ -20,6 +20,7 @@ #include "common/math/math_util.h" #include "common/util/error_manager/error_manager.h" #include "framework/common/debug/ge_log.h" +#include "framework/common/debug/log.h" #include "graph/build/memory/hybrid_mem_assigner.h" #include "graph/build/memory/var_mem_assign_util.h" #include "graph/build/memory/block_mem_assigner.h" @@ -116,7 +117,7 @@ Status GraphMemoryAssigner::AssignMemory() { return ge::FAILED; } int64_t var_size_assign = ge::VarManager::Instance(session_id)->GetVarMemSize(RT_MEMORY_HBM) - var_size_before_assign; - GELOGI("GraphMemoryAssigner::AssignMemory variable size = %ld", var_size_assign); + GELOGD("GraphMemoryAssigner::AssignMemory variable size = %ld", var_size_assign); mem_assigner_ = std::move(mem_assigner); @@ -148,8 +149,10 @@ ge::Status GraphMemoryAssigner::CalculateTensorRealSizeAndOutSize(const ge::Cons GeShape output_shape = output_desc->GetShape(); std::vector output_dims = output_shape.GetDims(); if (dim_index >= static_cast(output_dims.size())) { - GELOGE(FAILED, "Invaild value(%ld) of attr _reuse_input_on_dim_index, which is out of data range [0, %zu).", - dim_index, output_dims.size()); + std::string error = "Invaild value" + FmtToStr(dim_index) + + " of attr _reuse_input_on_dim_index, which is out of data range [0," + + std::to_string(output_dims.size()) + ")"; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } @@ -170,8 +173,9 @@ ge::Status GraphMemoryAssigner::CalculateTensorRealSizeAndOutSize(const ge::Cons } if (output_mem_size < 0) { - GELOGE(FAILED, "After calculating tensor memory size, output_mem_size = %ld, out of data range [0, %ld]", - output_mem_size, INT64_MAX); + std::string error = "After calculating tensor memory size, output_mem_size" + FmtToStr(output_mem_size) + + " is out of data range [0," + std::to_string(INT64_MAX) + "]"; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } @@ -196,7 +200,8 @@ Status GraphMemoryAssigner::GetMaxBatchLabel(const map> } else if (mem_reuse_model == kVirtualOutputNodeMemoryReuse) { input_output_desc = op_desc->GetInputDescPtr(kVirtualNodeDataIndex); } else { - GELOGE(FAILED, "Invalid parameter memory reuse model, which is: %d.", mem_reuse_model); + std::string error = "Invalid parameter memory reuse model, which is " + FmtToStr(mem_reuse_model); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } GE_CHECK_NOTNULL(input_output_desc); @@ -208,7 +213,8 @@ Status GraphMemoryAssigner::GetMaxBatchLabel(const map> } else { vector current_shape_dims = input_output_desc->GetShape().GetDims(); if (current_shape_dims.size() != max_shape_dims.size()) { - GELOGE(FAILED, "The shape size of several nodes between multiple batches does not match."); + std::string error = "The shape of several nodes between multiple batches does not match."; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } for (size_t j = 0; j < current_shape_dims.size(); ++j) { @@ -216,7 +222,8 @@ Status GraphMemoryAssigner::GetMaxBatchLabel(const map> continue; } if (max_batch_dim_find && max_batch_dim != j) { - GELOGE(FAILED, "The shape of several nodes between multiple batches does not match."); + std::string error = "The shape of several nodes between multiple batches does not match."; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } max_batch_dim_find = true; @@ -290,26 +297,25 @@ Status GraphMemoryAssigner::AssignZeroCopyMemory(map &mem_offse mem_offset[RT_MEMORY_HBM] += memory_block->Size(); memory_block->SetTailOffset(mem_offset[RT_MEMORY_HBM] - 1); } - GELOGI("mem_offset_ include zero_copy_memory is %zu.", mem_offset[RT_MEMORY_HBM]); // set offset for zero copy nodes priority_assigner->SetOpMemOffset(true); zero_mem_copy_size = mem_offset[RT_MEMORY_HBM] - mem_offset_tmp; auto iter = memory_offset_.find(RT_MEMORY_HBM); if (iter == memory_offset_.end()) { - GELOGE(FAILED, "Memory offset don't have memory type[hbm]."); + std::string error = "Memory offset does not have memory type[HBM]"; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } iter->second.mem_offset_ = mem_offset[RT_MEMORY_HBM]; - GELOGI("max_mem_offset:%zu, mem_offset:%zu, zero_mem_copy_size:%zu.", mem_offset[RT_MEMORY_HBM], mem_offset_tmp, + GELOGD("max_mem_offset:%zu, mem_offset:%zu, zero_mem_copy_size:%zu.", mem_offset[RT_MEMORY_HBM], mem_offset_tmp, zero_mem_copy_size); return SUCCESS; } Status GraphMemoryAssigner::ReAssignContinuousMemory(bool is_loop_graph) { - GELOGI("Begin to reassign continuous memory"); Status ret; for (auto &node : compute_graph_->GetAllNodes()) { // Get the continuous input type of the node, default is false @@ -380,7 +386,7 @@ Status GraphMemoryAssigner::ReAssignContinuousMemory(bool is_loop_graph) { } } for (auto pair : memory_offset_) { - GELOGI("After reassign continuous memory, memory type = %ld, memoffset = %zu.", pair.first, + GELOGD("After reassign continuous memory, memory type = %ld, memoffset = %zu.", pair.first, pair.second.mem_offset_); } return ge::SUCCESS; @@ -393,7 +399,8 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node, (void)ge::AttrUtils::GetBool(node->GetOpDesc(), ATTR_NAME_CONTINUOUS_INPUT_ALLOC, continuous_input_alloc); auto iter = memory_offset_.find(memory_type); if (iter == memory_offset_.end()) { - GELOGE(FAILED, "Memory offset don't have memory type[%ld].", memory_type); + std::string error = "Memory offset does not have memory type" + FmtToStr(memory_type); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } for (auto &in_data_anchor : node->GetAllInDataAnchors()) { @@ -410,22 +417,24 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node, // continuous output of the previous node is the same, we can support it. If size != 1, there may be // conflict between the two, we can not support it. auto peer_output_size = peer_op_desc->GetOutputsSize(); - GE_IF_BOOL_EXEC(is_peer_output_continuous && (peer_output_size != 1), - GELOGE(PARAM_INVALID, - "Current node %s requires continuous input, while the previous node %s requires " - "continuous output. There may be conflict between the two. This node is not supported now.", - node->GetOpDesc()->GetName().c_str(), peer_op_desc->GetName().c_str()); - return PARAM_INVALID;); + GE_IF_BOOL_EXEC( + is_peer_output_continuous && (peer_output_size != 1), + std::string error = + "Current op" + FmtToStr(node->GetOpDesc()->GetName()) + " requires continuous input, while the previous op" + + FmtToStr(peer_op_desc->GetName()) + + " requires continuous output. There may be conflict between the two. This node is not supported now."; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return PARAM_INVALID;); bool is_peer_reference = false; // If GetBool fail, is_peer_reference is false. (void)AttrUtils::GetBool(peer_op_desc, ATTR_NAME_REFERENCE, is_peer_reference); - GE_IF_BOOL_EXEC(is_peer_reference, - GELOGE(PARAM_INVALID, - "Current node %s requires continuous input, while the previous node %s requires " - "reference. There may be conflict between the two. This node is not supported now.", - node->GetOpDesc()->GetName().c_str(), peer_op_desc->GetName().c_str()); - return PARAM_INVALID;); + GE_IF_BOOL_EXEC( + is_peer_reference, + std::string error = + "Current op" + FmtToStr(node->GetOpDesc()->GetName()) + " requires continuous input, while the previous op" + + FmtToStr(peer_op_desc->GetName()) + + " requires continuous output. There may be conflict between the two. This node is not supported now."; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return PARAM_INVALID;); vector output_list = peer_op_desc->GetOutputOffset(); std::vector offsets_for_fusion = {}; @@ -448,7 +457,7 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node, output_list.at(peer_out_data_anchor->GetIdx()) - continuous_mem_start + tensor_desc_size + MEM_ALIGN_SIZE; } GELOGI( - "[IMAS]Check Continuous input : Set %s name[%s] output[%d] offset to [%zu] stream_id[%ld] size[%zu] " + "[IMAS]Check Continuous input : Set %s name[%s] output[%d] offset to [%ld] stream_id[%ld] size[%u] " "real_size[%u].", node->GetOwnerComputeGraph()->GetName().c_str(), peer_op_desc->GetName().c_str(), peer_out_data_anchor->GetIdx(), output_list.at(peer_out_data_anchor->GetIdx()), peer_op_desc->GetStreamId(), @@ -458,6 +467,8 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node, output_list.at(peer_out_data_anchor->GetIdx()) = iter->second.mem_offset_; } else { + std::string error = "index" + FmtToStr(peer_out_data_anchor->GetIdx()) + " is out of range."; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); GELOGE(FAILED, "index : %d is out of range.", peer_out_data_anchor->GetIdx()); return FAILED; } @@ -470,8 +481,9 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node, auto offset_for_fusion = offsets_for_fusion[peer_out_data_anchor->GetIdx()]; iter->second.mem_offset_ += offset_for_fusion; } else { - GELOGE(FAILED, "fusion: peer node %s index : %d is out of range.", peer_op_desc->GetName().c_str(), - peer_out_data_anchor->GetIdx()); + std::string error = "fusion: peer node" + FmtToStr(peer_op_desc->GetName()) + " index" + + FmtToStr(peer_out_data_anchor->GetIdx()) + " is out of range."; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } } else { @@ -615,14 +627,16 @@ Status GraphMemoryAssigner::ReAssignReuseAndNoPaddingContinuousInputMemory() { if (attr_reuse && attr_continuous) { if (op_desc->GetOutputsSize() != kVirtualInputNodeOutputSize) { // When current virtual node has several outputs, can't directly determine which input is the tensor for reuse. - GELOGE(FAILED, "Only one output is supported, current virtual node %s has %zu inputs.", n->GetName().c_str(), - op_desc->GetOutputsSize()); + std::string error = "Only one output is supported, current virtual node" + FmtToStr(n->GetName()) + " has " + + FmtToStr(op_desc->GetOutputsSize()) + " outputs."; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } GE_CHK_STATUS_RET(GetNodeMemoryType(n, memory_type, "input"), "Get node memory type failed."); auto iter = memory_offset_.find(memory_type); if (iter == memory_offset_.end()) { - GELOGE(FAILED, "Memory offset don't have memory type[%ld].", memory_type); + std::string error = "Memory offset does not have memory type" + FmtToStr(memory_type); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } GELOGD("Start to reassign memory for virtual input node, memory offset = %zu, memory type = %ld.", @@ -757,14 +771,16 @@ Status GraphMemoryAssigner::ReAssignReuseAndNoPaddingContinuousOutputMemory() { auto in_data_anchor_list = n->GetAllInDataAnchors(); if (in_data_anchor_list.size() != kVirtualOutputNodeInputSize) { // When current virtual node has several inputs, can't directly determine which input is the tensor for reuse. - GELOGE(FAILED, "Only one input is supported, current virtual node %s has %zu inputs.", n->GetName().c_str(), - in_data_anchor_list.size()); + std::string error = "Only one input is supported, current virtual node" + FmtToStr(n->GetName()) + " has " + + FmtToStr(in_data_anchor_list.size()) + " inputs."; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } GE_CHK_STATUS_RET(GetNodeMemoryType(n, memory_type, "output"), "Get node memory type failed."); auto iter = memory_offset_.find(memory_type); if (iter == memory_offset_.end()) { - GELOGE(FAILED, "Memory offset don't have memory type[%ld].", memory_type); + std::string error = "Memory offset does not have memory type" + FmtToStr(RT_MEMORY_HBM); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } GELOGD("Start to reassign memory for virtual output node, memory offset = %zu, memory type = %ld.", @@ -789,8 +805,10 @@ Status GraphMemoryAssigner::ReAssignReuseAndNoPaddingContinuousOutputMemory() { string current_node_full_name = op_desc->GetName(); size_t pos = current_node_full_name.find(kMbatchNodeNameFlag); if (pos == string::npos) { - GELOGE(FAILED, "Cannot find key string [%s] of multi-batch in name of virtual output node, node name: %s.", - kMbatchNodeNameFlag, n->GetName().c_str()); + std::string error = "Cannot find key string" + FmtToStr(kMbatchNodeNameFlag) + + " of multi-batch in name of virtual output node, the node name is " + + FmtToStr(n->GetName()); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } string fixed_name = current_node_full_name.substr(0, pos); @@ -818,7 +836,6 @@ Status GraphMemoryAssigner::ReAssignVirtualNodesMemory(map nodes_mem_offset_list; for (auto &i_map : mem_reuse_nodes_map) { @@ -828,7 +845,8 @@ Status GraphMemoryAssigner::ReAssignVirtualNodesMemory(mapsecond.mem_offset_; @@ -846,7 +864,8 @@ Status GraphMemoryAssigner::ReAssignVirtualNodesMemory(mapGetName().c_str()); + std::string error = "Op" + FmtToStr(peer_in_node_desc->GetName()) + + " cannot have both atomic and is_reference attribute."; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return ge::PARAM_INVALID; } @@ -1021,7 +1043,8 @@ Status GraphMemoryAssigner::AssignAtomicOutputAndWorkspaceMemory(const ge::NodeP Status GraphMemoryAssigner::AssignConnectNetOutputAtomicMemory(vector &connect_netoutput_nodes) { auto iter = memory_offset_.find(RT_MEMORY_HBM); if (iter == memory_offset_.end()) { - GELOGE(FAILED, "Memory offset don't have memory type[%ld].", RT_MEMORY_HBM); + std::string error = "Memory offset does not have memory type" + FmtToStr(RT_MEMORY_HBM); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } for (auto &node : connect_netoutput_nodes) { @@ -1122,9 +1145,9 @@ bool GraphMemoryAssigner::CheckInputIsSupportAtomic(const ge::NodePtr &node) { } if ((peer_op_desc->GetType() == CONSTANTOP) || (peer_op_desc->GetType() == AIPP_DATA_TYPE) || (peer_op_desc->GetType() == VARIABLE)) { - GELOGE(ge::FAILED, - "The current node is %s, and the peer out node is %s. Currently, this scenario is not supported", - node->GetName().c_str(), peer_op_desc->GetName().c_str()); + std::string error = "Op" + FmtToStr(node->GetName()) + "'s peer out node" + FmtToStr(peer_op_desc->GetName()) + + " is invalid, only support Constant/AippData/Variable"; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return false; } } @@ -1144,19 +1167,23 @@ Status GraphMemoryAssigner::AssignAtomicOutputMemory(const ge::NodePtr &node, ve // Check atomic output vector output_list = op_desc->GetOutputOffset(); if (atomic_output_index.size() > output_list.size()) { - GELOGE(ge::FAILED, "The size of atomic_output_index is more than the size of output_list"); + std::string error = + "Op" + FmtToStr(node->GetName()) + "'s size of atomic_output_index is more than the size of output_list"; + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return ge::FAILED; } auto output_list_size = static_cast(output_list.size()); auto iter = memory_offset_.find(RT_MEMORY_HBM); if (iter == memory_offset_.end()) { - GELOGE(FAILED, "Memory offset don't have memory type[%ld].", RT_MEMORY_HBM); + std::string error = "Memory offset does not have memory type" + FmtToStr(RT_MEMORY_HBM); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } for (auto &output_index : atomic_output_index) { if (output_index >= output_list_size) { - GELOGE(ge::PARAM_INVALID, "The output index %ld is more than the size %ld of output_list.", output_index, - output_list_size); + std::string error = "Op" + FmtToStr(node->GetName()) + "'s output index" + FmtToStr(output_index) + + " is more than the size" + FmtToStr(output_list_size) + " of output_list."; + GE_ERRORLOG_AND_ERRORMSG(ge::PARAM_INVALID, error.c_str()); return ge::PARAM_INVALID; } @@ -1200,7 +1227,9 @@ Status GraphMemoryAssigner::AssignAtomicOutputMemory(const ge::NodePtr &node, ve Status GraphMemoryAssigner::GetMemoryAssignmentStatus(const ge::NodePtr &node, int64_t output_index, bool &is_mem_assigned) { if (static_cast(output_index) >= node->GetAllOutDataAnchors().size()) { - GELOGE(ge::PARAM_INVALID, "Output index %ld is more than the size of node's AllOutDataAnchors.", output_index); + std::string error = "Op" + FmtToStr(node->GetName()) + "'s output index" + FmtToStr(output_index) + + " is more than the size of node's AllOutDataAnchors."; + GE_ERRORLOG_AND_ERRORMSG(ge::PARAM_INVALID, error.c_str()); return ge::PARAM_INVALID; } auto out_data_anchor = node->GetAllOutDataAnchors().at(output_index); @@ -1227,15 +1256,17 @@ Status GraphMemoryAssigner::AssignOrdinaryAtomicWorkspaceMemory(const ge::OpDesc GELOGI("Begin to reassign normal atomic memory, node = %s.", op_desc->GetName().c_str()); auto mem_type_iter = memory_offset_.find(RT_MEMORY_HBM); if (mem_type_iter == memory_offset_.end()) { - GELOGE(FAILED, "Memory offset don't have memory type[%ld].", RT_MEMORY_HBM); + std::string error = "Memory offset does not have memory type" + FmtToStr(RT_MEMORY_HBM); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } vector workspace_vector = op_desc->GetWorkspace(); for (auto iter = workspace_info.begin(); iter != workspace_info.end(); ++iter) { if (op_desc->GetName() != iter->first) { - GELOGE(ge::PARAM_INVALID, "The node name %s and the node name %s in workspace info are inconsistent.", - op_desc->GetName().c_str(), iter->first.c_str()); + std::string error = "The node name" + FmtToStr(op_desc->GetName()) + " and the node name" + + FmtToStr(iter->first) + " in workspace info are inconsistent."; + GE_ERRORLOG_AND_ERRORMSG(ge::PARAM_INVALID, error.c_str()); return ge::PARAM_INVALID; } @@ -1247,8 +1278,9 @@ Status GraphMemoryAssigner::AssignOrdinaryAtomicWorkspaceMemory(const ge::OpDesc auto workspace_index = static_cast(info_iter.first); auto workspace_size = info_iter.second; if (workspace_index >= workspace_vector.size()) { - GELOGE(ge::PARAM_INVALID, "The workspace index %lu is more than the size %zu of workspace vector.", - workspace_index, workspace_vector.size()); + std::string error = "The workspace index" + FmtToStr(workspace_index) + " is more than the size" + + FmtToStr(workspace_vector.size()) + " of workspace vector."; + GE_ERRORLOG_AND_ERRORMSG(ge::PARAM_INVALID, error.c_str()); return ge::PARAM_INVALID; } @@ -1274,7 +1306,8 @@ Status GraphMemoryAssigner::AssignFusionAtomicWorkspaceMemory(const ge::OpDescPt GELOGI("Begin to reassign fusion atomic memory, node = %s.", op_desc->GetName().c_str()); auto mem_type_iter = memory_offset_.find(RT_MEMORY_HBM); if (mem_type_iter == memory_offset_.end()) { - GELOGE(FAILED, "Memory offset don't have memory type[%ld].", RT_MEMORY_HBM); + std::string error = "Memory offset does not have memory type" + FmtToStr(RT_MEMORY_HBM); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } map> sub_node_workspace_offset; @@ -1322,7 +1355,9 @@ Status GraphMemoryAssigner::CheckOffset() { vector input_list = node->GetOpDesc()->GetInputOffset(); for (auto input : input_list) { if (input == ge::kInvalidOffset) { - GELOGE(FAILED, "Invalid offset in node: %s input: %ld.", node->GetName().c_str(), ge::kInvalidOffset); + std::string error = + "Invalid input offset" + FmtToStr(ge::kInvalidOffset) + +" in node" + FmtToStr(node->GetName()); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } } @@ -1331,7 +1366,9 @@ Status GraphMemoryAssigner::CheckOffset() { vector output_list = node->GetOpDesc()->GetOutputOffset(); for (uint32_t i = 0; i < output_list.size(); ++i) { if (output_list[i] == ge::kInvalidOffset) { - GELOGE(FAILED, "Invalid offset in node: %s output: %ld.", node->GetName().c_str(), ge::kInvalidOffset); + std::string error = + "Invalid output offset" + FmtToStr(ge::kInvalidOffset) + +" in node" + FmtToStr(node->GetName()); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } if (node->GetType() == IDENTITY || node->GetType() == READVARIABLEOP) { @@ -1349,7 +1386,10 @@ Status GraphMemoryAssigner::CheckOffset() { vector workspace_list = node->GetOpDesc()->GetWorkspace(); for (auto workspace : workspace_list) { if (workspace == ge::kInvalidOffset) { - GELOGE(FAILED, "Invalid offset in node: %s workspace: %ld.", node->GetName().c_str(), ge::kInvalidOffset); + std::string error = + "Invalid workspace" + FmtToStr(ge::kInvalidOffset) + +" in node" + FmtToStr(node->GetName()); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); + GELOGE(FAILED, "Invalid workspace in node: %s workspace: %ld.", node->GetName().c_str(), ge::kInvalidOffset); return FAILED; } } @@ -1412,8 +1452,9 @@ ge::Status GraphMemoryAssigner::UpdateConstArgsOffset(const NodePtr &node, vecto const auto &parent_desc = owner->GetParentNode()->GetOpDesc(); const auto parent_inputs = parent_desc->GetInputOffset(); if (parent_inputs.size() <= parent_index) { - GELOGE(FAILED, "Get Parent input offset failed, node: %s, input size: %zu, parent index: %u", - node->GetName().c_str(), parent_inputs.size(), parent_index); + std::string error = "Get Parent input offset failed, node is " + FmtToStr(node->GetName()) + +", input_size is " + + FmtToStr(parent_inputs.size()) + ", parent index is " + FmtToStr(parent_index); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } @@ -1449,10 +1490,10 @@ ge::Status GraphMemoryAssigner::UpdateOpInputOffset(const NodePtr &node, vector< auto ori_input_offset_list_size = origin_input_list.size(); auto mem_type_size = memory_type.size(); if ((input_size != mem_type_size) || (input_size != ori_input_offset_list_size)) { - GELOGE(ge::FAILED, - "fusion: node[%s] input_size[%zu] diff from memory_type_size[%zu]" - " from ori_input_offset_list_size[%lu]", - tmp_op_desc->GetName().c_str(), input_size, mem_type_size, ori_input_offset_list_size); + std::string error = "fusion: node" + FmtToStr(tmp_op_desc->GetName()) + +" input_size" + + FmtToStr(input_size) + " diff from memory_type_size" + FmtToStr(mem_type_size) + + " from ori_input_offset_list_size" + FmtToStr(ori_input_offset_list_size); + GE_ERRORLOG_AND_ERRORMSG(ge::FAILED, error.c_str()); return ge::FAILED; } // not hbm keep orignal inputoffest @@ -1467,7 +1508,7 @@ ge::Status GraphMemoryAssigner::UpdateOpInputOffset(const NodePtr &node, vector< GE_CHK_STATUS(TensorUtils::GetDataOffset(tensor_desc, input_offset)); } - GELOGI("%s node[%s] input[%d] is set from node[%s] out index[%lu] offset[%ld]", + GELOGD("%s node[%s] input[%d] is set from node[%s] out index[%lu] offset[%ld]", has_mem_type_attr == true ? "Fusion" : "", tmp_op_desc->GetName().c_str(), valid_input_index, peer_out_anchor->GetOwnerNode()->GetOpDesc()->GetName().c_str(), out_index, input_offset); input_list.emplace_back(input_offset); @@ -1653,15 +1694,20 @@ ge::Status GraphMemoryAssigner::GetNodeMemoryType(const NodePtr &node, int64_t & } if (mem_type_list.empty()) { if (memory_offset_.find(memory_type) == memory_offset_.end()) { - GELOGE(FAILED, "Memory offset map does not have memory type[%ld].", memory_type); + std::string error = "Memory offset map does not have memory type" + FmtToStr(memory_type) + +", opname is " + + FmtToStr(node->GetName()) + ", optype is " + FmtToStr(node->GetType()); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } return SUCCESS; } if (mem_type_list.size() != node->GetAllInDataAnchorsSize()) { - GELOGE(FAILED, "The size[%zu] of mem type list is not equal to the size of in data anchor[%u].", - mem_type_list.size(), node->GetAllInDataAnchorsSize()); + std::string error = "The size" + FmtToStr(mem_type_list.size()) + + " of mem type list is not equal to the size of in data anchor" + + FmtToStr(node->GetAllInDataAnchorsSize()) + ", opname is " + FmtToStr(node->GetName()) + + ", optype is " + FmtToStr(node->GetType()); + GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str()); return FAILED; } @@ -1681,12 +1727,17 @@ bool GraphMemoryAssigner::CheckContinuousMemType(vector mem_type_list) int64_t mem_type_tmp = mem_type_list[0]; for (auto mem_type : mem_type_list) { if (mem_type != mem_type_tmp) { + std::string error = "The memory is continuous, but the type of the input memory is inconsistent. They are " + + FmtToStr(mem_type_tmp) + " and " + FmtToStr(mem_type); + ErrorManager::GetInstance().ATCReportErrMessage("E10043", {"reason"}, {error}); GELOGW("The memory is continuous, but the type of the input memory is inconsistent. They are [%ld] and [%ld].", mem_type_tmp, mem_type); return false; } } if (memory_offset_.find(mem_type_tmp) == memory_offset_.end()) { + std::string error = "Memory offset map does not have memory type" + FmtToStr(mem_type_tmp); + ErrorManager::GetInstance().ATCReportErrMessage("E10043", {"reason"}, {error}); GELOGW("Memory offset map does not have memory type[%ld].", mem_type_tmp); return false; } diff --git a/src/ge/graph/build/memory/hybrid_mem_assigner.cc b/src/ge/graph/build/memory/hybrid_mem_assigner.cc index 32246f7d..eea1aefc 100644 --- a/src/ge/graph/build/memory/hybrid_mem_assigner.cc +++ b/src/ge/graph/build/memory/hybrid_mem_assigner.cc @@ -62,9 +62,9 @@ Status HybridMemAssigner::Assign() { std::unique_ptr priority_assigner; - GELOGI("Binary-block memory size:%zu, max-block memory size:%zu", bin_mem_size, max_mem_size); + GELOGD("Binary-block memory size:%zu, max-block memory size:%zu", bin_mem_size, max_mem_size); if (bin_mem_size <= max_mem_size) { - GELOGI("Use binary-block memory assigner method"); + GELOGD("Use binary-block memory assigner method"); priority_assigner = std::move(binary_assigner); } else { GELOGI("Use max-block memory assigner method"); diff --git a/src/ge/graph/build/model_builder.cc b/src/ge/graph/build/model_builder.cc index ea2272fa..34257ab8 100644 --- a/src/ge/graph/build/model_builder.cc +++ b/src/ge/graph/build/model_builder.cc @@ -190,7 +190,6 @@ void ModelBuilder::SetInputIsConst(const ge::NodePtr &n) { GE_IF_BOOL_EXEC(peer_out_anchor == nullptr, continue); const auto &src_node = peer_out_anchor->GetOwnerNode(); if (!NodeUtils::GetConstOpType(src_node, const_type)) { - GELOGI("Node %s:%zu, sorce node: %s Not Const", n->GetName().c_str(), index, src_node->GetName().c_str()); continue; } @@ -233,7 +232,6 @@ Status ModelBuilder::AdjustConstWeightSize(const ge::NodePtr &node, size_t &mem_ Status ModelBuilder::SetInputOutputDesc() { Status ret; - GELOGI("Start to SetInputOutputDesc."); for (const ge::NodePtr &n : compute_graph_->GetNodes(compute_graph_->GetGraphUnknownFlag())) { auto node_op_desc = n->GetOpDesc(); @@ -246,7 +244,6 @@ Status ModelBuilder::SetInputOutputDesc() { // final graph. if ((GetLocalOmgContext().format == domi::DOMI_TENSOR_ND) && (!node_op_desc->HasAttr("_is_single_op")) && ((node_op_desc->GetType() == DATA_TYPE) || (node_op_desc->GetType() == NETOUTPUT))) { - GELOGI("The node [%s] format should be set ND.", node_op_desc->GetName().c_str()); auto inputDescsPtr = node_op_desc->GetAllInputsDescPtr(); auto outputDescsPtr = node_op_desc->GetAllOutputsDescPtr(); ge::Format format = ge::FORMAT_ND; @@ -291,7 +288,7 @@ void ModelBuilder::AddNodeInputProperty() { vector src_index_list; for (const auto &in_data_anchor : node->GetAllInDataAnchors()) { auto peer_out_anchor = in_data_anchor->GetPeerOutAnchor(); - GE_IF_BOOL_EXEC(peer_out_anchor == nullptr, GELOGW("peer_out_anchor is nullptr!"); continue); + GE_IF_BOOL_EXEC(peer_out_anchor == nullptr, continue); GE_IF_BOOL_EXEC(node_op_desc->HasAttr(MERGE_PRENODE_FLAG), continue); ge::NodePtr src_node = peer_out_anchor->GetOwnerNode(); @@ -348,7 +345,6 @@ void ModelBuilder::AddNodeInputProperty() { } Status ModelBuilder::AdjustInputTensorFlag() { - GELOGI("Start to AdjustInputTensorFlag."); for (const ge::NodePtr &n : compute_graph_->GetNodes(compute_graph_->GetGraphUnknownFlag())) { if ((n->GetType() == DATA_TYPE) || (n->GetType() == AIPP_DATA_TYPE)) { GELOGD("Data node: %s.", n->GetName().c_str()); @@ -442,7 +438,6 @@ Status ModelBuilder::BuildModelDef(ge::Model &model) { return FAILED); const DumpProperties &dump_properties = PropertiesManager::Instance().GetDumpProperties(session_id_); bool is_op_debug = dump_properties.IsOpDebugOpen(); - GELOGI("Get op debug:%d", is_op_debug); if (is_op_debug) { if (!ge::AttrUtils::SetBool(&model, ATTR_OP_DEBUG_FLAG, is_op_debug)) { GELOGE(FAILED, "SetBool of ATTR_OP_DEBUG_FLAG failed."); @@ -611,7 +606,6 @@ Status ModelBuilder::SaveDataToModel(ge::Model &model, ge::GeModel &ge_model) { } tbe_name_set.insert(tbe_kernel->GetName()); tbe_kernel_store_.AddTBEKernel(tbe_kernel); - GELOGI("Add tbe kernel bin %s", tbe_kernel->GetName().c_str()); } for (const ge::NodePtr &n : compute_graph_->GetNodes(compute_graph_->GetGraphUnknownFlag())) { @@ -681,7 +675,6 @@ Status ModelBuilder::PreBuildModel() { GELOGE(FAILED, "Graph_ is not valid."); return FAILED; } - GELOGI("BuildModel begin."); GE_CHK_STATUS_RET(SetInputOutputDesc(), "SetInputOutputDesc Failed!"); diff --git a/src/ge/graph/build/run_context.cc b/src/ge/graph/build/run_context.cc index 35f68186..21a8fc35 100644 --- a/src/ge/graph/build/run_context.cc +++ b/src/ge/graph/build/run_context.cc @@ -141,7 +141,7 @@ void RunContextUtil::DestroyRtModelResources() noexcept { Status RunContextUtil::CreateRunContext(Model &model, const ComputeGraphPtr &graph, Buffer &buffer, const uint64_t session_id) { - GELOGI("Begin to Create RunContext, session_id = %lu", session_id); + GELOGD("Begin to Create RunContext, session_id = %lu", session_id); // check params if (graph == nullptr) { GELOGE(PARAM_INVALID, "CreateRunContext param graph is null. session_id=%lu", session_id); @@ -153,21 +153,21 @@ Status RunContextUtil::CreateRunContext(Model &model, const ComputeGraphPtr &gra GELOGE(INTERNAL_ERROR, "Get stream_num attr from model_def failed. session_id=%lu", session_id); return INTERNAL_ERROR; } - GELOGI("Stream_num = %u", stream_num); + GELOGD("Stream_num = %u", stream_num); uint32_t event_num = 0; if (!AttrUtils::GetInt(&model, ATTR_MODEL_EVENT_NUM, event_num)) { GELOGE(INTERNAL_ERROR, "Get event_num attr from model failed. session_id=%lu", session_id); return INTERNAL_ERROR; } - GELOGI("Event_num = %u", event_num); + GELOGD("Event_num = %u", event_num); uint32_t label_num = 0; if (!AttrUtils::GetInt(&model, ATTR_MODEL_LABEL_NUM, label_num)) { GELOGE(INTERNAL_ERROR, "Get label_num attr from model failed. session_id=%lu", session_id); return INTERNAL_ERROR; } - GELOGI("Label_num = %u", label_num); + GELOGD("Label_num = %u", label_num); Status ret = CreateRtModelResources(stream_num, event_num, label_num); if (ret != SUCCESS) { @@ -199,11 +199,11 @@ Status RunContextUtil::CreateRunContext(Model &model, const ComputeGraphPtr &gra void RunContextUtil::PrintMemInfo() { for (auto iter : mem_type_to_data_mem_base_) { - GELOGI("CreateRunContext: memory type = %ld, data memory base = %p", iter.first, iter.second); + GELOGD("CreateRunContext: memory type = %ld, data memory base = %p", iter.first, iter.second); } for (auto iter : mem_type_to_data_mem_size_) { - GELOGI("CreateRunContext: memory type = %ld, data memory size = %lu", iter.first, iter.second); + GELOGD("CreateRunContext: memory type = %ld, data memory size = %lu", iter.first, iter.second); } } diff --git a/src/ge/graph/build/stream_allocator.cc b/src/ge/graph/build/stream_allocator.cc index bcfea1d8..f4a9444a 100644 --- a/src/ge/graph/build/stream_allocator.cc +++ b/src/ge/graph/build/stream_allocator.cc @@ -67,11 +67,10 @@ StreamAllocator::StreamAllocator(ComputeGraphPtr whole_graph, const Graph2SubGra } enable_single_stream_ = (single_stream_str == kTrueStr) ? true : false; - GELOGI("Enable single stream: %s.", enable_single_stream_ ? kTrueStr : kFalseStr); + GELOGD("Enable single stream: %s.", enable_single_stream_ ? kTrueStr : kFalseStr); } Status StreamAllocator::AssignLogicalStreams(const std::map &max_parallel_num, bool hcom_parallel) { - GELOGI("Assign logical streams start."); GE_CHECK_NOTNULL(whole_graph_); GE_DUMP(whole_graph_, "BeforeAssignedLogicalStreams"); @@ -92,15 +91,12 @@ Status StreamAllocator::AssignLogicalStreams(const std::map &m return status; } GE_DUMP(whole_graph_, "AfterAssignedLogicalStreams"); - GELOGI("Assign logical streams success."); - return SUCCESS; } // After allocating the logical stream in the graph, refresh the stream in the // graph and insert the synchronization node. Status StreamAllocator::RefreshRealStream(int64_t &stream_num, int64_t &event_num) { - GELOGI("RefreshRealStream start."); GE_CHECK_NOTNULL(whole_graph_); GE_DUMP(whole_graph_, "BeforeRefreshRealStream"); @@ -174,8 +170,7 @@ Status StreamAllocator::RefreshRealStream(int64_t &stream_num, int64_t &event_nu GELOGI("None of nodes need to assign stream, stream num is 0, it will cause error, so change it to 1"); stream_num_ = 1; } - GELOGI("stream num: %ld, event num: %u.", stream_num_, event_num_); - GELOGI("RefreshRealStream successfully."); + GELOGD("stream num: %ld, event num: %u.", stream_num_, event_num_); stream_num = stream_num_; event_num = static_cast(event_num_); @@ -1241,7 +1236,7 @@ void StreamAllocator::DumpEvents() { for (const auto &one_pair : after_refresh_stream_nodes) { int64_t stream_id = one_pair.first; - GELOGI("After RefreshRealStream: stream %ld.", stream_id); + GELOGD("After RefreshRealStream: stream %ld.", stream_id); for (const auto &node : one_pair.second) { string send_event_str; @@ -1273,7 +1268,7 @@ Status StreamAllocator::GetMaxStreamAndTask(bool huge_stream, uint32_t &max_stre GELOGE(FAILED, "Get max stream and task count by rts failed."); return FAILED; } - GELOGI("Allowed max stream count: %u, max task count per stream: %u.", max_stream_count, max_task_count); + GELOGD("Allowed max stream count: %u, max task count per stream: %u.", max_stream_count, max_task_count); return SUCCESS; } diff --git a/src/ge/graph/build/stream_graph_optimizer.cc b/src/ge/graph/build/stream_graph_optimizer.cc index 49ecc674..7e8709a0 100644 --- a/src/ge/graph/build/stream_graph_optimizer.cc +++ b/src/ge/graph/build/stream_graph_optimizer.cc @@ -31,7 +31,7 @@ StreamGraphOptimizer::~StreamGraphOptimizer() {} void StreamGraphOptimizer::RefreshNodeId(const ComputeGraphPtr &comp_graph, Graph2SubGraphInfoList &subgraph_map) { size_t node_size = comp_graph->GetAllNodesSize(); - GELOGI("Refresh placeholder and end nodeId start from node num: %zu", node_size); + GELOGD("Refresh placeholder and end nodeId start from node num: %zu", node_size); for (const auto &subgraph_pair : subgraph_map) { for (const auto &subgraph_info : subgraph_pair.second) { ComputeGraphPtr subgraph = subgraph_info->GetSubGraph(); @@ -75,8 +75,6 @@ bool StreamGraphOptimizer::IsSameStreamId(const ComputeGraphPtr &comp_graph) { Status StreamGraphOptimizer::OptimizeStreamedSubGraph(const ComputeGraphPtr &comp_graph, Graph2SubGraphInfoList &subgraph_map, struct RunContext &run_context) { - GELOGI("Optimize streamed subgraph start."); - RefreshNodeId(comp_graph, subgraph_map); std::shared_ptr instance = ge::GELib::GetInstance(); @@ -87,7 +85,7 @@ Status StreamGraphOptimizer::OptimizeStreamedSubGraph(const ComputeGraphPtr &com ComputeGraphPtr subgraph = subgraph_info->GetSubGraph(); GE_CHECK_NOTNULL(subgraph); - GELOGI("Optimize subgraph %s", subgraph->GetName().c_str()); + GELOGD("Optimize subgraph %s", subgraph->GetName().c_str()); std::string engine_name = subgraph_info->GetEngineName(); @@ -129,7 +127,7 @@ Status StreamGraphOptimizer::OptimizeStreamedSubGraph(const ComputeGraphPtr &com subgraph->GetName().c_str(), engine_name.c_str(), graph_optimizers.size(), ret); return ret; } - GELOGI( + GELOGD( "[optimizeStreamedSubGraph]: optimize streamed subgraph success, subgraph: %s, engine_name: %s, graph " "Optimizer num: %zu!", subgraph->GetName().c_str(), engine_name.c_str(), graph_optimizers.size()); @@ -138,7 +136,7 @@ Status StreamGraphOptimizer::OptimizeStreamedSubGraph(const ComputeGraphPtr &com } } - GELOGI("Optimize streamed subgraph success."); + GELOGD("Optimize streamed subgraph success."); return SUCCESS; } } // namespace ge diff --git a/src/ge/graph/build/task_generator.cc b/src/ge/graph/build/task_generator.cc index 7d47b611..d3db8e5a 100644 --- a/src/ge/graph/build/task_generator.cc +++ b/src/ge/graph/build/task_generator.cc @@ -68,7 +68,7 @@ TaskGenerator::TaskGenerator(uint8_t *var_mem_base, uint64_t var_mem_size) { TaskGenerator::~TaskGenerator() {} Status TaskGenerator::GetTaskInfo(Model &model, ComputeGraphPtr &graph, uint64_t session_id, RunContext &run_context) { - GELOGI("Begin to Get TaskInfo. session_id=%lu", session_id); + GELOGD("Begin to Get TaskInfo. session_id=%lu", session_id); // Check params if (graph == nullptr) { GELOGE(PARAM_INVALID, "GetTaskInfo param graph is null. session_id=%lu", session_id); @@ -120,7 +120,7 @@ Status TaskGenerator::GetTaskInfo(Model &model, ComputeGraphPtr &graph, uint64_t return ret; } - GELOGI("Get TaskInfo success. session_id=%lu", session_id); + GELOGD("Get TaskInfo success. session_id=%lu", session_id); return SUCCESS; } @@ -232,7 +232,7 @@ Status TaskGenerator::SaveFusionNodes(map> &fusion } } } - GELOGI("Fusion: get fusion group numbers [%zu].", fusion_nodes.size()); + GELOGD("Fusion: get fusion group numbers [%zu].", fusion_nodes.size()); return SUCCESS; } @@ -573,7 +573,7 @@ Status TaskGenerator::MarkFirstAndLastOps(const vector &ops, bool is_ continuous_op_lists.back().emplace_back(op_desc); } } - GELOGI("Number of continuous node lists is %zu.", continuous_op_lists.size()); + GELOGD("Number of continuous node lists is %zu.", continuous_op_lists.size()); for (const auto &continuous_ops : continuous_op_lists) { map> first_and_last_ops; @@ -841,13 +841,12 @@ Status TaskGenerator::GetFpBpIndex(const ComputeGraphPtr &graph, ProfilingPoint Status TaskGenerator::FindProfilingTaskIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point, vector &all_reduce_nodes) const { - GELOGI("Start FindProfilingTaskIndex."); GE_CHECK_NOTNULL(graph); const char *profiling_mode = std::getenv(kProfilingMode); bool is_profiling = (profiling_mode != nullptr) || ProfilingManager::Instance().ProfilingOn() || ProfilingManager::Instance().ProfilingTrainingTraceOn(); if (!is_profiling) { - GELOGW("Profiling is not open."); + GELOGD("Profiling is not open."); return SUCCESS; } diff --git a/src/ge/graph/execute/graph_execute.cc b/src/ge/graph/execute/graph_execute.cc index e1322180..a828bd2d 100644 --- a/src/ge/graph/execute/graph_execute.cc +++ b/src/ge/graph/execute/graph_execute.cc @@ -91,7 +91,7 @@ Status GraphExecutor::SetDynamicSize(uint32_t model_id, const std::vectorSetDynamicSize(model_id, batch_num, dynamic_type); if (ret != SUCCESS) { - GELOGE(FAILED, "SetDynamicSize failed"); + GELOGE(ret, "SetDynamicSize failed"); return ret; } return SUCCESS; @@ -115,7 +115,7 @@ Status GraphExecutor::FreeInOutBuffer() { malloc_flag_ = false; return SUCCESS; } else { - GELOGI("[GraphManager] not malloc buffer."); + GELOGD("[GraphManager] not malloc buffer."); return SUCCESS; } } diff --git a/src/ge/graph/load/graph_loader.cc b/src/ge/graph/load/graph_loader.cc index c173d67a..0b17b721 100644 --- a/src/ge/graph/load/graph_loader.cc +++ b/src/ge/graph/load/graph_loader.cc @@ -212,9 +212,9 @@ Status GraphLoader::CommandHandle(const Command &command) { return ret; } } catch (std::bad_alloc &) { - GELOGE(MEMALLOC_FAILED, "Command handle failed, bad memory allocation occur !"); + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Command handle failed, bad memory allocation occur !"); - return MEMALLOC_FAILED; + return ACL_ERROR_GE_MEMORY_ALLOCATION; } catch (...) { GELOGE(FAILED, "Command handle failed, some exceptions occur !"); @@ -285,7 +285,7 @@ Status GraphLoader::ExecuteModel(uint32_t model_id, rtStream_t stream, bool asyn return ret; } - GELOGI("Execute model success, model_id:%u.", model_id); + GELOGD("Execute model success, model_id:%u.", model_id); return SUCCESS; } diff --git a/src/ge/graph/load/new_model_manager/cpu_queue_schedule.cc b/src/ge/graph/load/new_model_manager/cpu_queue_schedule.cc index 01e1cfa8..f521b2d4 100644 --- a/src/ge/graph/load/new_model_manager/cpu_queue_schedule.cc +++ b/src/ge/graph/load/new_model_manager/cpu_queue_schedule.cc @@ -131,7 +131,7 @@ Status CpuTaskZeroCopy::Init(std::vector &mbuf_list, std::map(reinterpret_cast(virtual_args_addr.second.at(i)))); + dst_addrs.push_back(static_cast(reinterpret_cast(virtual_args_addr.second.at(i)))); } } index++; diff --git a/src/ge/graph/load/new_model_manager/data_dumper.cc b/src/ge/graph/load/new_model_manager/data_dumper.cc index 10c26d87..5160cc9f 100644 --- a/src/ge/graph/load/new_model_manager/data_dumper.cc +++ b/src/ge/graph/load/new_model_manager/data_dumper.cc @@ -159,7 +159,6 @@ void DataDumper::SetLoopAddr(void *global_step, void *loop_per_iter, void *loop_ } void DataDumper::SaveDumpInput(const std::shared_ptr &node) { - GELOGI("Start to save data %s message", node->GetName().c_str()); if (node != nullptr) { auto input_op_desc = node->GetOpDesc(); if (input_op_desc == nullptr) { @@ -180,7 +179,6 @@ void DataDumper::SaveDumpInput(const std::shared_ptr &node) { {op_desc->GetName(), {input_op_desc, dst_in_data_anchor->GetIdx(), out_data_anchor->GetIdx()}}); } } - GELOGI("Save data message successfully"); } } @@ -218,7 +216,7 @@ void DataDumper::SaveDumpOpInfo(const RuntimeParam &model_param, const OpDescPtr GELOGW("Get input size failed"); return; } - GELOGI("Save dump op info, the input size is %ld", input_size); + GELOGD("Save dump op info, the input size is %ld", input_size); op_desc_info.input_size.emplace_back(input_size); } for (size_t j = 0; j < op->GetOutputsSize(); ++j) { @@ -234,7 +232,7 @@ void DataDumper::SaveDumpOpInfo(const RuntimeParam &model_param, const OpDescPtr GELOGW("Get input size failed"); return; } - GELOGI("Save dump op info, the output size is %ld", output_size); + GELOGD("Save dump op info, the output size is %ld", output_size); op_desc_info.output_size.emplace_back(output_size); } op_desc_info.input_addrs = ModelUtils::GetInputDataAddrs(model_param, op); @@ -301,22 +299,16 @@ static void SetOpMappingLoopAddr(uintptr_t step_id, uintptr_t loop_per_iter, uin if (step_id != 0) { GELOGI("step_id exists."); op_mapping_info.set_step_id_addr(static_cast(step_id)); - } else { - GELOGI("step_id is null."); } if (loop_per_iter != 0) { GELOGI("loop_per_iter exists."); op_mapping_info.set_iterations_per_loop_addr(static_cast(loop_per_iter)); - } else { - GELOGI("loop_per_iter is null."); } if (loop_cond != 0) { GELOGI("loop_cond exists."); op_mapping_info.set_loop_cond_addr(static_cast(loop_cond)); - } else { - GELOGI("loop_cond is null."); } } @@ -672,7 +664,7 @@ Status DataDumper::LoadDumpInfo() { PrintCheckLog(dump_list_key); if (op_list_.empty()) { - GELOGW("op_list_ is empty"); + GELOGD("op_list_ is empty"); } aicpu::dump::OpMappingInfo op_mapping_info; @@ -684,8 +676,6 @@ Status DataDumper::LoadDumpInfo() { op_mapping_info.set_flag(kAicpuLoadFlag); op_mapping_info.set_dump_step(dump_properties_.GetDumpStep()); SetOpMappingLoopAddr(global_step_, loop_per_iter_, loop_cond_, op_mapping_info); - GELOGI("Dump step is %s and dump path is %s dump model is %s in load dump info", - dump_properties_.GetDumpStep().c_str(), dump_path.c_str(), dump_list_key.c_str()); auto ret = BuildTaskInfo(op_mapping_info); if (ret != SUCCESS) { GELOGE(ret, "Build task info failed"); @@ -812,7 +802,6 @@ void DataDumper::SetOpDebugIdToAicpu(uint32_t task_id, uint32_t stream_id, void Status DataDumper::UnloadDumpInfo() { if (!load_flag_) { - GELOGI("No need to UnloadDumpInfo."); load_flag_ = false; return SUCCESS; } @@ -838,7 +827,6 @@ Status DataDumper::UnloadDumpInfo() { void DataDumper::PrintCheckLog(string &dump_list_key) { std::set model_list = dump_properties_.GetAllDumpModel(); if (model_list.empty()) { - GELOGI("No model need dump."); return; } diff --git a/src/ge/graph/load/new_model_manager/davinci_model.cc b/src/ge/graph/load/new_model_manager/davinci_model.cc index faa7da59..7a348c17 100644 --- a/src/ge/graph/load/new_model_manager/davinci_model.cc +++ b/src/ge/graph/load/new_model_manager/davinci_model.cc @@ -17,11 +17,7 @@ #include "graph/load/new_model_manager/davinci_model.h" #include -#include #include -#include -#include -#include #include #include #include @@ -62,6 +58,8 @@ #include "runtime/rt_model.h" #include "runtime/stream.h" #include "securec.h" +#include "graph/common/local_context.h" +#include "common/formats/utils/formats_trans_utils.h" // create std::thread, catch exceptions using try/catch #define CREATE_STD_THREAD(thread_id, func, args) \ @@ -80,6 +78,7 @@ namespace { const uint32_t kDataIndex = 0; const uint32_t kOutputNum = 1; const uint32_t kTrueBranchStreamNum = 1; +const uint32_t kGetDynamicDimsCount = 1; const uint32_t kThreadNum = 16; const uint32_t kAddrLen = sizeof(void *); const int kDecimal = 10; @@ -88,9 +87,12 @@ const uint32_t kDataMemAlignSizeCompare = 64; const uint32_t kDumpL1FusionOpMByteSize = 2 * 1024 * 1024; const uint32_t kDumpFlagOfL1Fusion = 0; const char *const kDefaultBatchLable = "Batch_default"; +const char *const kGetDynamicDimsName = "ascend_mbatch_get_dynamic_dims_node"; const int32_t kInvalidStream = -1; const uint32_t kEndOfSequence = 0x0704000a; const uint32_t kEndOfSequenceNew = 507005; +const int32_t kModelAbortNormal = 0x0704000e; +const int32_t kModelAbortNormalNew = 507024; inline bool IsDataOp(const std::string &node_type) { return node_type == DATA_TYPE || node_type == AIPP_DATA_TYPE || node_type == ANN_DATA_TYPE; @@ -201,7 +203,6 @@ DavinciModel::~DavinciModel() { OpDebugUnRegister(); - GELOGI("do ReleaseTask"); ReleaseTask(); CleanTbeHandle(); @@ -332,7 +333,6 @@ Status DavinciModel::InitModelMem(void *dev_ptr, size_t mem_size, void *weight_p GELOGI("[IMAS]InitModelMem graph_%u MallocMemory type[W] memaddr[%p] mem_size[%zu]", runtime_param_.graph_id, weights_mem_base_, weights_size); GE_CHK_RT_RET(rtMemcpy(weights_mem_base_, weights_size, weights.GetData(), weights_size, RT_MEMCPY_HOST_TO_DEVICE)); - GELOGI("copy weights data to device"); } GE_CHK_STATUS_RET(InitVariableMem(), "Init variable memory failed."); @@ -483,7 +483,7 @@ Status DavinciModel::SetTSDevice() { int64_t value = 0; bool ret = ge::AttrUtils::GetInt(ge_model_, ATTR_MODEL_CORE_TYPE, value); uint32_t core_type = ret ? static_cast(value) : 0; - GELOGI("SetTSDevice: %u", core_type); + GELOGD("SetTSDevice: %u", core_type); rtError_t rt_ret = rtSetTSDevice(core_type); if (rt_ret != RT_ERROR_NONE) { GELOGE(RT_FAILED, "SetTSDevice failed, ret: 0x%X", rt_ret); @@ -538,7 +538,6 @@ Status DavinciModel::OpDebugRegister() { } void DavinciModel::OpDebugUnRegister() { - GELOGI("OpDebugUnRegister, is_op_debug_reg_ = %d", is_op_debug_reg_); if (is_op_debug_reg_) { debug_reg_mutex_.unlock(); rtError_t rt_ret = RT_ERROR_NONE; @@ -643,7 +642,7 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size GE_CHK_STATUS_RET(TransVarDataUtils::CopyVarData(compute_graph, session_id_, device_id_), "copy var data failed."); GE_TIMESTAMP_START(InitModelMem); - GELOGI("Known node is %d", known_node_); + GELOGD("Known node is %d", known_node_); if (!known_node_) { GE_CHK_STATUS_RET_NOLOG(InitModelMem(dev_ptr, mem_size, weight_ptr, weight_size)); data_inputer_ = new (std::nothrow) DataInputer(); @@ -703,7 +702,6 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size } Shrink(); - GELOGI("Davinci model init success."); return ret; } @@ -896,7 +894,6 @@ Status DavinciModel::InitNodes(const ComputeGraphPtr &compute_graph) { } GE_TIMESTAMP_ADD(InitTbeHandle); } - AdjustDataOpList(data_by_index); GE_TIMESTAMP_CALLNUM_END(LoadTBEKernelBinToOpDesc, "GraphLoader::LoadTBEKernelBinToOpDesc."); GE_TIMESTAMP_CALLNUM_END(InitTbeHandle, "GraphLoader::InitTbeHandle."); @@ -964,18 +961,21 @@ Status DavinciModel::InitDataOp(const NodePtr &node, uint32_t &data_op_index, ma const vector output_size_list = ModelUtils::GetOutputSize(op_desc); const vector virtual_addr_list = ModelUtils::GetOutputDataAddrs(runtime_param_, op_desc); const vector output_offset_list = op_desc->GetOutputOffset(); - if (output_offset_list.size() != virtual_addr_list.size()) { - GELOGE(PARAM_INVALID, "virtual_addr size:%zu should be equal to offset size:%zu.", virtual_addr_list.size(), - output_offset_list.size()); + if (output_size_list.empty() || virtual_addr_list.empty() || (output_size_list.size() != virtual_addr_list.size()) || + (output_offset_list.size() != virtual_addr_list.size())) { + GELOGE(PARAM_INVALID, "Data[%s] init failed: output size is %zu, virtual_addr size is %zu, offset size is %zu.", + op_desc->GetName().c_str(), output_size_list.size(), virtual_addr_list.size(), output_offset_list.size()); return PARAM_INVALID; } auto data_index = data_op_index; if (AttrUtils::GetInt(op_desc, ATTR_NAME_INDEX, data_index)) { - GELOGI("ge_train: get new index %u, old %u", data_index, data_op_index); + GELOGD("ge_train: get new index %u, old %u", data_index, data_op_index); } bool fusion_flag = false; ZeroCopyOffset zero_copy_offset; - Status ret = zero_copy_offset.InitInputDataInfo(output_size_list, virtual_addr_list, op_desc, fusion_flag); + int64_t data_size = output_size_list[kDataIndex]; + void *virtual_addr = virtual_addr_list[kDataIndex]; + Status ret = zero_copy_offset.InitInputDataInfo(data_size, virtual_addr, op_desc, fusion_flag); if (ret != SUCCESS) { GELOGE(PARAM_INVALID, "InitDataInfo of input_info %s failed.", op_desc->GetName().c_str()); return PARAM_INVALID; @@ -992,7 +992,6 @@ Status DavinciModel::InitDataOp(const NodePtr &node, uint32_t &data_op_index, ma new_input_outside_addrs_[addr] = zero_copy_offset; } - GELOGI("SetInputOutsideAddr success."); data_op_index++; if (InitInputZeroCopyNodes(node) != SUCCESS) { GELOGE(PARAM_INVALID, "Input zero copy nodes init failed!"); @@ -1052,6 +1051,15 @@ Status DavinciModel::InitInputZeroCopyNodes(const NodePtr &node) { return SUCCESS; } +bool DavinciModel::IsGetNextSinkDynamic(const OpDescPtr &op_desc) { + bool getnext_sink_dynamic = false; + if (ge::AttrUtils::GetBool(op_desc, ATTR_GETNEXT_SINK_DYNMAIC, getnext_sink_dynamic) && getnext_sink_dynamic) { + GELOGI("ATTR_GETNEXT_SINK_DYNMAIC has been set and is true."); + return true; + } + return false; +} + /// @ingroup ge /// @brief NetOutput Op Initialize. /// @param [in] NodePtr: NetOutput Op. @@ -1076,10 +1084,9 @@ Status DavinciModel::InitNetOutput(const NodePtr &node) { const vector input_size_list = ModelUtils::GetInputSize(op_desc); const vector virtual_addr_list = ModelUtils::GetInputDataAddrs(runtime_param_, op_desc); const vector input_offset_list = op_desc->GetInputOffset(); - if (input_offset_list.size() != virtual_addr_list.size()) { - GELOGE(PARAM_INVALID, "virtual_addr size should be equal to offset size."); - return PARAM_INVALID; - } + GE_IF_BOOL_EXEC(input_offset_list.size() != virtual_addr_list.size(), + GELOGE(PARAM_INVALID, "virtual_addr size should be equal to offset size."); + return PARAM_INVALID;); if (input_size_list.empty() && virtual_addr_list.empty()) { GELOGI("NetOutput[%s] is empty.", op_desc->GetName().c_str()); return SUCCESS; @@ -1093,13 +1100,18 @@ Status DavinciModel::InitNetOutput(const NodePtr &node) { size_t num = new_output_data_info_.size(); bool fusion_flag = false; - for (size_t idx = 0; idx < input_size_list.size(); ++idx) { + size_t input_count = input_size_list.size(); + is_getnext_sink_dynamic_ = false; + if (IsGetNextSinkDynamic(op_desc)) { + input_count = input_size_list.size() - kGetDynamicDimsCount; + is_getnext_sink_dynamic_ = true; + } + for (size_t idx = 0; idx < input_count; ++idx) { ZeroCopyOffset zero_copy_offset; Status ret = zero_copy_offset.InitOutputDataInfo(input_size_list, virtual_addr_list, op_desc, idx, fusion_flag); - if (ret != SUCCESS) { - GELOGE(PARAM_INVALID, "InitDataInfo of input_info %s failed.", op_desc->GetName().c_str()); - return PARAM_INVALID; - } + GE_IF_BOOL_EXEC(ret != SUCCESS, + GELOGE(PARAM_INVALID, "InitDataInfo of input_info %s failed.", op_desc->GetName().c_str()); + return PARAM_INVALID;); new_output_data_info_[num + idx] = zero_copy_offset; void *addr = virtual_addr_list.at(idx); int64_t input_offset = input_offset_list.at(idx); @@ -1116,17 +1128,206 @@ Status DavinciModel::InitNetOutput(const NodePtr &node) { DisableZeroCopy(real_addr); real_virtual_addrs_.insert(real_addr); } - GELOGI("SetOutputOutsideAddr success."); } - if (InitOutputZeroCopyNodes(node) != SUCCESS) { - GELOGE(PARAM_INVALID, "Output zero copy nodes init failed!"); + GE_IF_BOOL_EXEC(InitOutputZeroCopyNodes(node) != SUCCESS, + GELOGE(PARAM_INVALID, "Output zero copy nodes init failed!"); + return PARAM_INVALID;); + GetAllGearsInfo(node); + if (is_getnext_sink_dynamic_) { + GE_IF_BOOL_EXEC(GetGetDynamicDimsNodeInfo(node) != SUCCESS, + GELOGE(PARAM_INVALID, "Failed to get info of getdynamicdims node."); + return PARAM_INVALID;); + } + if (is_online_infer_dynamic_) { + GE_IF_BOOL_EXEC(GetGearAndRealOutSizeInfo(input_count, node) != SUCCESS, + GELOGE(PARAM_INVALID, "Failed to get gear and real out size info."); + return PARAM_INVALID;); + GE_IF_BOOL_EXEC(GetGearAndRealOutShapeInfo(input_count, op_desc) != SUCCESS, + GELOGE(PARAM_INVALID, "Failed to get gear and real out shape info."); + return PARAM_INVALID;); + } + return SUCCESS; +} + +void DavinciModel::GetAllGearsInfo(const NodePtr &node) { + is_online_infer_dynamic_ = false; + all_gears_info_.clear(); + std::string shapes; + (void)AttrUtils::GetStr(node->GetOpDesc(), ATTR_ALL_GEARS_INFO, shapes); + if (!shapes.empty()) { + is_online_infer_dynamic_ = true; + std::vector shape_strs = ge::StringUtils::Split(shapes, ';'); + for (const auto &shape_str : shape_strs) { + if (shape_str.empty()) { + continue; + } + std::vector gear_info; + std::vector dims = ge::StringUtils::Split(shape_str, ','); + for (const auto &dim : dims) { + if (dim.empty()) { + continue; + } + gear_info.emplace_back(std::strtol(dim.c_str(), nullptr, kDecimal)); + } + if (!gear_info.empty()) { + all_gears_info_.emplace_back(gear_info); + GELOGD("Init all gears info from %s, gaer info is %s.", node->GetName().c_str(), + formats::JoinToString(gear_info).c_str()); + } + } + } +} +Status DavinciModel::GetGetDynamicDimsNodeInfo(const NodePtr &node) { + GE_CHECK_NOTNULL(node->GetOpDesc()); + size_t input_count = node->GetAllInDataAnchors().size(); + GELOGI("input_anchor count of %s is %zu.", node->GetName().c_str(), input_count); + size_t get_dynamic_dims_index = input_count - kGetDynamicDimsCount; + auto in_anchor = node->GetAllInDataAnchors().at(get_dynamic_dims_index); + auto peer_out_anchor = in_anchor->GetPeerOutAnchor(); + if (peer_out_anchor == nullptr) { + GELOGE(PARAM_INVALID, "Out anchor of getdynmaicdims node should not be nullptr."); return PARAM_INVALID; } - GELOGI("DavinciModel::InitNetoutput success."); + auto peer_node = peer_out_anchor->GetOwnerNode(); + auto op_desc = peer_node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + if (op_desc->GetName() == kGetDynamicDimsName && op_desc->GetType() == GETDYNAMICDIMS) { + GELOGD("Start get info of %s.", op_desc->GetName().c_str()); + auto input_addr = ModelUtils::GetInputDataAddrs(runtime_param_, node->GetOpDesc()); + auto input_size = ModelUtils::GetInputSize(node->GetOpDesc()); + if (input_addr.empty() || input_size.empty()) { + GELOGE(PARAM_INVALID, "Not set output of %s", op_desc->GetName().c_str()); + return PARAM_INVALID; + } + auto input_desc = node->GetOpDesc()->GetInputDescPtr(get_dynamic_dims_index); + GE_CHECK_NOTNULL(input_desc); + if (input_desc->GetShape().GetDims().empty()) { + GELOGE(PARAM_INVALID, "Not set output desc shape of %s.", op_desc->GetName().c_str()); + return PARAM_INVALID; + } + netoutput_last_input_addr_ = input_addr[get_dynamic_dims_index]; + netoutput_last_input_size_ = input_size[get_dynamic_dims_index]; + shape_of_cur_dynamic_dims_ = input_desc->GetShape().GetDims().at(0); + GELOGD("Shape of cur dynamic dims is %zu, size is %ld, addr is %p.", shape_of_cur_dynamic_dims_, + netoutput_last_input_size_, netoutput_last_input_addr_); + } + return SUCCESS; +} + +Status DavinciModel::GetGearAndRealOutSizeInfo(size_t input_count, const NodePtr &node) { + GELOGD("Start get gear and real output size info of %s, input count is %zu.", node->GetName().c_str(), input_count); + merge_nodes_gear_and_real_out_size_info_.clear(); + for (size_t idx = 0; idx < input_count; ++idx) { + auto in_anchor = node->GetAllInDataAnchors().at(idx); + auto peer_out_anchor = in_anchor->GetPeerOutAnchor(); + if (peer_out_anchor == nullptr) { + continue; + } + auto peer_node = peer_out_anchor->GetOwnerNode(); + auto op_desc = peer_node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + if ((peer_node->GetType() == MERGE) && (op_desc->HasAttr(ATTR_INSERT_BY_MBATCH))) { + if (GetRealOutputSizeOfMerge(idx, peer_node) != SUCCESS) { + GELOGE(PARAM_INVALID, "Get real output size of %s failed.", peer_node->GetName().c_str()); + return PARAM_INVALID; + } + } + } return SUCCESS; } +Status DavinciModel::GetRealOutputSizeOfMerge(size_t input_index, const NodePtr &merge_node) { + GELOGD("Start get output size of %s, which is %zu input to netoutput.", merge_node->GetName().c_str(), input_index); + std::map, int64_t> gear_and_real_out_size_info; + for (auto &in_anchor : merge_node->GetAllInDataAnchors()) { + auto peer_out_anchor = in_anchor->GetPeerOutAnchor(); + if (peer_out_anchor == nullptr) { + continue; + } + auto in_node = peer_out_anchor->GetOwnerNode(); + GELOGD("Input node of merge is %s.", in_node->GetName().c_str()); + auto op_desc = in_node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + string batch_label; + if (AttrUtils::GetStr(op_desc, ATTR_NAME_BATCH_LABEL, batch_label)) { + size_t batch_index = static_cast(stoi(batch_label.substr(batch_label.rfind('_') + 1))); + GELOGD("Batch index of %s is %zu.", op_desc->GetName().c_str(), batch_index); + if (batch_index > all_gears_info_.size()) { + GELOGE(PARAM_INVALID, "The value of ATTR_NAME_BATCH_LABEL is invalid."); + return PARAM_INVALID; + } + + const vector output_size_list = ModelUtils::GetOutputSize(op_desc); + int output_index = ge::AnchorUtils::GetIdx(peer_out_anchor); + auto tensor_desc = op_desc->GetOutputDescPtr(output_index); + GE_CHECK_NOTNULL(tensor_desc); + int64_t data_size = 0; + if (TensorUtils::GetTensorSizeInBytes(*tensor_desc, data_size) != GRAPH_SUCCESS) { + GELOGE(FAILED, "Get tensor size in bytes failed."); + return FAILED; + } + gear_and_real_out_size_info[all_gears_info_[batch_index]] = data_size; + GELOGD("Get real gear index is: %zu, gear info is %s, size is %ld, tensor size is %ld", batch_index, + formats::JoinToString(all_gears_info_[batch_index]).c_str(), output_size_list[output_index], data_size); + } + } + merge_nodes_gear_and_real_out_size_info_[input_index] = gear_and_real_out_size_info; + return SUCCESS; +} + +Status DavinciModel::GetGearAndRealOutShapeInfo(size_t input_count, const OpDescPtr &op_desc) { + GELOGD("Start to get dynamic output dims of %s.", op_desc->GetName().c_str()); + merge_nodes_gear_and_real_out_shape_info_.clear(); + std::vector dynamic_output_shape_info; + if (!AttrUtils::GetListStr(op_desc, ATTR_NAME_DYNAMIC_OUTPUT_DIMS, dynamic_output_shape_info)) { + GELOGD("Can not get dynamic output dims attr"); + return SUCCESS; + } + GELOGI("Dynamic output shape info is %s", formats::JoinToString(dynamic_output_shape_info).c_str()); + std::vector> dynamic_output_shape; + ParseDynamicOutShape(dynamic_output_shape_info, dynamic_output_shape); + // idx: input_index to netoutput + for (size_t idx = 0; idx < input_count; ++idx) { + std::map, vector> gear_and_real_out_shape_info; + for (auto &it : dynamic_output_shape) { + auto gear_index = static_cast(it[0]); + if (gear_index > all_gears_info_.size()) { + GELOGE(PARAM_INVALID, "The value of cur index: %zu is invalid.", static_cast(it[0])); + return PARAM_INVALID; + } + + if (static_cast(it[1]) == idx) { + vector output_shape; + for (size_t i = 2; i < it.size(); ++i) { + output_shape.emplace_back(it[i]); + } + gear_and_real_out_shape_info[all_gears_info_[gear_index]] = output_shape; + GELOGD("Get real gear index is: %zu, gear info is %s, output shape is %s.", gear_index, + formats::JoinToString(all_gears_info_[gear_index]).c_str(), formats::JoinToString(output_shape).c_str()); + } + } + merge_nodes_gear_and_real_out_shape_info_[idx] = gear_and_real_out_shape_info; + } + return SUCCESS; +} + +void DavinciModel::ParseDynamicOutShape(const std::vector &str_info, + std::vector> &vec_info) { + for (size_t i = 0; i < str_info.size(); ++i) { + std::vector shape; + std::vector dims = ge::StringUtils::Split(str_info[i], ','); + for (const auto &dim : dims) { + if (dim.empty()) { + continue; + } + shape.emplace_back(std::strtol(dim.c_str(), nullptr, kDecimal)); + } + GELOGI("Shape from attr is %s.", formats::JoinToString(shape).c_str()); + vec_info.emplace_back(shape); + } +} + /// /// @ingroup ge /// @brief output zero copy node Initialize. @@ -1254,7 +1455,7 @@ Status DavinciModel::InitLabelSet(const OpDescPtr &op_desc) { return INTERNAL_ERROR; } if (label_index >= LabelNum()) { - GELOGE(INTERNAL_ERROR, "InitLabelSet: label index: %u >= label size: %zu.", label_index, LabelNum()); + GELOGE(INTERNAL_ERROR, "InitLabelSet: label index: %u >= label size: %u.", label_index, LabelNum()); return INTERNAL_ERROR; } if (label_id_indication_.count(label_index) > 0) { @@ -1299,8 +1500,8 @@ Status DavinciModel::InitVariable(const OpDescPtr &op_desc) { Status DavinciModel::SetQueIds(const std::vector &input_queue_ids, const std::vector &output_queue_ids) { if (input_queue_ids.empty() && output_queue_ids.empty()) { - GELOGE(GE_EXEC_MODEL_QUEUE_ID_INVALID, "Param is empty"); - return GE_EXEC_MODEL_QUEUE_ID_INVALID; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID, "Param is empty"); + return ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID; } input_queue_ids_ = input_queue_ids; @@ -1321,15 +1522,16 @@ Status DavinciModel::LoadWithQueue() { } if (input_queue_ids_.size() != new_input_data_info_.size()) { - GELOGE(GE_EXEC_MODEL_QUEUE_ID_INVALID, "Input queue ids not match model: input_queue=%zu input_data=%zu", + GELOGE(ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID, "Input queue ids not match model: input_queue=%zu input_data=%zu", input_queue_ids_.size(), new_input_data_info_.size()); - return GE_EXEC_MODEL_QUEUE_ID_INVALID; + return ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID; } if (output_queue_ids_.size() != new_output_data_info_.size()) { - GELOGE(GE_EXEC_MODEL_QUEUE_ID_INVALID, "Output queue ids not match model: output_queue=%zu output_data=%zu", - output_queue_ids_.size(), new_output_data_info_.size()); - return GE_EXEC_MODEL_QUEUE_ID_INVALID; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID, + "Output queue ids not match model: output_queue=%zu output_data=%zu", output_queue_ids_.size(), + new_output_data_info_.size()); + return ACL_ERROR_GE_EXEC_MODEL_QUEUE_ID_INVALID; } GE_CHK_STATUS_RET(AddHeadStream(), "Add head stream failed."); @@ -1672,7 +1874,7 @@ Status DavinciModel::GetAIPPInfo(uint32_t index, AippConfigInfo &aipp_info) { OpDescPtr data_op = data_op_list_[index]; if (!data_op->HasAttr(ATTR_NAME_AIPP)) { GELOGW("GetAIPPInfo: there is not AIPP related with index %u.", index); - return GE_AIPP_NOT_EXIST; + return ACL_ERROR_GE_AIPP_NOT_EXIST; } std::unique_ptr aipp_params(new (std::nothrow) domi::AippOpParams()); @@ -1711,8 +1913,9 @@ Status DavinciModel::GetAippType(uint32_t index, InputAippType &type, size_t &ai } else if (data_mode == "dynamic_aipp_conf") { type = DYNAMIC_AIPP_NODE; } else { - GELOGE(INTERNAL_ERROR, "The info of aipp releated info %s is invalid with index %u.", data_mode.c_str(), index); - return INTERNAL_ERROR; + GELOGE(ACL_ERROR_GE_AIPP_MODE_INVALID, "The info of aipp releated info %s is invalid with index %u.", + data_mode.c_str(), index); + return ACL_ERROR_GE_AIPP_MODE_INVALID; } if (type == DATA_WITH_DYNAMIC_AIPP) { @@ -1726,8 +1929,8 @@ Status DavinciModel::GetAippType(uint32_t index, InputAippType &type, size_t &ai } } if (aipp_index == 0xFFFFFFFF) { - GELOGE(INTERNAL_ERROR, "Can not find aipp data node from index %u", index); - return INTERNAL_ERROR; + GELOGE(ACL_ERROR_GE_AIPP_NOT_EXIST, "Can not find aipp data node from index %u", index); + return ACL_ERROR_GE_AIPP_NOT_EXIST; } } return SUCCESS; @@ -1762,7 +1965,6 @@ void DavinciModel::GetModelAttr(std::vector &dynamic_output_shape_i if (op->GetType() != NETOUTPUT) { continue; } - GELOGI("Start to get dynamic output dims attr"); if (!AttrUtils::GetListStr(op, ATTR_NAME_DYNAMIC_OUTPUT_DIMS, dynamic_output_shape_info)) { GELOGD("Can not get dynamic output dims attr"); } @@ -1918,7 +2120,7 @@ void DavinciModel::CreateOutput(uint32_t index, OpDescPtr &op_desc, InputOutputD } Status DavinciModel::GetOutputDescInfo(vector &output_desc, std::vector &formats) { - GELOGI("Output node size: %zu", output_op_list_.size()); + GELOGD("Output node size: %zu", output_op_list_.size()); for (size_t i = 0; i < output_op_list_.size(); i++) { auto &op_desc = output_op_list_[i]; uint32_t out_size = static_cast(op_desc->GetInputsSize()); @@ -1981,7 +2183,7 @@ Status DavinciModel::CopyInputData(const InputData &input_data, bool device_data void *mem_addr = data.second.GetBasicAddr(); void *data_buf_addr = reinterpret_cast(reinterpret_cast(data_buf.data)); uint64_t data_buf_length = data_buf.length; - GELOGI("[IMAS]CopyPlainData memcpy graph_%lu type[F] input[%lu] dst[%p] src[%p] mem_size[%lu] datasize[%lu]", + GELOGI("[IMAS]CopyPlainData memcpy graph_%u type[F] input[%u] dst[%p] src[%p] mem_size[%lu] datasize[%lu]", runtime_param_.graph_id, data.first, mem_addr, data_buf_addr, data_size, data_buf_length); GE_CHK_RT_RET(rtMemcpy(mem_addr, data_size, data_buf_addr, data_buf_length, kind)); } @@ -2029,8 +2231,6 @@ Status DavinciModel::SinkModelProfile() { Msprof::Engine::Reporter *reporter = PluginImpl::GetPluginReporter(); GE_IF_BOOL_EXEC(reporter == nullptr, GELOGI("Profiling report is nullptr!"); return SUCCESS); - GELOGI("Start collect model load profiling data."); - Msprof::Engine::ReporterData reporter_data{}; // report model data tag name std::string tag_name; @@ -2088,7 +2288,6 @@ Status DavinciModel::SinkModelProfile() { uint32_t op_num = fusion_op_info->original_op_names.size(); uint32_t task_id = task->GetTaskID(); if (op_num > 0) { - GELOGI("task.id = %u, opNum = %u", task_id, op_num); op_id_map.insert(std::make_pair(fusion_op_info->op_index, task_id)); } } @@ -2325,6 +2524,7 @@ Status DavinciModel::CopyOutputData(uint32_t data_id, OutputData &output_data, r } std::vector &blobs = output_data.blobs; + size_t idx = 0; for (const auto &output : new_output_data_info_) { if (output.first >= blobs.size()) { GELOGE(FAILED, "Blobs not match: blobs=%zu, tensor=%zu, index=%u, size=%ld", blobs.size(), @@ -2345,18 +2545,26 @@ Status DavinciModel::CopyOutputData(uint32_t data_id, OutputData &output_data, r if (is_dynamic_) { GELOGI("No need to check output data size."); } else if (buffer.length < mem_size) { - GELOGE(FAILED, "Tensor data size=%lu, buffer size=%u", mem_size, buffer.length); + GELOGE(FAILED, "Tensor data size=%lu, buffer size=%lu", mem_size, buffer.length); return FAILED; } else if (buffer.length > mem_size) { - GELOGW("Tensor data size=%lu, buffer size=%u", mem_size, buffer.length); + GELOGW("Tensor data size=%lu, buffer size=%lu", mem_size, buffer.length); + } + int64_t data_size = output.second.GetDataSize(); + + if (is_online_infer_dynamic_) { + if (merge_nodes_gear_and_real_out_size_info_.find(idx) != merge_nodes_gear_and_real_out_size_info_.end()) { + auto gear_and_real_out_size_info = merge_nodes_gear_and_real_out_size_info_[idx]; + data_size = gear_and_real_out_size_info[cur_dynamic_dims_]; + } } - uint64_t data_size = output.second.GetDataSize(); uint64_t buffer_length = buffer.length; void *buffer_addr = reinterpret_cast(reinterpret_cast(buffer.data)); - GELOGI("[IMAS]CopyPlainData memcpy graph_%u type[F] output[%u] memaddr[%p] mem_size[%lu] datasize[%u]", + GELOGI("[IMAS]CopyPlainData memcpy graph_%u type[F] output[%u] memaddr[%p] mem_size[%lu] datasize[%lu]", runtime_param_.graph_id, output.first, output.second.GetBasicAddr(), data_size, buffer_length); GE_CHK_RT_RET(rtMemcpy(buffer_addr, buffer_length, output.second.GetBasicAddr(), data_size, kind)); + idx++; } return SUCCESS; } @@ -2372,19 +2580,31 @@ Status DavinciModel::GenOutputTensorInfo(const OpDescPtr &op_desc, uint32_t data std::vector out_buffer_size_vec; std::vector> shape_info_vec; size_t input_num = op_desc->GetInputsSize(); + if (is_getnext_sink_dynamic_) { + input_num = input_num - kGetDynamicDimsCount; + } for (size_t i = 0; i < input_num; ++i) { int64_t size = 0; auto input_desc = op_desc->GetInputDescPtr(i); GE_CHECK_NOTNULL(input_desc); auto ret = TensorUtils::GetTensorSizeInBytes(*input_desc, size); - if (ret != GRAPH_SUCCESS) { - GELOGE(ret, "Get size from TensorDesc failed, op:%s, input index:%zu", op_desc->GetName().c_str(), i); - return ret; + GE_IF_BOOL_EXEC(ret != GRAPH_SUCCESS, + GELOGE(ret, "Get size from TensorDesc failed, op:%s, input id:%zu", op_desc->GetName().c_str(), i); + return ret); + std::vector output_shape = input_desc->GetShape().GetDims(); + if (is_online_infer_dynamic_) { + if (merge_nodes_gear_and_real_out_size_info_.find(i) != merge_nodes_gear_and_real_out_size_info_.end()) { + auto gear_and_real_out_size_info = merge_nodes_gear_and_real_out_size_info_[i]; + size = gear_and_real_out_size_info[cur_dynamic_dims_]; + auto gear_and_real_out_shape_info = merge_nodes_gear_and_real_out_shape_info_[i]; + output_shape = gear_and_real_out_shape_info[cur_dynamic_dims_]; + is_dynamic_ = true; + } } + GELOGI("Output size is %ld, output shape is %s.", size, formats::JoinToString(output_shape).c_str()); out_buffer_size_vec.push_back(size); - shape_info_vec.push_back(input_desc->GetShape().GetDims()); + shape_info_vec.push_back(output_shape); } - GELOGI("Output blobs size:%zu, data index:%u, model id:%u", out_buffer_size_vec.size(), data_index, model_id_); for (size_t i = 0; i < out_buffer_size_vec.size(); ++i) { std::unique_ptr data_buf(new (std::nothrow) uint8_t[out_buffer_size_vec[i]]); @@ -2398,7 +2618,8 @@ Status DavinciModel::GenOutputTensorInfo(const OpDescPtr &op_desc, uint32_t data output.data = std::move(data_buf); output.length = out_buffer_size_vec[i]; outputs.emplace_back(std::move(output)); - GELOGI("Output index:%zu, data_length:%lu.", i, output.length); + GELOGD("Output index:%zu, output dims is %s, data length:%lu.", i, formats::JoinToString(output.dims).c_str(), + output.length); } return SUCCESS; } @@ -2447,8 +2668,18 @@ Status DavinciModel::ReturnResult(uint32_t data_id, const bool rslt_flg, const b output_data->index = data_id; output_data->model_id = model_id_; + is_getnext_sink_dynamic_ = false; // copy output data from op to designated position for (auto &op_desc : output_op_list_) { + if (IsGetNextSinkDynamic(op_desc)) { + GELOGD("Reinit cur dynamic dims when getnext sink dynamic."); + is_getnext_sink_dynamic_ = true; + cur_dynamic_dims_.clear(); + cur_dynamic_dims_.resize(shape_of_cur_dynamic_dims_); + GE_CHK_RT_RET(rtMemcpy(cur_dynamic_dims_.data(), shape_of_cur_dynamic_dims_ * sizeof(int64_t), + netoutput_last_input_addr_, netoutput_last_input_size_, RT_MEMCPY_DEVICE_TO_HOST)); + } + GELOGD("Cur dynamic dims is %s.", formats::JoinToString(cur_dynamic_dims_).c_str()); if (GenOutputTensorInfo(op_desc, data_index, output_data, outputs) != SUCCESS) { return INTERNAL_ERROR; } @@ -2521,12 +2752,10 @@ void *DavinciModel::Run(DavinciModel *model) { continue; } GELOGI("Getting the input data, model_id:%u", model_id); - GE_IF_BOOL_EXEC(!model->RunFlag(), break); InputData current_data = data_wrapper->GetInput(); GELOGI("Model thread Run begin, model id:%u, data index:%u.", model_id, current_data.index); - GE_TIMESTAMP_START(Model_SyncVarData); ret = model->SyncVarData(); GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( @@ -2543,6 +2772,18 @@ void *DavinciModel::Run(DavinciModel *model) { ret != SUCCESS, (void)model->ReturnResult(current_data.index, false, false, data_wrapper->GetOutput()); CsaInteract::GetInstance().StoreInternalErrorCode(ret, ERROR_MODULE_FMK, JOBSUBSTATE_GRAPH_EXEC); continue, "Copy input data to model failed."); // [No need to check value] + if (model->is_online_infer_dynamic_ && !model->is_getnext_sink_dynamic_) { + model->cur_dynamic_dims_.clear(); + GE_IF_BOOL_EXEC(current_data.blobs.empty(), break); + auto shape_data_buffer_data = current_data.blobs.back().data; + auto shape_data_buffer_length = current_data.blobs.back().length; + model->cur_dynamic_dims_.assign( + reinterpret_cast(shape_data_buffer_data), + reinterpret_cast(shape_data_buffer_data) + shape_data_buffer_length / sizeof(int64_t)); + GELOGD("Data: cur dynamic dims is %s", formats::JoinToString(model->cur_dynamic_dims_).c_str()); + delete[](int64_t *) current_data.blobs.back().data; + current_data.blobs.pop_back(); + } GE_IF_BOOL_EXEC(ProfilingManager::Instance().ProfilingModelExecuteOn(), model->SetProfileTime(MODEL_PRE_PROC_END)); GE_IF_BOOL_EXEC(ProfilingManager::Instance().ProfilingModelExecuteOn(), model->SetProfileTime(MODEL_INFER_START)); if (ProfilingManager::Instance().ProfilingOpTraceOn()) { @@ -2565,9 +2806,14 @@ void *DavinciModel::Run(DavinciModel *model) { GELOGI("rtStreamSynchronize start."); rt_ret = rtStreamSynchronize(model->rt_model_stream_); - GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, rslt_flg = false; - (void)model->ReturnResult(current_data.index, false, seq_end_flag, data_wrapper->GetOutput()); - continue); // [No need to check value] + if (rt_ret == kModelAbortNormal || rt_ret == kModelAbortNormalNew) { + GELOGI("The model with multiple datasets aborts normally."); + } else { + GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, rslt_flg = false; + (void)model->ReturnResult(current_data.index, false, seq_end_flag, data_wrapper->GetOutput()); + continue); // [No need to check value] + } + GELOGI("rtStreamSynchronize end."); (void)ProfilingManager::Instance().StopProfiling(); // just profiling, no need to check value } @@ -2588,12 +2834,17 @@ void *DavinciModel::Run(DavinciModel *model) { if (rt_ret == kEndOfSequence || rt_ret == kEndOfSequenceNew) { seq_end_flag = true; } - GE_IF_BOOL_EXEC( - rt_ret != RT_ERROR_NONE, rslt_flg = false; GELOGI("seq_end_flg: %d", seq_end_flag); - (void)model->ReturnResult(current_data.index, false, seq_end_flag, - data_wrapper->GetOutput()); // [No need to check value] - CsaInteract::GetInstance().StoreInternalErrorCode(rt_ret, ERROR_MODULE_RUNTIME, JOBSUBSTATE_GRAPH_EXEC); - continue); + if (rt_ret == kModelAbortNormal || rt_ret == kModelAbortNormalNew) { + GELOGI("The model with multiple datasets aborts normally."); + } else { + GE_IF_BOOL_EXEC( + rt_ret != RT_ERROR_NONE, rslt_flg = false; GELOGI("seq_end_flg: %d", seq_end_flag); + (void)model->ReturnResult(current_data.index, false, seq_end_flag, + data_wrapper->GetOutput()); // [No need to check value] + CsaInteract::GetInstance().StoreInternalErrorCode(rt_ret, ERROR_MODULE_RUNTIME, JOBSUBSTATE_GRAPH_EXEC); + continue); + } + GELOGI("rtStreamSynchronize end."); GE_IF_BOOL_EXEC(model->is_first_execute_, GE_TIMESTAMP_EVENT_END(rtStreamSynchronize, "GraphExcute::Wait for rtStreamSynchronize")); @@ -2730,7 +2981,7 @@ void DavinciModel::UnbindTaskSinkStream() { Status DavinciModel::CreateKnownZeroCopyMap(const vector &inputs, const vector &outputs) { GELOGI("DavinciModel::CreateKnownZeroCopyMap in."); if (inputs.size() > data_op_list_.size()) { - GELOGE(FAILED, "input data addr %u should less than input op number %u.", inputs.size(), data_op_list_.size()); + GELOGE(FAILED, "input data addr %zu should less than input op number %zu.", inputs.size(), data_op_list_.size()); return FAILED; } // remove zero copy addr in last iteration @@ -2739,16 +2990,16 @@ Status DavinciModel::CreateKnownZeroCopyMap(const vector &inputs, const for (size_t i = 0; i < inputs.size(); ++i) { const vector addr_list = ModelUtils::GetOutputDataAddrs(runtime_param_, data_op_list_[i]); knonw_input_data_info_[addr_list[kDataIndex]] = inputs[i]; - GELOGI("DavinciModel::CreateKnownZeroCopyMap input %d,v addr %p,p addr %p .", i, addr_list[kDataIndex], inputs[i]); + GELOGI("DavinciModel::CreateKnownZeroCopyMap input %zu,v addr %p,p addr %p .", i, addr_list[kDataIndex], inputs[i]); } if (output_op_list_.size() < kOutputNum) { - GELOGW("output op num in graph is %u.", output_op_list_.size()); + GELOGW("output op num in graph is %zu.", output_op_list_.size()); return SUCCESS; } const vector addr_list = ModelUtils::GetInputDataAddrs(runtime_param_, output_op_list_[kDataIndex]); for (size_t i = 0; i < addr_list.size() && i < outputs.size(); ++i) { knonw_output_data_info_[addr_list[i]] = outputs[i]; - GELOGI("DavinciModel::CreateKnownZeroCopyMap output %d,v addr %p,p addr %p .", i, addr_list[i], outputs[i]); + GELOGI("DavinciModel::CreateKnownZeroCopyMap output %zu,v addr %p,p addr %p .", i, addr_list[i], outputs[i]); } GELOGI("DavinciModel::CreateKnownZeroCopyMap success."); return SUCCESS; @@ -2758,13 +3009,13 @@ Status DavinciModel::UpdateKnownZeroCopyAddr() { for (size_t i = 0; i < total_io_addrs_.size(); ++i) { auto it_in = knonw_input_data_info_.find(total_io_addrs_[i]); if (it_in != knonw_input_data_info_.end()) { - GELOGI("DavinciModel::UpdateKnownZeroCopyAddr input %d,v addr %p,p addr %p .", i, total_io_addrs_[i], + GELOGI("DavinciModel::UpdateKnownZeroCopyAddr input %zu,v addr %p,p addr %p .", i, total_io_addrs_[i], knonw_input_data_info_.at(total_io_addrs_[i])); total_io_addrs_[i] = knonw_input_data_info_.at(total_io_addrs_[i]); } auto it_out = knonw_output_data_info_.find(total_io_addrs_[i]); if (it_out != knonw_output_data_info_.end()) { - GELOGI("DavinciModel::UpdateKnownZeroCopyAddr output %d,v addr %p,p addr %p .", i, total_io_addrs_[i], + GELOGI("DavinciModel::UpdateKnownZeroCopyAddr output %zu,v addr %p,p addr %p .", i, total_io_addrs_[i], knonw_output_data_info_.at(total_io_addrs_[i])); total_io_addrs_[i] = knonw_output_data_info_.at(total_io_addrs_[i]); } @@ -2785,7 +3036,7 @@ Status DavinciModel::UpdateKnownNodeArgs(const vector &inputs, const vec if (task != nullptr) { Status ret = task->UpdateArgs(); if (ret != SUCCESS) { - GELOGE(FAILED, "task %d created by davinci model is nullptr.", task_index); + GELOGE(FAILED, "task %zu created by davinci model is nullptr.", task_index); return FAILED; } } @@ -2814,7 +3065,7 @@ Status DavinciModel::UpdateKnownNodeArgs(const vector &inputs, const vec } Status DavinciModel::InitTaskInfo(domi::ModelTaskDef &model_task_def) { - GELOGI("InitTaskInfo in, task size %zu", model_task_def.task().size()); + GELOGI("InitTaskInfo in, task size %d", model_task_def.task().size()); task_list_.resize(model_task_def.task_size()); for (int i = 0; i < model_task_def.task_size(); ++i) { // dynamic shape will create task_list_ before @@ -2890,14 +3141,14 @@ Status DavinciModel::DistributeTask() { task_desc_info_.clear(); bool flag = GetL1FusionEnableOption(); - char *skt_enable_env = std::getenv("SKT_ENABLE"); - int64_t env_flag = (skt_enable_env != nullptr) ? std::strtol(skt_enable_env, nullptr, kDecimal) : 0; + char skt_enable_env[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv("SKT_ENABLE", skt_enable_env, MMPA_MAX_PATH); + int64_t env_flag = (res == EN_OK) ? std::strtol(skt_enable_env, nullptr, kDecimal) : 0; if (env_flag != 0) { flag = true; } const auto &model_task_def = ge_model_->GetModelTaskDefPtr(); - GELOGI("there are %zu task need to save.", task_list_.size()); for (size_t task_index = 0; task_index < task_list_.size(); ++task_index) { auto &task = task_list_.at(task_index); GE_CHK_STATUS_RET(task->Distribute(), "Task[%zu] distribute fail", task_index); @@ -3079,7 +3330,7 @@ bool DavinciModel::CheckInputAndModelSize(const int64_t &input_size, const int64 if (input_size > op_size) { GELOGW( - "Input size [%u] is bigger than om size need [%u], " + "Input size [%ld] is bigger than om size need [%ld], " "MAY cause inference result ERROR, please check model input", input_size, op_size); } @@ -3161,7 +3412,7 @@ Status DavinciModel::UpdateIoTaskArgs(const std::map & for (const auto &data : data_info) { if (data.first >= blobs.size()) { // check data index. - GELOGE(FAILED, "Verify %s data num failed: can not find No.%zu data, because user only feeds %zu", + GELOGE(FAILED, "Verify %s data num failed: can not find No.%u data, because user only feeds %zu", input_or_output.c_str(), data.first, blobs.size()); return FAILED; } @@ -3271,7 +3522,7 @@ Status DavinciModel::InitConstant(const OpDescPtr &op_desc) { GeTensor *tensor = const_cast(v_weights[0].get()); GE_IF_BOOL_EXEC( static_cast(v_output_size[0]) < tensor->GetData().size(), - GELOGE(PARAM_INVALID, "output size:%u less than weight data size:%zu", v_output_size[0], tensor->GetData().size()); + GELOGE(PARAM_INVALID, "output size:%ld less than weight data size:%zu", v_output_size[0], tensor->GetData().size()); return PARAM_INVALID;); GE_IF_BOOL_EXEC(tensor->GetData().size() == 0, GELOGW("const op:%s has no weight data.", op_desc->GetName().c_str()); @@ -3293,13 +3544,12 @@ Status DavinciModel::InitConstant(const OpDescPtr &op_desc) { "Shape size is invalid"); uint64_t offset = static_cast(elem_num * kBytes); - uint64_t hbm_raw_data_base_addr = - reinterpret_cast(reinterpret_cast(v_output_addr[0])) + offset; + uint64_t hbm_raw_data_base_addr = static_cast(reinterpret_cast(v_output_addr[0])) + offset; for (int64_t i = elem_num - 1; i >= 0; --i) { buff[i] = hbm_raw_data_base_addr + (buff[i] - buff[0]); } } - GELOGI("[IMAS]InitConstant memcpy graph_%u type[V] name[%s] output[%d] memaddr[%p] mem_size[%u] datasize[%zu]", + GELOGI("[IMAS]InitConstant memcpy graph_%u type[V] name[%s] output[%d] memaddr[%p] mem_size[%lu] datasize[%zu]", runtime_param_.graph_id, op_desc->GetName().c_str(), 0, v_output_addr[0], v_output_size[0], tensor->GetData().size()); GE_CHK_RT_RET(rtMemcpy(v_output_addr[0], v_output_size[0], tensor->GetData().data(), tensor->GetData().size(), @@ -3330,12 +3580,12 @@ Status DavinciModel::InitTbeHandle(const OpDescPtr &op_desc) { if (rtQueryFunctionRegistered(bin_file_key) != RT_ERROR_NONE) { void *bin_handle = nullptr; if (!kernel_store.FindTBEHandle(bin_file_key, bin_handle)) { - GELOGI("TBE: can't find the kernel_name[%s] in HandleMap", bin_file_key); + GELOGD("TBE: can't find the kernel_name[%s] in HandleMap", bin_file_key); rtDevBinary_t binary; std::string json_string; GE_IF_BOOL_EXEC(AttrUtils::GetStr(op_desc, TVM_ATTR_NAME_MAGIC, json_string), - GELOGI("Get original type of session_graph_id.")); + GELOGD("Get original type of session_graph_id.")); if (json_string == "RT_DEV_BINARY_MAGIC_ELF_AICPU") { binary.magic = RT_DEV_BINARY_MAGIC_ELF_AICPU; } else if (json_string == "RT_DEV_BINARY_MAGIC_ELF") { @@ -3351,13 +3601,13 @@ Status DavinciModel::InitTbeHandle(const OpDescPtr &op_desc) { binary.data = tbe_kernel->GetBinData(); binary.length = tbe_kernel->GetBinDataSize(); - GELOGI("TBE: binary.length: %lu", binary.length); + GELOGD("TBE: binary.length: %lu", binary.length); GE_CHK_RT_RET(rtDevBinaryRegister(&binary, &bin_handle)); std::string meta_data; GE_IF_BOOL_EXEC(AttrUtils::GetStr(op_desc, TVM_ATTR_NAME_METADATA, meta_data), GELOGI("Get original type of json_string")); - GELOGI("TBE: meta data: %s", meta_data.empty() ? "null" : meta_data.c_str()); + GELOGD("TBE: meta data: %s", meta_data.empty() ? "null" : meta_data.c_str()); GE_IF_BOOL_EXEC(!meta_data.empty(), GE_CHK_RT_RET(rtMetadataRegister(bin_handle, meta_data.c_str()))); kernel_store.StoreTBEHandle(bin_file_key, bin_handle, tbe_kernel); @@ -3368,8 +3618,7 @@ Status DavinciModel::InitTbeHandle(const OpDescPtr &op_desc) { std::string kernel_name; GE_IF_BOOL_EXEC(AttrUtils::GetStr(op_desc, op_desc->GetName() + "_kernelname", kernel_name), - GELOGI("Get original type of kernel_name")); - GELOGI("TBE: binfile_key=%s, kernel_name=%s", bin_file_key, kernel_name.c_str()); + GELOGD("Get original type of kernel_name")); GE_CHK_RT_RET(rtFunctionRegister(bin_handle, bin_file_key, bin_file_key, kernel_name.c_str(), 0)); used_tbe_handle_map_[bin_file_key] = 1; // Init used num to 1. return SUCCESS; @@ -3564,7 +3813,7 @@ Status DavinciModel::InitModelStream(rtStream_t stream) { Status DavinciModel::NnExecute(rtStream_t stream, bool async_mode, const InputData &input_data, OutputData &output_data) { is_async_mode_ = async_mode; - GELOGI("Model Run begin, model id:%u, data index:%u, flag:%d.", model_id_, input_data.index, is_async_mode_); + GELOGD("Model Run begin, model id:%u, data index:%u, flag:%d.", model_id_, input_data.index, is_async_mode_); GE_CHK_STATUS_RET(InitModelStream(stream), "Init model stream failed."); is_dynamic_ = input_data.is_dynamic_batch; if (!is_dynamic_) { @@ -3576,7 +3825,7 @@ Status DavinciModel::NnExecute(rtStream_t stream, bool async_mode, const InputDa GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ret != SUCCESS, return ret, "Copy input data to model failed. model id: %u", model_id_); - GELOGI("current_data.index=%u", input_data.index); + GELOGD("current_data.index=%u", input_data.index); GE_IF_BOOL_EXEC(ProfilingManager::Instance().ProfilingModelExecuteOn(), SetProfileTime(MODEL_PRE_PROC_END)); if (!task_list_.empty()) { @@ -3585,7 +3834,7 @@ Status DavinciModel::NnExecute(rtStream_t stream, bool async_mode, const InputDa rtError_t rt_ret = rtModelExecute(rt_model_handle_, rt_model_stream_, 0); GE_CHK_RT_EXEC(rt_ret, return RT_ERROR_TO_GE_STATUS(rt_ret)); GE_IF_BOOL_EXEC(ProfilingManager::Instance().ProfilingModelExecuteOn(), SetProfileTime(MODEL_INFER_END)); - GELOGI("rtModelExecute end"); + GELOGD("rtModelExecute end"); } if (!is_async_mode_) { @@ -3597,7 +3846,7 @@ Status DavinciModel::NnExecute(rtStream_t stream, bool async_mode, const InputDa // report model time data GE_IF_BOOL_EXEC(ProfilingManager::Instance().ProfilingModelExecuteOn(), (void)SinkTimeProfile(input_data)); - GELOGI("Model run end, model id:%u", model_id_); + GELOGD("Model run end, model id:%u", model_id_); return SUCCESS; } @@ -3654,7 +3903,9 @@ Status DavinciModel::InitEntryTask() { uint8_t *DavinciModel::MallocFeatureMapMem(size_t data_size) { uint8_t *mem_base = nullptr; const string purpose("feature map,used for op input and output."); - if (std::getenv(kEnvGeuseStaticMemory) != nullptr) { + char ge_static_mem_env[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv(kEnvGeuseStaticMemory, ge_static_mem_env, MMPA_MAX_PATH); + if (res == EN_OK) { data_size = static_cast(VarManager::Instance(session_id_)->GetGraphMemoryMaxSize()); string memory_key = std::to_string(0) + "_f"; mem_base = MemManager::Instance(RT_MEMORY_HBM)->MallocMemory(purpose, memory_key, data_size, GetDeviceId()); @@ -3684,7 +3935,9 @@ uint8_t *DavinciModel::MallocP2PMem(size_t p2p_data_size) { uint8_t *DavinciModel::MallocWeightsMem(size_t weights_size) { uint8_t *weights_mem_base = nullptr; const string purpose("weights memory in inference network."); - if (std::getenv(kEnvGeuseStaticMemory) != nullptr) { + char ge_static_mem_env[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv(kEnvGeuseStaticMemory, ge_static_mem_env, MMPA_MAX_PATH); + if (res == EN_OK) { string weight_memory_key = std::to_string(0) + "_w"; weights_mem_base = MemManager::Instance(RT_MEMORY_HBM)->MallocMemory(purpose, weight_memory_key, weights_size, GetDeviceId()); @@ -3695,7 +3948,9 @@ uint8_t *DavinciModel::MallocWeightsMem(size_t weights_size) { } void DavinciModel::FreeFeatureMapMem() { - if (std::getenv(kEnvGeuseStaticMemory) != nullptr && is_inner_mem_base_) { + char ge_static_mem_env[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv(kEnvGeuseStaticMemory, ge_static_mem_env, MMPA_MAX_PATH); + if (res == EN_OK && is_inner_mem_base_) { string weight_memory_key = std::to_string(0) + "_f"; if (MemManager::Instance(RT_MEMORY_HBM)->GetMemoryAddr(weight_memory_key) != nullptr) { GE_CHK_STATUS(MemManager::Instance(RT_MEMORY_HBM)->FreeMemory(weight_memory_key, GetDeviceId()), @@ -3727,7 +3982,9 @@ void DavinciModel::FreeP2PMem() { } void DavinciModel::FreeWeightsMem() { - if (std::getenv(kEnvGeuseStaticMemory) != nullptr) { + char ge_static_mem_env[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv(kEnvGeuseStaticMemory, ge_static_mem_env, MMPA_MAX_PATH); + if (res == EN_OK) { string memory_key = std::to_string(0) + "_w"; if (MemManager::Instance(RT_MEMORY_HBM)->GetMemoryAddr(memory_key) != nullptr) { GE_CHK_STATUS(MemManager::Instance(RT_MEMORY_HBM)->FreeMemory(memory_key, GetDeviceId()), @@ -3743,7 +4000,6 @@ void DavinciModel::FreeWeightsMem() { } Status DavinciModel::TransAllVarData(ComputeGraphPtr &graph, uint32_t graph_id) { - GELOGI("TransAllVarData start: session_id:%lu, graph_id: %u.", session_id_, graph_id); rtContext_t ctx = nullptr; rtError_t rt_ret = rtCtxGetCurrent(&ctx); if (rt_ret != RT_ERROR_NONE) { @@ -3764,13 +4020,10 @@ Status DavinciModel::TransAllVarData(ComputeGraphPtr &graph, uint32_t graph_id) GE_CHK_STATUS_RET_NOLOG( TransVarDataUtils::TransAllVarData(variable_node_list, session_id_, ctx, graph_id, kThreadNum)); - - GELOGI("TransAllVarData success."); return SUCCESS; } void DavinciModel::SetDataDumperArgs(const ComputeGraphPtr &compute_graph) { - GELOGI("set data dumper args, name: %s, id: %u.", name_.c_str(), model_id_); data_dumper_.SetModelName(name_); data_dumper_.SetModelId(model_id_); data_dumper_.SetOmName(om_name_); @@ -3796,15 +4049,13 @@ void DavinciModel::SetDataDumperArgs(const ComputeGraphPtr &compute_graph) { } return v_output_addr[0]; } - GELOGW("op is null."); + GELOGD("op is null."); return nullptr; }; data_dumper_.SetLoopAddr(get_var_addr(GetVariableOp(NODE_NAME_GLOBAL_STEP), runtime_param_), get_var_addr(GetVariableOp(NODE_NAME_FLOWCTRL_LOOP_PER_ITER), runtime_param_), get_var_addr(GetVariableOp(NODE_NAME_FLOWCTRL_LOOP_COND), runtime_param_)); - - GELOGI("SetDataDumperArgs end."); } uint32_t DavinciModel::GetFlowctrlIndex(uint32_t op_index) { @@ -3823,7 +4074,6 @@ void DavinciModel::SaveHcclFollowStream(int64_t main_stream_id, rtStream_t strea } Status DavinciModel::GetComputeGraphInfo(vector &graph_desc_info) { - GELOGI("GetComputeGraphInfo start."); auto &all_op_desc = data_dumper_.GetAllOpDescInfo(); for (auto &op_desc : all_op_desc) { ComputeGraphDescInfo compute_graph_info; @@ -3843,7 +4093,6 @@ Status DavinciModel::GetComputeGraphInfo(vector &graph_des graph_desc_info.emplace_back(compute_graph_info); } - GELOGI("GetComputeGraphInfo end."); return SUCCESS; } @@ -3858,8 +4107,8 @@ Status DavinciModel::GetOrigInputInfo(uint32_t index, OriginInputInfo &orig_inpu GE_CHK_BOOL_RET_STATUS(index < data_op_list_.size(), PARAM_INVALID, "Index %u is invalid.", index); OpDescPtr data_op = data_op_list_[index]; if (!data_op->HasAttr(ATTR_NAME_AIPP_INPUTS) || !data_op->HasAttr(ATTR_NAME_AIPP_OUTPUTS)) { - GELOGE(GE_AIPP_NOT_EXIST, "GetOrigInputInfo: there is not AIPP related with index %u.", index); - return GE_AIPP_NOT_EXIST; + GELOGE(ACL_ERROR_GE_AIPP_NOT_EXIST, "GetOrigInputInfo: there is not AIPP related with index %u.", index); + return ACL_ERROR_GE_AIPP_NOT_EXIST; } vector inputs; @@ -3902,13 +4151,13 @@ Status DavinciModel::GetAllAippInputOutputDims(uint32_t index, std::vectorHasAttr(ATTR_NAME_AIPP_INPUTS) || !data_op->HasAttr(ATTR_NAME_AIPP_OUTPUTS)) { - GELOGE(GE_AIPP_NOT_EXIST, "GetAllAippInputOutputDims: there is not AIPP related with index %u.", index); - return GE_AIPP_NOT_EXIST; + GELOGE(ACL_ERROR_GE_AIPP_NOT_EXIST, "GetAllAippInputOutputDims: there is not AIPP related with index %u.", index); + return ACL_ERROR_GE_AIPP_NOT_EXIST; } vector inputs; if (AttrUtils::GetListStr(data_op, ATTR_NAME_AIPP_INPUTS, inputs) && !inputs.empty()) { - GELOGI("GetAllAippInputOutputDims: Data: %s has %u related aippInfo.", data_op->GetName().c_str(), inputs.size()); + GELOGI("GetAllAippInputOutputDims: Data: %s has %zu related aippInfo.", data_op->GetName().c_str(), inputs.size()); for (auto it : inputs) { InputOutputDims input_info; ParseAIPPInfo(it, input_info); @@ -3919,7 +4168,7 @@ Status DavinciModel::GetAllAippInputOutputDims(uint32_t index, std::vectorGetInputDescPtr(kDataIndex)), data_input_size); GELOGD( - "GetAllAippInputOutputDims related Data[%d]: tensor_name is %s, dim_num is %u, tensor_size: %zu, format: " + "GetAllAippInputOutputDims related Data[%d]: tensor_name is %s, dim_num is %zu, tensor_size: %zu, format: " "%s, data_type: %s, shape: %s .", index, data_op->GetName().c_str(), data_input_desc->GetShape().GetDimNum(), data_input_size, TypeUtils::FormatToSerialString(data_input_desc->GetFormat()).c_str(), diff --git a/src/ge/graph/load/new_model_manager/davinci_model.h b/src/ge/graph/load/new_model_manager/davinci_model.h index 85b2922f..274ac6ed 100644 --- a/src/ge/graph/load/new_model_manager/davinci_model.h +++ b/src/ge/graph/load/new_model_manager/davinci_model.h @@ -47,6 +47,7 @@ #include "mmpa/mmpa_api.h" #include "proto/task.pb.h" #include "task_info/task_info.h" +#include "graph/common/local_context.h" namespace ge { // op debug need 2048 bits buffer @@ -521,7 +522,6 @@ class DavinciModel { bool is_inner_p2p_mem_base_; // input data manager DataInputer *data_inputer_; - int64_t load_begin_time_; int64_t load_end_time_; struct timeInfo time_info_; @@ -840,6 +840,14 @@ class DavinciModel { void ParseAIPPInfo(std::string in_out_info, InputOutputDims &dims_info); void SetLabelForDynamic(const NodePtr &node); + void ParseDynamicOutShape(const std::vector &str_info, std::vector> &vec_info); + bool IsGetNextSinkDynamic(const OpDescPtr &op_desc); + void GetAllGearsInfo(const NodePtr &node); + Status GetGetDynamicDimsNodeInfo(const NodePtr &node); + Status GetGearAndRealOutSizeInfo(size_t input_count, const NodePtr &node); + Status GetRealOutputSizeOfMerge(size_t input_index, const NodePtr &merge_node); + Status GetGearAndRealOutShapeInfo(size_t input_count, const OpDescPtr &op_desc); + bool is_model_has_inited_; uint32_t model_id_; uint32_t runtime_model_id_; @@ -992,6 +1000,17 @@ class DavinciModel { void *op_debug_addr_ = nullptr; void *p2p_debug_addr_ = nullptr; bool is_new_model_desc_{false}; + bool is_online_infer_dynamic_ = false; + bool is_getnext_sink_dynamic_ = false; + std::vector cur_dynamic_dims_; + void *netoutput_last_input_addr_ = nullptr; + int64_t netoutput_last_input_size_ = 0; + size_t shape_of_cur_dynamic_dims_ = 0; + // key: input_index: input is merge node; value: each gear info and each output size + std::map, int64_t>> merge_nodes_gear_and_real_out_size_info_; + // key: input_index: input is merge node; value: each gear info and each output shape + std::map, vector>> merge_nodes_gear_and_real_out_shape_info_; + std::vector> all_gears_info_; }; } // namespace ge #endif // GE_GRAPH_LOAD_NEW_MODEL_MANAGER_DAVINCI_MODEL_H_ diff --git a/src/ge/graph/load/new_model_manager/model_manager.cc b/src/ge/graph/load/new_model_manager/model_manager.cc index e3c6873c..18aff0dd 100644 --- a/src/ge/graph/load/new_model_manager/model_manager.cc +++ b/src/ge/graph/load/new_model_manager/model_manager.cc @@ -29,6 +29,8 @@ #include "graph/load/new_model_manager/davinci_model.h" #include "graph/load/new_model_manager/davinci_model_parser.h" #include "model/ge_root_model.h" +#include "graph/common/local_context.h" +#include "common/formats/utils/formats_trans_utils.h" namespace ge { thread_local uint32_t device_count = 0; @@ -200,7 +202,6 @@ void ModelManager::DestroyAicpuSession(uint64_t session_id) { } ge::Status ModelManager::DestroyAicpuSessionForInfer(uint32_t model_id) { - GELOGI("Destroy aicpu session for infer, model id is %u.", model_id); std::lock_guard lock(map_mutex_); auto it = model_map_.find(model_id); if (it == model_map_.end()) { @@ -208,7 +209,6 @@ ge::Status ModelManager::DestroyAicpuSessionForInfer(uint32_t model_id) { return GE_EXEC_MODEL_ID_INVALID; } uint64_t session_id = it->second->GetSessionId(); - GELOGI("Destroy aicpu session for infer, session id is %lu.", session_id); DestroyAicpuSession(session_id); return SUCCESS; } @@ -444,6 +444,46 @@ Status ModelManager::DataInput(const InputData &input_data, OutputData &output_d return SUCCESS; } +Status ModelManager::GetCurDynamicDims(const vector> &user_real_input_dims, + const vector>> &user_input_dims, + vector &cur_dynamic_dims) { + GELOGD(" Start get cur dynamic dims."); + if (user_real_input_dims.size() != user_input_dims.size()) { + GELOGE(INTERNAL_ERROR, "The input count of user: %zu should be equal to the data count of graph: %zu", + user_real_input_dims.size(), user_input_dims.size()); + return INTERNAL_ERROR; + } + + for (size_t i = 0; i < user_input_dims.size(); ++i) { + if (user_real_input_dims[i].size() != user_input_dims[i].second.size()) { + GELOGE(INTERNAL_ERROR, + "The shape size: %zu of dynamic input: %s should be equal to the shape size of input shape: %zu.", + user_real_input_dims[i].size(), user_input_dims[i].first.c_str(), user_input_dims[i].second.size()); + return INTERNAL_ERROR; + } + for (size_t j = 0; j < user_input_dims.at(i).second.size(); ++j) { + if (user_input_dims.at(i).second.at(j) < 0) { + cur_dynamic_dims.emplace_back(user_real_input_dims[i][j]); + } + } + } + GELOGD("Cur dynamic dims is %s.", formats::JoinToString(cur_dynamic_dims).c_str()); + bool cur_dynamic_dims_valid = false; + std::vector shape_strs = ge::StringUtils::Split(GetLocalOmgContext().dynamic_dims, ';'); + for (auto dynamic_dim : shape_strs) { + if (dynamic_dim == formats::JoinToString(cur_dynamic_dims)) { + cur_dynamic_dims_valid = true; + break; + } + } + if (!cur_dynamic_dims_valid) { + GELOGE(INTERNAL_ERROR, "Cur dynamic dims is %s, not exist in options.", + formats::JoinToString(cur_dynamic_dims).c_str()); + return INTERNAL_ERROR; + } + return SUCCESS; +} + /// /// @ingroup domi_ome /// @brief load Input and output TensorInfo for Model @@ -461,13 +501,30 @@ Status ModelManager::DataInputTensor(uint32_t model_id, const std::vector cur_dynamic_dims; + if (!GetLocalOmgContext().user_real_input_dims.empty()) { + if (GetCurDynamicDims(GetLocalOmgContext().user_real_input_dims, GetLocalOmgContext().user_input_dims, + cur_dynamic_dims) != SUCCESS) { + GELOGE(INTERNAL_ERROR, "[Train_Dynamic] Failed to Parse real_dynamic_dims."); + return INTERNAL_ERROR; + } + DataBuffer data; + data.data = new (std::nothrow) int64_t[cur_dynamic_dims.size()]; + GE_CHECK_NOTNULL(data.data); + uint64_t length = static_cast(cur_dynamic_dims.size() * sizeof(int64_t)); + GE_CHK_BOOL_EXEC(memcpy_s(data.data, length, cur_dynamic_dims.data(), length) == EOK, return INTERNAL_ERROR, + "Failed to memcpy data."); + data.length = length; + input_data.blobs.push_back(data); + } + } OutputData output_data; output_data.model_id = model_id; @@ -877,7 +934,7 @@ Status ModelManager::GetInputOutputDescInfo(const uint32_t model_id, vector> &batch_info, int32_t &dynamic_type) { std::shared_ptr davinci_model = GetModel(model_id); - GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, GE_EXEC_MODEL_ID_INVALID, + GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, "GetDynamicBatchInfo failed, Invalid model id %u!", model_id); return davinci_model->GetDynamicBatchInfo(batch_info, dynamic_type); @@ -892,8 +949,8 @@ Status ModelManager::GetDynamicBatchInfo(const uint32_t model_id, std::vector> &batch_info) { std::shared_ptr davinci_model = GetModel(model_id); - GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, PARAM_INVALID, "GetCombinedDynamicDims Failed, Invalid Model ID %u!", - model_id); + GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, + "GetCombinedDynamicDims Failed, Invalid Model ID %u!", model_id); davinci_model->GetCombinedDynamicDims(batch_info); return SUCCESS; @@ -909,7 +966,7 @@ Status ModelManager::GetCombinedDynamicDims(const uint32_t model_id, vector &user_input_shape_order) { auto davinci_model = GetModel(model_id); - GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, PARAM_INVALID, + GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, "GetUserDesignateShapeOrder Failed, Invalid Model ID %u!", model_id) davinci_model->GetUserDesignateShapeOrder(user_input_shape_order); return SUCCESS; @@ -950,16 +1007,16 @@ Status ModelManager::GetInputOutputDescInfoForZeroCopy(const uint32_t model_id, /// Status ModelManager::GetAIPPInfo(const uint32_t model_id, uint32_t index, AippConfigInfo &aipp_info) { std::shared_ptr davinci_model = GetModel(model_id); - GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, PARAM_INVALID, "GetAIPPInfo failed, invalid model_id is %u.", - model_id); + GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, + "GetAIPPInfo failed, invalid model_id is %u.", model_id); return davinci_model->GetAIPPInfo(index, aipp_info); } Status ModelManager::GetAippType(uint32_t model_id, uint32_t index, InputAippType &type, size_t &aipp_index) { std::shared_ptr davinci_model = GetModel(model_id); - GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, PARAM_INVALID, "GetAIPPInfo failed, invalid model_id is %u.", - model_id); + GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, + "GetAIPPInfo failed, invalid model_id is %u.", model_id); return davinci_model->GetAippType(index, type, aipp_index); } @@ -967,8 +1024,8 @@ Status ModelManager::GetAippType(uint32_t model_id, uint32_t index, InputAippTyp Status ModelManager::GenSessionId(uint64_t &session_id) { std::lock_guard lock(session_id_create_mutex_); - struct timeval tv; - if (gettimeofday(&tv, nullptr) != 0) { + mmTimeval tv; + if (mmGetTimeOfDay(&tv, nullptr) != 0) { GELOGE(INTERNAL_ERROR, "Failed to get current time."); return INTERNAL_ERROR; } @@ -985,8 +1042,9 @@ Status ModelManager::GenSessionId(uint64_t &session_id) { Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model, shared_ptr listener, void *dev_ptr, size_t mem_size, void *weight_ptr, size_t weight_size) { - GE_CHK_BOOL_RET_STATUS(model.key.empty() || access(model.key.c_str(), F_OK) == 0, GE_EXEC_MODEL_KEY_PATH_INVALID, - "input key file path %s is invalid, %s", model.key.c_str(), strerror(errno)); + GE_CHK_BOOL_RET_STATUS(model.key.empty() || mmAccess2(model.key.c_str(), M_F_OK) == EN_OK, + ACL_ERROR_GE_EXEC_MODEL_KEY_PATH_INVALID, "input key file path %s is invalid, %s", + model.key.c_str(), strerror(errno)); GenModelId(&model_id); shared_ptr davinci_model = nullptr; @@ -1004,8 +1062,8 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model try { davinci_model = std::make_shared(model.priority, listener); } catch (std::bad_alloc &) { - GELOGE(MEMALLOC_FAILED, "Make shared failed"); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Make shared failed"); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } catch (...) { GELOGE(INTERNAL_ERROR, "Make shared failed since other exception raise"); return INTERNAL_ERROR; @@ -1044,7 +1102,6 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ret != SUCCESS, break, "DavinciInit failed."); InsertModel(model_id, davinci_model); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(davinci_model == nullptr, ret = PARAM_INVALID; break, "Insert model failed"); GELOGI("Parse model %u success.", model_id); @@ -1071,8 +1128,8 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model Status ModelManager::LoadModelWithQ(uint32_t &model_id, const ModelData &model_data, const std::vector &input_queue_ids, const std::vector &output_queue_ids) { - GE_CHK_BOOL_RET_STATUS(model_data.key.empty() || access(model_data.key.c_str(), F_OK) == 0, - GE_EXEC_MODEL_KEY_PATH_INVALID, "input key file path %s is not valid, %s", + GE_CHK_BOOL_RET_STATUS(model_data.key.empty() || mmAccess2(model_data.key.c_str(), M_F_OK) == EN_OK, + ACL_ERROR_GE_EXEC_MODEL_KEY_PATH_INVALID, "input key file path %s is not valid, %s", model_data.key.c_str(), strerror(errno)); ModelHelper model_helper; @@ -1084,8 +1141,8 @@ Status ModelManager::LoadModelWithQ(uint32_t &model_id, const ModelData &model_d shared_ptr davinci_model = MakeShared(model_data.priority, nullptr); if (davinci_model == nullptr) { - GELOGE(MEMALLOC_FAILED, "create model failed."); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "create model failed."); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } ret = davinci_model->Assign(model_helper.GetGeModel()); @@ -1153,7 +1210,7 @@ Status ModelManager::ExecuteModel(uint32_t model_id, rtStream_t stream, bool asy Status status = davinci_model->NnExecute(stream, async_mode, input_data, output_data); if (status == SUCCESS) { - GELOGI("Execute model %u success.", model_id); + GELOGD("Execute model %u success.", model_id); } return status; @@ -1210,7 +1267,6 @@ Status ModelManager::LoadCustAicpuSo(const OpDescPtr &op_desc, const string &so_ } Status ModelManager::LaunchKernelCustAicpuSo(const string &kernel_name) { - GELOGI("LaunchCustAucpuSo in, kernel name %s", kernel_name.c_str()); std::lock_guard lock(cust_aicpu_mutex_); if (cust_aicpu_so_.size() == 0) return SUCCESS; // get current context @@ -1340,13 +1396,13 @@ Status ModelManager::GetModelMemAndWeightSize(const ModelData &model, size_t &me auto partition_table = reinterpret_cast(model_data); if (partition_table->num == 1) { - GELOGE(GE_EXEC_MODEL_PARTITION_NUM_INVALID, "om model is error,please use executable om model"); - return GE_EXEC_MODEL_PARTITION_NUM_INVALID; + GELOGE(ACL_ERROR_GE_EXEC_MODEL_PARTITION_NUM_INVALID, "om model is error,please use executable om model"); + return ACL_ERROR_GE_EXEC_MODEL_PARTITION_NUM_INVALID; } ModelPartition task_partition; if (om_file_helper.GetModelPartition(ModelPartitionType::TASK_INFO, task_partition) != SUCCESS) { - GELOGE(GE_EXEC_LOAD_TASK_PARTITION_FAILED, "get task model partition failed."); - return GE_EXEC_LOAD_TASK_PARTITION_FAILED; + GELOGE(ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED, "get task model partition failed."); + return ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED; } std::shared_ptr model_task_def = MakeShared(); @@ -1355,14 +1411,14 @@ Status ModelManager::GetModelMemAndWeightSize(const ModelData &model, size_t &me } if (task_partition.size != 0) { if (!ReadProtoFromArray(task_partition.data, static_cast(task_partition.size), model_task_def.get())) { - GELOGE(GE_EXEC_LOAD_TASK_PARTITION_FAILED, "ReadProtoFromArray failed."); - return GE_EXEC_LOAD_TASK_PARTITION_FAILED; + GELOGE(ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED, "ReadProtoFromArray failed."); + return ACL_ERROR_GE_EXEC_LOAD_TASK_PARTITION_FAILED; } } ModelPartition partition_weight; ret = om_file_helper.GetModelPartition(ModelPartitionType::WEIGHTS_DATA, partition_weight); - GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ret != SUCCESS, return GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED, + GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ret != SUCCESS, return ACL_ERROR_GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED, "Get weight partition failed. ret = %u", ret); mem_size = model_task_def->memory_size(); @@ -1381,8 +1437,8 @@ void ModelManager::GenModelId(uint32_t *id) { Status ModelManager::GetOrigInputInfo(uint32_t model_id, uint32_t index, OriginInputInfo &orig_input_info) { std::shared_ptr davinci_model = GetModel(model_id); - GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, PARAM_INVALID, "GetOrigInputInfo failed, invalid model_id is %u.", - model_id); + GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, + "GetOrigInputInfo failed, invalid model_id is %u.", model_id); return davinci_model->GetOrigInputInfo(index, orig_input_info); } @@ -1391,7 +1447,7 @@ Status ModelManager::GetAllAippInputOutputDims(uint32_t model_id, uint32_t index std::vector &input_dims, std::vector &output_dims) { std::shared_ptr davinci_model = GetModel(model_id); - GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, PARAM_INVALID, + GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, "GetAllAippInputOutputDims failed, invalid model_id is %u.", model_id); return davinci_model->GetAllAippInputOutputDims(index, input_dims, output_dims); diff --git a/src/ge/graph/load/new_model_manager/model_manager.h b/src/ge/graph/load/new_model_manager/model_manager.h index f2a8b9c8..df043c35 100644 --- a/src/ge/graph/load/new_model_manager/model_manager.h +++ b/src/ge/graph/load/new_model_manager/model_manager.h @@ -18,7 +18,6 @@ #define GE_GRAPH_LOAD_NEW_MODEL_MANAGER_MODEL_MANAGER_H_ #include -#include #include #include #include @@ -124,6 +123,18 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelManager { ge::Status DataInputTensor(uint32_t model_id, const std::vector &inputs); + /// + /// @ingroup domi_ome + /// @brief Get cur_dynamic_dims for all input. + /// @param [in] vector> &user_real_input_dims: dims info of all user_inputs. + /// @param [in] vector>> &user_input_dims: key:name. value:dynamic dims from option. + /// @param [out] vector &cur_dynamic_dims: real dims gather, where the index of -1. + /// @return 0: SUCCESS / others: INTERNAL_ERROR + /// + Status GetCurDynamicDims(const vector> &user_real_input_dims, + const vector>> &user_input_dims, + vector &cur_dynamic_dims); + /// /// @ingroup domi_ome /// @brief model start to run diff --git a/src/ge/graph/load/new_model_manager/model_utils.cc b/src/ge/graph/load/new_model_manager/model_utils.cc index 61c77202..7279f473 100644 --- a/src/ge/graph/load/new_model_manager/model_utils.cc +++ b/src/ge/graph/load/new_model_manager/model_utils.cc @@ -337,9 +337,7 @@ vector ModelUtils::GetInputDataAddrs(const RuntimeParam &model_param, Co continue; } - GE_IF_BOOL_EXEC(non_const_index >= v_input_offset.size(), - GELOGW("offsets=%zu, inputs=%zu, index=%zu.", v_input_offset.size(), inputs_size, non_const_index); - break); + GE_IF_BOOL_EXEC(non_const_index >= v_input_offset.size(), break); int64_t input_offset = v_input_offset[non_const_index]; non_const_index++; @@ -356,7 +354,7 @@ vector ModelUtils::GetInputDataAddrs(const RuntimeParam &model_param, Co // feature maps void *mem_addr = nullptr; if (has_mem_type_attr && v_memory_type[i] == RT_MEMORY_L1) { // fusion - mem_addr = reinterpret_cast(reinterpret_cast(input_offset)); + mem_addr = reinterpret_cast(static_cast(input_offset)); v_input_data_addr.push_back(mem_addr); } else if (has_mem_type_attr && v_memory_type[i] == RT_MEMORY_TS_4G) { int64_t tensor_size = 0; @@ -424,7 +422,7 @@ vector ModelUtils::GetOutputDataAddrs(const RuntimeParam &model_param, C // feature maps void *mem_addr = nullptr; if (has_mem_type_attr && v_memory_type[i] == RT_MEMORY_L1) { // fusion - mem_addr = reinterpret_cast(reinterpret_cast(v_output_offset[i])); + mem_addr = reinterpret_cast(static_cast(v_output_offset[i])); v_output_data_addr.push_back(mem_addr); } else if (has_mem_type_attr && v_memory_type[i] == RT_MEMORY_TS_4G) { const GeTensorDescPtr tensor_desc = op_desc->MutableOutputDesc(i); @@ -500,7 +498,7 @@ vector ModelUtils::GetWorkspaceDataAddrs(const RuntimeParam &model_param continue; } if (has_mem_type_attr && v_memory_type[i] == RT_MEMORY_L1) { - v_workspace_data_addr.push_back(reinterpret_cast(reinterpret_cast(v_workspace_offset[i]))); + v_workspace_data_addr.push_back(reinterpret_cast(static_cast(v_workspace_offset[i]))); GELOGI("[IMAS]GetWorkspaceDataAddrs graph_%u type[L1] name[%s], mem_addr[workspace index %zu]:0x%lx", model_param.graph_id, op_desc->GetName().c_str(), i, v_workspace_offset[i]); } else if (v_workspace_bytes[i] == 0) { diff --git a/src/ge/graph/load/new_model_manager/task_info/event_record_task_info.cc b/src/ge/graph/load/new_model_manager/task_info/event_record_task_info.cc index f742118c..817f3c0c 100644 --- a/src/ge/graph/load/new_model_manager/task_info/event_record_task_info.cc +++ b/src/ge/graph/load/new_model_manager/task_info/event_record_task_info.cc @@ -32,14 +32,13 @@ Status EventRecordTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *da return ret; } - if (task_def.event_id() >= davinci_model->EventNum()) { - GELOGE(INTERNAL_ERROR, "event_list_ size = %u cur =%u!", davinci_model->EventNum(), task_def.event_id()); + const auto &eventList = davinci_model->GetEventList(); + if (task_def.event_id() >= eventList.size()) { + GELOGE(INTERNAL_ERROR, "event list size:%zu, cur:%u!", eventList.size(), task_def.event_id()); return INTERNAL_ERROR; } - if (!davinci_model->GetEventList().empty()) { - event_ = davinci_model->GetEventList()[task_def.event_id()]; - } + event_ = eventList[task_def.event_id()]; return SUCCESS; } diff --git a/src/ge/graph/load/new_model_manager/task_info/event_wait_task_info.cc b/src/ge/graph/load/new_model_manager/task_info/event_wait_task_info.cc index e8f96b35..4ce19452 100644 --- a/src/ge/graph/load/new_model_manager/task_info/event_wait_task_info.cc +++ b/src/ge/graph/load/new_model_manager/task_info/event_wait_task_info.cc @@ -32,15 +32,13 @@ Status EventWaitTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *davi return ret; } - if (task_def.event_id() >= davinci_model->EventNum()) { - GELOGE(INTERNAL_ERROR, "event_list_ size = %u cur =%u!", davinci_model->EventNum(), task_def.event_id()); + const auto &eventList = davinci_model->GetEventList(); + if (task_def.event_id() >= eventList.size()) { + GELOGE(INTERNAL_ERROR, "event list size:%zu, cur:%u!", eventList.size(), task_def.event_id()); return INTERNAL_ERROR; } - if (!davinci_model->GetEventList().empty()) { - event_ = davinci_model->GetEventList()[task_def.event_id()]; - } - + event_ = eventList[task_def.event_id()]; event_type_ = task_def.event_ex().event_type(); return SUCCESS; diff --git a/src/ge/graph/load/new_model_manager/task_info/kernel_ex_task_info.cc b/src/ge/graph/load/new_model_manager/task_info/kernel_ex_task_info.cc index b21a9dc5..dbd60238 100644 --- a/src/ge/graph/load/new_model_manager/task_info/kernel_ex_task_info.cc +++ b/src/ge/graph/load/new_model_manager/task_info/kernel_ex_task_info.cc @@ -149,7 +149,7 @@ Status KernelExTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *davin return FAILED; } - uint64_t workspace_base_addr = reinterpret_cast(reinterpret_cast(workspace_data_addrs[0])); + uint64_t workspace_base_addr = static_cast(reinterpret_cast(workspace_data_addrs[0])); const vector input_addrs = ModelUtils::GetInputDataAddrs(rts_param, op_desc); const vector output_addrs = ModelUtils::GetOutputDataAddrs(rts_param, op_desc); vector io_addrs; @@ -287,7 +287,7 @@ Status KernelExTaskInfo::CopyTaskInfo(const domi::KernelExDef &kernel_def, const } if (workspace_data_sizes[0] < static_cast(kernel_def.task_info_size())) { - GELOGE(FAILED, "Node:%s workspace size is %zu, task info size is %zu.", op_desc->GetName().c_str(), + GELOGE(FAILED, "Node:%s workspace size is %ld, task info size is %d.", op_desc->GetName().c_str(), workspace_data_sizes[0], kernel_def.task_info_size()); return FAILED; } diff --git a/src/ge/graph/load/new_model_manager/task_info/kernel_task_info.cc b/src/ge/graph/load/new_model_manager/task_info/kernel_task_info.cc index 8c00c1d7..ac9a913f 100644 --- a/src/ge/graph/load/new_model_manager/task_info/kernel_task_info.cc +++ b/src/ge/graph/load/new_model_manager/task_info/kernel_task_info.cc @@ -31,6 +31,7 @@ #include "runtime/kernel.h" #include "super_kernel/super_kernel.h" #include "super_kernel/super_kernel_factory.h" +#include "cce/aicpu_engine_struct.h" namespace { const uint8_t kL2LoadToDdr = 1; @@ -73,7 +74,8 @@ Status KernelTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *davinci GELOGD("node[%s] is_n_batch_spilt %d", op_desc_->GetName().c_str(), is_n_batch_spilt_); (void)AttrUtils::GetInt(*op_desc_, ATTR_NAME_FUSION_GROUP_KEY, group_key_); has_group_key_ = (group_key_ != kInvalidGroupKey); - GELOGD("node[%s] has_group_key_ %ld, group key is [%ld]", op_desc_->GetName().c_str(), has_group_key_, group_key_); + GELOGD("node[%s] has_group_key_ %d, group key is [%ld]", op_desc_->GetName().c_str(), has_group_key_, group_key_); + // fusion_op_info vector original_op_names; bool result = AttrUtils::GetListStr(op_desc_, ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, original_op_names); @@ -176,7 +178,7 @@ void KernelTaskInfo::UpdateTaskId() { } task_id_ = task_id; stream_id_ = stream_id; - GELOGI("UpdateTaskId:UpdateTaskId [%u], stream id [%u]:", task_id, stream_id); + GELOGD("UpdateTaskId:UpdateTaskId [%u], stream id [%u]:", task_id, stream_id); } } @@ -216,7 +218,7 @@ Status KernelTaskInfo::SuperKernelLaunch() { rtError_t rt_ret; auto &skt_kernel_list = skt_info_.kernel_list; auto &skt_arg_list = skt_info_.arg_list; - GELOGI("SuperKernelLaunch: Skt_kernel_list size[%d] skt_arg_list[%d]", skt_kernel_list.size(), skt_arg_list.size()); + GELOGI("SuperKernelLaunch: Skt_kernel_list size[%zu] skt_arg_list[%zu]", skt_kernel_list.size(), skt_arg_list.size()); if (skt_kernel_list.size() == kSKTSingleSize && skt_arg_list.size() == kSKTSingleSize) { rt_ret = rtKernelLaunchWithFlag(skt_info_.kernel_list[0], static_cast(skt_info_.last_block_dim), skt_info_.arg_list[0], skt_info_.last_args_size, @@ -367,8 +369,9 @@ Status KernelTaskInfo::Distribute() { GELOGI("Known node %s args addr %p, offset %u.", op_desc_->GetName().c_str(), args_, args_offset_); } rtError_t rt_ret = RT_ERROR_NONE; - char *skt_enable_env = getenv("SKT_ENABLE"); - int64_t env_flag = (skt_enable_env != nullptr) ? strtol(skt_enable_env, nullptr, 10) : 0; + char skt_enable_env[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv("SKT_ENABLE", skt_enable_env, MMPA_MAX_PATH); + int64_t env_flag = (res == EN_OK) ? strtol(skt_enable_env, nullptr, 10) : 0; bool call_skt = ((env_flag != 0) || is_l1_fusion_enable_); if (kernel_type_ == cce::ccKernelType::AI_CPU || kernel_type_ == cce::ccKernelType::CUST_AI_CPU) { GELOGI("distribute task info kernel_type %d, flag %d", kernel_type_, dump_flag_); @@ -379,7 +382,7 @@ Status KernelTaskInfo::Distribute() { call_save_dump_ = true; } else { /* default: not skt launch */ - GELOGI( + GELOGD( "KernelTaskInfo Distribute Start, sktenable:%d taskid:%u sktid:%u last_sktid:%u stubfunc_name:%s " "stubfunc:%p blockdim:%u stream:%p", call_skt, task_id_, skt_id_, skt_info_.last_task_id, stub_func_name_.c_str(), stub_func_, block_dim_, stream_); @@ -406,7 +409,7 @@ Status KernelTaskInfo::Distribute() { } // set for task_id_ UpdateTaskId(); - GELOGI( + GELOGD( "KernelTaskInfo Distribute Success. sktenable:%d taskid:%d sktid:%d stubfunc_name:%s stubfunc:%p " "blockdim:%d stream:%p", call_skt, task_id_, skt_id_, stub_func_name_.c_str(), stub_func_, block_dim_, stream_); @@ -747,15 +750,15 @@ Status KernelTaskInfo::InitAICPUCustomTask(uint32_t op_index, const domi::Kernel } } *(reinterpret_cast(args + ctx_.argsOffset[0])) = - reinterpret_cast(reinterpret_cast(custom_info_.input_descs)); // arg 0 + static_cast(reinterpret_cast(custom_info_.input_descs)); // arg 0 *(reinterpret_cast(args + ctx_.argsOffset[1])) = - reinterpret_cast(reinterpret_cast(custom_info_.input_addrs)); // arg 1 + static_cast(reinterpret_cast(custom_info_.input_addrs)); // arg 1 *(reinterpret_cast(args + ctx_.argsOffset[2])) = - reinterpret_cast(reinterpret_cast(custom_info_.output_descs)); // arg 2 + static_cast(reinterpret_cast(custom_info_.output_descs)); // arg 2 *(reinterpret_cast(args + ctx_.argsOffset[3])) = - reinterpret_cast(reinterpret_cast(custom_info_.output_addrs)); // arg 3 + static_cast(reinterpret_cast(custom_info_.output_addrs)); // arg 3 *(reinterpret_cast(args + ctx_.argsOffset[4])) = - reinterpret_cast(reinterpret_cast(custom_info_.attr_handle)); // arg 4 + static_cast(reinterpret_cast(custom_info_.attr_handle)); // arg 4 rt_ret = rtMalloc(&args_, args_size_, RT_MEMORY_HBM); if (rt_ret != RT_ERROR_NONE) { @@ -913,7 +916,7 @@ Status KernelTaskInfo::InitAicpuTask(uint32_t op_index, const domi::KernelDef &k op_desc_->GetType().c_str(), ext_info.size(), aicpu_ext_info_addr_); aicpu_param_head->extInfoAddr = reinterpret_cast(aicpu_ext_info_addr_); - aicpu_param_head->extInfoLength = reinterpret_cast(ext_info.size()); + aicpu_param_head->extInfoLength = static_cast(ext_info.size()); // malloc device memory for args rtError_t rt_ret = rtMalloc(static_cast(&args_), args_size_, RT_MEMORY_HBM); @@ -956,12 +959,40 @@ Status KernelTaskInfo::InitAicpuTaskExtInfo(const std::string &ext_info) { if (ext_info.empty()) { return SUCCESS; } + + std::unique_ptr copy_ext_info; + copy_ext_info.reset(new (std::nothrow) uint8_t[ext_info.size()]); + GE_CHECK_NOTNULL(copy_ext_info); + auto sec_ret = memcpy_s(copy_ext_info.get(), ext_info.size(), ext_info.c_str(), ext_info.size()); + if (sec_ret != EOK) { + GELOGE(FAILED, "memcpy failed, ret: %d", sec_ret); + return FAILED; + } + + auto ext_info_data = copy_ext_info.get(); + size_t offset = 0; + while (offset + sizeof(aicpu::FWKAdapter::ExtInfo) <= ext_info.size()) { + auto aicpu_ext_info = reinterpret_cast(ext_info_data + offset); + GELOGD("Ext infoType=%d, infoLen=%u.", aicpu_ext_info->infoType, aicpu_ext_info->infoLen); + if (aicpu_ext_info->infoType == aicpu::FWKAdapter::FWK_ADPT_EXT_SESSION_INFO) { + GE_CHK_BOOL_RET_STATUS(aicpu_ext_info->infoLen == sizeof(SessionInfo), PARAM_INVALID, + "Parse ext session info failed as infoLen must be %zu but %u.", sizeof(SessionInfo), + aicpu_ext_info->infoLen); + SessionInfo *session_info = reinterpret_cast(aicpu_ext_info->infoMsg); + session_info->sessionId = davinci_model_->GetSessionId(); + session_info->sessFlag = true; + GELOGD("Update aicpu_task ext_info session_info session_id is %lu", session_info->sessionId); + } + offset += sizeof(aicpu::FWKAdapter::ExtInfo); + offset += aicpu_ext_info->infoLen; + } + auto rt_ret = rtMalloc(&aicpu_ext_info_addr_, ext_info.size(), RT_MEMORY_HBM); if (rt_ret != RT_ERROR_NONE) { GELOGE(RT_FAILED, "rtMalloc ext_info error: 0x%X, size=%zu", rt_ret, ext_info.size()); return RT_ERROR_TO_GE_STATUS(rt_ret); } - rt_ret = rtMemcpy(aicpu_ext_info_addr_, ext_info.size(), ext_info.c_str(), ext_info.size(), RT_MEMCPY_HOST_TO_DEVICE); + rt_ret = rtMemcpy(aicpu_ext_info_addr_, ext_info.size(), ext_info_data, ext_info.size(), RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { GELOGE(RT_FAILED, "rtMemcpy ext_info error: 0x%X, size=%zu", rt_ret, ext_info.size()); return RT_ERROR_TO_GE_STATUS(rt_ret); @@ -1122,18 +1153,25 @@ Status KernelTaskInfo::CceUpdateKernelArgs(const domi::KernelContext &context, u } GELOGI("FileName:%s, Path:%s.", file_name.c_str(), canonicalPath.c_str()); - auto handle = dlopen(canonicalPath.c_str(), RTLD_NOW | RTLD_GLOBAL); + auto handle = mmDlopen(canonicalPath.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); + const char *error = ""; if (handle == nullptr) { - GELOGE(GE_PLGMGR_SO_NOT_EXIST, "Failed in dlopen %s! ", dlerror()); + error = mmDlerror(); + GE_IF_BOOL_EXEC(error == nullptr, error = ""); + GELOGE(GE_PLGMGR_SO_NOT_EXIST, "Failed in dlopen %s! ", error); return FAILED; } cce::ccStatus_t cc_ret; - auto cceUpdateKernelArgs = (cce::ccStatus_t(*)(cce::ccOpContext &, uint64_t, uint64_t, uint64_t, void *, uint64_t, - void *))dlsym(handle, "ccUpdateKernelArgs"); + std::string update_kernel_args = "ccUpdateKernelArgs"; + auto cceUpdateKernelArgs = + (cce::ccStatus_t(*)(cce::ccOpContext &, uint64_t, uint64_t, uint64_t, void *, uint64_t, void *))mmDlsym( + handle, const_cast(update_kernel_args.c_str())); if (cceUpdateKernelArgs == nullptr) { GELOGE(FAILED, "Failed to invoke function ccUpdateKernelArgs"); - if (dlclose(handle) != 0) { - GELOGW("Failed to close handle %s", dlerror()); + if (mmDlclose(handle) != 0) { + error = mmDlerror(); + GE_IF_BOOL_EXEC(error == nullptr, error = ""); + GELOGW("Failed to close handle %s", error); } return FAILED; } else { @@ -1146,8 +1184,10 @@ Status KernelTaskInfo::CceUpdateKernelArgs(const domi::KernelContext &context, u const_cast(kernel_def.args().data()), args_size_, sm_contrl); } } - if (dlclose(handle) != 0) { - GELOGW("Failed to close handle %s", dlerror()); + if (mmDlclose(handle) != 0) { + error = mmDlerror(); + GE_IF_BOOL_EXEC(error == nullptr, error = ""); + GELOGW("Failed to close handle %s", error); return FAILED; } if (cc_ret != cce::CC_STATUS_SUCCESS) { @@ -1188,7 +1228,7 @@ Status KernelTaskInfo::SetFlowtable(std::string &flowtable, const domi::KernelDe *(reinterpret_cast( args + (reinterpret_cast(const_cast(context.args_offset().data())))[0])) = - reinterpret_cast(reinterpret_cast(flowtable_)); + static_cast(reinterpret_cast(flowtable_)); } return SUCCESS; } diff --git a/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel.cc b/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel.cc index 100a4fea..2fa00c8c 100644 --- a/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel.cc +++ b/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel.cc @@ -23,7 +23,7 @@ Status SuperKernel::Launch(rtStream_t stream, uint32_t dump_flag) { const void *func_stub_ = this->GetFuncStub(); const void *args[] = {this->GetNavTablePtr(), - reinterpret_cast(reinterpret_cast(this->GetNavTableSize()))}; + reinterpret_cast(static_cast(this->GetNavTableSize()))}; rtError_t rt_ret = rtMalloc((void **)&(device_args_addr_), sizeof(args), RT_MEMORY_HBM); GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, GELOGE(RT_FAILED, "rtMalloc failied. error: 0x%X", rt_ret); diff --git a/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel_factory.cc b/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel_factory.cc index ca42b4e2..52366a1c 100644 --- a/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel_factory.cc +++ b/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel_factory.cc @@ -27,7 +27,7 @@ SuperKernelFactory &SuperKernelFactory::GetInstance() { Status SuperKernelFactory::Init() { if (!is_init_) { std::string skt_bin = "libcce_aicore.so"; - handle_ = dlopen(skt_bin.c_str(), RTLD_NOW | RTLD_GLOBAL); + handle_ = mmDlopen(skt_bin.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); if (handle_ == nullptr) { GELOGE(FAILED, "SKT: open skt lib failed, please check LD_LIBRARY_PATH."); } @@ -85,8 +85,10 @@ Status SuperKernelFactory::FuseKernels(const std::vector &stub_func_list "equal to 2"); return FAILED; } - GELOGI("SKT: superkernel start fuse, superkernel size %d.", stub_func_list.size()); - uint64_t nav_table[2 * stub_func_list.size()]; + GELOGI("SKT: superkernel start fuse, superkernel size %zu.", stub_func_list.size()); + const size_t nav_table_len = 2 * stub_func_list.size(); + std::unique_ptr nav_table(new (std::nothrow) uint64_t[nav_table_len]); + GE_CHECK_NOTNULL(nav_table); uint64_t nav_table_size = 2 * stub_func_list.size() * sizeof(int64_t); rtError_t rt_ret; @@ -99,16 +101,16 @@ Status SuperKernelFactory::FuseKernels(const std::vector &stub_func_list GELOGD("SKT: fuseKernels subFunc %p, device func address %p", stub_func_list[i], sub_device_func); // store two uint64_t address // address divided by 4 because of 32bits encoding, call offset will *4 when calculating - nav_table[i * 2] = reinterpret_cast(reinterpret_cast(sub_device_func)) / 4; + nav_table[i * 2] = static_cast(reinterpret_cast(sub_device_func)) / 4; GELOGD("SKT: CALL offet %lu", nav_table[i * 2]); - nav_table[i * 2 + 1] = reinterpret_cast(reinterpret_cast(args_addr_list[i])); + nav_table[i * 2 + 1] = static_cast(reinterpret_cast(args_addr_list[i])); GELOGD("SKT: fuseKernels args base address %lu", nav_table[i * 2 + 1]); } rt_ret = rtMalloc((void **)&hbm_nav_table_addr, nav_table_size, RT_MEMORY_HBM); GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, GELOGE(RT_FAILED, "rtMalloc failed. error: 0x%X", rt_ret); return RT_ERROR_TO_GE_STATUS(rt_ret);) - rt_ret = - rtMemcpy((void *)hbm_nav_table_addr, nav_table_size, (void *)nav_table, nav_table_size, RT_MEMCPY_HOST_TO_DEVICE); + rt_ret = rtMemcpy((void *)hbm_nav_table_addr, nav_table_size, (void *)nav_table.get(), nav_table_size, + RT_MEMCPY_HOST_TO_DEVICE); GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, GELOGE(RT_FAILED, "rtMemcpy failed. error: 0x%X", rt_ret); GE_CHK_RT(rtFree(hbm_nav_table_addr)); return RT_ERROR_TO_GE_STATUS(rt_ret);) // Create the necessary metadata for the super kernel diff --git a/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel_factory.h b/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel_factory.h index 7db44eec..b02385a6 100644 --- a/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel_factory.h +++ b/src/ge/graph/load/new_model_manager/task_info/super_kernel/super_kernel_factory.h @@ -34,8 +34,10 @@ class SuperKernelFactory { ~SuperKernelFactory() { if (handle_ != nullptr) { GELOGI("SKT: SKT LIB PATH release."); - if (dlclose(handle_) != 0) { - GELOGW("failed to close handle, message: %s", dlerror()); + if (mmDlclose(handle_) != 0) { + const char *error = mmDlerror(); + GE_IF_BOOL_EXEC(error == nullptr, error = ""); + GELOGW("failed to close handle, message: %s", error); } } }; diff --git a/src/ge/graph/load/new_model_manager/zero_copy_offset.cc b/src/ge/graph/load/new_model_manager/zero_copy_offset.cc index 910c1a72..7a94d10b 100644 --- a/src/ge/graph/load/new_model_manager/zero_copy_offset.cc +++ b/src/ge/graph/load/new_model_manager/zero_copy_offset.cc @@ -30,49 +30,37 @@ ZeroCopyOffset::ZeroCopyOffset() {} ZeroCopyOffset::~ZeroCopyOffset() {} -Status ZeroCopyOffset::InitInputDataInfo(const vector &output_size_list, - const vector &virtual_addr_list, const OpDescPtr &op_desc, +Status ZeroCopyOffset::InitInputDataInfo(int64_t output_size, void *virtual_addr, const OpDescPtr &op_desc, bool &fusion_flag) { GELOGI("[ZCPY] Start to InitInputDataInfo of %s, total_data_size is %ld, virtual_addr is %p", - op_desc->GetName().c_str(), output_size_list[kDataIndex], virtual_addr_list[kDataIndex]); - if (output_size_list.empty() || virtual_addr_list.empty() || (output_size_list.size() != virtual_addr_list.size())) { - GELOGE(PARAM_INVALID, "Data[%s] init failed: Output size is %zu, Output addr is %zu", op_desc->GetName().c_str(), - output_size_list.size(), virtual_addr_list.size()); - return PARAM_INVALID; - } - - basic_addr_ = virtual_addr_list[kDataIndex]; + op_desc->GetName().c_str(), output_size, virtual_addr); + basic_addr_ = virtual_addr; (void)ge::AttrUtils::GetListInt(op_desc, ATTR_ZERO_COPY_BASIC_OFFSET, zero_copy_basic_offset_); (void)ge::AttrUtils::GetListInt(op_desc, ATTR_ZERO_COPY_RELATIVE_OFFSET, zero_copy_relative_offset_); GE_CHK_BOOL_EXEC(zero_copy_basic_offset_.size() == zero_copy_relative_offset_.size(), return PARAM_INVALID, "basic_offset_size should be equal to relative_offset_size"); - GELOGI("[ZCPY] zero_copy_basic_offset size is %zu", zero_copy_basic_offset_.size()); + GELOGD("[ZCPY] zero_copy_basic_offset size is %zu", zero_copy_basic_offset_.size()); int64_t virtual_addr_offset = op_desc->GetOutputOffset().at(kDataIndex); - GELOGI("virtual_addr_offset is %ld.", virtual_addr_offset); IsL2Fusion(zero_copy_basic_offset_, virtual_addr_offset, fusion_flag); uint32_t out_count = 0; - data_size_ = output_size_list[kDataIndex]; + data_size_ = output_size; if (!fusion_flag) { - GELOGI("[ZCPY] %s not set l2_fusion.", op_desc->GetName().c_str()); out_count++; - data_info_.emplace_back(output_size_list[kDataIndex], virtual_addr_list[kDataIndex]); + data_info_.emplace_back(output_size, virtual_addr); relative_offset_.emplace_back(0); - GELOGI("[ZCPY] %s size is %ld, virtual_addr is %p.", op_desc->GetName().c_str(), output_size_list[kDataIndex], - virtual_addr_list[kDataIndex]); + GELOGD("[ZCPY] %s size is %ld, virtual_addr is %p.", op_desc->GetName().c_str(), output_size, virtual_addr); } else { GELOGI("[ZCPY] set l2_fusion for %s.", op_desc->GetName().c_str()); for (size_t index = 0; index < zero_copy_basic_offset_.size(); ++index) { if (zero_copy_basic_offset_.at(index) == virtual_addr_offset) { out_count++; - uint64_t out_offset = - reinterpret_cast(virtual_addr_list[kDataIndex]) + zero_copy_relative_offset_.at(index); - int64_t real_data_size = ModelUtils::GetOutputSize(op_desc).at(kDataIndex); - data_info_.emplace_back(real_data_size, reinterpret_cast(reinterpret_cast(out_offset))); + uint64_t out_offset = reinterpret_cast(virtual_addr) + zero_copy_relative_offset_.at(index); + data_info_.emplace_back(output_size, reinterpret_cast(static_cast(out_offset))); relative_offset_.emplace_back(zero_copy_relative_offset_.at(index)); GELOGI("[ZCPY] virtual_addr: %p has been l2-fusion to %lu, need copy data_size is %ld.", basic_addr_, - out_offset, real_data_size); + out_offset, output_size); } } } @@ -83,7 +71,6 @@ Status ZeroCopyOffset::InitInputDataInfo(const vector &output_size_list Status ZeroCopyOffset::InitOutputDataInfo(const vector &input_size_list, const vector &virtual_addr_list, const OpDescPtr &op_desc, const size_t &idx, bool &fusion_flag) { - GELOGI("[ZCPY] Start to InitOutputDataInfo of %s.", op_desc->GetName().c_str()); int64_t size = input_size_list[idx]; auto tensor_desc = op_desc->GetInputDescPtr(idx); GE_CHECK_NOTNULL(tensor_desc); @@ -92,7 +79,7 @@ Status ZeroCopyOffset::InitOutputDataInfo(const vector &input_size_list return FAILED; } - GELOGI("Tensor data size: GetSize=%ld, GetTensorSizeInBytes=%ld", input_size_list[idx], size); + GELOGD("Tensor data size: GetSize=%ld, GetTensorSizeInBytes=%ld", input_size_list[idx], size); basic_addr_ = virtual_addr_list[idx]; (void)ge::AttrUtils::GetListInt(op_desc, ATTR_ZERO_COPY_BASIC_OFFSET, zero_copy_basic_offset_); @@ -100,13 +87,11 @@ Status ZeroCopyOffset::InitOutputDataInfo(const vector &input_size_list GE_CHK_BOOL_EXEC(zero_copy_basic_offset_.size() == zero_copy_relative_offset_.size(), return PARAM_INVALID, "basic_offset_size should be equal to relative_offset_size"); int64_t virtual_addr_offset = op_desc->GetInputOffset().at(idx); - GELOGI("virtual_addr_offset is %ld.", virtual_addr_offset); IsL2Fusion(zero_copy_basic_offset_, virtual_addr_offset, fusion_flag); uint32_t in_count = 0; data_size_ = size; if (!fusion_flag) { - GELOGI("[ZCPY] %s not set l2-fusion.", op_desc->GetName().c_str()); in_count++; data_info_.emplace_back(size, virtual_addr_list[idx]); // op_desc not set l2fusion when fusion_flag is false @@ -119,7 +104,7 @@ Status ZeroCopyOffset::InitOutputDataInfo(const vector &input_size_list in_count++; uint64_t in_offset = reinterpret_cast(virtual_addr_list[idx]) + zero_copy_relative_offset_.at(index); int64_t real_data_size = ModelUtils::GetInputSize(op_desc).at(idx); - data_info_.emplace_back(real_data_size, reinterpret_cast(reinterpret_cast(in_offset))); + data_info_.emplace_back(real_data_size, reinterpret_cast(static_cast(in_offset))); relative_offset_.emplace_back(zero_copy_relative_offset_.at(index)); GELOGI("[ZCPY] virtual_addr: %p has been l2-fusion from %lu, need copy data_size is %ld.", basic_addr_, in_offset, real_data_size); @@ -142,10 +127,8 @@ void ZeroCopyOffset::IsL2Fusion(const vector &fusion_basic_addrs, const void ZeroCopyOffset::SetInputOutsideAddrs(const vector &output_offset_list, void *addr, const size_t &index, bool fusion_flag, std::set &real_virtual_addrs) { - GELOGI("[ZCPY] Start to SetInputOutsideAddrs for virtual_addr %p.", addr); uint32_t out_count = 0; if (!fusion_flag) { - GELOGI("[ZCPY] not set l2-fusion for virtual_adr %p.", addr); out_count++; std::map> addr_mapping; addr_mapping[addr] = {}; @@ -175,7 +158,6 @@ void ZeroCopyOffset::SetOutputOutsideAddrs(const int64_t &input_offset, const bo GELOGI("[ZCPY] Start to SetOutputOutsideAddrs for virtual_addr %p.", addr); uint32_t out_count = 0; if (!fusion_flag) { - GELOGI("[ZCPY] not set l2-fusion for virtual_addr %p.", addr); out_count++; std::map> addr_mapping; addr_mapping[addr] = {}; @@ -209,7 +191,7 @@ bool ZeroCopyOffset::SetOutsideAddrsValue(ZeroCopyTask &zero_copy_task, void *ou GE_CHK_STATUS(zero_copy_task.SetTaskArgsOffset(addr_val, offset), "Input args invalid."); void *args_val = static_cast(args) + offset; args_addrs->second.push_back(args_val); - GELOGI("[ZCPY] set copy input: virtual_addr: 0x%lx, task_addr: %p, args: %p, offset: %zu.", addr_val, args_val, + GELOGD("[ZCPY] set copy input: virtual_addr: 0x%lx, task_addr: %p, args: %p, offset: %zu.", addr_val, args_val, args, offset); set_batch_label_flag = true; } diff --git a/src/ge/graph/load/new_model_manager/zero_copy_offset.h b/src/ge/graph/load/new_model_manager/zero_copy_offset.h index 8749d937..e641e8de 100644 --- a/src/ge/graph/load/new_model_manager/zero_copy_offset.h +++ b/src/ge/graph/load/new_model_manager/zero_copy_offset.h @@ -42,8 +42,7 @@ class ZeroCopyOffset { ZeroCopyOffset(); ~ZeroCopyOffset(); - Status InitInputDataInfo(const vector &output_size_list, const vector &virtual_addr_list, - const OpDescPtr &op_desc, bool &fusion_flag); + Status InitInputDataInfo(int64_t output_size, void *virtual_addr, const OpDescPtr &op_desc, bool &fusion_flag); void SetInputOutsideAddrs(const vector &output_offset_list, void *addr, const size_t &index, bool fusion_flag, std::set &real_virtual_addrs); diff --git a/src/ge/graph/load/new_model_manager/zero_copy_task.cc b/src/ge/graph/load/new_model_manager/zero_copy_task.cc index 4a083f33..420510db 100644 --- a/src/ge/graph/load/new_model_manager/zero_copy_task.cc +++ b/src/ge/graph/load/new_model_manager/zero_copy_task.cc @@ -19,6 +19,7 @@ #include "framework/common/debug/ge_log.h" #include "framework/common/util.h" #include "graph/load/new_model_manager/model_utils.h" +#include "common/ge_compiler_options.h" namespace ge { const char *const kDefaultBatchLable = "Batch_default"; @@ -48,7 +49,7 @@ Status ZeroCopyTask::SetTaskArgsOffset(uintptr_t addr, size_t offset) { it->second.insert(offset); } - GELOGI("[ZCPY] %s set task, virtual_addr: 0x%lx, args_addr: %p, size: %zu, offset: %zu", name_.c_str(), addr, + GELOGD("[ZCPY] %s set task, virtual_addr: 0x%lx, args_addr: %p, size: %zu, offset: %zu", name_.c_str(), addr, args_addr_, args_size_, offset); return SUCCESS; } @@ -157,7 +158,7 @@ Status ZeroCopyTask::DistributeParam(bool async_mode, rtStream_t stream) { rt_err = rtMemcpyAsync(args_addr_, args_size_, args_info_.data(), args_info_.size(), RT_MEMCPY_HOST_TO_DEVICE_EX, stream); } else { - __builtin_prefetch(args_addr_); + GE_BUILTIN_PREFETCH(args_addr_); rt_err = rtMemcpy(args_addr_, args_size_, args_info_.data(), args_info_.size(), RT_MEMCPY_HOST_TO_DEVICE); } @@ -166,7 +167,7 @@ Status ZeroCopyTask::DistributeParam(bool async_mode, rtStream_t stream) { return RT_ERROR_TO_GE_STATUS(rt_err); } - GELOGI("[ZCPY] %s refresh task args success, args_addr: %p, size: %zu, args_info_: %p, length: %zu", name_.c_str(), + GELOGD("[ZCPY] %s refresh task args success, args_addr: %p, size: %zu, args_info_: %p, length: %zu", name_.c_str(), args_addr_, args_size_, args_info_.data(), args_info_.size()); return SUCCESS; } diff --git a/src/ge/graph/manager/graph_manager.cc b/src/ge/graph/manager/graph_manager.cc index 17fa1299..b2a6fb54 100644 --- a/src/ge/graph/manager/graph_manager.cc +++ b/src/ge/graph/manager/graph_manager.cc @@ -108,6 +108,10 @@ #include "graph/types.h" #include "inc/pass_manager.h" #include "init/gelib.h" +#include "ir_build/atc_ir_common.h" +#include "graph/common/local_context.h" +#include "graph/common/omg_util.h" +#include "common/formats/utils/formats_trans_utils.h" namespace { const char *const kSummary = "Summary"; @@ -121,6 +125,12 @@ const char *const kCheckPointGraph = "checkpoint_graph"; const char *const kVectorEngine = "VectorEngine"; const char *const kAIcoreEngine = "AIcoreEngine"; const char *const kOffOptimize = "off_optimize"; +const int32_t kDynamicDimsTypeIsGetNext = 0; +const int32_t kDynamicDimsTypeIsData = 1; +const int64_t kInvalidDynaimcDimsType = -1; +const char *const kSubstrOfGetNextNosinkName = "IteratorGetNext"; +const char *const kShapeDataName = "ascend_mbatch_shape_data"; +const char *const kGetNextName = "IteratorV2"; bool IsTailingOptimization() { string is_tailing_optimization_option; @@ -280,6 +290,42 @@ Status GraphManager::Finalize() { return unload_model_ret; } +Status GraphManager::InitDynamicParams(ComputeGraphPtr &compute_graph) { + for (const auto &node : compute_graph->GetAllNodes()) { + auto op_desc = node->GetOpDesc(); + if (op_desc == nullptr) { + continue; + } + GetLocalOmgContext().need_multi_batch = false; + std::string op_type; + auto ret = GetOriginalType(node, op_type); + if (ret != SUCCESS) { + GELOGE(FAILED, "Failed to get node %s original type.", node->GetName().c_str()); + return FAILED; + } + if ((op_desc->GetType() == DATA) || (op_type == kGetNextName)) { + GELOGI("Need to process multi batch for compute graph."); + GetLocalOmgContext().need_multi_batch = true; + break; + } + } + if (!options_.input_shape.empty() && !options_.dynamic_dims.empty()) { + if (!ge::ParseInputShape(options_.input_shape, GetLocalOmgContext().input_dims, + GetLocalOmgContext().user_input_dims, true)) { + GELOGE(GRAPH_PARAM_INVALID, "Failed to parse input shape: %s.", options_.input_shape.c_str()); + return GRAPH_PARAM_INVALID; + } + GetLocalOmgContext().dynamic_dims = options_.dynamic_dims; + } + if (options_.dynamic_node_type == kDynamicDimsTypeIsGetNext) { + GetLocalOmgContext().dynamic_node_type = GETNEXT; + } + if (options_.dynamic_node_type == kDynamicDimsTypeIsData) { + GetLocalOmgContext().dynamic_node_type = DATA; + } + return SUCCESS; +} + Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph, const std::map &options, const OmgContext &omg_context) { if (HasGraphNode(graph_id)) { @@ -298,6 +344,7 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph, return GE_GRAPH_GRAPH_ALREADY_EXIST; } (void)AttrUtils::SetBool(*compute_graph, ATTR_NAME_GRAPH_HAS_BEEN_ADDED, true); + compute_graph_ = compute_graph; } else { GELOGE(FAILED, "compute graph is null"); return FAILED; @@ -311,19 +358,13 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph, for (auto &subgraph : compute_graph->GetAllSubgraphs()) { (void)AttrUtils::SetStr(*subgraph, ATTR_NAME_SESSION_GRAPH_ID, session_graph_id); } - GELOGW("Get graph session_graph_id attr failed, set session id to default value: [0]"); + GELOGD("Get graph session_graph_id attr failed, set session id to default value: [0]"); } GraphNodePtr graph_node = MakeShared(graph_id); - if (graph_node == nullptr) { - GELOGE(FAILED, "GraphNode make shared failed"); - return FAILED; - } + GE_IF_BOOL_EXEC(graph_node == nullptr, GELOGE(FAILED, "GraphNode make shared failed"); return FAILED); std::shared_ptr graph_ptr = MakeShared(graph); - if (graph_ptr == nullptr) { - GELOGE(FAILED, "GraphPtr make shared failed"); - return FAILED; - } + GE_IF_BOOL_EXEC(graph_ptr == nullptr, GELOGE(FAILED, "GraphPtr make shared failed"); return FAILED); graph_node->SetGraph(graph_ptr); graph_node->SetOptions(options); @@ -333,6 +374,10 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph, if (!options_.output_datatype.empty()) { GetLocalOmgContext().output_type = options_.output_datatype; } + if (InitDynamicParams(compute_graph) != SUCCESS) { + GELOGE(GRAPH_PARAM_INVALID, "Failed to init params when online infer is dynamic."); + return GRAPH_PARAM_INVALID; + } CompilerStages &stages = GetCompilerStages(graph_id); stages.preparer.SetOptions(options_); @@ -344,8 +389,6 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph, stages.builder.SetOptions(options_); var_acc_ctrl_.AddGraph(graph_id, compute_graph); - - GELOGI("[GraphManager] add graph success, graph_id = %u.", graph_id); return SUCCESS; } @@ -383,7 +426,7 @@ Status GraphManager::AddGraphWithCopy(const GraphId &graph_id, const Graph &grap for (auto &subgraph : new_compute_graph->GetAllSubgraphs()) { (void)AttrUtils::SetStr(*subgraph, ATTR_NAME_SESSION_GRAPH_ID, session_graph_id); } - GELOGW("Get graph session_graph_id attr failed, set session id to default value: [0]"); + GELOGD("Get graph session_graph_id attr failed, set session id to default value: [0]"); } GraphNodePtr graph_node = MakeShared(graph_id); @@ -416,8 +459,6 @@ Status GraphManager::AddGraphWithCopy(const GraphId &graph_id, const Graph &grap stages.builder.SetOptions(options_); var_acc_ctrl_.AddGraph(graph_id, new_compute_graph); - - GELOGI("[GraphManager] add graph success, graph_id = %u.", graph_id); return SUCCESS; } @@ -493,7 +534,7 @@ Status GraphManager::OptimizeSubGraphWithMultiThreads(ComputeGraphPtr compute_gr const auto &root_subgraph_list = sub_graph_map[compute_graph]; std::string op_compile_strategy; (void)AttrUtils::GetStr(compute_graph, ATTR_NAME_OP_COMPILE_STRATEGY, op_compile_strategy); - GELOGI("OptimizeSubGraphWithMultiThreads Process op_compile_strategy:%s", op_compile_strategy.c_str()); + GELOGD("OptimizeSubGraphWithMultiThreads Process op_compile_strategy:%s", op_compile_strategy.c_str()); for (const auto &subgraph : root_subgraph_list) { if (!op_compile_strategy.empty()) { (void)AttrUtils::SetStr(subgraph->GetSubGraph(), ATTR_NAME_OP_COMPILE_STRATEGY, op_compile_strategy); @@ -523,7 +564,7 @@ Status GraphManager::OptimizeSubGraphWithMultiThreads(ComputeGraphPtr compute_gr vector_future.emplace_back(std::move(f)); } } - GELOGI("All sub graph num is %zu", vector_future.size()); + GELOGD("All sub graph num is %zu", vector_future.size()); for (size_t i = 0; i < vector_future.size(); ++i) { Status ret_status = vector_future[i].get(); if (ret_status != SUCCESS) { @@ -647,7 +688,7 @@ Status GraphManager::SetSubgraph(uint64_t session_id, ComputeGraphPtr compute_gr /// Multiply optimize subgraph: /// 1. run lx buffer while build_mode is normal and buffer_optimize is empty or "off_optimize"; /// 2. run lx fusion or buffer according build_mode and build_step in fe. - GELOGI("Directly optimize subgraph with build mode:%s, and step:%s, buffer_optimize:%s.", + GELOGD("Directly optimize subgraph with build mode:%s, and step:%s, buffer_optimize:%s.", options_.build_mode.c_str(), options_.build_step.c_str(), buffer_optimize.c_str()); Status ret = OptimizeSubGraphWithMultiThreads(compute_graph, sub_graph_map, session_id); if (ret != SUCCESS) { @@ -692,7 +733,7 @@ Status GraphManager::PreRunOptimizeOriginalGraph(const GraphNodePtr &graph_node, GE_CHK_STATUS_RET(graph_pass.Run(compute_graph)); GE_CHK_STATUS_RET(stages.optimizer.IdentifyReference(compute_graph), "Identify reference failed."); - GELOGI("PreRun:PreRunOptimizeOriginalGraph success."); + GELOGD("PreRun:PreRunOptimizeOriginalGraph success."); return SUCCESS; } @@ -706,10 +747,10 @@ Status GraphManager::PreRunOptimizeSubGraph(const GraphNodePtr &graph_node, ge:: if (options_.build_mode == BUILD_MODE_TUNING && options_.build_step == BUILD_STEP_AFTER_UB_MATCH) { std::string tuning_path; (void)GetContext().GetOption(TUNING_PATH, tuning_path); - GELOGI("Dump path:%s.", tuning_path.c_str()); + GELOGD("Dump path:%s.", tuning_path.c_str()); GraphUtils::DumpGEGraph(compute_graph, "", true, tuning_path); } - GELOGI("PreRun:PreRunOptimizeSubGraph success."); + GELOGD("PreRun:PreRunOptimizeSubGraph success."); return SUCCESS; } @@ -729,12 +770,12 @@ Status GraphManager::PreRunAfterOptimizeSubGraph(const GraphNodePtr &graph_node, } GM_RUN_AND_DUMP_PERF("Build", Build, graph_node, compute_graph, ge_root_model, session_id); - GELOGI("PreRun:PreRunAfterOptimizeSubGraph success."); + GELOGD("PreRun:PreRunAfterOptimizeSubGraph success."); return SUCCESS; } Status GraphManager::SetRtContext(rtContext_t rt_context, rtCtxMode_t mode, uint64_t session_id, uint32_t graph_id) { - GELOGI("set rt_context, session id: %lu, graph id: %u, mode %d, device id:%u.", session_id, graph_id, + GELOGD("set rt_context, session id: %lu, graph id: %u, mode %d, device id:%u.", session_id, graph_id, static_cast(mode), ge::GetContext().DeviceId()); rtError_t rt_ret = rtCtxCreate(&rt_context, mode, ge::GetContext().DeviceId()); @@ -1195,7 +1236,7 @@ Status GraphManager::BuildGraphForUnregisteredOp(const GraphId &graph_id, const Status GraphManager::BuildGraph(const GraphId &graph_id, const std::vector &inputs, GeRootModelPtr &ge_root_model, uint64_t session_id, bool async) { - GELOGI("[BuildGraph] start to build graph, graph_id=%u.", graph_id); + GELOGD("[BuildGraph] start to build graph, graph_id=%u.", graph_id); if (inputs.empty()) { GELOGW("[BuildGraph] BuildGraph warning: empty GeTensor inputs"); } @@ -1393,10 +1434,8 @@ Status GraphManager::ParseOptions(const std::map &opti // get encrypt mode ret = ParseOption(options, ENCRYPT_MODE, options_.encrypt_mode); - if (ret != SUCCESS) { - GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.encryptMode value invalid."); - return GE_GRAPH_OPTIONS_INVALID; - } + GE_IF_BOOL_EXEC(ret != SUCCESS, GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.encryptMode value invalid."); + return GE_GRAPH_OPTIONS_INVALID); // get ek file ParseOption(options, EK_FILE, options_.ek_file); @@ -1434,33 +1473,27 @@ Status GraphManager::ParseOptions(const std::map &opti // get weight compress flag ret = ParseOption(options, COMPRESS_FLAG, options_.compress_flag); - if (ret != SUCCESS) { - GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.compressFlag value is invalid, must be 0 or 1."); - return GE_GRAPH_OPTIONS_INVALID; - } + GE_IF_BOOL_EXEC(ret != SUCCESS, + GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.compressFlag value is invalid, must be 0 or 1."); + return GE_GRAPH_OPTIONS_INVALID); // ge.graphType. options_.run_graph_flag = true; ret = ParseOption(options, RUN_FLAG, options_.run_graph_flag); - if (ret != SUCCESS) { - GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.runFlag value is invalid, must be 0 or 1."); - return GE_GRAPH_OPTIONS_INVALID; - } + GE_IF_BOOL_EXEC(ret != SUCCESS, GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.runFlag value is invalid, must be 0 or 1."); + return GE_GRAPH_OPTIONS_INVALID); // ge.graphType ret = ParseTrainGraphFlag(options_.run_graph_flag, options_.train_graph_flag); - if (ret != SUCCESS) { - GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.runFlag value is invalid"); - return GE_GRAPH_OPTIONS_INVALID; - } + GE_IF_BOOL_EXEC(ret != SUCCESS, GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.runFlag value is invalid"); + return GE_GRAPH_OPTIONS_INVALID); // parse FmkOp options_.local_fmk_op_flag = false; ret = ParseOption(options, LOCAL_FMKOP_FLAG, options_.local_fmk_op_flag); - if (ret != SUCCESS) { - GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.localFmkopFlag value is invalid, must be 0 or 1."); - return GE_GRAPH_OPTIONS_INVALID; - } + GE_IF_BOOL_EXEC(ret != SUCCESS, + GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.localFmkopFlag value is invalid, must be 0 or 1."); + return GE_GRAPH_OPTIONS_INVALID); options_.enable_print_op_pass = true; ret = ParseOption(options, ENABLE_PRINT_OP_PASS, options_.enable_print_op_pass); @@ -1472,20 +1505,23 @@ Status GraphManager::ParseOptions(const std::map &opti // parse hcom parallel options_.hcom_parallel = false; ret = ParseOption(options, HCOM_PARALLEL, options_.hcom_parallel); - if (ret != SUCCESS) { - GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.hcomParallel value is invalid, must be 0 or 1."); - return GE_GRAPH_OPTIONS_INVALID; - } - + GE_IF_BOOL_EXEC(ret != SUCCESS, + GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.hcomParallel value is invalid, must be 0 or 1."); + return GE_GRAPH_OPTIONS_INVALID); // net output node dataType ParseOption(options, OUTPUT_DATATYPE, options_.output_datatype); // Set save_original_model flag (ge.save_original_model) ParseOption(options, SAVE_ORIGINAL_MODEL, options_.save_original_model); - GELOGI("Set save original model flag %s", options_.save_original_model.c_str()); // Original model file name ParseOption(options, ORIGINAL_MODEL_FILE, options_.original_model_file); + ParseOption(options, INPUT_SHAPE, options_.input_shape); + ParseOption(options, kDynamicDims, options_.dynamic_dims); + ParseOption(options, DYNAMIC_NODE_TYPE, options_.dynamic_node_type); + GELOGD("Dynamic dims params: input shape is %s, dynamic dims is %s, dynamic node type is %d.", + options_.input_shape.c_str(), options_.dynamic_dims.c_str(), options_.dynamic_node_type); + // Set Build model and step ParseOption(options, BUILD_MODE, options_.build_mode); ParseOption(options, BUILD_STEP, options_.build_step); @@ -1813,12 +1849,29 @@ Status GraphManager::RegisterCallBackFunc( return SUCCESS; } +Status GraphManager::RegisterCallBackFunc( + const std::string &key, const std::function &)> &callback) { + std::lock_guard lock(member_mutex_); + GELOGI("[GraphManager] RegisterCallBackFunc, key=%s.", key.c_str()); + callback_map_[key] = callback; + return SUCCESS; +} + Status GraphManager::PushSummaryData2ME(const GraphId &graph_id, const std::map &summary_data) { std::lock_guard lock(member_mutex_); GELOGI("[GraphManager] PushSummaryData2ME, dataSize=%zu.", summary_data.size()); auto itr = me_callback_map_.find(kSummary); if (itr == me_callback_map_.end()) { + auto iter = callback_map_.find(kSummary); + if (iter != callback_map_.end()) { + std::map tmp_summary_data; + for (auto &data : summary_data) { + AscendString tmp(data.first.c_str()); + tmp_summary_data[tmp] = data.second; + } + return iter->second(graph_id, tmp_summary_data); + } GELOGE(FAILED, "[GraphManager] PushSummaryData2ME failed, not found summary callback."); return FAILED; } @@ -1830,6 +1883,15 @@ Status GraphManager::PushSaveData2ME(const GraphId &graph_id, const std::map tmp_save_data; + for (auto &data : save_data) { + AscendString tmp(data.first.c_str()); + tmp_save_data[tmp] = data.second; + } + return iter->second(graph_id, tmp_save_data); + } GELOGE(FAILED, "[GraphManager] PushSaveData2ME failed, not found checkpoint callback."); return FAILED; } @@ -2185,7 +2247,7 @@ Status GraphManager::OptimizeStage1(ge::ComputeGraphPtr &compute_graph) { } Status GraphManager::OptimizeStage2(ge::ComputeGraphPtr &compute_graph) { - GELOGI("Start optimize after merge sub graph."); + GELOGD("Start optimize after merge sub graph."); PassManager after_merge_passes; GE_CHK_STATUS_RET(after_merge_passes.AddPass("OptimizeStage2::AfterMergePasses::LinkGenMaskNodesPass", @@ -2436,7 +2498,7 @@ Status GraphManager::ProcessSubGraphWithMultiThreads(GraphManager *graph_manager ComputeGraphPtr compute_graph_tmp = sub_graph_info_ptr->GetSubGraph(); const std::string &engine_name = sub_graph_info_ptr->GetEngineName(); - GELOGI("ProcessSubGraphWithMultiThreads start, graph name is %s, engine_name is %s, thread id is %lu", + GELOGD("ProcessSubGraphWithMultiThreads start, graph name is %s, engine_name is %s, thread id is %lu", compute_graph_tmp != nullptr ? compute_graph_tmp->GetName().c_str() : "", engine_name.c_str(), pthread_self()); GE_DUMP(compute_graph_tmp, "OptimizeSubGraphBefore"); @@ -2448,11 +2510,11 @@ Status GraphManager::ProcessSubGraphWithMultiThreads(GraphManager *graph_manager GELOGE(ret, "SubGraph optimize Failed %s", engine_name.c_str()); return ret; } else { - GELOGI("SubGraph optimize success %s", engine_name.c_str()); + GELOGD("SubGraph optimize success %s", engine_name.c_str()); } GE_DUMP(compute_graph_tmp, "OptimizeSubGraphAfter"); sub_graph_info_ptr->SetSubGraph(compute_graph_tmp); - GELOGI("ProcessSubGraphWithMultiThreads end, graph name is %s, engine_name is %s, thread id is %lu", + GELOGD("ProcessSubGraphWithMultiThreads end, graph name is %s, engine_name is %s, thread id is %lu", compute_graph_tmp != nullptr ? compute_graph_tmp->GetName().c_str() : "", engine_name.c_str(), pthread_self()); } else { @@ -2650,6 +2712,118 @@ void GraphManager::PreRunThread(GraphManager *graph_manager) { } } +Status GraphManager::DistinguishGetNextAndData(ComputeGraphPtr &graph, vector &data_nodes, + vector &getnext_nosink_nodes, + vector &getnext_sink_nodes) { + GELOGD("Start distinguish getnext and data node."); + for (NodePtr &input_node : graph->GetDirectNode()) { + GE_CHECK_NOTNULL(input_node); + OpDescPtr op_desc = input_node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + if (op_desc->GetType() == DATA && op_desc->GetName() != kShapeDataName) { + if (op_desc->GetName().find(kSubstrOfGetNextNosinkName) == string::npos) { + data_nodes.emplace_back(input_node); + } else { + getnext_nosink_nodes.emplace_back(input_node); + } + } + std::string op_type; + auto ret = GetOriginalType(input_node, op_type); + if (ret != SUCCESS) { + GELOGE(FAILED, "Failed to get node %s original type.", input_node->GetName().c_str()); + return FAILED; + } + if (op_type == kGetNextName) { + GELOGD("Name of getnext sink is %s.", op_desc->GetName().c_str()); + getnext_sink_nodes.emplace_back(input_node); + } + } + GELOGI("data count is %zu, getnext nosink count is %zu, getnext sink count is %zu.", data_nodes.size(), + getnext_nosink_nodes.size(), getnext_sink_nodes.size()); + return SUCCESS; +} + +void GraphManager::ParseInputsDimsForData(const std::vector &input_tensor) { + GELOGD("Start parse input dims from data."); + for (size_t i = 0; i < input_tensor.size(); ++i) { + std::vector dynamic_dim; + for (size_t j = 0; j < input_tensor[i].dims.size(); ++j) { + dynamic_dim.emplace_back(input_tensor[i].dims[j]); + } + GELOGD("Input tensor dims is %s.", formats::JoinToString(dynamic_dim).c_str()); + GetLocalOmgContext().user_real_input_dims.emplace_back(input_tensor[i].dims); + } +} + +Status GraphManager::ParseInputsDimsForGetNexNosinkAndData(const vector &dynamic_nodes, + const std::vector &input_tensor) { + GELOGD("Start parse inputs dims when coexist data and getnext sink."); + for (size_t i = 0; i < dynamic_nodes.size(); ++i) { + auto op_desc = dynamic_nodes.at(i)->GetOpDesc(); + if (op_desc == nullptr) { + continue; + } + GeAttrValue::INT index = 0; + if (!(AttrUtils::GetInt(op_desc, ATTR_NAME_INDEX, index))) { + GELOGE(PARAM_INVALID, "Get index from attr failed"); + return PARAM_INVALID; + } + if (static_cast(index) > input_tensor.size()) { + GELOGE(PARAM_INVALID, "The count of input tensor should be equal to the count of data."); + return PARAM_INVALID; + } + + GetLocalOmgContext().user_real_input_dims.emplace_back(input_tensor.at(index).dims); + GELOGI("Shape dims of %d data is %s.", index, formats::JoinToString(input_tensor.at(index).dims).c_str()); + } + return SUCCESS; +} + +Status GraphManager::ParseInputsDims(const std::vector &input_tensor) { + GELOGI("Start parse input dims of %zu input tensor.", input_tensor.size()); + GetLocalOmgContext().user_real_input_dims.clear(); + if (!GetLocalOmgContext().dynamic_node_type.empty()) { + vector data_nodes; + vector getnext_nosink_nodes; + vector getnext_sink_nodes; + if (DistinguishGetNextAndData(compute_graph_, data_nodes, getnext_nosink_nodes, getnext_sink_nodes) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to distinguish getnext and data node."); + return PARAM_INVALID; + } + if (GetLocalOmgContext().dynamic_node_type == DATA) { + if (getnext_nosink_nodes.empty()) { + // just data or data+getnext_sink + ParseInputsDimsForData(input_tensor); + } else { + // data+getnext_nosink, but only need to get shape_dims of data + if (ParseInputsDimsForGetNexNosinkAndData(data_nodes, input_tensor) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to parse dims from data, when data coexist with getnext nosink."); + return PARAM_INVALID; + } + } + } else { + if (getnext_nosink_nodes.empty()) { + // just getnext_sink or getnext_sink+data, need to get shape_dims from aicpu op + GELOGI("Need to get dims from aicpu op: GETDYNAMICDIMS."); + return SUCCESS; + } else { + if (data_nodes.empty()) { + // just getnext_nosink + ParseInputsDimsForData(input_tensor); + } else { + // getnext_nosink + data, but only need to get shape_dims of getnext_nosink + if (ParseInputsDimsForGetNexNosinkAndData(getnext_nosink_nodes, input_tensor) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to parse dims from getnext nosink, when data coexist with getnext nosink"); + return PARAM_INVALID; + } + } + } + } + } + GELOGI("Parse %zu inputs dims success.", GetLocalOmgContext().user_real_input_dims.size()); + return SUCCESS; +} + void GraphManager::RunThread(GraphManager *graph_manager) { if (prctl(PR_SET_NAME, ("GE_Run")) != 0) { GELOGW("Set thread name failed."); @@ -2671,8 +2845,15 @@ void GraphManager::RunThread(GraphManager *graph_manager) { if (args.graph_node->graph_run_async_listener_ != nullptr) { args.graph_node->graph_run_async_listener_->SetCallback(args.callback); } - Status ret; + // parse inputs.dims to vector> dynamic_dims + ret = graph_manager->ParseInputsDims(args.input_tensor); + if (ret != SUCCESS) { + ReturnError(graph_manager, args.callback, ret, "ParseInputsDims failed, thread exit."); + args.graph_node->Unlock(); + return; + } + if (!args.graph_node->GetLoadFlag()) { ret = graph_manager->LoadGraphAsync(args.ge_root_model, args.graph_node); if (ret != SUCCESS || args.ge_root_model == nullptr) { @@ -2697,12 +2878,12 @@ void GraphManager::RunThread(GraphManager *graph_manager) { ret = graph_manager->graph_executor_.ExecuteGraphAsync(args.graph_id, args.graph_node->GetGeRootModel(), args.input_tensor); args.graph_node->SetRunFlag(false); - args.graph_node->Unlock(); if (ret != SUCCESS) { - GELOGE(ret, "[GraphManager] Run graph async failed, graph_id=%u.", args.graph_id); - StopQueue(graph_manager); + ReturnError(graph_manager, args.callback, ret, "ExecuteGraphAsync failed, thread exit."); + args.graph_node->Unlock(); return; } + args.graph_node->Unlock(); GELOGI("[GraphManager] Run graph async success, graph_id=%u.", args.graph_id); } } diff --git a/src/ge/graph/manager/graph_manager.h b/src/ge/graph/manager/graph_manager.h index 3f2cfa9e..e1a4c579 100644 --- a/src/ge/graph/manager/graph_manager.h +++ b/src/ge/graph/manager/graph_manager.h @@ -72,6 +72,7 @@ class GraphManager { /// Status AddGraph(const GraphId &graph_id, const Graph &graph, const std::map &options, const OmgContext &omg_context); + Status InitDynamicParams(ComputeGraphPtr &compute_graph); /// /// @ingroup ge_graph @@ -160,6 +161,10 @@ class GraphManager { Status RegisterCallBackFunc( const std::string &key, const std::function &)> &callback); + Status RegisterCallBackFunc( + const std::string &key, + const std::function &)> &callback); + const bool GetTrainFlag() const { return options_.train_graph_flag; } bool IsGraphNeedRebuild(uint32_t graph_id); @@ -213,6 +218,12 @@ class GraphManager { static Status ProcessSubGraphWithMultiThreads(GraphManager *graph_manager, GraphId root_graph_id, const SubGraphInfoPtr &sub_graph_info_ptr, uint64_t session_id, const GEThreadLocalContext &ge_context); + Status ParseInputsDims(const std::vector &input_tensor); + Status DistinguishGetNextAndData(ComputeGraphPtr &graph, vector &data_nodes, + vector &getnext_nosink_nodes, vector &getnext_sink_nodes); + void ParseInputsDimsForData(const std::vector &input_tensor); + Status ParseInputsDimsForGetNexNosinkAndData(const vector &dynamic_nodes, + const std::vector &input_tensor); Status PreRun(const GraphNodePtr &graph_node, const std::vector &inputs, GeRootModelPtr &ge_root_model, uint64_t session_id = INVALID_SESSION_ID); @@ -362,7 +373,7 @@ class GraphManager { BlockingQueue run_args_q_{}; std::thread prerun_thread_; std::thread run_thread_; - + ComputeGraphPtr compute_graph_; std::map graph_map_; std::map cache_helper_map_; @@ -375,6 +386,8 @@ class GraphManager { // summary and checkpoint callback function list for ME, key is summary or checkpoint std::map &)>> me_callback_map_; + std::map &)>> callback_map_; + bool init_flag_; GraphManagerOptions options_; diff --git a/src/ge/graph/manager/graph_manager_utils.h b/src/ge/graph/manager/graph_manager_utils.h index be39df21..3589c3a4 100644 --- a/src/ge/graph/manager/graph_manager_utils.h +++ b/src/ge/graph/manager/graph_manager_utils.h @@ -249,6 +249,9 @@ struct GraphManagerOptions { std::string save_original_model; std::string build_mode; std::string build_step; + std::string input_shape; + std::string dynamic_dims; + int32_t dynamic_node_type = -1; GraphManagerOptions() : stream_num(1), perf_level(domi::GEN_TASK_WITHOUT_FUSION), diff --git a/src/ge/graph/manager/graph_var_manager.cc b/src/ge/graph/manager/graph_var_manager.cc index 8633e361..62ed02f3 100644 --- a/src/ge/graph/manager/graph_var_manager.cc +++ b/src/ge/graph/manager/graph_var_manager.cc @@ -92,13 +92,13 @@ ge::Status VarResource::SaveVarAddr(const std::string &var_name, const ge::GeTen GELOGD("VarResource::SaveVarAddr, var_key = %s", var_key.c_str()); if (var_addr_mgr_map_.count(var_key) == 0) { uint64_t logic_address = VarManager::Instance(session_id_)->GetVarMemLogicBase() + - reinterpret_cast(reinterpret_cast(address)); + static_cast(reinterpret_cast(address)); GELOGI("SaveVarAddr node_name %s, tensor_desc format %s, type %s.", var_name.c_str(), TypeUtils::FormatToSerialString(tensor_desc.GetFormat()).c_str(), TypeUtils::DataTypeToSerialString(tensor_desc.GetDataType()).c_str()); VarAddrMgr var_addr_mgr; - var_addr_mgr.address = reinterpret_cast(reinterpret_cast(logic_address)); - var_addr_mgr.offset = reinterpret_cast(reinterpret_cast(address)); + var_addr_mgr.address = reinterpret_cast(static_cast(logic_address)); + var_addr_mgr.offset = static_cast(reinterpret_cast(address)); var_addr_mgr.tensor_desc = tensor_desc; var_addr_mgr.memory_type = memory_type; var_addr_mgr_map_[var_key] = var_addr_mgr; @@ -509,8 +509,8 @@ ge::Status VarManager::AssignVarMem(const std::string &var_name, const ge::GeTen return ge::INTERNAL_ERROR; } - result = var_resource_->SaveVarAddr( - var_name, tensor_desc, reinterpret_cast(reinterpret_cast(mem_offset)), memory_type); + result = var_resource_->SaveVarAddr(var_name, tensor_desc, + reinterpret_cast(static_cast(mem_offset)), memory_type); if (result != SUCCESS) { GELOGE(ge::INTERNAL_ERROR, "AssignVarMem by offset failed."); return ge::INTERNAL_ERROR; @@ -526,8 +526,8 @@ ge::Status VarManager::AssignVarMem(const std::string &var_name, const ge::GeTen ge::GeTensorDesc cur_tensor_desc; result = var_resource_->GetCurVarDesc(var_name, cur_tensor_desc); if (result != SUCCESS) { - var_resource_->SetVarAddr(var_name, tensor_desc, - reinterpret_cast(reinterpret_cast(mem_offset)), memory_type); + var_resource_->SetVarAddr(var_name, tensor_desc, reinterpret_cast(static_cast(mem_offset)), + memory_type); return SUCCESS; } @@ -541,8 +541,8 @@ ge::Status VarManager::AssignVarMem(const std::string &var_name, const ge::GeTen ge::TypeUtils::DataTypeToSerialString(cur_tensor_desc.GetDataType()).c_str(), ge::TypeUtils::FormatToSerialString(cur_tensor_desc.GetFormat()).c_str(), cur_tensor_desc.GetShape().GetDims().size()); - var_resource_->SetVarAddr(var_name, tensor_desc, - reinterpret_cast(reinterpret_cast(mem_offset)), memory_type); + var_resource_->SetVarAddr(var_name, tensor_desc, reinterpret_cast(static_cast(mem_offset)), + memory_type); } return SUCCESS; @@ -642,7 +642,7 @@ ge::Status VarManager::SyncBroadCastData2Var(uint32_t graph_id, const std::strin bool VarManager::IsVarAddr(const int64_t &offset) { std::lock_guard lock(mutex_); if (var_resource_ == nullptr) { - GELOGW("VarManager has not been init."); + GELOGD("VarManager has not been init."); return false; } return var_resource_->IsVarAddr(offset); diff --git a/src/ge/graph/manager/trans_var_data_utils.cc b/src/ge/graph/manager/trans_var_data_utils.cc index 60a0d0db..f51cbf04 100644 --- a/src/ge/graph/manager/trans_var_data_utils.cc +++ b/src/ge/graph/manager/trans_var_data_utils.cc @@ -370,7 +370,7 @@ Status TransVarDataUtils::SyncVarData2BroadCast(const string &var_name, const ge GE_MAKE_GUARD_RTMEM(src_host_addr); GE_CHK_STATUS_RET(SyncTensorToHost(var_name, src_tensor_desc, &src_host_addr, src_addr_size, session_id)); - GELOGI("src_addr_size: %u, dst_addr_size: %u", src_addr_size, dst_addr_size); + GELOGI("src_addr_size: %ld, dst_addr_size: %ld", src_addr_size, dst_addr_size); GE_CHK_BOOL_RET_STATUS(src_addr_size == dst_addr_size, FAILED, "var data size is not equal broadcast "); GE_CHK_RT_RET(rtMemcpy(dst_addr, dst_addr_size, src_host_addr, src_addr_size, RT_MEMCPY_HOST_TO_DEVICE)); @@ -398,8 +398,7 @@ Status TransVarDataUtils::SyncTensorToHost(const string &var_name, const ge::GeT uint8_t *src_addr = nullptr; GE_CHK_STATUS_RET(VarManager::Instance(session_id)->GetVarAddr(var_name, src_tensor_desc, &src_addr)); uint8_t *mem_addr = - src_addr - - static_cast(reinterpret_cast(VarManager::Instance(session_id)->GetVarMemLogicBase())) + + src_addr - static_cast(static_cast(VarManager::Instance(session_id)->GetVarMemLogicBase())) + static_cast( reinterpret_cast(VarManager::Instance(session_id)->GetVarMemoryBase(RT_MEMORY_HBM))); GE_CHK_RT_RET(rtMallocHost(reinterpret_cast(host_addr), src_tensor_size)); @@ -415,8 +414,7 @@ Status TransVarDataUtils::SyncTensorToDevice(const string &var_name, const uint8 uint8_t *dst_addr = nullptr; GE_CHK_STATUS_RET(VarManager::Instance(session_id)->GetVarAddr(var_name, dst_tensor_desc, &dst_addr)); uint8_t *mem_addr = - dst_addr - - static_cast(reinterpret_cast(VarManager::Instance(session_id)->GetVarMemLogicBase())) + + dst_addr - static_cast(static_cast(VarManager::Instance(session_id)->GetVarMemLogicBase())) + static_cast( reinterpret_cast(VarManager::Instance(session_id)->GetVarMemoryBase(RT_MEMORY_HBM))); GE_CHK_RT_RET(rtMemcpy(mem_addr, addr_size, host_addr, addr_size, RT_MEMCPY_HOST_TO_DEVICE)); @@ -494,7 +492,7 @@ Status TransVarDataUtils::TransAllVarData(const vector &variable_nodes, } Status TransVarDataUtils::CopyVarData(const ComputeGraphPtr &compute_graph, uint64_t session_id, uint32_t device_id) { - GELOGI("CopyVarData start: session_id:%lu.", session_id); + GELOGD("CopyVarData start: session_id:%lu.", session_id); if (compute_graph == nullptr) { GELOGE(FAILED, "compute_graph is nullptr"); return FAILED; diff --git a/src/ge/graph/manager/util/debug.cc b/src/ge/graph/manager/util/debug.cc index b2ef1c92..ca4855b0 100644 --- a/src/ge/graph/manager/util/debug.cc +++ b/src/ge/graph/manager/util/debug.cc @@ -32,7 +32,8 @@ Debug::~Debug() = default; void Debug::DumpProto(const Message &proto, const char *file) { std::string file_path = RealPath(file); - int fd = open(file_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int fd = + mmOpen2(file_path.c_str(), M_WRONLY | M_CREAT | O_TRUNC, M_IRUSR | M_IWUSR | M_UMASK_GRPREAD | M_UMASK_OTHREAD); if (fd == -1) { GELOGW("Write %s failed", file_path.c_str()); return; @@ -40,7 +41,7 @@ void Debug::DumpProto(const Message &proto, const char *file) { auto output = ge::MakeShared(fd); if (output == nullptr) { GELOGW("create output failed."); - if (close(fd) != 0) { + if (mmClose(fd) != 0) { GELOGW("close fd failed."); } return; @@ -49,7 +50,7 @@ void Debug::DumpProto(const Message &proto, const char *file) { if (!ret) { GELOGW("dump proto failed."); } - if (close(fd) != 0) { + if (mmClose(fd) != 0) { GELOGW("close fd failed."); } } diff --git a/src/ge/graph/manager/util/debug.h b/src/ge/graph/manager/util/debug.h index 9cedb680..e1b13caf 100644 --- a/src/ge/graph/manager/util/debug.h +++ b/src/ge/graph/manager/util/debug.h @@ -17,7 +17,6 @@ #ifndef GE_GRAPH_MANAGER_UTIL_DEBUG_H_ #define GE_GRAPH_MANAGER_UTIL_DEBUG_H_ -#include #include #include #include @@ -25,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ge/graph/optimize/graph_optimize.cc b/src/ge/graph/optimize/graph_optimize.cc index 807b43f5..43e231c0 100644 --- a/src/ge/graph/optimize/graph_optimize.cc +++ b/src/ge/graph/optimize/graph_optimize.cc @@ -55,8 +55,7 @@ void AddNodeInputProperty(ComputeGraphPtr &compute_graph) { for (auto &in_data_anchor : node->GetAllInDataAnchors()) { auto peer_out_anchor = in_data_anchor->GetPeerOutAnchor(); - GE_IF_BOOL_EXEC( - peer_out_anchor == nullptr, GELOGW("peer_out_anchor is nullptr! node: %s", node->GetName().c_str()); continue); + GE_IF_BOOL_EXEC(peer_out_anchor == nullptr, continue); ge::NodePtr src_node = peer_out_anchor->GetOwnerNode(); src_index_list = node_op_desc->GetSrcIndex(); @@ -239,11 +238,11 @@ Status GraphOptimize::OptimizeGraphBeforeBuildForRts(ComputeGraphPtr &compute_gr } auto graph_optimizer = instance_ptr->OpsKernelManagerObj().GetAllGraphOptimizerObjsByPriority(); - GELOGI("optimize by opskernel in graph optimize before build phase. num of graph_optimizer is %zu.", + GELOGD("optimize by opskernel in graph optimize before build phase. num of graph_optimizer is %zu.", graph_optimizer.size()); Status ret = SUCCESS; string exclude_core_Type = (core_type_ == kVectorCore) ? kAicoreEngine : kVectorEngine; - GELOGI("[OptimizeGraphBeforeBuildForRts]: engine type will exclude: %s, core_type_: %s", exclude_core_Type.c_str(), + GELOGD("[OptimizeGraphBeforeBuildForRts]: engine type will exclude: %s, core_type_: %s", exclude_core_Type.c_str(), core_type_.c_str()); if (graph_optimizer.size() != 0) { for (auto iter = graph_optimizer.begin(); iter != graph_optimizer.end(); ++iter) { diff --git a/src/ge/graph/optimize/mem_rw_conflict_optimize.cc b/src/ge/graph/optimize/mem_rw_conflict_optimize.cc index 02f57b24..01039de0 100644 --- a/src/ge/graph/optimize/mem_rw_conflict_optimize.cc +++ b/src/ge/graph/optimize/mem_rw_conflict_optimize.cc @@ -132,6 +132,22 @@ InputRWType GetInputRwTypeInConflict(const std::set &rw_type_set) { } } +bool IsSubgraphInputNode(const NodePtr &node) { + if ((node == nullptr) || (node->GetOpDesc() == nullptr) || (node->GetType() != DATA) || + (node->GetOwnerComputeGraph()->GetParentNode() == nullptr)) { + return false; + } + return true; +} + +bool IsSubgraphOutputNode(const NodePtr &node) { + if ((node == nullptr) || (node->GetOpDesc() == nullptr) || (node->GetType() != NETOUTPUT) || + (node->GetOwnerComputeGraph()->GetParentNode() == nullptr)) { + return false; + } + return true; +} + NodePtr CreateIdentityAfterSrcNode(const Node &src_node, int out_anchor_idx) { if (src_node.GetOpDesc() == nullptr) { return nullptr; @@ -378,7 +394,7 @@ bool CheckIdentityIsNearSubgraph(const Node &node) { continue; } // near entrance of subgraph - if (in_node->GetType() == DATA && NodeUtils::IsSubgraphInput(in_node)) { + if (IsSubgraphInputNode(in_node)) { return true; } // near subgraph @@ -393,7 +409,7 @@ bool CheckIdentityIsNearSubgraph(const Node &node) { continue; } // near output of subgraph - if (out_node->GetType() == NETOUTPUT && NodeUtils::IsSubgraphOutput(out_node)) { + if (IsSubgraphOutputNode(out_node)) { return true; } // near subgraph @@ -608,6 +624,30 @@ Status InsertIdentityAsNeeded(const NodePtr &node) { } return SUCCESS; } +Status HandleAllreduceDuplicateInput(ComputeGraphPtr &compute_graph) { + for (const auto &node : compute_graph->GetDirectNode()) { + if (node->GetType() == HCOMALLREDUCE) { + std::set pre_out_anchor_set; + for (const auto &in_data_anchor : node->GetAllInDataAnchors()) { + auto pre_out_anchor = in_data_anchor->GetPeerOutAnchor(); + GE_CHECK_NOTNULL(pre_out_anchor); + if (pre_out_anchor_set.find(pre_out_anchor) == pre_out_anchor_set.end()) { + pre_out_anchor_set.emplace(pre_out_anchor); + continue; + } + // need insert identity + auto pre_node = pre_out_anchor->GetOwnerNode(); + auto identity_node = CreateIdentityAfterSrcNode(*pre_node, pre_out_anchor->GetIdx()); + GE_CHECK_NOTNULL(identity_node); + auto ret = GraphUtils::InsertNodeBetweenDataAnchors(pre_out_anchor, in_data_anchor, identity_node); + GE_CHK_STATUS_RET(ret, "Fail to insert identity."); + GELOGI("InsertNode %s between %s and %s successfully.", identity_node->GetName().c_str(), + pre_node->GetName().c_str(), node->GetName().c_str()); + } + } + } + return SUCCESS; +} } // namespace namespace ge { @@ -666,13 +706,14 @@ Status GraphOptimize::CheckRWConflict(ComputeGraphPtr &compute_graph, bool &has_ return SUCCESS; } Status GraphOptimize::HandleMemoryRWConflict(ComputeGraphPtr &compute_graph) { + GE_DUMP(compute_graph, "BeforeHandleMemConflict"); node_rwtype_map_.clear(); auto sub_graph_vec = compute_graph->GetAllSubgraphs(); if (sub_graph_vec.empty()) { - GELOGD("No sub graph here. Ignore memory conflict handle."); - return SUCCESS; + // only root graph, to handle allreduce servral input from one output anchor + return HandleAllreduceDuplicateInput(compute_graph); } - GE_DUMP(compute_graph, "BeforeHandleMemConflict"); + // 1.loop all subgraph, mark rw type from inside to outside Status ret = MarkRWTypeForAllSubgraph(sub_graph_vec); if (ret != SUCCESS) { diff --git a/src/ge/graph/optimize/optimizer/allreduce_fusion_pass.cc b/src/ge/graph/optimize/optimizer/allreduce_fusion_pass.cc deleted file mode 100644 index be025730..00000000 --- a/src/ge/graph/optimize/optimizer/allreduce_fusion_pass.cc +++ /dev/null @@ -1,397 +0,0 @@ -/** - * Copyright 2019-2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "graph/optimize/optimizer/allreduce_fusion_pass.h" -#include -#include "common/debug/log.h" -#include "framework/common/debug/ge_log.h" -#include "common/types.h" -#include "common/util.h" -#include "graph/anchor.h" -#include "graph/node.h" -#include "graph/op_desc.h" -#include "graph/utils/attr_utils.h" -#include "graph/utils/graph_utils.h" -#include "graph/utils/tensor_utils.h" -#include "graph/debug/ge_attr_define.h" -#include "hccl/base.h" -#include "hccl/hcom.h" - -namespace ge { -Status AllReducePass::Run(ge::ComputeGraphPtr graph) { - GELOGI("FusionAllReducePass: start"); - std::vector fusionOps; - std::vector inputGradientSize; - std::vector inputGradientTime; - - static const float inputGradientSizeTemp = 0.0; - static const float inputGradientTimeTemp = 0.0; - - // Get all nodes - for (auto nodePtr : graph->GetDirectNode()) { - GE_IF_BOOL_EXEC(nullptr == nodePtr, GELOGW("FusionAllReducePass: null node exists"); continue;); - - ge::OpDescPtr opDescPtr = nodePtr->GetOpDesc(); - GE_IF_BOOL_EXEC(nullptr == opDescPtr, - GELOGW("FusionAllReducePass: desc of node %s is null", nodePtr->GetName().c_str()); - continue;) - GE_IF_BOOL_EXEC(HCOMALLREDUCE == opDescPtr->GetType(), - // the op is allreduce and fusion > 0, then run fusion - std::int64_t hcom_fusion = 1; - GE_IF_BOOL_EXEC(!ge::AttrUtils::GetInt(opDescPtr, HCOM_ATTR_FUSION, hcom_fusion), - GELOGW("FusionAllReducePass: not get hcom_fusion from opDescPtr " - "by HCOM_ATTR_FUSION")); - GELOGI("after GetInt, hcom_fusion is :%ld", hcom_fusion); GE_IF_BOOL_EXEC( - hcom_fusion > 0, fusionOps.push_back(nodePtr); inputGradientSize.push_back(inputGradientSizeTemp); - inputGradientTime.push_back(inputGradientTimeTemp);)) - } - // The number of allredecue operator must be more than 1 - GE_IF_BOOL_EXEC(1 >= fusionOps.size(), GELOGW("FusionAllReducePass NOT_CHANGED: the graph has " - "%lu allreduce operator", - fusionOps.size()); - return NOT_CHANGED;); - - string group = "group"; - u32 gradientNum = fusionOps.size(); - string model_name_str = graph->GetName(); - const char *model_name = model_name_str.c_str(); - model_feature modelFeature{model_name, gradientNum, inputGradientSize.data(), inputGradientTime.data()}; - - u32 segmentNum = 0; - u32 segmentIndex[HCCL_MAX_SEGMENT_NUM] = {}; - - // Call HCCL function: hcom_gradient_segment - GELOGI("FusionAllReducePass: invoking hcom_get_split_strategy"); - GE_IF_BOOL_EXEC(HCCL_SUCCESS != hcom_get_split_strategy(group.c_str(), &modelFeature, HCCL_MAX_SEGMENT_NUM, - &segmentNum, segmentIndex), - GELOGE(FAILED, "FusionAllReducePass FAILED: the graph has %lu allreduce operator", fusionOps.size()); - return FAILED;) - GELOGI("FusionAllReducePass: invoke hcom_get_split_strategy successfully"); - - // check whether segmentNum is legal or not - GE_IF_BOOL_EXEC((HCCL_MAX_SEGMENT_NUM < segmentNum || 1 > segmentNum || segmentNum > gradientNum), - GELOGE(FAILED, - "FusionAllReducePass FAILED: illegal segmentNum=%u, " - "HCCL_MAX_SEGMENT_NUM=%u, gradientNum=%u", - segmentNum, HCCL_MAX_SEGMENT_NUM, gradientNum); - return FAILED;); - - // check whether segmentIndex is legal or not - GE_IF_BOOL_EXEC((segmentIndex[segmentNum - 1] != gradientNum - 1), - GELOGE(FAILED, - "FusionAllReducePass FAILED: illegal segmentIndex[0]=%u, " - "segmentIndex[segmentNum-1]=%u, gradientNum=%u", - segmentIndex[0], segmentIndex[(segmentNum)-1], gradientNum); - return FAILED;); - - for (uint32_t i = 0; i < segmentNum - 1; i++) { - GE_IF_BOOL_EXEC(segmentIndex[i] >= segmentIndex[i + 1], GELOGE(FAILED, - "FusionAllReducePass FAILED: illegal " - "segmentIndex[%u]=%u, segmentIndex[%u]=%u", - i, segmentIndex[i], i + 1, segmentIndex[i + 1]); - return FAILED;); - } - - // check whether fusion is needed or not - GE_IF_BOOL_EXEC( - segmentNum == gradientNum, - GELOGE(NOT_CHANGED, "FusionAllReducePass NOT_CHANGED: segmentNum=%u, gradientNum=%u", segmentNum, gradientNum); - return NOT_CHANGED;) - - std::unordered_set anchorPtrSet; - std::vector fusionOpPeerOutDataAnchor; - std::vector fusionOpPeerOutDataToInControl; - std::vector fusionOpPeerOutControlAnchor; - std::vector> fusionOpPeerInDataAnchor; - std::vector> fusionOpPeerInControlFromOutData; - std::vector fusionOpPeerInControlAnchor; - ge::OutControlAnchorPtr previousNewAllreduceOutControlAnchor = nullptr; - - // Traversing the segmentNum - uint32_t start = 0; - uint32_t end = 0; - for (uint32_t segmentIdx = 0; segmentIdx < segmentNum; segmentIdx++) { - end = segmentIndex[segmentIdx]; - GE_IF_BOOL_EXEC(end - start < 1, - GELOGI("FusionAllReducePass: segmentIndex[%u]=%u", segmentIdx, segmentIndex[segmentIdx]); - start = end + 1; continue;); - - ge::OpDescPtr originDescPtr = fusionOps[start]->GetOpDesc(); - GE_CHECK_NOTNULL(originDescPtr); - ge::OpDescPtr newAllreduceDesc = AttrUtils::CloneOpDesc(originDescPtr); - GE_CHECK_NOTNULL(newAllreduceDesc); - - // Cleat buffer - anchorPtrSet.clear(); - fusionOpPeerOutDataAnchor.clear(); - fusionOpPeerOutDataToInControl.clear(); - fusionOpPeerOutControlAnchor.clear(); - fusionOpPeerInDataAnchor.clear(); - fusionOpPeerInControlFromOutData.clear(); - fusionOpPeerInControlAnchor.clear(); - - // Traversing the Allreduce operators of each group - int outDataAnchorIndex = 0; - GE_CHK_STATUS_RET(GetPeerOutDataToInData(anchorPtrSet, fusionOpPeerOutDataAnchor, fusionOps[start]), - "Get peer outDataAnchor to inDataAnchor failed"); - - GE_CHK_STATUS_RET(GetPeerInAnchorToOutData(anchorPtrSet, fusionOpPeerInDataAnchor, fusionOpPeerInControlFromOutData, - fusionOps[start]), - "Get peer inDataAnchor and inControlAnchor to outDataAnchor failed"); - - GE_CHK_STATUS_RET(GetPeerOutDataToInControl(anchorPtrSet, fusionOpPeerOutDataToInControl, fusionOps[start]), - "Get peer outDataAnchor to inControlAnchor failed"); - GE_CHK_STATUS_RET(GetPeerOutControlToInControl(anchorPtrSet, fusionOpPeerOutControlAnchor, fusionOps[start]), - "Get peer outControlAnchor to inControlAnchor failed"); - GE_CHK_STATUS_RET(GetPeerInControlFromOutControl(anchorPtrSet, fusionOpPeerInControlAnchor, fusionOps[start]), - "Get peer outControlAnchor from inControlAnchor failed"); - GE_CHK_STATUS_RET(graph->RemoveNode(fusionOps[start]), "FusionAllReducePass FAILED: remove node %s\n.", - fusionOps[start]->GetName().c_str()); - - for (uint32_t idx = start + 1; idx <= end; idx++) { - GE_CHK_STATUS_RET( - GetPeerOutDataToInData(anchorPtrSet, fusionOpPeerOutDataAnchor, fusionOps[idx], newAllreduceDesc), - "Get peer outDataAnchor to inDataAnchor failed"); - GE_CHK_STATUS_RET(GetPeerOutDataToInControl(anchorPtrSet, fusionOpPeerOutDataToInControl, fusionOps[idx]), - "Get peer outDataAnchor to inControlAnchor failed"); - GE_CHK_STATUS_RET(GetPeerOutControlToInControl(anchorPtrSet, fusionOpPeerOutControlAnchor, fusionOps[idx]), - "Get peer outControlAnchor to inControlAnchor failed"); - GE_CHK_STATUS_RET( - GetPeerAnchorFromOutData(anchorPtrSet, fusionOpPeerInDataAnchor, fusionOpPeerInControlFromOutData, - fusionOps[idx], newAllreduceDesc, outDataAnchorIndex), - "Get peerAnchor from outDataAnchor failed"); - GE_CHK_STATUS_RET(GetPeerInControlFromOutControl(anchorPtrSet, fusionOpPeerInControlAnchor, fusionOps[idx]), - "Get peer outControlAnchor from inControlAnchor failed"); - - // Delete the node - GE_CHK_STATUS_RET(graph->RemoveNode(fusionOps[idx]), "FusionAllReducePass FAILED: remove node %s\n.", - fusionOps[idx]->GetName().c_str()); - } - - NodePtr newAllReducePtr = graph->AddNode(newAllreduceDesc); - GE_CHECK_NOTNULL(newAllReducePtr); - // Link the inputDataAnchor - for (uint32_t i = 0; i < fusionOpPeerOutDataAnchor.size(); i++) { - GE_CHK_STATUS_RET( - GraphUtils::AddEdge(fusionOpPeerOutDataAnchor[i], newAllReducePtr->GetInDataAnchor(static_cast(i))), - "FusionAllReducePass FAILED: add input data edge failed"); - } - - // Link the inputControlAnchor - for (uint32_t i = 0; i < fusionOpPeerOutControlAnchor.size(); i++) { - GE_CHK_STATUS_RET(GraphUtils::AddEdge(fusionOpPeerOutControlAnchor[i], newAllReducePtr->GetInControlAnchor()), - "FusionAllReducePass FAILED: add input control edge failed"); - } - - for (uint32_t i = 0; i < fusionOpPeerOutDataToInControl.size(); i++) { - GE_CHK_STATUS_RET(GraphUtils::AddEdge(fusionOpPeerOutDataToInControl[i], newAllReducePtr->GetInControlAnchor()), - "FusionAllReducePass FAILED: add edge from out data to incontrol " - "failed"); - } - - // Link the outputDataAnchor - for (uint32_t i = 0; i < fusionOpPeerInDataAnchor.size(); i++) { - auto peerInDataAnchor = fusionOpPeerInDataAnchor[i].second; - GE_CHK_STATUS_RET( - GraphUtils::AddEdge(newAllReducePtr->GetOutDataAnchor(fusionOpPeerInDataAnchor[i].first), peerInDataAnchor), - "FusionAllReducePass FAILED: add output data edge failed"); - } - for (uint32_t i = 0; i < fusionOpPeerInControlFromOutData.size(); i++) { - auto peerInControlAnchor = fusionOpPeerInControlFromOutData[i].second; - GE_CHK_STATUS_RET( - GraphUtils::AddEdge(newAllReducePtr->GetOutDataAnchor(fusionOpPeerInControlFromOutData[i].first), - peerInControlAnchor), - "FusionAllReducePass FAILED: add edge from out data to in control " - "failed"); - } - - // Link the outputControlAnchor - for (uint32_t i = 0; i < fusionOpPeerInControlAnchor.size(); i++) { - GE_CHK_STATUS_RET(GraphUtils::AddEdge(newAllReducePtr->GetOutControlAnchor(), fusionOpPeerInControlAnchor[i]), - "FusionAllReducePass FAILED: add output control edge failed"); - } - - // Link the newAllreduce - if (segmentIdx > 0 && previousNewAllreduceOutControlAnchor != nullptr) { - GE_CHK_STATUS_RET( - GraphUtils::AddEdge(previousNewAllreduceOutControlAnchor, newAllReducePtr->GetInControlAnchor()), - "FusionAllReducePass FAILED: add input previous control edge failed"); - } - - previousNewAllreduceOutControlAnchor = newAllReducePtr->GetOutControlAnchor(); - start = end + 1; - } - - return SUCCESS; -} - -Status AllReducePass::GetPeerOutDataToInData(std::unordered_set &anchorSet, - vector &peerOutDataAnchorVec, - ge::NodePtr &srcNodePtr) { - for (auto inDataAnchor : srcNodePtr->GetAllInDataAnchors()) { - GE_IF_BOOL_EXEC(inDataAnchor == nullptr, continue;); - OutDataAnchorPtr peerOutDataAnchor = inDataAnchor->GetPeerOutAnchor(); - GE_IF_BOOL_EXEC(peerOutDataAnchor == nullptr, continue;); - if (anchorSet.count(peerOutDataAnchor.get()) == 0) { - peerOutDataAnchorVec.push_back(peerOutDataAnchor); - anchorSet.insert(peerOutDataAnchor.get()); - GE_CHK_STATUS_RET(GraphUtils::RemoveEdge(peerOutDataAnchor, inDataAnchor)); - } - } - return SUCCESS; -} - -Status AllReducePass::GetPeerInAnchorToOutData( - std::unordered_set &anchorSet, std::vector> &fusionOpPeerInDataAnchor, - std::vector> &fusionOpPeerInControlFromOutData, ge::NodePtr &srcNodePtr) { - for (auto outDataAnchor : srcNodePtr->GetAllOutDataAnchors()) { - GE_IF_BOOL_EXEC(outDataAnchor == nullptr, continue;); - for (auto peerInDataAnchor : outDataAnchor->GetPeerInDataAnchors()) { - GE_IF_BOOL_EXEC(peerInDataAnchor == nullptr, continue;); - if (anchorSet.count(peerInDataAnchor.get()) == 0) { - std::pair pairPeerInDataAnchor; - pairPeerInDataAnchor.first = 0; - pairPeerInDataAnchor.second = peerInDataAnchor; - fusionOpPeerInDataAnchor.push_back(pairPeerInDataAnchor); - anchorSet.insert(peerInDataAnchor.get()); - GE_CHK_STATUS_RET(GraphUtils::RemoveEdge(outDataAnchor, peerInDataAnchor)); - } - } - - for (auto peerInControlAnchorFromData : outDataAnchor->GetPeerInControlAnchors()) { - GE_IF_BOOL_EXEC(peerInControlAnchorFromData == nullptr, continue;); - if (anchorSet.count(peerInControlAnchorFromData.get()) == 0) { - std::pair pairPeerInControlAnchorFromData; - pairPeerInControlAnchorFromData.first = 0; - pairPeerInControlAnchorFromData.second = peerInControlAnchorFromData; - fusionOpPeerInControlFromOutData.push_back(pairPeerInControlAnchorFromData); - anchorSet.insert(peerInControlAnchorFromData.get()); - GE_CHK_STATUS_RET(GraphUtils::RemoveEdge(outDataAnchor, peerInControlAnchorFromData)); - } - } - } - return SUCCESS; -} - -Status AllReducePass::GetPeerOutDataToInData(std::unordered_set &anchorSet, - vector &peerOutDataAnchorVec, - ge::NodePtr &srcNodePtr, ge::OpDescPtr &dstOpDescPtr) { - for (auto inDataAnchor : srcNodePtr->GetAllInDataAnchors()) { - GE_IF_BOOL_EXEC(inDataAnchor == nullptr, continue;); - OutDataAnchorPtr peerOutDataAnchor = inDataAnchor->GetPeerOutAnchor(); - GE_IF_BOOL_EXEC(peerOutDataAnchor == nullptr, continue;); - if (anchorSet.count(peerOutDataAnchor.get()) == 0) { - peerOutDataAnchorVec.push_back(peerOutDataAnchor); - anchorSet.insert(peerOutDataAnchor.get()); - if (dstOpDescPtr->AddInputDesc(inDataAnchor->GetOwnerNode()->GetOpDesc()->GetInputDesc(inDataAnchor->GetIdx())) != - ge::GRAPH_SUCCESS) { - GELOGW("GetPeerOutDataToInData: AddInputDesc failed"); - } - GE_CHK_STATUS_RET(GraphUtils::RemoveEdge(peerOutDataAnchor, inDataAnchor)); - } - } - return SUCCESS; -} - -Status AllReducePass::GetPeerOutDataToInControl(std::unordered_set &anchorSet, - vector &peerOutDataToInControlVec, - ge::NodePtr &srcNodePtr) { - InControlAnchorPtr inControlAnchor = srcNodePtr->GetInControlAnchor(); - GE_CHECK_NOTNULL(inControlAnchor); - for (auto peerOutDataToInControl : inControlAnchor->GetPeerOutDataAnchors()) { - GE_IF_BOOL_EXEC(peerOutDataToInControl == nullptr, continue;); - if (anchorSet.count(peerOutDataToInControl.get()) == 0) { - peerOutDataToInControlVec.push_back(peerOutDataToInControl); - anchorSet.insert(peerOutDataToInControl.get()); - GE_CHK_STATUS_RET(GraphUtils::RemoveEdge(peerOutDataToInControl, inControlAnchor)); - } - } - return SUCCESS; -} - -Status AllReducePass::GetPeerOutControlToInControl(std::unordered_set &anchorSet, - vector &peerOutControlToInControlVec, - ge::NodePtr &srcNodePtr) { - InControlAnchorPtr inControlAnchor = srcNodePtr->GetInControlAnchor(); - GE_CHECK_NOTNULL(inControlAnchor); - for (auto peerOutControlAnchor : inControlAnchor->GetPeerOutControlAnchors()) { - GE_IF_BOOL_EXEC(peerOutControlAnchor == nullptr, continue;); - if (anchorSet.count(peerOutControlAnchor.get()) == 0) { - peerOutControlToInControlVec.push_back(peerOutControlAnchor); - anchorSet.insert(peerOutControlAnchor.get()); - GE_CHK_STATUS_RET(GraphUtils::RemoveEdge(peerOutControlAnchor, inControlAnchor)); - } - } - return SUCCESS; -} - -Status AllReducePass::GetPeerAnchorFromOutData( - std::unordered_set &anchorSet, vector> &peerInDataFromOutDataVec, - vector> &peerInControlFromOutDataVec, ge::NodePtr &srcNodePtr, - ge::OpDescPtr &dstOpDescPtr, int &index) { - for (auto outDataAnchor : srcNodePtr->GetAllOutDataAnchors()) { - GE_IF_BOOL_EXEC(outDataAnchor == nullptr, continue;) - if (outDataAnchor->GetPeerInDataAnchors().size() > 0 || outDataAnchor->GetPeerInControlAnchors().size() > 0) { - if (dstOpDescPtr->AddOutputDesc( - outDataAnchor->GetOwnerNode()->GetOpDesc()->GetOutputDesc(outDataAnchor->GetIdx())) != ge::GRAPH_SUCCESS) { - GELOGW("GetPeerAnchorFromOutData: AddOutputDesc failed"); - } - index++; - } - - for (auto peerInDataAnchor : outDataAnchor->GetPeerInDataAnchors()) { - GE_IF_BOOL_EXEC(peerInDataAnchor == nullptr, continue;) - if (anchorSet.count(peerInDataAnchor.get()) == 0) { - std::pair pairPeerInDataAnchor; - pairPeerInDataAnchor.first = index; - pairPeerInDataAnchor.second = peerInDataAnchor; - peerInDataFromOutDataVec.push_back(pairPeerInDataAnchor); - anchorSet.insert(peerInDataAnchor.get()); - GE_CHK_STATUS_RET(GraphUtils::RemoveEdge(outDataAnchor, peerInDataAnchor)) - } - } - - for (auto peerInControlAnchorFromData : outDataAnchor->GetPeerInControlAnchors()) { - GE_IF_BOOL_EXEC(peerInControlAnchorFromData == nullptr, continue;) - if (anchorSet.count(peerInControlAnchorFromData.get()) == 0) { - std::pair pairPeerInControlAnchorFromData; - pairPeerInControlAnchorFromData.first = index; - pairPeerInControlAnchorFromData.second = peerInControlAnchorFromData; - peerInControlFromOutDataVec.push_back(pairPeerInControlAnchorFromData); - anchorSet.insert(peerInControlAnchorFromData.get()); - GE_CHK_STATUS_RET(GraphUtils::RemoveEdge(outDataAnchor, peerInControlAnchorFromData)) - } - } - } - return SUCCESS; -} - -Status AllReducePass::GetPeerInControlFromOutControl(std::unordered_set &anchorSet, - vector &peerInControlFromOutControlVec, - ge::NodePtr &srcNodePtr) { - OutControlAnchorPtr outControlAnchor = srcNodePtr->GetOutControlAnchor(); - GE_CHECK_NOTNULL(outControlAnchor); - for (auto peerInControlAnchor : outControlAnchor->GetPeerInControlAnchors()) { - GE_IF_BOOL_EXEC(peerInControlAnchor == nullptr, continue;) - if (anchorSet.count(peerInControlAnchor.get()) == 0) { - peerInControlFromOutControlVec.push_back(peerInControlAnchor); - anchorSet.insert(peerInControlAnchor.get()); - GE_CHK_STATUS_RET(GraphUtils::RemoveEdge(outControlAnchor, peerInControlAnchor)) - } - } - return SUCCESS; -} -} // namespace ge diff --git a/src/ge/graph/optimize/optimizer/allreduce_fusion_pass.h b/src/ge/graph/optimize/optimizer/allreduce_fusion_pass.h deleted file mode 100644 index 2701ba16..00000000 --- a/src/ge/graph/optimize/optimizer/allreduce_fusion_pass.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2019-2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GE_GRAPH_OPTIMIZE_OPTIMIZER_ALLREDUCE_FUSION_PASS_H_ -#define GE_GRAPH_OPTIMIZE_OPTIMIZER_ALLREDUCE_FUSION_PASS_H_ - -#include -#include -#include -#include "inc/graph_pass.h" - -namespace ge { -// -class AllReducePass : public GraphPass { - public: - Status Run(ge::ComputeGraphPtr graph) override; - - private: - Status GetPeerOutDataToInData(std::unordered_set &anchorSet, - vector &peerOutDataAnchorVec, ge::NodePtr &srcNodePtr, - ge::OpDescPtr &dstOpDescPtr); - Status GetPeerOutDataToInControl(std::unordered_set &anchorSet, - vector &peerOutDataToInControlVec, ge::NodePtr &srcNodePtr); - Status GetPeerOutControlToInControl(std::unordered_set &anchorSet, - vector &peerOutControlToInControlVec, - ge::NodePtr &srcNodePtr); - Status GetPeerAnchorFromOutData(std::unordered_set &anchorSet, - vector> &peerInDataFromOutDataVec, - vector> &peerInControlFromOutDataVec, - ge::NodePtr &srcNodePtr, ge::OpDescPtr &dstOpDescPtr, int &index); - Status GetPeerInControlFromOutControl(std::unordered_set &anchorSet, - vector &peerInControlFromOutControlVec, - ge::NodePtr &srcNodePtr); - Status GetPeerOutDataToInData(std::unordered_set &anchorSet, - std::vector &peerOutDataAnchorVec, ge::NodePtr &srcNodePtr); - Status GetPeerInAnchorToOutData(std::unordered_set &anchorSet, - std::vector> &fusionOpPeerInDataAnchor, - std::vector> &fusionOpPeerInControlFromOutData, - ge::NodePtr &srcNodePtr); -}; -} // namespace ge -#endif // GE_GRAPH_OPTIMIZE_OPTIMIZER_ALLREDUCE_FUSION_PASS_H_ diff --git a/src/ge/graph/partition/engine_place.cc b/src/ge/graph/partition/engine_place.cc index 80ac355f..455e29c0 100644 --- a/src/ge/graph/partition/engine_place.cc +++ b/src/ge/graph/partition/engine_place.cc @@ -50,7 +50,7 @@ Status EnginePlacer::Check() const { Status EnginePlacer::Run() { std::lock_guard lock(check_support_cost_mutex); - GELOGI("Engine placer starts."); + GELOGD("Engine placer starts."); if (Check() != SUCCESS) { return FAILED; } @@ -99,7 +99,7 @@ Status EnginePlacer::Run() { for (auto &it : ge::GELib::GetInstance()->DNNEngineManagerObj().GetCheckSupportCost()) { GEEVENT("The time cost of %s::CheckSupported is [%lu] micro second.", it.first.c_str(), it.second); } - GELOGI("Engine placer ends."); + GELOGD("Engine placer ends."); return is_check_support_success ? SUCCESS : FAILED; } diff --git a/src/ge/graph/partition/graph_partition.cc b/src/ge/graph/partition/graph_partition.cc index 8d4bcf51..6f424f5d 100644 --- a/src/ge/graph/partition/graph_partition.cc +++ b/src/ge/graph/partition/graph_partition.cc @@ -225,7 +225,7 @@ Status ge::GraphPartitioner::MergeSubGraph(ge::ComputeGraphPtr &output_merged_co GELOGE(GE_GRAPH_UNSUPPORTED, "Cannot call merging in partition mode"); return FAILED; } - GELOGI("Graph merge starts."); + GELOGD("Graph merge starts."); // check input param for (const auto &it : sub_graph_list) { if (it == nullptr) { @@ -263,7 +263,7 @@ Status ge::GraphPartitioner::MergeSubGraph(ge::ComputeGraphPtr &output_merged_co return FAILED; } GE_TIMESTAMP_END(MergeSubGraphEnginePlacerRun, "GraphPartitioner::MergeGraphEnginePlacerRun"); - GELOGI("Graph merge ends."); + GELOGD("Graph merge ends."); return SUCCESS; } @@ -383,12 +383,19 @@ graphStatus ge::GraphPartitioner::AddPlaceHolderEndInSrcDstGraph(const AnchorPtr GE_IF_BOOL_EXEC(!AttrUtils::SetInt(pld_op_desc, "anchorIndex", AnchorUtils::GetIdx(out_anchor)), GELOGW("SetInt anchorIndex failed");) GE_IF_BOOL_EXEC(!pld_op_desc->SetExtAttr("parentNode", src_node), GELOGW("SetPldExtAttr parentNode failed");) - - OpDescPtr src_node_op_desc = src_node->GetOpDesc(); - GE_CHECK_NOTNULL(src_node_op_desc); GE_IF_BOOL_EXEC( - !AttrUtils::SetStr(pld_op_desc, ATTR_NAME_PLD_FRONT_NODE_ENGINE_NAME, src_node_op_desc->GetOpEngineName()), + !AttrUtils::SetStr(pld_op_desc, ATTR_NAME_PLD_FRONT_NODE_ENGINE_NAME, src_node_opdesc->GetOpEngineName()), GELOGW("SetStr frontNodeEngineName failed");) + std::string l2_info_attr; + if (AttrUtils::GetStr(src_node_opdesc, "_task_L2FusionInfo", l2_info_attr)) { + GE_IF_BOOL_EXEC(!AttrUtils::SetStr(pld_op_desc, "_task_L2FusionInfo", l2_info_attr), + GELOGW("SetStr l2_info_attr failed");) + } + int64_t anchor_index_for_lxfusion; + if (AttrUtils::GetInt(src_node_opdesc, "_data_anchor_index_for_lxfusion", anchor_index_for_lxfusion)) { + GE_IF_BOOL_EXEC(!AttrUtils::SetInt(pld_op_desc, "_data_anchor_index_for_lxfusion", anchor_index_for_lxfusion), + GELOGW("SetInt anchor_index_for_lxfusion failed");) + } // do not care over flow graph_info_.num_of_pld_end_++; // replace output_desc of pld with input node's output desc @@ -582,7 +589,7 @@ Status ge::GraphPartitioner::Initialize(ge::ComputeGraphPtr compute_graph) { new_cluster->engine_name_.c_str(), new_cluster->index_, new_cluster->stream_label_.c_str()); temp_index++; } - GELOGI("Initialize ends."); + GELOGD("Initialize ends."); return SUCCESS; } @@ -753,11 +760,11 @@ void ge::GraphPartitioner::MarkClusters() { } } } - GELOGI("MarkClusters ends."); + GELOGD("MarkClusters ends."); } Status ge::GraphPartitioner::SplitSubGraphs(ge::ComputeGraphPtr compute_graph) { - GELOGI("SplitSubGraphs starts."); + GELOGD("SplitSubGraphs starts."); if (compute_graph == nullptr) { GELOGE(FAILED, "parameter ptr is null."); return FAILED; @@ -822,7 +829,7 @@ Status ge::GraphPartitioner::SplitSubGraphs(ge::ComputeGraphPtr compute_graph) { } } } - GELOGI("SplitSubGraphs ends."); + GELOGD("SplitSubGraphs ends."); return SUCCESS; } diff --git a/src/ge/graph/passes/atomic_addr_clean_pass.cc b/src/ge/graph/passes/atomic_addr_clean_pass.cc index 1baa9baa..76262ecf 100644 --- a/src/ge/graph/passes/atomic_addr_clean_pass.cc +++ b/src/ge/graph/passes/atomic_addr_clean_pass.cc @@ -33,10 +33,12 @@ namespace ge { Status AtomicAddrCleanPass::Run(ComputeGraphPtr graph) { GE_CHECK_NOTNULL(graph); GELOGD("AtomicAddrCleanPass begin."); + bool is_unknown_graph = graph->GetGraphUnknownFlag(); + // 1.Recoginze atomic and loop mark vector atomic_node_vec; for (NodePtr &node : graph->GetDirectNode()) { - if (IsAtomicOp(node)) { + if (IsAtomicOp(node, is_unknown_graph)) { atomic_node_vec.push_back(node); } if (!is_loop_graph_ && node->GetType() == LOOPCOND) { @@ -46,11 +48,10 @@ Status AtomicAddrCleanPass::Run(ComputeGraphPtr graph) { } } if (atomic_node_vec.empty()) { - GELOGI("There is no atomic node. Ignore atomicAddrClean pass."); + GELOGD("There is no atomic node. Ignore atomicAddrClean pass."); return SUCCESS; } - bool is_unknown_graph = graph->GetGraphUnknownFlag(); if (is_unknown_graph) { GELOGD("Graph[%s] is unknown graph. It will call fe interface to compile op.", graph->GetName().c_str()); GE_CHK_STATUS_RET(CompileUnknownGraphOp(atomic_node_vec)); @@ -240,55 +241,102 @@ Status AtomicAddrCleanPass::LinkToAtomicNode(const NodePtr &atomic_node, NodePtr return SUCCESS; } -bool AtomicAddrCleanPass::IsAtomicOp(const NodePtr &node) { +bool AtomicAddrCleanPass::IsAtomicOp(const NodePtr &node, bool is_unknown_graph) { GE_IF_BOOL_EXEC(node == nullptr, GELOGE(FAILED, "node is null."); return false); OpDescPtr op_desc = node->GetOpDesc(); if (op_desc == nullptr) { return false; } + + if (CheckAtomicFromOpsKernel(node)) { + return true; + } + + // 2.Check atomic attr in node + std::map> node_workspace_offset; + bool has_atomic_input = op_desc->HasAttr(ATOMIC_ATTR_INPUT_INDEX); + bool has_atomic_output = op_desc->HasAttr(ATOMIC_ATTR_OUTPUT_INDEX); + node_workspace_offset = op_desc->TryGetExtAttr(EXT_ATTR_ATOMIC_WORKSPACE_OFFSET, node_workspace_offset); + if (!has_atomic_input && !has_atomic_output && node_workspace_offset.empty()) { + return false; + } + + if (!is_unknown_graph) { + if (!has_atomic_input && has_atomic_output && node_workspace_offset.empty()) { + std::vector atomic_output_index; + (void)ge::AttrUtils::GetListInt(op_desc, ATOMIC_ATTR_OUTPUT_INDEX, atomic_output_index); + bool is_all_output_peer_also_atomic = true; + for (const auto &output_index : atomic_output_index) { + if (!IsOutputIndexPeerInputAtomic(node, output_index)) { + is_all_output_peer_also_atomic = false; + break; + } + } + if (is_all_output_peer_also_atomic) { + GELOGI("all out peer node input atomic, skip this out atomic process, node name: %s", node->GetName().c_str()); + return false; + } + } + } + + graphStatus ret = op_desc->SetAttr(ATOMIC_ATTR_IS_ATOMIC_NODE, GeAttrValue::CreateFrom(true)); + if (ret != GRAPH_SUCCESS) { + GELOGW("set attr ATOMIC_ATTR_IS_ATOMIC_NODE fail."); + } + GELOGD("Recognized atomic op %s from attr.", op_desc->GetName().c_str()); + return true; +} + +// just hccl may mark atomic from ops kernel now, and hccl's atomic if for all input +bool AtomicAddrCleanPass::CheckAtomicFromOpsKernel(const NodePtr &node) { // 1.Check if isAtomic attrs exist for HCOM std::shared_ptr instance_ptr = GELib::GetInstance(); if ((instance_ptr == nullptr) || (!instance_ptr->InitFlag())) { - GELOGW("GELib not initialized"); + GELOGW("GELib not initialized, atomic from ops kernel judge false, node_name: %s", node->GetName().c_str()); return false; } OpsKernelManager &ops_kernel_manager = instance_ptr->OpsKernelManagerObj(); - vector op_info_vec = ops_kernel_manager.GetOpsKernelInfo(op_desc->GetType()); + vector op_info_vec = ops_kernel_manager.GetOpsKernelInfo(node->GetType()); for (const auto &op_info : op_info_vec) { if (op_info.isAtomic) { - GELOGI("Recognized atomic op %s from DNN_HCCL engine.", op_desc->GetName().c_str()); // check peer input is DATA for (auto &in_data_anchor : node->GetAllInDataAnchors()) { if (in_data_anchor->GetPeerOutAnchor() != nullptr && in_data_anchor->GetPeerOutAnchor()->GetOwnerNode() != nullptr) { auto peer_in_node = in_data_anchor->GetPeerOutAnchor()->GetOwnerNode(); if (peer_in_node->GetType() == DATA) { - GELOGI("Recognized atomic op %s from DNN_HCCL engine and input is DATA.", op_desc->GetName().c_str()); + GELOGI("Recognized atomic op %s from %s engine and input is DATA.", node->GetName().c_str(), + op_info.engine.c_str()); return false; } } } + GELOGI("Recognized atomic op %s from %s engine.", node->GetName().c_str(), op_info.engine.c_str()); hcom_node_vec_.push_back(node); return true; } } - // 2.Check atomic attr in node - std::map> node_workspace_offset; - bool has_atomic_input = op_desc->HasAttr(ATOMIC_ATTR_INPUT_INDEX); - bool has_atomic_output = op_desc->HasAttr(ATOMIC_ATTR_OUTPUT_INDEX); - node_workspace_offset = op_desc->TryGetExtAttr(EXT_ATTR_ATOMIC_WORKSPACE_OFFSET, node_workspace_offset); - if (!has_atomic_input && !has_atomic_output && node_workspace_offset.empty()) { + return false; +} + +bool AtomicAddrCleanPass::IsOutputIndexPeerInputAtomic(const NodePtr &node, int64_t output_index) { + auto out_data_anchor = node->GetAllOutDataAnchors().at(output_index); + if (out_data_anchor == nullptr) { return false; } - graphStatus ret = op_desc->SetAttr(ATOMIC_ATTR_IS_ATOMIC_NODE, GeAttrValue::CreateFrom(true)); - if (ret != GRAPH_SUCCESS) { - GELOGW("set attr ATOMIC_ATTR_IS_ATOMIC_NODE fail."); + for (const auto input_anchor : out_data_anchor->GetPeerInDataAnchors()) { + auto output_node = input_anchor->GetOwnerNode(); + // just hccl may mark atomic from ops kernel now, and hccl's atomic if for all input + // hccl's attr ATOMIC_ATTR_INPUT_INDEX mark on CalcOpRunningParam, can't be get here + if (CheckAtomicFromOpsKernel(output_node)) { + return true; + } } - GELOGD("Recognized atomic op %s from FE engine.", op_desc->GetName().c_str()); - return true; + return false; } + /// /// @brief Clear Status, used for subgraph pass /// @return SUCCESS diff --git a/src/ge/graph/passes/atomic_addr_clean_pass.h b/src/ge/graph/passes/atomic_addr_clean_pass.h index e22c1792..b0235894 100644 --- a/src/ge/graph/passes/atomic_addr_clean_pass.h +++ b/src/ge/graph/passes/atomic_addr_clean_pass.h @@ -72,7 +72,7 @@ class AtomicAddrCleanPass : public GraphPass { * @param node * @return */ - bool IsAtomicOp(const NodePtr &node); + bool IsAtomicOp(const NodePtr &node, bool is_unknown_graph); /** * Handle atomic node in unknown graph @@ -84,6 +84,10 @@ class AtomicAddrCleanPass : public GraphPass { Status HandleDispersedAtomicNodes(ComputeGraphPtr &graph, const std::vector &atomic_node_vec, std::vector &common_atomic_nodes); + bool CheckAtomicFromOpsKernel(const NodePtr &node); + + bool IsOutputIndexPeerInputAtomic(const NodePtr &node, int64_t output_index); + vector hcom_node_vec_; bool is_loop_graph_ = false; }; diff --git a/src/ge/graph/passes/compile_nodes_pass.cc b/src/ge/graph/passes/compile_nodes_pass.cc index 037cc332..7d7ad7a0 100644 --- a/src/ge/graph/passes/compile_nodes_pass.cc +++ b/src/ge/graph/passes/compile_nodes_pass.cc @@ -36,7 +36,7 @@ const char *const kAICPUKernelLibName = "aicpu_tf_kernel"; namespace ge { graphStatus CompileNodesPass::Run(ComputeGraphPtr graph) { GE_TIMESTAMP_START(CompileNodesPass); - GELOGI("[CompileNodesPass]: optimize begin."); + GELOGD("[CompileNodesPass]: optimize begin."); if (graph == nullptr) { return GRAPH_SUCCESS; } @@ -70,6 +70,10 @@ graphStatus CompileNodesPass::Run(ComputeGraphPtr graph) { std::vector node_vec{node}; kernel_to_compile_nodes.insert(std::make_pair(kernel_lib_name, node_vec)); } + } else { + GELOGE(GRAPH_FAILED, "Get node:%s, type:%s supported kernel failed.", node->GetName().c_str(), + node->GetType().c_str()); + return GRAPH_FAILED; } } // compile node follow different kernel, currently only TBE kernel @@ -78,7 +82,7 @@ graphStatus CompileNodesPass::Run(ComputeGraphPtr graph) { GELOGE(result, "Compile op failed."); return result; } - GELOGI("[CompileNodesPass]: Optimize success."); + GELOGD("[CompileNodesPass]: Optimize success."); GE_TIMESTAMP_EVENT_END(CompileNodesPass, "OptimizeStage2::ControlAttrOptimize::CompileNodesPass"); return GRAPH_SUCCESS; } @@ -108,8 +112,28 @@ graphStatus CompileNodesPass::GetSupportedKernel(const NodePtr &node, const std: } // begin accuracy supported check if (!CheckAccuracySupport(kernel_info, instance, op_desc)) { - // if check accuracy support failed , try to go to aicpu engine - kernel_lib_name = kAICPUKernelLibName; + // if check accuracy support failed , try to go to other engine. + GELOGD("Check Accuracy Supported return not support, node name is %s. Try to go to other engine.", + op_desc->GetName().c_str()); + string kernel_name_origin = kernel_lib_name; + OpsKernelManager &ops_kernel_manager = instance->OpsKernelManagerObj(); + auto kernel_map = ops_kernel_manager.GetAllOpsKernelInfoStores(); + for (auto it = kernel_map.begin(); it != kernel_map.end(); ++it) { + string tmp_kernel_name = it->first; + if (tmp_kernel_name == kernel_name_origin) { + continue; + } + OpsKernelInfoStorePtr tmp_kernel_info = it->second; + if (CheckAccuracySupport(tmp_kernel_info, instance, op_desc)) { + kernel_lib_name = tmp_kernel_name; + GELOGD("Find kernel lib %s support node:%s, type:%s , get kernel lib success.", tmp_kernel_name.c_str(), + node->GetName().c_str(), op_desc->GetType().c_str()); + return GRAPH_SUCCESS; + } + } + GELOGE(GRAPH_FAILED, "Cannot find kernel lib support node:%s, type:%s , get kernel lib failed.", + node->GetName().c_str(), op_desc->GetType().c_str()); + return GRAPH_FAILED; } return GRAPH_SUCCESS; } @@ -123,8 +147,6 @@ bool CompileNodesPass::CheckAccuracySupport(const OpsKernelInfoStorePtr &kernel_ } string reason; if (!(kernel_info->CheckAccuracySupported(*ge_desc, reason, true))) { - GELOGW("Check Accuracy Supported return not support, node name is %s, reason: %s. Try to go to AICPU engine.", - op_desc->GetName().c_str(), reason.c_str()); return false; } return true; diff --git a/src/ge/graph/passes/cond_remove_pass.cc b/src/ge/graph/passes/cond_remove_pass.cc index 1650be92..cc5a230b 100644 --- a/src/ge/graph/passes/cond_remove_pass.cc +++ b/src/ge/graph/passes/cond_remove_pass.cc @@ -326,7 +326,7 @@ Status CondRemovePass::GetCondInfo(const NodePtr &node, ComputeGraphPtr &graph, return FAILED; } } else { - GELOGI("no need cond_pass for node %s.", node->GetName().c_str()); + GELOGD("no need cond_pass for node %s.", node->GetName().c_str()); return NOT_CHANGED; } diff --git a/src/ge/graph/passes/data_pass.cc b/src/ge/graph/passes/data_pass.cc index 517e7737..5da3c5a0 100644 --- a/src/ge/graph/passes/data_pass.cc +++ b/src/ge/graph/passes/data_pass.cc @@ -16,13 +16,138 @@ #include "graph/passes/data_pass.h" -#include - #include "framework/common/debug/ge_log.h" #include "graph/utils/graph_utils.h" -#include "register/op_registry.h" namespace ge { +namespace { +Status MappingSubgraphInput(const ComputeGraphPtr &graph, const std::function &input) { + for (const auto &node : graph->GetDirectNode()) { + if (node->GetType() != DATA) { + continue; + } + + int index = -1; + if (!AttrUtils::GetInt(node->GetOpDesc(), "index", index)) { + GELOGE(FAILED, "Failed to get index from data[%s]", node->GetName().c_str()); + return FAILED; + } + + int parent_index = input(index); + GELOGI("Generate subgraph input map for subgraph %s, data index %d, parent index %d", graph->GetName().c_str(), + index, parent_index); + if (!AttrUtils::SetInt(node->GetOpDesc(), ATTR_NAME_PARENT_NODE_INDEX, parent_index)) { + GELOGE(FAILED, "Failed to set parent index for node %s", node->GetName().c_str()); + return FAILED; + } + } + + return SUCCESS; +} + +Status MappingSubgraphOutput(const ComputeGraphPtr &graph, const std::function &output) { + const auto &output_node = graph->FindFirstNodeMatchType(NETOUTPUT); + if (output_node == nullptr) { + return SUCCESS; + } + + const auto &op_desc = output_node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + for (size_t index = 0; index < op_desc->GetInputsSize(); ++index) { + int parent_index = output(index); + GELOGI("Generate subgraph output map for subgraph %s, index %zu, parent index %d", graph->GetName().c_str(), index, + parent_index); + if (parent_index == -1) { + continue; + } + + GeTensorDescPtr tensor = op_desc->MutableInputDesc(index); + GE_CHECK_NOTNULL(tensor); + if (!AttrUtils::SetInt(tensor, ATTR_NAME_PARENT_NODE_INDEX, parent_index)) { + GELOGE(FAILED, "Failed to set parent index for graph %s", graph->GetName().c_str()); + return FAILED; + } + } + + return SUCCESS; +} + +Status MappingSubgraphIndex(const ComputeGraphPtr &graph, const std::function &input, + const std::function &output) { + GE_CHECK_NOTNULL(graph); + GE_CHECK_NOTNULL(input); + GE_CHECK_NOTNULL(output); + if (MappingSubgraphInput(graph, input) != SUCCESS) { + GELOGE(FAILED, "Failed to mapping subgraph input for graph: %s", graph->GetName().c_str()); + return FAILED; + } + + if (MappingSubgraphOutput(graph, output) != SUCCESS) { + GELOGE(FAILED, "Failed to mapping subgraph output for graph: %s", graph->GetName().c_str()); + return FAILED; + } + + return SUCCESS; +} + +Status ParseSubgraphPostFnCase(const string &subgraph_name, const ComputeGraphPtr &graph) { + return MappingSubgraphIndex( + graph, [](int data_index) { return data_index + 1; }, [](int retval_index) { return retval_index; }); +} + +Status ParseSubgraphPostFnIf(const string &subgraph_name, const ComputeGraphPtr &graph) { + return MappingSubgraphIndex( + graph, [](int data_index) { return data_index + 1; }, [](int retval_index) { return retval_index; }); +} + +Status ParseSubgraphPostFnWhile(const string &subgraph_name, const ComputeGraphPtr &graph) { + return MappingSubgraphIndex( + graph, [](int data_index) { return data_index; }, + [&](int retval_index) { return (subgraph_name == "cond") ? -1 : retval_index; }); +} + +Status ParseSubgraphPostFnFor(const string &subgraph_name, const ComputeGraphPtr &graph) { + return MappingSubgraphIndex( + graph, [](int data_index) { return (data_index == 0) ? 0 : data_index + 2; }, + [](int retval_index) { return retval_index; }); +} + +Status ParseSubgraphPostFnPartitionedCall(const string &subgraph_name, const ComputeGraphPtr &graph) { + return MappingSubgraphIndex( + graph, [](int data_index) { return data_index; }, [](int retval_index) { return retval_index; }); +} +} // namespace + +Status DataPass::PostParseSubgraph(const ComputeGraphPtr &graph, const string &ir_name, const NodePtr &parent_node) { + using ParseSubgraphFunc = std::function; + const static std::map subgraph_handle = { + {FOR, ParseSubgraphPostFnFor}, + {CASE, ParseSubgraphPostFnCase}, + {IF, ParseSubgraphPostFnIf}, + {_IF, ParseSubgraphPostFnIf}, + {STATELESSIF, ParseSubgraphPostFnIf}, + {WHILE, ParseSubgraphPostFnWhile}, + {_WHILE, ParseSubgraphPostFnWhile}, + {STATELESSWHILE, ParseSubgraphPostFnWhile}, + {PARTITIONEDCALL, ParseSubgraphPostFnPartitionedCall}, + {STATEFULPARTITIONEDCALL, ParseSubgraphPostFnPartitionedCall}}; + + auto post_func_it = subgraph_handle.find(parent_node->GetType()); + if (post_func_it == subgraph_handle.end()) { + GELOGE(FAILED, "The subgraph post func for node %s type %s is null.", parent_node->GetName().c_str(), + parent_node->GetType().c_str()); + return FAILED; + } + + if (post_func_it->second(ir_name, graph) != SUCCESS) { + GELOGE(FAILED, "Failed to post process subgraph %s on node %s type %s", graph->GetName().c_str(), + parent_node->GetName().c_str(), parent_node->GetType().c_str()); + return FAILED; + } + + return SUCCESS; +} + Status DataPass::Run(ComputeGraphPtr compute_graph) { GE_CHECK_NOTNULL(compute_graph); if (compute_graph->GetParentNode() == nullptr) { // for subgraph post process. @@ -63,21 +188,6 @@ Status DataPass::Run(ComputeGraphPtr compute_graph) { node->GetOpDesc()->SetName(parent_node->GetName() + "_" + compute_graph->GetName() + "/" + node->GetName()); } - auto post_func = domi::OpRegistry::Instance()->GetParseSubgraphPostFunc(parent_node->GetType()); - if (post_func == nullptr) { - GELOGW("The subgraph post func for node %s type %s is null.", parent_node->GetName().c_str(), - parent_node->GetType().c_str()); - return SUCCESS; - } - - auto graph = GraphUtils::CreateGraphFromComputeGraph(compute_graph); - auto ret = post_func(subgraph_name, graph); - if (ret != SUCCESS) { - GELOGE(FAILED, "Failed to post-process subgraph %s on node %s type %s", graph.GetName().c_str(), - parent_node->GetName().c_str(), parent_node->GetType().c_str()); - return FAILED; - } - - return SUCCESS; + return PostParseSubgraph(compute_graph, subgraph_name, parent_node); } } // namespace ge diff --git a/src/ge/graph/passes/data_pass.h b/src/ge/graph/passes/data_pass.h index 1f6d0f0b..daaf8839 100644 --- a/src/ge/graph/passes/data_pass.h +++ b/src/ge/graph/passes/data_pass.h @@ -24,6 +24,9 @@ namespace ge { class DataPass : public GraphPass { public: Status Run(ge::ComputeGraphPtr graph); + + private: + Status PostParseSubgraph(const ComputeGraphPtr &graph, const string &ir_name, const NodePtr &parent_node); }; } // namespace ge diff --git a/src/ge/graph/passes/flow_ctrl_pass.cc b/src/ge/graph/passes/flow_ctrl_pass.cc index 877f940f..5b1e00e5 100644 --- a/src/ge/graph/passes/flow_ctrl_pass.cc +++ b/src/ge/graph/passes/flow_ctrl_pass.cc @@ -359,9 +359,8 @@ Status FlowCtrlPass::CreateIterCtrlFalseBranch(ComputeGraphPtr &compute_graph, c return FAILED; } GE_CHK_STATUS_RET(SetStreamLabel(active_node, switch_node->GetName()), "set stream label failed"); - GE_IF_BOOL_EXEC(!AttrUtils::SetBool(active_node->GetOpDesc(), ATTR_NAME_IS_LOOP_ACTIVE, true), - DOMI_LOGE("set ATTR_NAME_IS_LOOP_ACTIVE failed"); - return FAILED); + GE_CHK_STATUS_RET(SetSwitchBranchNodeLabel(active_node, switch_node->GetName()), + "set switch branch node label failed"); string model_exit_name = switch_node->GetName() + "_ModelExit"; GE_CHK_STATUS_RET(SetActiveLabelList(active_node, {model_exit_name}), "set active label list failed"); diff --git a/src/ge/graph/passes/mark_agnostic_pass.cc b/src/ge/graph/passes/mark_agnostic_pass.cc index 7f6fd965..5597b452 100644 --- a/src/ge/graph/passes/mark_agnostic_pass.cc +++ b/src/ge/graph/passes/mark_agnostic_pass.cc @@ -17,6 +17,7 @@ #include "graph/passes/mark_agnostic_pass.h" #include "graph/utils/node_utils.h" +#include "graph/utils/tensor_utils.h" namespace ge { Status MarkAgnosticPass::Run(ComputeGraphPtr graph) { @@ -48,6 +49,16 @@ Status MarkAgnosticPass::Run(ComputeGraphPtr graph) { } if (node_type == MERGE) { GELOGD("Mark format agnostic and continuous for merge node %s", node->GetName().c_str()); + auto in_nodes = node->GetInAllNodes(); + vector input_nodes(in_nodes.begin(), in_nodes.end()); + /// Enter-----------+ + /// +-> Merge + /// NextIteration---+ + if (input_nodes.size() == 2) { + if (input_nodes[0]->GetType() == ENTER && input_nodes[1]->GetType() == NEXTITERATION) { + continue; + } + } const OpDescPtr op_desc = node->GetOpDesc(); const GeTensorDescPtr op_tensor = op_desc->MutableOutputDesc(0); if (op_tensor == nullptr) { diff --git a/src/ge/graph/passes/mark_graph_unknown_status_pass.cc b/src/ge/graph/passes/mark_graph_unknown_status_pass.cc index 2abec90b..49476987 100644 --- a/src/ge/graph/passes/mark_graph_unknown_status_pass.cc +++ b/src/ge/graph/passes/mark_graph_unknown_status_pass.cc @@ -19,6 +19,10 @@ #include "graph/debug/ge_attr_define.h" namespace ge { +namespace { +const char *const kOwnerGraphIsUnknown = "OwnerGraphIsUnknown"; +} + Status MarkGraphUnknownStatusPass::Run(ComputeGraphPtr graph) { GE_CHECK_NOTNULL(graph); bool is_unknown_shape = false; @@ -35,6 +39,11 @@ Status MarkGraphUnknownStatusPass::Run(ComputeGraphPtr graph) { break; } } + + for (const auto &node : graph->GetDirectNode()) { + GELOGD("Set OwnerGraphIsUnknown attr to node[%s]", node->GetName().c_str()); + (void)AttrUtils::SetBool(node->GetOpDesc(), kOwnerGraphIsUnknown, is_unknown_shape); + } graph->SetGraphUnknownFlag(is_unknown_shape); GELOGD("mark graph [%s] unknown status success! value is %d", graph->GetName().c_str(), is_unknown_shape); return SUCCESS; diff --git a/src/ge/graph/passes/memcpy_addr_async_pass.cc b/src/ge/graph/passes/memcpy_addr_async_pass.cc index f4bf9c00..0067d248 100644 --- a/src/ge/graph/passes/memcpy_addr_async_pass.cc +++ b/src/ge/graph/passes/memcpy_addr_async_pass.cc @@ -250,7 +250,7 @@ NodePtr MemcpyAddrAsyncPass::CreateMemcpyAddrAsyncNode(const ComputeGraphPtr &gr } } - NodePtr memcpy_addr_async_node = graph->AddNodeAfter(op_desc, out_data_anchor->GetOwnerNode()); + NodePtr memcpy_addr_async_node = graph->AddNode(op_desc); GE_CHECK_NOTNULL_EXEC(memcpy_addr_async_node, return nullptr); return memcpy_addr_async_node; @@ -278,7 +278,7 @@ Status MemcpyAddrAsyncPass::InsertMemcpyAddrAsyncNode(const OutDataAnchorPtr &ou } Status MemcpyAddrAsyncPass::InsertMemAddrAsyncNodeBeforeNetoutput(const ComputeGraphPtr &graph, const NodePtr &node) { - GELOGI("Start AddMemcpyAddrAsyncNode for %s.", node->GetName().c_str()); + GELOGD("Start AddMemcpyAddrAsyncNode for %s.", node->GetName().c_str()); for (const auto &in_data_anchor : node->GetAllInDataAnchors()) { auto in_node = NodeUtils::GetInDataNodeByIndex(*node, in_data_anchor->GetIdx()); GE_CHECK_NOTNULL(in_node); diff --git a/src/ge/graph/passes/merge_pass.cc b/src/ge/graph/passes/merge_pass.cc index dc4451e9..93fc5869 100644 --- a/src/ge/graph/passes/merge_pass.cc +++ b/src/ge/graph/passes/merge_pass.cc @@ -34,6 +34,11 @@ using domi::SUCCESS; namespace ge { const int kValueIndexOutputIndex = 1; +bool IsEmptyTensor(const GeShape &shape) { + const auto &dims = shape.GetDims(); + return std::any_of(dims.begin(), dims.end(), [](int64_t dim) { return dim == 0; }); +} + Status MergePass::Run(NodePtr &node) { GELOGD("MergePass running"); if (node == nullptr) { @@ -53,6 +58,11 @@ Status MergePass::Run(NodePtr &node) { return PARAM_INVALID; } + if (OptimizeEmptyTensorInput(node) != SUCCESS) { + GELOGE(FAILED, "[%s] remove empty_tensor inputs failed.", node->GetName().c_str()); + return FAILED; + } + auto in_data_nodes = node->GetInDataNodes(); switch (in_data_nodes.size()) { case 0: { @@ -203,4 +213,27 @@ bool MergePass::IsMergeInputNeedOptimized(NodePtr &node) const { } return true; } + +Status MergePass::OptimizeEmptyTensorInput(const NodePtr &node) { + for (const auto &in_data_anchor : node->GetAllInDataAnchors()) { + const auto &peer_data_anchor = in_data_anchor->GetPeerOutAnchor(); + if (peer_data_anchor == nullptr) { + continue; + } + if ((peer_data_anchor->GetOwnerNode() == nullptr) || (peer_data_anchor->GetOwnerNode()->GetOpDesc() == nullptr)) { + continue; + } + const auto &op_desc = peer_data_anchor->GetOwnerNode()->GetOpDesc(); + if (IsEmptyTensor(op_desc->GetOutputDesc(peer_data_anchor->GetIdx()).GetShape())) { + if (GraphUtils::RemoveEdge(peer_data_anchor, in_data_anchor) != GRAPH_SUCCESS) { + GELOGE(FAILED, "Remove data edge %s:%d->%s:%d failed.", op_desc->GetName().c_str(), peer_data_anchor->GetIdx(), + node->GetName().c_str(), in_data_anchor->GetIdx()); + return FAILED; + } + GELOGD("Remove data edge %s:%d->%s:%d", op_desc->GetName().c_str(), peer_data_anchor->GetIdx(), + node->GetName().c_str(), in_data_anchor->GetIdx()); + } + } + return SUCCESS; +} } // namespace ge diff --git a/src/ge/graph/passes/merge_pass.h b/src/ge/graph/passes/merge_pass.h index dd39b591..6622e00c 100644 --- a/src/ge/graph/passes/merge_pass.h +++ b/src/ge/graph/passes/merge_pass.h @@ -29,6 +29,7 @@ class MergePass : public BaseNodePass { Status ChangeIndexToConstant(NodePtr &node, int &value_index); Status CreateConstByValue(NodePtr &node, int value_index, OpDescPtr &op_desc); bool IsMergeInputNeedOptimized(NodePtr &node) const; + static Status OptimizeEmptyTensorInput(const NodePtr &node); }; } // namespace ge #endif // GE_GRAPH_PASSES_MERGE_PASS_H_ diff --git a/src/ge/graph/passes/multi_batch_clone_pass.cc b/src/ge/graph/passes/multi_batch_clone_pass.cc index c6d446af..c14a30d1 100644 --- a/src/ge/graph/passes/multi_batch_clone_pass.cc +++ b/src/ge/graph/passes/multi_batch_clone_pass.cc @@ -609,11 +609,17 @@ Status MultiBatchClonePass::CreateSubgraphs(const ComputeGraphPtr &graph, const /// Status MultiBatchClonePass::PostProcSubgraph(const ComputeGraphPtr &graph) { auto func_desc = case_node_->GetOpDesc(); + domi::ParseSubgraphFuncV2 parse_func_v2 = nullptr; auto post_func = domi::OpRegistry::Instance()->GetParseSubgraphPostFunc(func_desc->GetType()); if (post_func == nullptr) { GELOGW("The subgraph post func for node %s type %s is null.", case_node_->GetName().c_str(), case_node_->GetType().c_str()); - return FAILED; + if (domi::OpRegistry::Instance()->GetParseSubgraphPostFunc(func_desc->GetType(), parse_func_v2) != SUCCESS || + parse_func_v2 == nullptr) { + GELOGW("The subgraph new post func v2 for node %s type %s is null", case_node_->GetName().c_str(), + case_node_->GetType().c_str()); + return FAILED; + } } for (const auto &name : func_desc->GetSubgraphInstanceNames()) { @@ -628,7 +634,12 @@ Status MultiBatchClonePass::PostProcSubgraph(const ComputeGraphPtr &graph) { "Subgraph: %s get subgraph name failed.", subgraph->GetName().c_str()); auto graph = GraphUtils::CreateGraphFromComputeGraph(subgraph); - auto ret = post_func(subgraph_name, graph); + Status ret = FAILED; + if (post_func != nullptr) { + ret = post_func(subgraph_name, graph); + } else if (parse_func_v2 != nullptr) { + ret = parse_func_v2(subgraph_name.c_str(), graph); + } if (ret != SUCCESS) { GELOGE(FAILED, "Failed to post-process subgraph %s on node %s type %s", graph.GetName().c_str(), case_node_->GetName().c_str(), case_node_->GetType().c_str()); diff --git a/src/ge/graph/passes/multi_batch_pass.cc b/src/ge/graph/passes/multi_batch_pass.cc index 3638f8a0..9cc6cb96 100644 --- a/src/ge/graph/passes/multi_batch_pass.cc +++ b/src/ge/graph/passes/multi_batch_pass.cc @@ -36,7 +36,7 @@ Status MultiBatchPass::Run(ComputeGraphPtr graph) { OutDataAnchorPtr pred_value = nullptr; Status ret = FindPredValue(graph, pred_value); if (ret == NOT_CHANGED) { - GELOGI("SwitchN node not exist, graph not changed."); + GELOGD("SwitchN node not exist, graph not changed."); return SUCCESS; } if (ret != SUCCESS) { @@ -160,7 +160,7 @@ Status MultiBatchPass::FindPredValue(const ComputeGraphPtr &graph, OutDataAnchor } if (switch_n_nodes_.empty()) { - GELOGI("SwitchN node not exist."); + GELOGD("SwitchN node not exist."); return NOT_CHANGED; } diff --git a/src/ge/graph/passes/set_input_output_offset_pass.cc b/src/ge/graph/passes/set_input_output_offset_pass.cc index 58c3be85..cdc4c78f 100644 --- a/src/ge/graph/passes/set_input_output_offset_pass.cc +++ b/src/ge/graph/passes/set_input_output_offset_pass.cc @@ -128,7 +128,7 @@ Status SetInputOutputOffsetPass::SetInputOffsetForHcom(const ge::NodePtr &node, } Status SetInputOutputOffsetPass::SetInputOffset(const NodePtr &node, const vector &connect_input) { - GELOGI("Start to SetInputOffset for %s.", node->GetName().c_str()); + GELOGD("Start to SetInputOffset for %s.", node->GetName().c_str()); std::vector memory_type; auto op_desc = node->GetOpDesc(); (void)ge::AttrUtils::GetListInt(op_desc, ATTR_NAME_INPUT_MEM_TYPE_LIST, memory_type); @@ -241,7 +241,7 @@ Status SetInputOutputOffsetPass::SetOutputOffsetForHcom(const NodePtr &node, con } Status SetInputOutputOffsetPass::SetOutputOffset(const NodePtr &node, const vector &connect_output) { - GELOGI("Start SetOutputOffset of %s.", node->GetName().c_str()); + GELOGD("Start SetOutputOffset of %s.", node->GetName().c_str()); bool attr_no_task = false; bool get_attr_no_task = ge::AttrUtils::GetBool(node->GetOpDesc(), ATTR_NAME_NOTASK, attr_no_task); if (get_attr_no_task && attr_no_task) { diff --git a/src/ge/graph/preprocess/graph_preprocess.cc b/src/ge/graph/preprocess/graph_preprocess.cc index 16428442..4e9bc45a 100644 --- a/src/ge/graph/preprocess/graph_preprocess.cc +++ b/src/ge/graph/preprocess/graph_preprocess.cc @@ -117,6 +117,7 @@ #include "graph/passes/variable_op_pass.h" #include "graph/passes/variable_prepare_op_pass.h" #include "graph/passes/variable_ref_delete_op_pass.h" +#include "graph/passes/mark_agnostic_pass.h" namespace ge { namespace { @@ -129,6 +130,8 @@ const char *const kMbatchSwitchnName = "mbatch-switch-name"; // the size of user defined output datatype or format string after split by ":". const size_t kUserDefinedElementCount = 2; +const int kDataOutIndex = 0; +const int64_t kInvalidDynaimcDimsType = -1; OpDescPtr CreateTensorShape(const GeTensorDesc &data_tensor) { GeTensorPtr tensor = MakeShared(); @@ -1160,6 +1163,9 @@ Status GraphPrepare::UpdateInput(const std::vector &user_input) { return FAILED; } + if (IsDynamicDims(input_node)) { + continue; + } GeTensorDesc desc(user_input[index].GetTensorDesc()); auto format = desc.GetFormat(); auto origin_format = desc.GetOriginFormat(); @@ -1224,10 +1230,7 @@ Status GraphPrepare::UpdateInput(const std::vector &user_input) { if (!options_.train_graph_flag) { Status ret = AdjustDataOpOutput(input_node); - if (ret != SUCCESS) { - GELOGE(ret, "AdjustDataOpOutput fail, ret:%u", ret); - return ret; - } + GE_IF_BOOL_EXEC(ret != SUCCESS, GELOGE(ret, "AdjustDataOpOutput fail, ret:%u", ret); return ret); } } } @@ -1574,6 +1577,22 @@ Status GraphPrepare::VerifyConstOp(const NodePtr &node) { return SUCCESS; } +bool GraphPrepare::IsDynamicDims(const NodePtr &input_node) { + auto data_shape = NodeUtils::GetOutputDesc(*input_node, kDataOutIndex).GetShape(); + const auto &dims = data_shape.GetDims(); + bool all_is_positive = false; + if (std::all_of(dims.begin(), dims.end(), [](int64_t val) { return val >= 0; })) { + all_is_positive = true; + } + if (!all_is_positive && !options_.input_shape.empty() && !options_.dynamic_dims.empty() && + options_.dynamic_node_type != kInvalidDynaimcDimsType) { + GELOGI("No need to check and update desc info, the dims of %s is %s.", input_node->GetName().c_str(), + formats::JoinToString(dims).c_str()); + return true; + } + return false; +} + Status GraphPrepare::CheckUserInput(const std::vector &user_input) { if (GetLocalOmgContext().is_dynamic_input) { return SUCCESS; @@ -1599,6 +1618,9 @@ Status GraphPrepare::CheckUserInput(const std::vector &user_input) { GELOGE(GE_GRAPH_INIT_FAILED, "user_input size:%zu, data op index:%ld.", user_input.size(), index); return GE_GRAPH_INIT_FAILED; } + if (IsDynamicDims(input_node)) { + continue; + } GeTensorDesc desc(user_input[index].GetTensorDesc()); for (size_t i = 0; i < desc.GetShape().GetDimNum(); ++i) { @@ -1684,6 +1706,7 @@ Status GraphPrepare::PrepareOptimize() { try { (void)original_graph_passes.AddPass("PrepareOptimize::ShapeOperateOpRemovePass", new ShapeOperateOpRemovePass); (void)original_graph_passes.AddPass("PrepareOptimize::ReplaceTransShapePass", new ReplaceTransShapePass); + (void)original_graph_passes.AddPass("PrepareOptimize::MarkAgnosticPass", new MarkAgnosticPass); } catch (std::bad_alloc &e) { GELOGE(INTERNAL_ERROR, "Add pass failed, bad memory allocation occurs."); return INTERNAL_ERROR; diff --git a/src/ge/graph/preprocess/graph_preprocess.h b/src/ge/graph/preprocess/graph_preprocess.h index 7c6e4013..b3ea8214 100644 --- a/src/ge/graph/preprocess/graph_preprocess.h +++ b/src/ge/graph/preprocess/graph_preprocess.h @@ -81,6 +81,7 @@ class GraphPrepare { Status GraphEquivalentTransformation(); void TypeConversionOfConstant(); + bool IsDynamicDims(const NodePtr &input_node); ge::ComputeGraphPtr compute_graph_; GraphManagerOptions options_; diff --git a/src/ge/graph/preprocess/multi_batch_copy_graph.cc b/src/ge/graph/preprocess/multi_batch_copy_graph.cc index 2d852053..9c4f8726 100644 --- a/src/ge/graph/preprocess/multi_batch_copy_graph.cc +++ b/src/ge/graph/preprocess/multi_batch_copy_graph.cc @@ -40,6 +40,7 @@ #include "graph/utils/type_utils.h" #include "inc/pass_manager.h" #include "graph/common/local_context.h" +#include "graph/common/omg_util.h" using std::set; using std::string; @@ -49,15 +50,23 @@ namespace ge { namespace multibatch { namespace { const char *const kMbatchSwitchnName = "mbatch-switch-name"; +const char *const kGetNextName = "IteratorV2"; const int kSwitchNDataIndex = 0; const int kSwitchNPredIndex = 1; const int kDataOutIndex = 0; const int kDataInIndex = 0; const int kMergeDataOutIndex = 0; const int kStaticOutput = -1; +const int kDivisionConst = 2; inline bool IsDataLikeType(const std::string &node_type) { return (node_type == DATA) || (node_type == AIPP); } +inline bool IsGetNextType(const NodePtr &node) { + std::string original_type; + GE_IF_BOOL_EXEC(GetOriginalType(node, original_type) != SUCCESS, GELOGW("Get original type failed"); return false); + return (original_type == kGetNextName); +} + NodePtr InsertMergeNodeToGraph(const std::string &name, size_t input_num, const ComputeGraphPtr &graph) { OpDescPtr desc = MakeShared(); if (desc == nullptr) { @@ -179,29 +188,6 @@ bool IsOnlyOutputToAipp(const NodePtr &node) { } return true; } - -Status CheckDataShape(const std::vector &nodes) { - size_t unknown_shape_count = 0; - for (const auto &node : nodes) { - if (node->GetType() != DATA) { - continue; - } - for (auto dim : NodeUtils::GetOutputDesc(*node, kDataOutIndex).GetShape().GetDims()) { - if (dim < 0) { - unknown_shape_count++; - break; - } - } - } - if (unknown_shape_count == 0) { - ErrorManager::GetInstance().ATCReportErrMessage("E10040"); - GELOGE(PARAM_INVALID, - "Need unknow shape data when user set --dynamic_batch_size, --dynamic_image_size or --dynamic_dims"); - return PARAM_INVALID; - } - - return SUCCESS; -} } // namespace Status MultiBatchGraphCopyer::CopyGraph() { @@ -257,15 +243,55 @@ Status MultiBatchGraphCopyer::Init() { if (IsDataLikeType(node->GetType())) { origin_data_nodes_.emplace_back(node); } + if (!GetLocalOmgContext().dynamic_node_type.empty() && IsGetNextType(node)) { + origin_data_nodes_.emplace_back(node); + } } return SUCCESS; } -Status MultiBatchGraphCopyer::LabelStatus() { +void MultiBatchGraphCopyer::LabelStatusForData(const NodePtr &data) { + auto data_shape = NodeUtils::GetOutputDesc(*data, kDataOutIndex).GetShape(); + GELOGI("Label status for %s, shape_dims is %s.", data->GetName().c_str(), + formats::JoinToString(data_shape.GetDims()).c_str()); + if (!IsAllDimsPositive(data_shape.GetDims())) { + origin_nodes_status_[data.get()] = kNodeInBatchBranch; + } +} + +void MultiBatchGraphCopyer::LabelStatusForGetNextSink(const NodePtr &data) { + auto op_desc = data->GetOpDesc(); + GELOGI("Out count of %s is %zu.", data->GetName().c_str(), op_desc->GetOutputsSize()); + size_t data_count = op_desc->GetOutputsSize() / kDivisionConst; + for (size_t i = 0; i < data_count; ++i) { + GeTensorDesc output_desc = op_desc->GetOutputDesc(i); + GELOGD("The %zu data shape from getnext sink is %s.", i, + formats::JoinToString(output_desc.GetShape().GetDims()).c_str()); + const auto &out_data_anchor = data->GetOutDataAnchor(i); + if (out_data_anchor == nullptr) { + continue; + } + size_t reference_times = out_data_anchor->GetPeerInDataAnchors().size(); + GELOGD("The %zu data has %zu referenced times.", i, reference_times); + getnext_sink_dynamic_out_mapping_.emplace_back(std::make_pair(i, reference_times)); + if (!IsAllDimsPositive(output_desc.GetShape().GetDims())) { + getnext_sink_dynamic_dims_ = true; + } + } + + if (getnext_sink_dynamic_dims_) { + origin_nodes_status_[data.get()] = kNodeInBatchBranch; + } +} + +Status MultiBatchGraphCopyer::LabelInBatchBranchStatus() { + GELOGD("Start label in batch branch status."); for (const auto &data : origin_data_nodes_) { - auto data_shape = NodeUtils::GetOutputDesc(*data, kDataOutIndex).GetShape(); - if (!IsAllDimsPositive(data_shape.GetDims())) { - origin_nodes_status_[data.get()] = kNodeInBatchBranch; + auto op_desc = data->GetOpDesc(); + GE_IF_BOOL_EXEC(op_desc == nullptr, GELOGE(PARAM_INVALID, "Op desc is nullptr."); return PARAM_INVALID); + LabelStatusForData(data); + if (!GetLocalOmgContext().dynamic_node_type.empty()) { + LabelStatusForGetNextSink(data); } } bool changed = true; @@ -288,6 +314,14 @@ Status MultiBatchGraphCopyer::LabelStatus() { } } } + return SUCCESS; +} + +Status MultiBatchGraphCopyer::LabelStatus() { + if (LabelInBatchBranchStatus() != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to label no in batch branch"); + return PARAM_INVALID; + } for (const auto &node : origin_all_nodes_) { if (!(node->GetOpDesc()->GetSubgraphInstanceNames().empty())) { @@ -298,13 +332,24 @@ Status MultiBatchGraphCopyer::LabelStatus() { origin_nodes_status_[node.get()] = kNodeOutBatchBranch; continue; } - if (IsDataLikeType(node->GetType())) { - if (IsOnlyOutputToAipp(node)) { - origin_nodes_status_[node.get()] = kNodeOutBatchBranch; - } else { + if (GetLocalOmgContext().dynamic_node_type.empty()) { + if (IsDataLikeType(node->GetType())) { + if (IsOnlyOutputToAipp(node)) { + origin_nodes_status_[node.get()] = kNodeOutBatchBranch; + } else { + origin_nodes_status_[node.get()] = kNodeStartNode; + } + continue; + } + } else { + if (IsDataLikeType(node->GetType())) { origin_nodes_status_[node.get()] = kNodeStartNode; + continue; + } + if (IsGetNextType(node)) { + origin_nodes_status_[node.get()] = kNodeStartNode; + continue; } - continue; } if (origin_nodes_status_.find(node.get()) == origin_nodes_status_.end()) { origin_nodes_status_[node.get()] = kNodeOutBatchBranch; @@ -317,49 +362,52 @@ Status MultiBatchGraphCopyer::CheckAndParseDynamicData() { size_t unknown_shape_count = 0; auto data_name_and_shape = GetLocalOmgContext().user_input_dims; GELOGD("raw data_name_and_shape size: %zu", data_name_and_shape.size()); - for (const auto &node : origin_all_nodes_) { - auto data_desc = NodeUtils::GetOutputDesc(*node, kDataOutIndex); - auto data_shape = data_desc.GetShape(); - auto data_format = data_desc.GetFormat() == Format::FORMAT_NCHW - ? "NCHW" - : data_desc.GetFormat() == Format::FORMAT_NHWC ? "NHWC" : "Others"; + if (!getnext_sink_dynamic_dims_) { + for (const auto &node : origin_all_nodes_) { + auto data_desc = NodeUtils::GetOutputDesc(*node, kDataOutIndex); + auto data_shape = data_desc.GetShape(); + auto data_format = data_desc.GetFormat() == Format::FORMAT_NCHW + ? "NCHW" + : data_desc.GetFormat() == Format::FORMAT_NHWC ? "NHWC" : "Others"; + auto data_name = node->GetName(); + auto branch_status = GetNodeStatus(node); + if (branch_status != kNodeStartNode) { + continue; + } + GELOGI("CheckAndParseDynamicData shape_dims is %s.", formats::JoinToString(data_shape.GetDims()).c_str()); + if (IsAllDimsPositive(data_shape.GetDims())) { + continue; + } - auto data_name = node->GetName(); - auto branch_status = GetNodeStatus(node); - if (branch_status != kNodeStartNode) { - continue; - } - if (IsAllDimsPositive(data_shape.GetDims())) { - continue; - } - ++unknown_shape_count; - auto iter = find(data_name_order_.begin(), data_name_order_.end(), data_name); - if (iter == data_name_order_.end()) { - if (dynamic_type_ == DynamicType::kDynamicBatch) { - auto ret = CheckDynamicBatchShape(data_shape.GetDims(), data_name); - if (!ret) { - return PARAM_INVALID; + std::vector data_shape_dims = data_shape.GetDims(); + ++unknown_shape_count; + auto iter = find(data_name_order_.begin(), data_name_order_.end(), data_name); + if (iter == data_name_order_.end()) { + if (dynamic_type_ == DynamicType::kDynamicBatch) { + auto ret = CheckDynamicBatchShape(data_shape_dims, data_name); + GE_IF_BOOL_EXEC(ret == false, + GELOGE(PARAM_INVALID, "Failed to check dynamic batch shape of %s.", data_name.c_str()); + return PARAM_INVALID); + } else if (dynamic_type_ == DynamicType::kDynamicImageSize) { + auto ret = CheckDynamicImageSizeShape(data_shape_dims, data_name, data_format); + GE_IF_BOOL_EXEC(ret == false, + GELOGE(PARAM_INVALID, "Failed to check dynamic image size shape of %s.", data_name.c_str()); + return PARAM_INVALID); + } else if (dynamic_type_ == DynamicType::kDynamicDims) { + ErrorManager::GetInstance().ATCReportErrMessage( + "E10001", {"parameter", "reason"}, {"--input_shape", "all dynamic data must be set in --input_shape"}); + GELOGE(INTERNAL_ERROR, "data: %s shape:%s must be set int --input_shape", node->GetName().c_str(), + data_shape.ToString().c_str()); + return INTERNAL_ERROR; } - } else if (dynamic_type_ == DynamicType::kDynamicImageSize) { - auto ret = CheckDynamicImageSizeShape(data_shape.GetDims(), data_name, data_format); - if (!ret) { - return PARAM_INVALID; - } - } else if (dynamic_type_ == DynamicType::kDynamicDims) { - ErrorManager::GetInstance().ATCReportErrMessage( - "E10001", {"parameter", "reason"}, {"--input_shape", "all dynamic data must be set in --input_shape"}); - GELOGE(INTERNAL_ERROR, "data: %s shape:%s must be set int --input_shape", node->GetName().c_str(), - data_shape.ToString().c_str()); - return INTERNAL_ERROR; + GELOGI("Data shape of %s is %s", data_name.c_str(), formats::JoinToString(data_shape_dims).c_str()); + data_name_and_shape.emplace_back(data_name, data_shape_dims); } - data_name_and_shape.emplace_back(data_name, data_shape.GetDims()); } } auto ret = ParserDataToDynmaicInfo(shapes_, data_name_and_shape, data_to_dynamic_info_); - if (ret != SUCCESS) { - return ret; - } - if (unknown_shape_count == 0) { + GE_CHK_STATUS_RET(ret, "Failed to parse data to dynamic info."); + if (!getnext_sink_dynamic_dims_ && unknown_shape_count == 0) { ErrorManager::GetInstance().ATCReportErrMessage("E10040"); GELOGE(PARAM_INVALID, "Need unknow shape data when user set --dynamic_batch_size, --dynamic_image_size or --dynamic_dims"); @@ -369,13 +417,17 @@ Status MultiBatchGraphCopyer::CheckAndParseDynamicData() { } Status MultiBatchGraphCopyer::CreateNewNodes() { - shape_data_ = InsertShapeDataNode(); - if (shape_data_ == nullptr) { - GELOGE(INTERNAL_ERROR, "Failed to create the shape data node for muti-batch"); - return INTERNAL_ERROR; + if (!getnext_sink_dynamic_dims_) { + shape_data_ = InsertShapeDataNode(); + } else { + shape_data_ = InsertGetDynamicDimsNode(); } + GE_IF_BOOL_EXEC(shape_data_ == nullptr, GELOGE(INTERNAL_ERROR, "Failed to create the shape node for multi batch"); + return INTERNAL_ERROR); + GE_CHECK_NOTNULL(shape_data_->GetOpDesc()); for (const auto &node : origin_all_nodes_) { + GE_CHECK_NOTNULL(node->GetOpDesc()); auto node_type = node->GetType(); Status ret = INTERNAL_ERROR; auto branch_status = GetNodeStatus(node); @@ -383,10 +435,7 @@ Status MultiBatchGraphCopyer::CreateNewNodes() { switch (branch_status) { case kNodeStartNode: GELOGD("Name: %s, type: %s, status: kNodeStartNode.", node->GetName().c_str(), node->GetType().c_str()); - ret = InsertSwitchNForData(node); - if (ret == SUCCESS) { - ret = UpdateMaxShapeToData(node); - } + ret = InsertSwitchNAndUpdateMaxShape(node); break; case kNodeInBatchBranch: GELOGD("Name: %s, type: %s, status: kNodeInBatchBranch.", node->GetName().c_str(), node->GetType().c_str()); @@ -395,6 +444,9 @@ Status MultiBatchGraphCopyer::CreateNewNodes() { case kNodeOutBatchBranch: GELOGD("Name: %s, type: %s, status: kNodeOutBatchBranch.", node->GetName().c_str(), node->GetType().c_str()); ret = InsertMergeForEdgeNode(node); + if (ret == SUCCESS) { + ret = LinkGetDynamicDimsToNetOutput(node); + } break; case kNodeNotSupportNode: GELOGD("Name: %s, type: %s, status: kNodeNotSupportNode.", node->GetName().c_str(), node->GetType().c_str()); @@ -441,7 +493,58 @@ NodePtr MultiBatchGraphCopyer::InsertMergeNode(const NodePtr &node, int index) { GELOGI("Create merge node %s for node %s index %d", merge_node_name.c_str(), node->GetName().c_str(), index); return merge_node; } + +NodePtr MultiBatchGraphCopyer::FindSwitchnNodeForDataEdge(const OutDataAnchorPtr &data_out_anchor, + const NodePtr &origin_node) { + auto data_node = data_out_anchor->GetOwnerNode(); + GELOGD("Start find switchn node insert between %s and %s", data_node->GetName().c_str(), + origin_node->GetName().c_str()); + NodePtr switchn = nullptr; + if (!getnext_sink_dynamic_dims_ && data_nodes_to_switchn_.count(data_node.get()) > 0) { + switchn = data_nodes_to_switchn_[data_node.get()]; + return switchn; + } + bool is_getnext_sink_data = false; + for (size_t i = 0; i < getnext_nodes_to_switchn_.size(); ++i) { + for (size_t j = 0; j < getnext_nodes_to_switchn_.at(i).size(); ++j) { + if (getnext_nodes_to_switchn_.at(i).at(j).first == data_node.get()) { + is_getnext_sink_data = true; + break; + } + } + } + // get output_idx of origin_node(getnext) + if (is_getnext_sink_data) { + auto output_idx = data_out_anchor->GetIdx(); + size_t referenced_index = 0; + GELOGI("The output idx %zu has %zu referenced nums.", output_idx, data_out_anchor->GetPeerInDataAnchors().size()); + for (const auto &peer_in_anchor : data_out_anchor->GetPeerInDataAnchors()) { + if (peer_in_anchor->GetOwnerNode()->GetOpDesc() == nullptr) { + GELOGE(INTERNAL_ERROR, "Op desc should not be nullptr."); + return nullptr; + } + if (getnext_nodes_to_switchn_.at(output_idx).empty()) { + GELOGI("Output idx %zu of %s is static output.", output_idx, data_node->GetName().c_str()); + return nullptr; + } + if (output_idx >= static_cast(getnext_nodes_to_switchn_.size()) || + referenced_index >= getnext_nodes_to_switchn_.at(output_idx).size()) { + GELOGE(INTERNAL_ERROR, "Output idx is %zu, referenced index is %zu", output_idx, referenced_index); + return nullptr; + } + if (peer_in_anchor->GetOwnerNode()->GetOpDesc()->GetName() == origin_node->GetName()) { + switchn = getnext_nodes_to_switchn_.at(output_idx).at(referenced_index).second; + GELOGI("Name of switchn is %s.", switchn->GetName().c_str()); + return switchn; + } + referenced_index++; + } + } + return switchn; +} + Status MultiBatchGraphCopyer::CopyInDataEdges(const NodePtr &origin_node, int batch_num, const NodePtr ©ed_node) { + GELOGI("Start copy data edges for %s and %s.", origin_node->GetName().c_str(), copyed_node->GetName().c_str()); for (auto &in_anchor : origin_node->GetAllInDataAnchors()) { auto origin_src_anchor = in_anchor->GetPeerOutAnchor(); if (origin_src_anchor == nullptr) { @@ -451,16 +554,15 @@ Status MultiBatchGraphCopyer::CopyInDataEdges(const NodePtr &origin_node, int ba auto origin_src_node = origin_src_anchor->GetOwnerNode(); auto dst_anchor = copyed_node->GetInDataAnchor(in_anchor->GetIdx()); GE_CHECK_NOTNULL(dst_anchor); - auto switchn_iter = data_nodes_to_switchn_.find(origin_src_node.get()); - if (switchn_iter != data_nodes_to_switchn_.end()) { - auto ret = GraphUtils::AddEdge(switchn_iter->second->GetOutDataAnchor(batch_num), dst_anchor); + auto switchn = FindSwitchnNodeForDataEdge(origin_src_anchor, origin_node); + if (switchn != nullptr) { + auto ret = GraphUtils::AddEdge(switchn->GetOutDataAnchor(batch_num), dst_anchor); if (ret != GRAPH_SUCCESS) { GELOGE(INTERNAL_ERROR, "Failed to add data edge between %s(%d) to %s(%d), error-code %u", - switchn_iter->second->GetName().c_str(), batch_num, copyed_node->GetName().c_str(), in_anchor->GetIdx(), - ret); + switchn->GetName().c_str(), batch_num, copyed_node->GetName().c_str(), in_anchor->GetIdx(), ret); return INTERNAL_ERROR; } - GELOGD("Add data edge from %s(%d) to %s(%d)", switchn_iter->second->GetName().c_str(), batch_num, + GELOGD("Add data edge from %s(%d) to %s(%d)", switchn->GetName().c_str(), batch_num, copyed_node->GetName().c_str(), in_anchor->GetIdx()); continue; } @@ -491,7 +593,9 @@ Status MultiBatchGraphCopyer::CopyInDataEdges(const NodePtr &origin_node, int ba } return SUCCESS; } + Status MultiBatchGraphCopyer::CopyInControlEdges(const NodePtr &node, int batch_num, const NodePtr ©ed_node) { + GELOGI("Start copy control edge for %s and %s.", node->GetName().c_str(), copyed_node->GetName().c_str()); for (auto &origin_src_node : node->GetInControlNodes()) { auto switchn_iter = data_nodes_to_switchn_.find(origin_src_node.get()); if (switchn_iter != data_nodes_to_switchn_.end()) { @@ -531,6 +635,7 @@ Status MultiBatchGraphCopyer::CopyInControlEdges(const NodePtr &node, int batch_ } return SUCCESS; } + NodePtr MultiBatchGraphCopyer::InsertShapeDataNode() { auto desc = MakeShared(); if (desc == nullptr) { @@ -544,11 +649,8 @@ NodePtr MultiBatchGraphCopyer::InsertShapeDataNode() { } desc->SetName(node_name); desc->SetType(DATA); - - GeTensorDesc tensor_desc; - tensor_desc.SetFormat(FORMAT_ND); - tensor_desc.SetShape(GeShape({static_cast(shapes_.at(0).size())})); - tensor_desc.SetDataType(DT_INT64); + // input and output of DATA is gear_info + GeTensorDesc tensor_desc(GeShape({static_cast(shapes_.at(0).size())}), FORMAT_ND, DT_INT64); auto ret = desc->AddInputDesc(tensor_desc); if (ret != GRAPH_SUCCESS) { GELOGE(INTERNAL_ERROR, "Failed to add input desc for created data"); @@ -578,6 +680,66 @@ NodePtr MultiBatchGraphCopyer::InsertShapeDataNode() { return data_node; } + +NodePtr MultiBatchGraphCopyer::InsertGetDynamicDimsNode() { + GELOGD("Start insert getdynamicdims node to get shape info."); + auto desc = MakeShared(); + if (desc == nullptr) { + GELOGE(OUT_OF_MEMORY, "Failed to create shape data node, out of memory"); + return nullptr; + } + string node_name = "ascend_mbatch_get_dynamic_dims_node"; + + // Only flush subgraph name + if (graph_->GetParentGraph() != nullptr) { + node_name = graph_->GetName() + "_" + node_name; + } + + desc->SetName(node_name); + desc->SetType(GETDYNAMICDIMS); + + // input of GetDynamicDims is shape_of_each_data, output is gear_info + for (size_t i = 0; i < GetLocalOmgContext().user_input_dims.size(); ++i) { + size_t input_shape_dims = GetLocalOmgContext().user_input_dims.at(i).second.size(); + if (input_shape_dims == 1 && GetLocalOmgContext().user_input_dims.at(i).second.at(0) == 0) { + GeTensorDesc tensor_desc; + tensor_desc.SetFormat(FORMAT_ND); + tensor_desc.SetDataType(DT_INT64); + auto ret = desc->AddInputDesc(tensor_desc); + GE_IF_BOOL_EXEC(ret != GRAPH_SUCCESS, GELOGE(INTERNAL_ERROR, "Failed to add input desc for created data"); + return nullptr); + continue; + } + GeTensorDesc tensor_desc(GeShape({static_cast(input_shape_dims)}), FORMAT_ND, DT_INT64); + auto ret = desc->AddInputDesc(tensor_desc); + GE_IF_BOOL_EXEC(ret != GRAPH_SUCCESS, GELOGE(INTERNAL_ERROR, "Failed to add input desc for created data"); + return nullptr); + } + + GeTensorDesc tensor_desc(GeShape({static_cast(shapes_.at(0).size())}), FORMAT_ND, DT_INT64); + auto ret = desc->AddOutputDesc(tensor_desc); + GE_IF_BOOL_EXEC(ret != GRAPH_SUCCESS, GELOGE(INTERNAL_ERROR, "Failed to add output desc for created data"); + return nullptr); + + if (!AttrUtils::SetBool(desc, ATTR_INSERT_BY_MBATCH, true)) { + GELOGE(INTERNAL_ERROR, "Failed to add attr for created data"); + return nullptr; + } + + auto data_node = graph_->AddNode(desc); + if (data_node == nullptr) { + GELOGE(INTERNAL_ERROR, "Failed to add shape data node to graph"); + return nullptr; + } + ret = GraphUtils::AppendInputNode(graph_, data_node); + if (ret != GRAPH_SUCCESS) { + GELOGE(INTERNAL_ERROR, "Failed to append data node %s as input to graph", data_node->GetName().c_str()); + return nullptr; + } + + return data_node; +} + Status MultiBatchGraphCopyer::CheckArguments() { if (graph_ == nullptr) { GELOGE(PARAM_INVALID, "Failed to copy graph, the graph is null"); @@ -586,6 +748,7 @@ Status MultiBatchGraphCopyer::CheckArguments() { return CheckDynamicParams(shapes_); } + Status MultiBatchGraphCopyer::CheckCopyResult(const std::vector &start_nodes) { for (auto &node : start_nodes) { if (IsOnlyOutputToAipp(node)) { @@ -602,12 +765,24 @@ Status MultiBatchGraphCopyer::CheckCopyResult(const std::vector &start_ } return SUCCESS; } + bool MultiBatchGraphCopyer::IsInBatchBranch(const NodePtr &node) { - return (nodes_to_batch_nodes_.count(node.get()) > 0) || (data_nodes_to_switchn_.count(node.get()) > 0); + if (!getnext_sink_dynamic_dims_) { + return (nodes_to_batch_nodes_.count(node.get()) > 0) || (data_nodes_to_switchn_.count(node.get()) > 0); + } else { + for (size_t i = 0; i < getnext_nodes_to_switchn_.size(); ++i) { + for (size_t j = 0; j < getnext_nodes_to_switchn_.at(i).size(); ++j) { + if (getnext_nodes_to_switchn_.at(i).at(j).first == node.get()) { + return true; + } + } + } + return nodes_to_batch_nodes_.count(node.get()) > 0; + } } -Status MultiBatchGraphCopyer::LinkDataToMerge(const NodePtr &data, const NodePtr &merge) { + +Status MultiBatchGraphCopyer::LinkDataToMerge(const NodePtr &data, const NodePtr &merge, const NodePtr &switchn) { // The caller should make sure that the there is a SwitchN node in the map - auto &switchn = data_nodes_to_switchn_[data.get()]; GELOGI("Link edge between data %s to merge %s throw switchn %s", data->GetName().c_str(), merge->GetName().c_str(), switchn->GetName().c_str()); for (size_t i = 0; i < shapes_.size(); ++i) { @@ -619,6 +794,7 @@ Status MultiBatchGraphCopyer::LinkDataToMerge(const NodePtr &data, const NodePtr } return SUCCESS; } + Status MultiBatchGraphCopyer::LinkNodeToMerge(const NodePtr &node, int out_index, const NodePtr &merge) { auto ©ed_nodes = nodes_to_batch_nodes_[node.get()]; if (copyed_nodes.size() != shapes_.size()) { @@ -659,12 +835,84 @@ Status MultiBatchGraphCopyer::LinkNodeToMerge(const NodePtr &node, int out_index } return SUCCESS; } -Status MultiBatchGraphCopyer::UpdateMaxShapeToData(const NodePtr &data) { - auto data_shape = NodeUtils::GetOutputDesc(*data, kDataOutIndex).GetShape(); - auto data_name = data->GetName(); - if (IsAllDimsPositive(data_shape.GetDims())) { - return SUCCESS; + +Status MultiBatchGraphCopyer::InsertSwitchNAndUpdateMaxShape(const NodePtr &node) { + std::vector> dynamic_out_to_switchn; + if (!getnext_sink_dynamic_dims_) { + if (InsertSwitchNForData(node, kDataOutIndex, kDataOutIndex, dynamic_out_to_switchn) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to insert switchn for %s.", node->GetName().c_str()); + return PARAM_INVALID; + } + if (UpdateMaxShapeToData(node, kDataOutIndex) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to update max shape of %s.", node->GetName().c_str()); + return PARAM_INVALID; + } + } else { + if (!IsGetNextType(node)) { + GELOGI("No need to insert switchn and update max shape for %s when get sink dynamic.", node->GetName().c_str()); + return SUCCESS; + } + for (size_t i = 0; i < getnext_sink_dynamic_out_mapping_.size(); ++i) { + dynamic_out_to_switchn.clear(); + for (size_t j = 0; j < getnext_sink_dynamic_out_mapping_.at(i).second; ++j) { + GELOGI("The %zu data_index has %zu referenced nums.", getnext_sink_dynamic_out_mapping_.at(i).first, + getnext_sink_dynamic_out_mapping_.at(i).second); + if (InsertSwitchNForData(node, getnext_sink_dynamic_out_mapping_.at(i).first, j, dynamic_out_to_switchn) != + SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to insert switchn for %s of %zu out anchor when referenced index is %zu", + node->GetName().c_str(), getnext_sink_dynamic_out_mapping_.at(i).first, j); + return PARAM_INVALID; + } + } + getnext_nodes_to_switchn_.emplace_back(dynamic_out_to_switchn); + } + + for (size_t i = 0; i < getnext_sink_dynamic_out_mapping_.size(); ++i) { + if (UpdateMaxShapeToData(node, i) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to update max shape of %zu out anchor", node->GetName().c_str(), i); + return PARAM_INVALID; + } + } } + return SUCCESS; +} + +Status MultiBatchGraphCopyer::UpdateShapeOfShapeNode(const NodePtr &node, size_t out_anchor_index) { + auto data_shape = NodeUtils::GetOutputDesc(*node, out_anchor_index).GetShape(); + size_t shape_index = out_anchor_index + (node->GetAllOutDataAnchors().size() / kDivisionConst); + GeTensorDesc output_desc = node->GetOpDesc()->GetOutputDesc(shape_index); + std::vector output_dims = {static_cast(data_shape.GetDims().size())}; + GeShape output_shape(output_dims); + output_desc.SetShape(output_shape); + if (node->GetOpDesc()->UpdateOutputDesc(shape_index, output_desc) != SUCCESS) { + GELOGE(FAILED, "Update output desc fail."); + return FAILED; + } + return SUCCESS; +} + +Status MultiBatchGraphCopyer::UpdateMaxShapeToData(const NodePtr &node, size_t out_anchor_index) { + GELOGD("Start update max shape of %s, %zu output.", node->GetName().c_str(), out_anchor_index); + auto data_shape = NodeUtils::GetOutputDesc(*node, out_anchor_index).GetShape(); + string data_name = node->GetName(); + if (getnext_sink_dynamic_dims_) { + data_name.append("_").append(std::to_string(out_anchor_index)); + } + GELOGD("Update max shape of %s, shape dims is %s.", data_name.c_str(), + formats::JoinToString(data_shape.GetDims()).c_str()); + if (!getnext_sink_dynamic_dims_) { + if (IsAllDimsPositive(data_shape.GetDims())) { + GELOGD("No need to do anything for static data."); + return SUCCESS; + } + } else { + if (IsAllDimsPositive(data_shape.GetDims())) { + // need to update shape of Shape_node + GE_CHK_STATUS_RET(UpdateShapeOfShapeNode(node, out_anchor_index), "Failed to update shape of shape node"); + return SUCCESS; + } + } + size_t max_shape_index = 0; int64_t max_size = 0; for (size_t i = 0; i < shapes_.size(); ++i) { @@ -684,53 +932,70 @@ Status MultiBatchGraphCopyer::UpdateMaxShapeToData(const NodePtr &data) { } // must not be error, the calc result has been checked in function InsertSwitchNForData (void)CalcShape(data_to_dynamic_info_.at(data_name).at(max_shape_index), data_shape); - auto ret = NodeUtils::UpdateOutputShape(*data, kDataOutIndex, data_shape); - if (ret != GRAPH_SUCCESS) { - GELOGE(INTERNAL_ERROR, "Failed to update output shape for data %s", data->GetName().c_str()); - return INTERNAL_ERROR; - } - ret = NodeUtils::UpdateInputShape(*data, kDataInIndex, data_shape); - if (ret != GRAPH_SUCCESS) { - GELOGE(INTERNAL_ERROR, "Failed to update input shape for data %s", data->GetName().c_str()); - return INTERNAL_ERROR; - } - GELOGI("Update the data %s input/output shape to the max %s", data->GetName().c_str(), + auto ret = NodeUtils::UpdateOutputShape(*node, out_anchor_index, data_shape); + GE_CHK_STATUS_RET(ret, "Failed to update output shape for data %s", node->GetName().c_str()); + // getnext_sink not has input + if (!getnext_sink_dynamic_dims_) { + ret = NodeUtils::UpdateInputShape(*node, kDataInIndex, data_shape); + GE_CHK_STATUS_RET(ret, "Failed to update input shape for data %s", node->GetName().c_str()); + } else { + // need to update shape of Shape_node when getnext_sink_dynamic + GE_CHK_STATUS_RET(UpdateShapeOfShapeNode(node, out_anchor_index), "Failed to update shape of shape node"); + } + GELOGI("Update the data %s input/output shape to the max %s", node->GetName().c_str(), formats::ShapeToString(data_shape).c_str()); return SUCCESS; } -Status MultiBatchGraphCopyer::InsertSwitchNForData(const NodePtr &data) { - auto data_shape = NodeUtils::GetOutputDesc(*data, kDataOutIndex).GetShape(); - auto data_name = data->GetName(); - (void)AttrUtils::SetListInt(data->GetOpDesc(), ATTR_MBATCH_ORIGIN_INPUT_DIMS, data_shape.GetDims()); + +Status MultiBatchGraphCopyer::InsertSwitchNForData(const NodePtr &node, const size_t &out_anchor_index, + const size_t &peer_in_anchor_index, + std::vector> &dynamic_out_to_switchn) { + auto data_shape = NodeUtils::GetOutputDesc(*node, out_anchor_index).GetShape(); + string data_name = node->GetName(); + if (getnext_sink_dynamic_dims_) { + data_name.append("_").append(std::to_string(out_anchor_index)); + } + (void)AttrUtils::SetListInt(node->GetOpDesc(), ATTR_MBATCH_ORIGIN_INPUT_DIMS, data_shape.GetDims()); + GELOGI("Insert switchn node of %s, shape dims is %s.", data_name.c_str(), + formats::JoinToString(data_shape.GetDims()).c_str()); if (IsAllDimsPositive(data_shape.GetDims())) { - GELOGI("The shape of data %s are positive(%s), skip the multi batch process", data->GetName().c_str(), + GELOGI("The shape of data %s are positive(%s), skip the multi batch process", node->GetName().c_str(), data_shape.ToString().c_str()); return SUCCESS; } auto switchn_desc = MakeShared(); - if (switchn_desc == nullptr) { - GELOGE(OUT_OF_MEMORY, "Failed to create switchn for data %s", data->GetName().c_str()); - return OUT_OF_MEMORY; - } - switchn_desc->SetName(data->GetName() + "_ascend_mbatch_switchn"); + GE_IF_BOOL_EXEC(switchn_desc == nullptr, + GELOGE(OUT_OF_MEMORY, "Failed to create switchn for data %s", node->GetName().c_str()); + return OUT_OF_MEMORY); + string switchn_name = node->GetName() + "_ascend_mbatch_switchn"; + if (getnext_sink_dynamic_dims_) { + switchn_name.append("_") + .append(std::to_string(out_anchor_index)) + .append("_") + .append(std::to_string(peer_in_anchor_index)); + } + GELOGI("name of switchn is %s.", switchn_name.c_str()); + switchn_desc->SetName(switchn_name); switchn_desc->SetType(SWITCHN); - GeTensorDesc tensor(NodeUtils::GetOutputDesc(*data, kDataOutIndex)); - if (switchn_desc->AddInputDesc("data", tensor) != GRAPH_SUCCESS) { // data - return OUT_OF_MEMORY; - } + GeTensorDesc tensor(NodeUtils::GetOutputDesc(*node, out_anchor_index)); + GE_IF_BOOL_EXEC(switchn_desc->AddInputDesc("data", tensor) != GRAPH_SUCCESS, + GELOGE(OUT_OF_MEMORY, "Failed to add input tensor desc for %s", switchn_desc->GetName().c_str()); + return OUT_OF_MEMORY); GeTensorDesc pred_tensor; - if (switchn_desc->AddInputDesc("pred_value", pred_tensor) != GRAPH_SUCCESS) { // pred - return OUT_OF_MEMORY; - } + GE_IF_BOOL_EXEC(switchn_desc->AddInputDesc("pred_value", pred_tensor) != GRAPH_SUCCESS, + GELOGE(OUT_OF_MEMORY, "Failed to add input pred tensor desc for %s", switchn_desc->GetName().c_str()); + return OUT_OF_MEMORY); std::vector input_dims_str; for (size_t i = 0; i < shapes_.size(); ++i) { + GELOGI("Start clac shape for data %s, batch shape is %s.", data_name.c_str(), + formats::JoinToString(data_to_dynamic_info_.at(data_name).at(i)).c_str()); auto shape = data_shape; auto ret = CalcShape(data_to_dynamic_info_.at(data_name).at(i), shape); if (ret != SUCCESS) { GELOGE(ret, "Failed to calculate the batched shape for data node %s, the shapes may not match", - data->GetName().c_str()); + node->GetName().c_str()); return ret; } tensor.SetShape(shape); @@ -738,7 +1003,7 @@ Status MultiBatchGraphCopyer::InsertSwitchNForData(const NodePtr &data) { int64_t tensor_size = 0; (void)TensorUtils::GetTensorSizeInBytes(tensor, tensor_size); input_str = TypeUtils::FormatToSerialString(tensor.GetFormat()) + ":" + - TypeUtils::DataTypeToSerialString(tensor.GetDataType()) + ":" + data->GetName() + ":" + + TypeUtils::DataTypeToSerialString(tensor.GetDataType()) + ":" + node->GetName() + ":" + std::to_string(tensor_size) + ":" + std::to_string(tensor.GetShape().GetDimNum()) + ":" + formats::JoinToString(tensor.GetShape().GetDims()); input_dims_str.emplace_back(input_str); @@ -751,9 +1016,9 @@ Status MultiBatchGraphCopyer::InsertSwitchNForData(const NodePtr &data) { GELOGE(GRAPH_FAILED, "Opdesc AddOutputDesc failed"); return GRAPH_FAILED; } - GELOGD("The SwitchN %s output index %zu, shape %s", switchn_desc->GetName().c_str(), i, shape.ToString().c_str()); + GELOGD("The switchn %s output index %zu, shape %s", switchn_desc->GetName().c_str(), i, shape.ToString().c_str()); } - (void)AttrUtils::SetListStr(data->GetOpDesc(), "_all_origin_gears_inputs", input_dims_str); + (void)AttrUtils::SetListStr(node->GetOpDesc(), "_all_origin_gears_inputs", input_dims_str); if (!AttrUtils::SetListStr(switchn_desc, ATTR_USER_DESIGNEATE_SHAPE_ORDER, data_name_order_)) { GELOGE(INTERNAL_ERROR, "Failed to add user designate shape order attr on switchn node %s", switchn_desc->GetName().c_str()); @@ -763,8 +1028,8 @@ Status MultiBatchGraphCopyer::InsertSwitchNForData(const NodePtr &data) { GELOGE(INTERNAL_ERROR, "Failed to add insert attr on switchn node %s", switchn_desc->GetName().c_str()); return INTERNAL_ERROR; } - if (!AttrUtils::SetStr(data->GetOpDesc(), kMbatchSwitchnName, switchn_desc->GetName())) { - GELOGE(INTERNAL_ERROR, "Failed to add switchn attr on data node %s", data->GetName().c_str()); + if (!AttrUtils::SetStr(node->GetOpDesc(), kMbatchSwitchnName, switchn_desc->GetName())) { + GELOGE(INTERNAL_ERROR, "Failed to add switchn attr on data node %s", node->GetName().c_str()); return INTERNAL_ERROR; } if (StampDynamicType(switchn_desc) != SUCCESS) { @@ -773,13 +1038,18 @@ Status MultiBatchGraphCopyer::InsertSwitchNForData(const NodePtr &data) { } auto switchn = graph_->AddNode(switchn_desc); - if (switchn == nullptr) { - GELOGE(OUT_OF_MEMORY, "Failed to create switchn %s from desc", switchn_desc->GetName().c_str()); - return OUT_OF_MEMORY; + GE_IF_BOOL_EXEC(switchn == nullptr, + GELOGE(OUT_OF_MEMORY, "Failed to create switchn %s from desc", switchn_desc->GetName().c_str()); + return OUT_OF_MEMORY); + if (!getnext_sink_dynamic_dims_) { + data_nodes_to_switchn_[node.get()] = switchn; + } else { + dynamic_out_to_switchn.emplace_back(std::make_pair(node.get(), switchn)); + GELOGD("Insert %s for %s.", switchn->GetName().c_str(), node->GetName().c_str()); } - data_nodes_to_switchn_[data.get()] = switchn; return SUCCESS; } + Status MultiBatchGraphCopyer::InsertMergeForEdgeNode(const NodePtr &node) { for (auto &in_data_anchor : node->GetAllInDataAnchors()) { auto src_out_anchor = in_data_anchor->GetPeerOutAnchor(); @@ -809,6 +1079,35 @@ Status MultiBatchGraphCopyer::InsertMergeForEdgeNode(const NodePtr &node) { return SUCCESS; } + +Status MultiBatchGraphCopyer::LinkGetDynamicDimsToNetOutput(const NodePtr &node) { + if (node->GetType() == NETOUTPUT) { + if (!GetLocalOmgContext().dynamic_node_type.empty()) { + if (!AttrUtils::SetStr(node->GetOpDesc(), ATTR_ALL_GEARS_INFO, GetLocalOmgContext().dynamic_dims)) { + GELOGE(INTERNAL_ERROR, "Failed to set all gears info attr on netoutput %s.", node->GetName().c_str()); + return INTERNAL_ERROR; + } + } + if (getnext_sink_dynamic_dims_) { + size_t input_index = node->GetAllInDataAnchors().size(); + if (NodeUtils::AppendInputAnchor(node, input_index + 1) != GRAPH_SUCCESS) { + GELOGE(INTERNAL_ERROR, "Append input anchor of %s of %zu failed.", node->GetName().c_str(), input_index); + return INTERNAL_ERROR; + } + auto ret = + ge::GraphUtils::AddEdge(shape_data_->GetOutDataAnchor(kDataOutIndex), node->GetInDataAnchor(input_index)); + GE_IF_BOOL_EXEC(ret != GRAPH_SUCCESS, GELOGE(INTERNAL_ERROR, "Failed to link netoutput %s to getdynamicdims %s", + node->GetName().c_str(), shape_data_->GetName().c_str()); + return INTERNAL_ERROR); + if (!AttrUtils::SetBool(node->GetOpDesc(), ATTR_GETNEXT_SINK_DYNMAIC, true)) { + GELOGE(INTERNAL_ERROR, "Failed to set getnext sink dynamic attr on netoutput %s.", node->GetName().c_str()); + return INTERNAL_ERROR; + } + } + } + return SUCCESS; +} + Status MultiBatchGraphCopyer::CopyNodeInBatchBranch(const NodePtr &node) { auto ©ed_nodes = nodes_to_batch_nodes_[node.get()]; for (size_t i = 0; i < shapes_.size(); ++i) { @@ -823,20 +1122,81 @@ Status MultiBatchGraphCopyer::CopyNodeInBatchBranch(const NodePtr &node) { } return SUCCESS; } + +Status MultiBatchGraphCopyer::AddAttrForGetDynamicDims(const NodePtr &node) { + GELOGD("Add attr for :%s, type is %s:", shape_data_->GetName().c_str(), shape_data_->GetType().c_str()); + size_t data_count = node->GetAllOutDataAnchors().size() / kDivisionConst; + if (!AttrUtils::SetInt(shape_data_->GetOpDesc(), ATTR_GETNEXT_SINK_DATA_COUNT, data_count)) { + GELOGE(INTERNAL_ERROR, "set ATTR_GETNEXT_SINK_DATA_COUNT failed"); + return INTERNAL_ERROR; + } + vector shape_info; + for (size_t i = 0; i < GetLocalOmgContext().user_input_dims.size(); ++i) { + if (GetLocalOmgContext().user_input_dims.at(i).second.size() == 1 && + GetLocalOmgContext().user_input_dims.at(i).second.at(0) == 0) { + shape_info.emplace_back(0); + continue; + } + shape_info.emplace_back(GetLocalOmgContext().user_input_dims.at(i).second.size()); + for (size_t j = 0; j < GetLocalOmgContext().user_input_dims.at(i).second.size(); ++j) { + shape_info.emplace_back(GetLocalOmgContext().user_input_dims.at(i).second.at(j)); + } + } + if (!AttrUtils::SetListInt(shape_data_->GetOpDesc(), ATTR_GETNEXT_SINK_SHAPE_INFO, shape_info)) { + GELOGE(INTERNAL_ERROR, "set ATTR_GETNEXT_SINK_SHAPE_INFO failed"); + return INTERNAL_ERROR; + } + return SUCCESS; +} + +Status MultiBatchGraphCopyer::AddLinkForGetDynamicDims(const NodePtr &node) { + GELOGD("Start relink out anchor from shape node to getdynamicdims, and delete link between shape node and identity."); + size_t input_index = 0; + GELOGD("Out count of %s is %zu.", node->GetName().c_str(), node->GetAllOutDataAnchors().size()); + size_t data_count = node->GetAllOutDataAnchors().size() / kDivisionConst; + for (size_t out_index = data_count; out_index < node->GetAllOutDataAnchors().size(); ++out_index, ++input_index) { + GELOGI("Start add %s of %zu out_anchor to %s of %zu in_anchor.", node->GetName().c_str(), out_index, + shape_data_->GetName().c_str(), input_index); + auto out_data_anchor = node->GetOutDataAnchor(out_index); + auto ret = GraphUtils::AddEdge(out_data_anchor, shape_data_->GetInDataAnchor(input_index)); + GE_IF_BOOL_EXEC(ret != GRAPH_SUCCESS, GELOGE(INTERNAL_ERROR, "Failed to link getnext %s to getdynamicdims %s", + node->GetName().c_str(), shape_data_->GetName().c_str()); + return INTERNAL_ERROR); + } + return SUCCESS; +} + Status MultiBatchGraphCopyer::LinkEdges() { Status ret; for (const auto &node : origin_all_nodes_) { - if (data_nodes_to_switchn_.count(node.get()) > 0) { - ret = LinkDataToSwitchN(node); - if (ret != SUCCESS) { - return ret; + GE_CHECK_NOTNULL(node->GetOpDesc()); + if (!getnext_sink_dynamic_dims_) { + if (data_nodes_to_switchn_.count(node.get()) > 0) { + auto switchn = data_nodes_to_switchn_[node.get()]; + GE_IF_BOOL_EXEC(switchn == nullptr, + GELOGE(PARAM_INVALID, "Switchn should not be nullptr for %s.", node->GetName().c_str()); + return OUT_OF_MEMORY); + ret = LinkDataToSwitchN(node, switchn, kDataOutIndex); + GE_CHK_STATUS_RET(ret, "Link data to switchn failed."); + } + } else { + if (IsGetNextType(node)) { + GELOGD("Start add attr and link edge for %s.", node->GetName().c_str()); + GE_CHK_STATUS_RET(AddAttrForGetDynamicDims(node), "Failed to add attr for %s.", node->GetName().c_str()); + GE_CHK_STATUS_RET(AddLinkForGetDynamicDims(node), "Failed to add link for %s.", node->GetName().c_str()); + } + for (size_t i = 0; i < getnext_nodes_to_switchn_.size(); ++i) { + for (size_t j = 0; j < getnext_nodes_to_switchn_.at(i).size(); ++j) { + if (getnext_nodes_to_switchn_.at(i).at(j).first == node.get()) { + auto switchn = getnext_nodes_to_switchn_.at(i).at(j).second; + GE_CHK_STATUS_RET(LinkDataToSwitchN(node, switchn, i), "Link %s to %s failed.", node->GetName().c_str(), + switchn->GetName().c_str()); + } + } } } if (nodes_to_merge_nodes_.count(node.get()) > 0) { - ret = LinkToMerge(node); - if (ret != SUCCESS) { - return ret; - } + GE_CHK_STATUS_RET(LinkToMerge(node), "Link %s to merge failed.", node->GetName().c_str()); } if (nodes_to_batch_nodes_.count(node.get()) > 0) { ret = LinkToNodeInBranch(node); @@ -849,20 +1209,21 @@ Status MultiBatchGraphCopyer::LinkEdges() { } return SUCCESS; } -Status MultiBatchGraphCopyer::LinkDataToSwitchN(const NodePtr &data) { - auto switchn = data_nodes_to_switchn_[data.get()]; + +Status MultiBatchGraphCopyer::LinkDataToSwitchN(const NodePtr &data, const NodePtr &switchn, const int &out_index) { auto ret = GraphUtils::AddEdge(shape_data_->GetOutDataAnchor(kDataOutIndex), switchn->GetInDataAnchor(kSwitchNPredIndex)); GE_IF_BOOL_EXEC(ret != GRAPH_SUCCESS, GELOGE(INTERNAL_ERROR, "Failed to link shape data %s to switchn %s", shape_data_->GetName().c_str(), switchn->GetName().c_str()); return INTERNAL_ERROR); - ret = GraphUtils::AddEdge(data->GetOutDataAnchor(kDataOutIndex), switchn->GetInDataAnchor(kSwitchNDataIndex)); + ret = GraphUtils::AddEdge(data->GetOutDataAnchor(out_index), switchn->GetInDataAnchor(kSwitchNDataIndex)); GE_IF_BOOL_EXEC(ret != GRAPH_SUCCESS, GELOGE(INTERNAL_ERROR, "Failed to link data %s to switchn %s", data->GetName().c_str(), switchn->GetName().c_str()); return INTERNAL_ERROR); return SUCCESS; } + Status MultiBatchGraphCopyer::LinkToMerge(const NodePtr &node) { auto &merge_nodes = nodes_to_merge_nodes_[node.get()]; for (size_t i = 0; i < merge_nodes.size(); ++i) { @@ -877,10 +1238,27 @@ Status MultiBatchGraphCopyer::LinkToMerge(const NodePtr &node) { } continue; } - if (data_nodes_to_switchn_.count(node.get()) > 0) { - auto ret = LinkDataToMerge(node, merge_node); - if (ret != SUCCESS) { - return ret; + + if (!getnext_sink_dynamic_dims_) { + if (data_nodes_to_switchn_.count(node.get()) > 0) { + auto &switchn = data_nodes_to_switchn_[node.get()]; + auto ret = LinkDataToMerge(node, merge_node, switchn); + if (ret != SUCCESS) { + return ret; + } + continue; + } + } else { + for (size_t j = 0; j < getnext_nodes_to_switchn_.size(); ++j) { + for (size_t k = 0; k < getnext_nodes_to_switchn_.at(j).size(); ++k) { + if (getnext_nodes_to_switchn_.at(j).at(k).first == node.get()) { + auto &switchn = getnext_nodes_to_switchn_.at(j).at(k).second; + auto ret = LinkDataToMerge(node, merge_node, switchn); + if (ret != SUCCESS) { + return ret; + } + } + } } continue; } @@ -890,7 +1268,9 @@ Status MultiBatchGraphCopyer::LinkToMerge(const NodePtr &node) { } return SUCCESS; } + Status MultiBatchGraphCopyer::LinkToNodeInBranch(const NodePtr &node) { + GELOGI("Start LinkToNodeInBranch for %s.", node->GetName().c_str()); auto &branch_nodes = nodes_to_batch_nodes_[node.get()]; for (size_t i = 0; i < branch_nodes.size(); ++i) { auto ret = CopyInDataEdges(node, i, branch_nodes[i]); @@ -904,6 +1284,7 @@ Status MultiBatchGraphCopyer::LinkToNodeInBranch(const NodePtr &node) { } return SUCCESS; } + Status MultiBatchGraphCopyer::LinkToNodeOutBranch(const NodePtr &node) { for (auto &in_data_anchor : node->GetAllInDataAnchors()) { auto src_out_anchor = in_data_anchor->GetPeerOutAnchor(); @@ -1031,18 +1412,41 @@ Status ProcessMultiBatch(ComputeGraphPtr &graph) { GE_CHK_STATUS_RET(pass_manager.AddPass("MultiBatchClonePass", new (std::nothrow) MultiBatchClonePass)); return pass_manager.Run(graph); } + if (!GetLocalOmgContext().need_multi_batch) { + GELOGI("No need to process_multi for no_train graph."); + return SUCCESS; + } + std::vector data_nodes; + std::vector getnext_nosink_nodes; + std::vector getnext_sink_nodes; + if (CheckSequenceOfOptions(graph, data_nodes, getnext_nosink_nodes, getnext_sink_nodes) != SUCCESS) { + GELOGE(PARAM_INVALID, "[Train_Dynamic] CheckSequenceOfOptions failed."); + return PARAM_INVALID; + } + if (UpdateNameOfInputShape(graph, data_nodes, getnext_nosink_nodes, getnext_sink_nodes) != SUCCESS) { + GELOGE(PARAM_INVALID, "[Train_Dynamic] UpdateNameForInputShapeOfOption failed."); + return PARAM_INVALID; + } + if (DeleteIdentityInsertByAdapter(graph) != SUCCESS) { + GELOGE(PARAM_INVALID, "DeleteIdentityInsertByAdapter failed."); + return PARAM_INVALID; + } std::vector> shapes; if (!InitDynamicParams(shapes)) { GELOGD("There is no multi-batch options, no need to process multi-batch copy"); return SUCCESS; } + if (CheckNegativeCountOfOptions(shapes) != SUCCESS) { + GELOGE(PARAM_INVALID, "Input_shape and dynamic_dims should set correct params."); + return PARAM_INVALID; + } + DynamicType dynamic_type = DynamicType::kDynamicUnknown; if (!GetLocalOmgContext().dynamic_batch_size.empty()) { dynamic_type = DynamicType::kDynamicBatch; } else if (!GetLocalOmgContext().dynamic_image_size.empty()) { dynamic_type = DynamicType::kDynamicImageSize; - ; } else if (!GetLocalOmgContext().dynamic_dims.empty()) { dynamic_type = DynamicType::kDynamicDims; } @@ -1142,9 +1546,11 @@ void GetDynamicShapeByMerge(const ComputeGraphPtr &graph, const NodePtr &node, s GELOGD("Try get dynamic shape info, Graph: %s, Node: %s", graph->GetName().c_str(), node->GetName().c_str()); const auto &netoutput_desc = node->GetOpDesc(); const auto &inputnode_to_netoutput = node->GetInAllNodes(); + GELOGI("Train_Dynamic Find the merge node size is %zu.", inputnode_to_netoutput.size()); for (size_t i = 0; i < inputnode_to_netoutput.size(); ++i) { bool insert_by_mbatch = false; (void)AttrUtils::GetBool(inputnode_to_netoutput.at(i)->GetOpDesc(), ATTR_INSERT_BY_MBATCH, insert_by_mbatch); + GELOGI("Train_Dynamic type is %s", inputnode_to_netoutput.at(i)->GetType().c_str()); if (inputnode_to_netoutput.at(i)->GetType() == MERGE && insert_by_mbatch) { GELOGI("Find the merge node %s with mbatch attr and the index is %zu", inputnode_to_netoutput.at(i)->GetName().c_str(), i); @@ -1164,6 +1570,10 @@ void GetDynamicShapeByMerge(const ComputeGraphPtr &graph, const NodePtr &node, s // Connect NetOutput directly void GetDirectOutputShape(const ComputeGraphPtr &graph, const NodePtr &node, const set &dynamic_output_index, vector &dynamic_output_dims) { + if (!GetLocalOmgContext().dynamic_node_type.empty()) { + GELOGD("No need to get directly shape info of %s when train.", node->GetName().c_str()); + return; + } GELOGD("Try get directly shape info, Graph: %s, Node: %s", graph->GetName().c_str(), node->GetName().c_str()); const auto &netoutput_desc = node->GetOpDesc(); const auto &inputnode_to_netoutput = node->GetInAllNodes(); diff --git a/src/ge/graph/preprocess/multi_batch_copy_graph.h b/src/ge/graph/preprocess/multi_batch_copy_graph.h index c75bf981..cd9e41f5 100644 --- a/src/ge/graph/preprocess/multi_batch_copy_graph.h +++ b/src/ge/graph/preprocess/multi_batch_copy_graph.h @@ -56,9 +56,7 @@ class MultiBatchGraphCopyer { data_name_order_.push_back(item.first); } } - void SetDataToDynamicInfo(const map>> &designate_shape) { - data_to_dynamic_info_ = designate_shape; - } + void SetDynamicType(const DynamicType dynamic_type) { dynamic_type_ = dynamic_type; } Status CopyGraph(); @@ -68,15 +66,26 @@ class MultiBatchGraphCopyer { // label status for origin_all_nodes_ Status LabelStatus(); + Status LabelInBatchBranchStatus(); + void LabelStatusForData(const NodePtr &data); + void LabelStatusForGetNextSink(const NodePtr &data); // add nodes functions Status CreateNewNodes(); NodePtr InsertShapeDataNode(); - Status InsertSwitchNForData(const NodePtr &data); + NodePtr InsertGetDynamicDimsNode(); + + Status InsertSwitchNAndUpdateMaxShape(const NodePtr &node); + + Status InsertSwitchNForData(const NodePtr &node, const size_t &out_anchor_index, const size_t &peer_in_anchor_index, + std::vector> &dynamic_out_to_switchn); + Status InsertIdentityAfterSwitchN(); - Status UpdateMaxShapeToData(const NodePtr &data); + Status UpdateMaxShapeToData(const NodePtr &node, size_t out_anchor_index); + Status UpdateShapeOfShapeNode(const NodePtr &node, size_t out_anchor_index); Status InsertMergeForEdgeNode(const NodePtr &node); + Status LinkGetDynamicDimsToNetOutput(const NodePtr &node); /// Insert a merge node for src node `node` on output index `index`. The merge node will be used to merge all nodes /// in batch-branch to one output to the node out of the batch-branch. @@ -94,12 +103,16 @@ class MultiBatchGraphCopyer { // link edges functions Status LinkEdges(); - Status LinkDataToSwitchN(const NodePtr &data); + Status AddAttrForGetDynamicDims(const NodePtr &node); + Status AddLinkForGetDynamicDims(const NodePtr &node); + + Status LinkDataToSwitchN(const NodePtr &data, const NodePtr &switchn, const int &out_index); Status LinkToMerge(const NodePtr &node); Status LinkToNodeInBranch(const NodePtr &node); Status LinkToNodeOutBranch(const NodePtr &node); - Status LinkDataToMerge(const NodePtr &data, const NodePtr &merge); + Status LinkDataToMerge(const NodePtr &data, const NodePtr &merge, const NodePtr &switchn); Status LinkNodeToMerge(const NodePtr &node, int out_index, const NodePtr &merge); + NodePtr FindSwitchnNodeForDataEdge(const OutDataAnchorPtr &data_out_anchor, const NodePtr &origin_node); Status CopyInDataEdges(const NodePtr &origin_node, int batch_num, const NodePtr ©ed_node); Status CopyInControlEdges(const NodePtr &node, int batch_num, const NodePtr ©ed_node); Status CheckAndParseDynamicData(); @@ -126,6 +139,11 @@ class MultiBatchGraphCopyer { // the data nodes, and the SwitchN nodes inserted after it std::map data_nodes_to_switchn_; + // the getnext_sink nodes, and the SwitchN nodes inserted after it + std::vector>> getnext_nodes_to_switchn_; + std::vector>> outidx_inidx_mappings_; + std::vector> outidx_inidx_mapping_; + // the nodes on the in/out-batch-branch edge, and the merge nodes inserted after it std::map> nodes_to_merge_nodes_; @@ -141,6 +159,9 @@ class MultiBatchGraphCopyer { // dynamic type : dynamic batch,, dynamic image size, dynamic dims. DynamicType dynamic_type_ = DynamicType::kDynamicUnknown; + + std::vector> getnext_sink_dynamic_out_mapping_; + bool getnext_sink_dynamic_dims_ = false; }; } // namespace multibatch } // namespace ge diff --git a/src/ge/graph/preprocess/multi_batch_options.cc b/src/ge/graph/preprocess/multi_batch_options.cc index 4ebae20c..416b8ab0 100644 --- a/src/ge/graph/preprocess/multi_batch_options.cc +++ b/src/ge/graph/preprocess/multi_batch_options.cc @@ -27,6 +27,9 @@ #include "graph/ge_context.h" #include "graph/common/local_context.h" #include "framework/common/types.h" +#include "graph/compute_graph.h" +#include "graph/utils/graph_utils.h" +#include "graph/common/omg_util.h" namespace ge { namespace multibatch { @@ -38,6 +41,17 @@ const int kDynamicBatchDynamicDimsNum = 1; const int kDynamicImgSizeDynamciDimsNum = 2; const size_t kMaxNDDimNum = 4; const size_t kMinNDDimNum = 1; +const size_t kNumOfGetnextNode = 1; +const int kDivisionConst = 2; +const char *const kSubstrOfGetNextNosinkName = "IteratorGetNext"; +const char *const kShapeDataName = "ascend_mbatch_shape_data"; +const char *const kGetNextName = "IteratorV2"; + +inline bool IsGetNextType(const NodePtr &node) { + std::string original_type; + GE_IF_BOOL_EXEC(GetOriginalType(node, original_type) != SUCCESS, GELOGW("Get original type failed."); return false); + return (original_type == kGetNextName); +} void ParseDynamicSize(string dynamic_size, vector> &shapes) { std::vector shape_strs = ge::StringUtils::Split(dynamic_size, ';'); @@ -59,6 +73,264 @@ void ParseDynamicSize(string dynamic_size, vector> &shapes) { } } +Status DistinguishGetNextAndData(ComputeGraphPtr &graph, vector &data_nodes, + vector &getnext_nosink_nodes, vector &getnext_sink_nodes) { + GELOGD("Start distinguish getnext and data node."); + for (NodePtr &input_node : graph->GetDirectNode()) { + GE_CHECK_NOTNULL(input_node); + OpDescPtr op_desc = input_node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + if (op_desc->GetType() == DATA && op_desc->GetName() != kShapeDataName) { + if (op_desc->GetName().find(kSubstrOfGetNextNosinkName) == string::npos) { + data_nodes.emplace_back(input_node); + GELOGD("Name of data node is %s.", op_desc->GetName().c_str()); + } else { + getnext_nosink_nodes.emplace_back(input_node); + GELOGD("Name of getnext nosink is %s.", op_desc->GetName().c_str()); + } + } + if (IsGetNextType(input_node)) { + GELOGD("Name of getnext sink is %s.", op_desc->GetName().c_str()); + getnext_sink_nodes.emplace_back(input_node); + } + } + GELOGI("Data count is %zu, getnext nosink count is %zu, getnext sink count is %zu.", data_nodes.size(), + getnext_nosink_nodes.size(), getnext_sink_nodes.size()); + return SUCCESS; +} + +Status CheckSequenceOfData(ComputeGraphPtr &graph, const vector &data_nodes) { + GELOGD("Start check input sequence from data nodes and input shape."); + if (data_nodes.size() != GetLocalOmgContext().user_input_dims.size()) { + GELOGE(PARAM_INVALID, "The count of input shape:%zu should be equal to the count of data num:%zu.", + GetLocalOmgContext().user_input_dims.size(), data_nodes.size()); + return PARAM_INVALID; + } + for (size_t i = 0; i < data_nodes.size(); ++i) { + auto data_node = data_nodes.at(i); + GE_CHECK_NOTNULL(data_node); + GE_CHECK_NOTNULL(data_node->GetOpDesc()); + auto output_shape = data_node->GetOpDesc()->GetOutputDesc(0).GetShape().GetDims(); + auto dynamic_dims = GetLocalOmgContext().user_input_dims.at(i).second; + GELOGD("The %zu data node is %s, node shape is %s, dynamic dim is %s.", i, data_node->GetName().c_str(), + formats::JoinToString(output_shape).c_str(), formats::JoinToString(dynamic_dims).c_str()); + if (output_shape.empty() && dynamic_dims.size() == 1 && dynamic_dims.at(0) == 0) { + GELOGI("No need to check sequence for constant."); + continue; + } + if (dynamic_dims.size() != output_shape.size()) { + GELOGE(PARAM_INVALID, "The output shape of %s is %s, the input shape from options of %s is %s.", + data_node->GetName().c_str(), formats::JoinToString(output_shape).c_str(), + GetLocalOmgContext().user_input_dims.at(i).first.c_str(), formats::JoinToString(dynamic_dims).c_str()); + return PARAM_INVALID; + } + for (size_t j = 0; j < dynamic_dims.size(); ++j) { + if (dynamic_dims.at(j) != kDynmaicDims && dynamic_dims.at(j) != output_shape.at(j)) { + GELOGE(INTERNAL_ERROR, "Value of input shape %s should be equal to %s.", + formats::JoinToString(dynamic_dims).c_str(), formats::JoinToString(output_shape).c_str()); + return INTERNAL_ERROR; + } + } + } + return SUCCESS; +} + +Status CheckSequenceOfGetnext(ComputeGraphPtr &graph, const vector &getnext_sink_node) { + GELOGD("Start check input sequence from getnext sink nodes and input shape."); + if (getnext_sink_node.size() != kNumOfGetnextNode) { + GELOGE(PARAM_INVALID, "Not support dynamic dims when a graph with multi getnext nodes."); + return PARAM_INVALID; + } + auto data_node = getnext_sink_node.at(0); + GE_CHECK_NOTNULL(data_node); + auto op_desc = data_node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + size_t data_count = data_node->GetAllOutDataAnchors().size() / kDivisionConst; + if (data_count != GetLocalOmgContext().user_input_dims.size()) { + GELOGE(PARAM_INVALID, "Output count of %s is %zu, should be equal to count of input shape: %zu", + op_desc->GetName().c_str(), data_count, GetLocalOmgContext().user_input_dims.size()); + return PARAM_INVALID; + } + for (size_t i = 0; i < data_count; ++i) { + auto output_shape = data_node->GetOpDesc()->GetOutputDesc(i).GetShape().GetDims(); + auto dynamic_dims = GetLocalOmgContext().user_input_dims.at(i).second; + GELOGD("The %zu getnext node is %s, node shape is %s, dynamic dim is %s.", i, data_node->GetName().c_str(), + formats::JoinToString(output_shape).c_str(), formats::JoinToString(dynamic_dims).c_str()); + if (output_shape.empty() && dynamic_dims.size() == 1 && dynamic_dims.at(0) == 0) { + GELOGI("No need to check sequence for constant."); + continue; + } + if (dynamic_dims.size() != output_shape.size()) { + GELOGE(PARAM_INVALID, "the output_shape of %s is %s, the input_shape from options of %s is %s.", + data_node->GetName().c_str(), formats::JoinToString(output_shape).c_str(), + GetLocalOmgContext().user_input_dims.at(i).first.c_str(), formats::JoinToString(dynamic_dims).c_str()); + return PARAM_INVALID; + } + for (size_t j = 0; j < dynamic_dims.size(); ++j) { + if (dynamic_dims.at(j) != kDynmaicDims && dynamic_dims.at(j) != output_shape.at(j)) { + GELOGE(INTERNAL_ERROR, "value of input_shape %s should be equal to %s.", + formats::JoinToString(dynamic_dims).c_str(), formats::JoinToString(output_shape).c_str()); + return INTERNAL_ERROR; + } + } + } + return SUCCESS; +} + +Status CheckSequenceOfOptions(ComputeGraphPtr &graph, vector &data_nodes, + vector &getnext_nosink_nodes, vector &getnext_sink_nodes) { + if (GetLocalOmgContext().dynamic_node_type.empty()) { + GELOGI("No need to CheckSequenceOfOptions."); + return SUCCESS; + } + + if (DistinguishGetNextAndData(graph, data_nodes, getnext_nosink_nodes, getnext_sink_nodes) != SUCCESS) { + GELOGE(PARAM_INVALID, "DistinguishGetNextAndData failed."); + return PARAM_INVALID; + } + + if (GetLocalOmgContext().dynamic_node_type == DATA) { + GELOGD("Users want data nodes to be dynamic."); + if (CheckSequenceOfData(graph, data_nodes) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to check sequence of data nodes."); + return PARAM_INVALID; + } + } else { + GELOGD("Users want getnext nodes to be dynamic."); + if (!getnext_nosink_nodes.empty()) { + if (CheckSequenceOfData(graph, getnext_nosink_nodes) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to check sequence of getnext nosink nodes."); + return PARAM_INVALID; + } + } else { + if (CheckSequenceOfGetnext(graph, getnext_sink_nodes) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to check sequence of getnext sink nodes."); + return PARAM_INVALID; + } + } + } + return SUCCESS; +} + +Status UpdateNameOfData(ComputeGraphPtr &graph, const vector &data_nodes) { + GELOGD("Update first value of input shape by data nodes."); + if (data_nodes.size() != GetLocalOmgContext().user_input_dims.size()) { + GELOGE(PARAM_INVALID, "count of data_nodes: %zu should be equal to input_shape count: %zu.", data_nodes.size(), + GetLocalOmgContext().user_input_dims.size()); + return PARAM_INVALID; + } + for (size_t i = 0; i < data_nodes.size(); ++i) { + GELOGD("The %zu data name is %s.", i, data_nodes.at(i)->GetOpDesc()->GetName().c_str()); + GetLocalOmgContext().user_input_dims.at(i).first = data_nodes.at(i)->GetOpDesc()->GetName(); + } + return SUCCESS; +} + +Status UpdateNameOfGetnext(ComputeGraphPtr &graph, const vector &getnext_sink_nodes) { + GELOGD("Update first value of input shape by getnext sink nodes."); + if (getnext_sink_nodes.size() != kNumOfGetnextNode) { + GELOGE(PARAM_INVALID, "Not support dynamic dims when a graph with multi getnext nodes."); + return PARAM_INVALID; + } + auto input_node = getnext_sink_nodes.at(0); + GE_CHECK_NOTNULL(input_node); + auto op_desc = input_node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + // user want getnext dynamic, just getnext or data+getnext_sink + size_t data_count = input_node->GetAllOutDataAnchors().size() / kDivisionConst; + if (data_count != GetLocalOmgContext().user_input_dims.size()) { + GELOGE(PARAM_INVALID, "Output count of %s is %zu, should be equal to count of input shape: %zu", + op_desc->GetName().c_str(), data_count, GetLocalOmgContext().user_input_dims.size()); + return PARAM_INVALID; + } + + for (size_t i = 0; i < data_count; ++i) { + string data_name = op_desc->GetName() + "_" + std::to_string(i); + GELOGD("Data just from getnext sink is %s.", data_name.c_str()); + GetLocalOmgContext().user_input_dims.at(i).first = data_name; + } + return SUCCESS; +} + +// need to distinguish online and offline, offline no need to update the name of input_shape +Status UpdateNameOfInputShape(ComputeGraphPtr &graph, const vector &data_nodes, + const vector &getnext_nosink_nodes, const vector &getnext_sink_nodes) { + if (GetLocalOmgContext().dynamic_node_type.empty()) { + GELOGI("No need to update first value of input shape when offline infer."); + return SUCCESS; + } + + if (GetLocalOmgContext().dynamic_node_type == DATA) { + GELOGD("Users want data nodes to be dynamic."); + if (UpdateNameOfData(graph, data_nodes) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to update first value of input shape of data nodes."); + return PARAM_INVALID; + } + } else { + GELOGD("Users want getnext nodes to be dynamic."); + if (!getnext_nosink_nodes.empty()) { + if (UpdateNameOfData(graph, getnext_nosink_nodes) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to update first value of input shape of getnext nosink nodes."); + return PARAM_INVALID; + } + } else { + if (UpdateNameOfGetnext(graph, getnext_sink_nodes) != SUCCESS) { + GELOGE(PARAM_INVALID, "Failed to update first value of input shape of getnext sink nodes."); + return PARAM_INVALID; + } + } + } + return SUCCESS; +} + +Status DeleteIdentityInsertByAdapter(ComputeGraphPtr &graph) { + GELOGD("Start delete identity node inserted by adapter."); + for (NodePtr &node : graph->GetDirectNode()) { + GE_CHECK_NOTNULL(node); + OpDescPtr op_desc = node->GetOpDesc(); + GE_CHECK_NOTNULL(op_desc); + if (IsGetNextType(node)) { + for (auto &out_data_anchor : node->GetAllOutDataAnchors()) { + GE_IF_BOOL_EXEC(out_data_anchor == nullptr, continue); + for (auto &peer_in_anchor : out_data_anchor->GetPeerInDataAnchors()) { + GE_IF_BOOL_EXEC(peer_in_anchor == nullptr, continue); + auto dst_node = peer_in_anchor->GetOwnerNode(); + GE_IF_BOOL_EXEC(dst_node == nullptr, continue); + if (dst_node->GetType() == IDENTITY) { + GELOGI("Need to remove %s.", dst_node->GetName().c_str()); + if (ge::GraphUtils::RemoveNodeWithoutRelink(graph, dst_node) != GRAPH_SUCCESS) { + GELOGE(FAILED, "Remove Identity node %s failed.", dst_node->GetName().c_str()); + return FAILED; + } + } + } + } + } + } + return SUCCESS; +} + +Status CheckNegativeCountOfOptions(const std::vector> &shapes) { + if (!GetLocalOmgContext().dynamic_dims.empty()) { + size_t negative_count = 0; + for (size_t i = 0; i < GetLocalOmgContext().user_input_dims.size(); ++i) { + for (size_t j = 0; j < GetLocalOmgContext().user_input_dims.at(i).second.size(); ++j) { + if (GetLocalOmgContext().user_input_dims.at(i).second.at(j) == kDynmaicDims) { + negative_count++; + } + } + } + for (size_t i = 0; i < shapes.size(); ++i) { + if (shapes.at(i).size() != negative_count) { + GELOGE(PARAM_INVALID, "Each gear num of dynamic_dims is %zu should be equal to %zu.", shapes.at(i).size(), + negative_count); + return PARAM_INVALID; + } + } + } + return SUCCESS; +} + /// /// @ingroup ge /// @brief Init Dynamic Param from Options. @@ -115,8 +387,10 @@ Status ParserDataToDynmaicInfo(const vector> &shapes, auto &data_shape = cur_item.second; auto dynamic_dims_num = std::count_if(data_shape.begin(), data_shape.end(), [&data_shape](int64_t dim) { return dim < 0; }); + GELOGI("Train_Dynamic dynamic_dims_num of %s is %zu", data_name.c_str(), dynamic_dims_num); vector> dynamic_info; for (auto &dynamic_gear_info : shapes) { + GELOGI("Train_Dynamic dynamic_gear_info is %s", formats::JoinToString(dynamic_gear_info).c_str()); vector one_gear; if (dynamic_gear_info.size() == static_cast(dynamic_dims_num)) { one_gear = dynamic_gear_info; @@ -139,6 +413,7 @@ Status ParserDataToDynmaicInfo(const vector> &shapes, data_name.c_str(), formats::JoinToString(data_shape).c_str()); return FAILED; } + GELOGI("Train_Dynamic one_gear is %s.", formats::JoinToString(one_gear).c_str()); dynamic_info.push_back(one_gear); } cur_data_index += dynamic_dims_num; @@ -226,6 +501,7 @@ Status CalcShape(const std::vector &batch_shape, GeShape &data_shape) { data_shape.SetDim(i, batch_shape[batch_shape_index++]); } } + GELOGI("CalcShape size of batch_shape is %zu, batch_shape_index is %zu.", batch_shape.size(), batch_shape_index); if (batch_shape_index != batch_shape.size()) { ErrorManager::GetInstance().ATCReportErrMessage( "E19012", {"function", "reason"}, diff --git a/src/ge/graph/preprocess/multi_batch_options.h b/src/ge/graph/preprocess/multi_batch_options.h index b5616399..634fdd44 100644 --- a/src/ge/graph/preprocess/multi_batch_options.h +++ b/src/ge/graph/preprocess/multi_batch_options.h @@ -28,6 +28,21 @@ namespace ge { namespace multibatch { /// /// @ingroup ge +/// @brief Update Dynamic Param from Options. +/// @param [in] ComputeGraphPtr &graph: the train graph +/// @return SUCCESS: valid / PARAM_INVALID: invalid. +/// +Status CheckSequenceOfOptions(ComputeGraphPtr &graph, std::vector &data_nodes, + std::vector &getnext_nosink_nodes, std::vector &getnext_sink_nodes); + +Status UpdateNameOfInputShape(ComputeGraphPtr &graph, const vector &data_nodes, + const vector &getnext_nosink_nodes, const vector &getnext_sink_nodes); + +Status DeleteIdentityInsertByAdapter(ComputeGraphPtr &graph); + +Status CheckNegativeCountOfOptions(const std::vector> &shapes); +/// +/// @ingroup ge /// @brief Init Dynamic Param from Options. /// @param [out] std::vector> &shapes: Result for Params. /// @return true: Configed for Multi batch / false: Not configed for Multi batch. diff --git a/src/ge/host_cpu_engine/module.mk b/src/ge/host_cpu_engine/module.mk index e6cfce80..861ab19b 100644 --- a/src/ge/host_cpu_engine/module.mk +++ b/src/ge/host_cpu_engine/module.mk @@ -80,6 +80,26 @@ LOCAL_C_INCLUDES := $(local_lib_inc_path) include ${BUILD_HOST_SHARED_LIBRARY} +#compiler for device ops kernel builder +include $(CLEAR_VARS) +LOCAL_MODULE := libhost_cpu_opskernel_builder +LOCAL_CFLAGS += -Werror +LOCAL_CFLAGS += -std=c++11 -Dgoogle=ascend_private +LOCAL_LDFLAGS := + +LOCAL_STATIC_LIBRARIES := +LOCAL_SHARED_LIBRARIES := libascend_protobuf \ + libc_sec \ + libslog \ + libgraph \ + libregister \ + +LOCAL_SRC_FILES := ops_kernel_store/host_cpu_ops_kernel_builder.cc + +LOCAL_C_INCLUDES := $(local_lib_inc_path) + +include ${BUILD_SHARED_LIBRARY} + #compiler for host static lib include $(CLEAR_VARS) LOCAL_MODULE := libhost_cpu_opskernel_builder diff --git a/src/ge/host_kernels/empty_kernel.cc b/src/ge/host_kernels/empty_kernel.cc index a5e5fbcf..ce4ddc4f 100644 --- a/src/ge/host_kernels/empty_kernel.cc +++ b/src/ge/host_kernels/empty_kernel.cc @@ -122,7 +122,7 @@ Status EmptyKernel::Compute(const OpDescPtr op_desc_ptr, const std::vector(input, output_ptr); break; default: - GELOGI("FloorDivKernel does not support Data type:%s", TypeUtils::DataTypeToSerialString(data_type).c_str()); - return PARAM_INVALID; + GELOGW("FloorDivKernel does not support Data type:%s", TypeUtils::DataTypeToSerialString(data_type).c_str()); + return NOT_CHANGED; } return ret; } diff --git a/src/ge/host_kernels/strided_slice_kernel.cc b/src/ge/host_kernels/strided_slice_kernel.cc index c6684c55..e4e81a86 100644 --- a/src/ge/host_kernels/strided_slice_kernel.cc +++ b/src/ge/host_kernels/strided_slice_kernel.cc @@ -223,6 +223,8 @@ Status StridedSliceKernel::InitParamWithAttrs(const std::vector orig_begin_vec, orig_end_vec, orig_stride_vec; GetOriginStrideVec(input, orig_begin_vec, orig_end_vec, orig_stride_vec); + // calculate begin_mask & end_mask by ellipsis_mask + ExpandStrideWithEllipsisMask(x_dims_num, x_dims, orig_begin_vec, orig_end_vec, orig_stride_vec); auto begin_dim_num = orig_begin_vec.size(); auto min_dim = x_dims_num > begin_dim_num ? begin_dim_num : x_dims_num; for (size_t i = 0; i < x_dims.size(); ++i) { @@ -281,11 +283,43 @@ void StridedSliceKernel::ExpandDimsWithNewAxis(const ConstGeTensorPtr &begin_ten } } +void StridedSliceKernel::ExpandStrideWithEllipsisMask(const size_t x_dims_num, const vector &x_dims, + vector &orig_begin_vec, vector &orig_end_vec, + vector &orig_stride_vec) { + if (attr_value_map_.at(STRIDE_SLICE_ATTR_ELLIPSIS_MASK) != 0) { + auto end_mask = attr_value_map_.at(STRIDE_SLICE_ATTR_END_MASK); + auto begin_mask = attr_value_map_.at(STRIDE_SLICE_ATTR_BEGIN_MASK); + if (begin_mask != 0 && x_dims_num != orig_begin_vec.size()) { + begin_mask *= begin_mask * (kMaskBitLeftUnit << (x_dims_num - orig_begin_vec.size() - 1)); + attr_value_map_.at(STRIDE_SLICE_ATTR_BEGIN_MASK) = begin_mask; + } + if (end_mask != 0 && x_dims_num != orig_end_vec.size()) { + end_mask *= end_mask * (kMaskBitLeftUnit << (x_dims_num - orig_end_vec.size() - 1)); + attr_value_map_.at(STRIDE_SLICE_ATTR_END_MASK) = end_mask; + } + for (size_t i = 0; i < x_dims_num; ++i) { + bool ellipsis_mask_flag = attr_value_map_.at(STRIDE_SLICE_ATTR_ELLIPSIS_MASK) & (kMaskBitLeftUnit << i); + if (ellipsis_mask_flag) { + auto ellipsis_dim = i; + orig_begin_vec[i] = 0; + orig_end_vec[i] = x_dims.at(i); + orig_stride_vec[i] = 1; + if (orig_begin_vec.size() < x_dims_num) { + for (size_t j = 1; j < (x_dims_num - orig_begin_vec.size() + 1); ++j) { + orig_begin_vec.insert((orig_begin_vec.begin() + ellipsis_dim + j), 0); + orig_end_vec.insert((orig_end_vec.begin() + ellipsis_dim + j), x_dims.at(ellipsis_dim + j)); + orig_stride_vec.insert((orig_stride_vec.begin() + ellipsis_dim + j), 1); + } + } + } + } + } +} + Status StridedSliceKernel::MaskCal(const size_t i, int64_t &begin_i, int64_t &end_i, int64_t &dim_i) const { auto i_temp = static_cast(i); bool begin_mask_flag = (attr_value_map_.at(STRIDE_SLICE_ATTR_BEGIN_MASK) & (kMaskBitLeftUnit << i_temp)); bool end_mask_flag = (attr_value_map_.at(STRIDE_SLICE_ATTR_END_MASK) & (kMaskBitLeftUnit << i_temp)); - bool ellipsis_mask_flag = (attr_value_map_.at(STRIDE_SLICE_ATTR_ELLIPSIS_MASK) & (kMaskBitLeftUnit << i_temp)); bool shrink_mask_flag = (attr_value_map_.at(STRIDE_SLICE_ATTR_SHRINK_AXIS_MASK) & (kMaskBitLeftUnit << i_temp)); if (shrink_mask_flag) { begin_i = (begin_i < 0 ? (dim_i + begin_i) : begin_i); @@ -302,10 +336,6 @@ Status StridedSliceKernel::MaskCal(const size_t i, int64_t &begin_i, int64_t &en } else { end_i = (end_i < 0 ? (dim_i + end_i) : end_i); } - if (ellipsis_mask_flag) { - begin_i = 0; - end_i = dim_i; - } } return SUCCESS; } @@ -316,8 +346,10 @@ Status StridedSliceKernel::StrideCal(const int64_t x_dims_i, int64_t &begin_i, i stride_i = kDefaultStrideSize; } else if (stride_i < 0) { stride_i = -stride_i; - begin_i = x_dims_i - begin_i - 1; - end_i = x_dims_i - end_i - 1; + if (begin_i < 0 && end_i < 0) { + begin_i = x_dims_i - begin_i - 1; + end_i = x_dims_i - end_i - 1; + } } if (end_i > x_dims_i) { diff --git a/src/ge/host_kernels/strided_slice_kernel.h b/src/ge/host_kernels/strided_slice_kernel.h index 65e572bf..a42b6024 100644 --- a/src/ge/host_kernels/strided_slice_kernel.h +++ b/src/ge/host_kernels/strided_slice_kernel.h @@ -36,6 +36,9 @@ class StridedSliceKernel : public Kernel { static Status StrideCal(const int64_t x_dims_i, int64_t &begin_i, int64_t &end_i, int64_t &stride_i, int64_t &dim_final); void ExpandDimsWithNewAxis(const ConstGeTensorPtr &begin_tensor, const size_t x_dims_num, vector &x_dims); + void ExpandStrideWithEllipsisMask(const size_t x_dims_num, const vector &x_dims, + vector &orig_begin_vec, vector &orig_end_vec, + vector &orig_stride_vec); void GetOutputDims(uint32_t dims_size, const std::vector &output_dims, vector &v_dims); diff --git a/src/ge/hybrid/executor/hybrid_execution_context.h b/src/ge/hybrid/executor/hybrid_execution_context.h index 37822039..43fd3855 100644 --- a/src/ge/hybrid/executor/hybrid_execution_context.h +++ b/src/ge/hybrid/executor/hybrid_execution_context.h @@ -53,16 +53,16 @@ struct GraphExecutionContext { mutable std::mutex mu; }; -#define RECORD_PROFILING_EVENT(context, evt_type, fmt, category, node_name, ...) \ - do { \ - if ((context != nullptr) && (context)->profiler != nullptr) { \ - if (node_name != nullptr) { \ - context->profiler->RecordEvent(evt_type, "tid:%lu [%s] [%s] " fmt, GetTid(), node_name, category, \ - ##__VA_ARGS__); \ - } else { \ - context->profiler->RecordEvent(evt_type, "tid:%lu [%s] " fmt, GetTid(), category, ##__VA_ARGS__); \ - } \ - } \ +#define RECORD_PROFILING_EVENT(context, evt_type, fmt, category, node_name, ...) \ + do { \ + if ((context != nullptr) && (context)->profiler != nullptr) { \ + if (node_name != nullptr) { \ + context->profiler->RecordEvent(evt_type, "tid:%lu [%s] [%s] " fmt, GeLog::GetTid(), node_name, category, \ + ##__VA_ARGS__); \ + } else { \ + context->profiler->RecordEvent(evt_type, "tid:%lu [%s] " fmt, GeLog::GetTid(), category, ##__VA_ARGS__); \ + } \ + } \ } while (0) #define RECORD_MODEL_EXECUTION_EVENT(context, fmt, ...) \ diff --git a/src/ge/hybrid/executor/hybrid_model_async_executor.cc b/src/ge/hybrid/executor/hybrid_model_async_executor.cc index 5b08ed2f..bc1ad178 100644 --- a/src/ge/hybrid/executor/hybrid_model_async_executor.cc +++ b/src/ge/hybrid/executor/hybrid_model_async_executor.cc @@ -52,7 +52,7 @@ Status HybridModelAsyncExecutor::Start(const std::shared_ptr &lis run_flag_ = true; listener_ = listener; - future_ = std::async([&]() -> Status { + future_ = std::async(std::launch::async, [&]() -> Status { GetContext().SetSessionId(executor_->GetContext()->session_id); return RunInternal(); }); @@ -66,7 +66,11 @@ Status HybridModelAsyncExecutor::Stop() { std::lock_guard lk(mu_); run_flag_ = false; data_inputer_->Stop(); - auto ret = future_.get(); + + Status ret = SUCCESS; + if (future_.valid()) { + ret = future_.get(); + } if (stream_ != nullptr) { GE_CHK_RT(rtStreamDestroy(stream_)); diff --git a/src/ge/hybrid/executor/rt_callback_manager.cc b/src/ge/hybrid/executor/rt_callback_manager.cc index 03681f13..f542d5f3 100644 --- a/src/ge/hybrid/executor/rt_callback_manager.cc +++ b/src/ge/hybrid/executor/rt_callback_manager.cc @@ -48,7 +48,8 @@ Status CallbackManager::RegisterCallback(rtCallback_t callback, void *user_data) Status CallbackManager::Init() { rtContext_t ctx = nullptr; GE_CHK_RT_RET(rtCtxGetCurrent(&ctx)); - ret_future_ = std::async([&](rtContext_t context) -> Status { return CallbackProcess(context); }, ctx); + ret_future_ = std::async( + std::launch::async, [&](rtContext_t context) -> Status { return CallbackProcess(context); }, ctx); if (!ret_future_.valid()) { GELOGE(INTERNAL_ERROR, "Failed to init callback manager."); return INTERNAL_ERROR; diff --git a/src/ge/hybrid/executor/subgraph_executor.cc b/src/ge/hybrid/executor/subgraph_executor.cc index 1a8de55f..d5b758a7 100644 --- a/src/ge/hybrid/executor/subgraph_executor.cc +++ b/src/ge/hybrid/executor/subgraph_executor.cc @@ -286,7 +286,7 @@ Status SubgraphExecutor::LaunchTasks() { Status SubgraphExecutor::ScheduleTasks() { GELOGD("[%s] Start to schedule prepare workers.", graph_item_->GetName().c_str()); - auto prepare_future = std::async([&]() -> Status { + auto prepare_future = std::async(std::launch::async, [&]() -> Status { GetContext().SetSessionId(context_->session_id); auto ret = PrepareNodes(); ready_queue_.Push(nullptr); diff --git a/src/ge/hybrid/executor/worker/shape_inference_engine.cc b/src/ge/hybrid/executor/worker/shape_inference_engine.cc index cc83ccfb..27a0c19d 100644 --- a/src/ge/hybrid/executor/worker/shape_inference_engine.cc +++ b/src/ge/hybrid/executor/worker/shape_inference_engine.cc @@ -60,7 +60,8 @@ Status ShapeInferenceEngine::InferShape(NodeState &node_state) { { std::lock_guard lk(mu_); RECORD_SHAPE_INFERENCE_EVENT(execution_context_, node_item.NodeName().c_str(), "[InferShapeAndType] Start"); - GE_CHK_STATUS_RET(ShapeRefiner::InferShapeAndType(node_item.node), "Invoke InferShapeAndType failed."); + GE_CHK_STATUS_RET(ShapeRefiner::InferShapeAndTypeForRunning(node_item.node, true), + "Invoke InferShapeAndType failed."); RECORD_SHAPE_INFERENCE_EVENT(execution_context_, node_item.NodeName().c_str(), "[InferShapeAndType] End"); } // Check again to make sure shape is valid after shape inference diff --git a/src/ge/hybrid/model/hybrid_model_builder.cc b/src/ge/hybrid/model/hybrid_model_builder.cc index 9beab52a..b04e8248 100644 --- a/src/ge/hybrid/model/hybrid_model_builder.cc +++ b/src/ge/hybrid/model/hybrid_model_builder.cc @@ -37,6 +37,16 @@ const uint32_t kSubgraphIndex = 0U; const uint32_t kVarOutputIndex = 0U; const uint32_t kAlignment = 32; const int kBytes = 8; +const char *const kOwnerGraphIsUnknown = "OwnerGraphIsUnknown"; + +bool IsGraphUnknown(ComputeGraph &graph) { + for (const auto &node : graph.GetDirectNode()) { + bool is_unknown_shape = false; + (void)AttrUtils::GetBool(node->GetOpDesc(), kOwnerGraphIsUnknown, is_unknown_shape); + return is_unknown_shape; + } + return false; +} int64_t CalcVarSizeInBytes(const GeTensorDesc &desc) { int64_t var_size = 0; @@ -525,7 +535,7 @@ Status HybridModelBuilder::UnfoldSubgraphs(ComputeGraph &root_graph, ComputeGrap auto subgraph = NodeUtils::GetSubgraph(*node, kSubgraphIndex); GE_CHECK_NOTNULL(subgraph); - bool is_unknown_shape = subgraph->GetGraphUnknownFlag(); + bool is_unknown_shape = IsGraphUnknown(*subgraph); if (!is_unknown_shape) { merged_graph->AddNode(node); GELOGD("[%s] Known shape partitioned call added to merged graph.", op_desc->GetName().c_str()); @@ -567,7 +577,7 @@ Status HybridModelBuilder::UnfoldSubgraph(ComputeGraph &root_graph, ComputeGraph if (sub_op_type == PARTITIONEDCALL) { auto sub_sub_graph = NodeUtils::GetSubgraph(*sub_node, kSubgraphIndex); GE_CHECK_NOTNULL(sub_sub_graph); - if (sub_sub_graph->GetGraphUnknownFlag()) { + if (IsGraphUnknown(*sub_sub_graph)) { GE_CHK_STATUS_RET(UnfoldSubgraph(root_graph, parent_graph, *sub_sub_graph), "[%s] Failed to merge subgraph", sub_sub_graph->GetName().c_str()); continue; @@ -647,7 +657,7 @@ Status HybridModelBuilder::LoadGraph() { continue; } - if (sub_graph->GetGraphUnknownFlag()) { + if (IsGraphUnknown(*sub_graph)) { GE_CHK_STATUS_RET(LoadDynamicSubgraph(*sub_graph, false), "Failed to load subgraph: [%s]", sub_graph->GetName().c_str()); } else { @@ -885,7 +895,7 @@ Status HybridModelBuilder::IndexTaskDefs() { continue; } - bool is_unknown_shape = sub_graph->GetGraphUnknownFlag(); + bool is_unknown_shape = IsGraphUnknown(*sub_graph); if (!is_unknown_shape) { GE_CHK_STATUS_RET_NOLOG(LoadGeModel(*sub_graph, ge_model)); continue; diff --git a/src/ge/hybrid/node_executor/aicore/aicore_node_executor.cc b/src/ge/hybrid/node_executor/aicore/aicore_node_executor.cc index 0d361656..3cd4ab85 100644 --- a/src/ge/hybrid/node_executor/aicore/aicore_node_executor.cc +++ b/src/ge/hybrid/node_executor/aicore/aicore_node_executor.cc @@ -241,6 +241,9 @@ TaskCompilerFactory &TaskCompilerFactory::GetInstance() { void TaskCompilerFactory::Register(CreateFn fn) { compiler_func_ = fn; } std::unique_ptr TaskCompilerFactory::GetTaskCompiler() { + if (compiler_func_ == nullptr) { + return nullptr; + } auto compiler_instance = std::unique_ptr(compiler_func_()); return compiler_instance; } diff --git a/src/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc b/src/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc index 1d6c464f..324d3e54 100644 --- a/src/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc +++ b/src/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc @@ -57,6 +57,9 @@ Status AicpuExtInfoHandler::Parse(const std::string &ext_info) { case aicpu::FWKAdapter::FWK_ADPT_EXT_OUTPUT_SHAPE: GE_CHK_STATUS_RET(ParseExtOutputShape(aicpu_ext_info), "Parse ext output shape failed."); break; + case aicpu::FWKAdapter::FWK_ADPT_EXT_SESSION_INFO: + GE_CHK_STATUS_RET(ParseExtSessionInfo(aicpu_ext_info), "Parse ext session info failed."); + break; default: GELOGD("Node[%s] ignore infoType=%d, infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoType, aicpu_ext_info->infoLen); @@ -123,6 +126,39 @@ Status AicpuExtInfoHandler::ParseExtOutputShape(AicpuExtInfo *aicpu_ext_info) { return SUCCESS; } +Status AicpuExtInfoHandler::ParseExtSessionInfo(AicpuExtInfo *aicpu_ext_info) { + GE_CHK_BOOL_RET_STATUS(aicpu_ext_info->infoLen == sizeof(AicpuSessionInfo), PARAM_INVALID, + "Node[%s] parse ext session info failed as infoLen must be %zu but %u.", node_name_.c_str(), + sizeof(SessionInfo), aicpu_ext_info->infoLen); + + session_info_ = reinterpret_cast(aicpu_ext_info->infoMsg); + GELOGI("Node[%s] parse session info success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen); + return SUCCESS; +} + +Status AicpuExtInfoHandler::UpdateSessionInfo(uint64_t session_id, uint64_t kernel_id, bool sess_flag) { + if (session_info_ == nullptr) { + GELOGD("There is no session info in ext_info, no need update."); + return SUCCESS; + } + + session_info_->sessionId = session_id; + session_info_->kernelId = kernel_id; + session_info_->sessFlag = sess_flag; + return SUCCESS; +} + +Status AicpuExtInfoHandler::UpdateSessionInfoSessionId(uint64_t session_id) { + if (session_info_ == nullptr) { + GELOGD("There is no session info in ext_info, no need update."); + return SUCCESS; + } + + session_info_->sessionId = session_id; + session_info_->sessFlag = true; + return SUCCESS; +} + Status AicpuExtInfoHandler::UpdateInputShapeAndType(uint32_t input_index, const GeTensorDesc &input_desc) { GE_CHECK_LE(input_index, input_num_); const auto &shape = input_desc.GetShape(); diff --git a/src/ge/hybrid/node_executor/aicpu/aicpu_ext_info.h b/src/ge/hybrid/node_executor/aicpu/aicpu_ext_info.h index a42678b1..ac4155bd 100644 --- a/src/ge/hybrid/node_executor/aicpu/aicpu_ext_info.h +++ b/src/ge/hybrid/node_executor/aicpu/aicpu_ext_info.h @@ -19,6 +19,7 @@ #include "external/ge/ge_api_error_codes.h" #include "cce/fwk_adpt_struct.h" +#include "cce/aicpu_engine_struct.h" #include "graph/op_desc.h" #include "graph/ge_tensor.h" @@ -26,6 +27,7 @@ namespace ge { namespace hybrid { using AicpuShapeAndType = aicpu::FWKAdapter::ShapeAndType; using AicpuExtInfo = aicpu::FWKAdapter::ExtInfo; +using AicpuSessionInfo = SessionInfo; class AicpuExtInfoHandler { public: @@ -43,12 +45,17 @@ class AicpuExtInfoHandler { Status UpdateOutputShapeAndType(uint32_t output_index, const GeTensorDesc &output_desc); + Status UpdateSessionInfo(uint64_t session_id, uint64_t kernel_id, bool sess_flag); + + Status UpdateSessionInfoSessionId(uint64_t session_id); + Status GetOutputShapeAndType(uint32_t output_index, GeShape &shape, DataType &data_type); private: Status ParseExtShapeType(AicpuExtInfo *aicpu_ext_info); Status ParseExtInputShape(AicpuExtInfo *aicpu_ext_info); Status ParseExtOutputShape(AicpuExtInfo *aicpu_ext_info); + Status ParseExtSessionInfo(AicpuExtInfo *aicpu_ext_info); static Status UpdateShapeAndType(const GeShape &shape, DataType data_type, AicpuShapeAndType *shape_and_type); @@ -59,6 +66,7 @@ class AicpuExtInfoHandler { const uint32_t input_num_; const uint32_t output_num_; UnknowShapeOpType unknown_type_; + AicpuSessionInfo *session_info_ = nullptr; std::unique_ptr ext_info_; size_t ext_info_len_ = 0; diff --git a/src/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc b/src/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc index 7b3d1971..12a1996e 100644 --- a/src/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc +++ b/src/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc @@ -40,28 +40,34 @@ Status AicpuNodeTaskBase::AllocTensorBuffer(size_t size, std::unique_ptris_dynamic) { - // dynamic node must have ext info - GE_CHK_STATUS_RET(aicpu_ext_handle_.Parse(kernel_ext_info), - "Node[%s] parse kernel ext info failed, kernel_ext_info_size=%zu.", node_name_.c_str(), - kernel_ext_info.size()); - } - - // if no ext info no need copy to device. +Status AicpuNodeTaskBase::InitExtInfo(const std::string &kernel_ext_info, int64_t session_id) { if (kernel_ext_info.empty()) { - GELOGI("Node[%s] kernel_ext_info is empty, no need copy to device, is_dynamic=%s.", node_name_.c_str(), - node_item_->is_dynamic ? "true" : "false"); - return SUCCESS; + if (node_item_->is_dynamic) { + // dynamic node must have ext info + GELOGE(PARAM_INVALID, "Node[%s] parse ext info failed as ext info is empty.", node_name_.c_str()); + return PARAM_INVALID; + } else { + // if no ext info no need copy to device. + GELOGI("Node[%s] kernel_ext_info is empty, no need copy to device, is_dynamic=%s.", node_name_.c_str(), + node_item_->is_dynamic ? "true" : "false"); + return SUCCESS; + } } + GE_CHK_STATUS_RET(aicpu_ext_handle_.Parse(kernel_ext_info), + "Node[%s] parse kernel ext info failed, kernel_ext_info_size=%zu.", node_name_.c_str(), + kernel_ext_info.size()); + GELOGD("To update aicpu_task ext_info session_info session_id to %lu", session_id); + GE_CHK_STATUS_RET(aicpu_ext_handle_.UpdateSessionInfoSessionId(session_id), "UpdateSessionInfoSessionId failed."); + // copy task args buf - GE_CHK_STATUS_RET(AllocTensorBuffer(kernel_ext_info.size(), ext_info_addr_dev_), - "Node[%s] alloc kernel_ext_info buf failed, size=%zu", node_name_.c_str(), kernel_ext_info.size()); + GE_CHK_STATUS_RET(AllocTensorBuffer(aicpu_ext_handle_.GetExtInfoLen(), ext_info_addr_dev_), + "Node[%s] alloc kernel_ext_info buf failed, size=%zu", node_name_.c_str(), + aicpu_ext_handle_.GetExtInfoLen()); // copy default ext info to device - GE_CHK_RT_RET(rtMemcpy(ext_info_addr_dev_->GetData(), ext_info_addr_dev_->GetSize(), kernel_ext_info.data(), - kernel_ext_info.size(), RT_MEMCPY_HOST_TO_DEVICE)); + GE_CHK_RT_RET(rtMemcpy(ext_info_addr_dev_->GetData(), ext_info_addr_dev_->GetSize(), aicpu_ext_handle_.GetExtInfo(), + aicpu_ext_handle_.GetExtInfoLen(), RT_MEMCPY_HOST_TO_DEVICE)); return SUCCESS; } @@ -273,7 +279,8 @@ Status AicpuTfNodeTask::Init(const HybridModel &model) { kernel_ext_info.size(), kernel_ext_info_size); // init ext info - GE_CHK_STATUS_RET(InitExtInfo(kernel_ext_info), "Node[%s] init ext info failed.", node_name_.c_str()); + uint64_t ext_session_id = model.GetSessionId(); + GE_CHK_STATUS_RET(InitExtInfo(kernel_ext_info, ext_session_id), "Node[%s] init ext info failed.", node_name_.c_str()); GE_CHK_STATUS_RET(InitForDependComputeTask(), "Node[%s] init for depend compute task failed.", node_name_.c_str()); // build fwk_op_kernel. @@ -638,7 +645,8 @@ Status AicpuNodeTask::Init(const HybridModel &model) { "Node[%s] task def kernel_ext_info.size=%zu, but kernel_ext_info_size=%u.", node_name.c_str(), kernel_ext_info.size(), kernel_ext_info_size); - GE_CHK_STATUS_RET(InitExtInfo(kernel_ext_info), "Node[%s] init ext info failed.", node_name.c_str()); + uint64_t ext_session_id = model.GetSessionId(); + GE_CHK_STATUS_RET(InitExtInfo(kernel_ext_info, ext_session_id), "Node[%s] init ext info failed.", node_name.c_str()); if (ext_info_addr_dev_ == nullptr) { aicpu_param_head->extInfoLength = 0; diff --git a/src/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h b/src/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h index 8aca6ff7..5e34244f 100644 --- a/src/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h +++ b/src/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h @@ -44,7 +44,7 @@ class AicpuNodeTaskBase : public NodeTask { Status ExecuteAsync(TaskContext &context, std::function done_callback) override; protected: - virtual Status InitExtInfo(const std::string &kernel_ext_info); + virtual Status InitExtInfo(const std::string &kernel_ext_info, int64_t session_id); virtual Status UpdateExtInfo(); diff --git a/src/ge/hybrid/node_executor/node_executor.cc b/src/ge/hybrid/node_executor/node_executor.cc index e0367000..1474f438 100644 --- a/src/ge/hybrid/node_executor/node_executor.cc +++ b/src/ge/hybrid/node_executor/node_executor.cc @@ -18,6 +18,7 @@ #include "framework/common/debug/log.h" #include "graph/utils/node_utils.h" #include "init/gelib.h" +#include "graph/utils/tensor_utils.h" #include "hybrid/model/hybrid_model.h" #include "graph/debug/ge_attr_define.h" #include "opskernel_manager/ops_kernel_builder_manager.h" @@ -32,6 +33,7 @@ const char *const kEngineNameAiCpuTf = "aicpu_tf_kernel"; const char *const kEngineNameHccl = "ops_kernel_info_hccl"; const char *const kEngineNameRts = "DNN_VM_RTS_OP_STORE"; const char *const kEngineNameHostCpu = "DNN_VM_HOST_CPU_OP_STORE"; +const char *const kOwnerGraphIsUnknown = "OwnerGraphIsUnknown"; } // namespace Status NodeExecutor::PrepareTask(NodeTask &task, TaskContext &context) const { GE_CHK_STATUS_RET_NOLOG(context.AllocateOutputs()); @@ -79,16 +81,17 @@ NodeExecutorManager::ExecutorType NodeExecutorManager::ResolveExecutorType(Node auto op_type = node.GetType(); if (op_type == PARTITIONEDCALL) { const auto &subgraph = NodeUtils::GetSubgraph(node, 0); - if (subgraph != nullptr && subgraph->GetGraphUnknownFlag()) { - GELOGD("node %s was marked as unknown shape in node_executor.", node.GetName().c_str()); - return ExecutorType::DYNAMIC_SUBGRAPH; - } - bool is_dynamic = false; - (void)NodeUtils::GetNodeUnknownShapeStatus(node, is_dynamic); - if (is_dynamic) { - return ExecutorType::DYNAMIC_SUBGRAPH; + if (subgraph != nullptr) { + for (const auto &node : subgraph->GetDirectNode()) { + bool is_unknown_shape = false; + (void)AttrUtils::GetBool(node->GetOpDesc(), kOwnerGraphIsUnknown, is_unknown_shape); + if (is_unknown_shape) { + return ExecutorType::DYNAMIC_SUBGRAPH; + } else { + return ExecutorType::COMPILED_SUBGRAPH; + } + } } - return ExecutorType::COMPILED_SUBGRAPH; } // rts kernel store is assigned to NetOutput diff --git a/src/ge/init/gelib.cc b/src/ge/init/gelib.cc index 5d1057c8..e664240a 100644 --- a/src/ge/init/gelib.cc +++ b/src/ge/init/gelib.cc @@ -108,7 +108,7 @@ Status GELib::InnerInitialize(const map &options) { Status initSystemStatus = SystemInitialize(options); GE_TIMESTAMP_END(SystemInitialize, "InnerInitialize::SystemInitialize"); if (initSystemStatus != SUCCESS) { - GELOGE(initSystemStatus); + GELOGE(initSystemStatus, "GE system initial failed."); RollbackInit(); return initSystemStatus; } @@ -118,7 +118,7 @@ Status GELib::InnerInitialize(const map &options) { Status initEmStatus = engineManager_.Initialize(options); GE_TIMESTAMP_END(EngineInitialize, "InnerInitialize::EngineInitialize"); if (initEmStatus != SUCCESS) { - GELOGE(initEmStatus); + GELOGE(initEmStatus, "GE engine manager initial failed."); RollbackInit(); return initEmStatus; } @@ -128,7 +128,7 @@ Status GELib::InnerInitialize(const map &options) { Status initOpsStatus = opsManager_.Initialize(options); GE_TIMESTAMP_END(OpsManagerInitialize, "InnerInitialize::OpsManagerInitialize"); if (initOpsStatus != SUCCESS) { - GELOGE(initOpsStatus); + GELOGE(initOpsStatus, "GE ops manager initial failed."); RollbackInit(); return initOpsStatus; } @@ -138,7 +138,7 @@ Status GELib::InnerInitialize(const map &options) { Status initOpsBuilderStatus = OpsKernelBuilderManager::Instance().Initialize(options); GE_TIMESTAMP_END(OpsKernelBuilderManagerInitialize, "InnerInitialize::OpsKernelBuilderManager"); if (initOpsBuilderStatus != SUCCESS) { - GELOGE(initOpsBuilderStatus); + GELOGE(initOpsBuilderStatus, "GE ops builder manager initial failed."); RollbackInit(); return initOpsBuilderStatus; } @@ -148,7 +148,7 @@ Status GELib::InnerInitialize(const map &options) { Status initSmStatus = sessionManager_.Initialize(options); GE_TIMESTAMP_END(SessionManagerInitialize, "InnerInitialize::SessionManagerInitialize"); if (initSmStatus != SUCCESS) { - GELOGE(initSmStatus); + GELOGE(initSmStatus, "GE session manager initial failed."); RollbackInit(); return initSmStatus; } diff --git a/src/ge/ir_build/atc_ir_common.cc b/src/ge/ir_build/atc_ir_common.cc index 658deea0..24274165 100644 --- a/src/ge/ir_build/atc_ir_common.cc +++ b/src/ge/ir_build/atc_ir_common.cc @@ -505,7 +505,7 @@ void PrintOptionMap(std::map &options, std::string tip for (auto iter = options.begin(); iter != options.end(); iter++) { std::string key = iter->first; std::string option_name = iter->second; - GELOGI("%s set successfully, option_key=%s, option_value=%s", tips.c_str(), key.c_str(), option_name.c_str()); + GELOGD("%s set successfully, option_key=%s, option_value=%s", tips.c_str(), key.c_str(), option_name.c_str()); } } diff --git a/src/ge/ir_build/ge_ir_build.cc b/src/ge/ir_build/ge_ir_build.cc index 9764ddaf..1b62c75e 100644 --- a/src/ge/ir_build/ge_ir_build.cc +++ b/src/ge/ir_build/ge_ir_build.cc @@ -18,7 +18,6 @@ #include #include "common/auth/file_saver.h" -#include "common/ge/tbe_plugin_manager.h" #include "external/register/register_types.h" #include "framework/common/debug/ge_log.h" #include "framework/common/ge_inner_error_codes.h" @@ -139,7 +138,7 @@ static void LoadOpsProto() { (void)manager->Initialize(option_tmp); } -graphStatus aclgrphBuildInitialize(std::map global_options) { +graphStatus aclgrphBuildInitializeImpl(std::map &global_options) { GELOGD("Enter aclgrphInitialize start!"); // check global options if (CheckGlobalOptions(global_options) != GRAPH_SUCCESS) { @@ -160,16 +159,31 @@ graphStatus aclgrphBuildInitialize(std::map global_opt GELOGE(ret, "GE initialize failed!"); return GRAPH_FAILED; } - // for functional subgraph assign _parent_index. - TBEPluginManager::Instance().InitPreparation(global_options); } GELOGW("gelib has been initialized!"); return GRAPH_SUCCESS; } +graphStatus aclgrphBuildInitialize(std::map global_options) { + return aclgrphBuildInitializeImpl(global_options); +} + +graphStatus aclgrphBuildInitialize(std::map &global_options) { + std::map tmp_global_options; + for (auto &option : global_options) { + if (option.first.GetString() == nullptr || option.second.GetString() == nullptr) { + GELOGE(GRAPH_FAILED, "AclgrphBuildInitialize option is nullptr."); + return GRAPH_FAILED; + } + std::string key = option.first.GetString(); + std::string val = option.second.GetString(); + tmp_global_options[key] = val; + } + return aclgrphBuildInitializeImpl(tmp_global_options); +} + void aclgrphBuildFinalize() { if (ge::GELib::GetInstance() != nullptr && ge::GELib::GetInstance()->InitFlag()) { - (void)TBEPluginManager::Instance().Finalize(); (void)ge::GELib::GetInstance()->Finalize(); return; } @@ -339,7 +353,7 @@ void Impl::SetRtSocVersion() { if (rt_ret != RT_ERROR_NONE) { GELOGW("Set soc version %s failed. ret:0x%X", soc_version, rt_ret); } - GELOGI("Set soc version %s success.", soc_version); + GELOGD("Set soc version %s success.", soc_version); } } @@ -358,18 +372,18 @@ graphStatus Impl::CreateInputsForIRBuild(const ge::Graph &graph, vectorGetType() == DATA) { (void)AttrUtils::SetInt(op, ATTR_NAME_INDEX, index++); - GELOGI("Data op inputDesc size: %zu", op->GetAllInputsDesc().size()); + GELOGD("Data op inputDesc size: %zu", op->GetAllInputsDesc().size()); ge::GeTensorDesc tensor = op->GetInputDesc(0); string data_op_name = op->GetName(); - GELOGI("Data op name: %s", data_op_name.c_str()); + GELOGD("Data op name: %s", data_op_name.c_str()); ge::GeShape data_shape; auto iter = omg_context_.input_dims.find(data_op_name); if (iter != omg_context_.input_dims.end()) { data_shape = ge::GeShape(iter->second); - GELOGI("Data op get shape from Context."); + GELOGD("Data op get shape from Context."); } else { data_shape = tensor.GetShape(); - GELOGI("Data op get shape from InputDesc in ge ir graph."); + GELOGD("Data op get shape from InputDesc in ge ir graph."); } // If user point input format, do work for all data ops; else do according to tensor_desc auto data_format = omg_context_.format != domi::DOMI_TENSOR_ND @@ -377,7 +391,7 @@ graphStatus Impl::CreateInputsForIRBuild(const ge::Graph &graph, vector &build_options, + ModelBufferData &model) { + GELOGD("Enter aclmdlBuildModel process!"); + std::map tmp_build_options; + for (auto &option : build_options) { + if (option.first.GetString() == nullptr || option.second.GetString() == nullptr) { + GELOGE(GRAPH_FAILED, "AclgrphBuildInitialize option is nullptr."); + return GRAPH_FAILED; + } + std::string key = option.first.GetString(); + std::string val = option.second.GetString(); + tmp_build_options[key] = val; + } + + Impl builder; + return builder.BuildModel(graph, tmp_build_options, model); +} + graphStatus aclgrphSaveModel(const string &output_file, const ModelBufferData &model) { GELOGD("Enter aclmdlSaveModel process!"); if (model.data.get() == nullptr || model.length == 0) { @@ -463,6 +495,21 @@ graphStatus aclgrphSaveModel(const string &output_file, const ModelBufferData &m static_cast(model.length)); } +graphStatus aclgrphSaveModel(const char *output_file, const ModelBufferData &model) { + GELOGD("Enter aclmdlSaveModel process!"); + if (model.data.get() == nullptr || model.length == 0) { + GELOGE(GRAPH_PARAM_INVALID, "Input model is illegal"); + return GRAPH_PARAM_INVALID; + } + if (output_file == nullptr) { + GELOGE(GRAPH_PARAM_INVALID, "Output file is nullptr."); + return GRAPH_PARAM_INVALID; + } + std::string str_output_file = output_file; + return FileSaver::SaveToFile((str_output_file + ".om"), reinterpret_cast(model.data.get()), + static_cast(model.length)); +} + graphStatus aclgrphGetIRVersion(int *major_version, int *minor_version, int *patch_version) { GELOGD("Enter aclgrphGetIRVersion process!"); GE_CHECK_NOTNULL(major_version); diff --git a/src/ge/omm/csa_interact.cc b/src/ge/omm/csa_interact.cc index dd3f6240..63ee6818 100644 --- a/src/ge/omm/csa_interact.cc +++ b/src/ge/omm/csa_interact.cc @@ -52,9 +52,11 @@ void CsaInteract::Init(int32_t dev_index, int64_t job_id) { if (!is_init_) { dev_index_ = dev_index; job_id_ = job_id; - char *file_dir_env = std::getenv(FMK_STATUS_FILE_DIR_ENV); + + char file_dir_env[MMPA_MAX_PATH] = {0x00}; + INT32 res = mmGetEnv(FMK_STATUS_FILE_DIR_ENV, file_dir_env, MMPA_MAX_PATH); string csa_path_prefix; - if (file_dir_env != nullptr) { + if (res == EN_OK) { csa_path_prefix = file_dir_env; } if (!csa_path_prefix.empty()) { @@ -186,21 +188,21 @@ Status CsaInteract::WriteHcomDetection(const std::string &content) { /// Status CsaInteract::WriteFile(const std::string &file_name, const std::string &content) { // if file path is not exist, then make path - INT32 flags = O_WRONLY | O_TRUNC | O_CREAT; - int32_t fd = mmOpen2(file_name.c_str(), flags, M_IRUSR | M_IWUSR | S_IRGRP); + INT32 flags = M_WRONLY | O_TRUNC | M_CREAT; + int32_t fd = mmOpen2(file_name.c_str(), flags, M_IRUSR | M_IWUSR | M_UMASK_GRPREAD); if (fd == EN_ERROR) { if (MakePath(file_name) != SUCCESS) { GELOGE(INTERNAL_ERROR, "csainteract create file path fail, errno is %d", errno); return INTERNAL_ERROR; } - fd = mmOpen2(file_name.c_str(), flags, M_IRUSR | M_IWUSR | S_IRGRP); + fd = mmOpen2(file_name.c_str(), flags, M_IRUSR | M_IWUSR | M_UMASK_GRPREAD); if (fd == EN_ERROR) { GELOGE(INTERNAL_ERROR, "open file fail, errno is %d", errno); return INTERNAL_ERROR; } } - ssize_t ret = write(fd, content.c_str(), content.length()); + mmSsize_t ret = mmWrite(fd, (void *)content.c_str(), content.length()); if (ret == EN_ERROR) { GELOGE(INTERNAL_ERROR, "write file fail, errno is %d", errno); ret = mmClose(fd); @@ -239,7 +241,7 @@ Status CsaInteract::MakePath(const std::string &file_name) { while (found != std::string::npos) { std::string pre_path = file_path.substr(0, found + 1); if (mmAccess(pre_path.c_str()) != EN_OK) { - if (mmMkdir(pre_path.c_str(), S_IRWXU) != EN_OK) { + if (mmMkdir(pre_path.c_str(), M_IRWXU) != EN_OK) { GELOGE(INTERNAL_ERROR, "csainteract mkdir fail, errno is %d", errno); return INTERNAL_ERROR; } diff --git a/src/ge/opskernel_manager/ops_kernel_manager.cc b/src/ge/opskernel_manager/ops_kernel_manager.cc index 346991c9..da1d3d91 100644 --- a/src/ge/opskernel_manager/ops_kernel_manager.cc +++ b/src/ge/opskernel_manager/ops_kernel_manager.cc @@ -85,7 +85,7 @@ Status OpsKernelManager::Initialize(const map &options_const) { initialize_ = options; Status rst0 = plugin_manager_.InvokeAll &, Status>(kInitialize, initialize_); if (rst0 == FAILED) { - GELOGE(GE_OPS_GET_NO_VALID_SO); + GELOGE(GE_OPS_GET_NO_VALID_SO, "There is invalid so about OpsKernelInfoStore."); return GE_OPS_GET_NO_VALID_SO; } Status rst1 = @@ -391,7 +391,7 @@ void OpsKernelManager::GetGraphOptimizerByEngine(const std::string &engine_name, continue; } if (attrs.engineName == engine_name) { - GELOGI("GetGraphOptimizerByEngine GraphOptimzer name: %s, engineName: %s", (it.first).c_str(), + GELOGD("GetGraphOptimizerByEngine GraphOptimzer name: %s, engineName: %s", (it.first).c_str(), attrs.engineName.c_str()); graph_optimizer.push_back(it.second); } diff --git a/src/ge/session/inner_session.cc b/src/ge/session/inner_session.cc index e9d8487a..3247ad1b 100644 --- a/src/ge/session/inner_session.cc +++ b/src/ge/session/inner_session.cc @@ -253,6 +253,24 @@ Status InnerSession::RegisterCallBackFunc( return SUCCESS; } +Status InnerSession::RegisterCallBackFunc( + const std::string &key, const std::function &)> &callback) { + std::lock_guard lock(resource_mutex_); + if (!init_flag_) { + GELOGE(GE_SESS_INIT_FAILED, "[InnerSession:%lu] initialize failed.", session_id_); + return GE_SESS_INIT_FAILED; + } + UpdateThreadContext(std::map{}); + Status ret = graph_manager_.RegisterCallBackFunc(key, callback); + if (ret != SUCCESS) { + GELOGE(ret, "[InnerSession:%lu] register %s callback function failed.", session_id_, key.c_str()); + return ret; + } + + GELOGI("[InnerSession:%lu] register %s callback function success.", session_id_, key.c_str()); + return SUCCESS; +} + Status InnerSession::BuildGraph(uint32_t graph_id, const std::vector &inputs) { UpdateThreadContext(graph_id); GELOGI("[InnerSession:%lu] build graph on session, graph_id=%u.", session_id_, graph_id); diff --git a/src/ge/session/inner_session.h b/src/ge/session/inner_session.h index bbbedca5..e73c0e3c 100644 --- a/src/ge/session/inner_session.h +++ b/src/ge/session/inner_session.h @@ -61,6 +61,10 @@ class InnerSession { Status RegisterCallBackFunc( const std::string &key, const std::function &)> &callback); + Status RegisterCallBackFunc( + const std::string &key, + const std::function &)> &callback); + const GraphManager &getGraphManagerObj() const; bool IsGraphNeedRebuild(uint32_t graph_id); diff --git a/src/ge/session/session_manager.cc b/src/ge/session/session_manager.cc index 978488ec..f31710d2 100644 --- a/src/ge/session/session_manager.cc +++ b/src/ge/session/session_manager.cc @@ -61,7 +61,7 @@ Status SessionManager::SetRtContext(SessionId session_id, rtContext_t rt_context Status SessionManager::CreateSession(const std::map &options, SessionId &session_id) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } SessionId next_session_id = 0; @@ -92,7 +92,7 @@ Status SessionManager::CreateSession(const std::map &o Status SessionManager::DestroySession(SessionId session_id) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } std::lock_guard lock(mutex_); @@ -119,7 +119,7 @@ Status SessionManager::DestroySession(SessionId session_id) { Status SessionManager::GetVariable(SessionId session_id, const std::string &name, Tensor &val) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } SessionPtr innerSession = nullptr; @@ -143,7 +143,7 @@ Status SessionManager::AddGraph(SessionId session_id, uint32_t graph_id, const G Status SessionManager::AddGraph(SessionId session_id, uint32_t graph_id, const Graph &graph, const std::map &options) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } SessionPtr innerSession = nullptr; @@ -173,7 +173,7 @@ Status SessionManager::AddGraph(SessionId session_id, uint32_t graph_id, const G Status SessionManager::AddGraphWithCopy(SessionId session_id, uint32_t graph_id, const Graph &graph, const std::map &options) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } SessionPtr innerSession = nullptr; @@ -203,7 +203,7 @@ Status SessionManager::AddGraphWithCopy(SessionId session_id, uint32_t graph_id, Status SessionManager::RunGraph(SessionId session_id, uint32_t graph_id, const std::vector &inputs, std::vector &outputs) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } SessionPtr innerSession = nullptr; @@ -221,7 +221,7 @@ Status SessionManager::RunGraph(SessionId session_id, uint32_t graph_id, const s Status SessionManager::RemoveGraph(SessionId session_id, uint32_t graph_id) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } SessionPtr innerSession = nullptr; @@ -239,7 +239,7 @@ Status SessionManager::RemoveGraph(SessionId session_id, uint32_t graph_id) { bool SessionManager::HasSession(SessionId session_id) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return false; } return session_manager_map_.find(session_id) != session_manager_map_.end(); @@ -247,7 +247,7 @@ bool SessionManager::HasSession(SessionId session_id) { Status SessionManager::GetNextSessionId(SessionId &next_session_id) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } static SessionId session_id = 0; @@ -260,7 +260,27 @@ Status SessionManager::RegisterCallBackFunc( SessionId session_id, const std::string &key, const std::function &)> &callback) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); + return GE_SESSION_MANAGER_NOT_INIT; + } + SessionPtr innerSession = nullptr; + { + std::lock_guard lock(mutex_); + std::map::iterator it = session_manager_map_.find(session_id); + if (it == session_manager_map_.end()) { + return GE_SESSION_NOT_EXIST; + } else { + innerSession = it->second; + } + } + return innerSession->RegisterCallBackFunc(key, callback); +} + +Status SessionManager::RegisterCallBackFunc( + SessionId session_id, const std::string &key, + const std::function &)> &callback) { + if (!init_flag_) { + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } SessionPtr innerSession = nullptr; @@ -278,7 +298,7 @@ Status SessionManager::RegisterCallBackFunc( Status SessionManager::BuildGraph(SessionId session_id, uint32_t graph_id, const std::vector &inputs) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } SessionPtr innerSession = nullptr; @@ -297,7 +317,7 @@ Status SessionManager::BuildGraph(SessionId session_id, uint32_t graph_id, const Status SessionManager::RunGraphAsync(SessionId session_id, uint32_t graph_id, const std::vector &inputs, RunAsyncCallback callback) { if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } SessionPtr innerSession = nullptr; @@ -317,7 +337,7 @@ Status SessionManager::GetVariables(SessionId session_id, const std::vector &var_values) { // step 0: init session manager if (!init_flag_) { - GELOGE(GE_SESSION_MANAGER_NOT_INIT); + GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); return GE_SESSION_MANAGER_NOT_INIT; } SessionPtr innerSession = nullptr; @@ -383,7 +403,7 @@ Status SessionManager::GetVariables(SessionId session_id, const std::vector &)> &callback); + Status RegisterCallBackFunc( + SessionId session_id, const std::string &key, + const std::function &)> &callback); bool IsGraphNeedRebuild(SessionId session_id, uint32_t graph_id); diff --git a/src/ge/single_op/single_op.cc b/src/ge/single_op/single_op.cc index c7d49331..cbc55e4b 100644 --- a/src/ge/single_op/single_op.cc +++ b/src/ge/single_op/single_op.cc @@ -43,49 +43,48 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY SingleOp::~SingleOp() { delete task; task = nullptr; } - GELOGI("SingleOp destory sessionId = %lu", aicpu_session_id_); - ModelManager::GetInstance()->DestroyAicpuSession(aicpu_session_id_); } Status SingleOp::ValidateArgs(const std::vector &inputs, const std::vector &outputs) { auto num_inputs = inputs.size(); if (num_inputs != input_sizes_.size()) { - GELOGE(PARAM_INVALID, "Input num mismatch. model expect %zu, but given %zu", input_addr_list_.size(), + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Input num mismatch. model expect %zu, but given %zu", input_addr_list_.size(), inputs.size()); - return PARAM_INVALID; + return ACL_ERROR_GE_PARAM_INVALID; } for (size_t i = 0; i < num_inputs; ++i) { // preventing from read out of bound size_t aligned_size = GetAlignedSize(inputs[i].length); - GELOGI("Input [%zu], aligned_size:%zu, inputs.length:%lu, input_sizes_:%lu", i, aligned_size, inputs[i].length, + GELOGI("Input [%zu], aligned_size:%zu, inputs.length:%lu, input_sizes_:%zu", i, aligned_size, inputs[i].length, input_sizes_[i]); if (aligned_size < input_sizes_[i]) { - GELOGE(PARAM_INVALID, + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Input size mismatch. index = %zu, model expect %zu," " but given %zu(after align)", i, input_sizes_[i], aligned_size); - return PARAM_INVALID; + return ACL_ERROR_GE_PARAM_INVALID; } } auto num_outputs = outputs.size(); if (num_outputs != output_sizes_.size()) { - GELOGE(PARAM_INVALID, "output num mismatch. model expect %zu, but given %zu", output_sizes_.size(), outputs.size()); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "output num mismatch. model expect %zu, but given %zu", output_sizes_.size(), + outputs.size()); + return ACL_ERROR_GE_PARAM_INVALID; } for (size_t i = 0; i < num_outputs; ++i) { // preventing from write out of bound size_t aligned_size = GetAlignedSize(outputs[i].length); - GELOGI("Output [%zu], aligned_size:%zu, outputs.length:%lu, output_sizes_:%lu", i, aligned_size, outputs[i].length, + GELOGI("Output [%zu], aligned_size:%zu, outputs.length:%lu, output_sizes_:%zu", i, aligned_size, outputs[i].length, output_sizes_[i]); if (aligned_size < output_sizes_[i]) { - GELOGE(PARAM_INVALID, + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Output size mismatch. index = %zu, model expect %zu," "but given %zu(after align)", i, output_sizes_[i], aligned_size); - return PARAM_INVALID; + return ACL_ERROR_GE_PARAM_INVALID; } } @@ -133,8 +132,8 @@ Status SingleOp::UpdateArgs(const std::vector &inputs, const std::ve auto rt_ret = rtMemcpyAsync(dst_io_addr, sizeof(uint64_t) * args_.size(), &args_[0], sizeof(uint64_t) * args_.size(), RT_MEMCPY_HOST_TO_DEVICE_EX, stream_); if (rt_ret != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "rtMemcpyAsync addresses failed, ret = %d", rt_ret); - return RT_FAILED; + GELOGE(rt_ret, "rtMemcpyAsync addresses failed, ret = %d", rt_ret); + return rt_ret; } } else if (task->GetOpTaskType() == OP_TASK_AICPUCC) { GELOGD("Update aicpu_CC task args"); @@ -142,7 +141,7 @@ Status SingleOp::UpdateArgs(const std::vector &inputs, const std::ve GE_CHECK_NOTNULL(task_io_addr); auto io_addr = reinterpret_cast(const_cast(task_io_addr)); for (size_t i = 0; i < io_addr_num; ++i) { - io_addr[i] = reinterpret_cast(args_[i]); + io_addr[i] = static_cast(args_[i]); } } else { GELOGW("Only TF_kernel aicpu and aicpu_CC are supported, but got %u", task->GetOpTaskType()); @@ -177,38 +176,37 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status SingleOp::ExecuteAsync(c void SingleOp::SetStream(rtStream_t stream) { stream_ = stream; } -void SingleOp::SetSessionID(uint64_t session_id) { aicpu_session_id_ = session_id; } - DynamicSingleOp::DynamicSingleOp(uintptr_t resource_id, std::mutex *stream_mutex, rtStream_t stream) : resource_id_(resource_id), stream_mutex_(stream_mutex), stream_(stream) {} -DynamicSingleOp::~DynamicSingleOp() { - GELOGI("DynamicSingleOp destory sessionId = %lu", aicpu_session_id_); - ModelManager::GetInstance()->DestroyAicpuSession(aicpu_session_id_); -} +DynamicSingleOp::~DynamicSingleOp() {} Status DynamicSingleOp::ValidateParams(const vector &input_desc, const std::vector &inputs, std::vector &output_desc, std::vector &outputs) const { if (inputs.size() != input_desc.size()) { - GELOGE(PARAM_INVALID, "Input number mismatches input desc number. Input num = %zu, input desc num = %zu", - inputs.size(), input_desc.size()); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, + "Input number mismatches input desc number. Input num = %zu, input desc num = %zu", inputs.size(), + input_desc.size()); + return ACL_ERROR_GE_PARAM_INVALID; } if (outputs.size() != output_desc.size()) { - GELOGE(PARAM_INVALID, "Output number mismatches output desc number. Output num = %zu, output desc num = %zu", - outputs.size(), output_desc.size()); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, + "Output number mismatches output desc number. Output num = %zu, output desc num = %zu", outputs.size(), + output_desc.size()); + return ACL_ERROR_GE_PARAM_INVALID; } if (input_desc.size() != num_inputs_) { - GELOGE(PARAM_INVALID, "Input number mismatches. expect %zu, but given %zu", num_inputs_, input_desc.size()); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Input number mismatches. expect %zu, but given %zu", num_inputs_, + input_desc.size()); + return ACL_ERROR_GE_PARAM_INVALID; } if (output_desc.size() != num_outputs_) { - GELOGE(PARAM_INVALID, "Output number mismatches. expect %zu, but given %zu", num_outputs_, output_desc.size()); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Output number mismatches. expect %zu, but given %zu", num_outputs_, + output_desc.size()); + return ACL_ERROR_GE_PARAM_INVALID; } return SUCCESS; @@ -235,8 +233,8 @@ Status DynamicSingleOp::AllocateWorkspaces(const std::vector &workspace GE_CHECK_NOTNULL(stream_resource); auto ws_base = stream_resource->MallocMemory(kPurpose, static_cast(total_size)); if (ws_base == nullptr) { - GELOGE(MEMALLOC_FAILED, "Failed to allocate memory of size: %ld", total_size); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to allocate memory of size: %ld", total_size); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } GELOGD("Done allocating workspace memory successfully."); @@ -277,11 +275,9 @@ Status DynamicSingleOp::ExecuteAsync(const vector &input_desc, con } else if (op_task_->GetOpTaskType() == OP_TASK_AICPU || op_task_->GetOpTaskType() == OP_TASK_AICPUCC) { return op_task_->LaunchKernel(input_desc, input_buffers, output_desc, output_buffers, stream_); } else { - GELOGE(UNSUPPORTED, "Only TBE_Task, AI_CPU_Task and AI_CPUCC_Task are supported, but got %u", + GELOGE(ACL_ERROR_GE_OP_TASK_TYPE_INVALID, "Only TBE_Task, AI_CPU_Task and AI_CPUCC_Task are supported, but got %u", op_task_->GetOpTaskType()); - return UNSUPPORTED; + return ACL_ERROR_GE_OP_TASK_TYPE_INVALID; } } - -void DynamicSingleOp::SetSessionID(uint64_t session_id) { aicpu_session_id_ = session_id; } } // namespace ge diff --git a/src/ge/single_op/single_op.h b/src/ge/single_op/single_op.h index 0ca4afef..a5ddc4c9 100644 --- a/src/ge/single_op/single_op.h +++ b/src/ge/single_op/single_op.h @@ -37,7 +37,6 @@ class SingleOp { Status ExecuteAsync(const std::vector &inputs, const std::vector &outputs); void SetStream(rtStream_t stream); - void SetSessionID(uint64_t session_id); private: Status ValidateArgs(const std::vector &inputs, const std::vector &outputs); @@ -52,7 +51,6 @@ class SingleOp { std::vector output_addr_list_; std::vector output_sizes_; std::vector args_; - uint64_t aicpu_session_id_ = 0; std::vector tasks_; std::vector> arg_table_; @@ -64,7 +62,6 @@ class DynamicSingleOp { ~DynamicSingleOp(); Status ExecuteAsync(const vector &input_desc, const std::vector &inputs, std::vector &output_desc, std::vector &outputs); - void SetSessionID(uint64_t session_id); private: friend class SingleOpModel; @@ -82,7 +79,6 @@ class DynamicSingleOp { rtStream_t stream_ = nullptr; size_t num_inputs_ = 0; size_t num_outputs_ = 0; - uint64_t aicpu_session_id_ = 0; }; } // namespace ge #endif // GE_SINGLE_OP_SINGLE_OP_H_ diff --git a/src/ge/single_op/single_op_manager.cc b/src/ge/single_op/single_op_manager.cc index 709b238f..2c8905b1 100644 --- a/src/ge/single_op/single_op_manager.cc +++ b/src/ge/single_op/single_op_manager.cc @@ -33,16 +33,16 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status SingleOpManager::GetOpFr SingleOp **single_op) { GELOGI("GetOpFromModel in. model name = %s", model_name.c_str()); if (single_op == nullptr) { - GELOGE(PARAM_INVALID, "single op is null"); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "single op is null"); + return ACL_ERROR_GE_INTERNAL_ERROR; } uintptr_t resource_id = 0; GE_CHK_STATUS_RET(GetResourceId(stream, resource_id)); StreamResource *res = GetResource(resource_id, stream); if (res == nullptr) { - GELOGE(MEMALLOC_FAILED, "GetResource failed"); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "GetResource failed"); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } SingleOp *op = res->GetOperator(model_data.model_data); @@ -107,8 +107,8 @@ Status SingleOpManager::GetDynamicOpFromModel(const string &model_name, const Mo GE_CHK_STATUS_RET(GetResourceId(stream, resource_id)); StreamResource *res = GetResource(resource_id, stream); if (res == nullptr) { - GELOGE(MEMALLOC_FAILED, "GetResource failed"); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "GetResource failed"); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } DynamicSingleOp *op = res->GetDynamicOperator(model_data.model_data); @@ -138,8 +138,8 @@ Status SingleOpManager::GetResourceId(rtStream_t stream, uintptr_t &resource_id) rtContext_t rt_cur_ctx = nullptr; auto rt_err = rtCtxGetCurrent(&rt_cur_ctx); if (rt_err != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "get current context failed, runtime result is %d", static_cast(rt_err)); - return RT_FAILED; + GELOGE(rt_err, "get current context failed, runtime result is %d", static_cast(rt_err)); + return rt_err; } // use current context as resource key instead GELOGI("use context as resource key instead when default stream"); diff --git a/src/ge/single_op/single_op_model.cc b/src/ge/single_op/single_op_model.cc index 8b59565f..df55c979 100644 --- a/src/ge/single_op/single_op_model.cc +++ b/src/ge/single_op/single_op_model.cc @@ -32,7 +32,7 @@ #include "task/aicpu_kernel_task_builder.h" #include "task/tbe_task_builder.h" -static std::atomic aicpu_sessionid(0); +static std::atomic aicpu_kernel_id(0); using domi::TaskDef; using std::unique_ptr; @@ -94,7 +94,7 @@ Status SingleOpModel::InitModelMem(StreamResource &res) { GELOGI("total memory: %lu, zero_copy_mem: %lu", model_params_.memory_size, model_params_.zero_copy_mem_size); model_params_.mem_base = res.MallocMemory(purpose, model_params_.memory_size - model_params_.zero_copy_mem_size); if (model_params_.mem_base == nullptr) { - return RT_FAILED; + return ACL_ERROR_GE_MEMORY_ALLOCATION; } } @@ -103,7 +103,7 @@ Status SingleOpModel::InitModelMem(StreamResource &res) { model_params_.weight_base = res.MallocWeight(purpose, model_params_.weight_size); if (model_params_.weight_base == nullptr) { // no need to free memory, for that was handled by StreamResources - return RT_FAILED; + return ACL_ERROR_GE_MEMORY_ALLOCATION; } auto weight_buffer = model_helper_.GetGeModel()->GetWeight(); @@ -118,8 +118,9 @@ Status SingleOpModel::InitModelMem(StreamResource &res) { Status SingleOpModel::ParseInputNode(const OpDescPtr &op_desc) { vector offsets = op_desc->GetOutputOffset(); if (offsets.size() != kDataOutputNum) { - GELOGE(PARAM_INVALID, "Data op should have only one output, but got %zu", op_desc->GetOutputOffset().size()); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Data op should have only one output, but got %zu", + op_desc->GetOutputOffset().size()); + return ACL_ERROR_GE_PARAM_INVALID; } auto output_desc = op_desc->GetOutputDescPtr(0); @@ -155,8 +156,8 @@ Status SingleOpModel::LoadAllNodes() { Graph graph = ge_model->GetGraph(); auto compute_graph = GraphUtils::GetComputeGraph(graph); if (compute_graph == nullptr) { - GELOGE(PARAM_INVALID, "[%s] compute_graph is null", model_name_.c_str()); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "[%s] compute_graph is null", model_name_.c_str()); + return ACL_ERROR_GE_INTERNAL_ERROR; } auto nodes = compute_graph->GetDirectNode(); @@ -248,27 +249,29 @@ Status SingleOpModel::BuildTaskList(SingleOp &single_op) { } else if (kernel_type == cce::ccKernelType::AI_CPU || kernel_type == cce::ccKernelType::CUST_AI_CPU) { GELOGD("Building AICPU_CC task"); OpTask *task = nullptr; - auto ret = BuildCpuKernelTask(task_def.kernel(), &task); + uint64_t singleop_kernel_id = aicpu_kernel_id++; + GELOGI("Build singleOp CCTask, kernel_id = %lu", singleop_kernel_id); + auto ret = BuildCpuKernelTask(task_def.kernel(), &task, singleop_kernel_id); if (ret != SUCCESS) { return ret; } single_op.tasks_.emplace_back(task); } else { - GELOGE(UNSUPPORTED, "Only TBE, AI_CPU, CUST_AI_CPU kernel are supported, but got %u", context.kernel_type()); - return UNSUPPORTED; + GELOGE(ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID, "Only TBE, AI_CPU, CUST_AI_CPU kernel are supported, but got %u", + context.kernel_type()); + return ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID; } } else if (task_type == RT_MODEL_TASK_KERNEL_EX) { GELOGD("Building AICPU_TF task"); AiCpuTask *aicpu_task = nullptr; bool depend_compute_flag = false; - uint64_t singleop_sessionid = aicpu_sessionid++; - GELOGI("Build singleOp, sessionId = %lu", singleop_sessionid); - auto ret = BuildKernelExTask(task_def.kernel_ex(), &aicpu_task, false, depend_compute_flag, singleop_sessionid); + uint64_t singleop_kernel_id = aicpu_kernel_id++; + GELOGI("Build singleOp TfTask, kernel_id = %lu", singleop_kernel_id); + auto ret = BuildKernelExTask(task_def.kernel_ex(), &aicpu_task, false, depend_compute_flag, singleop_kernel_id); if (ret != SUCCESS) { return ret; } single_op.tasks_.emplace_back(aicpu_task); - single_op.SetSessionID(singleop_sessionid); } else { // skip GELOGD("Skip task type: %d", static_cast(task_type)); @@ -279,7 +282,7 @@ Status SingleOpModel::BuildTaskList(SingleOp &single_op) { void SingleOpModel::ParseArgTable(TbeOpTask *task, SingleOp &op) { if (task == nullptr) { - GELOGE(PARAM_INVALID, "tbe op task is nullptr"); + GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "tbe op task is nullptr"); return; } // args: addr1, addr2, addr3 ... @@ -302,14 +305,14 @@ Status SingleOpModel::BuildKernelTask(const domi::KernelDef &kernel_def, TbeOpTa const auto &context = kernel_def.context(); auto iter = op_list_.find(context.op_index()); if (iter == op_list_.end()) { - GELOGE(INTERNAL_ERROR, "op desc not found. op index = %u", context.op_index()); - return INTERNAL_ERROR; + GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "op desc not found. op index = %u", context.op_index()); + return ACL_ERROR_GE_INTERNAL_ERROR; } auto *tbe_task = new (std::nothrow) TbeOpTask(); if (tbe_task == nullptr) { - GELOGE(MEMALLOC_FAILED, "create tbe op task failed"); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "create tbe op task failed"); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } auto builder = TbeTaskBuilder(model_name_, iter->second, kernel_def); @@ -325,20 +328,20 @@ Status SingleOpModel::BuildKernelTask(const domi::KernelDef &kernel_def, TbeOpTa } Status SingleOpModel::BuildKernelExTask(const domi::KernelExDef &kernel_def, AiCpuTask **task, bool dynamic_flag, - bool &depend_compute_flag, uint64_t session_id) { + bool &depend_compute_flag, uint64_t kernel_id) { auto iter = op_list_.find(kernel_def.op_index()); if (iter == op_list_.end()) { - GELOGE(INTERNAL_ERROR, "op desc not found. op index = %u", kernel_def.op_index()); - return INTERNAL_ERROR; + GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "op desc not found. op index = %u", kernel_def.op_index()); + return ACL_ERROR_GE_INTERNAL_ERROR; } std::unique_ptr aicpu_task(new (std::nothrow) AiCpuTask()); if (aicpu_task == nullptr) { - GELOGE(MEMALLOC_FAILED, "create aicpu_TF op task failed"); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "create aicpu_TF op task failed"); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } auto builder = AiCpuTaskBuilder(iter->second->GetOpDesc(), kernel_def); - auto ret = builder.BuildTask(*aicpu_task, model_params_, dynamic_flag, session_id); + auto ret = builder.BuildTask(*aicpu_task, model_params_, dynamic_flag, kernel_id); if (ret != SUCCESS) { GELOGE(ret, "build aicpu_TF op task failed"); return ret; @@ -349,21 +352,21 @@ Status SingleOpModel::BuildKernelExTask(const domi::KernelExDef &kernel_def, AiC return SUCCESS; } -Status SingleOpModel::BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTask **task) { +Status SingleOpModel::BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTask **task, uint64_t kernel_id) { const auto &context = kernel_def.context(); auto iter = op_list_.find(context.op_index()); if (iter == op_list_.end()) { - GELOGE(INTERNAL_ERROR, "op desc not found. op index = %u", context.op_index()); - return INTERNAL_ERROR; + GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "op desc not found. op index = %u", context.op_index()); + return ACL_ERROR_GE_INTERNAL_ERROR; } std::unique_ptr aicpucc_task(new (std::nothrow) AiCpuCCTask()); if (aicpucc_task == nullptr) { - GELOGE(MEMALLOC_FAILED, "create aicpu_CC op task failed"); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "create aicpu_CC op task failed"); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } auto builder = AiCpuCCTaskBuilder(iter->second->GetOpDesc(), kernel_def); - auto ret = builder.BuildTask(*aicpucc_task); + auto ret = builder.BuildTask(*aicpucc_task, kernel_id); if (ret != SUCCESS) { GELOGE(ret, "build aicpu_CC op task failed"); return ret; @@ -392,11 +395,14 @@ Status SingleOpModel::BuildModelTaskKernel(const TaskDef &task_def, DynamicSingl } else if (kernel_type == cce::ccKernelType::AI_CPU || kernel_type == cce::ccKernelType::CUST_AI_CPU) { GELOGD("Building AICPU_CC task"); OpTask *task = nullptr; - GE_CHK_STATUS_RET_NOLOG(BuildCpuKernelTask(task_def.kernel(), &task)); + uint64_t dynamic_singleop_kernel_id = aicpu_kernel_id++; + GELOGI("Build dynamic singleOp CCTask, kernel_id = %lu", dynamic_singleop_kernel_id); + GE_CHK_STATUS_RET_NOLOG(BuildCpuKernelTask(task_def.kernel(), &task, dynamic_singleop_kernel_id)); single_op.op_task_.reset(task); } else { - GELOGE(UNSUPPORTED, "Only TBE, AI_CPU, CUST_AI_CPU kernel are supported, but got %u", context.kernel_type()); - return UNSUPPORTED; + GELOGE(ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID, "Only TBE, AI_CPU, CUST_AI_CPU kernel are supported, but got %u", + context.kernel_type()); + return ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID; } return SUCCESS; } @@ -419,27 +425,26 @@ Status SingleOpModel::BuildTaskListForDynamicOp(DynamicSingleOp &single_op) { GE_CHK_STATUS_RET_NOLOG(BuildModelTaskKernel(task_def, single_op)); } else if (task_type == RT_MODEL_TASK_KERNEL_EX) { if (single_op.op_task_ != nullptr) { - GELOGE(UNSUPPORTED, "Do not support dynamic op with multiple tasks."); - return UNSUPPORTED; + GELOGE(ACL_ERROR_GE_OP_TASK_TYPE_INVALID, "Do not support dynamic op with multiple tasks."); + return ACL_ERROR_GE_OP_TASK_TYPE_INVALID; } GELOGD("Building AICPU_TF task"); AiCpuTask *aicpu_task = nullptr; bool depend_compute_flag = false; - uint64_t dynamic_singleop_sessionid = aicpu_sessionid++; - GELOGI("Build dynamic singleOp, sessionId = %lu", dynamic_singleop_sessionid); + uint64_t dynamic_singleop_kernel_id = aicpu_kernel_id++; + GELOGI("Build dynamic singleOp TfTask, kernel_id = %lu", dynamic_singleop_kernel_id); GE_CHK_STATUS_RET_NOLOG( - BuildKernelExTask(task_def.kernel_ex(), &aicpu_task, true, depend_compute_flag, dynamic_singleop_sessionid)); + BuildKernelExTask(task_def.kernel_ex(), &aicpu_task, true, depend_compute_flag, dynamic_singleop_kernel_id)); if (depend_compute_flag) { if (i >= tasks.size() - 1) { - GELOGE(FAILED, "The copy task of the fourth operator was not found."); - return FAILED; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "The copy task of the fourth operator was not found."); + return ACL_ERROR_GE_PARAM_INVALID; } ++i; const TaskDef ©_task_def = tasks[i]; GE_CHK_STATUS_RET_NOLOG(aicpu_task->SetMemCopyTask(copy_task_def.kernel_ex())); } single_op.op_task_.reset(aicpu_task); - single_op.SetSessionID(dynamic_singleop_sessionid); } else { // skip GELOGD("Skip task type: %d", static_cast(task_type)); diff --git a/src/ge/single_op/single_op_model.h b/src/ge/single_op/single_op_model.h index 09b90050..75de359f 100644 --- a/src/ge/single_op/single_op_model.h +++ b/src/ge/single_op/single_op_model.h @@ -67,8 +67,8 @@ class SingleOpModel { Status BuildTaskListForDynamicOp(DynamicSingleOp &dynamic_single_op); Status BuildKernelTask(const domi::KernelDef &kernel_def, TbeOpTask **task); Status BuildKernelExTask(const domi::KernelExDef &kernel_def, AiCpuTask **task, bool dynamic_flag, - bool &depend_compute_flag, uint64_t session_id); - Status BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTask **task); + bool &depend_compute_flag, uint64_t kernel_id); + Status BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTask **task, uint64_t kernel_id); Status BuildModelTaskKernel(const domi::TaskDef &task_def, DynamicSingleOp &single_op); static void ParseOpModelParams(ModelHelper &model_helper, SingleOpModelParam ¶m); diff --git a/src/ge/single_op/stream_resource.cc b/src/ge/single_op/stream_resource.cc index c2b93974..06a68465 100644 --- a/src/ge/single_op/stream_resource.cc +++ b/src/ge/single_op/stream_resource.cc @@ -155,8 +155,8 @@ Status StreamResource::BuildOperator(const string &model_name, const ModelData & auto new_op = std::unique_ptr(new (std::nothrow) SingleOp(&stream_mu_, stream_)); if (new_op == nullptr) { - GELOGE(MEMALLOC_FAILED, "new SingleOp failed"); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "new SingleOp failed"); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } GELOGI("To build operator: %s", model_name.c_str()); diff --git a/src/ge/single_op/task/aicpu_kernel_task_builder.cc b/src/ge/single_op/task/aicpu_kernel_task_builder.cc index 8cb2a6da..768d779c 100644 --- a/src/ge/single_op/task/aicpu_kernel_task_builder.cc +++ b/src/ge/single_op/task/aicpu_kernel_task_builder.cc @@ -25,20 +25,20 @@ AiCpuCCTaskBuilder::AiCpuCCTaskBuilder(const OpDescPtr &op_desc, const domi::Ker Status AiCpuCCTaskBuilder::SetKernelArgs(AiCpuCCTask &task) { size_t aicpu_arg_size = kernel_def_.args_size(); if (aicpu_arg_size <= 0) { - GELOGE(RT_FAILED, "aicpu_arg_size is invalid, value = %zu", aicpu_arg_size); - return RT_FAILED; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "aicpu_arg_size is invalid, value = %zu", aicpu_arg_size); + return ACL_ERROR_GE_PARAM_INVALID; } std::unique_ptr aicpu_args; aicpu_args.reset(new (std::nothrow) uint8_t[aicpu_arg_size]()); if (aicpu_args == nullptr) { - GELOGE(RT_FAILED, "malloc failed, size = %zu", aicpu_arg_size); - return RT_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "malloc failed, size = %zu", aicpu_arg_size); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } auto err = memcpy_s(aicpu_args.get(), aicpu_arg_size, kernel_def_.args().data(), aicpu_arg_size); if (err != EOK) { - GELOGE(RT_FAILED, "memcpy_s args failed, size = %zu, err = %d", aicpu_arg_size, err); - return RT_FAILED; + GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "memcpy_s args failed, size = %zu, err = %d", aicpu_arg_size, err); + return ACL_ERROR_GE_INTERNAL_ERROR; } task.SetIoAddr(aicpu_args.get() + sizeof(aicpu::AicpuParamHead)); @@ -46,7 +46,7 @@ Status AiCpuCCTaskBuilder::SetKernelArgs(AiCpuCCTask &task) { return SUCCESS; } -Status AiCpuCCTaskBuilder::BuildTask(AiCpuCCTask &task) { +Status AiCpuCCTaskBuilder::BuildTask(AiCpuCCTask &task, uint64_t kernel_id) { auto ret = SetKernelArgs(task); if (ret != SUCCESS) { return ret; @@ -76,7 +76,7 @@ Status AiCpuCCTaskBuilder::BuildTask(AiCpuCCTask &task) { "task def kernel_ext_info.size=%zu, but kernel_ext_info_size=%u.", kernel_ext_info.size(), kernel_ext_info_size); - ret = task.SetExtInfoAndType(kernel_ext_info); + ret = task.SetExtInfoAndType(kernel_ext_info, kernel_id); if (ret != SUCCESS) { GELOGE(ret, "Init ext info failed."); return ret; diff --git a/src/ge/single_op/task/aicpu_kernel_task_builder.h b/src/ge/single_op/task/aicpu_kernel_task_builder.h index f9ca0530..e77e3c10 100644 --- a/src/ge/single_op/task/aicpu_kernel_task_builder.h +++ b/src/ge/single_op/task/aicpu_kernel_task_builder.h @@ -30,7 +30,7 @@ class AiCpuCCTaskBuilder { explicit AiCpuCCTaskBuilder(const OpDescPtr &op_desc, const domi::KernelDef &kernel_def); ~AiCpuCCTaskBuilder() = default; - Status BuildTask(AiCpuCCTask &task); + Status BuildTask(AiCpuCCTask &task, uint64_t kernel_id); private: Status SetKernelArgs(AiCpuCCTask &task); diff --git a/src/ge/single_op/task/aicpu_task_builder.cc b/src/ge/single_op/task/aicpu_task_builder.cc index aa26d049..11199256 100644 --- a/src/ge/single_op/task/aicpu_task_builder.cc +++ b/src/ge/single_op/task/aicpu_task_builder.cc @@ -30,8 +30,8 @@ Status AiCpuTaskBuilder::SetInputOutputAddr(void **io_addr, const std::vector(addresses.data()); @@ -39,8 +39,8 @@ Status AiCpuTaskBuilder::SetInputOutputAddr(void **io_addr, const std::vector(reinterpret_cast(io_addr)); @@ -65,16 +65,16 @@ Status AiCpuTaskBuilder::SetKernelArgs(void **args, STR_FWK_OP_KERNEL &fwk_op_ke void *fwk_op_args = nullptr; auto rt_ret = rtMalloc(&fwk_op_args, sizeof(STR_FWK_OP_KERNEL), RT_MEMORY_HBM); if (rt_ret != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "malloc arg memory failed, ret = %d", rt_ret); - return RT_FAILED; + GELOGE(rt_ret, "malloc arg memory failed, ret = %d", rt_ret); + return rt_ret; } rt_ret = rtMemcpy(fwk_op_args, sizeof(STR_FWK_OP_KERNEL), &fwk_op_kernel, sizeof(STR_FWK_OP_KERNEL), RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { (void)rtFree(fwk_op_args); - GELOGE(RT_FAILED, "copy args failed, ret = %d", rt_ret); - return RT_FAILED; + GELOGE(rt_ret, "copy args failed, ret = %d", rt_ret); + return rt_ret; } *args = fwk_op_args; return SUCCESS; @@ -83,9 +83,9 @@ Status AiCpuTaskBuilder::SetKernelArgs(void **args, STR_FWK_OP_KERNEL &fwk_op_ke Status AiCpuTaskBuilder::InitWorkspaceAndIO(void **io_addr, void **kernel_workspace, const SingleOpModelParam ¶m, bool dynamic_flag) { if (kernel_def_.args_size() > sizeof(STR_FWK_OP_KERNEL)) { - GELOGE(PARAM_INVALID, "sizeof STR_FWK_OP_KERNEL is: %lu, but args_size is: %d", sizeof(STR_FWK_OP_KERNEL), - kernel_def_.args_size()); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "sizeof STR_FWK_OP_KERNEL is: %lu, but args_size is: %d", + sizeof(STR_FWK_OP_KERNEL), kernel_def_.args_size()); + return ACL_ERROR_GE_PARAM_INVALID; } auto addresses = BuildTaskUtils::GetAddresses(op_desc_, param); auto ws_addr_vec = addresses.at(BuildTaskUtils::kAddressIndexWorkspace); @@ -94,8 +94,8 @@ Status AiCpuTaskBuilder::InitWorkspaceAndIO(void **io_addr, void **kernel_worksp GE_CHK_RT_RET(rtMalloc(kernel_workspace, kernel_def_.task_info_size(), RT_MEMORY_HBM)); } else { if (ws_addr_vec.empty()) { - GELOGE(PARAM_INVALID, "workspace Data Address is empty."); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "workspace Data Address is empty."); + return ACL_ERROR_GE_PARAM_INVALID; } *kernel_workspace = ws_addr_vec[0]; } @@ -110,7 +110,7 @@ Status AiCpuTaskBuilder::InitWorkspaceAndIO(void **io_addr, void **kernel_worksp } Status AiCpuTaskBuilder::BuildTask(ge::AiCpuTask &task, const SingleOpModelParam ¶m, bool dynamic_flag, - uint64_t session_id) { + uint64_t kernel_id) { GE_CHK_STATUS_RET_NOLOG(InitWorkspaceAndIO(&task.io_addr_, &task.workspace_addr_, param, dynamic_flag)); STR_FWK_OP_KERNEL fwk_op_kernel = {0}; @@ -129,7 +129,7 @@ Status AiCpuTaskBuilder::BuildTask(ge::AiCpuTask &task, const SingleOpModelParam GE_CHK_BOOL_RET_STATUS(kernel_ext_info.size() == kernel_ext_info_size, FAILED, "task def kernel_ext_info.size=%zu, but kernel_ext_info_size=%u.", kernel_ext_info.size(), kernel_ext_info_size); - GE_CHK_STATUS_RET(task.SetExtInfoAndType(kernel_ext_info), "Init ext info failed."); + GE_CHK_STATUS_RET(task.SetExtInfoAndType(kernel_ext_info, kernel_id), "Init ext info failed."); if (task.ext_info_addr_dev_ != nullptr) { fwk_op_kernel.fwkKernelBase.fwk_kernel.extInfoAddr = reinterpret_cast(task.ext_info_addr_dev_); @@ -137,13 +137,9 @@ Status AiCpuTaskBuilder::BuildTask(ge::AiCpuTask &task, const SingleOpModelParam } GE_CHK_STATUS_RET(task.InitForSummaryAndCopy(), "AiCpuTask init for summary and copy task failed."); - // Create session - fwk_op_kernel.fwkKernelBase.fwk_kernel.sessionID = session_id; - GELOGI("Begin to CreateAicpuSession, session id: %lu", session_id); - GE_CHECK_NOTNULL(ModelManager::GetInstance()); - GE_IF_BOOL_EXEC(ModelManager::GetInstance()->CreateAicpuSession(session_id) != SUCCESS, - GELOGE(FAILED, "CreateAicpuSession error. session id: %lu", session_id); - return FAILED;) + fwk_op_kernel.fwkKernelBase.fwk_kernel.sessionID = ULLONG_MAX; + fwk_op_kernel.fwkKernelBase.fwk_kernel.kernelID = kernel_id; + fwk_op_kernel.fwkKernelBase.fwk_kernel.opType = aicpu::FWKAdapter::FWKOperateType::FWK_ADPT_KERNEL_RUN_NO_SESS; ret = SetKernelArgs(&task.args_, fwk_op_kernel); if (ret != SUCCESS) { return ret; diff --git a/src/ge/single_op/task/aicpu_task_builder.h b/src/ge/single_op/task/aicpu_task_builder.h index 76ccb161..302c9c7d 100644 --- a/src/ge/single_op/task/aicpu_task_builder.h +++ b/src/ge/single_op/task/aicpu_task_builder.h @@ -29,7 +29,7 @@ class AiCpuTaskBuilder { AiCpuTaskBuilder(const OpDescPtr &op_desc, const domi::KernelExDef &kernel_def); ~AiCpuTaskBuilder() = default; - Status BuildTask(AiCpuTask &task, const SingleOpModelParam ¶m, bool dynamic_flag, uint64_t session_id); + Status BuildTask(AiCpuTask &task, const SingleOpModelParam ¶m, bool dynamic_flag, uint64_t kernel_id); private: static Status SetKernelArgs(void **args, STR_FWK_OP_KERNEL &kernel); diff --git a/src/ge/single_op/task/op_task.cc b/src/ge/single_op/task/op_task.cc index edd69c07..9e49db0a 100644 --- a/src/ge/single_op/task/op_task.cc +++ b/src/ge/single_op/task/op_task.cc @@ -245,7 +245,7 @@ AiCpuBaseTask::~AiCpuBaseTask() { } } -Status AiCpuBaseTask::SetExtInfoAndType(const std::string &kernel_ext_info) { +Status AiCpuBaseTask::SetExtInfoAndType(const std::string &kernel_ext_info, uint64_t kernel_id) { if (kernel_ext_info.empty()) { GELOGI("Kernel_ext_info is empty, no need copy to device."); return SUCCESS; @@ -266,9 +266,11 @@ Status AiCpuBaseTask::SetExtInfoAndType(const std::string &kernel_ext_info) { return ret; } - GE_CHK_RT_RET(rtMalloc(&ext_info_addr_dev_, kernel_ext_info.size(), RT_MEMORY_HBM)); - GE_CHK_RT_RET(rtMemcpy(ext_info_addr_dev_, kernel_ext_info.size(), kernel_ext_info.data(), kernel_ext_info.size(), - RT_MEMCPY_HOST_TO_DEVICE)); + GE_CHK_STATUS_RET(aicpu_ext_handle_->UpdateSessionInfo(ULLONG_MAX, kernel_id, false), "UpdateSessionInfo failed."); + + GE_CHK_RT_RET(rtMalloc(&ext_info_addr_dev_, aicpu_ext_handle_->GetExtInfoLen(), RT_MEMORY_HBM)); + GE_CHK_RT_RET(rtMemcpy(ext_info_addr_dev_, aicpu_ext_handle_->GetExtInfoLen(), aicpu_ext_handle_->GetExtInfo(), + aicpu_ext_handle_->GetExtInfoLen(), RT_MEMCPY_HOST_TO_DEVICE)); return SUCCESS; } @@ -668,8 +670,8 @@ Status AiCpuCCTask::LaunchKernel(rtStream_t stream) { static_cast(kernel_name_.data()), block_dim_, args_.get(), static_cast(arg_size_), sm_desc, stream, dump_flag_); if (ret != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "Invoke rtCpuKernelLaunch failed. ret = %d", ret); - return RT_FAILED; + GELOGE(ret, "Invoke rtCpuKernelLaunch failed. ret = %d", ret); + return ret; } GELOGD("Invoke rtCpuKernelLaunch succeeded"); diff --git a/src/ge/single_op/task/op_task.h b/src/ge/single_op/task/op_task.h index 2975a900..87cfe903 100644 --- a/src/ge/single_op/task/op_task.h +++ b/src/ge/single_op/task/op_task.h @@ -118,7 +118,7 @@ class AiCpuBaseTask : public OpTask { const UnknowShapeOpType GetUnknownType() const { return unknown_type_; } protected: - Status SetExtInfoAndType(const std::string &kernel_ext_info); + Status SetExtInfoAndType(const std::string &kernel_ext_info, uint64_t kernel_id); Status UpdateExtInfo(const std::vector &input_desc, std::vector &output_desc, rtStream_t stream); diff --git a/src/ge/single_op/task/tbe_task_builder.cc b/src/ge/single_op/task/tbe_task_builder.cc index 935c62a3..594352aa 100644 --- a/src/ge/single_op/task/tbe_task_builder.cc +++ b/src/ge/single_op/task/tbe_task_builder.cc @@ -91,9 +91,9 @@ Status TbeTaskBuilder::DoRegisterBinary(const OpKernelBin &kernel_bin, void **bi binary.magic = param.core_type == 0 ? RT_DEV_BINARY_MAGIC_ELF : RT_DEV_BINARY_MAGIC_ELF_AIVEC; auto ret = rtDevBinaryRegister(&binary, bin_handle); if (ret != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "rtDevBinaryRegister failed, bin key = %s, core_type = %ld, rt ret = %d", stub_name_.c_str(), + GELOGE(ret, "rtDevBinaryRegister failed, bin key = %s, core_type = %ld, rt ret = %d", stub_name_.c_str(), param.core_type, static_cast(ret)); - return RT_FAILED; + return ret; } return SUCCESS; @@ -106,9 +106,9 @@ Status TbeTaskBuilder::DoRegisterMeta(void *bin_handle) { if (!meta_data.empty()) { auto rt_ret = rtMetadataRegister(bin_handle, meta_data.c_str()); if (rt_ret != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "rtMetadataRegister failed. bin key = %s, meta_data = %s, rt ret = %d", stub_name_.c_str(), + GELOGE(rt_ret, "rtMetadataRegister failed. bin key = %s, meta_data = %s, rt ret = %d", stub_name_.c_str(), meta_data.c_str(), static_cast(rt_ret)); - return RT_FAILED; + return rt_ret; } } @@ -118,9 +118,9 @@ Status TbeTaskBuilder::DoRegisterMeta(void *bin_handle) { Status TbeTaskBuilder::DoRegisterFunction(void *bin_handle, const char *stub_name, const char *kernel_name) { auto rt_ret = rtFunctionRegister(bin_handle, stub_name, stub_name, kernel_name, FUNC_MODE_NORMAL); if (rt_ret != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "rtFunctionRegister failed. bin key = %s, kernel name = %s, rt ret = %d", stub_name, kernel_name, + GELOGE(rt_ret, "rtFunctionRegister failed. bin key = %s, kernel name = %s, rt ret = %d", stub_name, kernel_name, static_cast(rt_ret)); - return RT_FAILED; + return rt_ret; } return SUCCESS; @@ -173,14 +173,15 @@ Status TbeTaskBuilder::RegisterKernel(TbeOpTask &task, const SingleOpModelParam auto tbe_kernel = GetTbeKernel(op_desc_); if (tbe_kernel == nullptr) { - GELOGE(PARAM_INVALID, "OP EXT ATTR NAME TBE_KERNEL not found. op = %s", op_desc_->GetName().c_str()); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "OP EXT ATTR NAME TBE_KERNEL not found. op = %s", + op_desc_->GetName().c_str()); + return ACL_ERROR_GE_INTERNAL_ERROR; } auto holder = std::unique_ptr(new (std::nothrow) KernelHolder(stub_func, tbe_kernel)); if (holder == nullptr) { - GELOGE(MEMALLOC_FAILED, "create KernelHodler failed."); - return MEMALLOC_FAILED; + GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "create KernelHodler failed."); + return ACL_ERROR_GE_MEMORY_ALLOCATION; } void *bin_handle = nullptr; @@ -189,8 +190,8 @@ Status TbeTaskBuilder::RegisterKernel(TbeOpTask &task, const SingleOpModelParam holder->SetBinHandle(bin_handle); if (!registry.AddKernel(stub_name_, std::move(holder))) { // should not happen. only one thread can reach here - GELOGE(INTERNAL_ERROR, "Add kernel failed. stub name = %s", stub_name_.c_str()); - return INTERNAL_ERROR; + GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "Add kernel failed. stub name = %s", stub_name_.c_str()); + return ACL_ERROR_GE_INTERNAL_ERROR; } } } @@ -218,15 +219,15 @@ Status TbeTaskBuilder::GetSmDesc(void **sm_desc, const SingleOpModelParam ¶m auto rtRet = rtMemAllocManaged(sm_desc, sm_desc_str.size(), RT_MEMORY_SPM); if (rtRet != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "rtMemAllocManaged failed, ret: %d", static_cast(rtRet)); - return RT_FAILED; + GELOGE(rtRet, "rtMemAllocManaged failed, ret: %d", static_cast(rtRet)); + return rtRet; } rtRet = rtMemcpy(*sm_desc, sm_desc_str.size(), sm_desc_str.data(), sm_desc_str.size(), RT_MEMCPY_HOST_TO_DEVICE); if (rtRet != RT_ERROR_NONE) { (void)rtMemFreeManaged(*sm_desc); - GELOGE(RT_FAILED, "rtMemcpy, ret: %d", static_cast(rtRet)); - return RT_FAILED; + GELOGE(rtRet, "rtMemcpy, ret: %d", static_cast(rtRet)); + return rtRet; } } @@ -240,8 +241,8 @@ Status TbeTaskBuilder::SetKernelArgs(TbeOpTask &task, const SingleOpModelParam & auto rtRet = rtMemcpy(args.get(), arg_size, kernel_def_.args().data(), arg_size, RT_MEMCPY_HOST_TO_HOST); if (rtRet != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "rtMemcpy args failed, size = %zu, ret = %d", arg_size, static_cast(rtRet)); - return RT_FAILED; + GELOGE(rtRet, "rtMemcpy args failed, size = %zu, ret = %d", arg_size, static_cast(rtRet)); + return rtRet; } const domi::KernelContext &context = kernel_def_.context(); @@ -259,8 +260,8 @@ Status TbeTaskBuilder::SetKernelArgs(TbeOpTask &task, const SingleOpModelParam & uint64_t src_len = sizeof(void *) * tensor_device_addr_vec.size(); rtRet = rtMemcpy(args.get() + offset, arg_size - offset, src_addr, src_len, RT_MEMCPY_HOST_TO_HOST); if (rtRet != RT_ERROR_NONE) { - GELOGE(RT_FAILED, "rtMemcpy addresses failed, ret = %d", static_cast(rtRet)); - return RT_FAILED; + GELOGE(rtRet, "rtMemcpy addresses failed, ret = %d", static_cast(rtRet)); + return rtRet; } } @@ -285,8 +286,8 @@ Status TbeTaskBuilder::BuildTask(TbeOpTask &task, const SingleOpModelParam ¶ void *stub_func = nullptr; auto rtRet = rtGetFunctionByName(stub_name_.c_str(), &stub_func); if (rtRet != SUCCESS) { - GELOGE(RT_FAILED, "rtGetFunctionByName failed."); - return RT_FAILED; + GELOGE(rtRet, "rtGetFunctionByName failed."); + return rtRet; } task.SetStubFunc(stub_name_, stub_func); @@ -299,8 +300,8 @@ Status TbeTaskBuilder::InitTilingInfo(TbeOpTask &task) { (void)AttrUtils::GetInt(op_desc_, kAttrOpParamSize, max_size); GELOGD("Got op param size by key: %s, ret = %ld", kAttrOpParamSize, max_size); if (max_size <= 0) { - GELOGE(PARAM_INVALID, "[%s] Invalid op_param_size: %ld.", op_desc_->GetName().c_str(), max_size); - return PARAM_INVALID; + GELOGE(ACL_ERROR_GE_PARAM_INVALID, "[%s] Invalid op_param_size: %ld.", op_desc_->GetName().c_str(), max_size); + return ACL_ERROR_GE_PARAM_INVALID; } void *tiling_buffer = nullptr; diff --git a/third_party/fwkacllib/inc/cce/aicpu_engine.h b/third_party/fwkacllib/inc/cce/aicpu_engine.h index 740f1200..8bf0bdb6 100644 --- a/third_party/fwkacllib/inc/cce/aicpu_engine.h +++ b/third_party/fwkacllib/inc/cce/aicpu_engine.h @@ -17,6 +17,8 @@ #ifndef AICPU_ENGINE_H__ #define AICPU_ENGINE_H__ +#include + #ifdef __cplusplus extern "C" { #endif @@ -36,12 +38,23 @@ typedef enum { /** * @ingroup aicpu engine * @brief aeCallInterface: - * a interface to call a function in a op kernfel lib + * a interface to call a function in a op kernfel lib * @param [in] addr void *, should be STR_KERNEL * format * @return aeStatus_t */ aeStatus_t aeCallInterface(void *addr); +/** + * @ingroup aicpu engine + * @brief aeBatchLoadKernelSo: + * a interface to load kernel so + * @param [in] loadSoNum load so number + * @param [in] soPaths load so paths + * @param [in] soNames load so names + * @return aeStatus_t + */ +aeStatus_t aeBatchLoadKernelSo(const uint32_t loadSoNum, const char *soPaths[], const char *soNames[]); + #ifdef __cplusplus } #endif diff --git a/third_party/fwkacllib/inc/cce/aicpu_engine_struct.h b/third_party/fwkacllib/inc/cce/aicpu_engine_struct.h index d61c981d..a5f43be9 100644 --- a/third_party/fwkacllib/inc/cce/aicpu_engine_struct.h +++ b/third_party/fwkacllib/inc/cce/aicpu_engine_struct.h @@ -40,6 +40,12 @@ typedef struct { } fwkKernelBase; } __attribute__((packed)) STR_FWK_OP_KERNEL; +struct SessionInfo { + uint64_t sessionId; + uint64_t kernelId; + bool sessFlag; +} __attribute__((packed)); + #ifdef __cplusplus } #endif diff --git a/third_party/fwkacllib/inc/cce/fwk_adpt_struct.h b/third_party/fwkacllib/inc/cce/fwk_adpt_struct.h index 957117cc..79d94023 100644 --- a/third_party/fwkacllib/inc/cce/fwk_adpt_struct.h +++ b/third_party/fwkacllib/inc/cce/fwk_adpt_struct.h @@ -48,7 +48,8 @@ enum FWKOperateType { FWK_ADPT_KERNEL_RUN, FWK_ADPT_KERNEL_DESTROY, FWK_ADPT_SESSION_DESTROY, - FWK_ADPT_SINGLE_OP_RUN + FWK_ADPT_SINGLE_OP_RUN, + FWK_ADPT_KERNEL_RUN_NO_SESS, }; // Extend Info type for task @@ -58,6 +59,7 @@ enum FWKTaskExtInfoType { FWK_ADPT_EXT_OUTPUT_SHAPE, FWK_ADPT_EXT_UPDATE_ADDR, FWK_ADPT_EXT_OP_NAME, + FWK_ADPT_EXT_SESSION_INFO, FWK_ADPT_EXT_INVALID }; diff --git a/third_party/fwkacllib/inc/hccl/hcom.h b/third_party/fwkacllib/inc/hccl/hcom.h index 90b96ac7..f147e4f9 100644 --- a/third_party/fwkacllib/inc/hccl/hcom.h +++ b/third_party/fwkacllib/inc/hccl/hcom.h @@ -96,7 +96,22 @@ extern HcclResult hcom_all_gather(const char *tag, void *inputPtr, void *outputP */ extern HcclResult hcom_all_reduce(const char *tag, void *inputPtr, void *outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op, const char *group, rtStream_t stream); - +/** + * @brief reduce operator. + * + * @param tag A string identifying the tag of the operator. + * @param inputPtr A pointer identifying the input data address of the operator. + * @param outputPtr A pointer identifying the output data address of the operator. + * @param count An integer(u64) identifying the number of the output data. + * @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32. + * @param op The reduction type of the operator, must be one of the following types: sum, min, max, prod. + * @param root An integer(u32) identifying the the root rank in the operator. + * @param group A string identifying the group name of ranks participating in the operator. + * @param stream A pointer identifying the stream information. + * @return HcclResult + */ +extern HcclResult hcom_reduce(const char *tag, void *inputPtr, void *outputPtr, u64 count, HcclDataType dataType, + HcclReduceOp op, u32 root, const char *group, rtStream_t stream); /** * @brief Broadcast operator. * diff --git a/third_party/fwkacllib/inc/register/op_registry.h b/third_party/fwkacllib/inc/register/op_registry.h index 3feea0df..2677a10b 100644 --- a/third_party/fwkacllib/inc/register/op_registry.h +++ b/third_party/fwkacllib/inc/register/op_registry.h @@ -70,12 +70,16 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistry { domi::ParseSubgraphFunc GetParseSubgraphPostFunc(const std::string &op_type); + Status GetParseSubgraphPostFunc(const std::string &op_type, domi::ParseSubgraphFuncV2 &parse_subgraph_func); + domi::ImplyType GetImplyTypeByOriOpType(const std::string &ori_optype); const std::vector &GetRemoveInputConfigure(const std::string &ori_optype) const; bool GetOmTypeByOriOpType(const std::string &ori_optype, std::string &om_type); + ParseOpToGraphFunc GetParseOpToGraphFunc(const std::string &op_type, const std::string &ori_type); + private: std::unordered_map op_run_mode_map_; std::unordered_map op_parse_params_fn_map_; @@ -85,6 +89,10 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistry { std::unordered_map op_types_to_parse_subgraph_post_func_; std::unordered_map> remove_input_configure_map_; std::unordered_map origin_type_to_om_type_; + std::unordered_map parse_op_to_graph_fn_map_; +#ifndef ONLY_COMPILE_OPEN_SRC + std::unordered_map op_types_to_parse_subgraph_post_func_v2_; +#endif }; } // namespace domi #endif // INC_REGISTER_OP_REGISTRY_H_ diff --git a/third_party/fwkacllib/inc/register/op_tiling.h b/third_party/fwkacllib/inc/register/op_tiling.h index 38370819..e94ad556 100644 --- a/third_party/fwkacllib/inc/register/op_tiling.h +++ b/third_party/fwkacllib/inc/register/op_tiling.h @@ -14,123 +14,18 @@ * limitations under the License. */ -#ifndef INC_OP_TILING_H_ -#define INC_OP_TILING_H_ +#ifndef INC_REGISTER_OP_TILING_H_ +#define INC_REGISTER_OP_TILING_H_ -#include "external/register/register_types.h" -#include "external/graph/tensor.h" #include "graph/debug/ge_attr_define.h" #include "graph/node.h" - -#include -#include -#include -#include -#include -#include -#include -#include "graph/node.h" - -#define REGISTER_OP_TILING_FUNC(optype, opfunc) \ - REGISTER_OP_TILING_FUNC_UNIQ_HELPER(optype, opfunc, __COUNTER__) - -#define REGISTER_OP_TILING_FUNC_UNIQ_HELPER(optype, opfunc, counter) \ - REGISTER_OP_TILING_FUNC_UNIQ(optype, opfunc, counter) - -#define REGISTER_OP_TILING_FUNC_UNIQ(optype, opfunc, counter) \ - static OpTilingInterf g_##optype##TilingInterf##counter(#optype, opfunc) +#include "register/op_tiling_registry.h" namespace optiling { -enum TensorArgType { - TA_NONE, - TA_SINGLE, - TA_LIST, -}; - - -using ByteBuffer = std::stringstream; - -struct TeOpTensor { - std::vector shape; - std::vector ori_shape; - std::string format; - std::string ori_format; - std::string dtype; - std::map attrs; -}; - - -struct TeOpTensorArg { - TensorArgType arg_type; - std::vector tensor; -}; - -struct OpRunInfo { - uint32_t block_dim; - std::vector workspaces; - ByteBuffer tiling_data; - bool clear_atomic; -}; - - -using TeOpAttrArgs = std::vector; -using TeConstTensorData = std::tuple; - -struct TeOpParas { - std::vector inputs; - std::vector outputs; - std::map const_inputs; - TeOpAttrArgs attrs; -}; - - -using OpTilingFunc = std::function; - -using OpTilingFuncPtr = bool(*)(const std::string&, const TeOpParas&, const nlohmann::json& , OpRunInfo&); - -class FMK_FUNC_HOST_VISIBILITY OpTilingInterf -{ -public: - OpTilingInterf(std::string op_type, OpTilingFunc func); - ~OpTilingInterf() = default; - static std::map &RegisteredOpInterf(); - static std::string OpTilingUuid; -}; - - -template -ByteBuffer& ByteBufferPut(ByteBuffer &buf, const T &value) -{ - buf.write(reinterpret_cast(&value), sizeof(value)); - buf.flush(); - return buf; -} - -template -ByteBuffer& ByteBufferGet(ByteBuffer &buf, T &value) -{ - buf.read(reinterpret_cast(&value), sizeof(value)); - return buf; -} - -inline size_t ByteBufferGetAll(ByteBuffer &buf, char *dest, size_t dest_len) -{ - size_t nread = 0; - size_t rn = 0; - do { - rn = buf.readsome(dest + nread, dest_len - nread); - nread += rn; - } while (rn > 0 && dest_len > nread); - - return nread; -} - - extern "C" ge::graphStatus OpParaCalculate(const ge::Node &node, OpRunInfo &run_info); extern "C" ge::graphStatus OpAtomicCalculate(const ge::Node &node, OpRunInfo &run_info); } -#endif // INC_OP_TILING_H_ +#endif // INC_REGISTER_OP_TILING_H_ diff --git a/third_party/fwkacllib/inc/register/op_tiling_registry.h b/third_party/fwkacllib/inc/register/op_tiling_registry.h new file mode 100644 index 00000000..dbc00fab --- /dev/null +++ b/third_party/fwkacllib/inc/register/op_tiling_registry.h @@ -0,0 +1,153 @@ +/** + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INC_REGISTER_OP_TILING_REGISTRY_H_ +#define INC_REGISTER_OP_TILING_REGISTRY_H_ + +#include +#include +#include +#include +#include +#include +#include "external/register/register_types.h" +#include "external/graph/tensor.h" + +#define REGISTER_OP_TILING_FUNC(optype, opfunc) \ + REGISTER_OP_TILING_FUNC_UNIQ_HELPER(optype, opfunc, __COUNTER__) + +#define REGISTER_OP_TILING_FUNC_UNIQ_HELPER(optype, opfunc, counter) \ + REGISTER_OP_TILING_FUNC_UNIQ(optype, opfunc, counter) + +#define REGISTER_OP_TILING_FUNC_UNIQ(optype, opfunc, counter) \ + static OpTilingInterf g_##optype##TilingInterf##counter(#optype, opfunc) + +#define REGISTER_OP_TILING_FUNC_NEW(optype, opfunc) \ + REGISTER_OP_TILING_UNIQ_HELPER(optype, opfunc, __COUNTER__) + +#define REGISTER_OP_TILING(optype, opfunc) \ + REGISTER_OP_TILING_UNIQ_HELPER(optype, opfunc, __COUNTER__) + +#define REGISTER_OP_TILING_UNIQ_HELPER(optype, opfunc, counter) \ + REGISTER_OP_TILING_UNIQ(optype, opfunc, counter) + +#define REGISTER_OP_TILING_UNIQ(optype, opfunc, counter) \ + static OpTilingRegistryInterf g_##optype##TilingRegistryInterf##counter(#optype, opfunc) + +namespace optiling { + +enum TensorArgType { + TA_NONE, + TA_SINGLE, + TA_LIST, +}; + +using ByteBuffer = std::stringstream; + +struct TeOpTensor { + std::vector shape; + std::vector ori_shape; + std::string format; + std::string ori_format; + std::string dtype; + std::map attrs; +}; + + +struct TeOpTensorArg { + TensorArgType arg_type; + std::vector tensor; +}; + +struct OpRunInfo { + uint32_t block_dim; + std::vector workspaces; + ByteBuffer tiling_data; + bool clear_atomic; +}; + + +using TeOpAttrArgs = std::vector; +using TeConstTensorData = std::tuple; + +struct TeOpParas { + std::vector inputs; + std::vector outputs; + std::map const_inputs; + TeOpAttrArgs attrs; + std::string op_type; +}; + + +using OpTilingFunc = std::function; + +using OpTilingFuncPtr = bool(*)(const std::string&, const TeOpParas&, const nlohmann::json& , OpRunInfo&); + +class FMK_FUNC_HOST_VISIBILITY OpTilingInterf +{ +public: + OpTilingInterf(std::string op_type, OpTilingFunc func); + ~OpTilingInterf() = default; + static std::map &RegisteredOpInterf(); + static std::string OpTilingUuid; +}; + +struct OpCompileInfo { + std::string str; + std::string key; +}; + +using OpTilingFuncNew = std::function; + +using OpTilingFuncPtrNew = bool(*)(const TeOpParas&, const OpCompileInfo& , OpRunInfo&); + +class FMK_FUNC_HOST_VISIBILITY OpTilingRegistryInterf { +public: + OpTilingRegistryInterf(std::string op_type, OpTilingFuncNew func); + ~OpTilingRegistryInterf() = default; + static std::map &RegisteredOpInterf(); +}; + +template +ByteBuffer& ByteBufferPut(ByteBuffer &buf, const T &value) +{ + buf.write(reinterpret_cast(&value), sizeof(value)); + buf.flush(); + return buf; +} + +template +ByteBuffer& ByteBufferGet(ByteBuffer &buf, T &value) +{ + buf.read(reinterpret_cast(&value), sizeof(value)); + return buf; +} + +inline size_t ByteBufferGetAll(ByteBuffer &buf, char *dest, size_t dest_len) +{ + size_t nread = 0; + size_t rn = 0; + do { + rn = buf.readsome(dest + nread, dest_len - nread); + nread += rn; + } while (rn > 0 && dest_len > nread); + + return nread; +} +} + +#endif // INC_REGISTER_OP_TILING_REGISTRY_H_ diff --git a/third_party/fwkacllib/inc/register/ops_kernel_builder_registry.h b/third_party/fwkacllib/inc/register/ops_kernel_builder_registry.h index 3c8e0470..8a8f3a18 100644 --- a/third_party/fwkacllib/inc/register/ops_kernel_builder_registry.h +++ b/third_party/fwkacllib/inc/register/ops_kernel_builder_registry.h @@ -26,6 +26,7 @@ using OpsKernelBuilderPtr = std::shared_ptr; class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpsKernelBuilderRegistry { public: + ~OpsKernelBuilderRegistry(); static OpsKernelBuilderRegistry &GetInstance(); void Register(const std::string &lib_name, const OpsKernelBuilderPtr &instance); @@ -37,6 +38,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpsKernelBuilderRegistry const std::map &GetAll() const; private: + OpsKernelBuilderRegistry() = default; std::map kernel_builders_; }; diff --git a/third_party/fwkacllib/inc/runtime/base.h b/third_party/fwkacllib/inc/runtime/base.h index 20b586d6..4e735438 100644 --- a/third_party/fwkacllib/inc/runtime/base.h +++ b/third_party/fwkacllib/inc/runtime/base.h @@ -1,18 +1,18 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd - * + * Copyright 2020 Huawei Technologies Co., Ltd + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * http://www.apache.org/licenses/LICENSE-2.0 - * + * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ +*/ #ifndef __CCE_RUNTIME_BASE_H__ #define __CCE_RUNTIME_BASE_H__ @@ -103,6 +103,7 @@ typedef enum tagRtError { RT_ERROR_MODEL_EXIT, RT_ERROR_MODEL_EXIT_STREAM_UNBIND, RT_ERROR_MODEL_EXIT_ID, + RT_ERROR_MODEL_ABORT_NORMAL, RT_ERROR_EVENT_BASE = 0x07050000, RT_ERROR_EVENT_NULL, diff --git a/third_party/fwkacllib/inc/runtime/config.h b/third_party/fwkacllib/inc/runtime/config.h index 6de84c02..c471f128 100644 --- a/third_party/fwkacllib/inc/runtime/config.h +++ b/third_party/fwkacllib/inc/runtime/config.h @@ -185,6 +185,14 @@ RTS_API rtError_t rtSetPlatformType(rtPlatformType_t platformType); */ RTS_API rtError_t rtMemGetL2Info(rtStream_t stream, void **ptr, uint32_t *size); +/** + * @ingroup + * @brief get runtime version. The version is returned as (1000 major + 10 minor). For example, RUNTIME 9.2 would be represented by 9020. + * @param [out] runtimeVersion + * @return RT_ERROR_NONE for ok + * @return RT_ERROR_INVALID_VALUE for error input + */ +RTS_API rtError_t rtGetRuntimeVersion(uint32_t *runtimeVersion); #if defined(__cplusplus) && !defined(COMPILE_OMG_PACKAGE) } #endif diff --git a/third_party/fwkacllib/inc/runtime/dev.h b/third_party/fwkacllib/inc/runtime/dev.h index fa844677..c70a2372 100644 --- a/third_party/fwkacllib/inc/runtime/dev.h +++ b/third_party/fwkacllib/inc/runtime/dev.h @@ -330,12 +330,12 @@ RTS_API rtError_t rtGetPairDevicesInfo(uint32_t devId, uint32_t otherDevId, int3 FEATURE_TYPE_MEMCPY = 0, FEATURE_TYPE_RSV, } rtFeatureType_t; - * @param [in] infoType info type + * @param [in] featureInfo info type typedef enum tagMemcpyInfo { MEMCPY_INFO_SUPPORT_ZEROCOPY = 0, MEMCPY_INFO _RSV, } rtMemcpyInfo_t; - * @param [out] value the capability info + * @param [out] value the capability info RT_CAPABILITY_SUPPORT or RT_CAPABILITY_NOT_SUPPORT * @return RT_ERROR_NONE for ok */ RTS_API rtError_t rtGetRtCapability(rtFeatureType_t featureType, int32_t featureInfo, int64_t *value); diff --git a/third_party/fwkacllib/inc/runtime/rt.h b/third_party/fwkacllib/inc/runtime/rt.h index c1872941..0d39389b 100644 --- a/third_party/fwkacllib/inc/runtime/rt.h +++ b/third_party/fwkacllib/inc/runtime/rt.h @@ -28,4 +28,4 @@ #include "rt_model.h" #include "stream.h" -#endif // __CCE_RUNTIME_RT_H__ \ No newline at end of file +#endif // __CCE_RUNTIME_RT_H__ diff --git a/third_party/fwkacllib/inc/tdt/status.h b/third_party/fwkacllib/inc/tdt/status.h index d3d6e7d1..dc9e670f 100644 --- a/third_party/fwkacllib/inc/tdt/status.h +++ b/third_party/fwkacllib/inc/tdt/status.h @@ -34,9 +34,16 @@ using TDT_StatusT = uint32_t; typedef uint32_t TDT_StatusT; #endif +#define LINUX 0 +#define WINDOWS 1 + #ifndef TDT_LIB_EXPORT +#if(TARGET_SYSTEM_NAME == WINDOWS) +#define TDT_LIB_EXPORT __declspec(dllexport) +#else #define TDT_LIB_EXPORT __attribute__((visibility("default"))) #endif +#endif /** * @ingroup tdt status. *