| @@ -118,7 +118,6 @@ set(EXECUTOR_SRC_LIST | |||||
| "common/profiling/profiling_manager.cc" | "common/profiling/profiling_manager.cc" | ||||
| "executor/ge_executor.cc" | "executor/ge_executor.cc" | ||||
| "ge_local_engine/engine/host_cpu_engine.cc" | "ge_local_engine/engine/host_cpu_engine.cc" | ||||
| "graph/build/memory/var_mem_assign_util.cc" | |||||
| "graph/execute/graph_execute.cc" | "graph/execute/graph_execute.cc" | ||||
| "graph/execute/model_executor.cc" | "graph/execute/model_executor.cc" | ||||
| "graph/load/graph_loader.cc" | "graph/load/graph_loader.cc" | ||||
| @@ -155,10 +154,8 @@ set(EXECUTOR_SRC_LIST | |||||
| "graph/load/model_manager/zero_copy_offset.cc" | "graph/load/model_manager/zero_copy_offset.cc" | ||||
| "graph/load/model_manager/zero_copy_task.cc" | "graph/load/model_manager/zero_copy_task.cc" | ||||
| "graph/manager/graph_caching_allocator.cc" | "graph/manager/graph_caching_allocator.cc" | ||||
| "graph/manager/graph_manager_utils.cc" | |||||
| "graph/manager/graph_mem_allocator.cc" | "graph/manager/graph_mem_allocator.cc" | ||||
| "graph/manager/graph_mem_manager.cc" | "graph/manager/graph_mem_manager.cc" | ||||
| "graph/manager/graph_var_manager.cc" | |||||
| "graph/manager/host_mem_allocator.cc" | "graph/manager/host_mem_allocator.cc" | ||||
| "graph/manager/host_mem_manager.cc" | "graph/manager/host_mem_manager.cc" | ||||
| #"graph/manager/memory_api.cc" # Just for runner. | #"graph/manager/memory_api.cc" # Just for runner. | ||||
| @@ -168,45 +165,11 @@ set(EXECUTOR_SRC_LIST | |||||
| "graph/manager/util/debug.cc" | "graph/manager/util/debug.cc" | ||||
| #"graph/manager/util/hcom_util.cc" # Just for runner. | #"graph/manager/util/hcom_util.cc" # Just for runner. | ||||
| "graph/passes/pass_utils.cc" | "graph/passes/pass_utils.cc" | ||||
| "host_kernels/add_kernel.cc" | |||||
| "host_kernels/broadcast_args_kernel.cc" | |||||
| "host_kernels/broadcast_gradient_args_kernel.cc" | |||||
| "host_kernels/cast_kernel.cc" | |||||
| "host_kernels/concat_offset_kernel.cc" | |||||
| "host_kernels/concat_v2_kernel.cc" | |||||
| "host_kernels/dynamic_stitch_kernel.cc" | |||||
| "host_kernels/empty_kernel.cc" | |||||
| "host_kernels/expanddims_kernel.cc" | |||||
| "host_kernels/fill_kernel.cc" | |||||
| "host_kernels/floordiv_kernel.cc" | |||||
| "host_kernels/floormod_kernel.cc" | |||||
| "host_kernels/gather_v2_kernel.cc" | |||||
| "host_kernels/greater_kernel.cc" | |||||
| "host_kernels/identity_kernel.cc" | |||||
| "host_kernels/kernel_utils.cc" | "host_kernels/kernel_utils.cc" | ||||
| "host_kernels/maximum_kernel.cc" | |||||
| "host_kernels/mul_kernel.cc" | |||||
| "host_kernels/pack_kernel.cc" | |||||
| "host_kernels/permute_kernel.cc" | |||||
| "host_kernels/range_kernel.cc" | |||||
| "host_kernels/rank_kernel.cc" | "host_kernels/rank_kernel.cc" | ||||
| "host_kernels/reduce_prod_kernel.cc" | |||||
| "host_kernels/reformat_kernel.cc" | |||||
| "host_kernels/reshape_kernel.cc" | |||||
| "host_kernels/rsqrt_kernel.cc" | |||||
| "host_kernels/shape_kernel.cc" | "host_kernels/shape_kernel.cc" | ||||
| "host_kernels/shape_n_kernel.cc" | "host_kernels/shape_n_kernel.cc" | ||||
| "host_kernels/size_kernel.cc" | "host_kernels/size_kernel.cc" | ||||
| "host_kernels/slice_d_kernel.cc" | |||||
| "host_kernels/slice_kernel.cc" | |||||
| "host_kernels/squeeze_kernel.cc" | |||||
| "host_kernels/ssd_prior_box_kernel.cc" | |||||
| "host_kernels/strided_slice_kernel.cc" | |||||
| "host_kernels/sub_kernel.cc" | |||||
| "host_kernels/transdata_kernel.cc" | |||||
| "host_kernels/transpose_kernel.cc" | |||||
| "host_kernels/unpack_kernel.cc" | |||||
| "host_kernels/unsqueeze_kernel.cc" | |||||
| "hybrid/common/npu_memory_allocator.cc" | "hybrid/common/npu_memory_allocator.cc" | ||||
| "hybrid/common/tensor_value.cc" | "hybrid/common/tensor_value.cc" | ||||
| "hybrid/executor/hybrid_execution_context.cc" | "hybrid/executor/hybrid_execution_context.cc" | ||||
| @@ -262,7 +225,6 @@ set(COMPILER_SRC_LIST | |||||
| "common/dump/dump_op.cc" | "common/dump/dump_op.cc" | ||||
| "common/ge/op_tiling_manager.cc" | "common/ge/op_tiling_manager.cc" | ||||
| "common/ge/plugin_manager.cc" | "common/ge/plugin_manager.cc" | ||||
| "common/profiling/profiling_manager.cc" | |||||
| "engine_manager/dnnengine_manager.cc" | "engine_manager/dnnengine_manager.cc" | ||||
| "ge_local_engine/engine/host_cpu_engine.cc" | "ge_local_engine/engine/host_cpu_engine.cc" | ||||
| "ge_opt_info/ge_opt_info.cc" | "ge_opt_info/ge_opt_info.cc" | ||||
| @@ -278,7 +240,6 @@ set(COMPILER_SRC_LIST | |||||
| "graph/build/memory/hybrid_mem_assigner.cc" | "graph/build/memory/hybrid_mem_assigner.cc" | ||||
| "graph/build/memory/max_block_mem_assigner.cc" | "graph/build/memory/max_block_mem_assigner.cc" | ||||
| "graph/build/memory/memory_assigner.cc" | "graph/build/memory/memory_assigner.cc" | ||||
| "graph/build/memory/var_mem_assign_util.cc" | |||||
| "graph/build/model_builder.cc" | "graph/build/model_builder.cc" | ||||
| "graph/build/run_context.cc" | "graph/build/run_context.cc" | ||||
| "graph/build/stream_allocator.cc" | "graph/build/stream_allocator.cc" | ||||
| @@ -289,20 +250,8 @@ set(COMPILER_SRC_LIST | |||||
| "graph/label/label_maker.cc" | "graph/label/label_maker.cc" | ||||
| "graph/label/partitioned_call_label_maker.cc" | "graph/label/partitioned_call_label_maker.cc" | ||||
| "graph/label/while_label_maker.cc" | "graph/label/while_label_maker.cc" | ||||
| "graph/load/model_manager/model_utils.cc" | |||||
| "graph/manager/graph_caching_allocator.cc" | |||||
| "graph/manager/graph_context.cc" | "graph/manager/graph_context.cc" | ||||
| "graph/manager/graph_manager.cc" | "graph/manager/graph_manager.cc" | ||||
| "graph/manager/graph_manager_utils.cc" | |||||
| "graph/manager/graph_mem_allocator.cc" | |||||
| "graph/manager/graph_mem_manager.cc" | |||||
| "graph/manager/graph_var_manager.cc" | |||||
| "graph/manager/host_mem_allocator.cc" | |||||
| "graph/manager/host_mem_manager.cc" | |||||
| "graph/manager/rdma_pool_allocator.cc" | |||||
| "graph/manager/session_scope_mem_allocator.cc" | |||||
| "graph/manager/trans_var_data_utils.cc" | |||||
| "graph/manager/util/debug.cc" | |||||
| "graph/manager/util/rt_context_util.cc" | "graph/manager/util/rt_context_util.cc" | ||||
| "graph/manager/util/variable_accelerate_ctrl.cc" | "graph/manager/util/variable_accelerate_ctrl.cc" | ||||
| "graph/optimize/graph_optimize.cc" | "graph/optimize/graph_optimize.cc" | ||||
| @@ -458,7 +407,6 @@ set(COMPILER_SRC_LIST | |||||
| "host_kernels/transpose_kernel.cc" | "host_kernels/transpose_kernel.cc" | ||||
| "host_kernels/unpack_kernel.cc" | "host_kernels/unpack_kernel.cc" | ||||
| "host_kernels/unsqueeze_kernel.cc" | "host_kernels/unsqueeze_kernel.cc" | ||||
| "hybrid/node_executor/aicpu/aicpu_ext_info.cc" | |||||
| "init/gelib.cc" | "init/gelib.cc" | ||||
| "ir_build/attr_options/keep_dtype_option.cc" | "ir_build/attr_options/keep_dtype_option.cc" | ||||
| "ir_build/attr_options/utils.cc" | "ir_build/attr_options/utils.cc" | ||||
| @@ -485,8 +433,6 @@ if (NOT ENABLE_D AND NOT ENABLE_ACL AND NOT ENABLE_MS_TESTCASES) | |||||
| message("CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}") | message("CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}") | ||||
| ############ libge_runner.so ############ | ############ libge_runner.so ############ | ||||
| add_library(ge_runner SHARED | add_library(ge_runner SHARED | ||||
| ${EXECUTOR_SRC_LIST} | |||||
| ${COMPILER_SRC_LIST} | |||||
| ${RUNNER_SRC_LIST} | ${RUNNER_SRC_LIST} | ||||
| $<TARGET_OBJECTS:$<IF:$<TARGET_EXISTS:msprofiler_fwk>,msprofiler_fwk,msprofiler_fwk_object>> | $<TARGET_OBJECTS:$<IF:$<TARGET_EXISTS:msprofiler_fwk>,msprofiler_fwk,msprofiler_fwk_object>> | ||||
| ) | ) | ||||
| @@ -562,7 +508,9 @@ target_link_libraries(ge_runner PRIVATE | |||||
| $<$<NOT:$<BOOL:${ENABLE_OPEN_SRC}>>:$<BUILD_INTERFACE:cce_headers>> | $<$<NOT:$<BOOL:${ENABLE_OPEN_SRC}>>:$<BUILD_INTERFACE:cce_headers>> | ||||
| adump_server | adump_server | ||||
| static_mmpa | static_mmpa | ||||
| ge_proto_common | |||||
| ge_compiler | |||||
| #ge_proto_common | |||||
| ge_executor_shared | |||||
| ge_proto_client | ge_proto_client | ||||
| -Wl,--no-as-needed | -Wl,--no-as-needed | ||||
| graph | graph | ||||
| @@ -594,7 +542,6 @@ target_compile_definitions(ge_compiler PRIVATE | |||||
| PROTOBUF_INLINE_NOT_IN_HEADERS=0 | PROTOBUF_INLINE_NOT_IN_HEADERS=0 | ||||
| REUSE_MEMORY=1 | REUSE_MEMORY=1 | ||||
| FMK_SUPPORT_DUMP | FMK_SUPPORT_DUMP | ||||
| FMK_HOST_INFER | |||||
| google=ascend_private | google=ascend_private | ||||
| FUNC_VISIBILITY | FUNC_VISIBILITY | ||||
| $<$<STREQUAL:${ENABLE_OPEN_SRC},True>:ONLY_COMPILE_OPEN_SRC> | $<$<STREQUAL:${ENABLE_OPEN_SRC},True>:ONLY_COMPILE_OPEN_SRC> | ||||
| @@ -603,7 +550,7 @@ target_compile_definitions(ge_compiler PRIVATE | |||||
| target_compile_options(ge_compiler PRIVATE | target_compile_options(ge_compiler PRIVATE | ||||
| -O2 | -O2 | ||||
| -fno-common | -fno-common | ||||
| -fvisibility=hidden | |||||
| -fvisibility=default | |||||
| $<$<STREQUAL:${CMAKE_CXX_COMPILER_VERSION},7.3.0>:-Werror=unused-variable> | $<$<STREQUAL:${CMAKE_CXX_COMPILER_VERSION},7.3.0>:-Werror=unused-variable> | ||||
| $<$<STREQUAL:${CMAKE_CXX_COMPILER_VERSION},7.3.0>:-Werror=unused-const-variable -Werror=format> | $<$<STREQUAL:${CMAKE_CXX_COMPILER_VERSION},7.3.0>:-Werror=unused-const-variable -Werror=format> | ||||
| ) | ) | ||||
| @@ -737,7 +684,7 @@ target_compile_options(ge_executor_shared PRIVATE | |||||
| -Werror | -Werror | ||||
| -O2 | -O2 | ||||
| -Wno-deprecated-declarations | -Wno-deprecated-declarations | ||||
| -fvisibility=hidden | |||||
| -fvisibility=default | |||||
| ) | ) | ||||
| target_compile_definitions(ge_executor_shared PRIVATE | target_compile_definitions(ge_executor_shared PRIVATE | ||||
| @@ -19,6 +19,7 @@ | |||||
| #include <malloc.h> | #include <malloc.h> | ||||
| #include "framework/common/debug/log.h" | #include "framework/common/debug/log.h" | ||||
| #include "framework/common/debug/ge_log.h" | #include "framework/common/debug/ge_log.h" | ||||
| #include "framework/executor/ge_executor.h" | |||||
| #include "common/ge/datatype_util.h" | #include "common/ge/datatype_util.h" | ||||
| #include "proto/ge_api.pb.h" | #include "proto/ge_api.pb.h" | ||||
| #include "graph/model_serialize.h" | #include "graph/model_serialize.h" | ||||
| @@ -161,6 +162,17 @@ Status GEInitializeImpl(const std::map<string, string> &options) { | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| ErrorManager::GetInstance().SetStage(error_message::kInitialize, error_message::kOther); | |||||
| GELOGI("GeExecutor initial."); | |||||
| GE_TIMESTAMP_START(GeExecutorInitialize); | |||||
| ret = GeExecutor::Initialize(options); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(ret, "[Init][GeExecutor] GeExecutor initialize failed."); | |||||
| REPORT_CALL_ERROR("E19999", "GeExecutor initialize failed."); | |||||
| return ret; | |||||
| } | |||||
| GE_TIMESTAMP_END(GeExecutorInitialize, "GeExecutor::Initialize"); | |||||
| // 7.check return status, return | // 7.check return status, return | ||||
| if (!g_ge_initialized) { | if (!g_ge_initialized) { | ||||
| // Initialize success, first time calling initialize | // Initialize success, first time calling initialize | ||||
| @@ -213,16 +225,18 @@ Status GEFinalize() { | |||||
| ErrorManager::GetInstance().GenWorkStreamIdDefault(); | ErrorManager::GetInstance().GenWorkStreamIdDefault(); | ||||
| GELOGT(TRACE_INIT, "GEFinalize start"); | GELOGT(TRACE_INIT, "GEFinalize start"); | ||||
| (void)GeExecutor::FinalizeEx(); | |||||
| GELOGI("SessionManager finalization."); | |||||
| if (g_session_manager != nullptr) { | |||||
| (void)g_session_manager->Finalize(); // always success. | |||||
| } | |||||
| // call Finalize | // call Finalize | ||||
| Status ret = SUCCESS; | Status ret = SUCCESS; | ||||
| Status middle_ret; | Status middle_ret; | ||||
| GELOGT(TRACE_RUNNING, "Finalizing environment"); | GELOGT(TRACE_RUNNING, "Finalizing environment"); | ||||
| std::shared_ptr<GELib> instancePtr = ge::GELib::GetInstance(); | |||||
| if (instancePtr == nullptr || !instancePtr->InitFlag()) { | |||||
| GELOGW("GEFinalize Failed: GE not initialized."); | |||||
| ret = GE_CLI_GE_NOT_INITIALIZED; | |||||
| } | |||||
| if (ret != GE_CLI_GE_NOT_INITIALIZED) { | |||||
| std::shared_ptr<GELib> instancePtr = GELib::GetInstance(); | |||||
| if (instancePtr != nullptr) { | |||||
| middle_ret = instancePtr->Finalize(); | middle_ret = instancePtr->Finalize(); | ||||
| GELOGI("GEFinalize finalize gelib ret=%u", middle_ret); | GELOGI("GEFinalize finalize gelib ret=%u", middle_ret); | ||||
| if (middle_ret != SUCCESS) { | if (middle_ret != SUCCESS) { | ||||
| @@ -230,11 +244,6 @@ Status GEFinalize() { | |||||
| } | } | ||||
| } | } | ||||
| GELOGI("SessionManager finalization."); | |||||
| if (g_session_manager != nullptr) { | |||||
| (void)g_session_manager->Finalize(); // always success. | |||||
| } | |||||
| middle_ret = TBEPluginManager::Instance().Finalize(); | middle_ret = TBEPluginManager::Instance().Finalize(); | ||||
| if (middle_ret != SUCCESS) { | if (middle_ret != SUCCESS) { | ||||
| ret = middle_ret; | ret = middle_ret; | ||||
| @@ -50,6 +50,9 @@ set(SRC_LIST | |||||
| "${GE_CODE_DIR}/ge/common/transop_util.cc" | "${GE_CODE_DIR}/ge/common/transop_util.cc" | ||||
| "${GE_CODE_DIR}/ge/common/types.cc" | "${GE_CODE_DIR}/ge/common/types.cc" | ||||
| "${GE_CODE_DIR}/ge/common/util.cc" | "${GE_CODE_DIR}/ge/common/util.cc" | ||||
| "${GE_CODE_DIR}/ge/graph/manager/graph_var_manager.cc" | |||||
| "${GE_CODE_DIR}/ge/graph/manager/graph_manager_utils.cc" | |||||
| "${GE_CODE_DIR}/ge/graph/build/memory/var_mem_assign_util.cc" | |||||
| ) | ) | ||||
| if (NOT ENABLE_D AND NOT ENABLE_ACL) | if (NOT ENABLE_D AND NOT ENABLE_ACL) | ||||
| @@ -0,0 +1,41 @@ | |||||
| /** | |||||
| * Copyright 2021 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_COMMON_MEM_MANAGER_H_ | |||||
| #define GE_GRAPH_COMMON_MEM_MANAGER_H_ | |||||
| #include <string> | |||||
| #include "external/ge/ge_api_types.h" | |||||
| #include "runtime/mem.h" | |||||
| namespace ge { | |||||
| class MemoryManager { | |||||
| public: | |||||
| virtual uint8_t *MallocMemory(rtMemType_t memory_type, const std::string &purpose, const std::string &memory_key, | |||||
| size_t memory_size, uint32_t device_id) = 0; | |||||
| virtual Status FreeMemory(rtMemType_t memory_type, const std::string &memory_key, uint32_t device_id) = 0; | |||||
| virtual uint8_t *GetMemoryBase(rtMemType_t memory_type, const std::string &memory_key, uint32_t device_id) = 0; | |||||
| virtual uint8_t *GetMemoryAddr(rtMemType_t memory_type, const std::string &memory_key, uint32_t device_id) = 0; | |||||
| virtual uint8_t *GetPoolMemory(rtMemType_t memory_type, size_t memory_size, uint32_t device_id) = 0; | |||||
| }; | |||||
| } // namespace ge | |||||
| #endif // GE_GRAPH_COMMON_MEM_MANAGER_H_ | |||||
| @@ -18,13 +18,9 @@ | |||||
| #include "framework/common/debug/ge_log.h" | #include "framework/common/debug/ge_log.h" | ||||
| #include "framework/common/debug/log.h" | #include "framework/common/debug/log.h" | ||||
| #include "framework/common/string_util.h" | |||||
| #include "graph/ge_context.h" | #include "graph/ge_context.h" | ||||
| #include "graph/utils/type_utils.h" | #include "graph/utils/type_utils.h" | ||||
| #include "external/graph/types.h" | |||||
| #include "runtime/base.h" | |||||
| #include "graph/load/model_manager/davinci_model.h" | #include "graph/load/model_manager/davinci_model.h" | ||||
| #include "mmpa/mmpa_api.h" | |||||
| namespace { | namespace { | ||||
| const char *const kTrainingTrace = "training_trace"; | const char *const kTrainingTrace = "training_trace"; | ||||
| @@ -82,14 +78,14 @@ ProfilingManager &ProfilingManager::Instance() { | |||||
| return profiling_manager; | return profiling_manager; | ||||
| } | } | ||||
| ge::Status ProfilingManager::Init(const Options &options) { | |||||
| ge::Status ProfilingManager::Init(const string &mode, const string &options, const string &job_id) { | |||||
| #ifdef DAVINCI_SUPPORT_PROFILING | #ifdef DAVINCI_SUPPORT_PROFILING | ||||
| vector<int32_t>().swap(device_id_); | vector<int32_t>().swap(device_id_); | ||||
| subscribe_count_ = 0; | subscribe_count_ = 0; | ||||
| GELOGI("ProfilingManager::Init job_id:%s", options.job_id.c_str()); | |||||
| GELOGI("ProfilingManager::Init job_id:%s", job_id.c_str()); | |||||
| struct MsprofGeOptions prof_conf = {{ 0 }}; | struct MsprofGeOptions prof_conf = {{ 0 }}; | ||||
| Status ret = InitFromOptions(options, prof_conf); | |||||
| Status ret = InitFromOptions(mode, options, job_id, prof_conf); | |||||
| if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
| GELOGE(ret, "[Init][Profiling]Failed, error_code %u", ret); | GELOGE(ret, "[Init][Profiling]Failed, error_code %u", ret); | ||||
| REPORT_CALL_ERROR("E19999", "Init profiling failed, error_code %u", ret); | REPORT_CALL_ERROR("E19999", "Init profiling failed, error_code %u", ret); | ||||
| @@ -121,25 +117,52 @@ ge::Status ProfilingManager::Init(const Options &options) { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| ge::Status ProfilingManager::InitFromOptions(const Options &options, MsprofGeOptions &prof_conf) { | |||||
| void ProfilingManager::Initialize(const map<string, string> &options) { | |||||
| GetContext().Init(); | |||||
| auto it = options.find(OPTION_EXEC_JOB_ID); | |||||
| string job_id = (it != options.end()) ? it->second : ""; | |||||
| it = options.find(OPTION_EXEC_SESSION_ID); | |||||
| string session_id = (it != options.end()) ? it->second : ""; | |||||
| it = options.find(OPTION_EXEC_PROFILING_MODE); | |||||
| string profiling_mode = (it != options.end()) ? it->second : ""; | |||||
| it = options.find(OPTION_EXEC_PROFILING_OPTIONS); | |||||
| string profiling_options = (it != options.end()) ? it->second : ""; | |||||
| GELOGI("Init Profiling. session Id: %s", session_id.c_str()); | |||||
| (void)Init(profiling_mode, profiling_options, job_id); | |||||
| } | |||||
| void ProfilingManager::Finalize() { | |||||
| if (ProfilingOn()) { | |||||
| StopProfiling(); | |||||
| PluginUnInit(); | |||||
| } | |||||
| } | |||||
| ge::Status ProfilingManager::InitFromOptions(const string &profiling_mode, const string &profiling_options, | |||||
| const string &job_id, MsprofGeOptions &prof_conf) { | |||||
| #ifdef DAVINCI_SUPPORT_PROFILING | #ifdef DAVINCI_SUPPORT_PROFILING | ||||
| // enable profiling by env | // enable profiling by env | ||||
| char env_profiling_mode[MMPA_MAX_PATH] = { 0x00 }; | char env_profiling_mode[MMPA_MAX_PATH] = { 0x00 }; | ||||
| is_execute_profiling_ = false; | is_execute_profiling_ = false; | ||||
| if (options.profiling_mode == "1" && !options.profiling_options.empty()) { | |||||
| if (profiling_mode == "1" && !profiling_options.empty()) { | |||||
| // enable profiling by ge option | // enable profiling by ge option | ||||
| if (strncpy_s(prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX, options.profiling_options.c_str(), | |||||
| if (strncpy_s(prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX, profiling_options.c_str(), | |||||
| MSPROF_OPTIONS_DEF_LEN_MAX - 1) != EOK) { | MSPROF_OPTIONS_DEF_LEN_MAX - 1) != EOK) { | ||||
| GELOGE(INTERNAL_ERROR, "[copy][ProfilingOptions]Failed, options %s", | GELOGE(INTERNAL_ERROR, "[copy][ProfilingOptions]Failed, options %s", | ||||
| options.profiling_options.c_str()); | |||||
| profiling_options.c_str()); | |||||
| REPORT_CALL_ERROR("E19999", "Copy profiling_options %s failed", | REPORT_CALL_ERROR("E19999", "Copy profiling_options %s failed", | ||||
| options.profiling_options.c_str()); | |||||
| profiling_options.c_str()); | |||||
| return INTERNAL_ERROR; | return INTERNAL_ERROR; | ||||
| } | } | ||||
| is_execute_profiling_ = true; | is_execute_profiling_ = true; | ||||
| GELOGI("The profiling in options is %s, %s. origin option: %s", options.profiling_mode.c_str(), prof_conf.options, | |||||
| options.profiling_options.c_str()); | |||||
| GELOGI("The profiling in options is %s, %s. origin option: %s", profiling_mode.c_str(), prof_conf.options, | |||||
| profiling_options.c_str()); | |||||
| } else { | } else { | ||||
| (void)mmGetEnv("PROFILING_MODE", env_profiling_mode, MMPA_MAX_PATH); | (void)mmGetEnv("PROFILING_MODE", env_profiling_mode, MMPA_MAX_PATH); | ||||
| (void)mmGetEnv("PROFILING_OPTIONS", prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX); | (void)mmGetEnv("PROFILING_OPTIONS", prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX); | ||||
| @@ -166,13 +189,13 @@ ge::Status ProfilingManager::InitFromOptions(const Options &options, MsprofGeOpt | |||||
| return ge::PARAM_INVALID; | return ge::PARAM_INVALID; | ||||
| } | } | ||||
| if (strncpy_s(prof_conf.jobId, MSPROF_OPTIONS_DEF_LEN_MAX, options.job_id.c_str(), MSPROF_OPTIONS_DEF_LEN_MAX - 1) != | |||||
| if (strncpy_s(prof_conf.jobId, MSPROF_OPTIONS_DEF_LEN_MAX, job_id.c_str(), MSPROF_OPTIONS_DEF_LEN_MAX - 1) != | |||||
| EOK) { | EOK) { | ||||
| GELOGE(INTERNAL_ERROR, "[Copy][JobId]Failed, original job_id %s", options.job_id.c_str()); | |||||
| REPORT_CALL_ERROR("E19999", "Copy job_id %s failed", options.job_id.c_str()); | |||||
| GELOGE(INTERNAL_ERROR, "[Copy][JobId]Failed, original job_id %s", job_id.c_str()); | |||||
| REPORT_CALL_ERROR("E19999", "Copy job_id %s failed", job_id.c_str()); | |||||
| return INTERNAL_ERROR; | return INTERNAL_ERROR; | ||||
| } | } | ||||
| GELOGI("Job id: %s, original job id: %s.", prof_conf.jobId, options.job_id.c_str()); | |||||
| GELOGI("Job id: %s, original job id: %s.", prof_conf.jobId, job_id.c_str()); | |||||
| #endif | #endif | ||||
| return ge::SUCCESS; | return ge::SUCCESS; | ||||
| } | } | ||||
| @@ -204,13 +227,14 @@ ge::Status ProfilingManager::ParseOptions(const std::string &options) { | |||||
| return ge::PARAM_INVALID; | return ge::PARAM_INVALID; | ||||
| } | } | ||||
| if (prof_options.contains(kFpPoint)) { | if (prof_options.contains(kFpPoint)) { | ||||
| fp_point_ = prof_options[kFpPoint]; | |||||
| domi::GetContext().forward_point = prof_options[kFpPoint]; | |||||
| } | } | ||||
| if (prof_options.contains(kBpPoint)) { | if (prof_options.contains(kBpPoint)) { | ||||
| bp_point_ = prof_options[kBpPoint]; | |||||
| domi::GetContext().backward_point = prof_options[kBpPoint]; | |||||
| } | } | ||||
| if (!fp_point_.empty() && !bp_point_.empty()) { | |||||
| GELOGI("Training trace bp fp is set, bp_point:%s, fp_point:%s.", bp_point_.c_str(), fp_point_.c_str()); | |||||
| if (!domi::GetContext().forward_point.empty() && !domi::GetContext().backward_point.empty()) { | |||||
| GELOGI("Training trace bp fp is set, bp_point:%s, fp_point:%s.", | |||||
| domi::GetContext().backward_point.c_str(), domi::GetContext().forward_point.c_str()); | |||||
| } | } | ||||
| is_training_trace_ = true; | is_training_trace_ = true; | ||||
| } catch (...) { | } catch (...) { | ||||
| @@ -593,6 +617,8 @@ Status ProfilingManager::ProfInit(uint64_t module) { | |||||
| is_training_trace_ = true; | is_training_trace_ = true; | ||||
| } | } | ||||
| GELOGI("Prof init success."); | GELOGI("Prof init success."); | ||||
| domi::GetContext().profiling_on = ProfilingOn(); | |||||
| domi::GetContext().profiling_trace_on = ProfilingTrainingTraceOn(); | |||||
| #endif | #endif | ||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| @@ -1003,56 +1029,6 @@ void ProfilingManager::GetOpInputOutputInfo(const OpDescPtr &op, TaskDescInfo &t | |||||
| GetOpOutputInfo(op, task_desc_info); | GetOpOutputInfo(op, task_desc_info); | ||||
| } | } | ||||
| void ProfilingManager::GetFpBpPoint(std::string &fp_point, std::string &bp_point) { | |||||
| // Env or options mode, fp_point_/bp_point_ have initiliazed on profiling init | |||||
| if (!fp_point_.empty() && !bp_point_.empty()) { | |||||
| fp_point = fp_point_; | |||||
| bp_point = bp_point_; | |||||
| GELOGI("Bp Fp have been initialized in env or options. bp_point: %s, fp_point: %s", bp_point.c_str(), | |||||
| fp_point.c_str()); | |||||
| return; | |||||
| } | |||||
| // ProfApi mode and training trace is set | |||||
| // Parse options first | |||||
| char env_profiling_options[MSPROF_OPTIONS_DEF_LEN_MAX] = {0x00}; | |||||
| bool is_profiling_valid = false; | |||||
| std::string profiling_options; | |||||
| if (ge::GetContext().GetOption(OPTION_EXEC_PROFILING_OPTIONS, profiling_options) == SUCCESS && | |||||
| !profiling_options.empty()) { | |||||
| is_profiling_valid = true; | |||||
| } else { | |||||
| INT32 ret = mmGetEnv("PROFILING_OPTIONS", env_profiling_options, MSPROF_OPTIONS_DEF_LEN_MAX); | |||||
| if (ret != EN_OK) { | |||||
| GELOGI("PROFILING_OPTIONS env is not exist."); | |||||
| return; | |||||
| } | |||||
| GELOGI("Parse env PROFILING_OPTIONS:%s.", env_profiling_options); | |||||
| profiling_options = env_profiling_options; | |||||
| is_profiling_valid = true; | |||||
| } | |||||
| if (is_profiling_valid) { | |||||
| try { | |||||
| Json prof_options = Json::parse(profiling_options); | |||||
| if (prof_options.contains(kFpPoint)) { | |||||
| fp_point_ = prof_options[kFpPoint]; | |||||
| } | |||||
| if (prof_options.contains(kBpPoint)) { | |||||
| bp_point_ = prof_options[kBpPoint]; | |||||
| } | |||||
| fp_point = fp_point_; | |||||
| bp_point = bp_point_; | |||||
| if (!fp_point_.empty() && !bp_point_.empty()) { | |||||
| GELOGI("Training trace bp fp is set, bp_point:%s, fp_point:%s.", bp_point_.c_str(), fp_point_.c_str()); | |||||
| } | |||||
| } catch (...) { | |||||
| GELOGW("Json prof options is invalid."); | |||||
| return; | |||||
| } | |||||
| } | |||||
| return; | |||||
| } | |||||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::GetDeviceIdFromGraph( | FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::GetDeviceIdFromGraph( | ||||
| uint32_t graph_id, uint32_t &device_id) { | uint32_t graph_id, uint32_t &device_id) { | ||||
| auto iter = device_id_map_.find(graph_id); | auto iter = device_id_map_.find(graph_id); | ||||
| @@ -17,12 +17,12 @@ | |||||
| #ifndef GE_COMMON_PROFILING_PROFILING_MANAGER_H_ | #ifndef GE_COMMON_PROFILING_PROFILING_MANAGER_H_ | ||||
| #define GE_COMMON_PROFILING_PROFILING_MANAGER_H_ | #define GE_COMMON_PROFILING_PROFILING_MANAGER_H_ | ||||
| #include <nlohmann/json.hpp> | |||||
| #include <mutex> | #include <mutex> | ||||
| #include <map> | #include <map> | ||||
| #include <string> | #include <string> | ||||
| #include <vector> | #include <vector> | ||||
| #include "nlohmann/json.hpp" | |||||
| #include "framework/common/ge_inner_error_codes.h" | #include "framework/common/ge_inner_error_codes.h" | ||||
| #include "framework/common/ge_types.h" | #include "framework/common/ge_types.h" | ||||
| #include "external/register/register_types.h" | #include "external/register/register_types.h" | ||||
| @@ -78,14 +78,17 @@ class ProfilingManager { | |||||
| ProfilingManager(); | ProfilingManager(); | ||||
| virtual ~ProfilingManager(); | virtual ~ProfilingManager(); | ||||
| static ProfilingManager &Instance(); | static ProfilingManager &Instance(); | ||||
| Status Init(const Options &options); | |||||
| void Initialize(const map<string, string> &options); | |||||
| void Finalize(); | |||||
| Status ProfInit(uint64_t module); | Status ProfInit(uint64_t module); | ||||
| Status ProfFinalize(); | Status ProfFinalize(); | ||||
| Status ProfStartProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | Status ProfStartProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | ||||
| Status ProfStopProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | Status ProfStopProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | ||||
| Status ProfModelSubscribe(uint64_t module, void *model); | Status ProfModelSubscribe(uint64_t module, void *model); | ||||
| Status ProfModelUnsubscribe(void *model); | Status ProfModelUnsubscribe(void *model); | ||||
| void StopProfiling(); | |||||
| bool ProfilingTrainingTraceOn() const { return is_training_trace_; } | bool ProfilingTrainingTraceOn() const { return is_training_trace_; } | ||||
| // report model load profiling data flag, data contain task desc info, step info, model load fusion op info | // report model load profiling data flag, data contain task desc info, step info, model load fusion op info | ||||
| bool ProfilingModelLoadOn() const { return is_load_profiling_; } | bool ProfilingModelLoadOn() const { return is_load_profiling_; } | ||||
| @@ -97,13 +100,12 @@ class ProfilingManager { | |||||
| void ProfilingTaskDescInfo(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, | void ProfilingTaskDescInfo(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, | ||||
| const int32_t &device_id); | const int32_t &device_id); | ||||
| void ProfilingOpInputOutInfo(const TaskDescInfo &task, Json &task_json); | void ProfilingOpInputOutInfo(const TaskDescInfo &task, Json &task_json); | ||||
| Status PluginInit(); | |||||
| void PluginUnInit() const; | |||||
| Status CallMsprofReport(ReporterData &reporter_data) const; | Status CallMsprofReport(ReporterData &reporter_data) const; | ||||
| struct MsprofCallback &GetMsprofCallback() { return prof_cb_; } | struct MsprofCallback &GetMsprofCallback() { return prof_cb_; } | ||||
| void SetMsprofCtrlCallback(MsprofCtrlCallback func) { prof_cb_.msprofCtrlCallback = func; } | void SetMsprofCtrlCallback(MsprofCtrlCallback func) { prof_cb_.msprofCtrlCallback = func; } | ||||
| void SetMsprofReporterCallback(MsprofReporterCallback func) { prof_cb_.msprofReporterCallback = func; } | void SetMsprofReporterCallback(MsprofReporterCallback func) { prof_cb_.msprofReporterCallback = func; } | ||||
| void GetFpBpPoint(std::string &fp_point, std::string &bp_point); | |||||
| void GetOpInputOutputInfo(const OpDescPtr &op, TaskDescInfo &task_desc_info) const; | void GetOpInputOutputInfo(const OpDescPtr &op, TaskDescInfo &task_desc_info) const; | ||||
| void ReportData(const int32_t &device_id, const std::string &data, const std::string &tag_name); | void ReportData(const int32_t &device_id, const std::string &data, const std::string &tag_name); | ||||
| Status ProfileStepInfo(uint64_t index_id, uint64_t model_id, uint16_t tag_id, rtStream_t stream, int32_t device_id); | Status ProfileStepInfo(uint64_t index_id, uint64_t model_id, uint16_t tag_id, rtStream_t stream, int32_t device_id); | ||||
| @@ -118,13 +120,19 @@ class ProfilingManager { | |||||
| Status GetModelIdFromGraph(uint32_t graph_id, uint32_t &model_id); | Status GetModelIdFromGraph(uint32_t graph_id, uint32_t &model_id); | ||||
| private: | private: | ||||
| Status InitFromOptions(const Options &options, MsprofGeOptions &prof_conf); | |||||
| Status Init(const string &mode, const string &options, const string &job_id); | |||||
| Status InitFromOptions(const string &mode, const string &options, const string &job_id, MsprofGeOptions &prof_conf); | |||||
| Status ParseOptions(const std::string &options); | Status ParseOptions(const std::string &options); | ||||
| Status ProfParseParam(const std::map<std::string, std::string> &config_para, int32_t &device_num, | Status ProfParseParam(const std::map<std::string, std::string> &config_para, int32_t &device_num, | ||||
| vector<int32_t> &device_list); | vector<int32_t> &device_list); | ||||
| Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para, | Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para, | ||||
| vector<int32_t> &device_list); | vector<int32_t> &device_list); | ||||
| uint64_t GetProfilingModule(); | uint64_t GetProfilingModule(); | ||||
| void StopProfiling(); | |||||
| Status PluginInit(); | |||||
| void PluginUnInit() const; | |||||
| void UpdateDeviceIdModuleMap(string prof_type, uint64_t module, const vector<int32_t> &device_list); | void UpdateDeviceIdModuleMap(string prof_type, uint64_t module, const vector<int32_t> &device_list); | ||||
| void UpdateSubscribeDeviceModuleMap(std::string prof_type, uint32_t device_id, uint64_t module); | void UpdateSubscribeDeviceModuleMap(std::string prof_type, uint32_t device_id, uint64_t module); | ||||
| void GetOpInputInfo(const OpDescPtr &op, TaskDescInfo &task_desc_info) const; | void GetOpInputInfo(const OpDescPtr &op, TaskDescInfo &task_desc_info) const; | ||||
| @@ -28,6 +28,7 @@ | |||||
| #include "graph/load/model_manager/model_manager.h" | #include "graph/load/model_manager/model_manager.h" | ||||
| #include "graph/manager/graph_mem_manager.h" | #include "graph/manager/graph_mem_manager.h" | ||||
| #include "graph/manager/graph_var_manager.h" | #include "graph/manager/graph_var_manager.h" | ||||
| #include "graph/manager/host_mem_manager.h" | |||||
| #include "single_op/single_op_manager.h" | #include "single_op/single_op_manager.h" | ||||
| #include "graph/load/model_manager/davinci_model.h" | #include "graph/load/model_manager/davinci_model.h" | ||||
| #include "opskernel_manager/ops_kernel_builder_manager.h" | #include "opskernel_manager/ops_kernel_builder_manager.h" | ||||
| @@ -244,13 +245,13 @@ static void InitOpsProtoManager() { | |||||
| GeExecutor::GeExecutor() {} | GeExecutor::GeExecutor() {} | ||||
| Status GeExecutor::Initialize() { | |||||
| GELOGI("Init GeExecutor begin."); | |||||
| Status GeExecutor::Initialize(const std::map<string, string> &options) { | |||||
| if (isInit_) { | if (isInit_) { | ||||
| GELOGW("Already initialized, no need to be initialized again."); | GELOGW("Already initialized, no need to be initialized again."); | ||||
| return ge::SUCCESS; | return ge::SUCCESS; | ||||
| } | } | ||||
| GELOGI("Init GeExecutor begin."); | |||||
| OpTilingManager::GetInstance().LoadSo(); | OpTilingManager::GetInstance().LoadSo(); | ||||
| Status init_hostcpu_engine_status = HostCpuEngine::GetInstance().Initialize(); | Status init_hostcpu_engine_status = HostCpuEngine::GetInstance().Initialize(); | ||||
| @@ -261,46 +262,61 @@ Status GeExecutor::Initialize() { | |||||
| InitOpsProtoManager(); | InitOpsProtoManager(); | ||||
| std::vector<rtMemType_t> mem_type(1, RT_MEMORY_HBM); | |||||
| mem_type.push_back(RT_MEMORY_P2P_DDR); | |||||
| auto ret = MemManager::Instance().Initialize(mem_type); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(ret, "[Initialize][MemManager] failed."); | |||||
| return ret; | |||||
| GE_CHK_STATUS_RET(HostMemManager::Instance().Initialize()); | |||||
| const std::vector<rtMemType_t> mem_type({1, RT_MEMORY_HBM, RT_MEMORY_P2P_DDR}); | |||||
| Status status = MemManager::Instance().Initialize(mem_type); | |||||
| if (status != SUCCESS) { | |||||
| GELOGE(status, "[Init][MemManager] MemoryAllocatorManager initialize failed."); | |||||
| REPORT_CALL_ERROR("E19999", "MemManager initialize failed."); | |||||
| return status; | |||||
| } | } | ||||
| GE_CHK_STATUS_RET(OpsKernelBuilderManager::Instance().Initialize({}, false), | GE_CHK_STATUS_RET(OpsKernelBuilderManager::Instance().Initialize({}, false), | ||||
| "[Initialize][OpsKernelBuilderManager] failed."); | "[Initialize][OpsKernelBuilderManager] failed."); | ||||
| // Start profiling | |||||
| Options profiling_options; | |||||
| profiling_options.device_id = 0; | |||||
| // job id need to be set, the value is meaningless; | |||||
| profiling_options.job_id = "1"; | |||||
| ProfilingManager::Instance().Init(profiling_options); | |||||
| const auto &model_manager = ModelManager::GetInstance(); | |||||
| GE_CHECK_NOTNULL(model_manager); | |||||
| status = model_manager->EnableExceptionDump(options); | |||||
| if (status != SUCCESS) { | |||||
| GELOGW("[Init][ModelManager] Enable exception dump failed."); | |||||
| } | |||||
| ProfilingManager::Instance().Initialize(options); | |||||
| isInit_ = true; | isInit_ = true; | ||||
| GELOGI("Init GeExecutor over."); | GELOGI("Init GeExecutor over."); | ||||
| return ge::SUCCESS; | |||||
| return SUCCESS; | |||||
| } | } | ||||
| Status GeExecutor::Finalize() { | |||||
| GELOGI("Uninit GeExecutor begin."); | |||||
| Status GeExecutor::FinalizeEx() { | |||||
| if (isInit_ == false) { | if (isInit_ == false) { | ||||
| GELOGW("GeExecutor has not been initialized."); | GELOGW("GeExecutor has not been initialized."); | ||||
| return ge::SUCCESS; | return ge::SUCCESS; | ||||
| } | } | ||||
| (void) OpsKernelBuilderManager::Instance().Finalize(); | |||||
| GELOGI("Uninit GeExecutor begin."); | |||||
| (void)OpsKernelBuilderManager::Instance().Finalize(); | |||||
| // Stop profiling | |||||
| if (ProfilingManager::Instance().ProfilingOn()) { | |||||
| ProfilingManager::Instance().StopProfiling(); | |||||
| ProfilingManager::Instance().PluginUnInit(); | |||||
| } | |||||
| HostMemManager::Instance().Finalize(); | |||||
| ProfilingManager::Instance().Finalize(); | |||||
| GELOGI("Uninit GeExecutor over."); | GELOGI("Uninit GeExecutor over."); | ||||
| return ge::SUCCESS; | |||||
| return SUCCESS; | |||||
| } | |||||
| Status GeExecutor::Initialize() { | |||||
| // job id need to be set, the value is meaningless; | |||||
| const std::map<string, string> options({ | |||||
| {OPTION_EXEC_JOB_ID, "1"}, {OPTION_EXEC_PROFILING_MODE, ""}, {OPTION_EXEC_PROFILING_OPTIONS, ""} | |||||
| }); | |||||
| return GeExecutor::Initialize(options); | |||||
| } | |||||
| Status GeExecutor::Finalize() { | |||||
| return GeExecutor::FinalizeEx(); | |||||
| } | } | ||||
| Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length, | Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length, | ||||
| @@ -32,7 +32,6 @@ | |||||
| #include "graph/ge_attr_value.h" | #include "graph/ge_attr_value.h" | ||||
| #include "graph/ge_context.h" | #include "graph/ge_context.h" | ||||
| #include "external/graph/ge_error_codes.h" | #include "external/graph/ge_error_codes.h" | ||||
| #include "graph/manager/graph_var_manager.h" | |||||
| #include "graph/optimize/common/params.h" | #include "graph/optimize/common/params.h" | ||||
| #include "external/graph/types.h" | #include "external/graph/types.h" | ||||
| #include "graph/utils/attr_utils.h" | #include "graph/utils/attr_utils.h" | ||||
| @@ -17,7 +17,7 @@ | |||||
| #include "graph/build/task_generator.h" | #include "graph/build/task_generator.h" | ||||
| #include <string> | #include <string> | ||||
| #include <utility> | #include <utility> | ||||
| #include "common/profiling/profiling_manager.h" | |||||
| #include "nlohmann/json.hpp" | |||||
| #include "framework/common/types.h" | #include "framework/common/types.h" | ||||
| #include "framework/common/util.h" | #include "framework/common/util.h" | ||||
| #include "framework/common/debug/ge_log.h" | #include "framework/common/debug/ge_log.h" | ||||
| @@ -35,6 +35,7 @@ | |||||
| #include "external/ge/ge_api_types.h" | #include "external/ge/ge_api_types.h" | ||||
| #include "opskernel_manager/ops_kernel_builder_manager.h" | #include "opskernel_manager/ops_kernel_builder_manager.h" | ||||
| using Json = nlohmann::json; | |||||
| using domi::LogTimeStampDef; | using domi::LogTimeStampDef; | ||||
| using domi::ModelTaskDef; | using domi::ModelTaskDef; | ||||
| using domi::TaskDef; | using domi::TaskDef; | ||||
| @@ -51,6 +52,9 @@ const char *const kIsOutputVar = "OUTPUT_IS_VAR"; | |||||
| const char *const kProfilingMode = "PROFILING_MODE"; | const char *const kProfilingMode = "PROFILING_MODE"; | ||||
| const char *const kIteratorV2 = "IteratorV2"; | const char *const kIteratorV2 = "IteratorV2"; | ||||
| const char *const kKernelInfoNameHccl = "ops_kernel_info_hccl"; | const char *const kKernelInfoNameHccl = "ops_kernel_info_hccl"; | ||||
| const char *const kFpPoint = "fp_point"; | |||||
| const char *const kBpPoint = "bp_point"; | |||||
| const uint32_t kProfilingArStep = 2; | const uint32_t kProfilingArStep = 2; | ||||
| const uint64_t kProfilingFpStartLogid = 1; | const uint64_t kProfilingFpStartLogid = 1; | ||||
| const uint64_t kProfilingBpEndLogid = 2; | const uint64_t kProfilingBpEndLogid = 2; | ||||
| @@ -65,6 +69,8 @@ namespace ge { | |||||
| TaskGenerator::TaskGenerator(uint8_t *var_mem_base, uint64_t var_mem_size) { | TaskGenerator::TaskGenerator(uint8_t *var_mem_base, uint64_t var_mem_size) { | ||||
| var_mem_base_ = var_mem_base; | var_mem_base_ = var_mem_base; | ||||
| var_mem_size_ = var_mem_size; | var_mem_size_ = var_mem_size; | ||||
| fp_point_ = domi::GetContext().forward_point; | |||||
| bp_point_ = domi::GetContext().backward_point; | |||||
| } | } | ||||
| TaskGenerator::~TaskGenerator() {} | TaskGenerator::~TaskGenerator() {} | ||||
| @@ -941,12 +947,53 @@ Status TaskGenerator::FindBpOfEnv(const ComputeGraphPtr &graph, const std::strin | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| Status TaskGenerator::GetFpBpIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point, | |||||
| vector<uint32_t> &all_reduce_nodes, std::string &fp_point_str, | |||||
| std::string &bp_point_str) const { | |||||
| void TaskGenerator::GetFpBpPoint(std::string &fp_point, std::string &bp_point) { | |||||
| // Env or options mode, fp_point_/bp_point_ have initiliazed on profiling init | |||||
| if (!fp_point_.empty() && !bp_point_.empty()) { | |||||
| fp_point = fp_point_; | |||||
| bp_point = bp_point_; | |||||
| GELOGI("Bp[%s] Fp[%s] have been initialized in env or options.", bp_point.c_str(), fp_point.c_str()); | |||||
| return; | |||||
| } | |||||
| // ProfApi mode and training trace is set | |||||
| // Parse options first | |||||
| std::string profiling_options; | |||||
| graphStatus get_status = GetContext().GetOption(OPTION_EXEC_PROFILING_OPTIONS, profiling_options); | |||||
| if (get_status != GRAPH_SUCCESS || profiling_options.empty()) { | |||||
| char env_profiling_options[MSPROF_OPTIONS_DEF_LEN_MAX] = {0x00}; | |||||
| if (mmGetEnv("PROFILING_OPTIONS", env_profiling_options, MSPROF_OPTIONS_DEF_LEN_MAX) != EN_OK) { | |||||
| GELOGI("PROFILING_OPTIONS env is not exist."); | |||||
| return; | |||||
| } | |||||
| GELOGI("Parse env PROFILING_OPTIONS:%s.", env_profiling_options); | |||||
| profiling_options = env_profiling_options; | |||||
| } | |||||
| ProfilingManager::Instance().GetFpBpPoint(fp_point_str, bp_point_str); | |||||
| if (!profiling_options.empty()) { | |||||
| try { | |||||
| Json prof_options = Json::parse(profiling_options); | |||||
| if (prof_options.contains(kFpPoint)) { | |||||
| fp_point_ = prof_options[kFpPoint]; | |||||
| } | |||||
| if (prof_options.contains(kBpPoint)) { | |||||
| bp_point_ = prof_options[kBpPoint]; | |||||
| } | |||||
| fp_point = fp_point_; | |||||
| bp_point = bp_point_; | |||||
| if (!fp_point_.empty() && !bp_point_.empty()) { | |||||
| GELOGI("Training trace bp fp is set, bp_point:%s, fp_point:%s.", bp_point_.c_str(), fp_point_.c_str()); | |||||
| } | |||||
| } catch (...) { | |||||
| GELOGW("Json prof options is invalid."); | |||||
| return; | |||||
| } | |||||
| } | |||||
| } | |||||
| Status TaskGenerator::GetFpBpIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point, | |||||
| vector<uint32_t> &all_reduce_nodes, const std::string &fp_point_str, | |||||
| const std::string &bp_point_str) const { | |||||
| Status ret = SUCCESS; | Status ret = SUCCESS; | ||||
| if (fp_point_str.empty()) { | if (fp_point_str.empty()) { | ||||
| ret = AutoFindFpOpIndex(graph, profiling_point); | ret = AutoFindFpOpIndex(graph, profiling_point); | ||||
| @@ -973,11 +1020,11 @@ Status TaskGenerator::FindProfilingNodeIndex(const ComputeGraphPtr &graph, Profi | |||||
| } | } | ||||
| Status TaskGenerator::FindProfilingTaskIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point, | Status TaskGenerator::FindProfilingTaskIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point, | ||||
| vector<uint32_t> &all_reduce_nodes) const { | |||||
| vector<uint32_t> &all_reduce_nodes) { | |||||
| GE_CHECK_NOTNULL(graph); | GE_CHECK_NOTNULL(graph); | ||||
| const char *profiling_mode = std::getenv(kProfilingMode); | const char *profiling_mode = std::getenv(kProfilingMode); | ||||
| bool is_profiling = (profiling_mode != nullptr) || ProfilingManager::Instance().ProfilingOn() || | |||||
| ProfilingManager::Instance().ProfilingTrainingTraceOn(); | |||||
| bool is_profiling = (profiling_mode != nullptr) || domi::GetContext().profiling_on || | |||||
| domi::GetContext().profiling_trace_on; | |||||
| if (!is_profiling) { | if (!is_profiling) { | ||||
| GELOGD("Profiling is not open."); | GELOGD("Profiling is not open."); | ||||
| return SUCCESS; | return SUCCESS; | ||||
| @@ -992,6 +1039,7 @@ Status TaskGenerator::FindProfilingTaskIndex(const ComputeGraphPtr &graph, Profi | |||||
| GELOGI("Start get FP/BP index."); | GELOGI("Start get FP/BP index."); | ||||
| std::string fp_point_str; | std::string fp_point_str; | ||||
| std::string bp_point_str; | std::string bp_point_str; | ||||
| GetFpBpPoint(fp_point_str, bp_point_str); | |||||
| Status ret = GetFpBpIndex(graph, profiling_point, all_reduce_nodes, fp_point_str, bp_point_str); | Status ret = GetFpBpIndex(graph, profiling_point, all_reduce_nodes, fp_point_str, bp_point_str); | ||||
| if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
| GELOGW("Get FP_POINT BP_POINT failed."); | GELOGW("Get FP_POINT BP_POINT failed."); | ||||
| @@ -1071,8 +1119,8 @@ Status TaskGenerator::InsertProfilingTaskBefore(const OpDescPtr &op_desc, const | |||||
| vector<uint32_t> &all_reduce_nodes, uint32_t node_index, | vector<uint32_t> &all_reduce_nodes, uint32_t node_index, | ||||
| vector<domi::TaskDef> &task_def_list) { | vector<domi::TaskDef> &task_def_list) { | ||||
| const char *profiling_mode = std::getenv(kProfilingMode); | const char *profiling_mode = std::getenv(kProfilingMode); | ||||
| bool is_profiling = (profiling_mode != nullptr) || ProfilingManager::Instance().ProfilingOn() || | |||||
| ProfilingManager::Instance().ProfilingTrainingTraceOn(); | |||||
| bool is_profiling = (profiling_mode != nullptr) || domi::GetContext().profiling_on || | |||||
| domi::GetContext().profiling_trace_on; | |||||
| bool is_insert_fp_profiling_task = false; | bool is_insert_fp_profiling_task = false; | ||||
| (void)ge::AttrUtils::GetBool(op_desc, ATTR_NAME_INSERT_FP_PROFILILNG_TASK, is_insert_fp_profiling_task); | (void)ge::AttrUtils::GetBool(op_desc, ATTR_NAME_INSERT_FP_PROFILILNG_TASK, is_insert_fp_profiling_task); | ||||
| bool is_insert_bp_profiling_task = false; | bool is_insert_bp_profiling_task = false; | ||||
| @@ -1167,8 +1215,8 @@ Status TaskGenerator::InsertProfilingTaskAfter(const OpDescPtr &op_desc, const P | |||||
| vector<domi::TaskDef> &task_def_list) { | vector<domi::TaskDef> &task_def_list) { | ||||
| GE_CHECK_NOTNULL(op_desc); | GE_CHECK_NOTNULL(op_desc); | ||||
| const char *profiling_mode = std::getenv(kProfilingMode); | const char *profiling_mode = std::getenv(kProfilingMode); | ||||
| bool is_profiling = (profiling_mode != nullptr) || ProfilingManager::Instance().ProfilingOn() || | |||||
| ProfilingManager::Instance().ProfilingTrainingTraceOn(); | |||||
| bool is_profiling = (profiling_mode != nullptr) || domi::GetContext().profiling_on || | |||||
| domi::GetContext().profiling_trace_on; | |||||
| bool is_insert_bp_profiling_task = false; | bool is_insert_bp_profiling_task = false; | ||||
| (void)ge::AttrUtils::GetBool(op_desc, ATTR_NAME_INSERT_BP_PROFILILNG_TASK, is_insert_bp_profiling_task); | (void)ge::AttrUtils::GetBool(op_desc, ATTR_NAME_INSERT_BP_PROFILILNG_TASK, is_insert_bp_profiling_task); | ||||
| bool is_insert_end_profiling_task = false; | bool is_insert_end_profiling_task = false; | ||||
| @@ -123,11 +123,12 @@ class TaskGenerator { | |||||
| Status FindBpOfEnv(const ComputeGraphPtr &graph, const std::string &bp_point_str, ProfilingPoint &profiling_point, | Status FindBpOfEnv(const ComputeGraphPtr &graph, const std::string &bp_point_str, ProfilingPoint &profiling_point, | ||||
| vector<uint32_t> &all_reduce_nodes) const; | vector<uint32_t> &all_reduce_nodes) const; | ||||
| void GetFpBpPoint(std::string &fp_point, std::string &bp_point); | |||||
| Status GetFpBpIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point, vector<uint32_t> &all_reduce_nodes, | Status GetFpBpIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point, vector<uint32_t> &all_reduce_nodes, | ||||
| std::string& fp_point_str, std::string& bp_point_str) const; | |||||
| const std::string &fp_point_str, const std::string &bp_point_str) const; | |||||
| Status FindProfilingTaskIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point, | Status FindProfilingTaskIndex(const ComputeGraphPtr &graph, ProfilingPoint &profiling_point, | ||||
| std::vector<uint32_t> &all_reduce_nodes) const; | |||||
| std::vector<uint32_t> &all_reduce_nodes); | |||||
| Status InsertProfilingTaskBefore(const OpDescPtr &op_desc, const ProfilingPoint &profiling_point, | Status InsertProfilingTaskBefore(const OpDescPtr &op_desc, const ProfilingPoint &profiling_point, | ||||
| std::vector<uint32_t> &all_reduce_nodes, uint32_t node_index, | std::vector<uint32_t> &all_reduce_nodes, uint32_t node_index, | ||||
| std::vector<domi::TaskDef> &task_def_list); | std::vector<domi::TaskDef> &task_def_list); | ||||
| @@ -164,6 +165,8 @@ class TaskGenerator { | |||||
| bool IsSubGraphOfDynamicGraph(const ComputeGraphPtr &graph) const; | bool IsSubGraphOfDynamicGraph(const ComputeGraphPtr &graph) const; | ||||
| std::string fp_point_; | |||||
| std::string bp_point_; | |||||
| uint8_t *var_mem_base_ = nullptr; | uint8_t *var_mem_base_ = nullptr; | ||||
| uint64_t var_mem_size_ = 0; | uint64_t var_mem_size_ = 0; | ||||
| }; | }; | ||||
| @@ -21,11 +21,14 @@ | |||||
| #include "common/ge_call_wrapper.h" | #include "common/ge_call_wrapper.h" | ||||
| #include "common/local_context.h" | #include "common/local_context.h" | ||||
| #include "graph/manager/graph_var_manager.h" | #include "graph/manager/graph_var_manager.h" | ||||
| #include "graph/manager/graph_mem_manager.h" | |||||
| #include "graph/manager/host_mem_manager.h" | |||||
| #include "graph/utils/tensor_adapter.h" | #include "graph/utils/tensor_adapter.h" | ||||
| #include "graph/load/graph_loader.h" | #include "graph/load/graph_loader.h" | ||||
| #include "graph/load/model_manager/model_manager.h" | #include "graph/load/model_manager/model_manager.h" | ||||
| #include "common/math/math_util.h" | #include "common/math/math_util.h" | ||||
| #include "common/formats/utils/formats_trans_utils.h" | #include "common/formats/utils/formats_trans_utils.h" | ||||
| #include "common/profiling/profiling_manager.h" | |||||
| namespace { | namespace { | ||||
| constexpr int32_t kBase = 10; | constexpr int32_t kBase = 10; | ||||
| @@ -40,6 +43,12 @@ namespace ge { | |||||
| /// @return Status result of function | /// @return Status result of function | ||||
| /// | /// | ||||
| Status ModelExecutor::Initialize(const map<string, string> &options, uint64_t session_id) { | Status ModelExecutor::Initialize(const map<string, string> &options, uint64_t session_id) { | ||||
| if (init_flag_) { | |||||
| GELOGW("ModelExecutor has already initialized."); | |||||
| return SUCCESS; | |||||
| } | |||||
| session_id_ = session_id; | |||||
| graph_run_listener_ = MakeShared<GraphModelListener>(sync_run_mutex_, condition_); | graph_run_listener_ = MakeShared<GraphModelListener>(sync_run_mutex_, condition_); | ||||
| if (graph_run_listener_ == nullptr) { | if (graph_run_listener_ == nullptr) { | ||||
| REPORT_CALL_ERROR("E19999", "New GraphModelListener fail"); | REPORT_CALL_ERROR("E19999", "New GraphModelListener fail"); | ||||
| @@ -47,14 +56,15 @@ Status ModelExecutor::Initialize(const map<string, string> &options, uint64_t se | |||||
| return MEMALLOC_FAILED; | return MEMALLOC_FAILED; | ||||
| } | } | ||||
| const auto model_manager = ModelManager::GetInstance(); | |||||
| GE_CHECK_NOTNULL(model_manager); | |||||
| Status status = model_manager->EnableExceptionDump(options); | |||||
| size_t total_mem_size = 0; | |||||
| GE_CHK_STATUS_RET_NOLOG(GetTotalMemorySize(total_mem_size)); | |||||
| Status status = VarManager::Instance(session_id)->SetMemoryMallocSize(options, total_mem_size); | |||||
| if (status != SUCCESS) { | if (status != SUCCESS) { | ||||
| GELOGE(status, "[Set][MemoryMallocSize] failed."); | |||||
| REPORT_CALL_ERROR("E19999", "VarManager SetMemoryMallocSize failed, InnerSession:%lu.", session_id_); | |||||
| return status; | return status; | ||||
| } | } | ||||
| session_id_ = session_id; | |||||
| train_graph_flag_ = ParseTrainGraphFlag(); | train_graph_flag_ = ParseTrainGraphFlag(); | ||||
| thread_run_flag_.store(true); | thread_run_flag_.store(true); | ||||
| run_thread_ = std::thread(&ModelExecutor::RunThread, this); | run_thread_ = std::thread(&ModelExecutor::RunThread, this); | ||||
| @@ -83,10 +93,39 @@ Status ModelExecutor::Finalize() { | |||||
| GELOGW("Graph executor FreeExecuteMemory failed, resources may not be released correctly."); | GELOGW("Graph executor FreeExecuteMemory failed, resources may not be released correctly."); | ||||
| } | } | ||||
| GELOGI("VarManager free var memory."); | |||||
| (void)VarManager::Instance(session_id_)->FreeVarMemory(); | |||||
| MemManager::Instance().FreeSessionMemory(session_id_); | |||||
| ModelManager::GetInstance()->DestroyAicpuSession(session_id_); | ModelManager::GetInstance()->DestroyAicpuSession(session_id_); | ||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| Status ModelExecutor::GetTotalMemorySize(size_t &total_mem_size) { | |||||
| rtError_t rt_ret = rtSetDevice(GetContext().DeviceId()); | |||||
| if (rt_ret != RT_ERROR_NONE) { | |||||
| REPORT_CALL_ERROR("E19999", "Call rtSetDevice failed, device_id:%u, ret:0x%X", | |||||
| GetContext().DeviceId(), rt_ret); | |||||
| GELOGE(RT_FAILED, "[Call][RtSetDevice] failed, device_id:%u, ret:0x%X", GetContext().DeviceId(), rt_ret); | |||||
| return RT_FAILED; | |||||
| } | |||||
| size_t free_mem = 0; | |||||
| rt_ret = rtMemGetInfoEx(RT_MEMORYINFO_HBM, &free_mem, &total_mem_size); | |||||
| if (rt_ret != RT_ERROR_NONE) { | |||||
| REPORT_CALL_ERROR("E19999", "Call rtMemGetInfo failed, ret:0x%X", rt_ret); | |||||
| GELOGE(RT_FAILED, "[Call][RtMemGetInfo] failed, ret:0x%X", rt_ret); | |||||
| return RT_FAILED; | |||||
| } | |||||
| rt_ret = rtDeviceReset(GetContext().DeviceId()); | |||||
| if (rt_ret != RT_ERROR_NONE) { | |||||
| REPORT_CALL_ERROR("E19999", "Call rtDeviceReset failed, device_id:%u, ret:0x%X", | |||||
| GetContext().DeviceId(), rt_ret); | |||||
| GELOGE(RT_FAILED, "[Call][RtDeviceReset] failed, device_id:%u, ret:0x%X", GetContext().DeviceId(), rt_ret); | |||||
| return RT_FAILED; | |||||
| } | |||||
| return SUCCESS; | |||||
| } | |||||
| // OPTION_GRAPH_RUN_MODE is supposed to be a session-level option, but it used to be set to global-level in the past. | // OPTION_GRAPH_RUN_MODE is supposed to be a session-level option, but it used to be set to global-level in the past. | ||||
| // If can not parse from session, it can parse from global by GetContext(). | // If can not parse from session, it can parse from global by GetContext(). | ||||
| bool ModelExecutor::ParseTrainGraphFlag() { | bool ModelExecutor::ParseTrainGraphFlag() { | ||||
| @@ -363,6 +402,7 @@ Status ModelExecutor::ModelLoad(const GeRootModelPtr &ge_root_model, const Graph | |||||
| ge_root_model->SetModelId(model_id); | ge_root_model->SetModelId(model_id); | ||||
| graph_node->SetGeRootModel(ge_root_model); | graph_node->SetGeRootModel(ge_root_model); | ||||
| AddGraphNode(graph_node->GetGraphId(), graph_node); | AddGraphNode(graph_node->GetGraphId(), graph_node); | ||||
| ProfilingManager::Instance().SetGraphIdToDeviceMap(graph_node->GetGraphId(), GetContext().DeviceId()); | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| @@ -92,6 +92,7 @@ class ModelExecutor : public Executor { | |||||
| private: | private: | ||||
| bool ParseTrainGraphFlag(); | bool ParseTrainGraphFlag(); | ||||
| Status GetTotalMemorySize(size_t &total_mem_size); | |||||
| void AddGraphNode(GraphId graph_id, const GraphNodePtr &graph_node); | void AddGraphNode(GraphId graph_id, const GraphNodePtr &graph_node); | ||||
| void RemoveGraphNode(GraphId graph_id); | void RemoveGraphNode(GraphId graph_id); | ||||
| @@ -500,6 +500,8 @@ void DavinciModel::InitRuntimeParams() { | |||||
| ret = ge::AttrUtils::GetInt(ge_model_, ATTR_MODEL_ZERO_COPY_MEMORY_SIZE, value); | ret = ge::AttrUtils::GetInt(ge_model_, ATTR_MODEL_ZERO_COPY_MEMORY_SIZE, value); | ||||
| runtime_param_.zero_copy_size = ret ? value : 0; | runtime_param_.zero_copy_size = ret ? value : 0; | ||||
| VarManager::Instance(session_id_)->SetMemManager(&MemManager::Instance()); | |||||
| GELOGI("InitRuntimeParams(), %s.", runtime_param_.ToString().c_str()); | GELOGI("InitRuntimeParams(), %s.", runtime_param_.ToString().c_str()); | ||||
| } | } | ||||
| @@ -109,7 +109,6 @@ | |||||
| #include "register/custom_pass_helper.h" | #include "register/custom_pass_helper.h" | ||||
| #include "external/graph/types.h" | #include "external/graph/types.h" | ||||
| #include "common/util/error_manager/error_manager.h" | #include "common/util/error_manager/error_manager.h" | ||||
| #include "common/profiling/profiling_manager.h" | |||||
| namespace { | namespace { | ||||
| const char *const kSummary = "Summary"; | const char *const kSummary = "Summary"; | ||||
| @@ -462,9 +461,6 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph, | |||||
| const std::map<std::string, std::string> &options, | const std::map<std::string, std::string> &options, | ||||
| const OmgContext &omg_context) { | const OmgContext &omg_context) { | ||||
| IncreaseGraphCount(graph_id); | IncreaseGraphCount(graph_id); | ||||
| auto device_id = GetContext().DeviceId(); | |||||
| GELOGD("Device id is %u", device_id); | |||||
| ProfilingManager::Instance().SetGraphIdToDeviceMap(graph_id, device_id); | |||||
| // validation for adding graphs of same graph_id in multi-thread secenario | // validation for adding graphs of same graph_id in multi-thread secenario | ||||
| // 1.previous thread owns same graph_id has finished the AddGraph procession | // 1.previous thread owns same graph_id has finished the AddGraph procession | ||||
| if (GetAddGraphCondition(graph_id) == kDoneAdded) { | if (GetAddGraphCondition(graph_id) == kDoneAdded) { | ||||
| @@ -69,6 +69,37 @@ Status MemManager::Initialize(const std::vector<rtMemType_t> &memory_type) { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| uint8_t *MemManager::MallocMemory(rtMemType_t memory_type, const std::string &purpose, const std::string &memory_key, | |||||
| size_t memory_size, uint32_t device_id) { | |||||
| return MemManager::Instance().MemInstance(memory_type).MallocMemory(purpose, memory_key, memory_size, device_id); | |||||
| } | |||||
| Status MemManager::FreeMemory(rtMemType_t memory_type, const std::string &memory_key, uint32_t device_id) { | |||||
| return MemManager::Instance().MemInstance(memory_type).FreeMemory(memory_key, device_id); | |||||
| } | |||||
| uint8_t *MemManager::GetMemoryBase(rtMemType_t memory_type, const std::string &memory_key, uint32_t device_id) { | |||||
| if (memory_type == RT_MEMORY_RDMA_HBM) { | |||||
| return MemManager::Instance().RdmaPoolInstance(RT_MEMORY_HBM).GetRdmaBaseAddr(); | |||||
| } | |||||
| return MemManager::Instance().MemInstance(memory_type).GetMemoryAddr(memory_key, device_id); | |||||
| } | |||||
| uint8_t *MemManager::GetMemoryAddr(rtMemType_t memory_type, const std::string &memory_key, uint32_t device_id) { | |||||
| return MemManager::Instance().MemInstance(memory_type).GetMemoryAddr(memory_key, device_id); | |||||
| } | |||||
| uint8_t *MemManager::GetPoolMemory(rtMemType_t memory_type, size_t memory_size, uint32_t device_id) { | |||||
| return MemManager::Instance().RdmaPoolInstance(memory_type).Malloc(memory_size, device_id); | |||||
| } | |||||
| void MemManager::FreeSessionMemory(uint64_t session_id, uint32_t device_id) { | |||||
| for (auto memory_type : memory_type_) { | |||||
| (void)SessionScopeMemInstance(memory_type).Free(session_id, device_id); | |||||
| } | |||||
| } | |||||
| template <typename T> | template <typename T> | ||||
| void FinalizeAllocatorMap(std::map<rtMemType_t, T *> &allocate_map) { | void FinalizeAllocatorMap(std::map<rtMemType_t, T *> &allocate_map) { | ||||
| for (auto &allocator : allocate_map) { | for (auto &allocator : allocate_map) { | ||||
| @@ -34,22 +34,34 @@ | |||||
| #include "graph/manager/session_scope_mem_allocator.h" | #include "graph/manager/session_scope_mem_allocator.h" | ||||
| #include "graph/node.h" | #include "graph/node.h" | ||||
| #include "runtime/mem.h" | #include "runtime/mem.h" | ||||
| #include "common/mem_manager.h" | |||||
| namespace ge { | namespace ge { | ||||
| using MemoryAllocatorPtr = std::shared_ptr<MemoryAllocator>; | |||||
| class MemManager { | |||||
| class MemManager : public MemoryManager { | |||||
| public: | public: | ||||
| MemManager(); | MemManager(); | ||||
| virtual ~MemManager(); | virtual ~MemManager(); | ||||
| static MemManager &Instance(); | static MemManager &Instance(); | ||||
| uint8_t *MallocMemory(rtMemType_t memory_type, const std::string &purpose, const std::string &memory_key, | |||||
| size_t memory_size, uint32_t device_id); | |||||
| Status FreeMemory(rtMemType_t memory_type, const std::string &memory_key, uint32_t device_id); | |||||
| uint8_t *GetMemoryBase(rtMemType_t memory_type, const std::string &memory_key, uint32_t device_id); | |||||
| uint8_t *GetMemoryAddr(rtMemType_t memory_type, const std::string &memory_key, uint32_t device_id); | |||||
| uint8_t *GetPoolMemory(rtMemType_t memory_type, size_t memory_size, uint32_t device_id); | |||||
| void FreeSessionMemory(uint64_t session_id, uint32_t device_id = 0); | |||||
| MemoryAllocator &MemInstance(rtMemType_t memory_type); | MemoryAllocator &MemInstance(rtMemType_t memory_type); | ||||
| CachingAllocator &CachingInstance(rtMemType_t memory_type); | CachingAllocator &CachingInstance(rtMemType_t memory_type); | ||||
| RdmaPoolAllocator &RdmaPoolInstance(rtMemType_t memory_type); | RdmaPoolAllocator &RdmaPoolInstance(rtMemType_t memory_type); | ||||
| HostMemAllocator &HostMemInstance(rtMemType_t memory_type); | HostMemAllocator &HostMemInstance(rtMemType_t memory_type); | ||||
| SessionScopeMemAllocator &SessionScopeMemInstance(rtMemType_t memory_type); | SessionScopeMemAllocator &SessionScopeMemInstance(rtMemType_t memory_type); | ||||
| MemManager(const MemManager &) = delete; | |||||
| MemManager &operator=(const MemManager &) = delete; | |||||
| /// | /// | ||||
| /// @ingroup ge_graph | /// @ingroup ge_graph | ||||
| /// @brief memory allocator manager init | /// @brief memory allocator manager init | ||||
| @@ -65,9 +77,10 @@ class MemManager { | |||||
| /// | /// | ||||
| void Finalize() noexcept; | void Finalize() noexcept; | ||||
| const std::vector<rtMemType_t> &GetAllMemoryType() const { return memory_type_; } | |||||
| private: | private: | ||||
| MemManager(const MemManager &) = delete; | |||||
| MemManager &operator=(const MemManager &) = delete; | |||||
| /// | /// | ||||
| /// @ingroup ge_graph | /// @ingroup ge_graph | ||||
| /// @param [in] memory_type memory type | /// @param [in] memory_type memory type | ||||
| @@ -17,7 +17,6 @@ | |||||
| #include "graph/manager/graph_var_manager.h" | #include "graph/manager/graph_var_manager.h" | ||||
| #include "graph/debug/ge_attr_define.h" | #include "graph/debug/ge_attr_define.h" | ||||
| #include "graph/manager/graph_mem_manager.h" | |||||
| #include "graph/manager/trans_var_data_utils.h" | #include "graph/manager/trans_var_data_utils.h" | ||||
| #include "graph/utils/type_utils.h" | #include "graph/utils/type_utils.h" | ||||
| #include "graph/ge_context.h" | #include "graph/ge_context.h" | ||||
| @@ -291,7 +290,7 @@ Status HbmMemResource::AssignVarMem(const std::string &var_name, uint64_t size, | |||||
| } | } | ||||
| Status RdmaMemResource::AssignVarMem(const std::string &var_name, uint64_t size, uint64_t session_id, size_t &address) { | Status RdmaMemResource::AssignVarMem(const std::string &var_name, uint64_t size, uint64_t session_id, size_t &address) { | ||||
| uint8_t *buffer = MemManager::Instance().RdmaPoolInstance(RT_MEMORY_HBM).Malloc(size); | |||||
| uint8_t *buffer = VarManager::Instance(session_id)->GetPoolMemory(RT_MEMORY_HBM, size); | |||||
| if (buffer == nullptr) { | if (buffer == nullptr) { | ||||
| REPORT_CALL_ERROR("E19999", "malloc rdma memory fail, var_size:%lu, var_name:%s", | REPORT_CALL_ERROR("E19999", "malloc rdma memory fail, var_size:%lu, var_name:%s", | ||||
| size, var_name.c_str()); | size, var_name.c_str()); | ||||
| @@ -339,8 +338,7 @@ void VarManager::Destory() { | |||||
| mem_resource_map_.clear(); | mem_resource_map_.clear(); | ||||
| } | } | ||||
| ge::Status VarManager::Init(const uint32_t &version, const uint64_t &session_id, const uint32_t &device_id, | |||||
| const uint64_t &job_id) { | |||||
| Status VarManager::Init(uint32_t version, uint64_t session_id, uint32_t device_id, uint64_t job_id) { | |||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | std::lock_guard<std::recursive_mutex> lock(mutex_); | ||||
| GELOGI("VarManager::Init, session id = %lu.", session_id); | GELOGI("VarManager::Init, session id = %lu.", session_id); | ||||
| if (var_resource_ == nullptr) { | if (var_resource_ == nullptr) { | ||||
| @@ -389,21 +387,6 @@ ge::Status VarManager::SetVarAddr(const std::string &var_name, const ge::GeTenso | |||||
| return ge::SUCCESS; | return ge::SUCCESS; | ||||
| } | } | ||||
| ge::Status VarManager::SaveVarAddr(const std::string &var_name, const ge::GeTensorDesc &tensor_desc, uint8_t *address, | |||||
| rtMemType_t memory_type) { | |||||
| GELOGI("VarManager::SaveVarAddr var_name = %s, data_type = %s, data_format = %s.", var_name.c_str(), | |||||
| ge::TypeUtils::DataTypeToSerialString(tensor_desc.GetDataType()).c_str(), | |||||
| ge::TypeUtils::FormatToSerialString(tensor_desc.GetFormat()).c_str()); | |||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | |||||
| if (var_resource_ == nullptr) { | |||||
| GELOGW("VarManager has not been init."); | |||||
| return ge::INTERNAL_ERROR; | |||||
| } | |||||
| var_resource_->SaveVarAddr(var_name, tensor_desc, address, memory_type); | |||||
| return ge::SUCCESS; | |||||
| } | |||||
| ge::Status VarManager::GetVarAddr(const std::string &var_name, const ge::GeTensorDesc &tensor_desc, uint8_t **dev_ptr, | ge::Status VarManager::GetVarAddr(const std::string &var_name, const ge::GeTensorDesc &tensor_desc, uint8_t **dev_ptr, | ||||
| rtMemType_t &memory_type) { | rtMemType_t &memory_type) { | ||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | std::lock_guard<std::recursive_mutex> lock(mutex_); | ||||
| @@ -637,8 +620,20 @@ rtMemType_t VarManager::GetVarMemType(const int64_t &offset) { | |||||
| return var_resource_->GetVarMemType(offset); | return var_resource_->GetVarMemType(offset); | ||||
| } | } | ||||
| void VarManager::SetMemManager(MemoryManager *mem_manager) { | |||||
| // Better use shared_ptr instead, reconsitution later. | |||||
| GELOGI("Set MemManager to VarManager."); | |||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | |||||
| mem_manager_ = mem_manager; | |||||
| } | |||||
| ge::Status VarManager::MallocVarMemory(size_t memory_size) { | ge::Status VarManager::MallocVarMemory(size_t memory_size) { | ||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | std::lock_guard<std::recursive_mutex> lock(mutex_); | ||||
| if (mem_manager_ == nullptr) { | |||||
| GELOGE(FAILED, "MemManager has not been init."); | |||||
| REPORT_INNER_ERROR("E19999", "MemManager has not been init, session_id: %lu", session_id_); | |||||
| return FAILED; | |||||
| } | |||||
| uint8_t *var_mem_base = nullptr; | uint8_t *var_mem_base = nullptr; | ||||
| string memory_key = std::to_string(session_id_); | string memory_key = std::to_string(session_id_); | ||||
| @@ -649,7 +644,7 @@ ge::Status VarManager::MallocVarMemory(size_t memory_size) { | |||||
| var_memory_size = (var_memory_size + kSessionMemAlignSize - 1) / kSessionMemAlignSize * kSessionMemAlignSize; | var_memory_size = (var_memory_size + kSessionMemAlignSize - 1) / kSessionMemAlignSize * kSessionMemAlignSize; | ||||
| const string purpose("variables and constant op memory in training network."); | const string purpose("variables and constant op memory in training network."); | ||||
| var_mem_base = MemManager::Instance().MemInstance(RT_MEMORY_HBM).MallocMemory(purpose, memory_key, var_memory_size); | |||||
| var_mem_base = mem_manager_->MallocMemory(RT_MEMORY_HBM, purpose, memory_key, var_memory_size, device_id_); | |||||
| if (var_mem_base == nullptr) { | if (var_mem_base == nullptr) { | ||||
| GELOGE(ge::INTERNAL_ERROR, "[Malloc][VarMemory] failed, size:%zu, session_id:%s", | GELOGE(ge::INTERNAL_ERROR, "[Malloc][VarMemory] failed, size:%zu, session_id:%s", | ||||
| var_memory_size, memory_key.c_str()); | var_memory_size, memory_key.c_str()); | ||||
| @@ -660,20 +655,29 @@ ge::Status VarManager::MallocVarMemory(size_t memory_size) { | |||||
| uint8_t *VarManager::GetVarMemoryBase(rtMemType_t memory_type) { | uint8_t *VarManager::GetVarMemoryBase(rtMemType_t memory_type) { | ||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | std::lock_guard<std::recursive_mutex> lock(mutex_); | ||||
| if (memory_type == RT_MEMORY_RDMA_HBM) { | |||||
| return MemManager::Instance().RdmaPoolInstance(RT_MEMORY_HBM).GetRdmaBaseAddr(); | |||||
| if (mem_manager_ == nullptr) { | |||||
| GELOGE(FAILED, "MemManager has not been init."); | |||||
| REPORT_INNER_ERROR("E19999", "MemManager has not been init, session_id: %lu", session_id_); | |||||
| return nullptr; | |||||
| } | } | ||||
| string memory_key = std::to_string(session_id_); | string memory_key = std::to_string(session_id_); | ||||
| return MemManager::Instance().MemInstance(memory_type).GetMemoryAddr(memory_key); | |||||
| return mem_manager_->GetMemoryBase(memory_type, memory_key, device_id_); | |||||
| } | } | ||||
| uint8_t *VarManager::GetVarMemoryAddr(uint8_t *logic_addr, rtMemType_t memory_type) { | uint8_t *VarManager::GetVarMemoryAddr(uint8_t *logic_addr, rtMemType_t memory_type) { | ||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | std::lock_guard<std::recursive_mutex> lock(mutex_); | ||||
| if (mem_manager_ == nullptr) { | |||||
| GELOGE(FAILED, "MemManager has not been init."); | |||||
| REPORT_INNER_ERROR("E19999", "MemManager has not been init, session_id: %lu", session_id_); | |||||
| return nullptr; | |||||
| } | |||||
| if (memory_type == RT_MEMORY_RDMA_HBM) { | if (memory_type == RT_MEMORY_RDMA_HBM) { | ||||
| return logic_addr; | return logic_addr; | ||||
| } | } | ||||
| string mem_key = std::to_string(session_id_); | string mem_key = std::to_string(session_id_); | ||||
| uint8_t *mem_base = MemManager::Instance().MemInstance(memory_type).GetMemoryAddr(mem_key); | |||||
| uint8_t *mem_base = mem_manager_->GetMemoryAddr(memory_type, mem_key, device_id_); | |||||
| if (mem_base == nullptr) { | if (mem_base == nullptr) { | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| @@ -684,8 +688,25 @@ uint8_t *VarManager::GetVarMemoryAddr(uint8_t *logic_addr, rtMemType_t memory_ty | |||||
| ge::Status VarManager::FreeVarMemory() { | ge::Status VarManager::FreeVarMemory() { | ||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | std::lock_guard<std::recursive_mutex> lock(mutex_); | ||||
| if (mem_manager_ == nullptr) { | |||||
| GELOGE(FAILED, "MemManager has not been init."); | |||||
| REPORT_INNER_ERROR("E19999", "MemManager has not been init, session_id: %lu", session_id_); | |||||
| return FAILED; | |||||
| } | |||||
| string memory_key = std::to_string(SessionId()); | string memory_key = std::to_string(SessionId()); | ||||
| return MemManager::Instance().MemInstance(RT_MEMORY_HBM).FreeMemory(memory_key); | |||||
| return mem_manager_->FreeMemory(RT_MEMORY_HBM, memory_key, device_id_); | |||||
| } | |||||
| uint8_t *VarManager::GetPoolMemory(rtMemType_t memory_type, size_t mem_size) { | |||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | |||||
| if (mem_manager_ == nullptr) { | |||||
| GELOGE(FAILED, "MemManager has not been init."); | |||||
| REPORT_INNER_ERROR("E19999", "MemManager has not been init, session_id: %lu", session_id_); | |||||
| return nullptr; | |||||
| } | |||||
| return mem_manager_->GetPoolMemory(memory_type, mem_size, device_id_); | |||||
| } | } | ||||
| ge::Status VarManager::SetTransRoad(const std::string &var_name, const VarTransRoad &trans_road) { | ge::Status VarManager::SetTransRoad(const std::string &var_name, const VarTransRoad &trans_road) { | ||||
| @@ -724,34 +745,7 @@ Status VarManager::GetChangedGraphId(const std::string &var_name, uint32_t &grap | |||||
| return var_resource_->GetChangedGraphId(var_name, graph_id); | return var_resource_->GetChangedGraphId(var_name, graph_id); | ||||
| } | } | ||||
| Status VarManager::GetTotalMemorySize(size_t &total_mem_size) { | |||||
| rtError_t rt_ret = rtSetDevice(GetContext().DeviceId()); | |||||
| if (rt_ret != RT_ERROR_NONE) { | |||||
| REPORT_CALL_ERROR("E19999", "Call rtSetDevice failed, device_id:%u, ret:0x%X", | |||||
| GetContext().DeviceId(), rt_ret); | |||||
| GELOGE(RT_FAILED, "[Call][RtSetDevice] failed, device_id:%u, ret:0x%X", GetContext().DeviceId(), rt_ret); | |||||
| return RT_FAILED; | |||||
| } | |||||
| size_t free_mem = 0; | |||||
| rt_ret = rtMemGetInfoEx(RT_MEMORYINFO_HBM, &free_mem, &total_mem_size); | |||||
| if (rt_ret != RT_ERROR_NONE) { | |||||
| REPORT_CALL_ERROR("E19999", "Call rtMemGetInfo failed, ret:0x%X", rt_ret); | |||||
| GELOGE(RT_FAILED, "[Call][RtMemGetInfo] failed, ret:0x%X", rt_ret); | |||||
| return RT_FAILED; | |||||
| } | |||||
| rt_ret = rtDeviceReset(GetContext().DeviceId()); | |||||
| if (rt_ret != RT_ERROR_NONE) { | |||||
| REPORT_CALL_ERROR("E19999", "Call rtDeviceReset failed, device_id:%u, ret:0x%X", | |||||
| GetContext().DeviceId(), rt_ret); | |||||
| GELOGE(RT_FAILED, "[Call][RtDeviceReset] failed, device_id:%u, ret:0x%X", GetContext().DeviceId(), rt_ret); | |||||
| return RT_FAILED; | |||||
| } | |||||
| return SUCCESS; | |||||
| } | |||||
| Status VarManager::SetMemoryMallocSize(const map<string, string> &options) { | |||||
| size_t total_mem_size = 0; | |||||
| GE_CHK_STATUS_RET_NOLOG(VarManager::GetTotalMemorySize(total_mem_size)); | |||||
| Status VarManager::SetMemoryMallocSize(const map<string, string> &options, size_t total_mem_size) { | |||||
| GEEVENT("Total memory size is %zu", total_mem_size); | GEEVENT("Total memory size is %zu", total_mem_size); | ||||
| graph_mem_max_size_ = floor(total_mem_size * kGraphMemoryManagerMallocRatio); | graph_mem_max_size_ = floor(total_mem_size * kGraphMemoryManagerMallocRatio); | ||||
| @@ -32,6 +32,7 @@ | |||||
| #include "graph/op_desc.h" | #include "graph/op_desc.h" | ||||
| #include "external/graph/tensor.h" | #include "external/graph/tensor.h" | ||||
| #include "runtime/mem.h" | #include "runtime/mem.h" | ||||
| #include "common/mem_manager.h" | |||||
| namespace ge { | namespace ge { | ||||
| const size_t kGraphMemoryManagerMallocMaxSize = 26UL * 1024UL * 1024UL * 1024UL; | const size_t kGraphMemoryManagerMallocMaxSize = 26UL * 1024UL * 1024UL * 1024UL; | ||||
| @@ -201,39 +202,37 @@ class RdmaMemResource : public MemResource { | |||||
| Status AssignVarMem(const std::string &var_name, uint64_t size, uint64_t session_id, size_t &address) override; | Status AssignVarMem(const std::string &var_name, uint64_t size, uint64_t session_id, size_t &address) override; | ||||
| }; | }; | ||||
| class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY VarManager { | |||||
| class VarManager { | |||||
| public: | public: | ||||
| static VarManager *Instance(uint64_t session_id); | static VarManager *Instance(uint64_t session_id); | ||||
| explicit VarManager(uint64_t session_id); | explicit VarManager(uint64_t session_id); | ||||
| ~VarManager() = default; | ~VarManager() = default; | ||||
| ge::Status Init(const uint32_t &version, const uint64_t &session_id, const uint32_t &device_id, | |||||
| const uint64_t &job_id); | |||||
| Status Init(uint32_t version, uint64_t session_id, uint32_t device_id, uint64_t job_id); | |||||
| void Destory(); | |||||
| void SetMemManager(MemoryManager *mem_manager); | |||||
| ge::Status AssignVarMem(const std::string &var_name, const ge::GeTensorDesc &tensor_desc, rtMemType_t memory_type); | |||||
| void Destory(); | |||||
| ge::Status SetVarAddr(const std::string &var_name, const ge::GeTensorDesc &tensor_desc, uint8_t *dev_ptr, | |||||
| rtMemType_t memory_type); | |||||
| Status AssignVarMem(const std::string &var_name, const GeTensorDesc &tensor_desc, rtMemType_t memory_type); | |||||
| ge::Status SaveVarAddr(const std::string &var_name, const ge::GeTensorDesc &tensor_desc, uint8_t *address, | |||||
| rtMemType_t memory_type); | |||||
| Status SetVarAddr(const std::string &var_name, const GeTensorDesc &tensor_desc, uint8_t *dev_ptr, | |||||
| rtMemType_t memory_type); | |||||
| ge::Status GetVarAddr(const std::string &var_name, const ge::GeTensorDesc &tensor_desc, uint8_t **dev_ptr, | |||||
| rtMemType_t &memory_type); | |||||
| Status GetVarAddr(const std::string &var_name, const GeTensorDesc &tensor_desc, uint8_t **dev_ptr, | |||||
| rtMemType_t &memory_type); | |||||
| ge::Status GetVarAddr(const std::string &var_name, const ge::GeTensorDesc &tensor_desc, uint8_t **dev_ptr); | |||||
| Status GetVarAddr(const std::string &var_name, const GeTensorDesc &tensor_desc, uint8_t **dev_ptr); | |||||
| ge::Status SaveBroadCastInfo(uint32_t graph_id, const VarBroadCastInfo &broad_cast_info); | |||||
| Status SaveBroadCastInfo(uint32_t graph_id, const VarBroadCastInfo &broad_cast_info); | |||||
| ge::Status GetCurVarDesc(const std::string &var_name, ge::GeTensorDesc &tensor_desc); | |||||
| Status GetCurVarDesc(const std::string &var_name, GeTensorDesc &tensor_desc); | |||||
| ge::Status RenewCurVarDesc(const std::string &var_name, ge::OpDescPtr op_desc); | |||||
| Status RenewCurVarDesc(const std::string &var_name, OpDescPtr op_desc); | |||||
| ge::Status MallocVarMemory(size_t memory_size = kMemoryVarManagerMallocSize); | |||||
| Status MallocVarMemory(size_t memory_size = kMemoryVarManagerMallocSize); | |||||
| ge::Status FreeVarMemory(); | |||||
| Status FreeVarMemory(); | |||||
| Status SetTransRoad(const std::string &var_name, const VarTransRoad &trans_road); | Status SetTransRoad(const std::string &var_name, const VarTransRoad &trans_road); | ||||
| @@ -243,7 +242,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY VarManager { | |||||
| Status GetChangedGraphId(const std::string &var_name, uint32_t &graph_id); | Status GetChangedGraphId(const std::string &var_name, uint32_t &graph_id); | ||||
| Status SetMemoryMallocSize(const std::map<string, string> &options); | |||||
| Status SetMemoryMallocSize(const std::map<string, string> &options, size_t total_mem_size); | |||||
| const size_t &GetGraphMemoryMaxSize() const { return graph_mem_max_size_; } | const size_t &GetGraphMemoryMaxSize() const { return graph_mem_max_size_; } | ||||
| @@ -281,6 +280,8 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY VarManager { | |||||
| uint8_t *GetVarMemoryAddr(uint8_t *logic_addr, rtMemType_t memory_type); | uint8_t *GetVarMemoryAddr(uint8_t *logic_addr, rtMemType_t memory_type); | ||||
| uint8_t *GetPoolMemory(rtMemType_t memory_type, size_t mem_size); | |||||
| Status GetAllVariables(std::map<std::string, GeTensorDesc> &all_variables); | Status GetAllVariables(std::map<std::string, GeTensorDesc> &all_variables); | ||||
| private: | private: | ||||
| @@ -295,6 +296,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY VarManager { | |||||
| std::unique_ptr<ge::VarResource> var_resource_; | std::unique_ptr<ge::VarResource> var_resource_; | ||||
| map<rtMemType_t, MemResource *> mem_resource_map_; | map<rtMemType_t, MemResource *> mem_resource_map_; | ||||
| mutable std::recursive_mutex mutex_; | mutable std::recursive_mutex mutex_; | ||||
| MemoryManager *mem_manager_{nullptr}; | |||||
| Status ParseMemoryMallocSize(std::string &memory_size, size_t &my_size); | Status ParseMemoryMallocSize(std::string &memory_size, size_t &my_size); | ||||
| Status GetTotalMemorySize(size_t &total_mem_size); | Status GetTotalMemorySize(size_t &total_mem_size); | ||||
| @@ -20,6 +20,8 @@ | |||||
| #include <string> | #include <string> | ||||
| #include <vector> | #include <vector> | ||||
| #include "graph/utils/node_utils.h" | #include "graph/utils/node_utils.h" | ||||
| #include "inc/kernel.h" | |||||
| #include "inc/kernel_factory.h" | |||||
| namespace ge { | namespace ge { | ||||
| namespace { | namespace { | ||||
| @@ -26,8 +26,6 @@ | |||||
| #include "graph/utils/attr_utils.h" | #include "graph/utils/attr_utils.h" | ||||
| #include "graph/utils/graph_utils.h" | #include "graph/utils/graph_utils.h" | ||||
| #include "graph/utils/op_desc_utils.h" | #include "graph/utils/op_desc_utils.h" | ||||
| #include "inc/kernel.h" | |||||
| #include "inc/kernel_factory.h" | |||||
| #include "graph/passes/pass_utils.h" | #include "graph/passes/pass_utils.h" | ||||
| namespace ge { | namespace ge { | ||||
| @@ -1,115 +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 "hybrid/hybrid_davinci_model.h" | |||||
| namespace ge { | |||||
| namespace hybrid { | |||||
| HybridDavinciModel::~HybridDavinciModel() {} | |||||
| std::unique_ptr<HybridDavinciModel> HybridDavinciModel::Create(const GeRootModelPtr &ge_root_model) { | |||||
| return std::unique_ptr<HybridDavinciModel>(new (std::nothrow)HybridDavinciModel()); | |||||
| } | |||||
| Status HybridDavinciModel::Init() { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| Status HybridDavinciModel::Execute(const std::vector<DataBuffer> &inputs, | |||||
| const std::vector<GeTensorDesc> &input_desc, | |||||
| std::vector<DataBuffer> &outputs, | |||||
| std::vector<GeTensorDesc> &output_desc, | |||||
| rtStream_t stream) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| Status HybridDavinciModel::Execute(const vector<GeTensor> &inputs, vector<GeTensor> &outputs) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| Status HybridDavinciModel::ModelRunStart() { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| Status HybridDavinciModel::ModelRunStop() { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| Status HybridDavinciModel::EnqueueData(const shared_ptr<InputDataWrapper> &data) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| void HybridDavinciModel::SetListener(const shared_ptr<ModelListener> &listener) { | |||||
| } | |||||
| void HybridDavinciModel::SetModelId(uint32_t model_id) { | |||||
| } | |||||
| void HybridDavinciModel::SetDeviceId(uint32_t device_id) { | |||||
| } | |||||
| void HybridDavinciModel::SetOmName(const string &om_name) { | |||||
| } | |||||
| uint64_t HybridDavinciModel::GetSessionId() { | |||||
| return 0; | |||||
| } | |||||
| uint32_t HybridDavinciModel::GetDataInputerSize() { | |||||
| return 0; | |||||
| } | |||||
| uint32_t HybridDavinciModel::GetDeviceId() const { | |||||
| return 0; | |||||
| } | |||||
| Status HybridDavinciModel::GetDynamicBatchInfo(std::vector<std::vector<int64_t>> &batch_info, int32_t &dynamic_type) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| void HybridDavinciModel::GetUserDesignateShapeOrder(std::vector<std::string> &user_input_shape_order) { | |||||
| } | |||||
| void HybridDavinciModel::GetModelAttr(std::vector<std::string> &dynamic_output_shape_info) { | |||||
| } | |||||
| Status HybridDavinciModel::GetInputOutputDescInfo(vector<InputOutputDescInfo> &input_desc, | |||||
| vector<InputOutputDescInfo> &output_desc, | |||||
| std::vector<uint32_t> &input_formats, | |||||
| std::vector<uint32_t> &output_formats) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| void HybridDavinciModel::SetModelDescVersion(bool is_new_model_desc) { | |||||
| } | |||||
| bool HybridDavinciModel::GetRunningFlag() const { | |||||
| return false; | |||||
| } | |||||
| Status HybridDavinciModel::SetRunAsyncListenerCallback(const RunAsyncCallback &callback) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| bool HybridDavinciModel::GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const { | |||||
| return true; | |||||
| } | |||||
| Status HybridDavinciModel::GetOpAttr(const std::string &op_name, const std::string &attr_name, | |||||
| std::string &attr_value) const { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| } // namespace hybrid | |||||
| } // namespace ge | |||||
| @@ -1537,6 +1537,7 @@ Status HybridModelBuilder::InitRuntimeParams() { | |||||
| var_manager_ = VarManager::Instance(runtime_param_.session_id); | var_manager_ = VarManager::Instance(runtime_param_.session_id); | ||||
| GE_CHECK_NOTNULL(var_manager_); | GE_CHECK_NOTNULL(var_manager_); | ||||
| var_manager_->SetMemManager(&MemManager::Instance()); | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| @@ -25,7 +25,6 @@ | |||||
| #include "common/ge/ge_util.h" | #include "common/ge/ge_util.h" | ||||
| #include "common/ge/plugin_manager.h" | #include "common/ge/plugin_manager.h" | ||||
| #include "common/profiling/profiling_manager.h" | |||||
| #include "common/properties_manager.h" | #include "common/properties_manager.h" | ||||
| #include "framework/common/debug/ge_log.h" | #include "framework/common/debug/ge_log.h" | ||||
| #include "framework/common/debug/log.h" | #include "framework/common/debug/log.h" | ||||
| @@ -37,8 +36,6 @@ | |||||
| #include "common/ge_call_wrapper.h" | #include "common/ge_call_wrapper.h" | ||||
| #include "graph/ge_context.h" | #include "graph/ge_context.h" | ||||
| #include "graph/ge_global_options.h" | #include "graph/ge_global_options.h" | ||||
| #include "graph/manager/graph_mem_manager.h" | |||||
| #include "graph/manager/host_mem_manager.h" | |||||
| #include "graph/manager/graph_var_manager.h" | #include "graph/manager/graph_var_manager.h" | ||||
| #include "runtime/kernel.h" | #include "runtime/kernel.h" | ||||
| #include "opskernel_manager/ops_kernel_builder_manager.h" | #include "opskernel_manager/ops_kernel_builder_manager.h" | ||||
| @@ -193,8 +190,6 @@ Status GELib::SystemInitialize(const map<string, string> &options) { | |||||
| InitOptions(options); | InitOptions(options); | ||||
| // In train and infer, profiling is always needed. | |||||
| InitProfiling(this->options_); | |||||
| // 1.`is_train_mode_` means case: train | // 1.`is_train_mode_` means case: train | ||||
| // 2.`(!is_train_mode_) && (options_.device_id != kDefaultDeviceIdForInfer)` means case: online infer | // 2.`(!is_train_mode_) && (options_.device_id != kDefaultDeviceIdForInfer)` means case: online infer | ||||
| // these two case with logical device id | // these two case with logical device id | ||||
| @@ -206,16 +201,6 @@ Status GELib::SystemInitialize(const map<string, string> &options) { | |||||
| return status; | return status; | ||||
| } | } | ||||
| void GELib::InitProfiling(Options &options) { | |||||
| GELOGI("Init Profiling. session Id: %ld, device id:%d ", options.session_id, options.device_id); | |||||
| std::lock_guard<std::mutex> lock(status_mutex_); | |||||
| GetContext().Init(); | |||||
| // Profiling init | |||||
| if (ProfilingManager::Instance().Init(options) != SUCCESS) { | |||||
| GELOGW("Profiling init failed."); | |||||
| } | |||||
| } | |||||
| void GELib::SetDefaultPrecisionMode(map<string, string> &new_options) { | void GELib::SetDefaultPrecisionMode(map<string, string> &new_options) { | ||||
| auto iter = new_options.find(PRECISION_MODE); | auto iter = new_options.find(PRECISION_MODE); | ||||
| if (iter != new_options.end()) { | if (iter != new_options.end()) { | ||||
| @@ -342,18 +327,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status GELib::InitSystemWithOpt | |||||
| GELOGW("System init with options is already inited and not shutdown."); | GELOGW("System init with options is already inited and not shutdown."); | ||||
| return SUCCESS); | return SUCCESS); | ||||
| std::vector<rtMemType_t> mem_type; | |||||
| mem_type.push_back(RT_MEMORY_HBM); | |||||
| mem_type.push_back(RT_MEMORY_P2P_DDR); | |||||
| Status initMmStatus = MemManager::Instance().Initialize(mem_type); | |||||
| if (initMmStatus != SUCCESS) { | |||||
| GELOGE(initMmStatus, "[Init][MemManager] MemoryAllocatorManager initialize failed."); | |||||
| REPORT_CALL_ERROR("E19999", "MemManager initialize failed."); | |||||
| return initMmStatus; | |||||
| } | |||||
| GE_CHK_STATUS_RET(HostMemManager::Instance().Initialize()); | |||||
| // set device id | // set device id | ||||
| GELOGI("set logical device id:%u", options.device_id); | GELOGI("set logical device id:%u", options.device_id); | ||||
| GetContext().SetCtxDeviceId(static_cast<uint32_t>(options.device_id)); | GetContext().SetCtxDeviceId(static_cast<uint32_t>(options.device_id)); | ||||
| @@ -390,17 +363,6 @@ Status GELib::SystemShutdownWithOptions(const Options &options) { | |||||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status GELib::InitSystemWithoutOptions() { | FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status GELib::InitSystemWithoutOptions() { | ||||
| GELOGI("Inference Init GELib begin."); | GELOGI("Inference Init GELib begin."); | ||||
| std::vector<rtMemType_t> mem_type; | |||||
| mem_type.push_back(RT_MEMORY_HBM); | |||||
| mem_type.push_back(RT_MEMORY_P2P_DDR); | |||||
| Status initMmStatus = MemManager::Instance().Initialize(mem_type); | |||||
| if (initMmStatus != SUCCESS) { | |||||
| GELOGE(initMmStatus, "[Init][MemoryManager] initialize failed."); | |||||
| REPORT_CALL_ERROR("E19999", "MemManager initialize failed."); | |||||
| return initMmStatus; | |||||
| } | |||||
| GE_CHK_STATUS_RET(HostMemManager::Instance().Initialize()); | |||||
| static bool is_inited = false; | static bool is_inited = false; | ||||
| if (is_inited) { | if (is_inited) { | ||||
| GELOGW("System init without options is already inited, don't need to init again."); | GELOGW("System init without options is already inited, don't need to init again."); | ||||
| @@ -451,21 +413,12 @@ Status GELib::Finalize() { | |||||
| GELOGI("VarManagerPool finalization."); | GELOGI("VarManagerPool finalization."); | ||||
| VarManagerPool::Instance().Destory(); | VarManagerPool::Instance().Destory(); | ||||
| GELOGI("MemManager finalization."); | |||||
| MemManager::Instance().Finalize(); | |||||
| GELOGI("HostMemManager finalization."); | |||||
| HostMemManager::Instance().Finalize(); | |||||
| GELOGI("HostCpuEngine finalization."); | GELOGI("HostCpuEngine finalization."); | ||||
| HostCpuEngine::GetInstance().Finalize(); | HostCpuEngine::GetInstance().Finalize(); | ||||
| GELOGI("Analyzer finalization"); | GELOGI("Analyzer finalization"); | ||||
| Analyzer::GetInstance()->Finalize(); | Analyzer::GetInstance()->Finalize(); | ||||
| // Shut down profiling | |||||
| ShutDownProfiling(); | |||||
| if (is_train_mode_ || (options_.device_id != kDefaultDeviceIdForInfer)) { | if (is_train_mode_ || (options_.device_id != kDefaultDeviceIdForInfer)) { | ||||
| GELOGI("System ShutDown."); | GELOGI("System ShutDown."); | ||||
| mid_state = SystemShutdownWithOptions(this->options_); | mid_state = SystemShutdownWithOptions(this->options_); | ||||
| @@ -494,15 +447,6 @@ Status GELib::Finalize() { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| void GELib::ShutDownProfiling() { | |||||
| std::lock_guard<std::mutex> lock(status_mutex_); | |||||
| if (ProfilingManager::Instance().ProfilingOn()) { | |||||
| ProfilingManager::Instance().StopProfiling(); | |||||
| ProfilingManager::Instance().PluginUnInit(); | |||||
| } | |||||
| } | |||||
| // Get Singleton Instance | // Get Singleton Instance | ||||
| std::shared_ptr<GELib> GELib::GetInstance() { return instancePtr_; } | std::shared_ptr<GELib> GELib::GetInstance() { return instancePtr_; } | ||||
| @@ -513,8 +457,7 @@ void GELib::RollbackInit() { | |||||
| if (opsManager_.init_flag_) { | if (opsManager_.init_flag_) { | ||||
| (void)opsManager_.Finalize(); | (void)opsManager_.Finalize(); | ||||
| } | } | ||||
| MemManager::Instance().Finalize(); | |||||
| HostMemManager::Instance().Finalize(); | |||||
| VarManagerPool::Instance().Destory(); | VarManagerPool::Instance().Destory(); | ||||
| } | } | ||||
| @@ -61,12 +61,6 @@ class GE_FUNC_VISIBILITY GELib { | |||||
| // get Initial flag | // get Initial flag | ||||
| bool InitFlag() const { return init_flag_; } | bool InitFlag() const { return init_flag_; } | ||||
| // get TrainMode flag | |||||
| bool IsTrainMode() { return is_train_mode_; } | |||||
| void InitProfiling(Options &options); | |||||
| void ShutDownProfiling(); | |||||
| Status InitSystemWithoutOptions(); | Status InitSystemWithoutOptions(); | ||||
| Status InitSystemWithOptions(Options &options); | Status InitSystemWithOptions(Options &options); | ||||
| Status SystemShutdownWithOptions(const Options &options); | Status SystemShutdownWithOptions(const Options &options); | ||||
| @@ -474,8 +474,8 @@ graphStatus Impl::CheckBuildModeAndBuildStep() { | |||||
| } | } | ||||
| } else { | } else { | ||||
| if (build_mode == BUILD_MODE_TUNING) { | if (build_mode == BUILD_MODE_TUNING) { | ||||
| REPORT_INPUT_ERROR("E10001", std::vector<std::string>({"parameter", "value", "reason"}), | |||||
| std::vector<std::string>({BUILD_MODE, it->second, "tuning must specify build step. Please check!"})); | |||||
| //REPORT_INPUT_ERROR("E10001", std::vector<std::string>({"parameter", "value", "reason"}), | |||||
| // std::vector<std::string>({BUILD_MODE, it->second, "tuning must specify build step. Please check!"})); | |||||
| GELOGE(GRAPH_PARAM_INVALID, "[Check][BuildMode] tuning must specify build step. Please check!"); | GELOGE(GRAPH_PARAM_INVALID, "[Check][BuildMode] tuning must specify build step. Please check!"); | ||||
| return GRAPH_PARAM_INVALID; | return GRAPH_PARAM_INVALID; | ||||
| } | } | ||||
| @@ -2,7 +2,6 @@ set(SRC_LIST | |||||
| "main.cc" | "main.cc" | ||||
| "single_op_parser.cc" | "single_op_parser.cc" | ||||
| "../session/omg.cc" | "../session/omg.cc" | ||||
| "../ir_build/option_utils.cc" | |||||
| ) | ) | ||||
| ############ atc_atc.bin ############ | ############ atc_atc.bin ############ | ||||
| @@ -127,6 +126,8 @@ target_link_libraries(fwk_atc.bin PRIVATE | |||||
| graph | graph | ||||
| error_manager | error_manager | ||||
| ge_runner | ge_runner | ||||
| ge_compiler | |||||
| ge_executor_shared | |||||
| parser_common | parser_common | ||||
| gflags | gflags | ||||
| json | json | ||||
| @@ -31,11 +31,9 @@ | |||||
| #include "graph/ge_local_context.h" | #include "graph/ge_local_context.h" | ||||
| #include "common/local_context.h" | #include "common/local_context.h" | ||||
| #include "graph/manager/graph_var_manager.h" | #include "graph/manager/graph_var_manager.h" | ||||
| #include "graph/manager/graph_mem_manager.h" | |||||
| #include "graph/utils/tensor_adapter.h" | #include "graph/utils/tensor_adapter.h" | ||||
| #include "runtime/mem.h" | #include "runtime/mem.h" | ||||
| #include "ir_build/option_utils.h" | #include "ir_build/option_utils.h" | ||||
| #include "common/profiling/profiling_manager.h" | |||||
| namespace ge { | namespace ge { | ||||
| namespace { | namespace { | ||||
| @@ -49,9 +47,9 @@ Status CheckReuseMemoryOption(const std::map<string, string> &options) { | |||||
| } else if (iter->second == "1") { | } else if (iter->second == "1") { | ||||
| GELOGD("%s=1, reuse memory is close", OPTION_EXEC_DISABLE_REUSED_MEMORY); | GELOGD("%s=1, reuse memory is close", OPTION_EXEC_DISABLE_REUSED_MEMORY); | ||||
| } else { | } else { | ||||
| GELOGE(PARAM_INVALID, "[CheckReuse][MemoryOption]option %s=%s is invalid", | |||||
| GELOGE(PARAM_INVALID, "[CheckReuse][MemoryOption]option %s=%s is invalid", | |||||
| OPTION_EXEC_DISABLE_REUSED_MEMORY, iter->second.c_str()); | OPTION_EXEC_DISABLE_REUSED_MEMORY, iter->second.c_str()); | ||||
| REPORT_INNER_ERROR("E19999", "CheckReuseMemoryOption failed because option %s=%s is invalid.", | |||||
| REPORT_INNER_ERROR("E19999", "CheckReuseMemoryOption failed because option %s=%s is invalid.", | |||||
| OPTION_EXEC_DISABLE_REUSED_MEMORY, iter->second.c_str()); | OPTION_EXEC_DISABLE_REUSED_MEMORY, iter->second.c_str()); | ||||
| return FAILED; | return FAILED; | ||||
| } | } | ||||
| @@ -132,16 +130,6 @@ Status InnerSession::Initialize() { | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| ret = VarManager::Instance(session_id_)->SetMemoryMallocSize(all_options); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(ret, "[Set][MemoryMallocSize] failed."); | |||||
| REPORT_CALL_ERROR("E19999", "VarManager SetMemoryMallocSize failed, InnerSession:%lu.", session_id_); | |||||
| (void)InnerFinalize(); | |||||
| GE_CHK_STATUS(RemoveDumpProperties(), "[Remove][DumpProperties] failed."); | |||||
| GE_CHK_RT(rtDeviceReset(static_cast<int32_t>(GetContext().DeviceId()))); | |||||
| return ret; | |||||
| } | |||||
| int32_t version = static_cast<int32_t>(SessionVersion::ClOUD_VERSION); | int32_t version = static_cast<int32_t>(SessionVersion::ClOUD_VERSION); | ||||
| const int DEFAULT_DEVICE_ID = 0; | const int DEFAULT_DEVICE_ID = 0; | ||||
| const int DEFAULT_JOB_ID = 0; | const int DEFAULT_JOB_ID = 0; | ||||
| @@ -170,13 +158,6 @@ Status InnerSession::Finalize() { | |||||
| } | } | ||||
| init_flag_ = false; | init_flag_ = false; | ||||
| // release var memory | |||||
| GELOGI("VarManager free var memory."); | |||||
| (void)VarManager::Instance(session_id_)->FreeVarMemory(); | |||||
| for (auto memory_type : MemManager::Instance().GetAllMemoryType()) { | |||||
| (void)MemManager::Instance().SessionScopeMemInstance(memory_type).Free(session_id_); | |||||
| } | |||||
| // release analyzer saved info(Session Level) | // release analyzer saved info(Session Level) | ||||
| Analyzer::GetInstance()->DestroySessionJsonObject(session_id_); | Analyzer::GetInstance()->DestroySessionJsonObject(session_id_); | ||||
| @@ -232,9 +213,6 @@ Status InnerSession::GetVariable(const std::string &name, Tensor &val) { | |||||
| Status InnerSession::AddGraph(uint32_t graph_id, const Graph &graph) { | Status InnerSession::AddGraph(uint32_t graph_id, const Graph &graph) { | ||||
| std::map<std::string, std::string> options; | std::map<std::string, std::string> options; | ||||
| auto device_id = GetContext().DeviceId(); | |||||
| GELOGD("Device id is %u", device_id); | |||||
| ProfilingManager::Instance().SetGraphIdToDeviceMap(graph_id, device_id); | |||||
| return AddGraph(graph_id, graph, options); | return AddGraph(graph_id, graph, options); | ||||
| } | } | ||||
| @@ -266,8 +244,8 @@ Status InnerSession::AddGraphWithCopy(uint32_t graph_id, const Graph &graph, | |||||
| if (!init_flag_) { | if (!init_flag_) { | ||||
| GELOGE(GE_SESS_INIT_FAILED, "[Add][Graph] failed because GraphManager not init, InnerSession:%lu, graph_id:%u.", | GELOGE(GE_SESS_INIT_FAILED, "[Add][Graph] failed because GraphManager not init, InnerSession:%lu, graph_id:%u.", | ||||
| session_id_, graph_id); | session_id_, graph_id); | ||||
| REPORT_INNER_ERROR("E19999", | |||||
| "AddGraphWithCopy failed because GraphManager not init, InnerSession:%lu, graph_id:%u.", | |||||
| REPORT_INNER_ERROR("E19999", | |||||
| "AddGraphWithCopy failed because GraphManager not init, InnerSession:%lu, graph_id:%u.", | |||||
| session_id_, graph_id); | session_id_, graph_id); | ||||
| return GE_SESS_INIT_FAILED; | return GE_SESS_INIT_FAILED; | ||||
| } | } | ||||
| @@ -275,7 +253,7 @@ Status InnerSession::AddGraphWithCopy(uint32_t graph_id, const Graph &graph, | |||||
| Status ret = graph_manager_.AddGraphWithCopy(graph_id, graph, options, domi::GetContext()); | Status ret = graph_manager_.AddGraphWithCopy(graph_id, graph, options, domi::GetContext()); | ||||
| if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
| GELOGE(ret, "[Add][Graph] failed, InnerSession:%lu graphid: %u.", session_id_, graph_id); | GELOGE(ret, "[Add][Graph] failed, InnerSession:%lu graphid: %u.", session_id_, graph_id); | ||||
| REPORT_CALL_ERROR("E19999", | |||||
| REPORT_CALL_ERROR("E19999", | |||||
| "GraphManager AddGraphWithCopy failed, InnerSession:%lu graphid: %u.", session_id_, graph_id); | "GraphManager AddGraphWithCopy failed, InnerSession:%lu graphid: %u.", session_id_, graph_id); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -306,7 +284,7 @@ Status InnerSession::RunGraph(uint32_t graph_id, const std::vector<Tensor> &inpu | |||||
| domi::GetContext().user_out_nodes.clear(); | domi::GetContext().user_out_nodes.clear(); | ||||
| if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
| GELOGE(ret, "[Run][Graph]failed, InnerSession:%lu graph_id=%u.", session_id_, graph_id); | GELOGE(ret, "[Run][Graph]failed, InnerSession:%lu graph_id=%u.", session_id_, graph_id); | ||||
| REPORT_CALL_ERROR("E19999", | |||||
| REPORT_CALL_ERROR("E19999", | |||||
| "GraphManager RunGraph failed, InnerSession:%lu graph_id=%u.", session_id_, graph_id); | "GraphManager RunGraph failed, InnerSession:%lu graph_id=%u.", session_id_, graph_id); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -546,7 +524,7 @@ Status InnerSession::SaveVariables(const Graph &graph, const std::vector<std::st | |||||
| Status InnerSession::AddDumpProperties(const DumpProperties &dump_properties) { | Status InnerSession::AddDumpProperties(const DumpProperties &dump_properties) { | ||||
| if (!is_dump_server_inited_) { | if (!is_dump_server_inited_) { | ||||
| if (dump_properties.IsDumpOpen() || dump_properties.IsOpDebugOpen()) { | if (dump_properties.IsDumpOpen() || dump_properties.IsOpDebugOpen()) { | ||||
| GE_IF_BOOL_EXEC(AdxDataDumpServerInit() != kDumpStatus, | |||||
| GE_IF_BOOL_EXEC(AdxDataDumpServerInit() != kDumpStatus, | |||||
| GELOGE(PARAM_INVALID, "[Init][AdxDataDumpServer] failed, session_id:%lu.", session_id_); | GELOGE(PARAM_INVALID, "[Init][AdxDataDumpServer] failed, session_id:%lu.", session_id_); | ||||
| return PARAM_INVALID) | return PARAM_INVALID) | ||||
| GELOGI("Init adx data dump server success"); | GELOGI("Init adx data dump server success"); | ||||
| @@ -50,9 +50,26 @@ class GE_FUNC_VISIBILITY GeExecutor { | |||||
| public: | public: | ||||
| GeExecutor(); | GeExecutor(); | ||||
| ~GeExecutor() = default; | ~GeExecutor() = default; | ||||
| ge::Status Initialize(); | ge::Status Initialize(); | ||||
| ge::Status Finalize(); | ge::Status Finalize(); | ||||
| /// | |||||
| /// @ingroup ge | |||||
| /// @brief Initialize global execute environment. | |||||
| /// @param [in] options: environment variables. | |||||
| /// @return init result | |||||
| /// | |||||
| static Status Initialize(const std::map<std::string, std::string> &options); | |||||
| /// | |||||
| /// @ingroup ge | |||||
| /// @brief Finalize global execute environment. | |||||
| /// @param [in] model_id: model id allocate from manager | |||||
| /// @return execute result | |||||
| /// | |||||
| static Status FinalizeEx(); | |||||
| ge::Status UnloadModel(uint32_t modelId); | ge::Status UnloadModel(uint32_t modelId); | ||||
| // Get input and output descriptor | // Get input and output descriptor | ||||
| @@ -73,8 +73,7 @@ struct OMGBufferData { | |||||
| }; | }; | ||||
| struct OmgContext { | struct OmgContext { | ||||
| OmgContext() { format = DOMI_TENSOR_ND; } | |||||
| domiTensorFormat_t format; | |||||
| domiTensorFormat_t format = DOMI_TENSOR_ND; | |||||
| // format of the input specified by the command line | // format of the input specified by the command line | ||||
| std::unordered_map<std::string, domiTensorFormat_t> input_nodes_format_map; | std::unordered_map<std::string, domiTensorFormat_t> input_nodes_format_map; | ||||
| @@ -110,6 +109,11 @@ struct OmgContext { | |||||
| RunMode run_mode = ONLY_PRE_CHECK; | RunMode run_mode = ONLY_PRE_CHECK; | ||||
| bool train_flag = false; | bool train_flag = false; | ||||
| std::string forward_point; | |||||
| std::string backward_point; | |||||
| bool profiling_on = false; | |||||
| bool profiling_trace_on = false; | |||||
| std::string output_type; | std::string output_type; | ||||
| // Whether to use dynamic batch size or dynamic image size | // Whether to use dynamic batch size or dynamic image size | ||||
| @@ -249,12 +249,7 @@ set(GRAPH_DAVINCI_MODEL_SRC_FILES | |||||
| "${GE_CODE_DIR}/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc" | "${GE_CODE_DIR}/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc" | ||||
| ) | ) | ||||
| set(GRAPH_EXECUTE_COMMON_SRC_FILES | |||||
| "${GE_CODE_DIR}/ge/hybrid/hybrid_davinci_model_stub.cc" | |||||
| ) | |||||
| set(GRAPH_BUILD_COMMON_SRC_FILES | set(GRAPH_BUILD_COMMON_SRC_FILES | ||||
| "${GE_CODE_DIR}/ge/graph/manager/graph_manager.cc" | |||||
| "${GE_CODE_DIR}/ge/client/ge_api.cc" | "${GE_CODE_DIR}/ge/client/ge_api.cc" | ||||
| "${GE_CODE_DIR}/ge/session/inner_session.cc" | "${GE_CODE_DIR}/ge/session/inner_session.cc" | ||||
| "${GE_CODE_DIR}/ge/session/session_manager.cc" | "${GE_CODE_DIR}/ge/session/session_manager.cc" | ||||
| @@ -263,6 +258,7 @@ set(GRAPH_BUILD_COMMON_SRC_FILES | |||||
| "${GE_CODE_DIR}/ge/plugin/engine/dnnengines.cc" | "${GE_CODE_DIR}/ge/plugin/engine/dnnengines.cc" | ||||
| "${GE_CODE_DIR}/ge/plugin/engine/engine_manage.cc" | "${GE_CODE_DIR}/ge/plugin/engine/engine_manage.cc" | ||||
| "${GE_CODE_DIR}/ge/graph/manager/graph_context.cc" | "${GE_CODE_DIR}/ge/graph/manager/graph_context.cc" | ||||
| "${GE_CODE_DIR}/ge/graph/manager/graph_manager.cc" | |||||
| ) | ) | ||||
| set(GRAPH_PASS_COMMON_SRC_FILES | set(GRAPH_PASS_COMMON_SRC_FILES | ||||
| @@ -530,7 +526,7 @@ set(DISTINCT_GRAPH_LOAD_TEST_FILES | |||||
| "graph/load/memcpy_addr_async_task_info_unittest.cc" | "graph/load/memcpy_addr_async_task_info_unittest.cc" | ||||
| "graph/load/memcpy_async_task_info_unittest.cc" | "graph/load/memcpy_async_task_info_unittest.cc" | ||||
| "graph/load/cpu_queue_schedule_unittest.cc" | "graph/load/cpu_queue_schedule_unittest.cc" | ||||
| "graph/ge_executor_unittest.cc" | |||||
| "executor/ge_executor_unittest.cc" | |||||
| "graph/load/model_helper_unittest.cc" | "graph/load/model_helper_unittest.cc" | ||||
| "graph/load/model_utils_unittest.cc" | "graph/load/model_utils_unittest.cc" | ||||
| ) | ) | ||||
| @@ -703,10 +699,6 @@ set(GENERATOR_TEST_FILES | |||||
| "generator/ge_generator_unittest.cc" | "generator/ge_generator_unittest.cc" | ||||
| ) | ) | ||||
| set(EXECUTOR_TEST_FILES | |||||
| "executor/ge_executor_unittest.cc" | |||||
| ) | |||||
| set(SINGLE_OP_TEST_FILES | set(SINGLE_OP_TEST_FILES | ||||
| "single_op/single_op_model_unittest.cc" | "single_op/single_op_model_unittest.cc" | ||||
| "single_op/single_op_manager_unittest.cc" | "single_op/single_op_manager_unittest.cc" | ||||
| @@ -861,25 +853,6 @@ target_link_libraries(ge_davinci_model PRIVATE | |||||
| json | json | ||||
| ) | ) | ||||
| # build graph execute common | |||||
| add_library(ge_execute_common STATIC ${GRAPH_EXECUTE_COMMON_SRC_FILES} ${PROTO_HDRS}) | |||||
| target_compile_definitions(ge_execute_common PRIVATE | |||||
| google=ascend_private | |||||
| ) | |||||
| target_compile_options(ge_execute_common PRIVATE | |||||
| -g --coverage -fprofile-arcs -ftest-coverage | |||||
| -Werror=format | |||||
| ) | |||||
| target_link_libraries(ge_execute_common PRIVATE | |||||
| $<BUILD_INTERFACE:intf_pub> | |||||
| c_sec | |||||
| json | |||||
| ascend_protobuf | |||||
| ) | |||||
| # build graph build common | # build graph build common | ||||
| add_library(ge_build_common STATIC ${GRAPH_BUILD_COMMON_SRC_FILES} ${PROTO_HDRS}) | add_library(ge_build_common STATIC ${GRAPH_BUILD_COMMON_SRC_FILES} ${PROTO_HDRS}) | ||||
| @@ -959,7 +932,7 @@ target_compile_definitions(ut_libge_multiparts_utest PRIVATE | |||||
| target_link_libraries(ut_libge_multiparts_utest | target_link_libraries(ut_libge_multiparts_utest | ||||
| $<BUILD_INTERFACE:intf_pub> | $<BUILD_INTERFACE:intf_pub> | ||||
| -Wl,--whole-archive | -Wl,--whole-archive | ||||
| ge_davinci_model ge_build_common ge_prepare_common ge_execute_common ge_pass_common ge_ut_common_format ge_ut_common | |||||
| ge_davinci_model ge_build_common ge_prepare_common ge_single_op ge_pass_common ge_ut_common_format ge_ut_common | |||||
| -Wl,--no-whole-archive | -Wl,--no-whole-archive | ||||
| gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | ||||
| ) | ) | ||||
| @@ -981,7 +954,7 @@ target_compile_options(ut_libge_others_utest PRIVATE | |||||
| target_link_libraries(ut_libge_others_utest | target_link_libraries(ut_libge_others_utest | ||||
| $<BUILD_INTERFACE:intf_pub> | $<BUILD_INTERFACE:intf_pub> | ||||
| -Wl,--whole-archive | -Wl,--whole-archive | ||||
| ge_davinci_model ge_build_common ge_prepare_common ge_pass_common ge_execute_common ge_ut_common ge_ut_common_format | |||||
| ge_davinci_model ge_build_common ge_prepare_common ge_pass_common ge_single_op ge_ut_common ge_ut_common_format | |||||
| -Wl,--no-whole-archive | -Wl,--no-whole-archive | ||||
| gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | ||||
| ) | ) | ||||
| @@ -1001,7 +974,7 @@ target_compile_options(ut_libge_kernel_utest PRIVATE | |||||
| target_link_libraries(ut_libge_kernel_utest | target_link_libraries(ut_libge_kernel_utest | ||||
| $<BUILD_INTERFACE:intf_pub> | $<BUILD_INTERFACE:intf_pub> | ||||
| -Wl,--whole-archive | -Wl,--whole-archive | ||||
| ge_davinci_model ge_build_common ge_prepare_common ge_pass_common ge_execute_common ge_ut_common ge_ut_common_format | |||||
| ge_davinci_model ge_build_common ge_prepare_common ge_pass_common ge_single_op ge_ut_common ge_ut_common_format | |||||
| -Wl,--no-whole-archive | -Wl,--no-whole-archive | ||||
| gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | ||||
| ) | ) | ||||
| @@ -1010,7 +983,6 @@ target_link_libraries(ut_libge_kernel_utest | |||||
| add_executable(ut_libge_distinct_load_utest | add_executable(ut_libge_distinct_load_utest | ||||
| ${COMMON_TEST_FILES} | ${COMMON_TEST_FILES} | ||||
| ${GENERATOR_TEST_FILES} | ${GENERATOR_TEST_FILES} | ||||
| ${EXECUTOR_TEST_FILES} | |||||
| ${DISTINCT_GRAPH_LOAD_TEST_FILES} | ${DISTINCT_GRAPH_LOAD_TEST_FILES} | ||||
| ${SINGLE_OP_TEST_FILES} | ${SINGLE_OP_TEST_FILES} | ||||
| ${PROFILING_MNG_TEST_FILES} | ${PROFILING_MNG_TEST_FILES} | ||||
| @@ -15,22 +15,103 @@ | |||||
| */ | */ | ||||
| #include <gtest/gtest.h> | #include <gtest/gtest.h> | ||||
| #include <memory> | |||||
| #include "common/ge_inner_error_codes.h" | |||||
| #include "common/types.h" | |||||
| #include "common/util.h" | |||||
| #include "runtime/mem.h" | |||||
| #include "common/util.h" | |||||
| #include "omg/omg_inner_types.h" | |||||
| #define private public | #define private public | ||||
| #define protected public | #define protected public | ||||
| #include "executor/ge_executor.h" | #include "executor/ge_executor.h" | ||||
| #include "graph/utils/tensor_utils.h" | |||||
| using namespace std; | |||||
| #include "common/auth/file_saver.h" | |||||
| #include "common/debug/log.h" | |||||
| #include "common/properties_manager.h" | |||||
| #include "common/types.h" | |||||
| #include "graph/load/graph_loader.h" | |||||
| #include "graph/load/model_manager/davinci_model.h" | |||||
| #include "hybrid/hybrid_davinci_model.h" | |||||
| #include "graph/load/model_manager/model_manager.h" | |||||
| #include "graph/load/model_manager/task_info/kernel_task_info.h" | |||||
| #include "graph/load/model_manager/task_info/kernel_ex_task_info.h" | |||||
| #include "graph/execute/graph_execute.h" | |||||
| #include "ge/common/dump/dump_properties.h" | |||||
| #include "graph/manager/graph_mem_allocator.h" | |||||
| #include "graph/utils/graph_utils.h" | |||||
| #include "proto/ge_ir.pb.h" | |||||
| #include "graph/manager/graph_var_manager.h" | |||||
| #undef private | |||||
| #undef protected | |||||
| using namespace std; | |||||
| namespace ge { | namespace ge { | ||||
| class UtestGeExecutor : public testing::Test { | class UtestGeExecutor : public testing::Test { | ||||
| protected: | protected: | ||||
| void SetUp() {} | |||||
| static void InitModelDefault(ge::Model &model) { | |||||
| ge::AttrUtils::SetInt(&model, ATTR_MODEL_MEMORY_SIZE, 0); | |||||
| ge::AttrUtils::SetInt(&model, ATTR_MODEL_WEIGHT_SIZE, 0); | |||||
| ge::AttrUtils::SetInt(&model, ATTR_MODEL_STREAM_NUM, 0); | |||||
| ge::AttrUtils::SetInt(&model, ATTR_MODEL_EVENT_NUM, 0); | |||||
| ge::AttrUtils::SetStr(&model, ATTR_MODEL_TARGET_TYPE, "MINI"); // domi::MINI | |||||
| auto compute_graph = std::make_shared<ge::ComputeGraph>("graph"); | |||||
| auto graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph); | |||||
| model.SetGraph(graph); | |||||
| } | |||||
| void TearDown() {} | |||||
| void SetUp() { | |||||
| unsetenv("FMK_SYSMODE"); | |||||
| unsetenv("FMK_DUMP_PATH"); | |||||
| unsetenv("FMK_USE_FUSION"); | |||||
| unsetenv("DAVINCI_TIMESTAT_ENABLE"); | |||||
| } | |||||
| }; | }; | ||||
| class DModelListener : public ge::ModelListener { | |||||
| public: | |||||
| DModelListener() { | |||||
| }; | |||||
| Status OnComputeDone(uint32_t model_id, uint32_t data_index, uint32_t resultCode, | |||||
| std::vector<ge::Tensor> &outputs) { | |||||
| GELOGI("In Call back. OnComputeDone"); | |||||
| return SUCCESS; | |||||
| } | |||||
| }; | |||||
| shared_ptr<ge::ModelListener> g_label_call_back(new DModelListener()); | |||||
| static ge::OpDescPtr CreateOpDesc(string name = "", string type = "") { | |||||
| auto op_desc = std::make_shared<ge::OpDesc>(name, type); | |||||
| op_desc->SetStreamId(0); | |||||
| op_desc->SetId(0); | |||||
| ge::AttrUtils::SetFloat(op_desc, ge::ATTR_NAME_ALPHA, 0); | |||||
| ge::AttrUtils::SetFloat(op_desc, ge::ATTR_NAME_BETA, 0); | |||||
| op_desc->SetWorkspace({}); | |||||
| ; | |||||
| op_desc->SetWorkspaceBytes({}); | |||||
| op_desc->SetInputOffset({}); | |||||
| op_desc->SetOutputOffset({}); | |||||
| ge::AttrUtils::SetListStr(op_desc, ge::ATTR_NAME_WEIGHT_NAME, {}); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_MODE, 0); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_PAD_MODE, 0); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_DATA_MODE, 0); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_CEIL_MODE, 0); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_NAN_OPT, 0); | |||||
| ge::AttrUtils::SetListInt(op_desc, ge::POOLING_ATTR_WINDOW, {}); | |||||
| ge::AttrUtils::SetListInt(op_desc, ge::POOLING_ATTR_PAD, {}); | |||||
| ge::AttrUtils::SetListInt(op_desc, ge::POOLING_ATTR_STRIDE, {}); | |||||
| ge::AttrUtils::SetListInt(op_desc, ge::ATTR_NAME_ACTIVE_STREAM_LIST, {1, 1}); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::ATTR_NAME_STREAM_SWITCH_COND, 0); | |||||
| return op_desc; | |||||
| } | |||||
| TEST_F(UtestGeExecutor, test_single_op_exec) { | TEST_F(UtestGeExecutor, test_single_op_exec) { | ||||
| GeExecutor exeutor; | GeExecutor exeutor; | ||||
| ModelData model_data; | ModelData model_data; | ||||
| @@ -45,4 +126,219 @@ TEST_F(UtestGeExecutor, test_ge_initialize) { | |||||
| EXPECT_EQ(executor.Initialize(), SUCCESS); | EXPECT_EQ(executor.Initialize(), SUCCESS); | ||||
| EXPECT_EQ(executor.Initialize(), SUCCESS); | EXPECT_EQ(executor.Initialize(), SUCCESS); | ||||
| } | } | ||||
| } // namespace ge | |||||
| TEST_F(UtestGeExecutor, load_data_from_file) { | |||||
| GeExecutor ge_executor; | |||||
| ge_executor.isInit_ = true; | |||||
| string test_smap = "/tmp/" + std::to_string(getpid()) + "_maps"; | |||||
| string self_smap = "/proc/" + std::to_string(getpid()) + "/maps"; | |||||
| string copy_smap = "cp -f " + self_smap + " " + test_smap; | |||||
| EXPECT_EQ(system(copy_smap.c_str()), 0); | |||||
| ModelData model_data; | |||||
| EXPECT_EQ(ge_executor.LoadDataFromFile(test_smap, model_data), SUCCESS); | |||||
| EXPECT_NE(model_data.model_data, nullptr); | |||||
| delete[] static_cast<char *>(model_data.model_data); | |||||
| model_data.model_data = nullptr; | |||||
| ge_executor.isInit_ = false; | |||||
| } | |||||
| TEST_F(UtestGeExecutor, InitFeatureMapAndP2PMem_failed) { | |||||
| DavinciModel model(0, g_label_call_back); | |||||
| model.is_feature_map_mem_has_inited_ = true; | |||||
| EXPECT_EQ(model.InitFeatureMapAndP2PMem(nullptr, 0), PARAM_INVALID); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, kernel_InitDumpArgs) { | |||||
| DavinciModel model(0, g_label_call_back); | |||||
| model.om_name_ = "testom"; | |||||
| model.name_ = "test"; | |||||
| OpDescPtr op_desc = CreateOpDesc("test", "test"); | |||||
| std::map<std::string, std::set<std::string>> model_dump_properties_map; | |||||
| std::set<std::string> s; | |||||
| model_dump_properties_map[DUMP_ALL_MODEL] = s; | |||||
| DumpProperties dp; | |||||
| dp.model_dump_properties_map_ = model_dump_properties_map; | |||||
| model.SetDumpProperties(dp); | |||||
| KernelTaskInfo kernel_task_info; | |||||
| kernel_task_info.davinci_model_ = &model; | |||||
| kernel_task_info.op_desc_ = op_desc; | |||||
| kernel_task_info.InitDumpArgs(0); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, kernel_ex_InitDumpArgs) { | |||||
| DavinciModel model(0, g_label_call_back); | |||||
| model.om_name_ = "testom"; | |||||
| model.name_ = "test"; | |||||
| OpDescPtr op_desc = CreateOpDesc("test", "test"); | |||||
| std::map<std::string, std::set<std::string>> model_dump_properties_map; | |||||
| std::set<std::string> s; | |||||
| model_dump_properties_map[DUMP_ALL_MODEL] = s; | |||||
| DumpProperties dp; | |||||
| dp.model_dump_properties_map_ = model_dump_properties_map; | |||||
| model.SetDumpProperties(dp); | |||||
| KernelExTaskInfo kernel_ex_task_info; | |||||
| kernel_ex_task_info.davinci_model_ = &model; | |||||
| kernel_ex_task_info.InitDumpArgs(nullptr, op_desc); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, kernel_ex_InitDumpFlag) { | |||||
| DavinciModel model(0, g_label_call_back); | |||||
| model.om_name_ = "testom"; | |||||
| model.name_ = "test"; | |||||
| OpDescPtr op_desc = CreateOpDesc("test", "test"); | |||||
| std::map<std::string, std::set<std::string>> model_dump_properties_map; | |||||
| std::set<std::string> s; | |||||
| model_dump_properties_map[DUMP_ALL_MODEL] = s; | |||||
| DumpProperties dp; | |||||
| dp.model_dump_properties_map_ = model_dump_properties_map; | |||||
| model.SetDumpProperties(dp); | |||||
| KernelExTaskInfo kernel_ex_task_info; | |||||
| kernel_ex_task_info.davinci_model_ = &model; | |||||
| kernel_ex_task_info.InitDumpFlag(op_desc); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, execute_graph_with_stream) { | |||||
| VarManager::Instance(0)->Init(0, 0, 0, 0); | |||||
| map<string, string> options; | |||||
| options[GRAPH_MEMORY_MAX_SIZE] = "1048576"; | |||||
| VarManager::Instance(0)->SetMemoryMallocSize(options, 1024UL * 1024UL * 1024UL); | |||||
| DavinciModel model(0, nullptr); | |||||
| ComputeGraphPtr graph = make_shared<ComputeGraph>("default"); | |||||
| GeModelPtr ge_model = make_shared<GeModel>(); | |||||
| ge_model->SetGraph(GraphUtils::CreateGraphFromComputeGraph(graph)); | |||||
| AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 10240); | |||||
| AttrUtils::SetInt(ge_model, ATTR_MODEL_STREAM_NUM, 1); | |||||
| shared_ptr<domi::ModelTaskDef> model_task_def = make_shared<domi::ModelTaskDef>(); | |||||
| ge_model->SetModelTaskDef(model_task_def); | |||||
| GeTensorDesc tensor(GeShape(), FORMAT_NCHW, DT_FLOAT); | |||||
| TensorUtils::SetSize(tensor, 512); | |||||
| { | |||||
| OpDescPtr op_desc = CreateOpDesc("data", DATA); | |||||
| op_desc->AddInputDesc(tensor); | |||||
| op_desc->AddOutputDesc(tensor); | |||||
| op_desc->SetInputOffset({1024}); | |||||
| op_desc->SetOutputOffset({1024}); | |||||
| NodePtr node = graph->AddNode(op_desc); // op_index = 0 | |||||
| } | |||||
| { | |||||
| OpDescPtr op_desc = CreateOpDesc("square", "Square"); | |||||
| op_desc->AddInputDesc(tensor); | |||||
| op_desc->AddOutputDesc(tensor); | |||||
| op_desc->SetInputOffset({1024}); | |||||
| op_desc->SetOutputOffset({1024}); | |||||
| NodePtr node = graph->AddNode(op_desc); // op_index = 1 | |||||
| domi::TaskDef *task_def = model_task_def->add_task(); | |||||
| task_def->set_stream_id(0); | |||||
| task_def->set_type(RT_MODEL_TASK_KERNEL); | |||||
| domi::KernelDef *kernel_def = task_def->mutable_kernel(); | |||||
| kernel_def->set_stub_func("stub_func"); | |||||
| kernel_def->set_args_size(64); | |||||
| string args(64, '1'); | |||||
| kernel_def->set_args(args.data(), 64); | |||||
| domi::KernelContext *context = kernel_def->mutable_context(); | |||||
| context->set_op_index(op_desc->GetId()); | |||||
| context->set_kernel_type(2); // ccKernelType::TE | |||||
| uint16_t args_offset[9] = {0}; | |||||
| context->set_args_offset(args_offset, 9 * sizeof(uint16_t)); | |||||
| } | |||||
| { | |||||
| OpDescPtr op_desc = CreateOpDesc("memcpy", MEMCPYASYNC); | |||||
| op_desc->AddInputDesc(tensor); | |||||
| op_desc->AddOutputDesc(tensor); | |||||
| op_desc->SetInputOffset({1024}); | |||||
| op_desc->SetOutputOffset({5120}); | |||||
| NodePtr node = graph->AddNode(op_desc); // op_index = 2 | |||||
| domi::TaskDef *task_def = model_task_def->add_task(); | |||||
| task_def->set_stream_id(0); | |||||
| task_def->set_type(RT_MODEL_TASK_MEMCPY_ASYNC); | |||||
| domi::MemcpyAsyncDef *memcpy_async = task_def->mutable_memcpy_async(); | |||||
| memcpy_async->set_src(1024); | |||||
| memcpy_async->set_dst(5120); | |||||
| memcpy_async->set_dst_max(512); | |||||
| memcpy_async->set_count(1); | |||||
| memcpy_async->set_kind(RT_MEMCPY_DEVICE_TO_DEVICE); | |||||
| memcpy_async->set_op_index(op_desc->GetId()); | |||||
| } | |||||
| { | |||||
| OpDescPtr op_desc = CreateOpDesc("output", NETOUTPUT); | |||||
| op_desc->AddInputDesc(tensor); | |||||
| op_desc->SetInputOffset({5120}); | |||||
| op_desc->SetSrcName( { "memcpy" } ); | |||||
| op_desc->SetSrcIndex( { 0 } ); | |||||
| NodePtr node = graph->AddNode(op_desc); // op_index = 3 | |||||
| } | |||||
| EXPECT_EQ(model.Assign(ge_model), SUCCESS); | |||||
| EXPECT_EQ(model.Init(), SUCCESS); | |||||
| EXPECT_EQ(model.input_addrs_list_.size(), 1); | |||||
| EXPECT_EQ(model.output_addrs_list_.size(), 1); | |||||
| EXPECT_EQ(model.task_list_.size(), 2); | |||||
| OutputData output_data; | |||||
| vector<Tensor> outputs; | |||||
| EXPECT_EQ(model.GenOutputTensorInfo(&output_data, outputs), SUCCESS); | |||||
| GraphExecutor graph_executer; | |||||
| graph_executer.init_flag_ = true; | |||||
| GeRootModelPtr ge_root_model = make_shared<GeRootModel>(graph); | |||||
| std::vector<GeTensor> input_tensor; | |||||
| std::vector<GeTensor> output_tensor; | |||||
| std::vector<InputOutputDescInfo> output_desc; | |||||
| InputOutputDescInfo desc0; | |||||
| output_desc.push_back(desc0); | |||||
| graph_executer.ExecuteGraphWithStream(0, nullptr, ge_root_model, input_tensor, output_tensor); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, get_op_attr) { | |||||
| shared_ptr<DavinciModel> model = MakeShared<DavinciModel>(1, g_label_call_back); | |||||
| model->SetId(1); | |||||
| model->om_name_ = "testom"; | |||||
| model->name_ = "test"; | |||||
| shared_ptr<hybrid::HybridDavinciModel> hybrid_model = MakeShared<hybrid::HybridDavinciModel>(); | |||||
| model->SetId(2); | |||||
| model->om_name_ = "testom_hybrid"; | |||||
| model->name_ = "test_hybrid"; | |||||
| std::shared_ptr<ModelManager> model_manager = ModelManager::GetInstance(); | |||||
| model_manager->InsertModel(1, model); | |||||
| model_manager->InsertModel(2, hybrid_model); | |||||
| OpDescPtr op_desc = CreateOpDesc("test", "test"); | |||||
| std::vector<std::string> value{"test"}; | |||||
| ge::AttrUtils::SetListStr(op_desc, ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, value); | |||||
| model->SaveSpecifyAttrValues(op_desc); | |||||
| GeExecutor ge_executor; | |||||
| GeExecutor::isInit_ = true; | |||||
| std::string attr_value; | |||||
| auto ret = ge_executor.GetOpAttr(1, "test", ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, attr_value); | |||||
| EXPECT_EQ(ret, SUCCESS); | |||||
| EXPECT_EQ(attr_value, "[4]test"); | |||||
| ret = ge_executor.GetOpAttr(2, "test", ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, attr_value); | |||||
| EXPECT_EQ(ret, PARAM_INVALID); | |||||
| ret = ge_executor.GetOpAttr(3, "test", ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, attr_value); | |||||
| EXPECT_EQ(ret, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID); | |||||
| } | |||||
| } | |||||
| @@ -62,6 +62,13 @@ static NodePtr CreateNode(ComputeGraph &graph, const string &name, const string | |||||
| return graph.AddNode(op_desc); | return graph.AddNode(op_desc); | ||||
| } | } | ||||
| TEST_F(UtestModelExecutorTest, test_get_total_memory_size) { | |||||
| ModelExecutor model_executor; | |||||
| size_t total_mem_size = 0; | |||||
| EXPECT_EQ(model_executor.GetTotalMemorySize(total_mem_size), SUCCESS); | |||||
| EXPECT_EQ(total_mem_size, 1024UL * 1024UL * 1024UL); | |||||
| } | |||||
| TEST_F(UtestModelExecutorTest, test_load_graph_sync) { | TEST_F(UtestModelExecutorTest, test_load_graph_sync) { | ||||
| ModelExecutor model_executor; | ModelExecutor model_executor; | ||||
| EXPECT_EQ(model_executor.Initialize({}, 0), SUCCESS); | EXPECT_EQ(model_executor.Initialize({}, 0), SUCCESS); | ||||
| @@ -1,349 +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 <gtest/gtest.h> | |||||
| #include <memory> | |||||
| #include "common/ge_inner_error_codes.h" | |||||
| #include "common/types.h" | |||||
| #include "common/util.h" | |||||
| #include "runtime/mem.h" | |||||
| #include "common/util.h" | |||||
| #include "omg/omg_inner_types.h" | |||||
| #define private public | |||||
| #define protected public | |||||
| #include "executor/ge_executor.h" | |||||
| #include "common/auth/file_saver.h" | |||||
| #include "common/debug/log.h" | |||||
| #include "common/properties_manager.h" | |||||
| #include "common/types.h" | |||||
| #include "graph/load/graph_loader.h" | |||||
| #include "graph/load/model_manager/davinci_model.h" | |||||
| #include "hybrid/hybrid_davinci_model.h" | |||||
| #include "graph/load/model_manager/model_manager.h" | |||||
| #include "graph/load/model_manager/task_info/kernel_task_info.h" | |||||
| #include "graph/load/model_manager/task_info/kernel_ex_task_info.h" | |||||
| #include "graph/execute/graph_execute.h" | |||||
| #include "ge/common/dump/dump_properties.h" | |||||
| #include "graph/manager/graph_mem_allocator.h" | |||||
| #include "graph/utils/graph_utils.h" | |||||
| #include "proto/ge_ir.pb.h" | |||||
| #include "graph/manager/graph_var_manager.h" | |||||
| #undef private | |||||
| #undef protected | |||||
| using namespace std; | |||||
| namespace ge { | |||||
| class UtestGeExecutor : public testing::Test { | |||||
| protected: | |||||
| static void InitModelDefault(ge::Model &model) { | |||||
| ge::AttrUtils::SetInt(&model, ATTR_MODEL_MEMORY_SIZE, 0); | |||||
| ge::AttrUtils::SetInt(&model, ATTR_MODEL_WEIGHT_SIZE, 0); | |||||
| ge::AttrUtils::SetInt(&model, ATTR_MODEL_STREAM_NUM, 0); | |||||
| ge::AttrUtils::SetInt(&model, ATTR_MODEL_EVENT_NUM, 0); | |||||
| ge::AttrUtils::SetStr(&model, ATTR_MODEL_TARGET_TYPE, "MINI"); // domi::MINI | |||||
| auto compute_graph = std::make_shared<ge::ComputeGraph>("graph"); | |||||
| auto graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph); | |||||
| model.SetGraph(graph); | |||||
| } | |||||
| void SetUp() { | |||||
| unsetenv("FMK_SYSMODE"); | |||||
| unsetenv("FMK_DUMP_PATH"); | |||||
| unsetenv("FMK_USE_FUSION"); | |||||
| unsetenv("DAVINCI_TIMESTAT_ENABLE"); | |||||
| } | |||||
| }; | |||||
| class DModelListener : public ge::ModelListener { | |||||
| public: | |||||
| DModelListener() { | |||||
| }; | |||||
| Status OnComputeDone(uint32_t model_id, uint32_t data_index, uint32_t resultCode, | |||||
| std::vector<ge::Tensor> &outputs) { | |||||
| GELOGI("In Call back. OnComputeDone"); | |||||
| return SUCCESS; | |||||
| } | |||||
| }; | |||||
| shared_ptr<ge::ModelListener> g_label_call_back(new DModelListener()); | |||||
| static ge::OpDescPtr CreateOpDesc(string name = "", string type = "") { | |||||
| auto op_desc = std::make_shared<ge::OpDesc>(name, type); | |||||
| op_desc->SetStreamId(0); | |||||
| op_desc->SetId(0); | |||||
| ge::AttrUtils::SetFloat(op_desc, ge::ATTR_NAME_ALPHA, 0); | |||||
| ge::AttrUtils::SetFloat(op_desc, ge::ATTR_NAME_BETA, 0); | |||||
| op_desc->SetWorkspace({}); | |||||
| ; | |||||
| op_desc->SetWorkspaceBytes({}); | |||||
| op_desc->SetInputOffset({}); | |||||
| op_desc->SetOutputOffset({}); | |||||
| ge::AttrUtils::SetListStr(op_desc, ge::ATTR_NAME_WEIGHT_NAME, {}); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_MODE, 0); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_PAD_MODE, 0); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_DATA_MODE, 0); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_CEIL_MODE, 0); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::POOLING_ATTR_NAN_OPT, 0); | |||||
| ge::AttrUtils::SetListInt(op_desc, ge::POOLING_ATTR_WINDOW, {}); | |||||
| ge::AttrUtils::SetListInt(op_desc, ge::POOLING_ATTR_PAD, {}); | |||||
| ge::AttrUtils::SetListInt(op_desc, ge::POOLING_ATTR_STRIDE, {}); | |||||
| ge::AttrUtils::SetListInt(op_desc, ge::ATTR_NAME_ACTIVE_STREAM_LIST, {1, 1}); | |||||
| ge::AttrUtils::SetInt(op_desc, ge::ATTR_NAME_STREAM_SWITCH_COND, 0); | |||||
| return op_desc; | |||||
| } | |||||
| TEST_F(UtestGeExecutor, load_data_from_file) { | |||||
| GeExecutor ge_executor; | |||||
| ge_executor.isInit_ = true; | |||||
| string test_smap = "/tmp/" + std::to_string(getpid()) + "_maps"; | |||||
| string self_smap = "/proc/" + std::to_string(getpid()) + "/maps"; | |||||
| string copy_smap = "cp -f " + self_smap + " " + test_smap; | |||||
| EXPECT_EQ(system(copy_smap.c_str()), 0); | |||||
| ModelData model_data; | |||||
| EXPECT_EQ(ge_executor.LoadDataFromFile(test_smap, model_data), SUCCESS); | |||||
| EXPECT_NE(model_data.model_data, nullptr); | |||||
| delete[] static_cast<char *>(model_data.model_data); | |||||
| model_data.model_data = nullptr; | |||||
| ge_executor.isInit_ = false; | |||||
| } | |||||
| /* | |||||
| TEST_F(UtestGeExecutor, fail_UnloadModel_model_manager_stop_unload_error) { | |||||
| uint32_t model_id = 1; | |||||
| ge::GeExecutor ge_executor; | |||||
| ge_executor.isInit_ = true; | |||||
| ge::Status ret = ge_executor.UnloadModel(model_id); | |||||
| EXPECT_EQ(ge::PARAM_INVALID, ret); | |||||
| ge_executor.isInit_ = false; | |||||
| ret = ge_executor.UnloadModel(model_id); | |||||
| EXPECT_EQ(ge::GE_EXEC_NOT_INIT, ret); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, fail_CommandHandle_model_manager_HandleCommand_error) { | |||||
| ge::Command cmd; | |||||
| ge::GeExecutor ge_executor; | |||||
| ge::Status ret = ge_executor.CommandHandle(cmd); | |||||
| EXPECT_EQ(ge::PARAM_INVALID, ret); | |||||
| } | |||||
| */ | |||||
| TEST_F(UtestGeExecutor, InitFeatureMapAndP2PMem_failed) { | |||||
| DavinciModel model(0, g_label_call_back); | |||||
| model.is_feature_map_mem_has_inited_ = true; | |||||
| EXPECT_EQ(model.InitFeatureMapAndP2PMem(nullptr, 0), PARAM_INVALID); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, kernel_InitDumpArgs) { | |||||
| DavinciModel model(0, g_label_call_back); | |||||
| model.om_name_ = "testom"; | |||||
| model.name_ = "test"; | |||||
| OpDescPtr op_desc = CreateOpDesc("test", "test"); | |||||
| std::map<std::string, std::set<std::string>> model_dump_properties_map; | |||||
| std::set<std::string> s; | |||||
| model_dump_properties_map[DUMP_ALL_MODEL] = s; | |||||
| DumpProperties dp; | |||||
| dp.model_dump_properties_map_ = model_dump_properties_map; | |||||
| model.SetDumpProperties(dp); | |||||
| KernelTaskInfo kernel_task_info; | |||||
| kernel_task_info.davinci_model_ = &model; | |||||
| kernel_task_info.op_desc_ = op_desc; | |||||
| kernel_task_info.InitDumpArgs(0); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, kernel_ex_InitDumpArgs) { | |||||
| DavinciModel model(0, g_label_call_back); | |||||
| model.om_name_ = "testom"; | |||||
| model.name_ = "test"; | |||||
| OpDescPtr op_desc = CreateOpDesc("test", "test"); | |||||
| std::map<std::string, std::set<std::string>> model_dump_properties_map; | |||||
| std::set<std::string> s; | |||||
| model_dump_properties_map[DUMP_ALL_MODEL] = s; | |||||
| DumpProperties dp; | |||||
| dp.model_dump_properties_map_ = model_dump_properties_map; | |||||
| model.SetDumpProperties(dp); | |||||
| KernelExTaskInfo kernel_ex_task_info; | |||||
| kernel_ex_task_info.davinci_model_ = &model; | |||||
| kernel_ex_task_info.InitDumpArgs(nullptr, op_desc); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, kernel_ex_InitDumpFlag) { | |||||
| DavinciModel model(0, g_label_call_back); | |||||
| model.om_name_ = "testom"; | |||||
| model.name_ = "test"; | |||||
| OpDescPtr op_desc = CreateOpDesc("test", "test"); | |||||
| std::map<std::string, std::set<std::string>> model_dump_properties_map; | |||||
| std::set<std::string> s; | |||||
| model_dump_properties_map[DUMP_ALL_MODEL] = s; | |||||
| DumpProperties dp; | |||||
| dp.model_dump_properties_map_ = model_dump_properties_map; | |||||
| model.SetDumpProperties(dp); | |||||
| KernelExTaskInfo kernel_ex_task_info; | |||||
| kernel_ex_task_info.davinci_model_ = &model; | |||||
| kernel_ex_task_info.InitDumpFlag(op_desc); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, execute_graph_with_stream) { | |||||
| VarManager::Instance(0)->Init(0, 0, 0, 0); | |||||
| map<string, string> options; | |||||
| options[GRAPH_MEMORY_MAX_SIZE] = "1048576"; | |||||
| VarManager::Instance(0)->SetMemoryMallocSize(options); | |||||
| DavinciModel model(0, nullptr); | |||||
| ComputeGraphPtr graph = make_shared<ComputeGraph>("default"); | |||||
| GeModelPtr ge_model = make_shared<GeModel>(); | |||||
| ge_model->SetGraph(GraphUtils::CreateGraphFromComputeGraph(graph)); | |||||
| AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 10240); | |||||
| AttrUtils::SetInt(ge_model, ATTR_MODEL_STREAM_NUM, 1); | |||||
| shared_ptr<domi::ModelTaskDef> model_task_def = make_shared<domi::ModelTaskDef>(); | |||||
| ge_model->SetModelTaskDef(model_task_def); | |||||
| GeTensorDesc tensor(GeShape(), FORMAT_NCHW, DT_FLOAT); | |||||
| TensorUtils::SetSize(tensor, 512); | |||||
| { | |||||
| OpDescPtr op_desc = CreateOpDesc("data", DATA); | |||||
| op_desc->AddInputDesc(tensor); | |||||
| op_desc->AddOutputDesc(tensor); | |||||
| op_desc->SetInputOffset({1024}); | |||||
| op_desc->SetOutputOffset({1024}); | |||||
| NodePtr node = graph->AddNode(op_desc); // op_index = 0 | |||||
| } | |||||
| { | |||||
| OpDescPtr op_desc = CreateOpDesc("square", "Square"); | |||||
| op_desc->AddInputDesc(tensor); | |||||
| op_desc->AddOutputDesc(tensor); | |||||
| op_desc->SetInputOffset({1024}); | |||||
| op_desc->SetOutputOffset({1024}); | |||||
| NodePtr node = graph->AddNode(op_desc); // op_index = 1 | |||||
| domi::TaskDef *task_def = model_task_def->add_task(); | |||||
| task_def->set_stream_id(0); | |||||
| task_def->set_type(RT_MODEL_TASK_KERNEL); | |||||
| domi::KernelDef *kernel_def = task_def->mutable_kernel(); | |||||
| kernel_def->set_stub_func("stub_func"); | |||||
| kernel_def->set_args_size(64); | |||||
| string args(64, '1'); | |||||
| kernel_def->set_args(args.data(), 64); | |||||
| domi::KernelContext *context = kernel_def->mutable_context(); | |||||
| context->set_op_index(op_desc->GetId()); | |||||
| context->set_kernel_type(2); // ccKernelType::TE | |||||
| uint16_t args_offset[9] = {0}; | |||||
| context->set_args_offset(args_offset, 9 * sizeof(uint16_t)); | |||||
| } | |||||
| { | |||||
| OpDescPtr op_desc = CreateOpDesc("memcpy", MEMCPYASYNC); | |||||
| op_desc->AddInputDesc(tensor); | |||||
| op_desc->AddOutputDesc(tensor); | |||||
| op_desc->SetInputOffset({1024}); | |||||
| op_desc->SetOutputOffset({5120}); | |||||
| NodePtr node = graph->AddNode(op_desc); // op_index = 2 | |||||
| domi::TaskDef *task_def = model_task_def->add_task(); | |||||
| task_def->set_stream_id(0); | |||||
| task_def->set_type(RT_MODEL_TASK_MEMCPY_ASYNC); | |||||
| domi::MemcpyAsyncDef *memcpy_async = task_def->mutable_memcpy_async(); | |||||
| memcpy_async->set_src(1024); | |||||
| memcpy_async->set_dst(5120); | |||||
| memcpy_async->set_dst_max(512); | |||||
| memcpy_async->set_count(1); | |||||
| memcpy_async->set_kind(RT_MEMCPY_DEVICE_TO_DEVICE); | |||||
| memcpy_async->set_op_index(op_desc->GetId()); | |||||
| } | |||||
| { | |||||
| OpDescPtr op_desc = CreateOpDesc("output", NETOUTPUT); | |||||
| op_desc->AddInputDesc(tensor); | |||||
| op_desc->SetInputOffset({5120}); | |||||
| op_desc->SetSrcName( { "memcpy" } ); | |||||
| op_desc->SetSrcIndex( { 0 } ); | |||||
| NodePtr node = graph->AddNode(op_desc); // op_index = 3 | |||||
| } | |||||
| EXPECT_EQ(model.Assign(ge_model), SUCCESS); | |||||
| EXPECT_EQ(model.Init(), SUCCESS); | |||||
| EXPECT_EQ(model.input_addrs_list_.size(), 1); | |||||
| EXPECT_EQ(model.output_addrs_list_.size(), 1); | |||||
| EXPECT_EQ(model.task_list_.size(), 2); | |||||
| OutputData output_data; | |||||
| vector<Tensor> outputs; | |||||
| EXPECT_EQ(model.GenOutputTensorInfo(&output_data, outputs), SUCCESS); | |||||
| GraphExecutor graph_executer; | |||||
| graph_executer.init_flag_ = true; | |||||
| GeRootModelPtr ge_root_model = make_shared<GeRootModel>(graph); | |||||
| std::vector<GeTensor> input_tensor; | |||||
| std::vector<GeTensor> output_tensor; | |||||
| std::vector<InputOutputDescInfo> output_desc; | |||||
| InputOutputDescInfo desc0; | |||||
| output_desc.push_back(desc0); | |||||
| graph_executer.ExecuteGraphWithStream(0, nullptr, ge_root_model, input_tensor, output_tensor); | |||||
| } | |||||
| TEST_F(UtestGeExecutor, get_op_attr) { | |||||
| shared_ptr<DavinciModel> model = MakeShared<DavinciModel>(1, g_label_call_back); | |||||
| model->SetId(1); | |||||
| model->om_name_ = "testom"; | |||||
| model->name_ = "test"; | |||||
| shared_ptr<hybrid::HybridDavinciModel> hybrid_model = MakeShared<hybrid::HybridDavinciModel>(); | |||||
| model->SetId(2); | |||||
| model->om_name_ = "testom_hybrid"; | |||||
| model->name_ = "test_hybrid"; | |||||
| std::shared_ptr<ModelManager> model_manager = ModelManager::GetInstance(); | |||||
| model_manager->InsertModel(1, model); | |||||
| model_manager->InsertModel(2, hybrid_model); | |||||
| OpDescPtr op_desc = CreateOpDesc("test", "test"); | |||||
| std::vector<std::string> value{"test"}; | |||||
| ge::AttrUtils::SetListStr(op_desc, ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, value); | |||||
| model->SaveSpecifyAttrValues(op_desc); | |||||
| GeExecutor ge_executor; | |||||
| GeExecutor::isInit_ = true; | |||||
| std::string attr_value; | |||||
| auto ret = ge_executor.GetOpAttr(1, "test", ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, attr_value); | |||||
| EXPECT_EQ(ret, SUCCESS); | |||||
| EXPECT_EQ(attr_value, "[4]test"); | |||||
| ret = ge_executor.GetOpAttr(2, "test", ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, attr_value); | |||||
| EXPECT_EQ(ret, PARAM_INVALID); | |||||
| ret = ge_executor.GetOpAttr(3, "test", ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, attr_value); | |||||
| EXPECT_EQ(ret, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID); | |||||
| } | |||||
| } | |||||
| @@ -52,10 +52,6 @@ int32_t MsprofReport(uint32_t moduleId, uint32_t type, void *data, uint32_t len) | |||||
| TEST_F(UtestDavinciModel, init_success) { | TEST_F(UtestDavinciModel, init_success) { | ||||
| DavinciModel model(0, nullptr); | DavinciModel model(0, nullptr); | ||||
| VarManager::Instance(0)->Init(0, 0, 0, 0); | |||||
| map<string, string> options; | |||||
| options[GRAPH_MEMORY_MAX_SIZE] = "1048576"; | |||||
| VarManager::Instance(0)->SetMemoryMallocSize(options); | |||||
| ComputeGraphPtr graph = make_shared<ComputeGraph>("default"); | ComputeGraphPtr graph = make_shared<ComputeGraph>("default"); | ||||
| ProfilingManager::Instance().is_load_profiling_ = true; | ProfilingManager::Instance().is_load_profiling_ = true; | ||||
| @@ -790,10 +786,6 @@ TEST_F(UtestDavinciModel, init_data_aipp_input_dims_normal) { | |||||
| // test label_set_task Init | // test label_set_task Init | ||||
| TEST_F(UtestDavinciModel, label_task_success) { | TEST_F(UtestDavinciModel, label_task_success) { | ||||
| VarManager::Instance(0)->Init(0, 0, 0, 0); | |||||
| map<string, string> options; | |||||
| options[GRAPH_MEMORY_MAX_SIZE] = "1048576"; | |||||
| VarManager::Instance(0)->SetMemoryMallocSize(options); | |||||
| DavinciModel model(0, nullptr); | DavinciModel model(0, nullptr); | ||||
| ComputeGraphPtr graph = make_shared<ComputeGraph>("default"); | ComputeGraphPtr graph = make_shared<ComputeGraph>("default"); | ||||
| @@ -961,11 +953,6 @@ TEST_F(UtestDavinciModel, simple_test_gmock) { | |||||
| } | } | ||||
| TEST_F(UtestDavinciModel, NnExecute) { | TEST_F(UtestDavinciModel, NnExecute) { | ||||
| VarManager::Instance(0)->Init(0, 0, 0, 0); | |||||
| map<string, string> options; | |||||
| options[GRAPH_MEMORY_MAX_SIZE] = "1048576"; | |||||
| VarManager::Instance(0)->SetMemoryMallocSize(options); | |||||
| DavinciModel model(0, nullptr); | DavinciModel model(0, nullptr); | ||||
| ComputeGraphPtr graph = make_shared<ComputeGraph>("default"); | ComputeGraphPtr graph = make_shared<ComputeGraph>("default"); | ||||
| ProfilingManager::Instance().is_load_profiling_ = true; | ProfilingManager::Instance().is_load_profiling_ = true; | ||||
| @@ -19,35 +19,31 @@ | |||||
| #define protected public | #define protected public | ||||
| #define private public | #define private public | ||||
| #include "graph/manager/graph_var_manager.h" | #include "graph/manager/graph_var_manager.h" | ||||
| #include "graph/manager/graph_mem_manager.h" | |||||
| #include "graph/ge_context.h" | #include "graph/ge_context.h" | ||||
| #undef protected | |||||
| #undef private | |||||
| namespace ge { | namespace ge { | ||||
| class UtestGraphVarManagerTest : public testing::Test { | class UtestGraphVarManagerTest : public testing::Test { | ||||
| protected: | protected: | ||||
| void SetUp() {} | |||||
| void TearDown() {} | |||||
| void SetUp() { | |||||
| VarManagerPool::Instance().Destory(); | |||||
| } | |||||
| void TearDown() { | |||||
| VarManagerPool::Instance().Destory(); | |||||
| } | |||||
| }; | }; | ||||
| TEST_F(UtestGraphVarManagerTest, test_get_total_memory_size) { | |||||
| size_t total_mem_size = 0; | |||||
| Status ret = VarManager::Instance(0)->GetTotalMemorySize(total_mem_size); | |||||
| EXPECT_EQ(total_mem_size, 1024UL * 1024UL * 1024UL); | |||||
| EXPECT_EQ(ret, SUCCESS); | |||||
| } | |||||
| TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_no_related_option) { | TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_no_related_option) { | ||||
| const map<string, string> options{}; | const map<string, string> options{}; | ||||
| Status ret = VarManager::Instance(0)->SetMemoryMallocSize(options); | |||||
| EXPECT_EQ(VarManager::Instance(0)->SetMemoryMallocSize(options, 1024UL * 1024UL * 1024UL), SUCCESS); | |||||
| EXPECT_EQ(VarManager::Instance(0)->graph_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (26.0f / 32.0f))); | EXPECT_EQ(VarManager::Instance(0)->graph_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (26.0f / 32.0f))); | ||||
| EXPECT_EQ(VarManager::Instance(0)->var_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (5.0f / 32.0f))); | EXPECT_EQ(VarManager::Instance(0)->var_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (5.0f / 32.0f))); | ||||
| EXPECT_EQ(ret, SUCCESS); | |||||
| EXPECT_EQ(VarManager::Instance(0)->Init(0, 0, 0, 0), SUCCESS); | |||||
| } | } | ||||
| TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_with_user_specify_graph_mem_max_size) { | TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_with_user_specify_graph_mem_max_size) { | ||||
| const map<string, string> options{{"ge.graphMemoryMaxSize", "536870912"}}; | const map<string, string> options{{"ge.graphMemoryMaxSize", "536870912"}}; | ||||
| Status ret = VarManager::Instance(0)->SetMemoryMallocSize(options); | |||||
| Status ret = VarManager::Instance(0)->SetMemoryMallocSize(options, 1024UL * 1024UL * 1024UL); | |||||
| EXPECT_EQ(VarManager::Instance(0)->graph_mem_max_size_, floor(1024UL * 1024UL * 1024UL / 2)); | EXPECT_EQ(VarManager::Instance(0)->graph_mem_max_size_, floor(1024UL * 1024UL * 1024UL / 2)); | ||||
| EXPECT_EQ(VarManager::Instance(0)->var_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (5.0f / 32.0f))); | EXPECT_EQ(VarManager::Instance(0)->var_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (5.0f / 32.0f))); | ||||
| EXPECT_EQ(ret, SUCCESS); | EXPECT_EQ(ret, SUCCESS); | ||||
| @@ -55,9 +51,38 @@ TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_with_user_specify_g | |||||
| TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_with_user_specify_var_mem_max_size) { | TEST_F(UtestGraphVarManagerTest, test_set_memory_malloc_size_with_user_specify_var_mem_max_size) { | ||||
| const map<string, string> options{{"ge.variableMemoryMaxSize", "536870912"}}; | const map<string, string> options{{"ge.variableMemoryMaxSize", "536870912"}}; | ||||
| Status ret = VarManager::Instance(0)->SetMemoryMallocSize(options); | |||||
| Status ret = VarManager::Instance(0)->SetMemoryMallocSize(options, 1024UL * 1024UL * 1024UL); | |||||
| EXPECT_EQ(VarManager::Instance(0)->graph_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (26.0f / 32.0f))); | EXPECT_EQ(VarManager::Instance(0)->graph_mem_max_size_, floor(1024UL * 1024UL * 1024UL * (26.0f / 32.0f))); | ||||
| EXPECT_EQ(VarManager::Instance(0)->var_mem_max_size_, floor(1024UL * 1024UL * 1024UL / 2)); | EXPECT_EQ(VarManager::Instance(0)->var_mem_max_size_, floor(1024UL * 1024UL * 1024UL / 2)); | ||||
| EXPECT_EQ(ret, SUCCESS); | EXPECT_EQ(ret, SUCCESS); | ||||
| } | } | ||||
| TEST_F(UtestGraphVarManagerTest, test_mem_manager_not_set) { | |||||
| EXPECT_EQ(VarManager::Instance(0)->Init(0, 0, 0, 0), SUCCESS); | |||||
| EXPECT_EQ(VarManager::Instance(0)->MallocVarMemory(1024), FAILED); | |||||
| EXPECT_EQ(VarManager::Instance(0)->GetVarMemoryBase(RT_MEMORY_RDMA_HBM), nullptr); | |||||
| EXPECT_EQ(VarManager::Instance(0)->GetVarMemoryAddr(nullptr, RT_MEMORY_RDMA_HBM), nullptr); | |||||
| GeTensorDesc tensor_desc; | |||||
| EXPECT_EQ(VarManager::Instance(0)->AssignVarMem("global_step", tensor_desc, RT_MEMORY_RDMA_HBM), INTERNAL_ERROR); | |||||
| } | |||||
| TEST_F(UtestGraphVarManagerTest, test_with_mem_manager) { | |||||
| const std::vector<rtMemType_t> memory_types({RT_MEMORY_HBM, RT_MEMORY_P2P_DDR}); | |||||
| EXPECT_EQ(MemManager::Instance().Initialize(memory_types), SUCCESS); | |||||
| VarManager::Instance(0)->SetMemManager(&MemManager::Instance()); | |||||
| EXPECT_EQ(VarManager::Instance(0)->Init(0, 0, 0, 0), SUCCESS); | |||||
| EXPECT_EQ(VarManager::Instance(0)->MallocVarMemory(1024), SUCCESS); | |||||
| EXPECT_EQ(VarManager::Instance(0)->GetVarMemoryBase(RT_MEMORY_RDMA_HBM), nullptr); | |||||
| uint8_t logic_addr = 0; | |||||
| EXPECT_EQ(VarManager::Instance(0)->GetVarMemoryAddr(&logic_addr, RT_MEMORY_RDMA_HBM), &logic_addr); | |||||
| EXPECT_NE(VarManager::Instance(0)->GetVarMemoryAddr(&logic_addr, RT_MEMORY_HBM), nullptr); | |||||
| // RdmaPoolAllocator block_bin_ not found. | |||||
| GeTensorDesc tensor_desc; | |||||
| EXPECT_EQ(VarManager::Instance(0)->AssignVarMem("global_step", tensor_desc, RT_MEMORY_RDMA_HBM), INTERNAL_ERROR); | |||||
| } | |||||
| } // namespace ge | } // namespace ge | ||||
| @@ -15,22 +15,11 @@ | |||||
| */ | */ | ||||
| #include <gtest/gtest.h> | #include <gtest/gtest.h> | ||||
| #include <memory> | |||||
| #include "graph/anchor.h" | |||||
| #include "graph/attr_value.h" | |||||
| #include "graph/debug/ge_attr_define.h" | |||||
| #include "graph/utils/graph_utils.h" | |||||
| #include "graph/utils/node_utils.h" | |||||
| #include "graph/utils/op_desc_utils.h" | |||||
| #include "graph/utils/tensor_utils.h" | |||||
| #include "omg/omg_inner_types.h" | #include "omg/omg_inner_types.h" | ||||
| #define protected public | #define protected public | ||||
| #define private public | #define private public | ||||
| #include "graph/manager/graph_mem_manager.h" | #include "graph/manager/graph_mem_manager.h" | ||||
| #undef protected | |||||
| #undef private | |||||
| using namespace std; | using namespace std; | ||||
| using namespace testing; | using namespace testing; | ||||
| @@ -83,7 +72,7 @@ TEST_F(UtestSessionScopeMemAllocator, free_success_session) { | |||||
| EXPECT_NE(nullptr, ptr); | EXPECT_NE(nullptr, ptr); | ||||
| ptr = MemManager::Instance().SessionScopeMemInstance(RT_MEMORY_HBM).Malloc(100, 0); | ptr = MemManager::Instance().SessionScopeMemInstance(RT_MEMORY_HBM).Malloc(100, 0); | ||||
| EXPECT_NE(nullptr, ptr); | EXPECT_NE(nullptr, ptr); | ||||
| for (auto memory_type : MemManager::Instance().GetAllMemoryType()) { | |||||
| for (auto memory_type : MemManager::Instance().memory_type_) { | |||||
| if (RT_MEMORY_P2P_DDR == memory_type) { | if (RT_MEMORY_P2P_DDR == memory_type) { | ||||
| EXPECT_NE(MemManager::Instance().SessionScopeMemInstance(memory_type).Free(0), SUCCESS); | EXPECT_NE(MemManager::Instance().SessionScopeMemInstance(memory_type).Free(0), SUCCESS); | ||||
| } else { | } else { | ||||
| @@ -164,7 +164,7 @@ TEST_F(UtestHcclNodeExecutor, gatheralltoallv_execute) { | |||||
| std::function<void()> done = []() {}; | std::function<void()> done = []() {}; | ||||
| ASSERT_EQ(task->ExecuteAsync(*node_state->GetTaskContext(), done), SUCCESS); | ASSERT_EQ(task->ExecuteAsync(*node_state->GetTaskContext(), done), SUCCESS); | ||||
| if (handle = nullptr) { | |||||
| if (handle != nullptr) { | |||||
| dlclose(handle); | dlclose(handle); | ||||
| } | } | ||||
| } | } | ||||
| @@ -221,7 +221,7 @@ TEST_F(UtestHcclNodeExecutor, alltoallv_execute) { | |||||
| std::function<void()> done = []() {}; | std::function<void()> done = []() {}; | ||||
| ASSERT_EQ(task->ExecuteAsync(*node_state->GetTaskContext(), done), SUCCESS); | ASSERT_EQ(task->ExecuteAsync(*node_state->GetTaskContext(), done), SUCCESS); | ||||
| if (handle = nullptr) { | |||||
| if (handle != nullptr) { | |||||
| dlclose(handle); | dlclose(handle); | ||||
| } | } | ||||
| } | } | ||||
| @@ -57,6 +57,7 @@ class SuccessNodeExecutor : public NodeExecutor { | |||||
| Status Finalize() override { | Status Finalize() override { | ||||
| finalized = true; | finalized = true; | ||||
| return SUCCESS; | |||||
| } | } | ||||
| bool initialized = false; | bool initialized = false; | ||||
| @@ -31,8 +31,6 @@ | |||||
| #include "graph/manager/graph_manager.h" | #include "graph/manager/graph_manager.h" | ||||
| #include "graph/ops_stub.h" | #include "graph/ops_stub.h" | ||||
| #include "inc/framework/omg/omg_inner_types.h" | #include "inc/framework/omg/omg_inner_types.h" | ||||
| #undef protected | |||||
| #undef private | |||||
| using namespace ge; | using namespace ge; | ||||
| using namespace std; | using namespace std; | ||||
| @@ -76,10 +74,21 @@ TEST_F(UtestGeProfilinganager, init_success) { | |||||
| struct MsprofGeOptions prof_conf = {{ 0 }}; | struct MsprofGeOptions prof_conf = {{ 0 }}; | ||||
| Status ret = ProfilingManager::Instance().InitFromOptions(options, prof_conf); | |||||
| Status ret = ProfilingManager::Instance().InitFromOptions(options.profiling_mode, options.profiling_options, options.job_id, prof_conf); | |||||
| EXPECT_EQ(ret, ge::SUCCESS); | EXPECT_EQ(ret, ge::SUCCESS); | ||||
| } | } | ||||
| TEST_F(UtestGeProfilinganager, initialize) { | |||||
| setenv("PROFILING_MODE", "true", true); | |||||
| const std::map<string, string> options({ | |||||
| {OPTION_EXEC_JOB_ID, "0"}, {OPTION_EXEC_PROFILING_MODE, "1"}, {OPTION_EXEC_PROFILING_OPTIONS, R"({"result_path":"/data/profiling","training_trace":"on","task_trace":"on","aicpu_trace":"on","fp_point":"Data_0","bp_point":"addn","ai_core_metrics":"ResourceConflictRatio"})"} | |||||
| }); | |||||
| ProfilingManager::Instance().Initialize(options); | |||||
| EXPECT_FALSE(ProfilingManager::Instance().is_execute_profiling_); | |||||
| } | |||||
| TEST_F(UtestGeProfilinganager, ParseOptions) { | TEST_F(UtestGeProfilinganager, ParseOptions) { | ||||
| setenv("PROFILING_MODE", "true", true); | setenv("PROFILING_MODE", "true", true); | ||||
| Options options; | Options options; | ||||
| @@ -110,35 +119,35 @@ TEST_F(UtestGeProfilinganager, report_data_) { | |||||
| ProfilingManager::Instance().ReportData(0, data, tag_name); | ProfilingManager::Instance().ReportData(0, data, tag_name); | ||||
| } | } | ||||
| TEST_F(UtestGeProfilinganager, get_fp_bp_point_) { | |||||
| map<std::string, string> options_map = { | |||||
| {OPTION_EXEC_PROFILING_OPTIONS, | |||||
| R"({"result_path":"/data/profiling","training_trace":"on","task_trace":"on","aicpu_trace":"on","fp_point":"Data_0","bp_point":"addn","ai_core_metrics":"ResourceConflictRatio"})"}}; | |||||
| GEThreadLocalContext &context = GetThreadLocalContext(); | |||||
| context.SetGraphOption(options_map); | |||||
| std::string fp_point; | |||||
| std::string bp_point; | |||||
| ProfilingManager::Instance().GetFpBpPoint(fp_point, bp_point); | |||||
| EXPECT_EQ(fp_point, "Data_0"); | |||||
| EXPECT_EQ(bp_point, "addn"); | |||||
| } | |||||
| TEST_F(UtestGeProfilinganager, get_fp_bp_point_empty) { | |||||
| // fp bp empty | |||||
| map<std::string, string> options_map = { | |||||
| { OPTION_EXEC_PROFILING_OPTIONS, | |||||
| R"({"result_path":"/data/profiling","training_trace":"on","task_trace":"on","aicpu_trace":"on","ai_core_metrics":"ResourceConflictRatio"})"}}; | |||||
| GEThreadLocalContext &context = GetThreadLocalContext(); | |||||
| context.SetGraphOption(options_map); | |||||
| std::string fp_point = "fp"; | |||||
| std::string bp_point = "bp"; | |||||
| ProfilingManager::Instance().bp_point_ = ""; | |||||
| ProfilingManager::Instance().fp_point_ = ""; | |||||
| ProfilingManager::Instance().GetFpBpPoint(fp_point, bp_point); | |||||
| EXPECT_EQ(fp_point, ""); | |||||
| EXPECT_EQ(bp_point, ""); | |||||
| } | |||||
| //TEST_F(UtestGeProfilinganager, get_fp_bp_point_) { | |||||
| // map<std::string, string> options_map = { | |||||
| // {OPTION_EXEC_PROFILING_OPTIONS, | |||||
| // R"({"result_path":"/data/profiling","training_trace":"on","task_trace":"on","aicpu_trace":"on","fp_point":"Data_0","bp_point":"addn","ai_core_metrics":"ResourceConflictRatio"})"}}; | |||||
| // GEThreadLocalContext &context = GetThreadLocalContext(); | |||||
| // context.SetGraphOption(options_map); | |||||
| // | |||||
| // std::string fp_point; | |||||
| // std::string bp_point; | |||||
| // ProfilingManager::Instance().GetFpBpPoint(fp_point, bp_point); | |||||
| // EXPECT_EQ(fp_point, "Data_0"); | |||||
| // EXPECT_EQ(bp_point, "addn"); | |||||
| //} | |||||
| //TEST_F(UtestGeProfilinganager, get_fp_bp_point_empty) { | |||||
| // // fp bp empty | |||||
| // map<std::string, string> options_map = { | |||||
| // { OPTION_EXEC_PROFILING_OPTIONS, | |||||
| // R"({"result_path":"/data/profiling","training_trace":"on","task_trace":"on","aicpu_trace":"on","ai_core_metrics":"ResourceConflictRatio"})"}}; | |||||
| // GEThreadLocalContext &context = GetThreadLocalContext(); | |||||
| // context.SetGraphOption(options_map); | |||||
| // std::string fp_point = "fp"; | |||||
| // std::string bp_point = "bp"; | |||||
| // ProfilingManager::Instance().bp_point_ = ""; | |||||
| // ProfilingManager::Instance().fp_point_ = ""; | |||||
| // ProfilingManager::Instance().GetFpBpPoint(fp_point, bp_point); | |||||
| // EXPECT_EQ(fp_point, ""); | |||||
| // EXPECT_EQ(bp_point, ""); | |||||
| //} | |||||
| TEST_F(UtestGeProfilinganager, set_step_info_success) { | TEST_F(UtestGeProfilinganager, set_step_info_success) { | ||||
| uint64_t index_id = 0; | uint64_t index_id = 0; | ||||