| @@ -76,21 +76,17 @@ if (ENABLE_OPEN_SRC) | |||
| find_module(runtime libruntime.so ${GE_LIB_PATH}) | |||
| find_module(runtime_compile libruntime_compile.so ${GE_LIB_PATH}) | |||
| find_module(resource libresource.so ${GE_LIB_PATH}) | |||
| find_module(error_manager liberror_manager.so ${GE_LIB_PATH}) | |||
| find_module(ascend_hal_stub libascend_hal.so ${GE_LIB_PATH}) | |||
| find_module(error_manager_static liberror_manager.a ${GE_LIB_PATH}) | |||
| find_module(msprofiler_fwk_ext libmsprofiler_fwk.a ${GE_LIB_PATH}) | |||
| #find_module(ascendcl_static libascendcl.a ${GE_LIB_PATH}) | |||
| elseif(ENABLE_GE_COV OR ENABLE_GE_UT) | |||
| add_subdirectory(tests) | |||
| else() | |||
| find_module(slog libslog.so ${ASCEND_ATC_DIR} ${ASCEND_DRIVER_COMMON_DIR}) | |||
| find_module(slog libalog.so ${ASCEND_ATC_DIR} ${ASCEND_DRIVER_COMMON_DIR}) | |||
| find_module(static_mmpa libmmpa.a ${ASCEND_ATC_DIR} ${ASCEND_RUNTIME_DIR}) | |||
| find_module(error_manager liberror_manager.so ${ASCEND_ATC_DIR} ${ASCEND_RUNTIME_DIR}) | |||
| if(PLATFORM STREQUAL "train") | |||
| find_module(adump_server libadump_server.a ${ASCEND_RUNTIME_DIR}) | |||
| find_module(runtime libruntime.so ${ASCEND_RUNTIME_DIR}) | |||
| find_module(error_manager liberror_manager.so ${ASCEND_RUNTIME_DIR}) | |||
| find_module(msprofiler_fwk_ext libmsprofiler_fwk.a ${ASCEND_RUNTIME_DIR}) | |||
| find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}/driver) | |||
| if(PRODUCT STREQUAL "flr3") | |||
| @@ -100,8 +96,6 @@ if (ENABLE_OPEN_SRC) | |||
| find_module(adump_server libadump_server.a ${ASCEND_ACL_DIR}) | |||
| find_module(runtime libruntime.so ${ASCEND_ACL_DIR}) | |||
| find_module(runtime_compile libruntime_compile.so ${ASCEND_ATC_DIR}) | |||
| find_module(error_manager liberror_manager.so ${ASCEND_ATC_DIR}) | |||
| find_module(error_manager_static liberror_manager.a ${ASCEND_ACL_DIR}) | |||
| find_module(msprofiler_ext libmsprofiler.a ${ASCEND_ACL_DIR}) | |||
| if(PRODUCT STREQUAL "flr3") | |||
| elseif(PRODUCT STREQUAL "flr1") | |||
| @@ -114,11 +108,9 @@ if (ENABLE_OPEN_SRC) | |||
| elseif(PLATFORM STREQUAL "all") | |||
| find_module(adump_server libadump_server.a ${ASCEND_RUNTIME_DIR}) | |||
| find_module(runtime libruntime.so ${ASCEND_RUNTIME_DIR}) | |||
| find_module(error_manager liberror_manager.so ${ASCEND_RUNTIME_DIR}) | |||
| find_module(msprofiler_fwk_ext libmsprofiler_fwk.a ${ASCEND_RUNTIME_DIR}) | |||
| find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}) | |||
| find_module(runtime_compile libruntime_compile.so ${ASCEND_ATC_DIR}) | |||
| find_module(error_manager_static liberror_manager.a ${ASCEND_ACL_DIR}) | |||
| find_module(msprofiler_ext libmsprofiler.a ${ASCEND_ACL_DIR}) | |||
| else() | |||
| message(STATUS "PLATFORM param is invalid, should be train or inference, you choose nothing!") | |||
| @@ -144,7 +136,6 @@ elseif (ENABLE_D OR ENABLE_ACL) | |||
| # common libraries | |||
| find_module(slog libalog.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| find_module(error_manager liberror_manager.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| find_module(static_mmpa libmmpa.a ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| if (ENABLE_D) | |||
| @@ -164,7 +155,6 @@ elseif(ENABLE_MS_TESTCASES) | |||
| # common libraries | |||
| find_module(slog libalog.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| find_module(error_manager liberror_manager.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| find_module(static_mmpa libmmpa.a ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef) | |||
| @@ -76,8 +76,8 @@ checkopts() | |||
| ENABLE_GE_ST="on" | |||
| ;; | |||
| t) | |||
| ENABLE_GE_UT="on" | |||
| ;; | |||
| ENABLE_GE_UT="on" | |||
| ;; | |||
| c) | |||
| ENABLE_GE_COV="on" | |||
| ;; | |||
| @@ -185,7 +185,7 @@ build_graphengine() | |||
| # build all the target | |||
| TARGET="ge_runner ge_compiler fwk_atc.bin atc_atc.bin opensrc_ascendcl ${TARGET}" | |||
| fi | |||
| make ${VERBOSE} ${TARGET} -j${THREAD_NUM} && make install | |||
| if [ $? -ne 0 ] | |||
| then | |||
| @@ -214,13 +214,14 @@ if [[ "X$ENABLE_GE_UT" = "Xon" || "X$ENABLE_GE_COV" = "Xon" ]]; then | |||
| cp ${BUILD_PATH}/tests/ut/ge/ut_libge_others_utest ${OUTPUT_PATH} | |||
| cp ${BUILD_PATH}/tests/ut/ge/ut_libge_kernel_utest ${OUTPUT_PATH} | |||
| ${OUTPUT_PATH}/ut_libgraph && | |||
| ${OUTPUT_PATH}/ut_libge_multiparts_utest && | |||
| ${OUTPUT_PATH}/ut_libge_distinct_load_utest && | |||
| ${OUTPUT_PATH}/ut_libge_others_utest && | |||
| ${OUTPUT_PATH}/ut_libge_kernel_utest | |||
| RUN_TEST_CASE=${OUTPUT_PATH}/ut_libgraph && ${RUN_TEST_CASE} && | |||
| RUN_TEST_CASE=${OUTPUT_PATH}/ut_libge_multiparts_utest && ${RUN_TEST_CASE} && | |||
| RUN_TEST_CASE=${OUTPUT_PATH}/ut_libge_distinct_load_utest && ${RUN_TEST_CASE} && | |||
| RUN_TEST_CASE=${OUTPUT_PATH}/ut_libge_others_utest && ${RUN_TEST_CASE} && | |||
| RUN_TEST_CASE=${OUTPUT_PATH}/ut_libge_kernel_utest && ${RUN_TEST_CASE} | |||
| if [[ "$?" -ne 0 ]]; then | |||
| echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!" | |||
| echo -e "\033[31m${RUN_TEST_CASE}\033[0m" | |||
| exit 1; | |||
| fi | |||
| echo "Generating coverage statistics, please wait..." | |||
| @@ -249,8 +250,8 @@ generate_package() | |||
| NNENGINE_PATH="plugin/nnengine/ge_config" | |||
| OPSKERNEL_PATH="plugin/opskernel" | |||
| ATC_LIB=("libc_sec.so" "libge_common.so" "libge_compiler.so" "libgraph.so" "libregister.so") | |||
| FWK_LIB=("libge_common.so" "libge_runner.so" "libgraph.so" "libregister.so") | |||
| ATC_LIB=("libc_sec.so" "libge_common.so" "libge_compiler.so" "libgraph.so" "libregister.so" "liberror_manager.so") | |||
| FWK_LIB=("libge_common.so" "libge_runner.so" "libgraph.so" "libregister.so" "liberror_manager.so") | |||
| PLUGIN_OPSKERNEL=("libge_local_engine.so" "libge_local_opskernel_builder.so" "libhost_cpu_engine.so" "libhost_cpu_opskernel_builder.so" "optimizer_priority.pbtxt") | |||
| PARSER_LIB=("lib_caffe_parser.so" "libfmk_onnx_parser.so" "libfmk_parser.so" "libparser_common.so") | |||
| @@ -269,7 +270,7 @@ generate_package() | |||
| mk_dir "${OUTPUT_PATH}/${FWK_BIN_PATH}" | |||
| mk_dir "${OUTPUT_PATH}/${FWK_INCLUDE_PATH}" | |||
| mk_dir "${OUTPUT_PATH}/${ATC_INCLUDE_PATH}" | |||
| cd "${OUTPUT_PATH}" | |||
| find ./ -name graphengine_lib.tar -exec rm {} \; | |||
| @@ -27,7 +27,7 @@ ExternalProject_Add(gtest_build | |||
| URL ${REQ_URL} | |||
| TLS_VERIFY OFF | |||
| CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_CXX_FLAGS=${gtest_CXXFLAGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/gtest <SOURCE_DIR> | |||
| -DBUILD_TESTING=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_MACOSX_RPATH=TRUE -Dgtest_disable_pthreads=ON | |||
| -DBUILD_TESTING=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_MACOSX_RPATH=TRUE | |||
| BUILD_COMMAND $(MAKE) | |||
| INSTALL_COMMAND $(MAKE) install | |||
| EXCLUDE_FROM_ALL TRUE | |||
| @@ -52,10 +52,27 @@ set_target_properties(gtest_main PROPERTIES | |||
| target_include_directories(gtest INTERFACE ${GTEST_PKG_DIR}/include) | |||
| target_include_directories(gtest_main INTERFACE ${GTEST_PKG_DIR}/include) | |||
| add_library(gmock SHARED IMPORTED) | |||
| set_target_properties(gmock PROPERTIES | |||
| IMPORTED_LOCATION ${GTEST_PKG_DIR}/lib/libgmock.so | |||
| ) | |||
| add_library(gmock_main SHARED IMPORTED) | |||
| set_target_properties(gmock_main PROPERTIES | |||
| IMPORTED_LOCATION ${GTEST_PKG_DIR}/lib/libgmock_main.so | |||
| ) | |||
| target_include_directories(gmock INTERFACE ${GTEST_PKG_DIR}/include) | |||
| target_include_directories(gmock_main INTERFACE ${GTEST_PKG_DIR}/include) | |||
| set(INSTALL_BASE_DIR "") | |||
| set(INSTALL_LIBRARY_DIR lib) | |||
| install(FILES ${GTEST_PKG_DIR}/lib/libgtest.so ${GTEST_PKG_DIR}/lib/libgtest_main.so OPTIONAL | |||
| install(FILES ${GTEST_PKG_DIR}/lib/libgtest.so ${GTEST_PKG_DIR}/lib/libgtest_main.so ${GTEST_PKG_DIR}/lib/libgmock.so ${GTEST_PKG_DIR}/lib/libgmock_main.so OPTIONAL | |||
| DESTINATION ${INSTALL_LIBRARY_DIR}) | |||
| add_dependencies(gtest gtest_build) | |||
| @@ -103,6 +103,7 @@ set(TRAIN_SRC_LIST | |||
| "common/profiling/profiling_manager.cc" | |||
| "common/dump/dump_manager.cc" | |||
| "common/dump/dump_properties.cc" | |||
| "common/dump/opdebug_register.cc" | |||
| "common/dump/dump_op.cc" | |||
| "common/profiling/ge_profiling.cc" | |||
| "common/profiling/ge_runner_profiling.cc" | |||
| @@ -133,7 +134,6 @@ set(TRAIN_SRC_LIST | |||
| "graph/load/model_manager/data_dumper.cc" | |||
| "graph/load/model_manager/data_inputer.cc" | |||
| "graph/load/model_manager/davinci_model.cc" | |||
| "graph/load/model_manager/davinci_model_parser.cc" | |||
| "graph/load/model_manager/model_manager.cc" | |||
| "graph/load/model_manager/model_utils.cc" | |||
| "graph/load/model_manager/aipp_utils.cc" | |||
| @@ -428,6 +428,7 @@ set(INFER_SRC_LIST | |||
| "common/dump/dump_properties.cc" | |||
| "common/dump/dump_manager.cc" | |||
| "common/dump/dump_op.cc" | |||
| "common/dump/opdebug_register.cc" | |||
| "common/dump/dump_server.cc" | |||
| "common/helper/model_cache_helper.cc" | |||
| "ge_local_engine/engine/host_cpu_engine.cc" | |||
| @@ -613,7 +614,6 @@ set(INFER_SRC_LIST | |||
| "graph/load/model_manager/model_manager.cc" | |||
| "graph/load/model_manager/data_inputer.cc" | |||
| "graph/load/model_manager/davinci_model.cc" | |||
| "graph/load/model_manager/davinci_model_parser.cc" | |||
| "graph/load/model_manager/model_utils.cc" | |||
| "graph/load/model_manager/aipp_utils.cc" | |||
| "graph/load/model_manager/tbe_handle_store.cc" | |||
| @@ -103,7 +103,7 @@ ge::Status Analyzer::Initialize() { | |||
| // Initialize file | |||
| string real_path = RealPath(kFilePath.c_str()); | |||
| if (real_path.empty()) { | |||
| GELOGE(FAILED, "File path is invalid."); | |||
| GELOGE(FAILED, "[Check][AnalyzeFilePath]File path is empty, Path invalid."); | |||
| return FAILED; | |||
| } | |||
| json_file_name_ = real_path + "/" + kAnalyzeFile; | |||
| @@ -155,12 +155,12 @@ std::shared_ptr<GraphInfo> Analyzer::GetJsonObject(uint64_t session_id, uint64_t | |||
| std::lock_guard<std::recursive_mutex> lg(mutex_); | |||
| auto iter = graph_infos_.find(session_id); | |||
| if (iter == graph_infos_.end()) { | |||
| GELOGE(PARAM_INVALID, "session_id:%lu does not exist!", session_id); | |||
| GELOGE(PARAM_INVALID, "[Check][Session_id]session_id:%lu does not exist! graph_id:%lu.", session_id, graph_id); | |||
| return nullptr; | |||
| } else { | |||
| auto iter1 = (iter->second).find(graph_id); | |||
| if (iter1 == (iter->second).end()) { | |||
| GELOGE(PARAM_INVALID, "graph_id:%lu does not exist!", graph_id); | |||
| GELOGE(PARAM_INVALID, "[Check][Graph_id]graph_id:%lu does not exist! session_id:%lu.", graph_id, session_id); | |||
| return nullptr; | |||
| } | |||
| GELOGI("GetJsonObject Success!session_id:%lu graph_id:%lu", session_id, graph_id); | |||
| @@ -186,11 +186,11 @@ ge::Status Analyzer::CreateAnalyzerFile() { | |||
| std::lock_guard<std::mutex> lg(file_mutex_); | |||
| int fd = open(json_file_name_.c_str(), O_WRONLY | O_CREAT | O_TRUNC, kFileAuthority); | |||
| if (fd < 0) { | |||
| GELOGE(INTERNAL_ERROR, "Fail to open the file: %s.", json_file_name_.c_str()); | |||
| GELOGE(INTERNAL_ERROR, "[FileOpen][AnalyzeFile]Fail to open the analyze file: %s.", json_file_name_.c_str()); | |||
| return INTERNAL_ERROR; | |||
| } | |||
| if (close(fd) != 0) { | |||
| GELOGE(INTERNAL_ERROR, "Fail to close the file: %s.", json_file_name_.c_str()); | |||
| GELOGE(INTERNAL_ERROR, "[FileClose][AnalyzeFile]Fail to close the analyze file: %s.", json_file_name_.c_str()); | |||
| return INTERNAL_ERROR; | |||
| } | |||
| is_json_file_create_ = true; | |||
| @@ -200,7 +200,7 @@ ge::Status Analyzer::CreateAnalyzerFile() { | |||
| } | |||
| ge::Status Analyzer::SaveAnalyzerDataToFile(uint64_t session_id, uint64_t graph_id) { | |||
| GELOGD("start to save analyze file!"); | |||
| GELOGD("start to save analyze file."); | |||
| auto graph_info = GetJsonObject(session_id, graph_id); | |||
| GE_CHECK_NOTNULL(graph_info); | |||
| @@ -211,7 +211,7 @@ ge::Status Analyzer::SaveAnalyzerDataToFile(uint64_t session_id, uint64_t graph_ | |||
| std::lock_guard<std::mutex> lg(file_mutex_); | |||
| json_file_.open(json_file_name_, std::ios::app); | |||
| if (!json_file_.is_open()) { | |||
| GELOGE(FAILED, "analyzer file does not exist[%s]", json_file_name_.c_str()); | |||
| GELOGE(FAILED, "[Check][AnalyzeFile]analyze file does not exist[%s]", json_file_name_.c_str()); | |||
| return PARAM_INVALID; | |||
| } | |||
| @@ -221,7 +221,7 @@ ge::Status Analyzer::SaveAnalyzerDataToFile(uint64_t session_id, uint64_t graph_ | |||
| try { | |||
| json_file_ << jsn.dump(kJsonDumpLevel) << std::endl; | |||
| } catch (nlohmann::detail::type_error &e) { | |||
| GELOGE(FAILED, "analyzer file [%s] failed because [%s]", json_file_name_.c_str(), e.what()); | |||
| GELOGE(FAILED, "[Json.dump][GraphInfo]json.dump to analyze file [%s] failed because [%s], session_id:%lu, graph_id:%lu", json_file_name_.c_str(), e.what(), session_id, graph_id); | |||
| ret_failed = true; | |||
| } | |||
| json_file_.close(); | |||
| @@ -229,7 +229,7 @@ ge::Status Analyzer::SaveAnalyzerDataToFile(uint64_t session_id, uint64_t graph_ | |||
| } | |||
| ge::Status Analyzer::DoAnalyze(DataInfo &data_info) { | |||
| GELOGD("start to do analyzer!"); | |||
| GELOGD("start to do analyzer process!"); | |||
| auto pnode = data_info.node_ptr; | |||
| GE_CHECK_NOTNULL(pnode); | |||
| @@ -241,7 +241,7 @@ ge::Status Analyzer::DoAnalyze(DataInfo &data_info) { | |||
| GE_CHECK_NOTNULL(graph_info); | |||
| auto status = SaveOpInfo(desc, data_info, graph_info); | |||
| if (status != SUCCESS) { | |||
| GELOGE(status, "save op info failed!"); | |||
| GELOGE(status, "[Check][SaveOpInfo]save op info: desc_name [%s] desc_type [%s] failed!", desc->GetName().c_str(), desc->GetType().c_str()); | |||
| return FAILED; | |||
| } | |||
| // create json file | |||
| @@ -32,6 +32,7 @@ | |||
| #include "graph/common/ge_call_wrapper.h" | |||
| #include "register/op_registry.h" | |||
| #include "common/ge/tbe_plugin_manager.h" | |||
| #include "common/util/error_manager/error_manager.h" | |||
| #include "toolchain/plog.h" | |||
| using domi::OpRegistry; | |||
| @@ -78,12 +79,21 @@ Status CheckOptionsValid(const std::map<string, string> &options) { | |||
| // Initialize GE, prepare for execution, call GELib::Initialize | |||
| Status GEInitializeImpl(const std::map<string, string> &options) { | |||
| ErrorManager::GetInstance().GenWorkStreamIdDefault(); | |||
| GELOGT(TRACE_INIT, "GEInitialize start"); | |||
| std::string path_base = ge::GELib::GetPath(); | |||
| auto ret = ErrorManager::GetInstance().Init(path_base); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(GE_CLI_INIT_FAILED, "ErrorManager init fail"); | |||
| return ret; | |||
| } | |||
| // 0.check init status | |||
| if (g_ge_initialized) { | |||
| GELOGW("GEInitialize is called more than once"); | |||
| return SUCCESS; | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOpsProtoInit); | |||
| // Load OpsProto lib plugin | |||
| std::string opsproto_path; | |||
| GetOpsProtoPath(opsproto_path); | |||
| @@ -98,6 +108,7 @@ Status GEInitializeImpl(const std::map<string, string> &options) { | |||
| return FAILED; | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOther); | |||
| // check options is valid | |||
| GE_TIMESTAMP_START(CheckOptionsValid); | |||
| if (CheckOptionsValid(options) != SUCCESS) { | |||
| @@ -105,13 +116,15 @@ Status GEInitializeImpl(const std::map<string, string> &options) { | |||
| } | |||
| GE_TIMESTAMP_END(CheckOptionsValid, "GEInitialize::CheckOptionsValid"); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOpsProtoInit); | |||
| GE_TIMESTAMP_START(InitPreparation); | |||
| TBEPluginManager::Instance().InitPreparation(options); | |||
| GE_TIMESTAMP_END(InitPreparation, "GEInitialize::InitPreparation"); | |||
| // call Initialize | |||
| GELOGT(TRACE_RUNNING, "Initializing environment"); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOther); | |||
| GE_TIMESTAMP_START(GELibInitialize); | |||
| Status ret = ge::GELib::Initialize(options); | |||
| ret = ge::GELib::Initialize(options); | |||
| GE_TIMESTAMP_END(GELibInitialize, "GEInitialize::GELibInitialize"); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(GE_CLI_INIT_FAILED, "geInitialize failed, error code = %u", ret); | |||
| @@ -130,6 +143,7 @@ Status GEInitializeImpl(const std::map<string, string> &options) { | |||
| // Initialize GE, prepare for execution, call GELib::Initialize | |||
| Status GEInitialize(const std::map<string, string> &options) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOther); | |||
| if (DlogReportInitialize() != SUCCESS) { | |||
| GELOGW("Dlog report device log initialize failed."); | |||
| } | |||
| @@ -137,6 +151,7 @@ Status GEInitialize(const std::map<string, string> &options) { | |||
| } | |||
| Status GEInitialize(const std::map<AscendString, AscendString> &options) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOther); | |||
| std::map<std::string, std::string> str_options; | |||
| for (auto &option : options) { | |||
| if (option.first.GetString() == nullptr || option.second.GetString() == nullptr) { | |||
| @@ -156,7 +171,10 @@ Status GEInitialize(const std::map<AscendString, AscendString> &options) { | |||
| // GE finalize, releasing all resources | |||
| Status GEFinalize() { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kFinalize, ErrorMessage::kFinalize); | |||
| GELOGT(TRACE_INIT, "GEFinalize start"); | |||
| ErrorManager::GetInstance().GenWorkStreamIdDefault(); | |||
| // check init status | |||
| if (!g_ge_initialized) { | |||
| GELOGW("GEFinalize is called before GEInitialize"); | |||
| @@ -202,9 +220,20 @@ Status GEFinalize() { | |||
| return ret; | |||
| } | |||
| std::string GEGetErrorMsg() { | |||
| return ErrorManager::GetInstance().GetErrorMessage(); | |||
| } | |||
| std::string GEGetWarningMsg() { | |||
| return ErrorManager::GetInstance().GetWarningMessage(); | |||
| } | |||
| // Initialize session,which calls innerSession | |||
| Session::Session(const std::map<string, string> &options) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOther); | |||
| GELOGT(TRACE_INIT, "Session Constructor start"); | |||
| ErrorManager::GetInstance().GenWorkStreamIdDefault(); | |||
| // check init status | |||
| sessionId_ = 0; | |||
| if (!g_ge_initialized) { | |||
| @@ -234,7 +263,10 @@ Session::Session(const std::map<string, string> &options) { | |||
| } | |||
| Session::Session(const std::map<AscendString, AscendString> &options) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOther); | |||
| GELOGT(TRACE_INIT, "Session Constructor start"); | |||
| ErrorManager::GetInstance().GenWorkStreamIdDefault(); | |||
| // check init status | |||
| sessionId_ = 0; | |||
| if (!g_ge_initialized) { | |||
| @@ -275,6 +307,7 @@ Session::Session(const std::map<AscendString, AscendString> &options) { | |||
| // session destructor | |||
| Session::~Session() { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kFinalize, ErrorMessage::kFinalize); | |||
| GELOGT(TRACE_INIT, "Session Destructor start"); | |||
| // 0.check init status | |||
| if (!g_ge_initialized) { | |||
| @@ -310,12 +343,16 @@ Session::~Session() { | |||
| } | |||
| Status Session::AddGraph(uint32_t graph_id, const Graph &graph) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| std::map<std::string, std::string> options; | |||
| ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id); | |||
| return AddGraph(graph_id, graph, options); | |||
| } | |||
| Status Session::AddGraph(uint32_t graph_id, const Graph &graph, const std::map<std::string, std::string> &options) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GELOGT(TRACE_INIT, "Start to add graph in Session. graph_id: %u, session_id: %lu.", graph_id, sessionId_); | |||
| ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id); | |||
| std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
| if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
| GELOGE(GE_CLI_GE_NOT_INITIALIZED, "AddGraph failed in Session."); | |||
| @@ -333,7 +370,9 @@ Status Session::AddGraph(uint32_t graph_id, const Graph &graph, const std::map<s | |||
| Status Session::AddGraph(uint32_t graph_id, const Graph &graph, | |||
| const std::map<AscendString, AscendString> &options) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GELOGT(TRACE_INIT, "Start to add graph in Session. graph_id: %u, session_id: %lu.", graph_id, sessionId_); | |||
| ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id); | |||
| std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
| if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
| GELOGE(GE_CLI_GE_NOT_INITIALIZED, "AddGraph failed in Session."); | |||
| @@ -360,13 +399,17 @@ Status Session::AddGraph(uint32_t graph_id, const Graph &graph, | |||
| } | |||
| Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id); | |||
| std::map<AscendString, AscendString> options; | |||
| return AddGraphWithCopy(graph_id, graph, options); | |||
| } | |||
| Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph, | |||
| const std::map<AscendString, AscendString> &options) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GELOGT(TRACE_INIT, "Start to add graph in Session. graph_id: %u, session_id: %lu.", graph_id, sessionId_); | |||
| ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id); | |||
| std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
| if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
| GELOGE(GE_CLI_GE_NOT_INITIALIZED, "AddGraph failed in Session."); | |||
| @@ -387,8 +430,10 @@ Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph, | |||
| } | |||
| Status Session::RemoveGraph(uint32_t graph_id) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GELOGT(TRACE_INIT, "Session RemoveGraph start"); | |||
| ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id); | |||
| // call RemoveGraph | |||
| std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
| if (!instance_ptr || !instance_ptr->InitFlag()) { | |||
| @@ -455,8 +500,10 @@ void PrintOutputResult(std::vector<Tensor> &outputs) { | |||
| } | |||
| Status Session::RunGraph(uint32_t graph_id, const std::vector<Tensor> &inputs, std::vector<Tensor> &outputs) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GELOGT(TRACE_INIT, "Session RunGraph start"); | |||
| ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id); | |||
| std::vector<Tensor> graph_inputs = inputs; | |||
| // call RunGraph | |||
| std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
| @@ -483,10 +530,12 @@ Status Session::RunGraph(uint32_t graph_id, const std::vector<Tensor> &inputs, s | |||
| } | |||
| Status Session::RegisterCallBackFunc(const std::string &key, const pCallBackFunc &callback) { | |||
| ErrorManager::GetInstance().GenWorkStreamIdDefault(); | |||
| return ge::GELib::GetInstance()->SessionManagerObj().RegisterCallBackFunc(sessionId_, key, callback); | |||
| } | |||
| Status Session::RegisterCallBackFunc(const char *key, const session::pCallBackFunc &callback) { | |||
| ErrorManager::GetInstance().GenWorkStreamIdDefault(); | |||
| std::string str_key; | |||
| if (key != nullptr) { | |||
| str_key = key; | |||
| @@ -495,6 +544,8 @@ Status Session::RegisterCallBackFunc(const char *key, const session::pCallBackFu | |||
| } | |||
| Status Session::BuildGraph(uint32_t graph_id, const std::vector<InputTensorInfo> &inputs) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id); | |||
| std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
| if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
| GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed"); | |||
| @@ -511,6 +562,8 @@ Status Session::BuildGraph(uint32_t graph_id, const std::vector<InputTensorInfo> | |||
| Status Session::RunGraphAsync(uint32_t graph_id, const std::vector<InputTensorInfo> &inputs, | |||
| RunAsyncCallback callback) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelExecute, ErrorMessage::kModelExecute); | |||
| ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id); | |||
| std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
| if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
| GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed"); | |||
| @@ -529,6 +582,8 @@ Status Session::RunGraphAsync(uint32_t graph_id, const std::vector<InputTensorIn | |||
| } | |||
| Status Session::GetVariables(const std::vector<std::string> &var_names, std::vector<Tensor> &var_values) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelExecute, ErrorMessage::kModelExecute); | |||
| ErrorManager::GetInstance().GenWorkStreamIdDefault(); | |||
| auto instance_ptr = ge::GELib::GetInstance(); | |||
| if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
| GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed"); | |||
| @@ -544,6 +599,8 @@ Status Session::GetVariables(const std::vector<std::string> &var_names, std::vec | |||
| } | |||
| Status Session::GetVariables(const std::vector<AscendString> &var_names, std::vector<Tensor> &var_values) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelExecute, ErrorMessage::kModelExecute); | |||
| ErrorManager::GetInstance().GenWorkStreamIdDefault(); | |||
| auto instance_ptr = ge::GELib::GetInstance(); | |||
| if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
| GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed"); | |||
| @@ -54,7 +54,7 @@ set(SRC_LIST | |||
| "util.cc" | |||
| "properties_manager.cc" | |||
| "types.cc" | |||
| "model_parser/base.cc" | |||
| "model_parser/model_parser.cc" | |||
| "kernel_store.cc" | |||
| "tbe_kernel_store.cc" | |||
| "cust_aicpu_kernel_store.cc" | |||
| @@ -25,7 +25,7 @@ void CustAICPUKernelStore::AddCustAICPUKernel(const CustAICPUKernelPtr &kernel) | |||
| } | |||
| void CustAICPUKernelStore::LoadCustAICPUKernelBinToOpDesc(const std::shared_ptr<ge::OpDesc> &op_desc) const { | |||
| GELOGD("LoadCustAICPUKernelBinToOpDesc in"); | |||
| GELOGD("LoadCustAICPUKernelBinToOpDesc in."); | |||
| if (op_desc != nullptr) { | |||
| auto kernel_bin = FindKernel(op_desc->GetName()); | |||
| if (kernel_bin != nullptr) { | |||
| @@ -34,6 +34,6 @@ void CustAICPUKernelStore::LoadCustAICPUKernelBinToOpDesc(const std::shared_ptr< | |||
| GELOGI("Load cust aicpu kernel:%s, %zu", kernel_bin->GetName().c_str(), kernel_bin->GetBinDataSize()); | |||
| } | |||
| } | |||
| GELOGD("LoadCustAICPUKernelBinToOpDesc success"); | |||
| GELOGD("LoadCustAICPUKernelBinToOpDesc success."); | |||
| } | |||
| } // namespace ge | |||
| @@ -22,6 +22,7 @@ namespace { | |||
| const char *const kDumpOFF = "OFF"; | |||
| const char *const kDumpoff = "off"; | |||
| const char *const kDumpOn = "on"; | |||
| const uint64_t kInferSessionId = 0; | |||
| } // namespace | |||
| namespace ge { | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpManager &DumpManager::GetInstance() { | |||
| @@ -30,15 +31,14 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpManager &DumpManager::GetIn | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpManager::SetDumpConf(const DumpConfig &dump_config) { | |||
| std::lock_guard<std::mutex> lock(mutex_); | |||
| dump_properties_.ClearDumpPropertyValue(); | |||
| dump_properties_.ClearDumpInfo(); | |||
| DumpProperties dump_properties; | |||
| std::string dump_status; | |||
| std::string dump_path; | |||
| std::string dump_mode; | |||
| std::string dump_op_switch; | |||
| if (dump_config.dump_status.empty()) { | |||
| dump_properties_map_.emplace(kInferSessionId, dump_properties); | |||
| GELOGI("Dump does not open"); | |||
| return SUCCESS; | |||
| } | |||
| @@ -46,14 +46,16 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpManager::SetDumpConf | |||
| dump_status = dump_config.dump_status; | |||
| GELOGI("Dump status is %s", dump_status.c_str()); | |||
| if (dump_config.dump_status == kDumpoff || dump_config.dump_status == kDumpOFF) { | |||
| dump_properties_.ClearDumpPropertyValue(); | |||
| dump_properties.ClearDumpPropertyValue(); | |||
| dump_properties_map_.emplace(kInferSessionId, dump_properties); | |||
| return SUCCESS; | |||
| } | |||
| dump_properties_.SetDumpStatus(dump_status); | |||
| dump_properties.SetDumpStatus(dump_status); | |||
| dump_op_switch = dump_config.dump_op_switch; | |||
| dump_properties_.SetDumpOpSwitch(dump_op_switch); | |||
| dump_properties.SetDumpOpSwitch(dump_op_switch); | |||
| if (dump_op_switch == kDumpoff && dump_config.dump_list.empty()) { | |||
| dump_properties_map_.emplace(kInferSessionId, dump_properties); | |||
| GELOGE(PARAM_INVALID, "Dump list is invalid,dump_op_switch is %s", dump_op_switch.c_str()); | |||
| return PARAM_INVALID; | |||
| } | |||
| @@ -67,15 +69,15 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpManager::SetDumpConf | |||
| GELOGI("Dump layer is %s in model", layer.c_str()); | |||
| dump_layers.insert(layer); | |||
| } | |||
| dump_properties_.AddPropertyValue(model_name, dump_layers); | |||
| dump_properties.AddPropertyValue(model_name, dump_layers); | |||
| } | |||
| if (dump_op_switch == kDumpOn) { | |||
| GELOGI("Start to dump model and single op,dumo op switch is %s", dump_op_switch.c_str()); | |||
| GELOGI("Start to dump model and single op,dump op switch is %s", dump_op_switch.c_str()); | |||
| } else { | |||
| GELOGI("Only dump model,dump op switch is %s", dump_op_switch.c_str()); | |||
| } | |||
| } else { | |||
| GELOGI("Only dump single op,dumo op switch is %s", dump_op_switch.c_str()); | |||
| GELOGI("Only dump single op,dump op switch is %s", dump_op_switch.c_str()); | |||
| } | |||
| dump_path = dump_config.dump_path; | |||
| @@ -89,27 +91,39 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status DumpManager::SetDumpConf | |||
| } | |||
| dump_path = dump_path + CurrentTimeInStr() + "/"; | |||
| GELOGI("Dump path is %s", dump_path.c_str()); | |||
| dump_properties_.SetDumpPath(dump_path); | |||
| dump_properties.SetDumpPath(dump_path); | |||
| dump_mode = dump_config.dump_mode; | |||
| GELOGI("Dump mode is %s", dump_mode.c_str()); | |||
| dump_properties_.SetDumpMode(dump_mode); | |||
| dump_properties.SetDumpMode(dump_mode); | |||
| dump_properties_map_.emplace(kInferSessionId, dump_properties); | |||
| return SUCCESS; | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const DumpProperties &DumpManager::GetDumpProperties() { | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const DumpProperties &DumpManager::GetDumpProperties( | |||
| uint64_t session_id) { | |||
| std::lock_guard<std::mutex> lock(mutex_); | |||
| return dump_properties_; | |||
| auto iter = dump_properties_map_.find(session_id); | |||
| if (iter != dump_properties_map_.end()) { | |||
| return iter->second; | |||
| } | |||
| static DumpProperties default_properties; | |||
| return default_properties; | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpManager::SetModelName(const std::string &model_name) { | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpManager::AddDumpProperties( | |||
| uint64_t session_id, const DumpProperties &dump_properties) { | |||
| std::lock_guard<std::mutex> lock(mutex_); | |||
| model_name_ = model_name; | |||
| dump_properties_map_.emplace(session_id, dump_properties); | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpManager::GetModelName() { | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpManager::RemoveDumpProperties(uint64_t session_id) { | |||
| std::lock_guard<std::mutex> lock(mutex_); | |||
| return model_name_; | |||
| auto iter = dump_properties_map_.find(session_id); | |||
| if (iter != dump_properties_map_.end()) { | |||
| dump_properties_map_.erase(iter); | |||
| } | |||
| } | |||
| } // namespace ge | |||
| @@ -28,14 +28,14 @@ class DumpManager { | |||
| static DumpManager &GetInstance(); | |||
| Status SetDumpConf(const DumpConfig &dump_config); | |||
| const DumpProperties &GetDumpProperties(); | |||
| void SetModelName(const std::string &model_name); | |||
| const std::string &GetModelName(); | |||
| const DumpProperties &GetDumpProperties(uint64_t session_id); | |||
| const std::map<uint64_t, DumpProperties> &GetDumpPropertiesMap() { return dump_properties_map_; } | |||
| void AddDumpProperties(uint64_t session_id, const DumpProperties &dump_properties); | |||
| void RemoveDumpProperties(uint64_t session_id); | |||
| private: | |||
| DumpProperties dump_properties_; | |||
| std::mutex mutex_; | |||
| std::string model_name_; | |||
| std::map<uint64_t, DumpProperties> dump_properties_map_; | |||
| }; | |||
| } // namespace ge | |||
| #endif // GE_COMMON_DUMP_DUMP_MANAGER_H_ | |||
| @@ -219,9 +219,9 @@ Status DumpOp::LaunchDumpOp() { | |||
| op_mapping_info.set_dump_path(dump_path); | |||
| op_mapping_info.set_flag(kAicpuLoadFlag); | |||
| op_mapping_info.set_dump_step(dump_properties_.GetDumpStep()); | |||
| if (!dynamic_model_name_.empty()) { | |||
| op_mapping_info.set_model_id(dynamic_model_id_); | |||
| if (!dynamic_model_name_.empty() && dump_properties_.IsDumpOpen()) { | |||
| op_mapping_info.set_model_name(dynamic_model_name_); | |||
| op_mapping_info.set_model_id(dynamic_model_id_); | |||
| } | |||
| SetOpMappingLoopAddr(global_step_, loop_per_iter_, loop_cond_, op_mapping_info); | |||
| GELOGI("Dump step is %s ,dump path is %s ,in Launch dump op", dump_properties_.GetDumpStep().c_str(), | |||
| @@ -253,7 +253,7 @@ Status DumpOp::LaunchDumpOp() { | |||
| } | |||
| op_mapping_info.mutable_task()->Add(std::move(task)); | |||
| } | |||
| if (dump_properties_.GetDumpMode() == kDumpAll) { | |||
| if (dump_properties_.GetDumpMode() == kDumpAll || dump_properties_.IsOpDebugOpen()) { | |||
| auto ret = DumpOutput(task); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Dump output failed when in dumping all"); | |||
| @@ -122,6 +122,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::ClearDumpI | |||
| dump_path_.clear(); | |||
| dump_step_.clear(); | |||
| dump_mode_.clear(); | |||
| dump_op_switch_.clear(); | |||
| dump_status_.clear(); | |||
| is_op_debug_ = false; | |||
| op_debug_mode_ = 0; | |||
| } | |||
| @@ -201,7 +203,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::string &DumpProperti | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void DumpProperties::SetDumpOpSwitch( | |||
| const std::string dump_op_switch) { | |||
| const std::string &dump_op_switch) { | |||
| dump_op_switch_ = dump_op_switch; | |||
| } | |||
| @@ -230,6 +232,8 @@ void DumpProperties::CopyFrom(const DumpProperties &other) { | |||
| dump_path_ = other.dump_path_; | |||
| dump_step_ = other.dump_step_; | |||
| dump_mode_ = other.dump_mode_; | |||
| dump_status_ = other.dump_status_; | |||
| dump_op_switch_ = other.dump_op_switch_; | |||
| model_dump_properties_map_ = other.model_dump_properties_map_; | |||
| is_op_debug_ = other.is_op_debug_; | |||
| @@ -65,7 +65,7 @@ class DumpProperties { | |||
| const std::string &GetDumpStatus() const; | |||
| void SetDumpOpSwitch(const std::string dump_op_switch); | |||
| void SetDumpOpSwitch(const std::string &dump_op_switch); | |||
| const std::string &GetDumpOpSwitch() const; | |||
| @@ -81,11 +81,11 @@ class DumpProperties { | |||
| const std::string &GetEnableDumpDebug() const {return enable_dump_debug_;} | |||
| private: | |||
| void CopyFrom(const DumpProperties &other); | |||
| void SetDumpDebugOptions(); | |||
| std::string enable_dump_; | |||
| std::string enable_dump_debug_; | |||
| @@ -0,0 +1,148 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "opdebug_register.h" | |||
| namespace { | |||
| const size_t kOpDebugMemorySize = 2048UL; | |||
| const size_t kDebugP2pSize = 8UL; | |||
| } // namespace | |||
| namespace ge { | |||
| OpdebugRegister::~OpdebugRegister() {} | |||
| Status OpdebugRegister::RegisterDebugForModel(rtModel_t model_handle, uint32_t op_debug_mode, DataDumper &data_dumper) { | |||
| GELOGD("Start to register debug for model in overflow"); | |||
| auto ret = MallocMemForOpdebug(); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Malloc memory for opdebug in model overflow failed ,ret:0x%X", ret); | |||
| return ret; | |||
| } | |||
| uint32_t debug_stream_id = 0; | |||
| uint32_t debug_task_id = 0; | |||
| auto rt_ret = rtDebugRegister(model_handle, op_debug_mode, op_debug_addr_, &debug_stream_id, &debug_task_id); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "rtDebugRegister error, ret: 0x%X", rt_ret); | |||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
| } | |||
| GELOGD("debug_task_id:%u, debug_stream_id:%u in model overflow", debug_task_id, debug_stream_id); | |||
| data_dumper.SaveOpDebugId(debug_task_id, debug_stream_id, p2p_debug_addr_, true); | |||
| return SUCCESS; | |||
| } | |||
| void OpdebugRegister::UnregisterDebugForModel(rtModel_t model_handle) { | |||
| rtError_t rt_ret = RT_ERROR_NONE; | |||
| if (model_handle != nullptr) { | |||
| GELOGD("start to call rtDebugUnRegister in model overflow."); | |||
| rt_ret = rtDebugUnRegister(model_handle); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGW("rtDebugUnRegister failed, ret: 0x%X", rt_ret); | |||
| } | |||
| } | |||
| if (op_debug_addr_ != nullptr) { | |||
| rt_ret = rtFree(op_debug_addr_); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGW("rtFree failed, ret: 0x%X", rt_ret); | |||
| } | |||
| op_debug_addr_ = nullptr; | |||
| } | |||
| if (p2p_debug_addr_ != nullptr) { | |||
| rt_ret = rtFree(p2p_debug_addr_); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGW("rtFree failed, ret: 0x%X", rt_ret); | |||
| } | |||
| p2p_debug_addr_ = nullptr; | |||
| } | |||
| return; | |||
| } | |||
| Status OpdebugRegister::RegisterDebugForStream(rtStream_t stream, uint32_t op_debug_mode, DataDumper &data_dumper) { | |||
| GELOGD("Start to register debug for stream in stream overflow"); | |||
| auto ret = MallocMemForOpdebug(); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Malloc memory for opdebug in stream overflow ,ret:0x%X", ret); | |||
| return ret; | |||
| } | |||
| uint32_t debug_stream_id = 0; | |||
| uint32_t debug_task_id = 0; | |||
| #ifdef ONLY_COMPILE_OPEN_SRC | |||
| auto rt_ret = rtDebugRegisterForStream(stream, op_debug_mode, op_debug_addr_, &debug_stream_id, &debug_task_id); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "rtDebugRegisterForStream error, ret: 0x%X", rt_ret); | |||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
| } | |||
| #endif | |||
| GELOGD("debug_task_id:%u, debug_stream_id:%u in stream overflow.", debug_task_id, debug_stream_id); | |||
| data_dumper.SaveOpDebugId(debug_task_id, debug_stream_id, p2p_debug_addr_, true); | |||
| return SUCCESS; | |||
| } | |||
| void OpdebugRegister::UnregisterDebugForStream(rtStream_t stream) { | |||
| rtError_t rt_ret = RT_ERROR_NONE; | |||
| #ifdef ONLY_COMPILE_OPEN_SRC | |||
| if (stream != nullptr) { | |||
| GELOGD("start call rtDebugUnRegisterForStream in unknown shape over flow."); | |||
| rt_ret = rtDebugUnRegisterForStream(stream); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGW("rtDebugUnRegisterForStream failed, ret: 0x%X", rt_ret); | |||
| } | |||
| } | |||
| #endif | |||
| if (op_debug_addr_ != nullptr) { | |||
| rt_ret = rtFree(op_debug_addr_); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGW("rtFree failed, ret: 0x%X", rt_ret); | |||
| } | |||
| op_debug_addr_ = nullptr; | |||
| } | |||
| if (p2p_debug_addr_ != nullptr) { | |||
| rt_ret = rtFree(p2p_debug_addr_); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGW("rtFree failed, ret: 0x%X", rt_ret); | |||
| } | |||
| p2p_debug_addr_ = nullptr; | |||
| } | |||
| return; | |||
| } | |||
| Status OpdebugRegister::MallocMemForOpdebug() { | |||
| rtError_t rt_ret = rtMalloc(&op_debug_addr_, kOpDebugMemorySize, RT_MEMORY_DDR); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "rtMalloc error, ret: 0x%X", rt_ret); | |||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
| } | |||
| uint64_t debug_addrs_tmp = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(op_debug_addr_)); | |||
| // For data dump, aicpu needs the pointer to pointer that save the real debug address. | |||
| rt_ret = rtMalloc(&p2p_debug_addr_, kDebugP2pSize, RT_MEMORY_HBM); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "rtMalloc error, ret: 0x%X", rt_ret); | |||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
| } | |||
| rt_ret = rtMemcpy(p2p_debug_addr_, sizeof(uint64_t), &debug_addrs_tmp, sizeof(uint64_t), RT_MEMCPY_HOST_TO_DEVICE); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "rtMemcpy to p2p_addr error: 0x%X", rt_ret); | |||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| } // namespace ge | |||
| @@ -0,0 +1,44 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GE_COMMON_DUMP_OPDEBUG_REGISTER_H_ | |||
| #define GE_COMMON_DUMP_OPDEBUG_REGISTER_H_ | |||
| #include <map> | |||
| #include "common/debug/ge_log.h" | |||
| #include "common/debug/log.h" | |||
| #include "graph/load/model_manager/data_dumper.h" | |||
| namespace ge { | |||
| class OpdebugRegister { | |||
| public: | |||
| OpdebugRegister() = default; | |||
| ~OpdebugRegister(); | |||
| Status RegisterDebugForModel(rtModel_t model_handle, uint32_t op_debug_mode, DataDumper &data_dumper); | |||
| void UnregisterDebugForModel(rtModel_t model_handle); | |||
| Status RegisterDebugForStream(rtStream_t stream, uint32_t op_debug_mode, DataDumper &data_dumper); | |||
| void UnregisterDebugForStream(rtStream_t stream); | |||
| private: | |||
| Status MallocMemForOpdebug(); | |||
| void *op_debug_addr_ = nullptr; | |||
| void *p2p_debug_addr_ = nullptr; | |||
| }; | |||
| } // namespace ge | |||
| #endif // GE_COMMON_DUMP_OPDEBUG_REGISTER_H_ | |||
| @@ -111,7 +111,7 @@ Status CastKernel(const CastArgs &args, uint8_t *dst, const size_t data_size, co | |||
| }; | |||
| auto it = transfer_handle.find(trans_mode); | |||
| if (it == transfer_handle.end()) { | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } else { | |||
| return (it->second)(args, dst, data_size); | |||
| } | |||
| @@ -127,8 +127,8 @@ Status DataTypeTransfer::TransDataType(const CastArgs &args, TransResult &result | |||
| std::string error = "Failed to trans data from datatype " + | |||
| FmtToStr(TypeUtils::DataTypeToSerialString(args.src_data_type)) + " to " + | |||
| FmtToStr(TypeUtils::DataTypeToSerialString(args.dst_data_type)) + " , it is not supported."; | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_DATATYPE_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| auto trans_mode = iter->second; | |||
| @@ -136,14 +136,14 @@ Status DataTypeTransfer::TransDataType(const CastArgs &args, TransResult &result | |||
| if (size <= 0) { | |||
| std::string error = "Failed to calc size from data type" + | |||
| FmtToStr(TypeUtils::DataTypeToSerialString(args.dst_data_type)) + ", it is not supported."; | |||
| GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
| return PARAM_INVALID; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_DATATYPE_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (args.src_data_size > static_cast<size_t>(SIZE_MAX / size)) { | |||
| std::string error = "args.src_data_size" + FmtToStr(args.src_data_size) + | |||
| " or data type size" + FmtToStr(size) + " is too big"; | |||
| GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
| return PARAM_INVALID; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_PARAM_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| size_t total_size = static_cast<size_t>(args.src_data_size * size); | |||
| result.length = total_size; | |||
| @@ -154,8 +154,8 @@ Status DataTypeTransfer::TransDataType(const CastArgs &args, TransResult &result | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[total_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to alloc the memory for dst buf %zu, data size %zu", total_size, args.src_data_size); | |||
| return OUT_OF_MEMORY; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to alloc the memory for dst buf %zu, data size %zu", total_size, args.src_data_size); | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| if (CastKernel(args, dst.get(), args.src_data_size, trans_mode) != SUCCESS) { | |||
| @@ -163,8 +163,8 @@ Status DataTypeTransfer::TransDataType(const CastArgs &args, TransResult &result | |||
| FmtToStr(TypeUtils::DataTypeToSerialString(args.src_data_type)) + " to " + | |||
| FmtToStr(TypeUtils::DataTypeToSerialString(args.dst_data_type)) + ", data size is " + | |||
| FmtToStr(std::to_string(args.src_data_size)); | |||
| GE_ERRORLOG_AND_ERRORMSG(INTERNAL_ERROR, error.c_str()); | |||
| return INTERNAL_ERROR; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_INTERNAL_ERROR, error.c_str()); | |||
| return ACL_ERROR_GE_INTERNAL_ERROR; | |||
| } | |||
| result.data = dst; | |||
| return SUCCESS; | |||
| @@ -39,22 +39,22 @@ Status CheckArgsForC1hwncoc0ToHwcn(const TransArgs &args) { | |||
| std::string error = "Dose not support trans format from " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| if (!CheckDataTypeSupported(args.src_data_type)) { | |||
| std::string error = "Failed to trans shape from NC1HWNCoC0 to HWCN, invalid data type" + | |||
| FmtToStr(TypeUtils::DataTypeToSerialString(args.src_data_type)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_DATATYPE_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(src_shape, kC1hwncoc0DimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check src shape %s", ShapeToString(src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check src shape %s", ShapeToString(src_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(dst_shape, kHwcnDimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s.", ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| auto cube_size = GetCubeSizeByDataType(args.src_data_type); | |||
| if (src_shape.at(kC1hwncoc0C1) != (dst_shape.at(kHwcnC) - 1) / cube_size + 1 || | |||
| @@ -63,8 +63,8 @@ Status CheckArgsForC1hwncoc0ToHwcn(const TransArgs &args) { | |||
| src_shape.at(kC1hwncoc0C0) != cube_size) { | |||
| std::string error = "Failed to check relationship between src and dst shape, src shape" + | |||
| FmtToStr(ShapeToString(src_shape)) + ", dst shape" + FmtToStr(ShapeToString(dst_shape)); | |||
| GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
| return PARAM_INVALID; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_SHAPE_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| @@ -73,10 +73,10 @@ Status CheckArgsForC1hwncoc0ToHwcn(const TransArgs &args) { | |||
| Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, int size, int64_t total_size) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[total_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), total_size, ShapeToString(args.dst_shape).c_str()); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| auto h = args.src_shape.at(kC1hwncoc0H); | |||
| @@ -114,12 +114,12 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, int size | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to copy data from C1HWNCoC0[%ld, %ld, %ld, %ld, %ld, %ld] offset %ld to " | |||
| "HWCN[%ld, %ld, %ld, %ld] offset %ld, err-code %d", | |||
| c1_idx, h_idx, w_idx, n_idx, co_idx, c0_idx, src_offset, h_idx, w_idx, c_idx, n_idx, dst_offset, | |||
| ret); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -132,8 +132,9 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, int size | |||
| } // namespace | |||
| Status FormatTransferC1hwncoc0Hwcn::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (CheckArgsForC1hwncoc0ToHwcn(args) != SUCCESS) { | |||
| return PARAM_INVALID; | |||
| Status ret = CheckArgsForC1hwncoc0ToHwcn(args); | |||
| if (ret != SUCCESS) { | |||
| return ret; | |||
| } | |||
| int size = GetSizeByDataType(args.src_data_type); | |||
| int64_t total_size = GetItemNumByShape(args.dst_shape) * size; | |||
| @@ -143,26 +144,27 @@ Status FormatTransferC1hwncoc0Hwcn::TransFormat(const TransArgs &args, TransResu | |||
| result.length = static_cast<size_t>(total_size); | |||
| return SUCCESS; | |||
| } | |||
| GELOGE(INTERNAL_ERROR, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Get %ld total size from dst shape %s, src shape %s.", total_size, | |||
| ShapeToString(args.dst_shape).c_str(), ShapeToString(args.src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| GELOGD("Begin to trans format from C1HWNCoC0 to HWCN, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| GELOGD("Begin to trans format from C1HWNCoC0 to HWCN, src shape %s, data type %s, dst shape %s, memory size %ld.", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| if (GetDstDataAfterTrans(args, result, size, total_size) != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ret = GetDstDataAfterTrans(args, result, size, total_size); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| return INTERNAL_ERROR; | |||
| return ret; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| Status FormatTransferC1hwncoc0Hwcn::TransShape(Format src_format, const std::vector<int64_t> &src_shape, | |||
| DataType data_type, Format dst_format, std::vector<int64_t> &dst_shape) { | |||
| GELOGD("The shape derivation from C1HWNCoC0 to HWCN is not unique. Trans shape in this direction is not supported"); | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| GELOGD("The shape derivation from C1HWNCoC0 to HWCN is not unique. Trans shape in this direction is not supported."); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| REGISTER_FORMAT_TRANSFER(FormatTransferC1hwncoc0Hwcn, FORMAT_C1HWNCoC0, FORMAT_HWCN) | |||
| @@ -32,7 +32,7 @@ Status TransShapeToFz(int64_t d, int64_t n, int64_t c, int64_t h, int64_t w, Dat | |||
| std::vector<int64_t> &dst_shape) { | |||
| auto c0 = GetCubeSizeByDataType(data_type); | |||
| if (c0 < 0) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| auto c1 = Ceil(c, c0); | |||
| @@ -50,7 +50,7 @@ Status TransShapeToFz(int64_t d, int64_t n, int64_t c, int64_t h, int64_t w, Dat | |||
| Status TransShapeDhwckToFz3D(const std::vector<int64_t> &src_shape, DataType data_type, | |||
| std::vector<int64_t> &dst_shape) { | |||
| if (!CheckShapeValid(src_shape, kDhwcnDimsNum)) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| auto d = src_shape.at(kDhwcnD); | |||
| auto h = src_shape.at(kDhwcnH); | |||
| @@ -62,7 +62,7 @@ Status TransShapeDhwckToFz3D(const std::vector<int64_t> &src_shape, DataType dat | |||
| } | |||
| Status TransFormatDhwckToFz3D(const TransArgs &args, TransResult &result) { | |||
| if (!CheckShapeValid(args.src_shape, kDhwcnDimsNum)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| int64_t d = args.src_shape[kDhwcnD]; | |||
| int64_t h = args.src_shape[kDhwcnH]; | |||
| @@ -94,10 +94,10 @@ Status TransFormatDhwckToFz3D(const TransArgs &args, TransResult &result) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[dst_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| for (int64_t di = 0; di < d; di++) { | |||
| @@ -122,9 +122,9 @@ Status TransFormatDhwckToFz3D(const TransArgs &args, TransResult &result) { | |||
| args.data + src_idx * data_size, static_cast<size_t>(data_size)); | |||
| } | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d, pad mode %d", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d, pad mode %d", | |||
| dst_offset, ret, pad_zero); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -149,28 +149,28 @@ Status FormatTransferDhwcnFractalZ3D::TransFormat(const TransArgs &args, TransRe | |||
| return ret; | |||
| } | |||
| if (!IsTransShapeDstCorrect(args, expect_shape)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| if (args.src_format == FORMAT_DHWCN && args.dst_format == FORMAT_FRACTAL_Z_3D) { | |||
| return TransFormatDhwckToFz3D(args, result); | |||
| } | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| Status FormatTransferDhwcnFractalZ3D::TransShape(Format src_format, const std::vector<int64_t> &src_shape, | |||
| DataType data_type, Format dst_format, | |||
| std::vector<int64_t> &dst_shape) { | |||
| if (CheckDataTypeSupport(data_type) != SUCCESS) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (src_format == FORMAT_DHWCN && dst_format == FORMAT_FRACTAL_Z_3D) { | |||
| return TransShapeDhwckToFz3D(src_shape, data_type, dst_shape); | |||
| } | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| REGISTER_FORMAT_TRANSFER(FormatTransferDhwcnFractalZ3D, FORMAT_DHWCN, FORMAT_FRACTAL_Z_3D) | |||
| @@ -32,7 +32,7 @@ Status TransShapeToFz(int64_t d, int64_t n, int64_t c, int64_t h, int64_t w, Dat | |||
| std::vector<int64_t> &dst_shape) { | |||
| auto c0 = GetCubeSizeByDataType(data_type); | |||
| if (c0 < 0) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| auto c1 = Ceil(c, c0); | |||
| @@ -50,7 +50,7 @@ Status TransShapeToFz(int64_t d, int64_t n, int64_t c, int64_t h, int64_t w, Dat | |||
| Status TransShapeDhwncToFz3DTranspose(const std::vector<int64_t> &src_shape, DataType data_type, | |||
| std::vector<int64_t> &dst_shape) { | |||
| if (!CheckShapeValid(src_shape, kDhwncDimsNum)) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| auto d = src_shape.at(kDhwncD); | |||
| auto h = src_shape.at(kDhwncH); | |||
| @@ -62,7 +62,7 @@ Status TransShapeDhwncToFz3DTranspose(const std::vector<int64_t> &src_shape, Dat | |||
| } | |||
| Status TransFormatDhwncToFz3DTranspose(const TransArgs &args, TransResult &result) { | |||
| if (!CheckShapeValid(args.src_shape, kDhwncDimsNum)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| int64_t d = args.src_shape[kDhwncD]; | |||
| int64_t h = args.src_shape[kDhwncH]; | |||
| @@ -95,10 +95,10 @@ Status TransFormatDhwncToFz3DTranspose(const TransArgs &args, TransResult &resul | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[dst_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| for (int64_t di = 0; di < d; di++) { | |||
| @@ -123,9 +123,9 @@ Status TransFormatDhwncToFz3DTranspose(const TransArgs &args, TransResult &resul | |||
| args.data + src_idx * data_size, static_cast<size_t>(data_size)); | |||
| } | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d, pad mode %d", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d, pad mode %d", | |||
| dst_offset, ret, pad_zero); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -150,28 +150,28 @@ Status FormatTransferDhwncFractalZ3DTranspose::TransFormat(const TransArgs &args | |||
| return ret; | |||
| } | |||
| if (!IsTransShapeDstCorrect(args, expect_shape)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| if (args.src_format == ge::FORMAT_DHWNC && args.dst_format == ge::FORMAT_FRACTAL_Z_3D_TRANSPOSE) { | |||
| return TransFormatDhwncToFz3DTranspose(args, result); | |||
| } | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| Status FormatTransferDhwncFractalZ3DTranspose::TransShape(Format src_format, const std::vector<int64_t> &src_shape, | |||
| DataType data_type, Format dst_format, | |||
| std::vector<int64_t> &dst_shape) { | |||
| if (CheckDataTypeSupport(data_type) != SUCCESS) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (src_format == FORMAT_DHWNC && dst_format == FORMAT_FRACTAL_Z_3D_TRANSPOSE) { | |||
| return TransShapeDhwncToFz3DTranspose(src_shape, data_type, dst_shape); | |||
| } | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| REGISTER_FORMAT_TRANSFER(FormatTransferDhwncFractalZ3DTranspose, FORMAT_DHWNC, FORMAT_FRACTAL_Z_3D_TRANSPOSE) | |||
| @@ -87,8 +87,8 @@ Status TransShapeToFracNz(const ShapeVector &src_shape, DataType data_type, Shap | |||
| hw_shape.push_back(DIM_DEFAULT_VALUE); | |||
| hw_shape.push_back(src_shape[kNdDimIndexN]); | |||
| if (!IsShapeValid(dst_shape)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| default: | |||
| @@ -106,8 +106,8 @@ Status TransShapeToFracNz(const ShapeVector &src_shape, DataType data_type, Shap | |||
| hw_shape.push_back(src_shape[size - kNdDimCountBackwardsWH]); | |||
| hw_shape.push_back(src_shape[size - kNdDimCountBackwardsW]); | |||
| if (!IsShapeValid(dst_shape)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -117,14 +117,14 @@ Status CheckShapeRelation(const TransArgs &args, ShapeVector &hw_shape) { | |||
| ShapeVector expect_src_shape; | |||
| auto ret = TransShapeToFracNz(args.dst_shape, args.src_data_type, expect_src_shape, hw_shape); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Trans shape from %s to %s, shape %s to %s, data type %s failed", | |||
| GELOGE(ret, "Trans shape from %s to %s, shape %s to %s, data type %s failed", | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), ShapeToString(args.dst_shape).c_str(), | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return INTERNAL_ERROR; | |||
| return ret; | |||
| } | |||
| if (!IsTransShapeSrcCorrect(args, expect_src_shape)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -139,10 +139,10 @@ Status TransFormatFromNdToFracNz(const TransArgs &args, TransResult &result, con | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[dst_size](), std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| // src&dst_shape can be written as times*H*W & times*W1*H1*H0*W0, respectively. dst_shape_size >= kDimNum4D | |||
| @@ -175,8 +175,8 @@ Status TransFormatFromNdToFracNz(const TransArgs &args, TransResult &result, con | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size * w0)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| auto w1_head = num_w1 * w0; | |||
| @@ -189,8 +189,8 @@ Status TransFormatFromNdToFracNz(const TransArgs &args, TransResult &result, con | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -210,10 +210,10 @@ Status TransFormatFromFracNzToNd(const TransArgs &args, TransResult &result, con | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[dst_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| auto times = dst_hw_shape.at(kNdDimIndexN); | |||
| @@ -246,8 +246,8 @@ Status TransFormatFromFracNzToNd(const TransArgs &args, TransResult &result, con | |||
| ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size * w0)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| auto w1_head = num_w1 * w0; | |||
| @@ -260,8 +260,8 @@ Status TransFormatFromFracNzToNd(const TransArgs &args, TransResult &result, con | |||
| ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -273,13 +273,19 @@ Status TransFormatFromFracNzToNd(const TransArgs &args, TransResult &result, con | |||
| } // namespace | |||
| Status FormatTransferFractalNz::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (!IsDataTypeSupport(args.src_data_type) || !CheckShape(args.src_format, args.src_shape) || | |||
| !IsShapeValid(args.dst_shape)) { | |||
| GELOGE(PARAM_INVALID, "Trans format from %s to %s, src shape %s, dst shape %s, data type %s is not supported", | |||
| if (!IsDataTypeSupport(args.src_data_type)) { | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Trans format from %s to %s, src shape %s, dst shape %s, data type %s is not supported", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), ShapeToString(args.src_shape).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShape(args.src_format, args.src_shape) || !IsShapeValid(args.dst_shape)) { | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Trans format from %s to %s, src shape %s, dst shape %s, data type %s is not supported", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), ShapeToString(args.src_shape).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| GELOGD("Begin to trans format from %s to %s, src shape %s, dst shape %s, data type %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| @@ -292,7 +298,7 @@ Status FormatTransferFractalNz::TransFormat(const TransArgs &args, TransResult & | |||
| return ret; | |||
| } | |||
| if (!IsTransShapeDstCorrect(args, expect_shape)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return TransFormatFromNdToFracNz(args, result, hw_shape); | |||
| } | |||
| @@ -300,31 +306,38 @@ Status FormatTransferFractalNz::TransFormat(const TransArgs &args, TransResult & | |||
| Status FormatTransferFractalNz::TransShape(Format src_format, const ShapeVector &src_shape, DataType data_type, | |||
| Format dst_format, ShapeVector &dst_shape) { | |||
| if (!IsDataTypeSupport(data_type)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID, | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, | |||
| "Trans format from %s to %s, src shape %s, data type %s is not supported", | |||
| TypeUtils::FormatToSerialString(src_format).c_str(), TypeUtils::FormatToSerialString(dst_format).c_str(), | |||
| ShapeToString(src_shape).c_str(), TypeUtils::DataTypeToSerialString(data_type).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShape(src_format, src_shape)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, | |||
| "Trans format from %s to %s, src shape %s, data type %s is not supported", | |||
| TypeUtils::FormatToSerialString(src_format).c_str(), TypeUtils::FormatToSerialString(dst_format).c_str(), | |||
| ShapeToString(src_shape).c_str(), TypeUtils::DataTypeToSerialString(data_type).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| ShapeVector hw_shape; | |||
| return TransShapeToFracNz(src_shape, data_type, dst_shape, hw_shape); | |||
| } | |||
| Status FormatTransferFractalNzND::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (!IsDataTypeSupport(args.src_data_type) || !IsShapeValid(args.src_shape) || | |||
| !CheckShape(args.dst_format, args.dst_shape)) { | |||
| GELOGE(PARAM_INVALID, "Trans format from %s to %s, src shape %s, dst shape %s, data type %s is not supported", | |||
| if (!IsDataTypeSupport(args.src_data_type)) { | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Trans format from %s to %s, src shape %s, dst shape %s, data type %s is not supported", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), ShapeToString(args.src_shape).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!IsShapeValid(args.src_shape) || !CheckShape(args.dst_format, args.dst_shape)) { | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Trans format from %s to %s, src shape %s, dst shape %s, data type %s is not supported", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), ShapeToString(args.src_shape).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| GELOGD("Begin to trans format from %s to %s, src shape %s, dst shape %s, data type %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| @@ -332,8 +345,9 @@ Status FormatTransferFractalNzND::TransFormat(const TransArgs &args, TransResult | |||
| ShapeToString(args.dst_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| ShapeVector hw_shape; | |||
| if (CheckShapeRelation(args, hw_shape) != SUCCESS) { | |||
| return PARAM_INVALID; | |||
| Status ret = CheckShapeRelation(args, hw_shape); | |||
| if (ret != SUCCESS) { | |||
| return ret; | |||
| } | |||
| return TransFormatFromFracNzToNd(args, result, hw_shape); | |||
| } | |||
| @@ -342,7 +356,7 @@ Status FormatTransferFractalNzND::TransShape(Format src_format, const ShapeVecto | |||
| Format dst_format, ShapeVector &dst_shape) { | |||
| GELOGD("The shape derivation from %s to %s is not unique. Trans shape is not supported", | |||
| TypeUtils::FormatToSerialString(src_format).c_str(), TypeUtils::FormatToSerialString(dst_format).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| REGISTER_FORMAT_TRANSFER(FormatTransferFractalNz, FORMAT_ND, FORMAT_FRACTAL_NZ) | |||
| @@ -42,7 +42,7 @@ Status CheckDataTypeSupport(DataType data_type) { return GetSizeByDataType(data_ | |||
| Status TransShapeToFz(int64_t n, int64_t c, int64_t h, int64_t w, DataType data_type, std::vector<int64_t> &dst_shape) { | |||
| auto c0 = GetCubeSizeByDataType(data_type); | |||
| if (c0 < 0) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| auto c1 = Ceil(c, c0); | |||
| @@ -54,16 +54,16 @@ Status TransShapeToFz(int64_t n, int64_t c, int64_t h, int64_t w, DataType data_ | |||
| dst_shape.push_back(kNiSize); | |||
| dst_shape.push_back(c0); | |||
| if (!IsShapeValid(dst_shape)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| Status TransShapeNchwToFz(const std::vector<int64_t> &src_shape, DataType data_type, std::vector<int64_t> &dst_shape) { | |||
| if (!CheckShapeValid(src_shape, kNchwDimsNum)) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| auto n = src_shape.at(kNchwN); | |||
| @@ -75,7 +75,7 @@ Status TransShapeNchwToFz(const std::vector<int64_t> &src_shape, DataType data_t | |||
| Status TransShapeHwcnToFz(const std::vector<int64_t> &src_shape, DataType data_type, std::vector<int64_t> &dst_shape) { | |||
| if (!CheckShapeValid(src_shape, kHwcnDimsNum)) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| auto h = src_shape.at(kHwcnH); | |||
| @@ -88,7 +88,7 @@ Status TransShapeHwcnToFz(const std::vector<int64_t> &src_shape, DataType data_t | |||
| Status TransShapeNhwcToFz(const std::vector<int64_t> &src_shape, DataType data_type, std::vector<int64_t> &dst_shape) { | |||
| if (!CheckShapeValid(src_shape, kNhwcDimsNum)) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| auto n = src_shape.at(kNhwcN); | |||
| @@ -127,10 +127,10 @@ Status TransFormatFromNchwToFz(const TransArgs &args, TransResult &result) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[dst_size], std::default_delete<uint8_t[]>()); | |||
| GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( | |||
| dst == nullptr, | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY;); | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION;); | |||
| for (int64_t vfi = 0; vfi < vf_cnt; vfi++) { | |||
| // vertical fractal matrix base index | |||
| @@ -163,8 +163,8 @@ Status TransFormatFromNchwToFz(const TransArgs &args, TransResult &result) { | |||
| if (protected_size < size) { | |||
| std::string error = "Failed to operate the dst memory, protected_size is " + | |||
| FmtToStr(protected_size) + " and size is " + FmtToStr(size); | |||
| GE_ERRORLOG_AND_ERRORMSG(INTERNAL_ERROR, error.c_str()); | |||
| return INTERNAL_ERROR; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_PARAM_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| char *dst_data = reinterpret_cast<char *>(dst.get() + offset); | |||
| const char *src_data = reinterpret_cast<const char *>(args.data + src_offset * size); | |||
| @@ -173,9 +173,9 @@ Status TransFormatFromNchwToFz(const TransArgs &args, TransResult &result) { | |||
| } | |||
| } | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d pad mode %d", offset, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d pad mode %d", offset, | |||
| ret, need_pad_zero); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -213,10 +213,10 @@ Status TransFormatHwcnToFz(const TransArgs &args, TransResult &result) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[dst_size], std::default_delete<uint8_t[]>()); | |||
| GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( | |||
| dst == nullptr, | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY;); | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION;); | |||
| for (int64_t c1i = 0; c1i < c1; c1i++) { | |||
| for (int64_t hi = 0; hi < h; hi++) { | |||
| @@ -235,9 +235,9 @@ Status TransFormatHwcnToFz(const TransArgs &args, TransResult &result) { | |||
| static_cast<size_t>(data_size)); | |||
| } else { | |||
| if (protected_size < data_size) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory, protected_size is %ld and size is %ld", | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Failed to operate the dst memory, protected_size is %ld and size is %ld", | |||
| protected_size, data_size); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| int64_t src_idx = hi * wcn + wi * cn + (c1i * c0 + c0i) * n + n1n0i; | |||
| char *dst_data = reinterpret_cast<char *>(dst.get() + dst_offset); | |||
| @@ -247,9 +247,9 @@ Status TransFormatHwcnToFz(const TransArgs &args, TransResult &result) { | |||
| } | |||
| } | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d, pad mode %d", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d, pad mode %d", | |||
| dst_offset, ret, pad_zero); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -288,10 +288,10 @@ Status TransFormatNhwcToFz(const TransArgs &args, TransResult &result) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[dst_size], std::default_delete<uint8_t[]>()); | |||
| GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( | |||
| dst == nullptr, | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY;); | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION;); | |||
| for (int64_t c1i = 0; c1i < c1; c1i++) { | |||
| for (int64_t hi = 0; hi < h; hi++) { | |||
| @@ -310,9 +310,9 @@ Status TransFormatNhwcToFz(const TransArgs &args, TransResult &result) { | |||
| static_cast<size_t>(data_size)); | |||
| } else { | |||
| if (protected_size < data_size) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory, protected_size is %ld and size is %ld", | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Failed to operate the dst memory, protected_size is %ld and size is %ld", | |||
| protected_size, data_size); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| int64_t src_idx = n1n0i * hwc + hi * wc + wi * c + (c1i * c0 + c0i); | |||
| char *dst_data = reinterpret_cast<char *>(dst.get() + dst_offset); | |||
| @@ -322,9 +322,9 @@ Status TransFormatNhwcToFz(const TransArgs &args, TransResult &result) { | |||
| } | |||
| } | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d, pad mode %d", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d, pad mode %d", | |||
| dst_offset, ret, pad_zero); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -349,7 +349,7 @@ Status FormatTransferFractalZ::TransFormat(const TransArgs &args, TransResult &r | |||
| return ret; | |||
| } | |||
| if (!IsTransShapeDstCorrect(args, expect_shape)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| if (args.src_format == FORMAT_NHWC && args.dst_format == FORMAT_FRACTAL_Z) { | |||
| @@ -364,13 +364,13 @@ Status FormatTransferFractalZ::TransFormat(const TransArgs &args, TransResult &r | |||
| return TransFormatFromNchwToFz(args, result); | |||
| } | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| Status FormatTransferFractalZ::TransShape(Format src_format, const std::vector<int64_t> &src_shape, DataType data_type, | |||
| Format dst_format, std::vector<int64_t> &dst_shape) { | |||
| if (CheckDataTypeSupport(data_type) != SUCCESS) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (src_format == FORMAT_NHWC && dst_format == FORMAT_FRACTAL_Z) { | |||
| @@ -383,7 +383,7 @@ Status FormatTransferFractalZ::TransShape(Format src_format, const std::vector<i | |||
| return TransShapeNchwToFz(src_shape, data_type, dst_shape); | |||
| } | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| REGISTER_FORMAT_TRANSFER(FormatTransferFractalZ, FORMAT_NCHW, FORMAT_FRACTAL_Z) | |||
| @@ -86,9 +86,9 @@ Status TransShapeToFracZz(const ShapeVector &src_shape, DataType data_type, Shap | |||
| hw_shape.push_back(DIM_DEFAULT_VALUE); | |||
| hw_shape.push_back(src_shape[kNdDimIndexN]); | |||
| if (!IsShapeValid(dst_shape)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| default: | |||
| @@ -106,9 +106,9 @@ Status TransShapeToFracZz(const ShapeVector &src_shape, DataType data_type, Shap | |||
| hw_shape.push_back(src_shape[size - kNdDimCountBackwardsWH]); | |||
| hw_shape.push_back(src_shape[size - kNdDimCountBackwardsW]); | |||
| if (!IsShapeValid(dst_shape)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -118,14 +118,14 @@ Status CheckShapeRelation(const TransArgs &args, ShapeVector &hw_shape) { | |||
| ShapeVector expect_src_shape; | |||
| auto ret = TransShapeToFracZz(args.dst_shape, args.src_data_type, expect_src_shape, hw_shape); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Trans shape from %s to %s, shape %s to %s, data type %s failed", | |||
| GELOGE(ret, "Trans shape from %s to %s, shape %s to %s, data type %s failed", | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), ShapeToString(args.dst_shape).c_str(), | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return INTERNAL_ERROR; | |||
| return ret; | |||
| } | |||
| if (!IsTransShapeSrcCorrect(args, expect_src_shape)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -140,10 +140,10 @@ Status TransFormatFromNdToFracZz(const TransArgs &args, TransResult &result, con | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[dst_size](), std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| // The src&dst_shape can be written as times*H*W & times*H1*W1*H0*W0, respectively. dst_shape_size >= kDimNum4D | |||
| auto times = hw_shape.at(kNdDimIndexN); | |||
| @@ -179,8 +179,8 @@ Status TransFormatFromNdToFracZz(const TransArgs &args, TransResult &result, con | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size * w0)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| auto w1_head = num_w1 * w0; | |||
| @@ -195,8 +195,8 @@ Status TransFormatFromNdToFracZz(const TransArgs &args, TransResult &result, con | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -217,10 +217,10 @@ Status TransFormatFromFracZzToNd(const TransArgs &args, TransResult &result, con | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[dst_size](), std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| // The src&dst_shape can be written as times*H*W & times*H1*W1*H0*W0, respectively. dst_shape_size >= kDimNum4D | |||
| @@ -257,8 +257,8 @@ Status TransFormatFromFracZzToNd(const TransArgs &args, TransResult &result, con | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size * w0)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| auto w1_head = num_w1 * w0; | |||
| @@ -273,8 +273,8 @@ Status TransFormatFromFracZzToNd(const TransArgs &args, TransResult &result, con | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "Failed to operate the dst memory at offset %ld, error-code %d", dst_offset, ret); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -287,13 +287,19 @@ Status TransFormatFromFracZzToNd(const TransArgs &args, TransResult &result, con | |||
| } // namespace | |||
| Status FormatTransferFractalZz::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (!IsDataTypeSupport(args.src_data_type) || !CheckShape(args.src_format, args.src_shape) || | |||
| !IsShapeValid(args.dst_shape)) { | |||
| GELOGE(PARAM_INVALID, "Not support trans format from %s to %s, src shape %s, dst shape %s, data type %s", | |||
| if (!IsDataTypeSupport(args.src_data_type)) { | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Not support trans format from %s to %s, src shape %s, dst shape %s, data type %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), ShapeToString(args.src_shape).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShape(args.src_format, args.src_shape) || !IsShapeValid(args.dst_shape)) { | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Not support trans format from %s to %s, src shape %s, dst shape %s, data type %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), ShapeToString(args.src_shape).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| GELOGD("Begin to trans format from %s to %s, src shape %s, dst shape %s, data type %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| @@ -306,7 +312,7 @@ Status FormatTransferFractalZz::TransFormat(const TransArgs &args, TransResult & | |||
| return ret; | |||
| } | |||
| if (!IsTransShapeDstCorrect(args, expect_shape)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return TransFormatFromNdToFracZz(args, result, hw_shape); | |||
| } | |||
| @@ -314,31 +320,38 @@ Status FormatTransferFractalZz::TransFormat(const TransArgs &args, TransResult & | |||
| Status FormatTransferFractalZz::TransShape(Format src_format, const ShapeVector &src_shape, DataType data_type, | |||
| Format dst_format, ShapeVector &dst_shape) { | |||
| if (!IsDataTypeSupport(data_type)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID, | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, | |||
| "Not support trans format from %s to %s, src shape %s, data type %s", | |||
| TypeUtils::FormatToSerialString(src_format).c_str(), TypeUtils::FormatToSerialString(dst_format).c_str(), | |||
| ShapeToString(src_shape).c_str(), TypeUtils::DataTypeToSerialString(data_type).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShape(src_format, src_shape)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, | |||
| "Not support trans format from %s to %s, src shape %s, data type %s", | |||
| TypeUtils::FormatToSerialString(src_format).c_str(), TypeUtils::FormatToSerialString(dst_format).c_str(), | |||
| ShapeToString(src_shape).c_str(), TypeUtils::DataTypeToSerialString(data_type).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| ShapeVector hw_shape; | |||
| return TransShapeToFracZz(src_shape, data_type, dst_shape, hw_shape); | |||
| } | |||
| Status FormatTransferFractalZzND::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (!IsDataTypeSupport(args.src_data_type) || !IsShapeValid(args.src_shape) || | |||
| !CheckShape(args.dst_format, args.dst_shape)) { | |||
| GELOGE(PARAM_INVALID, "Not support trans format from %s to %s, src shape %s, dst shape %s, data type %s", | |||
| if (!IsDataTypeSupport(args.src_data_type)) { | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Not support trans format from %s to %s, src shape %s, dst shape %s, data type %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), ShapeToString(args.src_shape).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!IsShapeValid(args.src_shape) || !CheckShape(args.dst_format, args.dst_shape)) { | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Not support trans format from %s to %s, src shape %s, dst shape %s, data type %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), ShapeToString(args.src_shape).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| GELOGD("Begin to trans format from %s to %s, src shape %s, dst shape %s, data type %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| @@ -346,8 +359,9 @@ Status FormatTransferFractalZzND::TransFormat(const TransArgs &args, TransResult | |||
| ShapeToString(args.dst_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| ShapeVector hw_shape; | |||
| if (CheckShapeRelation(args, hw_shape) != SUCCESS) { | |||
| return PARAM_INVALID; | |||
| Status ret = CheckShapeRelation(args, hw_shape); | |||
| if (ret != SUCCESS) { | |||
| return ret; | |||
| } | |||
| return TransFormatFromFracZzToNd(args, result, hw_shape); | |||
| } | |||
| @@ -356,7 +370,7 @@ Status FormatTransferFractalZzND::TransShape(Format src_format, const ShapeVecto | |||
| Format dst_format, ShapeVector &dst_shape) { | |||
| GELOGD("The shape derivation from %s to %s is not unique. Trans shape is not supported", | |||
| TypeUtils::FormatToSerialString(src_format).c_str(), TypeUtils::FormatToSerialString(dst_format).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| REGISTER_FORMAT_TRANSFER(FormatTransferFractalZz, FORMAT_ND, FORMAT_FRACTAL_ZZ) | |||
| @@ -37,25 +37,25 @@ Status CheckArgsForFracZToHwcn(const TransArgs &args) { | |||
| std::string error = "Dose not support trans format from " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| if (!CheckDataTypeSupported(args.src_data_type)) { | |||
| GELOGE(UNSUPPORTED, "Failed to trans shape from FORMAT_FRACTAL_Z to HWCN, invalid data type %s", | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Failed to trans shape from FORMAT_FRACTAL_Z to HWCN, invalid data type %s", | |||
| TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(src_shape, kFracZDimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check src shape %s", ShapeToString(src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check src shape %s", ShapeToString(src_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(dst_shape, kHwcnDimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| int64_t c0 = GetCubeSizeByDataType(args.src_data_type); | |||
| if (c0 < 0) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| int64_t c1 = Ceil(dst_shape.at(kHwcnC), c0); | |||
| int64_t n0 = Ceil(dst_shape.at(kHwcnN), static_cast<int64_t>(kNiSize)); | |||
| @@ -64,8 +64,8 @@ Status CheckArgsForFracZToHwcn(const TransArgs &args) { | |||
| std::string error = "Failed to check relationship between src shape" + | |||
| FmtToStr(ShapeToString(src_shape)) + " and dst shape" + | |||
| FmtToStr(ShapeToString(dst_shape)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return PARAM_INVALID; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_SHAPE_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| @@ -74,10 +74,10 @@ Status CheckArgsForFracZToHwcn(const TransArgs &args) { | |||
| Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const int size, const int64_t total_size) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[total_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), total_size, ShapeToString(args.dst_shape).c_str()); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| auto n0 = args.src_shape.at(kFracZN0); | |||
| @@ -113,11 +113,11 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to copy data from FracZ offset %ld to HWCN[%ld, %ld, %ld, %ld] " | |||
| "offset %ld, err-code %d", | |||
| src_offset, h_idx, w_idx, c_idx, n_idx, dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -130,8 +130,9 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| } // namespace | |||
| Status FormatTransferFracZHwcn::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (CheckArgsForFracZToHwcn(args) != SUCCESS) { | |||
| return PARAM_INVALID; | |||
| Status ret = CheckArgsForFracZToHwcn(args); | |||
| if (ret != SUCCESS) { | |||
| return ret; | |||
| } | |||
| int size = GetSizeByDataType(args.src_data_type); | |||
| auto total_size = GetItemNumByShape(args.dst_shape) * size; | |||
| @@ -142,18 +143,19 @@ Status FormatTransferFracZHwcn::TransFormat(const TransArgs &args, TransResult & | |||
| return SUCCESS; | |||
| } | |||
| GELOGE(INTERNAL_ERROR, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| ShapeToString(args.dst_shape).c_str(), ShapeToString(args.src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| GELOGD("Begin to trans format from FracZ to HWCN, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| if (GetDstDataAfterTrans(args, result, size, total_size) != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ret = GetDstDataAfterTrans(args, result, size, total_size); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| return INTERNAL_ERROR; | |||
| return ret; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -161,7 +163,7 @@ Status FormatTransferFracZHwcn::TransFormat(const TransArgs &args, TransResult & | |||
| Status FormatTransferFracZHwcn::TransShape(Format src_format, const std::vector<int64_t> &src_shape, DataType data_type, | |||
| Format dst_format, std::vector<int64_t> &dst_shape) { | |||
| GELOGD("The shape derivation from FracZ to HWCN is not unique. Trans shape in this direction is not supported"); | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| REGISTER_FORMAT_TRANSFER(FormatTransferFracZHwcn, FORMAT_FRACTAL_Z, FORMAT_HWCN) | |||
| @@ -38,32 +38,32 @@ Status CheckArgsForFracZToNchw(const TransArgs &args) { | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| if (!CheckDataTypeSupported(args.src_data_type)) { | |||
| GELOGE(UNSUPPORTED, "Failed to trans shape from FORMAT_FRACTAL_Z to NCHW, invalid data type %s", | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Failed to trans shape from FORMAT_FRACTAL_Z to NCHW, invalid data type %s", | |||
| TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(src_shape, kFracZDimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check src shape %s", ShapeToString(src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check src shape %s", ShapeToString(src_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(dst_shape, kNchwDimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| int64_t c0 = GetCubeSizeByDataType(args.src_data_type); | |||
| if (c0 < 0) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| int64_t c1 = Ceil(dst_shape.at(kNchwC), c0); | |||
| int64_t n0 = Ceil(dst_shape.at(kNchwN), static_cast<int64_t>(kNiSize)); | |||
| if (src_shape.at(kFracZHWC1) != dst_shape.at(kNchwH) * dst_shape.at(kNchwW) * c1 || src_shape.at(kFracZC0) != c0 || | |||
| src_shape.at(kFracZNi) != kNiSize || src_shape.at(kFracZN0) != n0) { | |||
| GELOGE(PARAM_INVALID, "Failed to check relationship between src and dst shape, src shape %s, dst shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check relationship between src and dst shape, src shape %s, dst shape %s", | |||
| ShapeToString(src_shape).c_str(), ShapeToString(dst_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| @@ -72,10 +72,10 @@ Status CheckArgsForFracZToNchw(const TransArgs &args) { | |||
| Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const int size, const int64_t total_size) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[total_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), total_size, ShapeToString(args.dst_shape).c_str()); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| auto n0 = args.src_shape.at(kFracZN0); | |||
| @@ -111,11 +111,11 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to copy data from FracZ offset %ld to NCHW[%ld, %ld, %ld, %ld] offset %ld, " | |||
| "err-code %d", | |||
| src_offset, n_idx, c_idx, h_idx, w_idx, dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -128,8 +128,9 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| } // namespace | |||
| Status FormatTransferFracZNchw::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (CheckArgsForFracZToNchw(args) != SUCCESS) { | |||
| return PARAM_INVALID; | |||
| Status ret = CheckArgsForFracZToNchw(args); | |||
| if (ret != SUCCESS) { | |||
| return ret; | |||
| } | |||
| int size = GetSizeByDataType(args.src_data_type); | |||
| auto total_size = GetItemNumByShape(args.dst_shape) * size; | |||
| @@ -140,19 +141,20 @@ Status FormatTransferFracZNchw::TransFormat(const TransArgs &args, TransResult & | |||
| return SUCCESS; | |||
| } | |||
| GELOGE(INTERNAL_ERROR, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| ShapeToString(args.dst_shape).c_str(), ShapeToString(args.src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| GELOGD("Begin to trans format from FracZ to NCHW, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| if (GetDstDataAfterTrans(args, result, size, total_size) != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ret = GetDstDataAfterTrans(args, result, size, total_size); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| return INTERNAL_ERROR; | |||
| return ret; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -160,7 +162,7 @@ Status FormatTransferFracZNchw::TransFormat(const TransArgs &args, TransResult & | |||
| Status FormatTransferFracZNchw::TransShape(Format src_format, const std::vector<int64_t> &src_shape, DataType data_type, | |||
| Format dst_format, std::vector<int64_t> &dst_shape) { | |||
| GELOGD("The shape derivation from FracZ to NCHW is not unique. Trans shape in this direction is not supported"); | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| REGISTER_FORMAT_TRANSFER(FormatTransferFracZNchw, FORMAT_FRACTAL_Z, FORMAT_NCHW) | |||
| @@ -43,9 +43,9 @@ Status TransShapeHwcnToC1hwncoc0(const DataType &data_type, const std::vector<in | |||
| dst_shape.push_back(cube_size); | |||
| dst_shape.push_back(cube_size); | |||
| if (!CheckShapeValid(dst_shape, kC1hwncoc0DimsNum)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -55,21 +55,21 @@ Status CheckArgsForHwcnToC1hwncoc0(const TransArgs &args) { | |||
| std::string error = "Dose not support trans format from " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| if (!CheckDataTypeSupported(args.src_data_type)) { | |||
| GELOGE(UNSUPPORTED, "Failed to trans shape from HWCN to C1HWNCoC0, invalid data type %s", | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Failed to trans shape from HWCN to C1HWNCoC0, invalid data type %s", | |||
| TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(args.src_shape, kHwcnDimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check src shape %s", ShapeToString(args.src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check src shape %s", ShapeToString(args.src_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(args.dst_shape, kC1hwncoc0DimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check dst shape %s", ShapeToString(args.dst_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", ShapeToString(args.dst_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| std::vector<int64_t> expect_dst_shape; | |||
| auto ret = TransShapeHwcnToC1hwncoc0(args.src_data_type, args.src_shape, expect_dst_shape); | |||
| @@ -77,12 +77,12 @@ Status CheckArgsForHwcnToC1hwncoc0(const TransArgs &args) { | |||
| return ret; | |||
| } | |||
| if (args.dst_shape != expect_dst_shape) { | |||
| GELOGE(PARAM_INVALID, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, | |||
| "Failed to trans format, src and dst shape are not compatible. src shape %s, dst shape %s, " | |||
| "expect dst shape %s", | |||
| ShapeToString(args.src_shape).c_str(), ShapeToString(args.dst_shape).c_str(), | |||
| ShapeToString(expect_dst_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| @@ -91,10 +91,10 @@ Status CheckArgsForHwcnToC1hwncoc0(const TransArgs &args) { | |||
| Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const int size, const int64_t total_size) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[total_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), total_size, ShapeToString(args.dst_shape).c_str()); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| auto h = args.src_shape.at(kHwcnH); | |||
| @@ -135,22 +135,22 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to copy data from HWCN[%ld, %ld, %ld, %ld] offset %ld to " | |||
| "C1HWNCoC0[%ld, %ld, %ld, %ld, %ld, %ld] offset %ld, err-code %d", | |||
| h_idx, w_idx, c_idx, n_idx, src_offset, c1_idx, h_idx, w_idx, n_idx, co_idx, c0_idx, | |||
| dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } else { | |||
| auto ret = | |||
| memset_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), 0, static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to set to 0 to C1HWNCoC0[%ld, %ld, %ld, %ld, %ld, %ld] offset %ld, " | |||
| "err-code %d", | |||
| c1_idx, h_idx, w_idx, n_idx, co_idx, c0_idx, dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -166,8 +166,9 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| } // namespace | |||
| Status FormatTransferHwcnC1hwncoc0::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (CheckArgsForHwcnToC1hwncoc0(args) != SUCCESS) { | |||
| return PARAM_INVALID; | |||
| Status ret = CheckArgsForHwcnToC1hwncoc0(args); | |||
| if (ret != SUCCESS) { | |||
| return ret; | |||
| } | |||
| int size = GetSizeByDataType(args.src_data_type); | |||
| auto total_size = GetItemNumByShape(args.dst_shape) * size; | |||
| @@ -178,18 +179,20 @@ Status FormatTransferHwcnC1hwncoc0::TransFormat(const TransArgs &args, TransResu | |||
| return SUCCESS; | |||
| } | |||
| GELOGE(INTERNAL_ERROR, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| ShapeToString(args.dst_shape).c_str(), ShapeToString(args.src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| GELOGD("Begin to trans format from HWCN to C1HWNCoC0, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| if (GetDstDataAfterTrans(args, result, size, total_size) != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ret = GetDstDataAfterTrans(args, result, size, total_size); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| return INTERNAL_ERROR; | |||
| return ret; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -198,15 +201,15 @@ Status FormatTransferHwcnC1hwncoc0::TransShape(Format src_format, const std::vec | |||
| DataType data_type, Format dst_format, std::vector<int64_t> &dst_shape) { | |||
| if (src_format == FORMAT_HWCN && CheckDataTypeSupported(data_type)) { | |||
| if (!CheckShapeValid(src_shape, kHwcnDimsNum)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check src shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check src shape %s", | |||
| ShapeToString(src_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return TransShapeHwcnToC1hwncoc0(data_type, src_shape, dst_shape); | |||
| } else if (src_format != FORMAT_HWCN) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } else { | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| } | |||
| @@ -37,33 +37,33 @@ Status CheckArgsForNc1hwc0ToNhwc(const TransArgs &args) { | |||
| std::string error = "Dose not support trans format from " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| if (!CheckDataTypeSupported(args.src_data_type)) { | |||
| GELOGE(UNSUPPORTED, "Failed to trans shape from NC1HWC0 to NHWC, invalid data type %s", | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Failed to trans shape from NC1HWC0 to NHWC, invalid data type %s", | |||
| TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(args.src_shape, kNc1hwc0DimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check src shape %s", ShapeToString(args.src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check src shape %s", ShapeToString(args.src_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(args.dst_shape, kNhwcDimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check dst shape %s", ShapeToString(args.dst_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", ShapeToString(args.dst_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| int64_t c0 = GetCubeSizeByDataType(args.src_data_type); | |||
| if (c0 <= 0) { | |||
| GELOGE(PARAM_INVALID, "Failed to get cube size, the data type is invalid"); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Failed to get cube size, the data type is invalid"); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (src_shape.at(kNc1hwc0H) != dst_shape.at(kNhwcH) || src_shape.at(kNc1hwc0W) != dst_shape.at(kNhwcW) || | |||
| src_shape.at(kNc1hwc0N) != dst_shape.at(kNhwcN) || src_shape.at(kNc1hwc0C0) != c0 || | |||
| src_shape.at(kNc1hwc0C1) != (Ceil(dst_shape.at(kNhwcC), c0))) { | |||
| GELOGE(PARAM_INVALID, "Failed to check relationship between src and dst shape, src shape %s, dst shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check relationship between src and dst shape, src shape %s, dst shape %s", | |||
| ShapeToString(src_shape).c_str(), ShapeToString(dst_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| @@ -72,10 +72,10 @@ Status CheckArgsForNc1hwc0ToNhwc(const TransArgs &args) { | |||
| Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const int size, const int64_t total_size) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[total_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), total_size, ShapeToString(args.dst_shape).c_str()); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| auto h = args.src_shape.at(kNc1hwc0H); | |||
| @@ -109,11 +109,11 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to copy data from NC1HWC0[%ld, %ld, %ld, %ld, %ld] offset %ld to NHWC[%ld, %ld, %ld, %ld]" | |||
| " offset %ld, err-code %d", | |||
| n_idx, c1_idx, h_idx, w_idx, c0_idx, src_offset, n_idx, c_idx, h_idx, w_idx, dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -126,8 +126,9 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| } // namespace | |||
| Status FormatTransferNc1hwc0Nhwc::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (CheckArgsForNc1hwc0ToNhwc(args) != SUCCESS) { | |||
| return PARAM_INVALID; | |||
| Status ret = CheckArgsForNc1hwc0ToNhwc(args); | |||
| if (ret != SUCCESS) { | |||
| return ret; | |||
| } | |||
| int size = GetSizeByDataType(args.src_data_type); | |||
| auto total_size = GetItemNumByShape(args.dst_shape) * size; | |||
| @@ -138,18 +139,20 @@ Status FormatTransferNc1hwc0Nhwc::TransFormat(const TransArgs &args, TransResult | |||
| return SUCCESS; | |||
| } | |||
| GELOGE(INTERNAL_ERROR, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| ShapeToString(args.dst_shape).c_str(), ShapeToString(args.src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| GELOGD("Begin to trans format from NC1HWC0 to NCHW, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| if (GetDstDataAfterTrans(args, result, size, total_size) != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ret = GetDstDataAfterTrans(args, result, size, total_size); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| return INTERNAL_ERROR; | |||
| return ret; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -157,7 +160,7 @@ Status FormatTransferNc1hwc0Nhwc::TransFormat(const TransArgs &args, TransResult | |||
| Status FormatTransferNc1hwc0Nhwc::TransShape(Format src_format, const std::vector<int64_t> &src_shape, | |||
| DataType data_type, Format dst_format, std::vector<int64_t> &dst_shape) { | |||
| GELOGD("The shape derivation from NC1HWC0 to NHWC is not unique. Trans shape in this direction is not supported"); | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| REGISTER_FORMAT_TRANSFER(FormatTransferNc1hwc0Nhwc, FORMAT_NC1HWC0, FORMAT_NHWC) | |||
| @@ -45,7 +45,7 @@ Status CheckDataTypeSupport(DataType data_type) { return GetSizeByDataType(data_ | |||
| Status TransShape(int64_t n, int64_t c, int64_t h, int64_t w, DataType data_type, std::vector<int64_t> &dst_shape) { | |||
| auto c0 = GetCubeSizeByDataType(data_type); | |||
| if (c0 < 0) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| auto chw = c * h * w; | |||
| @@ -59,9 +59,9 @@ Status TransShape(int64_t n, int64_t c, int64_t h, int64_t w, DataType data_type | |||
| dst_shape.push_back(c0); | |||
| if (!IsShapeValid(dst_shape)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -69,7 +69,7 @@ Status TransShape(int64_t n, int64_t c, int64_t h, int64_t w, DataType data_type | |||
| Status TransShapeNchwToFzC04(const std::vector<int64_t> &src_shape, DataType data_type, | |||
| std::vector<int64_t> &dst_shape) { | |||
| if (!CheckShapeValid(src_shape, kNchwDimsNum)) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| auto n = src_shape.at(kNchwN); | |||
| @@ -94,8 +94,8 @@ Status TransFormatFromNchwToFzC04(const TransArgs &args, TransResult &result) { | |||
| std::vector<int64_t> expect_shape = {n, h, w, c}; | |||
| auto ret = ge::formats::Transpose(data, args.src_shape, args.src_data_type, perm_arg_1, trans_result_1); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to Transpose from NCHW to HWCN"); | |||
| return NOT_CHANGED; | |||
| GELOGE(ret, "Failed to Transpose from NCHW to HWCN"); | |||
| return ret; | |||
| } | |||
| TransArgs args_tmp = args; | |||
| @@ -104,8 +104,8 @@ Status TransFormatFromNchwToFzC04(const TransArgs &args, TransResult &result) { | |||
| // check size it should be same with original | |||
| size_t expect_size = n * c * h * w * size; // before has do check about mul | |||
| if (trans_result_1.length != expect_size) { | |||
| GELOGE(INTERNAL_ERROR, "size is not match after transpose!"); | |||
| return NOT_CHANGED; | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, "size is not match after transpose!"); | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| // prepare for padding in chw | |||
| @@ -118,20 +118,20 @@ Status TransFormatFromNchwToFzC04(const TransArgs &args, TransResult &result) { | |||
| // data overflow check totally | |||
| GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(h_o, w_o), | |||
| GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", h_o, w_o); | |||
| return INTERNAL_ERROR); | |||
| GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", h_o, w_o); | |||
| return ACL_ERROR_GE_INTERNAL_ERROR); | |||
| GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(n_o, c_o), | |||
| GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", n_o, c_o); | |||
| return INTERNAL_ERROR); | |||
| GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", n_o, c_o); | |||
| return ACL_ERROR_GE_INTERNAL_ERROR); | |||
| auto t1 = h_o * w_o; | |||
| auto t2 = n_o * c_o; | |||
| GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(t1, t2), GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", t1, t2); | |||
| return INTERNAL_ERROR); | |||
| return ACL_ERROR_GE_INTERNAL_ERROR); | |||
| int64_t total_ele_cnt = n_o * c_o * h_o * w_o; | |||
| GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(total_ele_cnt, size), | |||
| GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%d]", total_ele_cnt, size); | |||
| return INTERNAL_ERROR); | |||
| GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%d]", total_ele_cnt, size); | |||
| return ACL_ERROR_GE_INTERNAL_ERROR); | |||
| int64_t dst_size = total_ele_cnt * size; | |||
| if (dst_size == 0) { | |||
| result.length = 0; | |||
| @@ -140,15 +140,15 @@ Status TransFormatFromNchwToFzC04(const TransArgs &args, TransResult &result) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[dst_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| auto retMem = memset_s(dst.get(), dst_size, 0, dst_size); | |||
| if (retMem != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "memst failed!"); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "memst failed!"); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| // copy data | |||
| auto block = c * h * w * size; | |||
| @@ -159,8 +159,8 @@ Status TransFormatFromNchwToFzC04(const TransArgs &args, TransResult &result) { | |||
| for (auto k = 0; k < n; k++) { | |||
| ret = memcpy_s(p_d + k * stride, protectSize, p_s + k * block, block); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "memcpy_s failed!"); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "memcpy_s failed!"); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| protectSize = protectSize - block; | |||
| } | |||
| @@ -169,8 +169,8 @@ Status TransFormatFromNchwToFzC04(const TransArgs &args, TransResult &result) { | |||
| std::vector<int64_t> perm_arg_2 = {2, 0, 1, 3}; | |||
| ret = ge::formats::Transpose(dst.get(), shape_o, args.src_data_type, perm_arg_2, result); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to Transpose from NCHW to HWCN"); | |||
| return NOT_CHANGED; | |||
| GELOGE(ret, "Failed to Transpose from NCHW to HWCN"); | |||
| return ret; | |||
| } | |||
| return SUCCESS; | |||
| @@ -180,7 +180,7 @@ Status PaddingNC(const TransArgs &args, TransArgs &args_tmp, std::shared_ptr<uin | |||
| args_tmp = args; | |||
| auto src_shape = args_tmp.src_shape; | |||
| if (!CheckShapeValid(src_shape, kNchwDimsNum)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| int64_t c0 = GetCubeSizeByDataType(args.src_data_type); | |||
| @@ -190,8 +190,8 @@ Status PaddingNC(const TransArgs &args, TransArgs &args_tmp, std::shared_ptr<uin | |||
| auto w = src_shape.at(kNchwW); | |||
| if (c > kMaxDimsNumC) { | |||
| GELOGE(PARAM_INVALID, "Invalie dim c num[%lu].It should be in (0,4]", c); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Invalie dim c num[%lu].It should be in (0,4]", c); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| auto n_o = Ceil(n, c0) * c0; | |||
| @@ -205,21 +205,21 @@ Status PaddingNC(const TransArgs &args, TransArgs &args_tmp, std::shared_ptr<uin | |||
| // data overflow check | |||
| GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(h_o, w_o), | |||
| GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", h_o, w_o); | |||
| return INTERNAL_ERROR); | |||
| GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", h_o, w_o); | |||
| return ACL_ERROR_GE_INTERNAL_ERROR); | |||
| GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(n_o, c_o), | |||
| GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", n_o, c_o); | |||
| return INTERNAL_ERROR); | |||
| GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", n_o, c_o); | |||
| return ACL_ERROR_GE_INTERNAL_ERROR); | |||
| auto t1 = h_o * w_o; | |||
| auto t2 = n_o * c_o; | |||
| GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(t1, t2), GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", t1, t2); | |||
| return INTERNAL_ERROR); | |||
| GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(t1, t2), GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", t1, t2); | |||
| return ACL_ERROR_GE_INTERNAL_ERROR); | |||
| int64_t total_ele_cnt = n_o * c_o * h_o * w_o; | |||
| int size = GetSizeByDataType(args.src_data_type); | |||
| GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(total_ele_cnt, size), | |||
| GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%d]", total_ele_cnt, size); | |||
| return INTERNAL_ERROR); | |||
| GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%d]", total_ele_cnt, size); | |||
| return ACL_ERROR_GE_INTERNAL_ERROR); | |||
| int64_t dst_size = total_ele_cnt * size; | |||
| if (dst_size == 0) { | |||
| @@ -228,15 +228,15 @@ Status PaddingNC(const TransArgs &args, TransArgs &args_tmp, std::shared_ptr<uin | |||
| dst.reset(new (std::nothrow) uint8_t[dst_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), dst_size); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| auto ret = memset_s(dst.get(), dst_size, 0, dst_size); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "memst failed!"); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "memst failed!"); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| auto p_s = args.data; | |||
| @@ -249,8 +249,8 @@ Status PaddingNC(const TransArgs &args, TransArgs &args_tmp, std::shared_ptr<uin | |||
| ret = memcpy_s(p_d + (i * c_o * h_o * w_o + j * h_o * w_o) * size, protectSize, | |||
| p_s + (i * c * h * w + j * h * w) * size, block); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, "memcpy_s failed!"); | |||
| return INTERNAL_ERROR; | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, "memcpy_s failed!"); | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| protectSize = protectSize - block; | |||
| } | |||
| @@ -270,7 +270,7 @@ Status FormatTransferNchwToFZC04::TransFormat(const TransArgs &args, TransResult | |||
| std::shared_ptr<uint8_t> dst = nullptr; | |||
| auto ret = PaddingNC(args, args_tmp, dst); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Padding in NC axis failed!"); | |||
| GELOGE(ret, "Padding in NC axis failed!"); | |||
| return ret; | |||
| } | |||
| @@ -281,26 +281,26 @@ Status FormatTransferNchwToFZC04::TransFormat(const TransArgs &args, TransResult | |||
| } | |||
| if (!IsTransShapeDstCorrect(args_tmp, expect_shape)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| if (args_tmp.src_format == FORMAT_NCHW && args_tmp.dst_format == FORMAT_FRACTAL_Z_C04) { | |||
| return TransFormatFromNchwToFzC04(args_tmp, result); | |||
| } | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| Status FormatTransferNchwToFZC04::TransShape(Format src_format, const std::vector<int64_t> &src_shape, | |||
| DataType data_type, Format dst_format, std::vector<int64_t> &dst_shape) { | |||
| if (CheckDataTypeSupport(data_type) != SUCCESS) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (src_format == FORMAT_NCHW && dst_format == FORMAT_FRACTAL_Z_C04) { | |||
| return TransShapeNchwToFzC04(src_shape, data_type, dst_shape); | |||
| } | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| REGISTER_FORMAT_TRANSFER(FormatTransferNchwToFZC04, FORMAT_NCHW, FORMAT_FRACTAL_Z_C04) | |||
| @@ -32,13 +32,13 @@ Status TransShapeNchwToNc1hwc0(const std::vector<int64_t> &src_shape, DataType d | |||
| std::vector<int64_t> &dst_shape) { | |||
| int64_t c0 = GetCubeSizeByDataType(data_type); | |||
| if (c0 <= 0) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID, "Failed to get cube size, the data type is invalid"); | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Failed to get cube size, the data type is invalid"); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(src_shape, kNchwDimsNum)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check src shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check src shape %s", | |||
| ShapeToString(src_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| dst_shape.clear(); | |||
| dst_shape.push_back(src_shape.at(kNchwN)); | |||
| @@ -47,9 +47,9 @@ Status TransShapeNchwToNc1hwc0(const std::vector<int64_t> &src_shape, DataType d | |||
| dst_shape.push_back(src_shape.at(kNchwW)); | |||
| dst_shape.push_back(c0); | |||
| if (!CheckShapeValid(dst_shape, kNc1hwc0DimsNum)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -59,8 +59,8 @@ Status CheckArgsForNchwToNc1hwc0(const TransArgs &args) { | |||
| std::string error = "Dose not support trans format from " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| std::vector<int64_t> expect_5d_shape; | |||
| auto ret = TransShapeNchwToNc1hwc0(args.src_shape, args.src_data_type, expect_5d_shape); | |||
| @@ -68,12 +68,12 @@ Status CheckArgsForNchwToNc1hwc0(const TransArgs &args) { | |||
| return ret; | |||
| } | |||
| if (expect_5d_shape != args.dst_shape) { | |||
| GELOGE(PARAM_INVALID, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, | |||
| "Failed to trans format, the src and dst shape are not compatible. data" | |||
| " type %s, src shape %s, dst shape %s, expect dst shape %s", | |||
| TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), ShapeToString(args.src_shape).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), ShapeToString(expect_5d_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| @@ -82,12 +82,12 @@ Status CheckArgsForNchwToNc1hwc0(const TransArgs &args) { | |||
| Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const int size, const int64_t total_size) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[total_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, | |||
| "Failed to trans format from %s to %s, can not alloc the memory for" | |||
| " dst buf %ld, shape %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), total_size, ShapeToString(args.dst_shape).c_str()); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| auto n = args.src_shape.at(kNchwN); | |||
| @@ -97,8 +97,8 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| int64_t c0 = GetCubeSizeByDataType(args.src_data_type); | |||
| if (c0 <= 0) { | |||
| GELOGE(INTERNAL_ERROR, "The c0 is invalid %ld", c0); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "The c0 is invalid %ld", c0); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| int64_t c1 = (c - 1) / c0 + 1; | |||
| int64_t hw = h * w; | |||
| @@ -129,21 +129,21 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
| static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to copy data from NCHW[%ld] offset %ld to " | |||
| "NC1HWC0[%ld, %ld, %ld, %ld, %ld] offset %ld, err-code %d", | |||
| srcIdx, src_offset, n_idx, c1_idx, h_idx, w_idx, c0_idx, dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } else { | |||
| auto ret = | |||
| memset_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), 0, static_cast<size_t>(size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to set to 0 to " | |||
| "NC1HWC0[%ld, %ld, %ld, %ld, %ld] offset %ld, err-code %d", | |||
| n_idx, c1_idx, h_idx, w_idx, c0_idx, dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -159,8 +159,9 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| } // namespace | |||
| Status FormatTransferNchwNc1hwc0::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (CheckArgsForNchwToNc1hwc0(args) != SUCCESS) { | |||
| return PARAM_INVALID; | |||
| Status ret = CheckArgsForNchwToNc1hwc0(args); | |||
| if (ret != SUCCESS) { | |||
| return ret; | |||
| } | |||
| // Guarantee the validity of parameters in check function | |||
| int size = GetSizeByDataType(args.src_data_type); | |||
| @@ -172,20 +173,21 @@ Status FormatTransferNchwNc1hwc0::TransFormat(const TransArgs &args, TransResult | |||
| return SUCCESS; | |||
| } | |||
| GELOGE(INTERNAL_ERROR, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| ShapeToString(args.dst_shape).c_str(), ShapeToString(args.src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| GELOGD( | |||
| "Begin to trans format from NCHW to NC1HWC0, src shape %s, data type " | |||
| "%s, dst shape %s memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| if (GetDstDataAfterTrans(args, result, size, total_size) != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ret = GetDstDataAfterTrans(args, result, size, total_size); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| return INTERNAL_ERROR; | |||
| return ret; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -195,7 +197,7 @@ Status FormatTransferNchwNc1hwc0::TransShape(Format src_format, const std::vecto | |||
| if (src_format == FORMAT_NCHW) { | |||
| return TransShapeNchwToNc1hwc0(src_shape, data_type, dst_shape); | |||
| } else { | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| } | |||
| @@ -34,8 +34,8 @@ Status TransShapeNhwcToNc1hwc0(const std::vector<int64_t> &src_shape, DataType d | |||
| std::vector<int64_t> &dst_shape) { | |||
| int64_t c0 = GetCubeSizeByDataType(data_type); | |||
| if (c0 <= 0) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID, "Failed to get cube size, the data type is invalid"); | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Failed to get cube size, the data type is invalid"); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| dst_shape.clear(); | |||
| dst_shape.push_back(src_shape.at(kNhwcN)); | |||
| @@ -44,9 +44,9 @@ Status TransShapeNhwcToNc1hwc0(const std::vector<int64_t> &src_shape, DataType d | |||
| dst_shape.push_back(src_shape.at(kNhwcW)); | |||
| dst_shape.push_back(c0); | |||
| if (!CheckShapeValid(dst_shape, kNc1hwc0DimsNum)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", | |||
| ShapeToString(dst_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -56,21 +56,21 @@ Status CheckArgsForNhwcToNc1hwc0(const TransArgs &args) { | |||
| std::string error = "Dose not support trans format from " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| if (!CheckDataTypeSupported(args.src_data_type)) { | |||
| GELOGE(UNSUPPORTED, "Failed to trans shape from NHWC to NC1HWC0, invalid data type %s", | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Failed to trans shape from NHWC to NC1HWC0, invalid data type %s", | |||
| TypeUtils::DataTypeToSerialString(args.src_data_type).c_str()); | |||
| return UNSUPPORTED; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(args.src_shape, kNhwcDimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check src shape %s", ShapeToString(args.src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check src shape %s", ShapeToString(args.src_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| if (!CheckShapeValid(args.dst_shape, kNc1hwc0DimsNum)) { | |||
| GELOGE(PARAM_INVALID, "Failed to check dst shape %s", ShapeToString(args.dst_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check dst shape %s", ShapeToString(args.dst_shape).c_str()); | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| std::vector<int64_t> expect_dst_shape; | |||
| auto ret = TransShapeNhwcToNc1hwc0(args.src_shape, args.src_data_type, expect_dst_shape); | |||
| @@ -78,12 +78,12 @@ Status CheckArgsForNhwcToNc1hwc0(const TransArgs &args) { | |||
| return ret; | |||
| } | |||
| if (args.dst_shape != expect_dst_shape) { | |||
| GELOGE(PARAM_INVALID, | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, | |||
| "Failed to trans format, the src and dst shape are not compatible. src shape %s, dst shape %s, " | |||
| "expect dst shape %s", | |||
| ShapeToString(args.src_shape).c_str(), ShapeToString(args.dst_shape).c_str(), | |||
| ShapeToString(expect_dst_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return SUCCESS; | |||
| @@ -92,10 +92,10 @@ Status CheckArgsForNhwcToNc1hwc0(const TransArgs &args) { | |||
| Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const int size, const int64_t total_size) { | |||
| std::shared_ptr<uint8_t> dst(new (std::nothrow) uint8_t[total_size], std::default_delete<uint8_t[]>()); | |||
| if (dst == nullptr) { | |||
| GELOGE(OUT_OF_MEMORY, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Failed to trans format from %s to %s, can not alloc the memory for dst buf %ld, shape %s", | |||
| TypeUtils::FormatToSerialString(args.src_format).c_str(), | |||
| TypeUtils::FormatToSerialString(args.dst_format).c_str(), total_size, ShapeToString(args.dst_shape).c_str()); | |||
| return OUT_OF_MEMORY; | |||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
| } | |||
| auto n = args.src_shape.at(kNhwcN); | |||
| @@ -131,19 +131,19 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| if (c_idx < c) { | |||
| auto ret = memcpy_s(dst.get() + dst_offset, protected_size, args.data + src_offset, size); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to copy data from NHWC[%ld, %ld, %ld, %ld] offset %ld to " | |||
| "NC1HWC0[%ld, %ld, %ld, %ld, %ld] offset %ld err-code %d", | |||
| n_idx, h_idx, w_idx, c_idx, src_offset, n_idx, c1_idx, h_idx, w_idx, c0_idx, dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } else { | |||
| auto ret = memset_s(dst.get() + dst_offset, protected_size, 0, size); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to set 0 to NC1HWC0[%ld, %ld, %ld, %ld, %ld] offset %ld base err-code %d", n_idx, c1_idx, | |||
| h_idx, w_idx, c0_idx, dst_offset, ret); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| } | |||
| } | |||
| @@ -158,8 +158,9 @@ Status GetDstDataAfterTrans(const TransArgs &args, TransResult &result, const in | |||
| } // namespace | |||
| Status FormatTransferNhwcNc1hwc0::TransFormat(const TransArgs &args, TransResult &result) { | |||
| if (CheckArgsForNhwcToNc1hwc0(args) != SUCCESS) { | |||
| return PARAM_INVALID; | |||
| Status ret = CheckArgsForNhwcToNc1hwc0(args); | |||
| if (ret != SUCCESS) { | |||
| return ret; | |||
| } | |||
| int size = GetSizeByDataType(args.src_data_type); | |||
| auto total_size = GetItemNumByShape(args.dst_shape) * size; | |||
| @@ -170,18 +171,20 @@ Status FormatTransferNhwcNc1hwc0::TransFormat(const TransArgs &args, TransResult | |||
| return SUCCESS; | |||
| } | |||
| GELOGE(INTERNAL_ERROR, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| GELOGE(ACL_ERROR_GE_DATATYPE_INVALID, "Get %ld total size from dst shape %s, src shape %s", total_size, | |||
| ShapeToString(args.dst_shape).c_str(), ShapeToString(args.src_shape).c_str()); | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| GELOGD("Begin to trans format from NHWC to NC1HWC0, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| if (GetDstDataAfterTrans(args, result, size, total_size) != SUCCESS) { | |||
| GELOGE(INTERNAL_ERROR, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ret = GetDstDataAfterTrans(args, result, size, total_size); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Failed to get data after trans, src shape %s, data type %s, dst shape %s, memory size %ld", | |||
| ShapeToString(args.src_shape).c_str(), TypeUtils::DataTypeToSerialString(args.src_data_type).c_str(), | |||
| ShapeToString(args.dst_shape).c_str(), total_size); | |||
| return INTERNAL_ERROR; | |||
| return ret; | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -190,15 +193,15 @@ Status FormatTransferNhwcNc1hwc0::TransShape(Format src_format, const std::vecto | |||
| DataType data_type, Format dst_format, std::vector<int64_t> &dst_shape) { | |||
| if (src_format == FORMAT_NHWC && CheckDataTypeSupported(data_type)) { | |||
| if (!CheckShapeValid(src_shape, kNhwcDimsNum)) { | |||
| GELOGE(ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID, "Failed to check src shape %s", | |||
| GELOGE(ACL_ERROR_GE_SHAPE_INVALID, "Failed to check src shape %s", | |||
| ShapeToString(src_shape).c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return TransShapeNhwcToNc1hwc0(src_shape, data_type, dst_shape); | |||
| } else if (src_format != FORMAT_NHWC) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } else { | |||
| return ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID; | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| } | |||
| @@ -141,7 +141,7 @@ std::vector<int64_t> TransShapeByPerm(const std::vector<int64_t> &src_shape, con | |||
| Status Transpose(const uint8_t *src, const std::vector<int64_t> &src_shape, DataType src_data_type, | |||
| const std::vector<int64_t> &perm_arg, TransResult &result) { | |||
| if (!IsTransposeArgValid(src, src_shape, src_data_type, perm_arg)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| auto dst_shape = TransShapeByPerm(src_shape, perm_arg); | |||
| @@ -172,12 +172,12 @@ Status Transpose(const uint8_t *src, const std::vector<int64_t> &src_shape, Data | |||
| auto ret = memcpy_s(dst.get() + dst_offset_bytes, static_cast<size_t>(protected_size), src + src_offset, | |||
| static_cast<size_t>(data_size)); | |||
| if (ret != EOK) { | |||
| GELOGE(INTERNAL_ERROR, | |||
| GELOGE(ACL_ERROR_GE_MEMORY_OPERATE_FAILED, | |||
| "Failed to transpose, src shape %s, perm arg %s, dst shape %s, " | |||
| "failed to write to dst offset %ld, current dim offset %s", | |||
| ShapeToString(src_shape).c_str(), ShapeToString(perm_arg).c_str(), ShapeToString(dst_shape).c_str(), | |||
| dst_offset_bytes, ShapeToString(dst_indexes).c_str()); | |||
| return INTERNAL_ERROR; | |||
| return ACL_ERROR_GE_MEMORY_OPERATE_FAILED; | |||
| } | |||
| AddOne(dst_shape, dst_indexes); | |||
| ++dst_index; | |||
| @@ -192,14 +192,14 @@ Status TransposeWithShapeCheck(const uint8_t *data, const std::vector<int64_t> & | |||
| const std::vector<int64_t> &dst_shape, DataType src_data_type, | |||
| const std::vector<int64_t> &perm_arg, TransResult &result) { | |||
| if (!IsTransposeArgValid(data, src_shape, src_data_type, perm_arg)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| auto expected_shape = TransShapeByPerm(src_shape, perm_arg); | |||
| if (dst_shape != expected_shape) { | |||
| std::string error = "Failed to trans axis for perm_arg" + | |||
| FmtToStr(ShapeToString(perm_arg)) + ", invalid dst shape" + | |||
| FmtToStr(ShapeToString(dst_shape)) + ", expect" + FmtToStr(ShapeToString(expected_shape)); | |||
| GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_SHAPE_INVALID, error.c_str()); | |||
| } | |||
| return Transpose(data, src_shape, src_data_type, perm_arg, result); | |||
| @@ -211,16 +211,16 @@ Status GetPermByForamt(Format src_format, Format dst_format, std::vector<int64_t | |||
| std::string error = "Failed to trans shape, do not support transpose from format " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| auto iter = dst_iter->second.find(dst_format); | |||
| if (iter == dst_iter->second.end()) { | |||
| std::string error = "Failed to trans shape, do not support transpose from format " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| perm = iter->second; | |||
| return SUCCESS; | |||
| @@ -233,7 +233,7 @@ Status FormatTransferTranspose::TransFormat(const TransArgs &args, TransResult & | |||
| return ret; | |||
| } | |||
| if (!IsTransShapeDstCorrect(args, expected_shape)) { | |||
| return PARAM_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| return Transpose(args.data, args.src_shape, args.src_data_type, perm_args[args.src_format][args.dst_format], result); | |||
| @@ -244,7 +244,7 @@ Status FormatTransferTranspose::TransShape(Format src_format, const std::vector< | |||
| std::vector<int64_t> perm_arg; | |||
| GE_CHK_STATUS_RET_NOLOG(GetPermByForamt(src_format, dst_format, perm_arg)); | |||
| if (!IsShapeArgValid(src_shape, perm_arg)) { | |||
| return ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID; | |||
| return ACL_ERROR_GE_SHAPE_INVALID; | |||
| } | |||
| dst_shape = TransShapeByPerm(src_shape, perm_arg); | |||
| return SUCCESS; | |||
| @@ -38,14 +38,14 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Status TransFormat(const TransArg | |||
| std::string error = "Failed to trans data from format " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| auto src_shape_size = GetItemNumByShape(args.src_shape); | |||
| if (args.data == nullptr && src_shape_size != 0) { | |||
| GELOGE(PARAM_INVALID, "Invalid input null data"); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Invalid input null data"); | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| return transfer->TransFormat(args, result); | |||
| @@ -64,8 +64,8 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Status TransShape(Format src_form | |||
| std::string error = "Failed to trans data from format " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.src_format)) + " to " + | |||
| FmtToStr(TypeUtils::FormatToSerialString(args.dst_format)); | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_FORMAT_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_FORMAT_INVALID; | |||
| } | |||
| return transfer->TransShape(src_format, src_shape, data_type, dst_format, dst_shape); | |||
| @@ -77,13 +77,13 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Status TransDataType(const CastAr | |||
| std::string error = "Failed to trans data from datatype " + | |||
| FmtToStr(TypeUtils::DataTypeToSerialString(args.src_data_type)) + " to " + | |||
| FmtToStr(TypeUtils::DataTypeToSerialString(args.dst_data_type)); | |||
| GE_ERRORLOG_AND_ERRORMSG(UNSUPPORTED, error.c_str()); | |||
| return UNSUPPORTED; | |||
| GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_DATATYPE_INVALID, error.c_str()); | |||
| return ACL_ERROR_GE_DATATYPE_INVALID; | |||
| } | |||
| if (args.data == nullptr && args.src_data_size != 0) { | |||
| GELOGE(PARAM_INVALID, "Invalid input null data"); | |||
| return PARAM_INVALID; | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Invalid input null data"); | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| return transfer->TransDataType(args, result); | |||
| @@ -53,6 +53,7 @@ string PluginManager::GetPath() { | |||
| GELOGW("Failed to read the shared library file path!"); | |||
| return string(); | |||
| } else { | |||
| GE_IF_BOOL_EXEC(dl_info.dli_fname == nullptr, return string()); | |||
| std::string so_path = dl_info.dli_fname; | |||
| char path[MMPA_MAX_PATH] = {0}; | |||
| if (so_path.length() >= MMPA_MAX_PATH) { | |||
| @@ -14,22 +14,15 @@ | |||
| * limitations under the License. | |||
| */ | |||
| #include <climits> | |||
| #include "common/helper/model_cache_helper.h" | |||
| #include <cstdio> | |||
| #include <fstream> | |||
| #include <functional> | |||
| #include "common/ge/ge_util.h" | |||
| #include "common/helper/model_cache_helper.h" | |||
| #include "common/types.h" | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "framework/common/ge_types.h" | |||
| #include "common/model_parser/model_parser.h" | |||
| #include "framework/common/helper/model_helper.h" | |||
| #include "framework/common/util.h" | |||
| #include "graph/detail/attributes_holder.h" | |||
| #include "graph/detail/model_serialize_imp.h" | |||
| #include "graph/load/model_manager/davinci_model_parser.h" | |||
| #include "graph/model.h" | |||
| #include "graph/utils/graph_utils.h" | |||
| #include "graph/utils/tensor_utils.h" | |||
| #include "init/gelib.h" | |||
| @@ -1682,7 +1675,7 @@ Status ModelCacheHelper::LoadOmModelFromCache(GeModelPtr &ge_model) const { | |||
| string key_path; | |||
| int32_t priority = 0; | |||
| ModelData model_data; | |||
| ret = DavinciModelParser::LoadFromFile(om_path.c_str(), key_path.c_str(), priority, model_data); | |||
| ret = ModelParserBase::LoadFromFile(om_path.c_str(), key_path.c_str(), priority, model_data); | |||
| if (ret != SUCCESS) { | |||
| GELOGW("LoadOmModelFromCache: Load model from file failed. ret = %u", ret); | |||
| return ret; | |||
| @@ -16,15 +16,10 @@ | |||
| #include "framework/common/helper/model_helper.h" | |||
| #include "common/ge/ge_util.h" | |||
| #include "common/util/error_manager/error_manager.h" | |||
| #include "framework/common/debug/log.h" | |||
| #include "framework/common/util.h" | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "common/model_parser/model_parser.h" | |||
| #include "framework/omg/model_tool.h" | |||
| #include "framework/omg/version.h" | |||
| #include "graph/debug/ge_attr_define.h" | |||
| #include "graph/load/model_manager/davinci_model_parser.h" | |||
| #include "graph/utils/attr_utils.h" | |||
| #include "graph/utils/graph_utils.h" | |||
| using std::string; | |||
| @@ -464,7 +459,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadModel(c | |||
| return ACL_ERROR_GE_EXEC_RELEASE_MODEL_DATA; | |||
| } | |||
| Status status = ge::DavinciModelParser::ParseModelContent(model_data, model_addr_tmp_, model_len_tmp_); | |||
| Status status = ModelParserBase::ParseModelContent(model_data, model_addr_tmp_, model_len_tmp_); | |||
| if (status != SUCCESS) { | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Parse model content failed!"); | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| @@ -513,7 +508,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadRootMod | |||
| return INTERNAL_ERROR; | |||
| } | |||
| Status status = ge::DavinciModelParser::ParseModelContent(model_data, model_addr_tmp_, model_len_tmp_); | |||
| Status status = ModelParserBase::ParseModelContent(model_data, model_addr_tmp_, model_len_tmp_); | |||
| if (status != SUCCESS) { | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Parse model content failed!"); | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| @@ -879,4 +874,97 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::GetModelNam | |||
| GE_CHK_BOOL_EXEC_WARN(!model_name.empty(), return FAILED, "Get model_name failed, check params --output"); | |||
| return SUCCESS; | |||
| } | |||
| Status ModelTool::GetModelInfoFromOm(const char *model_file, ge::proto::ModelDef &model_def, uint32_t &modeldef_size) { | |||
| GE_CHECK_NOTNULL(model_file); | |||
| ge::ModelData model; | |||
| int32_t priority = 0; | |||
| Status ret = ModelParserBase::LoadFromFile(model_file, "", priority, model); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "LoadFromFile failed."); | |||
| return ret; | |||
| } | |||
| std::function<void()> callback = [&]() { | |||
| if (model.model_data != nullptr) { | |||
| delete[] reinterpret_cast<char *>(model.model_data); | |||
| model.model_data = nullptr; | |||
| } | |||
| }; | |||
| GE_MAKE_GUARD(release, callback); | |||
| uint8_t *model_data = nullptr; | |||
| uint32_t model_len = 0; | |||
| ret = ModelParserBase::ParseModelContent(model, model_data, model_len); | |||
| if (ret != SUCCESS) { | |||
| ErrorManager::GetInstance().ATCReportErrMessage("E10003", | |||
| {"parameter", "value", "reason"}, {"om", model_file, "invalid om file"}); | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, | |||
| "ParseModelContent failed because of invalid om file. Please check --om param."); | |||
| return ret; | |||
| } | |||
| OmFileLoadHelper om_load_helper; | |||
| ret = om_load_helper.Init(model_data, model_len); | |||
| if (ret != SUCCESS) { | |||
| ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"Om file init failed"}); | |||
| GELOGE(ge::FAILED, "Om file init failed."); | |||
| return ret; | |||
| } | |||
| ModelPartition ir_part; | |||
| ret = om_load_helper.GetModelPartition(MODEL_DEF, ir_part); | |||
| if (ret != SUCCESS) { | |||
| ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"Get model part failed"}); | |||
| GELOGE(ge::FAILED, "Get model part failed."); | |||
| return ret; | |||
| } | |||
| bool flag = ReadProtoFromArray(ir_part.data, ir_part.size, &model_def); | |||
| if (!flag) { | |||
| ret = INTERNAL_ERROR; | |||
| ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"ReadProtoFromArray failed"}); | |||
| GELOGE(ret, "ReadProtoFromArray failed."); | |||
| return ret; | |||
| } | |||
| modeldef_size = ir_part.size; | |||
| return ret; | |||
| } | |||
| Status ModelTool::GetModelInfoFromPbtxt(const char *model_file, ge::proto::ModelDef &model_def) { | |||
| GE_CHECK_NOTNULL(model_file); | |||
| ge::ModelData model; | |||
| int32_t priority = 0; | |||
| Status ret = ModelParserBase::LoadFromFile(model_file, "", priority, model); | |||
| auto free_model_data = [](void **ptr) -> void { | |||
| if (ptr != nullptr && *ptr != nullptr) { | |||
| delete[] reinterpret_cast<char *>(*ptr); | |||
| *ptr = nullptr; | |||
| } | |||
| }; | |||
| if (ret != SUCCESS) { | |||
| free_model_data(&model.model_data); | |||
| GELOGE(ret, "LoadFromFile failed."); | |||
| return ret; | |||
| } | |||
| try { | |||
| bool flag = google::protobuf::TextFormat::ParseFromString(reinterpret_cast<char *>(model.model_data), &model_def); | |||
| if (!flag) { | |||
| free_model_data(&model.model_data); | |||
| ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"ParseFromString failed"}); | |||
| GELOGE(FAILED, "ParseFromString failed."); | |||
| return FAILED; | |||
| } | |||
| free_model_data(&model.model_data); | |||
| return SUCCESS; | |||
| } catch (google::protobuf::FatalException &e) { | |||
| free_model_data(&model.model_data); | |||
| ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"ParseFromString failed, exception message[" | |||
| + std::string(e.what()) + "]"}); | |||
| GELOGE(FAILED, "ParseFromString failed. exception message : %s", e.what()); | |||
| return FAILED; | |||
| } | |||
| } | |||
| } // namespace ge | |||
| @@ -165,7 +165,7 @@ Status OmFileLoadHelper::LoadModelPartitionTable(uint8_t *model_data, const uint | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| size_t mem_offset = SIZE_OF_MODEL_PARTITION_TABLE(*partition_table); | |||
| GELOGD("ModelPartitionTable num :%u, ModelFileHeader length :%zu, ModelPartitionTable length :%zu", | |||
| GELOGD("ModelPartitionTable num:%u, ModelFileHeader length:%zu, ModelPartitionTable length:%zu", | |||
| partition_table->num, sizeof(ModelFileHeader), mem_offset); | |||
| if (model_data_size <= mem_offset) { | |||
| GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "invalid model data, partition_table->num:%u, model data size %u", | |||
| @@ -207,7 +207,8 @@ Status OmFileLoadHelper::LoadModelPartitionTable(uint8_t *model_data, uint32_t m | |||
| "ModelFileHeader length :%zu, ModelPartitionTable length :%zu", | |||
| index, partition_table->num, sizeof(ModelFileHeader), partition_table_size); | |||
| if (model_data_size <= cur_offset) { | |||
| GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "invalid model data, partition_table->num:%u, model data size %u", | |||
| GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, | |||
| "invalid model data, partition_table->num:%u, model data size %u", | |||
| partition_table->num, model_data_size); | |||
| return ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID; | |||
| } | |||
| @@ -14,16 +14,13 @@ | |||
| * limitations under the License. | |||
| */ | |||
| #include "common/model_parser/base.h" | |||
| #include "common/helper/model_helper.h" | |||
| #include <securec.h> | |||
| #include "common/model_parser/model_parser.h" | |||
| #include <fstream> | |||
| #include <memory> | |||
| #include <string> | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "framework/common/debug/log.h" | |||
| #include "framework/common/util.h" | |||
| #include "securec.h" | |||
| #include "common/helper/model_helper.h" | |||
| namespace ge { | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelParserBase::ModelParserBase() {} | |||
| @@ -20,6 +20,8 @@ | |||
| #include "framework/common/debug/log.h" | |||
| #include "framework/common/string_util.h" | |||
| #include "graph/ge_context.h" | |||
| #include "graph/utils/type_utils.h" | |||
| #include "graph/types.h" | |||
| #include "runtime/base.h" | |||
| #include "graph/load/model_manager/davinci_model.h" | |||
| @@ -31,12 +33,30 @@ const char *const kBpPoint = "bp_point"; | |||
| #ifdef DAVINCI_SUPPORT_PROFILING | |||
| const size_t kReportMaxLen = 2048; | |||
| const int32_t kMaxDeviceNum = 256; | |||
| const uint32_t kInteval = 2; | |||
| const std::string kConfigNumsdev = "devNums"; | |||
| const std::string kConfigDevIdList = "devIdList"; | |||
| const std::string kProfStart = "prof_start"; | |||
| const std::string kProfStop = "prof_stop"; | |||
| const std::string kProfModelSubscribe = "prof_model_subscribe"; | |||
| const std::string kProfModelUnsubscribe = "prof_model_cancel_subscribe"; | |||
| const std::string kModelName = "model_name"; | |||
| const std::string kModelId = "model_id"; | |||
| const std::string kOpNmae = "op_name"; | |||
| const std::string kOptype = "op_type"; | |||
| const std::string kBlockDim = "block_dims"; | |||
| const std::string kTaskId = "task_id"; | |||
| const std::string kStreamId = "stream_id"; | |||
| const std::string kShapeType = "shape_type"; | |||
| const std::string kCurIterNum = "cur_iter_num"; | |||
| const std::string kTaskType = "task_type"; | |||
| const std::string kInput = "input"; | |||
| const std::string kOutput = "output"; | |||
| const std::string kFormat = "format"; | |||
| const std::string kDataType = "data_type"; | |||
| const std::string kShape = "shape"; | |||
| const std::string kIdx = "idx"; | |||
| #endif | |||
| } // namespace | |||
| @@ -206,118 +226,69 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::StopProf | |||
| #endif | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ProfilingTaskDescInfo( | |||
| uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, const int32_t &device_id) { | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ProfilingOpInputOutInfo( | |||
| const TaskDescInfo &task, Json &task_json) { | |||
| #ifdef DAVINCI_SUPPORT_PROFILING | |||
| std::string data; | |||
| for (const auto &task : task_desc_info) { | |||
| std::string model_name = task.model_name; | |||
| std::string op_name = task.op_name; | |||
| uint32_t block_dim = task.block_dim; | |||
| uint32_t task_id = task.task_id; | |||
| uint32_t stream_id = task.stream_id; | |||
| std::string shape_type = task.shape_type; | |||
| int64_t cur_iter_num = task.cur_iter_num; | |||
| uint32_t task_type = task.task_type; | |||
| data = model_name.append(" ") | |||
| .append(op_name).append(" ") | |||
| .append(std::to_string(block_dim)).append(" ") | |||
| .append(std::to_string(task_id)).append(" ") | |||
| .append(std::to_string(stream_id)).append(" ") | |||
| .append(std::to_string(model_id)).append(" ") | |||
| .append(shape_type).append(" ") | |||
| .append(std::to_string(cur_iter_num)).append(" ") | |||
| .append(std::to_string(task_type)).append("\n"); | |||
| ReporterData reporter_data{}; | |||
| reporter_data.deviceId = device_id; | |||
| reporter_data.data = (unsigned char *)data.c_str(); | |||
| reporter_data.dataLen = data.size(); | |||
| int ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, "task_desc_info", sizeof("task_desc_info")); | |||
| if (ret != EOK) { | |||
| GELOGE(ret, "Report data tag of task_desc_info memcpy error!"); | |||
| return; | |||
| } | |||
| int32_t cb_ret = CallMsprofReport(reporter_data); | |||
| if (cb_ret != 0) { | |||
| GELOGE(cb_ret, "Reporter data of task_desc_info failed, ret:%d", cb_ret); | |||
| return; | |||
| } | |||
| for (size_t i = 0; i < task.input_format.size(); i++) { | |||
| Json tmp_input; | |||
| tmp_input[kIdx] = i; | |||
| Format format = task.input_format[i]; | |||
| tmp_input[kFormat] = TypeUtils::FormatToSerialString(format); | |||
| DataType data_type = task.input_data_type[i]; | |||
| tmp_input[kDataType] = TypeUtils::DataTypeToSerialString(data_type); | |||
| tmp_input[kShape] = task.input_shape[i]; | |||
| task_json[kInput] += tmp_input; | |||
| } | |||
| for (size_t i = 0; i < task.output_format.size(); i++) { | |||
| Json tmp_output; | |||
| tmp_output[kIdx] = i; | |||
| Format format = task.output_format[i]; | |||
| tmp_output[kFormat] = TypeUtils::FormatToSerialString(format); | |||
| DataType data_type = task.output_data_type[i]; | |||
| tmp_output[kDataType] = TypeUtils::DataTypeToSerialString(data_type); | |||
| tmp_output[kShape] = task.output_shape[i]; | |||
| task_json[kOutput] += tmp_output; | |||
| } | |||
| data.clear(); | |||
| #endif | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ProfilingGraphDescInfo( | |||
| uint32_t model_id, const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info, const int32_t &device_id) { | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ProfilingTaskDescInfo( | |||
| uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, const int32_t &device_id) { | |||
| #ifdef DAVINCI_SUPPORT_PROFILING | |||
| std::string data; | |||
| for (const auto &graph : compute_graph_desc_info) { | |||
| data.append("model_name:") | |||
| .append(graph.model_name) | |||
| .append(" op_name:") | |||
| .append(graph.op_name) | |||
| .append(" op_type:") | |||
| .append(graph.op_type); | |||
| for (size_t i = 0; i < graph.input_format.size(); ++i) { | |||
| data.append(" input_id:") | |||
| .append(std::to_string(i)) | |||
| .append(" input_format:") | |||
| .append(std::to_string(graph.input_format.at(i))) | |||
| .append(" input_data_type:") | |||
| .append(std::to_string(graph.input_data_type.at(i))) | |||
| .append(" input_shape:\""); | |||
| size_t input_shape_len = graph.input_shape.at(i).size(); | |||
| if (input_shape_len == 0) { | |||
| data.append(""); | |||
| } else if (input_shape_len == 1) { | |||
| data.append(std::to_string(graph.input_shape.at(i).at(0))); | |||
| } else { | |||
| for (size_t j = 0; j < input_shape_len - 1; ++j) { | |||
| data.append(std::to_string(graph.input_shape.at(i).at(j))).append(","); | |||
| } | |||
| data.append(std::to_string(graph.input_shape.at(i).at(input_shape_len - 1))); | |||
| } | |||
| data.append("\""); | |||
| } | |||
| for (size_t i = 0; i < graph.output_format.size(); ++i) { | |||
| data.append(" output_id:") | |||
| .append(std::to_string(i)) | |||
| .append(" output_format:") | |||
| .append(std::to_string(graph.output_format.at(i))) | |||
| .append(" output_data_type:") | |||
| .append(std::to_string(graph.output_data_type.at(i))) | |||
| .append(" output_shape:\""); | |||
| size_t output_shape_len = graph.output_shape.at(i).size(); | |||
| if (output_shape_len == 0) { | |||
| data.append(""); | |||
| } else if (output_shape_len == 1) { | |||
| data.append(std::to_string(graph.output_shape.at(i).at(0))); | |||
| } else { | |||
| for (size_t j = 0; j < output_shape_len - 1; ++j) { | |||
| data.append(std::to_string(graph.output_shape.at(i).at(j))).append(","); | |||
| } | |||
| data.append(std::to_string(graph.output_shape.at(i).at(output_shape_len - 1))); | |||
| } | |||
| data.append("\""); | |||
| for (const auto &task : task_desc_info) { | |||
| Json task_info; | |||
| task_info[kModelName] = task.model_name; | |||
| task_info[kModelId] = model_id; | |||
| task_info[kOpNmae] = task.op_name; | |||
| task_info[kOptype] = task.op_type; | |||
| task_info[kBlockDim] = task.block_dim; | |||
| task_info[kTaskType] = task.task_type; | |||
| task_info[kTaskId] = task.task_id; | |||
| task_info[kStreamId] = task.stream_id; | |||
| task_info[kCurIterNum] = task.cur_iter_num; | |||
| task_info[kShapeType] = task.shape_type; | |||
| ProfilingOpInputOutInfo(task, task_info); | |||
| std::string reported_data; | |||
| try { | |||
| reported_data = task_info.dump(kInteval, ' ', false, Json::error_handler_t::ignore); | |||
| } catch (std::exception &e) { | |||
| GELOGE(FAILED, "Failed to convert JSON to string, reason: %s.", e.what()); | |||
| return ; | |||
| } catch (...) { | |||
| GELOGE(FAILED, "Failed to convert JSON to string."); | |||
| return; | |||
| } | |||
| data.append(" model_id:").append(std::to_string(model_id)); | |||
| data.append(" task_id:").append(std::to_string(graph.task_id)); | |||
| data.append(" stream_id:").append(std::to_string(graph.stream_id)); | |||
| data.append("\n"); | |||
| GraphDescReport(device_id, data); | |||
| data.clear(); | |||
| reported_data.append(",") | |||
| .append("\n"); | |||
| ReportData(device_id, reported_data, "task_desc_info"); | |||
| } | |||
| #endif | |||
| } | |||
| void ProfilingManager::GraphDescReport(const int32_t &device_id, const string &data) { | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ReportData( | |||
| const int32_t &device_id, const string &data, const string &tag_name) { | |||
| #ifdef DAVINCI_SUPPORT_PROFILING | |||
| ReporterData reporter_data{}; | |||
| int ret = -1; | |||
| @@ -325,36 +296,38 @@ void ProfilingManager::GraphDescReport(const int32_t &device_id, const string &d | |||
| size_t index = data.size() / kReportMaxLen; | |||
| if (index >= 1) { | |||
| reporter_data.deviceId = device_id; | |||
| ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, "graph_desc_info", sizeof("graph_desc_info")); | |||
| GE_IF_BOOL_EXEC(ret != EOK, GELOGE(ret, "Report data tag of graph_desc_info memcpy error!"); return;); | |||
| ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, tag_name.c_str(), tag_name.size()); | |||
| GE_IF_BOOL_EXEC(ret != EOK, GELOGE(ret, "Report data tag [%s] memcpy error!", tag_name.c_str()); return;); | |||
| for (size_t i = 0; i < index; ++i) { | |||
| reporter_data.data = (unsigned char *)data.c_str() + kReportMaxLen * i; | |||
| reporter_data.dataLen = kReportMaxLen; | |||
| cb_ret = CallMsprofReport(reporter_data); | |||
| GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data of graph_desc_info failed, ret:%d", cb_ret); return;); | |||
| GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data [%s] failed, ret:%d", tag_name.c_str(), cb_ret); | |||
| return;); | |||
| } | |||
| reporter_data.dataLen = data.size() - kReportMaxLen * index; | |||
| if (reporter_data.dataLen != 0) { | |||
| reporter_data.data = (unsigned char *)data.c_str() + kReportMaxLen * index; | |||
| cb_ret = CallMsprofReport(reporter_data); | |||
| GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data of graph_desc_info failed, ret:%d", cb_ret); return;); | |||
| GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data [%s] failed, ret:%d", tag_name.c_str(), cb_ret); | |||
| return;); | |||
| } | |||
| } else { | |||
| reporter_data.deviceId = device_id; | |||
| reporter_data.data = (unsigned char *)data.c_str(); | |||
| reporter_data.dataLen = data.size(); | |||
| ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, "graph_desc_info", sizeof("graph_desc_info")); | |||
| GE_IF_BOOL_EXEC(ret != EOK, GELOGE(ret, "Report data tag of graph_desc_info memcpy error!"); return;); | |||
| ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, tag_name.c_str(), tag_name.size()); | |||
| GE_IF_BOOL_EXEC(ret != EOK, GELOGE(ret, "Report data tag [%s] memcpy error!", tag_name.c_str()); return;); | |||
| cb_ret = CallMsprofReport(reporter_data); | |||
| GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data of graph_desc_info failed, ret:%d", cb_ret); return;); | |||
| GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data [%s] failed, ret:%d", tag_name.c_str(), cb_ret); | |||
| return;); | |||
| } | |||
| #endif | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ReportProfilingData( | |||
| uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, | |||
| const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info) { | |||
| uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info) { | |||
| #ifdef DAVINCI_SUPPORT_PROFILING | |||
| int32_t logic_device_id = 0; | |||
| rtError_t rt_ret = rtGetDevice(&logic_device_id); | |||
| @@ -365,8 +338,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ReportPr | |||
| GELOGD("current logic_device_id:%d", logic_device_id); | |||
| GELOGD("start ProfilingTaskDescInfo."); | |||
| ProfilingTaskDescInfo(model_id, task_desc_info, logic_device_id); | |||
| GELOGD("start ProfilingGraphDescInfo."); | |||
| ProfilingGraphDescInfo(model_id, compute_graph_desc_info, logic_device_id); | |||
| GELOGD("Report profiling data for GE end."); | |||
| #endif | |||
| } | |||
| @@ -813,6 +784,44 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::CallMs | |||
| static_cast<void *>(&reporter_data), sizeof(ReporterData)); | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::GetOpInputOutputInfo( | |||
| const OpDescPtr &op, TaskDescInfo &task_desc_info) const { | |||
| std::vector<Format> input_format; | |||
| std::vector<std::vector<int64_t>> input_shape; | |||
| std::vector<DataType> input_data_type; | |||
| for (size_t i = 0; i < op->GetAllInputsSize(); ++i) { | |||
| GeTensorDescPtr input_tensor_desc = op->MutableInputDesc(i); | |||
| if (input_tensor_desc == nullptr) { | |||
| continue; | |||
| } | |||
| input_format.emplace_back(input_tensor_desc->GetFormat()); | |||
| input_shape.emplace_back(input_tensor_desc->GetShape().GetDims()); | |||
| input_data_type.emplace_back(input_tensor_desc->GetDataType()); | |||
| } | |||
| std::vector<Format> output_format; | |||
| std::vector<std::vector<int64_t>> output_shape; | |||
| std::vector<DataType> output_data_type; | |||
| for (size_t j = 0; j < op->GetOutputsSize(); ++j) { | |||
| GeTensorDescPtr output_tensor_desc = op->MutableOutputDesc(j); | |||
| if (output_tensor_desc == nullptr) { | |||
| continue; | |||
| } | |||
| output_format.emplace_back(output_tensor_desc->GetFormat()); | |||
| output_shape.emplace_back(output_tensor_desc->GetShape().GetDims()); | |||
| output_data_type.emplace_back(output_tensor_desc->GetDataType()); | |||
| } | |||
| std::vector<Format> format_default = { FORMAT_NULL }; | |||
| std::vector<std::vector<int64_t>> shape_default = { {0} }; | |||
| std::vector<DataType> data_type_default = { DT_UNDEFINED }; | |||
| task_desc_info.input_format = input_format.empty() ? format_default : input_format; | |||
| task_desc_info.input_shape = input_shape.empty() ? shape_default : input_shape; | |||
| task_desc_info.input_data_type = input_data_type.empty() ? data_type_default : input_data_type; | |||
| task_desc_info.output_format = output_format.empty() ? format_default : output_format; | |||
| task_desc_info.output_shape = output_shape.empty() ? shape_default : output_shape; | |||
| task_desc_info.output_data_type = output_data_type.empty() ? data_type_default : output_data_type; | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::GetFpBpPoint( | |||
| std::string &fp_point, std::string &bp_point) { | |||
| // Env or options mode, fp_point_/bp_point_ have initiliazed on profiling init | |||
| @@ -54,6 +54,8 @@ namespace { | |||
| } // namespace | |||
| namespace ge { | |||
| class OpDesc; | |||
| using OpDescPtr = std::shared_ptr<OpDesc>; | |||
| struct DeviceSubsInfo { | |||
| uint64_t module; | |||
| uint32_t subscribe_count; | |||
| @@ -82,12 +84,10 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager { | |||
| bool ProfilingModelExecuteOn() const; | |||
| // is_execute_profiling_ only used by ge option and env | |||
| bool ProfilingOn() const { return is_load_profiling_ && is_execute_profiling_; } | |||
| void ReportProfilingData(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, | |||
| const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info); | |||
| void ReportProfilingData(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); | |||
| void ProfilingGraphDescInfo(uint32_t model_id, const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info, | |||
| const int32_t &device_id); | |||
| void ProfilingOpInputOutInfo(const TaskDescInfo &task, Json &task_json); | |||
| Status PluginInit() const; | |||
| void PluginUnInit() const; | |||
| Status CallMsprofReport(ReporterData &reporter_data) const; | |||
| @@ -95,6 +95,8 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager { | |||
| void SetMsprofCtrlCallback(MsprofCtrlCallback func) { prof_cb_.msprofCtrlCallback = 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 ReportData(const int32_t &device_id, const std::string &data, const std::string &tag_name); | |||
| private: | |||
| Status InitFromOptions(const Options &options, MsprofGeOptions &prof_conf); | |||
| Status ParseOptions(const std::string &options); | |||
| @@ -103,7 +105,6 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager { | |||
| Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para, | |||
| vector<int32_t> &device_list); | |||
| uint64_t GetProfilingModule(); | |||
| void GraphDescReport(const int32_t &device_id, const string &data); | |||
| 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); | |||
| @@ -165,24 +165,4 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void PropertiesManager::SetProp | |||
| delimiter = de; | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY DumpProperties &PropertiesManager::GetDumpProperties( | |||
| uint64_t session_id) { | |||
| std::lock_guard<std::mutex> lock(mutex_); | |||
| // If session_id is not found in dump_properties_map_, operator[] will insert one. | |||
| return dump_properties_map_[session_id]; | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void PropertiesManager::AddDumpProperties( | |||
| uint64_t session_id, const DumpProperties &dump_properties) { | |||
| std::lock_guard<std::mutex> lock(mutex_); | |||
| dump_properties_map_.emplace(session_id, dump_properties); | |||
| } | |||
| FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void PropertiesManager::RemoveDumpProperties(uint64_t session_id) { | |||
| std::lock_guard<std::mutex> lock(mutex_); | |||
| auto iter = dump_properties_map_.find(session_id); | |||
| if (iter != dump_properties_map_.end()) { | |||
| dump_properties_map_.erase(iter); | |||
| } | |||
| } | |||
| } // namespace ge | |||
| @@ -83,13 +83,6 @@ class PropertiesManager { | |||
| */ | |||
| void SetPropertyDelimiter(const std::string &de); | |||
| DumpProperties &GetDumpProperties(uint64_t session_id); | |||
| const map<uint64_t, DumpProperties> &GetDumpPropertiesMap() { return dump_properties_map_; } | |||
| void AddDumpProperties(uint64_t session_id, const DumpProperties &dump_properties); | |||
| void RemoveDumpProperties(uint64_t session_id); | |||
| private: | |||
| // Private construct, destructor | |||
| PropertiesManager(); | |||
| @@ -111,8 +104,6 @@ class PropertiesManager { | |||
| std::map<std::string, std::string> properties_map_; | |||
| std::mutex mutex_; | |||
| std::map<uint64_t, DumpProperties> dump_properties_map_; | |||
| }; | |||
| } // namespace ge | |||
| @@ -217,7 +217,7 @@ std::string DNNEngineManager::GetDNNEngineName(const ge::NodePtr &node_ptr) { | |||
| std::string unsupported_reason; | |||
| // It will be replaced by engine' checksupport | |||
| uint64_t start_time = GetCurrentTimestamp(); | |||
| if (kernel_info_store->second->CheckSupported(op_desc, unsupported_reason)) { | |||
| if (kernel_info_store->second->CheckSupported(node_ptr, unsupported_reason)) { | |||
| checksupport_cost_[kernel_name] += GetCurrentTimestamp() - start_time; | |||
| op_desc->SetOpEngineName(it.engine); | |||
| op_desc->SetOpKernelLibName(kernel_name); | |||
| @@ -17,6 +17,7 @@ set(SRC_LIST | |||
| "../common/dump/dump_properties.cc" | |||
| "../common/dump/dump_manager.cc" | |||
| "../common/dump/dump_op.cc" | |||
| "../common/dump/opdebug_register.cc" | |||
| "../common/profiling/ge_profiling.cc" | |||
| "../graph/load/graph_loader.cc" | |||
| "../graph/execute/graph_execute.cc" | |||
| @@ -33,7 +34,6 @@ set(SRC_LIST | |||
| "../model/ge_model.cc" | |||
| "../model/ge_root_model.cc" | |||
| "../graph/load/model_manager/davinci_model.cc" | |||
| "../graph/load/model_manager/davinci_model_parser.cc" | |||
| "../graph/load/model_manager/model_manager.cc" | |||
| "../graph/load/model_manager/tbe_handle_store.cc" | |||
| "../graph/load/model_manager/cpu_queue_schedule.cc" | |||
| @@ -250,15 +250,14 @@ target_link_options(ge_executor_shared PRIVATE | |||
| target_link_libraries(ge_executor_shared PRIVATE | |||
| $<BUILD_INTERFACE:intf_pub> | |||
| msprofiler | |||
| static_mmpa | |||
| -Wl,--no-as-needed | |||
| ge_common | |||
| runtime | |||
| slog | |||
| mmpa | |||
| graph | |||
| register | |||
| error_manager | |||
| ascend_hal_stub | |||
| ascend_protobuf | |||
| c_sec | |||
| -Wl,--as-needed | |||
| @@ -16,7 +16,6 @@ | |||
| #include "executor/ge_executor.h" | |||
| #include <cce/cce.h> | |||
| #include <cce/compiler_stub.h> | |||
| #include <ctime> | |||
| #include <iostream> | |||
| #include "common/debug/log.h" | |||
| @@ -24,19 +23,11 @@ | |||
| #include "common/helper/model_helper.h" | |||
| #include "common/profiling/profiling_manager.h" | |||
| #include "common/dump/dump_manager.h" | |||
| #include "common/util.h" | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "framework/common/util.h" | |||
| #include "graph/execute/graph_execute.h" | |||
| #include "graph/load/graph_loader.h" | |||
| #include "graph/load/model_manager/davinci_model_parser.h" | |||
| #include "graph/load/model_manager/model_manager.h" | |||
| #include "graph/manager/graph_mem_allocator.h" | |||
| #include "graph/model.h" | |||
| #include "graph/utils/graph_utils.h" | |||
| #include "mmpa/mmpa_api.h" | |||
| #include "single_op/single_op_manager.h" | |||
| #include "graph/manager/graph_var_manager.h" | |||
| #include "graph/load/model_manager/davinci_model.h" | |||
| #include "opskernel_manager/ops_kernel_builder_manager.h" | |||
| @@ -56,7 +47,7 @@ void GetGeTensorDescFromDomiInfo(std::vector<ge::TensorDesc> &ge_descs, | |||
| uint32_t idx = 0; | |||
| for (auto desc_item : domi_descs) { | |||
| ge::TensorDesc ge_desc; | |||
| ge_desc.SetName(desc_item.name); | |||
| ge_desc.SetName(desc_item.name.c_str()); | |||
| ge_desc.SetDataType(static_cast<ge::DataType>(desc_item.data_type)); | |||
| ge_desc.SetFormat(static_cast<ge::Format>(formats[idx])); | |||
| std::vector<int64_t> shape_dims; | |||
| @@ -454,7 +445,8 @@ Status GeExecutor::GetCurDynamicDims(uint32_t model_id, const vector<uint64_t> & | |||
| if (all_data_dims[i] < 0) { | |||
| cur_dynamic_dims.push_back(dynamic_dims[i]); | |||
| } else if (static_cast<uint64_t>(all_data_dims[i]) != dynamic_dims[i]) { | |||
| GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, "Static dims should be same, index: %zu value: %lu should be %ld", | |||
| GELOGE(ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID, | |||
| "Static dims should be same, index: %zu value: %lu should be %ld", | |||
| i, dynamic_dims[i], all_data_dims[i]); | |||
| return ACL_ERROR_GE_DYNAMIC_INPUT_LENGTH_INVALID; | |||
| } | |||
| @@ -930,12 +922,22 @@ Status GeExecutor::GetMemAndWeightSize(const void *model_data, size_t model_size | |||
| Status GeExecutor::LoadSingleOp(const std::string &model_name, const ge::ModelData &modelData, void *stream, | |||
| SingleOp **single_op) { | |||
| return SingleOpManager::GetInstance().GetOpFromModel(model_name, modelData, stream, single_op); | |||
| return LoadSingleOpV2(model_name, modelData, stream, single_op, 0); | |||
| } | |||
| Status GeExecutor::LoadSingleOpV2(const std::string &model_name, const ge::ModelData &modelData, void *stream, | |||
| SingleOp **single_op, const uint64_t model_id) { | |||
| return SingleOpManager::GetInstance().GetOpFromModel(model_name, modelData, stream, single_op, model_id); | |||
| } | |||
| Status GeExecutor::LoadDynamicSingleOp(const std::string &model_name, const ge::ModelData &modelData, void *stream, | |||
| DynamicSingleOp **single_op) { | |||
| return SingleOpManager::GetInstance().GetDynamicOpFromModel(model_name, modelData, stream, single_op); | |||
| return LoadDynamicSingleOpV2(model_name, modelData, stream, single_op, 0); | |||
| } | |||
| Status GeExecutor::LoadDynamicSingleOpV2(const std::string &model_name, const ge::ModelData &modelData, void *stream, | |||
| DynamicSingleOp **single_op, const uint64_t model_id) { | |||
| return SingleOpManager::GetInstance().GetDynamicOpFromModel(model_name, modelData, stream, single_op, model_id); | |||
| } | |||
| Status GeExecutor::ExecuteAsync(SingleOp *executor, const std::vector<DataBuffer> &inputs, | |||
| @@ -28,7 +28,10 @@ | |||
| namespace ge { | |||
| namespace model_runner { | |||
| namespace { | |||
| const int kOffsetUnit = 8; | |||
| const uint32_t kStringHeadElems = 2; | |||
| } // namespace | |||
| RuntimeModel::~RuntimeModel() { | |||
| GELOGI("RuntimeModel destructor start"); | |||
| @@ -496,10 +499,15 @@ bool RuntimeModel::InitConstantInfo(std::shared_ptr<DavinciModel> &davinci_model | |||
| return false; | |||
| } | |||
| uint64_t *buff = reinterpret_cast<uint64_t *>(const_cast<char *>(constant->weight_data.data())); | |||
| int64_t offset = elem_num * kOffsetUnit; | |||
| uint32_t head_len = kOffsetUnit * kStringHeadElems; | |||
| if (ge::CheckInt64Uint32MulOverflow(elem_num, head_len) != SUCCESS) { | |||
| GELOGE(FAILED, "Shape size is invalid"); | |||
| return false; | |||
| } | |||
| int64_t offset = elem_num * head_len; | |||
| uintptr_t hbm_raw_data_base_addr = reinterpret_cast<uintptr_t>(constant->output_addrs[0]) + offset; | |||
| for (int64_t i = elem_num - 1; i >= 0; --i) { | |||
| buff[i] = hbm_raw_data_base_addr + (buff[i] - buff[0]); | |||
| buff[i * kStringHeadElems] = hbm_raw_data_base_addr + (buff[i * kStringHeadElems] - buff[0]); | |||
| } | |||
| } | |||
| @@ -66,7 +66,8 @@ bool ContainsDynamicInpus(const ge::OpDesc &op_desc) { | |||
| } // namespace | |||
| namespace ge { | |||
| static Status CheckEngineTypeSupport(const OpDescPtr &op_desc, OpEngineType engine_type) { | |||
| static Status CheckEngineTypeSupport(const NodePtr &node, OpEngineType engine_type) { | |||
| const OpDescPtr &op_desc = node->GetOpDesc(); | |||
| GE_CHECK_NOTNULL_EXEC(op_desc, return PARAM_INVALID); | |||
| if (engine_type == ENGINE_SYS) { | |||
| GELOGI("CheckEngineType: use default engine."); | |||
| @@ -123,7 +124,7 @@ static Status CheckEngineTypeSupport(const OpDescPtr &op_desc, OpEngineType engi | |||
| auto kernel_info_store = kernel_map.find(kernel_name); | |||
| if (kernel_info_store != kernel_map.end()) { | |||
| std::string unsupported_reason; | |||
| if (kernel_info_store->second->CheckSupported(op_desc, unsupported_reason)) { | |||
| if (kernel_info_store->second->CheckSupported(node, unsupported_reason)) { | |||
| op_desc->SetOpEngineName(op_engine_name); | |||
| op_desc->SetOpKernelLibName(kernel_name); | |||
| GELOGI("CheckEngineType:Set OpKernelLibName %s and engine name %s into op_desc %s", kernel_name.c_str(), | |||
| @@ -147,7 +148,7 @@ static Status CheckEngineTypeSupport(const OpDescPtr &op_desc, OpEngineType engi | |||
| return FAILED; | |||
| } | |||
| static Status AddInputs(const ComputeGraphPtr &graph, const NodePtr &node, GeTensorDesc &tensor, int32_t index, | |||
| static Status AddInputs(const ComputeGraphPtr &graph, const NodePtr &node, const GeTensorDesc &tensor, int32_t index, | |||
| bool attr) { | |||
| GE_CHECK_NOTNULL_EXEC(graph, return PARAM_INVALID); | |||
| GE_CHECK_NOTNULL_EXEC(node, return PARAM_INVALID); | |||
| @@ -326,6 +327,8 @@ Status GeGenerator::Initialize(const map<string, string> &options, OmgContext &o | |||
| GELOGE(MEMALLOC_FAILED, "Make shared failed"); | |||
| return MEMALLOC_FAILED; | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOpsProtoInit); | |||
| string opsproto_path; | |||
| GetOpsProtoPath(opsproto_path); | |||
| GELOGI("Get opsproto path is %s", opsproto_path.c_str()); | |||
| @@ -374,6 +377,7 @@ Status GeGenerator::Initialize(const map<string, string> &options, OmgContext &o | |||
| } | |||
| Status GeGenerator::Finalize() { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kFinalize, ErrorMessage::kFinalize); | |||
| GE_CHECK_NOTNULL_EXEC(impl_, return PARAM_INVALID); | |||
| Status ret = impl_->graph_manager_.Finalize(); | |||
| if (ret != SUCCESS) { | |||
| @@ -385,12 +389,14 @@ Status GeGenerator::Finalize() { | |||
| Status GeGenerator::GenerateOfflineModel(const Graph &graph, const string &file_name_prefix, | |||
| const vector<GeTensor> &inputs) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GELOGI("Start to generate offline model."); | |||
| ModelBufferData model; | |||
| return GenerateModel(graph, file_name_prefix, inputs, model, true); | |||
| } | |||
| Status GeGenerator::GenerateOnlineModel(const Graph &graph, const vector<GeTensor> &inputs, ModelBufferData &model) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| return GenerateModel(graph, "online", inputs, model, false); | |||
| } | |||
| @@ -671,6 +677,8 @@ Status GeGenerator::CheckForSingleOp(OpDescPtr &op_desc, const vector<GeTensor> | |||
| Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs, | |||
| const string &model_file_name, OpEngineType engine_type, ModelBufferData &model_buff, | |||
| bool is_offline) { | |||
| GE_CHECK_NOTNULL_EXEC(impl_, return PARAM_INVALID); | |||
| impl_->is_offline_ = is_offline; | |||
| if (!is_offline) { | |||
| (void)AttrUtils::SetBool(op_desc, ATTR_SINGLE_OP_SCENE, true); | |||
| } | |||
| @@ -690,27 +698,26 @@ Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &in | |||
| OpDescPtr op_desc_tmp = AttrUtils::CloneOpDesc(op_desc); | |||
| GE_CHECK_NOTNULL(op_desc_tmp); | |||
| // 1. check engine type when compile online | |||
| // 1. Create ComputeGraph. | |||
| string name = ge::CurrentTimeInStr() + "_" + model_file_name; | |||
| Graph graph; | |||
| GE_CHK_STATUS(BuildSingleOpGraph(op_desc, inputs, outputs, name, graph), "make graph fail."); | |||
| // 2. check engine type when compile online | |||
| if (model_file_name == kFileNameSuffix) { | |||
| Status ret = CheckEngineTypeSupport(op_desc, engine_type); | |||
| auto comp_graph = GraphUtils::GetComputeGraph(graph); | |||
| GE_CHECK_NOTNULL(comp_graph); | |||
| auto node = comp_graph->FindNode(op_desc->GetName()); | |||
| Status ret = CheckEngineTypeSupport(node, engine_type); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "check engine type failed."); | |||
| return ret; | |||
| } | |||
| } | |||
| // 2. Create ComputeGraph. | |||
| string name = ge::CurrentTimeInStr() + "_" + model_file_name; | |||
| Graph graph; | |||
| if (BuildSingleOpGraph(op_desc, inputs, outputs, name, graph) != ge::SUCCESS) { | |||
| GELOGE(GRAPH_FAILED, "make graph fail."); | |||
| return GRAPH_FAILED; | |||
| } | |||
| GELOGI("ATC parser success in single op build."); | |||
| GeRootModelPtr ge_root_model = nullptr; | |||
| GE_CHECK_NOTNULL_EXEC(impl_, return PARAM_INVALID); | |||
| impl_->is_offline_ = is_offline; | |||
| GE_CHK_STATUS_RET_NOLOG(impl_->BuildModel(graph, inputs, ge_root_model)); | |||
| map<string, GeAttrValue> op_attrs = op_desc_tmp->GetAllAttrs(); | |||
| GE_CHECK_NOTNULL(ge_root_model); | |||
| @@ -723,7 +730,7 @@ Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &in | |||
| const ComputeGraphPtr root_graph = ge_root_model->GetRootGraph(); | |||
| GeModelPtr &ge_model = name_to_ge_model.begin()->second; | |||
| GE_CHK_STATUS_RET_NOLOG(CheckDynamicSupport(ge_model, root_graph)); | |||
| GELOGD("The opType in op_desc_tmp is [%s]", op_desc_tmp->GetType().c_str()); | |||
| GELOGI("After build model, The opType in op_desc_tmp is [%s]", op_desc_tmp->GetType().c_str()); | |||
| bool all_shape = false; | |||
| (void)AttrUtils::GetBool(op_desc, kAicpuAllshape, all_shape); | |||
| @@ -738,6 +745,7 @@ Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &in | |||
| } else { | |||
| GE_CHK_STATUS_RET_NOLOG(impl_->SaveParams(ge_model, op_desc_tmp->GetType(), op_attrs, inputs, outputs)); | |||
| } | |||
| GELOGI("Start save GeModel to Model buffer"); | |||
| GE_CHK_STATUS_RET_NOLOG(impl_->SaveModel(model_file_name, ge_model, model_buff)); | |||
| return SUCCESS; | |||
| } | |||
| @@ -753,10 +761,13 @@ Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &in | |||
| */ | |||
| Status GeGenerator::BuildSingleOpModel(OpDescPtr &op_desc, const vector<GeTensor> &inputs, | |||
| const vector<GeTensor> &outputs, const string &model_file_name) { | |||
| GELOGI("Start to build single op offline model."); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GELOGI("Start to build single op offline model, input size: %zu, output size: %zu", inputs.size(), outputs.size()); | |||
| ModelBufferData model_buff; | |||
| OpEngineType engine_type = ENGINE_SYS; | |||
| return BuildSingleOp(op_desc, inputs, outputs, model_file_name, engine_type, model_buff, true); | |||
| Status status = BuildSingleOp(op_desc, inputs, outputs, model_file_name, engine_type, model_buff, true); | |||
| GELOGI("Finish build single offline model, status: %u", status); | |||
| return status; | |||
| } | |||
| /** | |||
| @@ -772,8 +783,11 @@ Status GeGenerator::BuildSingleOpModel(OpDescPtr &op_desc, const vector<GeTensor | |||
| Status GeGenerator::BuildSingleOpModel(OpDescPtr &op_desc, const vector<GeTensor> &inputs, | |||
| const vector<GeTensor> &outputs, OpEngineType engine_type, | |||
| ModelBufferData &model_buff) { | |||
| GELOGI("Start to build single op online"); | |||
| return BuildSingleOp(op_desc, inputs, outputs, kFileNameSuffix, engine_type, model_buff, false); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GELOGI("Start to build single op online, input size: %zu, output size: %zu", inputs.size(), outputs.size()); | |||
| Status status = BuildSingleOp(op_desc, inputs, outputs, kFileNameSuffix, engine_type, model_buff, false); | |||
| GELOGI("Finish build single online model, status: %u", status); | |||
| return status; | |||
| } | |||
| Status GeGenerator::BuildSingleOpGraph(OpDescPtr &op_desc, const vector<GeTensor> &inputs, | |||
| @@ -798,8 +812,7 @@ Status GeGenerator::BuildSingleOpGraph(OpDescPtr &op_desc, const vector<GeTensor | |||
| } | |||
| } else { | |||
| for (const auto &in_desc : inputs) { | |||
| GeTensorDesc input_desc = in_desc.GetTensorDesc(); | |||
| GE_CHK_STATUS_RET_NOLOG(AddInputs(compute_graph, op_node, input_desc, arg_index, true)); | |||
| GE_CHK_STATUS_RET_NOLOG(AddInputs(compute_graph, op_node, in_desc.GetTensorDesc(), arg_index, true)); | |||
| arg_index++; | |||
| } | |||
| } | |||
| @@ -908,6 +921,7 @@ Status GeGenerator::Impl::BuildModel(const Graph &graph, const vector<GeTensor> | |||
| ret = graph_manager_.BuildGraph(graph_id, inputs, ge_root_model, session_id); | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(GE_GENERATOR_GRAPH_MANAGER_BUILD_GRAPH_FAILED, "GraphManager build graph fail, graph id: %u", graph_id); | |||
| VarManagerPool::Instance().RemoveVarManager(session_id); | |||
| @@ -222,6 +222,7 @@ Status GraphBuilder::BuildForKnownShapeGraph(ComputeGraphPtr &comp_graph, | |||
| return SUCCESS; | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kPreBuild); | |||
| GELOGI("Begin to build known shape graph[%s].", comp_graph->GetName().c_str()); | |||
| Status ret = SecondPartition(comp_graph); | |||
| GE_CHK_STATUS_RET(ret, "Graph[%s] second partition Failed.", comp_graph->GetName().c_str()); | |||
| @@ -252,6 +253,7 @@ Status GraphBuilder::BuildForKnownShapeGraph(ComputeGraphPtr &comp_graph, | |||
| GE_TIMESTAMP_END(BuildModelForGetTask, "GraphBuilder::BuildModelForGetTask"); | |||
| GE_DUMP(comp_graph, "AfterBuildModel"); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kTaskGenerate); | |||
| GE_TIMESTAMP_START(GetTaskInfo); | |||
| ret = GetTaskInfo(builder, model_ptr, comp_graph, subgraph_map, session_id); | |||
| GE_TIMESTAMP_END(GetTaskInfo, "GraphBuilder::GetTaskInfo"); | |||
| @@ -261,6 +263,7 @@ Status GraphBuilder::BuildForKnownShapeGraph(ComputeGraphPtr &comp_graph, | |||
| return ret; | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| ge_model_ptr = MakeShared<ge::GeModel>(); | |||
| if (ge_model_ptr == nullptr) { | |||
| return MEMALLOC_FAILED; | |||
| @@ -320,6 +323,7 @@ Status GraphBuilder::SetConstantInputOffset(ComputeGraphPtr &comp_graph) { | |||
| Status GraphBuilder::BuildForUnknownShapeGraph(ComputeGraphPtr &comp_graph, GeModelPtr &ge_model_ptr, | |||
| uint64_t session_id) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kPreBuild); | |||
| GELOGI("Begin to build unknown shape graph[%s].", comp_graph->GetName().c_str()); | |||
| Graph2SubGraphInfoList subgraph_map; | |||
| ge::ModelBuilder builder(session_id, comp_graph, subgraph_map, stream_max_parallel_num_, hcom_parallel_, build_mode_); | |||
| @@ -352,9 +356,11 @@ Status GraphBuilder::BuildForUnknownShapeGraph(ComputeGraphPtr &comp_graph, GeMo | |||
| GE_CHK_STATUS_RET(builder.BuildModelForGetDynShapeTask(*model_ptr), | |||
| "Graph[%s] builder BuildModelForGetDynShapeTask() return fail.", comp_graph->GetName().c_str()); | |||
| GE_TIMESTAMP_END(BuildModelForGetDynShapeTask, "GraphBuilder::BuildModelForGetDynShapeTask"); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kTaskGenerate); | |||
| GE_TIMESTAMP_START(GetTaskInfo); | |||
| Status ret = GetTaskInfo(builder, model_ptr, comp_graph, subgraph_map, session_id); | |||
| GE_TIMESTAMP_END(GetTaskInfo, "GraphBuilder::GetTaskInfo"); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GraphUtils::DumpGEGraph(comp_graph, "AfterGetTask"); | |||
| GraphUtils::DumpGEGraphToOnnx(*comp_graph, "AfterGetTask"); | |||
| @@ -157,8 +157,8 @@ ge::Status GraphMemoryAssigner::AssignMemory2HasRefAttrNode() { | |||
| } | |||
| ge::Status CalculateTensorRealSizeAndOutSize(const ge::ConstGeTensorDescPtr &output_desc, | |||
| int64_t dim_index, int64_t &output_mem_size, | |||
| int64_t &batch_dim_num, int64_t &out_size) { | |||
| int64_t dim_index, int64_t &output_mem_size, | |||
| int64_t &batch_dim_num, int64_t &out_size) { | |||
| graphStatus graph_status = ge::TensorUtils::GetSize(*output_desc, out_size); | |||
| if (graph_status != GRAPH_SUCCESS) { | |||
| GELOGE(FAILED, "Opdesc GetSize failed!"); | |||
| @@ -430,18 +430,18 @@ Status GraphMemoryAssigner::ReAssignContinuousMemory(bool is_loop_graph) { | |||
| GELOGE(FAILED, "node %s has no continuous type!", node->GetName().c_str()); | |||
| return FAILED; | |||
| } | |||
| GE_CHK_STATUS_RET(AssignContinuousInputMemoryWithAtomicProcess(node, iter->second), | |||
| GE_CHK_STATUS_RET(AssignContinuousInputMemoryWithAtomicProcess(node, iter->second, true), | |||
| "Assign node %s continuous input memory failed.", node->GetName().c_str()) | |||
| } | |||
| for (auto pair : memory_offset_) { | |||
| GELOGD("After reassign continuous memory, memory type = %ld, memoffset = %zu.", pair.first, | |||
| GELOGD("After reassign continuous memory, memory type = %ld, mem_offset = %zu.", pair.first, | |||
| pair.second.mem_offset_); | |||
| } | |||
| return ge::SUCCESS; | |||
| } | |||
| Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node, int64_t &continuous_mem_start, | |||
| int64_t &continuous_mem_size, int64_t memory_type, uint32_t continuous_type) { | |||
| int64_t &continuous_mem_size, int64_t memory_type, uint32_t continuous_type, bool reverse_refresh) { | |||
| GELOGI("Current node %s needs continuous input.", node->GetName().c_str()); | |||
| auto iter = memory_offset_.find(memory_type); | |||
| if (iter == memory_offset_.end()) { | |||
| @@ -508,12 +508,16 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node, | |||
| std::map<int32_t, int32_t> out2ins; | |||
| GE_CHK_STATUS_RET(GetAllRef(node, out2ins), "Node: %s get all ref failed", node->GetName().c_str()); | |||
| // output is beginning offset, set offset for input; only support this case now | |||
| if (out2ins.size() == 1 && out2ins.begin()->second == 0) { | |||
| if ((out2ins.size() == 1) && (out2ins.begin()->second == 0) && (reverse_refresh)) { | |||
| auto peer_output_offset = output_list.at(peer_out_data_anchor->GetIdx()); | |||
| output_list.at(peer_out_data_anchor->GetIdx()) = output_list_this.at(out2ins.begin()->first); | |||
| peer_op_desc->SetOutputOffset(output_list); | |||
| GELOGI("Node %s out %d ref in %d input node %s, use output offset %ld update %ld.", node->GetName().c_str(), | |||
| out2ins.begin()->first, out2ins.begin()->second, peer_op_desc->GetName().c_str(), | |||
| output_list_this.at(out2ins.begin()->first), peer_output_offset); | |||
| } else { | |||
| GELOGW("Node %s out %d ref in %d with total ref numbers %zu", node->GetName().c_str(), out2ins.begin()->first, | |||
| out2ins.begin()->second, out2ins.size()); | |||
| GELOGD("Node %s out %d ref in %d input node %s with total ref numbers %zu.", node->GetName().c_str(), | |||
| out2ins.begin()->first, out2ins.begin()->second, peer_op_desc->GetName().c_str(), out2ins.size()); | |||
| } | |||
| // first input is beginning offset | |||
| mem_offset = output_list.at(peer_out_data_anchor->GetIdx()); | |||
| @@ -538,7 +542,7 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node, | |||
| } | |||
| GELOGI("[IMAS]Continuous input : Set %s name[%s] optype[%s] output[%d] offset to [%zu] stream_id[%ld] memtype[%ld] " | |||
| "size[%zu] realsize[%ld] nopadding[%d].", node->GetOwnerComputeGraph()->GetName().c_str(), | |||
| "size[%zu] realsize[%ld] nopadding size[%d].", node->GetOwnerComputeGraph()->GetName().c_str(), | |||
| peer_op_desc->GetName().c_str(), node->GetType().c_str(), peer_out_data_anchor->GetIdx(), | |||
| output_list.at(peer_out_data_anchor->GetIdx()), peer_op_desc->GetStreamId(), memory_type, | |||
| is_continuous_input_allocated ? 0UL : align_size, real_size, is_nopadding); | |||
| @@ -1535,12 +1539,17 @@ ge::Status GraphMemoryAssigner::GetAllRef(const NodePtr &node, map<int32_t, int3 | |||
| bool GraphMemoryAssigner::AssignContinuousInputMemoryWithAtomicProcessDirectly( | |||
| const NodePtr &input_continuous_node, map<NodePtr, uint32_t> &node_2_continuous_type) { | |||
| for (const auto &in_node : input_continuous_node->GetInDataNodes()) { | |||
| if (in_node->GetType() == VARIABLE) { | |||
| GELOGI("node %s 's precursor node %s is variable, do not store.", input_continuous_node->GetName().c_str(), | |||
| in_node->GetName().c_str()); | |||
| return true; | |||
| } | |||
| auto iter = node_2_continuous_type.find(in_node); | |||
| // In node's topo order in the front, so function can not be exception | |||
| auto continuous_type = iter->second; | |||
| bool continuous_input = ((continuous_type & kTypeInput) != 0) || ((continuous_type & kTypeInputNoPadding) != 0); | |||
| if (continuous_input) { | |||
| GELOGI("node %s 's precursor node %s need assign continuous input memory, store node firstly.", | |||
| GELOGI("Node %s 's precursor node %s need assign continuous input memory, store node firstly.", | |||
| input_continuous_node->GetName().c_str(), in_node->GetName().c_str()); | |||
| return false; | |||
| } | |||
| @@ -1550,7 +1559,7 @@ bool GraphMemoryAssigner::AssignContinuousInputMemoryWithAtomicProcessDirectly( | |||
| node_2_continuous_type.emplace(out_node, continuous_type); | |||
| bool continuous_input = ((continuous_type & kTypeInput) != 0) || ((continuous_type & kTypeInputNoPadding) != 0); | |||
| if (continuous_input) { | |||
| GELOGI("node %s 's succeed node %s need assign continuous input memory, store node firstly.", | |||
| GELOGI("Node %s 's succeed node %s need assign continuous input memory, store node firstly.", | |||
| input_continuous_node->GetName().c_str(), out_node->GetName().c_str()); | |||
| return false; | |||
| } | |||
| @@ -1560,13 +1569,15 @@ bool GraphMemoryAssigner::AssignContinuousInputMemoryWithAtomicProcessDirectly( | |||
| } | |||
| ge::Status GraphMemoryAssigner::AssignContinuousInputMemoryWithAtomicProcess(const NodePtr &input_continuous_node, | |||
| uint32_t continuous_type) { | |||
| uint32_t continuous_type, | |||
| bool reverse_refresh) { | |||
| int64_t mem_clean_start = 0; | |||
| int64_t mem_clean_size = 0; | |||
| int64_t memory_type = RT_MEMORY_HBM; | |||
| GE_CHK_STATUS_RET(GetNodeMemoryType(input_continuous_node, memory_type, "input"), "Get node memory type failed."); | |||
| auto ret = AssignContinuousInputMemory(input_continuous_node, mem_clean_start, mem_clean_size, memory_type, continuous_type); | |||
| auto ret = AssignContinuousInputMemory(input_continuous_node, mem_clean_start, mem_clean_size, memory_type, | |||
| continuous_type, reverse_refresh); | |||
| if (ret != ge::SUCCESS) { | |||
| GELOGE(ret, "Assign continuous input memory failed!"); | |||
| return ret; | |||
| @@ -131,13 +131,14 @@ class GraphMemoryAssigner { | |||
| std::map<NodePtr, uint32_t> &node_2_continuous_type); | |||
| ge::Status AssignContinuousInputMemoryWithAtomicProcess(const NodePtr &input_continuous_node, | |||
| uint32_t continuous_type); | |||
| uint32_t continuous_type, bool reverse_refresh = false); | |||
| ge::Status FilterAtomicNodesForMemoryAssign(map<string, map<NodePtr, vector<NodePtr>>> &normal_atomic_nodes_map, | |||
| map<string, vector<NodePtr>> &connecting_output_atomic_nodes); | |||
| ge::Status AssignContinuousInputMemory(const ge::NodePtr &node, int64_t &continuous_mem_start, | |||
| int64_t &continuous_mem_size, int64_t memory_type, uint32_t continuous_type); | |||
| int64_t &continuous_mem_size, int64_t memory_type, uint32_t continuous_type, | |||
| bool reverse_refresh = false); | |||
| ge::Status AssignContinuousOutputMemory(const ge::NodePtr &node, int64_t memory_type, uint32_t continuous_type); | |||
| @@ -19,6 +19,7 @@ | |||
| #include <set> | |||
| #include <unordered_map> | |||
| #include "common/ge/ge_util.h" | |||
| #include "common/dump/dump_manager.h" | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "graph/anchor.h" | |||
| #include "graph/attr_value.h" | |||
| @@ -260,7 +261,9 @@ Status ModelBuilder::SetInputOutputDesc() { | |||
| GE_IF_BOOL_EXEC(n->GetInAllNodes().empty() && n->GetOutAllNodes().empty(), continue;); | |||
| SetInputIsConst(n); | |||
| if (IsGeLocalOp(n->GetOpDesc())) { | |||
| bool is_unknow = false; | |||
| (void)NodeUtils::GetNodeUnknownShapeStatus(*n, is_unknow); | |||
| if ((IsGeLocalOp(n->GetOpDesc())) && (!is_unknow)) { | |||
| GE_CHK_STATUS_RET(CalcOutputSize(n), "Calculate output size failed"); | |||
| } | |||
| ret = AdjustConstWeightSize(n, weight_offset_); | |||
| @@ -363,8 +366,11 @@ void ModelBuilder::InitL1FusionOption() { | |||
| string buffer_optimize = "off_optimize"; | |||
| graphStatus ret = ge::GetContext().GetOption(BUFFER_OPTIMIZE, buffer_optimize); | |||
| if (ret == GRAPH_SUCCESS) { | |||
| is_l1_fusion_enable_ = (buffer_optimize == "l1_optimize"); | |||
| GELOGD("The value of %s is %s.", BUFFER_OPTIMIZE.c_str(), buffer_optimize.c_str()); | |||
| bool off_superkernel = false; | |||
| (void)AttrUtils::GetBool(compute_graph_, ATTR_NAME_OFF_SUPERKERNEL_ATTR, off_superkernel); | |||
| is_l1_fusion_enable_ = ((buffer_optimize == "l1_optimize") && (!off_superkernel)); | |||
| GELOGI("Compute graph %s the value of %s is %s, superkernel flag %d.", compute_graph_->GetName().c_str(), | |||
| BUFFER_OPTIMIZE.c_str(), buffer_optimize.c_str(), is_l1_fusion_enable_); | |||
| } else { | |||
| GELOGW("The value of %s is empty.", kEnableL1Fusion.c_str()); | |||
| } | |||
| @@ -429,7 +435,7 @@ Status ModelBuilder::BuildModelDef(ge::Model &model) { | |||
| GE_CHK_BOOL_EXEC(ge::AttrUtils::SetBool(&model, ATTR_NAME_SWITCH_FOR_L1_FUSION, is_l1_fusion_enable_), | |||
| GELOGE(FAILED, "SetBool of ATTR_NAME_SWITCH_FOR_L1_FUSION failed."); | |||
| return FAILED); | |||
| const DumpProperties &dump_properties = PropertiesManager::Instance().GetDumpProperties(session_id_); | |||
| const DumpProperties &dump_properties = DumpManager::GetInstance().GetDumpProperties(session_id_); | |||
| bool is_op_debug = dump_properties.IsOpDebugOpen(); | |||
| if (is_op_debug) { | |||
| if (!ge::AttrUtils::SetBool(&model, ATTR_OP_DEBUG_FLAG, is_op_debug)) { | |||
| @@ -683,6 +689,7 @@ Status ModelBuilder::PreBuildModel() { | |||
| Status ModelBuilder::BuildModelForGetTask(ge::Model &model) { | |||
| GE_CHK_STATUS_RET(AdjustInputTensorFlag(), "AdjustInputTensorFlag failed!"); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kStreamAlloc); | |||
| // Assign logical streams. | |||
| StreamAllocator stream_allocator(compute_graph_, subgraphs_); | |||
| GE_TIMESTAMP_START(AssignLogicalStreams); | |||
| @@ -690,6 +697,7 @@ Status ModelBuilder::BuildModelForGetTask(ge::Model &model) { | |||
| "Assign logical streams failed."); | |||
| GE_TIMESTAMP_END(AssignLogicalStreams, "GraphBuilder::AssignLogicalStreams"); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kMemoryAlloc); | |||
| // Assign functional op labels. | |||
| auto root_graph = GraphUtils::FindRootGraph(compute_graph_); | |||
| (void)AttrUtils::GetInt(*root_graph, ATTR_MODEL_LABEL_NUM, label_num_); | |||
| @@ -700,22 +708,25 @@ Status ModelBuilder::BuildModelForGetTask(ge::Model &model) { | |||
| "Assign Memory Failed!"); | |||
| GE_TIMESTAMP_END(AssignMemory, "GraphBuilder::AssignMemory"); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GE_TIMESTAMP_START(SetInputOutputOffset); | |||
| SetInputOutputOffsetPass input_output_offset; | |||
| GE_CHK_STATUS_RET(input_output_offset.Run(compute_graph_), "Set input output offset failed."); | |||
| GE_TIMESTAMP_END(SetInputOutputOffset, "SetInputOutputOffsetPass::Run."); | |||
| GE_TIMESTAMP_END(SetInputOutputOffset, "SetInputOutputOffsetPass::Run"); | |||
| // Compile single op in graph build stage | |||
| GE_TIMESTAMP_START(CompileSingleOp); | |||
| GE_CHK_STATUS_RET(CompileSingleOp(), "ATC builder CompileSingleOp() return fail."); | |||
| GE_TIMESTAMP_EVENT_END(CompileSingleOp, "GraphBuilder::CompileSingleOp"); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kStreamAlloc); | |||
| // Refresh real streams and insert event nodes. | |||
| GE_TIMESTAMP_START(RefreshRealStream); | |||
| GE_CHK_STATUS_RET(stream_allocator.RefreshRealStream(stream_num_, event_num_), "RefreshRealStream failed."); | |||
| huge_streams_ = stream_allocator.GetHugeStreams(); | |||
| GE_TIMESTAMP_END(RefreshRealStream, "GraphBuilder::RefreshRealStream"); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GE_TIMESTAMP_START(MergeWeights); | |||
| GE_CHK_STATUS_RET(MergeWeights(), "MergeWeights Failed!"); | |||
| GE_TIMESTAMP_END(MergeWeights, "GraphBuilder::MergeWeights"); | |||
| @@ -852,7 +852,7 @@ Status TaskGenerator::FindProfilingTaskIndex(const ComputeGraphPtr &graph, Profi | |||
| // subgraph of dynamic graph no need to find index, has been found in parent graph | |||
| if (IsSubGraphOfDynamicGraph(graph)) { | |||
| GELOGI("Graph[%s] is subgraph of dynamic graph, no nned to find index.", graph->GetName().c_str()); | |||
| GELOGI("Graph[%s] is subgraph of dynamic graph, no need to find index.", graph->GetName().c_str()); | |||
| return SUCCESS; | |||
| } | |||
| @@ -1042,7 +1042,7 @@ Status TaskGenerator::InsertProfilingTaskAfter(const OpDescPtr &op_desc, const P | |||
| } | |||
| GELOGD("Insert bp profiling task: %d, insert end profiling task: %d, fp index: %u, bp index: %u, end index size: %zu", | |||
| is_insert_bp_profiling_task, is_insert_end_profiling_task, profiling_point.fp_index, profiling_point.bp_index, | |||
| profiling_point.end_index.size() ); | |||
| profiling_point.end_index.size()); | |||
| bool is_all_reduce = (op_desc->GetType() == HCOMALLREDUCE || op_desc->GetType() == HVDCALLBACKALLREDUCE); | |||
| if ((profiling_point.bp_index == node_index) || (!is_all_reduce && is_insert_bp_profiling_task)) { | |||
| @@ -19,12 +19,8 @@ | |||
| #include <memory> | |||
| #include <string> | |||
| #include "common/ge_inner_error_codes.h" | |||
| #include "common/model_parser/base.h" | |||
| #include "graph/load/model_manager/model_manager.h" | |||
| #include "omm/csa_interact.h" | |||
| #include "runtime/dev.h" | |||
| #include "runtime/mem.h" | |||
| namespace ge { | |||
| GraphExecutor::GraphExecutor() | |||
| @@ -20,19 +20,13 @@ | |||
| #include <vector> | |||
| #include "common/helper/model_helper.h" | |||
| #include "common/util.h" | |||
| #include "common/model_parser/model_parser.h" | |||
| #include "graph/ge_context.h" | |||
| #include "graph/load/model_manager/davinci_model_parser.h" | |||
| #include "graph/load/model_manager/model_manager.h" | |||
| #include "graph/manager/graph_var_manager.h" | |||
| #include "omm/csa_interact.h" | |||
| #include "runtime/dev.h" | |||
| namespace ge { | |||
| GraphLoader::GraphLoader() = default; | |||
| GraphLoader::~GraphLoader() = default; | |||
| Status GraphLoader::UnloadModel(uint32_t model_id) { | |||
| auto model_manager = ModelManager::GetInstance(); | |||
| GE_CHECK_NOTNULL(model_manager); | |||
| @@ -120,7 +114,6 @@ Status GraphLoader::GetMaxUsedMemory(uint32_t model_id, uint64_t &max_size) { | |||
| Status GraphLoader::LoadDataFromFile(const std::string &path, const std::string &key_path, int32_t priority, | |||
| ModelData &model_data) { | |||
| Status ret; | |||
| if (!CheckInputPathValid(path)) { | |||
| GELOGE(ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID, "model path is invalid: %s", path.c_str()); | |||
| return ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID; | |||
| @@ -132,16 +125,15 @@ Status GraphLoader::LoadDataFromFile(const std::string &path, const std::string | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| ret = DavinciModelParser::LoadFromFile(path.c_str(), key_path.c_str(), priority, model_data); | |||
| Status ret = ModelParserBase::LoadFromFile(path.c_str(), key_path.c_str(), priority, model_data); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "LoadModelFromFile: Load failed. ret = %u", ret); | |||
| if (model_data.model_data != nullptr) { | |||
| delete[] static_cast<char *>(model_data.model_data); | |||
| model_data.model_data = nullptr; | |||
| } | |||
| return ret; | |||
| } | |||
| return SUCCESS; | |||
| return ret; | |||
| } | |||
| Status GraphLoader::CommandHandle(const Command &command) { | |||
| @@ -32,9 +32,9 @@ | |||
| namespace ge { | |||
| class GraphLoader { | |||
| public: | |||
| GraphLoader(); | |||
| GraphLoader() = default; | |||
| virtual ~GraphLoader(); | |||
| virtual ~GraphLoader() = default; | |||
| GraphLoader(const GraphLoader &in) = delete; | |||
| @@ -36,21 +36,9 @@ | |||
| namespace ge { | |||
| class DataDumper { | |||
| public: | |||
| explicit DataDumper(const RuntimeParam &rsh) | |||
| : model_name_(), | |||
| model_id_(0), | |||
| runtime_param_(rsh), | |||
| dev_mem_load_(nullptr), | |||
| dev_mem_unload_(nullptr), | |||
| op_list_(), | |||
| input_map_(), | |||
| load_flag_(false), | |||
| device_id_(0), | |||
| global_step_(0), | |||
| loop_per_iter_(0), | |||
| loop_cond_(0), | |||
| compute_graph_(nullptr), | |||
| ref_info_() {} | |||
| DataDumper() : runtime_param_{} {} | |||
| explicit DataDumper(const RuntimeParam &rsh) : runtime_param_(rsh) {} | |||
| ~DataDumper(); | |||
| @@ -105,10 +93,10 @@ class DataDumper { | |||
| // for inference data dump | |||
| std::string om_name_; | |||
| uint32_t model_id_; | |||
| uint32_t model_id_ = 0; | |||
| const RuntimeParam &runtime_param_; | |||
| void *dev_mem_load_; | |||
| void *dev_mem_unload_; | |||
| void *dev_mem_load_ = nullptr; | |||
| void *dev_mem_unload_ = nullptr; | |||
| struct InnerDumpInfo; | |||
| struct InnerInputMapping; | |||
| @@ -119,16 +107,15 @@ class DataDumper { | |||
| uint32_t end_graph_stream_id_ = 0; | |||
| bool is_end_graph_ = false; | |||
| std::multimap<std::string, InnerInputMapping> input_map_; // release after DavinciModel::Init | |||
| bool load_flag_; | |||
| uint32_t device_id_; | |||
| uintptr_t global_step_; | |||
| uintptr_t loop_per_iter_; | |||
| uintptr_t loop_cond_; | |||
| ComputeGraphPtr compute_graph_; // release after DavinciModel::Init | |||
| std::map<OpDescPtr, void *> ref_info_; // release after DavinciModel::Init | |||
| bool load_flag_ = false; | |||
| uint32_t device_id_ = 0; | |||
| uintptr_t global_step_ = 0; | |||
| uintptr_t loop_per_iter_ = 0; | |||
| uintptr_t loop_cond_ = 0; | |||
| ComputeGraphPtr compute_graph_ = nullptr; // release after DavinciModel::Init | |||
| std::map<OpDescPtr, void *> ref_info_; // release after DavinciModel::Init | |||
| void *l1_fusion_addr_ = nullptr; | |||
| uint32_t op_debug_task_id_ = 0; | |||
| uint32_t op_debug_stream_id_ = 0; | |||
| void *op_debug_addr_ = nullptr; | |||
| @@ -144,20 +131,16 @@ class DataDumper { | |||
| Status DumpOutputWithTask(const InnerDumpInfo &inner_dump_info, aicpu::dump::Task &task); | |||
| Status DumpInput(const InnerDumpInfo &inner_dump_info, aicpu::dump::Task &task); | |||
| Status DumpRefInput(const DataDumper::InnerDumpInfo &inner_dump_info, aicpu::dump::Input &input, size_t i, | |||
| const std::string &node_name_index); | |||
| const std::string &node_name_index); | |||
| Status ExecuteLoadDumpInfo(aicpu::dump::OpMappingInfo &op_mapping_info); | |||
| void SetEndGraphIdToAicpu(uint32_t task_id, uint32_t stream_id, aicpu::dump::OpMappingInfo &op_mapping_info); | |||
| void SetOpDebugIdToAicpu(uint32_t task_id, uint32_t stream_id, void *op_debug_addr, | |||
| aicpu::dump::OpMappingInfo &op_mapping_info); | |||
| Status ExecuteUnLoadDumpInfo(aicpu::dump::OpMappingInfo &op_mapping_info); | |||
| Status GenerateInput(aicpu::dump::Input &input, | |||
| const OpDesc::Vistor<GeTensorDesc> &tensor_descs, | |||
| const uintptr_t &addr, | |||
| size_t index); | |||
| Status GenerateOutput(aicpu::dump::Output &output, | |||
| const OpDesc::Vistor<GeTensorDesc> &tensor_descs, | |||
| const uintptr_t &addr, | |||
| size_t index); | |||
| Status GenerateInput(aicpu::dump::Input &input, const OpDesc::Vistor<GeTensorDesc> &tensor_descs, | |||
| const uintptr_t &addr, size_t index); | |||
| Status GenerateOutput(aicpu::dump::Output &output, const OpDesc::Vistor<GeTensorDesc> &tensor_descs, | |||
| const uintptr_t &addr, size_t index); | |||
| void GenerateOpBuffer(const int64_t &size, aicpu::dump::Task &task); | |||
| }; | |||
| struct DataDumper::InnerDumpInfo { | |||
| @@ -92,12 +92,39 @@ const uint32_t kEndOfSequence = 0x0704000a; | |||
| const uint32_t kEndOfSequenceNew = 507005; | |||
| const int32_t kModelAbortNormal = 0x0704000e; | |||
| const int32_t kModelAbortNormalNew = 507024; | |||
| const uint32_t kInteval = 2; | |||
| const char *const kModelName = "model_name"; | |||
| const char *const kModeleId = "model_id"; | |||
| const char *const kLoadStartTime = "load_start_time"; | |||
| const char *const kLoadEndTime = "load_end_time"; | |||
| const char *const kFusionOpInfo = "fusion_op_info"; | |||
| const char *const kFusionOpName = "fusion_op_name"; | |||
| const char *const kOriginalOpNum = "origin_op_num"; | |||
| const char *const kOriginalOpName = "origin_op_name"; | |||
| const char *const kStreamId = "stream_id"; | |||
| const char *const kFusionOpMemoryInfo = "memory_info"; | |||
| const char *const kInputSize = "input_size"; | |||
| const char *const kOutputSize = "output_size"; | |||
| const char *const kWeightSize = "weight_size"; | |||
| const char *const kWorkSpaceSize = "workspace_size"; | |||
| const char *const kTotalSize = "total_size"; | |||
| const char *const kTaskCount = "task_count"; | |||
| const char *const kTaskId = "task_id"; | |||
| const char* const kRequestId = "request_id"; | |||
| const char* const kThreadId = "thread_id"; | |||
| const char* const kInputBeginTime = "input_begin_time"; | |||
| const char* const kInputEndTime = "input_end_time"; | |||
| const char* const kInferBeginTime = "infer_begin_time"; | |||
| const char* const kInferEndTime = "infer_end_time"; | |||
| const char* const kOutputBeginTime = "output_start_time"; | |||
| const char* const kOutputEndTime = "output_end_time"; | |||
| const uint32_t kStringHeadElems = 2; | |||
| inline bool IsDataOp(const std::string &node_type) { | |||
| return node_type == DATA_TYPE || node_type == AIPP_DATA_TYPE || node_type == ANN_DATA_TYPE; | |||
| return (node_type == DATA_TYPE) || (node_type == AIPP_DATA_TYPE) || (node_type == ANN_DATA_TYPE); | |||
| } | |||
| inline bool IsTbeTask(const OpDescPtr &op_desc) { | |||
| bool IsTbeTask(const OpDescPtr &op_desc) { | |||
| uint32_t run_mode = static_cast<uint32_t>(domi::ImplyType::INVALID); | |||
| if (!AttrUtils::GetInt(op_desc, ATTR_NAME_IMPLY_TYPE, run_mode)) { | |||
| return false; | |||
| @@ -187,12 +214,12 @@ DavinciModel::~DavinciModel() { | |||
| UnbindTaskSinkStream(); | |||
| for (size_t i = 0; i < label_list_.size(); ++i) { | |||
| if (label_list_[i] != nullptr) { | |||
| GE_LOGW_IF(rtLabelDestroy(label_list_[i]) != RT_ERROR_NONE, "Destroy label failed, index: %zu", i); | |||
| GE_LOGW_IF(rtLabelDestroy(label_list_[i]) != RT_ERROR_NONE, "Destroy label failed, index:%zu.", i); | |||
| } | |||
| } | |||
| for (size_t i = 0; i < stream_list_.size(); ++i) { | |||
| GE_LOGW_IF(rtStreamDestroy(stream_list_[i]) != RT_ERROR_NONE, "Destroy stream failed, index: %zu", i); | |||
| GE_LOGW_IF(rtStreamDestroy(stream_list_[i]) != RT_ERROR_NONE, "Destroy stream failed, index:%zu.", i); | |||
| } | |||
| for (size_t i = 0; i < event_list_.size(); ++i) { | |||
| @@ -205,6 +232,8 @@ DavinciModel::~DavinciModel() { | |||
| FreeP2PMem(); | |||
| OpDebugUnRegister(); | |||
| if (l1_fusion_addr_ != nullptr) { | |||
| GE_CHK_RT(rtFree(l1_fusion_addr_)); | |||
| } | |||
| @@ -215,8 +244,6 @@ DavinciModel::~DavinciModel() { | |||
| } | |||
| } | |||
| OpDebugUnRegister(); | |||
| ReleaseTask(); | |||
| CleanTbeHandle(); | |||
| @@ -251,7 +278,7 @@ void DavinciModel::UnbindHcomStream() { | |||
| for (size_t i = 0; i < all_hccl_stream_list_.size(); i++) { | |||
| GE_LOGW_IF(rtModelUnbindStream(rt_model_handle_, all_hccl_stream_list_[i]) != RT_ERROR_NONE, | |||
| "Unbind hccl stream from model failed! Index: %zu", i); | |||
| GE_LOGW_IF(rtStreamDestroy(all_hccl_stream_list_[i]) != RT_ERROR_NONE, "Destroy hccl stream for rt_model failed!") | |||
| GE_LOGW_IF(rtStreamDestroy(all_hccl_stream_list_[i]) != RT_ERROR_NONE, "Destroy hccl stream for rt_model failed") | |||
| } | |||
| } | |||
| return; | |||
| @@ -337,7 +364,7 @@ Status DavinciModel::InitWeightMem(void *dev_ptr, void *weight_ptr, size_t weigh | |||
| Status DavinciModel::InitFeatureMapAndP2PMem(void *dev_ptr, size_t mem_size) { | |||
| if (is_feature_map_mem_has_inited_) { | |||
| GELOGE(PARAM_INVALID, "call InitFeatureMapMem more than once."); | |||
| GELOGE(PARAM_INVALID, "call InitFeatureMapMem more than once"); | |||
| return PARAM_INVALID; | |||
| } | |||
| is_feature_map_mem_has_inited_ = true; | |||
| @@ -391,7 +418,7 @@ Status DavinciModel::InitFeatureMapAndP2PMem(void *dev_ptr, size_t mem_size) { | |||
| Status DavinciModel::InitVariableMem() { | |||
| // malloc variable memory base | |||
| var_mem_base_ = VarManager::Instance(session_id_)->GetVarMemoryBase(RT_MEMORY_HBM); | |||
| if (TotalVarMemSize() && var_mem_base_ == nullptr) { | |||
| if (TotalVarMemSize() && (var_mem_base_ == nullptr)) { | |||
| Status ret = VarManager::Instance(session_id_)->MallocVarMemory(TotalVarMemSize()); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Malloc variable memory failed."); | |||
| @@ -453,7 +480,7 @@ void DavinciModel::CheckHasHcomOp(const ComputeGraphPtr &compute_graph) { | |||
| for (const auto &node : compute_graph->GetAllNodes()) { | |||
| OpDescPtr op_desc = node->GetOpDesc(); | |||
| GE_IF_BOOL_EXEC(op_desc == nullptr, GELOGW("Node OpDesc is nullptr"); continue); | |||
| GE_IF_BOOL_EXEC(op_desc == nullptr, GELOGW("Node OpDesc is nullptr."); continue); | |||
| if (hcom_opp_types.count(op_desc->GetType()) > 0) { | |||
| uint32_t stream_id = static_cast<uint32_t>(op_desc->GetStreamId()); | |||
| hcom_streams_.emplace(stream_id); | |||
| @@ -500,25 +527,25 @@ Status DavinciModel::DoTaskSink() { | |||
| } | |||
| GE_CHK_RT_RET(rtGetAicpuDeploy(&deploy_type_)); | |||
| GELOGI("do task_sink. AiCpu deploy type is: %x.", deploy_type_); | |||
| GELOGI("Do task_sink. AiCpu deploy type is: %x.", deploy_type_); | |||
| GE_CHK_STATUS_RET(BindModelStream(), "Bind model stream failed."); | |||
| if (known_node_) { | |||
| GE_CHK_STATUS_RET(MallocKnownArgs(), "Mallloc known node args failed."); | |||
| GE_CHK_STATUS_RET(MallocKnownArgs(), "Mallloc known node's args failed"); | |||
| } | |||
| GE_CHK_STATUS_RET(InitTaskInfo(*model_task_def.get()), "InitTaskInfo failed."); | |||
| GE_CHK_STATUS_RET(InitTaskInfo(*model_task_def.get()), "InitTaskInfo failed"); | |||
| GE_CHK_STATUS_RET(ModelManager::GetInstance()->LaunchCustAicpuSo(), "Launch cust aicpu so failed."); | |||
| GE_CHK_STATUS_RET(ModelManager::GetInstance()->LaunchCustAicpuSo(), "Launch cust aicpu so failed"); | |||
| GE_CHK_STATUS_RET(ModelManager::GetInstance()->CheckAicpuOpList(ge_model_), "Check aicpu op type failed."); | |||
| GE_CHK_STATUS_RET(ModelManager::GetInstance()->CheckAicpuOpList(ge_model_), "Check aicpu op type failed"); | |||
| GE_CHK_STATUS_RET(InitEntryTask(), "InitEntryTask failed."); | |||
| GE_CHK_STATUS_RET(InitEntryTask(), "InitEntryTask failed"); | |||
| GE_CHK_STATUS_RET(InitL1DataDumperArgs(), "InitL1DataDumperArgs failed."); | |||
| GE_CHK_STATUS_RET(InitL1DataDumperArgs(), "InitL1DataDumperArgs failed"); | |||
| GE_CHK_STATUS_RET(DistributeTask(), "Distribute failed."); | |||
| GE_CHK_STATUS_RET(DistributeTask(), "Distribute failed"); | |||
| GE_CHK_RT_RET(rtModelLoadComplete(rt_model_handle_)); | |||
| @@ -531,7 +558,7 @@ Status DavinciModel::SetTSDevice() { | |||
| int64_t value = 0; | |||
| bool ret = ge::AttrUtils::GetInt(ge_model_, ATTR_MODEL_CORE_TYPE, value); | |||
| uint32_t core_type = ret ? static_cast<uint32_t>(value) : 0; | |||
| GELOGD("SetTSDevice: %u", core_type); | |||
| GELOGD("SetTSDevice: %u.", core_type); | |||
| rtError_t rt_ret = rtSetTSDevice(core_type); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "SetTSDevice failed, ret: 0x%X", rt_ret); | |||
| @@ -541,77 +568,21 @@ Status DavinciModel::SetTSDevice() { | |||
| } | |||
| Status DavinciModel::OpDebugRegister() { | |||
| bool is_op_debug = false; | |||
| (void)ge::AttrUtils::GetBool(ge_model_, ATTR_OP_DEBUG_FLAG, is_op_debug); | |||
| GELOGD("The value of op debug in ge_model is %d.", is_op_debug); | |||
| if (is_op_debug) { | |||
| debug_reg_mutex_.lock(); | |||
| rtError_t rt_ret = rtMalloc(&op_debug_addr_, kOpDebugMemorySize, RT_MEMORY_DDR); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "rtMalloc error, ret: 0x%X", rt_ret); | |||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
| } | |||
| uint64_t debug_addrs_tmp = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(op_debug_addr_)); | |||
| // For data dump, aicpu needs the pointer to pointer that save the real debug address. | |||
| rt_ret = rtMalloc(&p2p_debug_addr_, kDebugP2pSize, RT_MEMORY_HBM); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "rtMalloc error, ret: 0x%X", rt_ret); | |||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
| } | |||
| rt_ret = rtMemcpy(p2p_debug_addr_, sizeof(uint64_t), &debug_addrs_tmp, sizeof(uint64_t), RT_MEMCPY_HOST_TO_DEVICE); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "rtMemcpy to p2p_addr error: 0x%X", rt_ret); | |||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
| } | |||
| uint32_t op_debug_mode = 0; | |||
| (void)ge::AttrUtils::GetInt(ge_model_, ATTR_OP_DEBUG_MODE, op_debug_mode); | |||
| GELOGD("The value of op_debug_mode in ge_model_ is %u.", op_debug_mode); | |||
| uint32_t debug_task_id = 0; | |||
| uint32_t debug_stream_id = 0; | |||
| rt_ret = rtDebugRegister(rt_model_handle_, op_debug_mode, op_debug_addr_, &debug_stream_id, &debug_task_id); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "rtDebugRegister error, ret: 0x%X", rt_ret); | |||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
| if (GetDumpProperties().IsOpDebugOpen()) { | |||
| uint32_t op_debug_mode = GetDumpProperties().GetOpDebugMode(); | |||
| auto ret = opdebug_register_.RegisterDebugForModel(rt_model_handle_, op_debug_mode, data_dumper_); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret,"Register known shape op debug failed, ret: 0x%X",ret); | |||
| return ret; | |||
| } | |||
| GELOGI("debug_task_id:%d, debug_stream_id:%u", debug_task_id, debug_stream_id); | |||
| is_op_debug_reg_ = true; | |||
| data_dumper_.SaveOpDebugId(debug_task_id, debug_stream_id, p2p_debug_addr_, is_op_debug); | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| void DavinciModel::OpDebugUnRegister() { | |||
| if (is_op_debug_reg_) { | |||
| debug_reg_mutex_.unlock(); | |||
| rtError_t rt_ret = RT_ERROR_NONE; | |||
| if (rt_model_handle_ != nullptr) { | |||
| GELOGD("start call debug_unregister."); | |||
| rt_ret = rtDebugUnRegister(rt_model_handle_); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGW("rtDebugUnRegister failed, ret: 0x%X", rt_ret); | |||
| } | |||
| } | |||
| if (op_debug_addr_ != nullptr) { | |||
| rt_ret = rtFree(op_debug_addr_); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGW("rtFree failed, ret: 0x%X", rt_ret); | |||
| } | |||
| op_debug_addr_ = nullptr; | |||
| } | |||
| if (p2p_debug_addr_ != nullptr) { | |||
| rt_ret = rtFree(p2p_debug_addr_); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGW("rtFree failed, ret: 0x%X", rt_ret); | |||
| } | |||
| p2p_debug_addr_ = nullptr; | |||
| } | |||
| opdebug_register_.UnregisterDebugForModel(rt_model_handle_); | |||
| is_op_debug_reg_ = false; | |||
| } | |||
| return; | |||
| @@ -620,9 +591,9 @@ void DavinciModel::OpDebugUnRegister() { | |||
| // initialize op sequence and call initialization function of each op respectively | |||
| Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size_t weight_size) { | |||
| // validating params | |||
| GELOGI("Priority is %d", priority_); | |||
| GELOGI("Priority is %d.", priority_); | |||
| GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(priority_ < 0 || priority_ > 7, return PARAM_INVALID, | |||
| "Priority must between 0-7, now is %d", priority_); | |||
| "Priority must between 0-7, now is %d.", priority_); | |||
| GE_CHK_BOOL_RET_STATUS(ge_model_ != nullptr, PARAM_INVALID, "GeModel is null."); | |||
| Graph graph = ge_model_->GetGraph(); | |||
| ComputeGraphPtr compute_graph = GraphUtils::GetComputeGraph(graph); | |||
| @@ -632,7 +603,7 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size | |||
| InitRuntimeParams(); | |||
| // RTS set aicore or vectorcore | |||
| GE_CHK_STATUS_RET(SetTSDevice(), "SetTSDevice failed"); | |||
| GE_CHK_STATUS_RET(SetTSDevice(), "SetTSDevice failed."); | |||
| version_ = ge_model_->GetVersion(); | |||
| name_ = ge_model_->GetName(); | |||
| @@ -683,7 +654,7 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size | |||
| runtime_param_.graph_id = compute_graph->GetGraphID(); | |||
| // op debug register | |||
| GE_CHK_STATUS_RET(OpDebugRegister(), "OpDebugRegister failed"); | |||
| GE_CHK_STATUS_RET(OpDebugRegister(), "OpDebugRegister failed."); | |||
| GE_TIMESTAMP_START(TransAllVarData); | |||
| GE_CHK_STATUS_RET(TransAllVarData(compute_graph, runtime_param_.graph_id), "TransAllVarData failed."); | |||
| @@ -691,7 +662,7 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size | |||
| GE_CHK_STATUS_RET(TransVarDataUtils::CopyVarData(compute_graph, session_id_, device_id_), "copy var data failed."); | |||
| GE_TIMESTAMP_START(InitModelMem); | |||
| GELOGD("Known node is %d", known_node_); | |||
| GELOGD("Known node is %d.", known_node_); | |||
| GE_CHK_STATUS_RET_NOLOG(InitWeightMem(dev_ptr, weight_ptr, weight_size)); | |||
| if (!known_node_) { | |||
| GE_CHK_STATUS_RET_NOLOG(InitFeatureMapAndP2PMem(dev_ptr, mem_size)); | |||
| @@ -709,10 +680,10 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size | |||
| (void)ge::AttrUtils::SetStr(op_desc, VAR_ATTR_VAR_IS_BROADCAST, "var_is_restore");); | |||
| } | |||
| GE_CHK_STATUS_RET(InitNodes(compute_graph), "Init nodes failed"); | |||
| GE_CHK_STATUS_RET(InitNodes(compute_graph), "Init nodes failed."); | |||
| GE_TIMESTAMP_START(DoTaskSink); | |||
| GE_CHK_STATUS_RET(DoTaskSink(), "Task sink failed"); | |||
| GE_CHK_STATUS_RET(DoTaskSink(), "Task sink failed."); | |||
| GE_TIMESTAMP_END(DoTaskSink, "GraphLoader::DoTaskSink"); | |||
| /// In zero copy model, if a aicpu operator is connected to the first or last layer, before model execution, | |||
| @@ -739,18 +710,12 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size | |||
| } | |||
| } | |||
| CREATE_STD_THREAD(shrink_id_, &DavinciModel::Shrink, this); | |||
| Shrink(); | |||
| return SUCCESS; | |||
| } | |||
| Status DavinciModel::ReportProfilingData() { | |||
| std::vector<ComputeGraphDescInfo> compute_graph_desc_info; | |||
| Status ret = GetComputeGraphInfo(compute_graph_desc_info); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "GetComputeGraphInfo failed."); | |||
| return ret; | |||
| } | |||
| ProfilingManager::Instance().ReportProfilingData(model_id_, GetTaskDescInfo(), compute_graph_desc_info); | |||
| ProfilingManager::Instance().ReportProfilingData(model_id_, GetTaskDescInfo()); | |||
| GE_CHK_STATUS(SinkModelProfile(), "Sink model profiler failed."); | |||
| return SUCCESS; | |||
| @@ -1193,7 +1158,7 @@ void DavinciModel::GetAllGearsInfo(const NodePtr &node) { | |||
| } | |||
| if (!gear_info.empty()) { | |||
| all_gears_info_.emplace_back(gear_info); | |||
| GELOGD("Init all gears info from %s, gaer info is %s.", node->GetName().c_str(), | |||
| GELOGD("Init all gears info from %s, gaer info is %s", node->GetName().c_str(), | |||
| formats::JoinToString(gear_info).c_str()); | |||
| } | |||
| } | |||
| @@ -1262,7 +1227,7 @@ Status DavinciModel::GetGearAndRealOutSizeInfo(const ComputeGraphPtr &graph, con | |||
| Status DavinciModel::GetRealOutputSizeOfCase(const ComputeGraphPtr &graph, size_t input_index, | |||
| const NodePtr &case_node) { | |||
| GELOGD("Start get output size of %s, which is %zu input to netoutput.", case_node->GetName().c_str(), input_index); | |||
| GELOGD("Start get output size of %s, which is %zu input to netoutput", case_node->GetName().c_str(), input_index); | |||
| const auto &func_desc = case_node->GetOpDesc(); | |||
| GE_CHECK_NOTNULL(func_desc); | |||
| std::map<vector<int32_t>, int64_t> gear_and_real_out_size_info; | |||
| @@ -1307,7 +1272,7 @@ Status DavinciModel::GetRealOutputSizeOfCase(const ComputeGraphPtr &graph, size_ | |||
| } | |||
| Status DavinciModel::GetGearAndRealOutShapeInfo(const ComputeGraphPtr &graph, const NodePtr &node) { | |||
| GELOGD("Start to get dynamic output dims of %s.", node->GetName().c_str()); | |||
| GELOGD("Start to get dynamic output dims of %s", node->GetName().c_str()); | |||
| merge_nodes_gear_and_real_out_shape_info_.clear(); | |||
| size_t idx = 0; | |||
| for (const auto &in_anchor : node->GetAllInDataAnchors()) { | |||
| @@ -1321,7 +1286,7 @@ Status DavinciModel::GetGearAndRealOutShapeInfo(const ComputeGraphPtr &graph, co | |||
| if ((peer_node->GetType() == CASE) && (op_desc->HasAttr(ATTR_INSERT_BY_MBATCH))) { | |||
| std::vector<std::string> dynamic_output_shape_info; | |||
| if (!AttrUtils::GetListStr(node->GetOpDesc(), ATTR_NAME_DYNAMIC_OUTPUT_DIMS, dynamic_output_shape_info)) { | |||
| GELOGD("Can not get dynamic output dims attr from %s.", node->GetName().c_str()); | |||
| GELOGD("Can not get dynamic output dims attr from %s", node->GetName().c_str()); | |||
| return SUCCESS; | |||
| } | |||
| GELOGI("Dynamic output shape info is %s", formats::JoinToString(dynamic_output_shape_info).c_str()); | |||
| @@ -1341,7 +1306,7 @@ Status DavinciModel::GetGearAndRealOutShapeInfo(const ComputeGraphPtr &graph, co | |||
| output_shape.emplace_back(it[i]); | |||
| } | |||
| gear_and_real_out_shape_info[all_gears_info_[gear_index]] = output_shape; | |||
| GELOGD("Get real gear index is: %zu, gear info is %s, output shape is %s.", | |||
| GELOGD("Get real gear index is: %zu, gear info is %s, output shape is %s", | |||
| gear_index, formats::JoinToString(all_gears_info_[gear_index]).c_str(), | |||
| formats::JoinToString(output_shape).c_str()); | |||
| } | |||
| @@ -1364,7 +1329,7 @@ void DavinciModel::ParseDynamicOutShape(const std::vector<std::string> &str_info | |||
| } | |||
| shape.emplace_back(std::strtol(dim.c_str(), nullptr, kDecimal)); | |||
| } | |||
| GELOGI("Shape from attr is %s.", formats::JoinToString(shape).c_str()); | |||
| GELOGI("Shape from attr is %s", formats::JoinToString(shape).c_str()); | |||
| vec_info.emplace_back(shape); | |||
| } | |||
| } | |||
| @@ -1407,7 +1372,7 @@ Status DavinciModel::InitLabelSet(const OpDescPtr &op_desc) { | |||
| return INTERNAL_ERROR; | |||
| } | |||
| GELOGI("InitLabelSet: label[%u]=%p stream[%u]=%p.", label_index, rt_label, stream_id, stream); | |||
| GELOGI("InitLabelSet: label[%u]=%p stream[%u]=%p", label_index, rt_label, stream_id, stream); | |||
| label_id_indication_.insert(label_index); | |||
| label_list_[label_index] = rt_label; | |||
| return SUCCESS; | |||
| @@ -1810,7 +1775,7 @@ void DavinciModel::GetUserDesignateShapeOrder(std::vector<std::string> &user_inp | |||
| /// | |||
| Status DavinciModel::InitAippInfo(uint32_t index, const OpDescPtr &op_desc) { | |||
| if (!op_desc->HasAttr(ATTR_NAME_AIPP)) { | |||
| GELOGW("There is not AIPP related with index %u.", index); | |||
| GELOGW("There is not AIPP related with index %u", index); | |||
| return SUCCESS; | |||
| } | |||
| @@ -1840,7 +1805,7 @@ Status DavinciModel::InitAippInfo(uint32_t index, const OpDescPtr &op_desc) { | |||
| Status DavinciModel::GetAippInfo(uint32_t index, AippConfigInfo &aipp_info) const { | |||
| const auto it = aipp_info_list_.find(index); | |||
| if (it == aipp_info_list_.end()) { | |||
| GELOGW("there is not AIPP related with index %u.", index); | |||
| GELOGW("there is not AIPP related with index %u", index); | |||
| return ACL_ERROR_GE_AIPP_NOT_EXIST; | |||
| } | |||
| @@ -1850,7 +1815,7 @@ Status DavinciModel::GetAippInfo(uint32_t index, AippConfigInfo &aipp_info) cons | |||
| Status DavinciModel::InitAippType(uint32_t index, const OpDescPtr &op_desc, const map<uint32_t, OpDescPtr> &data_list) { | |||
| if (!op_desc->HasAttr(ATTR_DATA_RELATED_AIPP_MODE)) { | |||
| GELOGW("There is no aipp releated info with index %u.", index); | |||
| GELOGW("There is no aipp releated info with index %u", index); | |||
| return SUCCESS; | |||
| } | |||
| @@ -1895,7 +1860,7 @@ Status DavinciModel::GetAippType(uint32_t index, InputAippType &aipp_type, size_ | |||
| GE_CHK_BOOL_RET_STATUS(index < input_addrs_list_.size(), PARAM_INVALID, "Index %u is invalid", index); | |||
| const auto it = aipp_type_list_.find(index); | |||
| if (it == aipp_type_list_.end()) { | |||
| GELOGW("There is no aipp releated info with index %u.", index); | |||
| GELOGW("There is no aipp releated info with index %u", index); | |||
| aipp_type = DATA_WITHOUT_AIPP; | |||
| aipp_index = 0xFFFFFFFF; | |||
| return SUCCESS; | |||
| @@ -2202,173 +2167,101 @@ Status DavinciModel::InitModelProfile() { | |||
| } | |||
| Status DavinciModel::SinkModelProfile() { | |||
| // profiling plugin must be registered | |||
| auto &prof_mgr = ProfilingManager::Instance(); | |||
| ReporterData reporter_data{}; | |||
| // report model data tag name | |||
| std::string tag_name("model_load_info_" + std::to_string(this->Id())); | |||
| GE_CHK_BOOL_EXEC(memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN, tag_name.c_str(), tag_name.size()) == EOK, | |||
| return FAILED, "Sink model tag memcpy error."); | |||
| // Model Header | |||
| std::string name = om_name_.empty() ? name_ : om_name_; | |||
| size_t name_len = name.size(); | |||
| reporter_data.deviceId = device_id_; | |||
| reporter_data.data = (unsigned char *)&name_len; | |||
| reporter_data.dataLen = sizeof(int32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| reporter_data.data = (unsigned char *)name.c_str(); | |||
| reporter_data.dataLen = name.size(); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| uint32_t model_id = this->Id(); | |||
| reporter_data.data = (unsigned char *)&model_id; | |||
| reporter_data.dataLen = sizeof(uint32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| // Load Start/End Time | |||
| int64_t start_time = this->GetLoadBeginTime(); | |||
| reporter_data.data = (unsigned char *)&start_time; | |||
| reporter_data.dataLen = sizeof(int64_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| int64_t end_time = this->GetLoadEndTime(); | |||
| reporter_data.data = (unsigned char *)&end_time; | |||
| reporter_data.dataLen = sizeof(int64_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| Json model_load_info; | |||
| model_load_info[kModelName] = name; | |||
| model_load_info[kModeleId] = model_id; | |||
| model_load_info[kLoadStartTime] = start_time; | |||
| model_load_info[kLoadEndTime] = end_time; | |||
| // fusion op info | |||
| using CIT = std::multimap<uint32_t, uint32_t>::const_iterator; | |||
| using Range = std::pair<CIT, CIT>; | |||
| for (const ProfileInfo &profile : profile_list_) { | |||
| // op name after fusion | |||
| Json fusion_op_info; | |||
| string fusion_op_name = profile.fusion_info.op_name; | |||
| int32_t fusion_op_name_len = fusion_op_name.size() == 0 ? 1 : fusion_op_name.size(); | |||
| reporter_data.data = (unsigned char *)&fusion_op_name_len; | |||
| reporter_data.dataLen = sizeof(int32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| reporter_data.data = (unsigned char *)fusion_op_name.c_str(); | |||
| reporter_data.dataLen = fusion_op_name_len; | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| // original op name before fusion | |||
| uint32_t op_num = profile.fusion_info.original_op_names.size(); | |||
| reporter_data.data = (unsigned char *)&op_num; | |||
| reporter_data.dataLen = sizeof(int32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| vector<string> original_name; | |||
| for (uint32_t k = 0; k < op_num; k++) { | |||
| std::string op_name = profile.fusion_info.original_op_names[k]; | |||
| int32_t op_name_len = op_name.size() == 0 ? 1 : op_name.size(); | |||
| reporter_data.data = (unsigned char *)&op_name_len; | |||
| reporter_data.dataLen = sizeof(int32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| reporter_data.data = (unsigned char *)op_name.c_str(); | |||
| reporter_data.dataLen = op_name_len; | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| } | |||
| // stream id info | |||
| original_name.emplace_back(profile.fusion_info.original_op_names[k]); | |||
| } | |||
| uint32_t stream_id = 0; | |||
| auto iter = profiler_report_op_info_.find(fusion_op_name); | |||
| if (iter != profiler_report_op_info_.end()) { | |||
| stream_id = iter->second.second; | |||
| } | |||
| reporter_data.data = (unsigned char *)&stream_id; | |||
| reporter_data.dataLen = sizeof(int32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| // memory info | |||
| reporter_data.data = (unsigned char *)&profile.memory_info; | |||
| reporter_data.dataLen = sizeof(profile.memory_info); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| // task info | |||
| reporter_data.data = (unsigned char *)&profile.task_count; | |||
| reporter_data.dataLen = sizeof(uint32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| fusion_op_info[kFusionOpName] = fusion_op_name; | |||
| fusion_op_info[kOriginalOpNum] = op_num; | |||
| fusion_op_info[kOriginalOpName] = original_name; | |||
| fusion_op_info[kStreamId] = stream_id; | |||
| fusion_op_info[kFusionOpMemoryInfo][kInputSize] = profile.memory_info.input_size; | |||
| fusion_op_info[kFusionOpMemoryInfo][kOutputSize] = profile.memory_info.output_size; | |||
| fusion_op_info[kFusionOpMemoryInfo][kWeightSize] = profile.memory_info.weight_size; | |||
| fusion_op_info[kFusionOpMemoryInfo][kWorkSpaceSize] = profile.memory_info.workspace_size; | |||
| fusion_op_info[kFusionOpMemoryInfo][kTotalSize] = profile.memory_info.total_size; | |||
| fusion_op_info[kTaskCount] = profile.task_count; | |||
| vector<uint32_t> task_id; | |||
| Range task_range = op_id_map_.equal_range(profile.fusion_info.op_index); | |||
| for (CIT idx = task_range.first; idx != task_range.second; ++idx) { | |||
| uint32_t task_id = idx->second; | |||
| reporter_data.data = (unsigned char *)&task_id; | |||
| reporter_data.dataLen = sizeof(uint32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| task_id.push_back(idx->second); | |||
| } | |||
| fusion_op_info[kTaskId] = task_id; | |||
| model_load_info[kFusionOpInfo] += fusion_op_info; | |||
| } | |||
| std::string tag_name("model_load_info_" + std::to_string(this->Id())); | |||
| std::string reported_data; | |||
| try { | |||
| reported_data = model_load_info.dump(kInteval, ' ', false, Json::error_handler_t::ignore); | |||
| } catch (std::exception &e) { | |||
| GELOGE(FAILED, "Failed to convert JSON to string, reason: %s.", e.what()); | |||
| } catch (...) { | |||
| GELOGE(FAILED, "Failed to convert JSON to string."); | |||
| } | |||
| reported_data.append(",") | |||
| .append("\n"); | |||
| prof_mgr.ReportData(device_id_, reported_data, tag_name); | |||
| return SUCCESS; | |||
| } | |||
| Status DavinciModel::SinkTimeProfile(const InputData ¤t_data) { | |||
| // profiling plugin must be registered | |||
| auto &prof_mgr = ProfilingManager::Instance(); | |||
| ReporterData reporter_data{}; | |||
| string name = om_name_.empty() ? name_ : om_name_; | |||
| Json model_time_info; | |||
| model_time_info[kModelName] = name; | |||
| model_time_info[kModeleId] = this->Id(); | |||
| model_time_info[kRequestId] = current_data.request_id; | |||
| model_time_info[kThreadId] = mmGetTid(); | |||
| model_time_info[kInputBeginTime] = time_info_.processBeginTime; | |||
| model_time_info[kInputEndTime] = time_info_.processEndTime; | |||
| model_time_info[kInferBeginTime] = time_info_.inferenceBeginTime; | |||
| model_time_info[kInferEndTime] = time_info_.inferenceEndTime; | |||
| model_time_info[kOutputBeginTime] = time_info_.dumpBeginTime; | |||
| model_time_info[kOutputEndTime] = time_info_.dumpEndTime; | |||
| // report model data tag name | |||
| std::string tag_name; | |||
| tag_name.append("model_time_info_") | |||
| .append(std::to_string(this->Id())) | |||
| .append("_") | |||
| .append(std::to_string(current_data.index)); | |||
| GE_CHK_BOOL_EXEC(memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN, tag_name.c_str(), tag_name.size()) == EOK, | |||
| return FAILED, "Sink model tag memcpy error."); | |||
| // device id | |||
| reporter_data.deviceId = device_id_; | |||
| // Model Header | |||
| string name; | |||
| if (!om_name_.empty()) { | |||
| name = om_name_; | |||
| } else { | |||
| name = name_; | |||
| } | |||
| size_t name_len = name.size(); | |||
| reporter_data.data = (unsigned char *)&name_len; | |||
| reporter_data.dataLen = sizeof(int32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| reporter_data.data = (unsigned char *)name.c_str(); | |||
| reporter_data.dataLen = name.size(); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u.", this->Id()); | |||
| // request id | |||
| uint64_t request_id = current_data.request_id; | |||
| reporter_data.data = (unsigned char *)&request_id; | |||
| reporter_data.dataLen = sizeof(uint32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u, data index:%u.", this->Id(), current_data.index); | |||
| // thread id | |||
| int32_t thread_id = GetDataInputTid(); | |||
| reporter_data.data = (unsigned char *)&thread_id; | |||
| reporter_data.dataLen = sizeof(int32_t); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u, data index:%u.", this->Id(), current_data.index); | |||
| // time info | |||
| time_info_.modelId = this->Id(); | |||
| reporter_data.data = (unsigned char *)&time_info_; | |||
| reporter_data.dataLen = sizeof(struct timeInfo); | |||
| GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED, | |||
| "Reporter data fail, model id:%u, data index:%u.", this->Id(), current_data.index); | |||
| .append(std::to_string(this->Id())) | |||
| .append("_") | |||
| .append(std::to_string(current_data.index)); | |||
| std::string reported_data; | |||
| try { | |||
| reported_data = model_time_info.dump(kInteval, ' ', false, Json::error_handler_t::ignore); | |||
| } catch (std::exception &e) { | |||
| GELOGE(FAILED, "Failed to convert JSON to string, reason: %s.", e.what()); | |||
| } catch (...) { | |||
| GELOGE(FAILED, "Failed to convert JSON to string."); | |||
| } | |||
| reported_data.append(",") | |||
| .append("\n"); | |||
| prof_mgr.ReportData(device_id_, reported_data, tag_name); | |||
| return SUCCESS; | |||
| } | |||
| @@ -2626,7 +2519,7 @@ Status DavinciModel::ReturnResult(uint32_t data_id, const bool rslt_flg, const b | |||
| /// @return Status result | |||
| /// | |||
| Status DavinciModel::ReturnNoOutput(uint32_t data_id) { | |||
| GELOGI("ReturnNoOutput model id:%u", model_id_); | |||
| GELOGI("ReturnNoOutput model id:%u.", model_id_); | |||
| GE_CHK_BOOL_EXEC(listener_ != nullptr, return PARAM_INVALID, "listener_ is null!"); | |||
| std::vector<ge::OutputTensorInfo> outputs; | |||
| @@ -2641,6 +2534,7 @@ void *DavinciModel::Run(DavinciModel *model) { | |||
| bool seq_end_flag = false; | |||
| uint32_t model_id = model->Id(); | |||
| uint32_t device_id = model->GetDeviceId(); | |||
| ErrorManager::GetInstance().SetErrorContext(model->GetErrorContext()); | |||
| GELOGI("Model Run thread start, model_id:%u.", model_id); | |||
| rtError_t rt_ret = rtSetDevice(static_cast<int32_t>(device_id)); | |||
| @@ -2651,6 +2545,7 @@ void *DavinciModel::Run(DavinciModel *model) { | |||
| // DeviceReset before thread run finished! | |||
| GE_MAKE_GUARD(not_used_var, [&] { GE_CHK_RT(rtDeviceReset(device_id)); }); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelExecute, ErrorMessage::kModelExecute); | |||
| while (model->RunFlag()) { | |||
| bool rslt_flg = true; | |||
| if (model->GetDataInputer() == nullptr) { | |||
| @@ -2773,10 +2668,6 @@ Status DavinciModel::DestroyThread() { | |||
| thread_id_.join(); | |||
| } | |||
| if (shrink_id_.joinable()) { | |||
| shrink_id_.join(); | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -2807,6 +2698,7 @@ Status DavinciModel::ModelRunStart() { | |||
| int64_t maxDumpOpNum = std::strtol(opt.c_str(), nullptr, kDecimal); | |||
| maxDumpOpNum_ = maxDumpOpNum; | |||
| error_context_ = ErrorManager::GetInstance().GetErrorContext(); | |||
| CREATE_STD_THREAD(thread_id_, DavinciModel::Run, this); | |||
| GELOGI("model tread create success, model id:%u.", model_id_); | |||
| return SUCCESS; | |||
| @@ -3069,13 +2961,15 @@ void DavinciModel::SaveProfilingTaskDescInfo(const OpDescPtr &op, const TaskInfo | |||
| task_desc_info.model_name = name_; | |||
| } | |||
| task_desc_info.op_name = op->GetName(); | |||
| task_desc_info.op_type = op->GetType(); | |||
| task_desc_info.block_dim = task_def.kernel().block_dim(); | |||
| task_desc_info.task_id = task->GetTaskID(); | |||
| task_desc_info.stream_id = task->GetStreamId(); | |||
| task_desc_info.shape_type = "static"; | |||
| task_desc_info.cur_iter_num = 0; | |||
| // task type | |||
| task_desc_info.task_type = kTaskTypeInvalid; | |||
| auto &prof_mgr = ProfilingManager::Instance(); | |||
| prof_mgr.GetOpInputOutputInfo(op, task_desc_info); | |||
| auto model_task_type = static_cast<rtModelTaskType_t>(task_def.type()); | |||
| if (model_task_type == RT_MODEL_TASK_KERNEL) { | |||
| const domi::KernelDef &kernel_def = task_def.kernel(); | |||
| @@ -3107,7 +3001,6 @@ void DavinciModel::SaveProfilingTaskDescInfo(const OpDescPtr &op, const TaskInfo | |||
| task_desc_info_.emplace_back(task_desc_info); | |||
| } | |||
| } | |||
| return; | |||
| } | |||
| Status DavinciModel::DistributeTask() { | |||
| @@ -3332,7 +3225,7 @@ Status DavinciModel::CopyModelData(const InputData &input_data, OutputData &outp | |||
| /// | |||
| Status DavinciModel::UpdateIoTaskArgs(const std::map<uint32_t, ZeroCopyOffset> &data_info, bool is_input, | |||
| const vector<DataBuffer> &blobs, bool is_dynamic, const string &batch_label) { | |||
| string input_or_output = "input"; | |||
| string input_or_output; | |||
| is_input ? input_or_output = "input" : input_or_output = "output"; | |||
| if (blobs.size() != data_info.size()) { | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Verify %s data num failed: model requires %zu, but user actually feeds %zu", | |||
| @@ -3342,7 +3235,8 @@ Status DavinciModel::UpdateIoTaskArgs(const std::map<uint32_t, ZeroCopyOffset> & | |||
| for (const auto &data : data_info) { | |||
| if (data.first >= blobs.size()) { // check data index. | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Verify %s data num failed: can not find No.%u data, because user only feeds %zu", | |||
| GELOGE(ACL_ERROR_GE_PARAM_INVALID, | |||
| "Verify %s data num failed: can not find No.%u data, because user only feeds %zu", | |||
| input_or_output.c_str(), data.first, blobs.size()); | |||
| return ACL_ERROR_GE_PARAM_INVALID; | |||
| } | |||
| @@ -3472,14 +3366,16 @@ Status DavinciModel::InitConstant(const OpDescPtr &op_desc) { | |||
| elem_num = 1; | |||
| } | |||
| uint64_t *buff = reinterpret_cast<uint64_t *>(tensor->MutableData().data()); | |||
| GE_CHK_BOOL_RET_STATUS(ge::CheckInt64Uint32MulOverflow(elem_num, kBytes) == SUCCESS, FAILED, | |||
| "Shape size is invalid"); | |||
| uint64_t offset = static_cast<uint64_t>(elem_num * kBytes); | |||
| if (ge::CheckInt64Uint32MulOverflow(elem_num, kBytes * kStringHeadElems) != SUCCESS) { | |||
| GELOGE(FAILED, "Shape size is invalid"); | |||
| return FAILED; | |||
| } | |||
| uint64_t offset = elem_num * kBytes * kStringHeadElems; | |||
| uint64_t hbm_raw_data_base_addr = | |||
| static_cast<uint64_t>(reinterpret_cast<uintptr_t>(v_output_addr[0])) + offset; | |||
| for (int64_t i = elem_num - 1; i >= 0; --i) { | |||
| buff[i] = hbm_raw_data_base_addr + (buff[i] - buff[0]); | |||
| buff[i * kStringHeadElems] = hbm_raw_data_base_addr + (buff[i * kStringHeadElems] - buff[0]); | |||
| } | |||
| } | |||
| GELOGI("[IMAS]InitConstant memcpy graph_%u type[V] name[%s] output[%d] memaddr[%p] mem_size[%lu] datasize[%zu]", | |||
| @@ -4007,41 +3903,6 @@ void DavinciModel::SaveHcclFollowStream(int64_t main_stream_id, rtStream_t strea | |||
| main_follow_stream_mapping_[main_stream_id].emplace_back(stream); | |||
| } | |||
| Status DavinciModel::GetComputeGraphInfo(vector<ComputeGraphDescInfo> &graph_desc_info) { | |||
| auto &all_op_desc = data_dumper_.GetAllOpDescInfo(); | |||
| for (auto &op_desc : all_op_desc) { | |||
| ComputeGraphDescInfo compute_graph_info; | |||
| if (!om_name_.empty()) { | |||
| compute_graph_info.model_name = om_name_; | |||
| } else { | |||
| compute_graph_info.model_name = name_; | |||
| } | |||
| std::vector<Format> format = { FORMAT_NULL }; | |||
| std::vector<std::vector<int64_t>> shape = { {0} }; | |||
| std::vector<DataType> data_type = { DT_UNDEFINED }; | |||
| compute_graph_info.op_name = op_desc.op_name; | |||
| compute_graph_info.op_type = op_desc.op_type; | |||
| compute_graph_info.input_format = op_desc.input_format.empty() ? format : op_desc.input_format; | |||
| compute_graph_info.input_shape = op_desc.input_shape.empty() ? shape : op_desc.input_shape; | |||
| compute_graph_info.input_data_type = op_desc.input_data_type.empty() ? data_type : op_desc.input_data_type; | |||
| compute_graph_info.output_format = op_desc.output_format.empty() ? format : op_desc.output_format; | |||
| compute_graph_info.output_shape = op_desc.output_shape.empty() ? shape : op_desc.output_shape; | |||
| compute_graph_info.output_data_type = op_desc.output_data_type.empty() ? data_type : op_desc.output_data_type; | |||
| uint32_t task_id = 0; | |||
| uint32_t stream_id = 0; | |||
| auto iter = profiler_report_op_info_.find(op_desc.op_name); | |||
| if (iter != profiler_report_op_info_.end()) { | |||
| task_id = iter->second.first; | |||
| stream_id = iter->second.second; | |||
| } | |||
| compute_graph_info.task_id = task_id; | |||
| compute_graph_info.stream_id = stream_id; | |||
| graph_desc_info.emplace_back(compute_graph_info); | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| void DavinciModel::SetTotalFixedAddrsSize(string tensor_name, int64_t fix_addr_size) { | |||
| if (tensor_name_to_fixed_addr_size_.find(tensor_name) == tensor_name_to_fixed_addr_size_.end()) { | |||
| tensor_name_to_fixed_addr_size_[tensor_name] = total_fixed_addr_size_; | |||
| @@ -4058,7 +3919,7 @@ Status DavinciModel::InitOrigInputInfo(uint32_t index, const OpDescPtr &op_desc) | |||
| vector<string> inputs; | |||
| if (AttrUtils::GetListStr(op_desc, ATTR_NAME_AIPP_INPUTS, inputs) && !inputs.empty()) { | |||
| std::string input = inputs[kAippOriginInputIndex]; | |||
| GELOGI("origin input str: %s", input.c_str()); | |||
| GELOGI("origin input str: %s.", input.c_str()); | |||
| std::vector<std::string> infos = ge::StringUtils::Split(input, ':'); | |||
| if (infos.size() != kAippInfoNum) { | |||
| GELOGE(ACL_ERROR_GE_AIPP_MODE_INVALID, "origin input str is invalid[%zu, %u].", infos.size(), kAippInfoNum); | |||
| @@ -4132,11 +3993,11 @@ Status DavinciModel::InitAippInputOutputDims(uint32_t index, const OpDescPtr &op | |||
| ConstGeTensorDescPtr data_input_desc = op_desc->GetInputDescPtr(kDataIndex); | |||
| int64_t data_input_size; | |||
| (void)TensorUtils::GetSize(*(op_desc->GetInputDescPtr(kDataIndex)), data_input_size); | |||
| GELOGD("related Data[%d]: tensor_name: %s, dim_num: %zu, tensor_size: %zu, format: %s, data_type: %s, shape: %s", | |||
| index, op_desc->GetName().c_str(), data_input_desc->GetShape().GetDimNum(), data_input_size, | |||
| TypeUtils::FormatToSerialString(data_input_desc->GetFormat()).c_str(), | |||
| TypeUtils::DataTypeToSerialString(data_input_desc->GetDataType()).c_str(), | |||
| formats::JoinToString(data_input_desc->GetShape().GetDims()).c_str()); | |||
| GELOGD("related Data[%d]: tensor_name: %s, dim_num: %zu, tensor_size: %zu, format: %s, data_type: %s, shape: %s.", | |||
| index, op_desc->GetName().c_str(), data_input_desc->GetShape().GetDimNum(), data_input_size, | |||
| TypeUtils::FormatToSerialString(data_input_desc->GetFormat()).c_str(), | |||
| TypeUtils::DataTypeToSerialString(data_input_desc->GetDataType()).c_str(), | |||
| formats::JoinToString(data_input_desc->GetShape().GetDims()).c_str()); | |||
| } | |||
| } | |||
| @@ -29,6 +29,7 @@ | |||
| #include "common/helper/om_file_helper.h" | |||
| #include "common/opskernel/ge_task_info.h" | |||
| #include "common/properties_manager.h" | |||
| #include "common/dump/opdebug_register.h" | |||
| #include "common/types.h" | |||
| #include "framework/common/util.h" | |||
| #include "graph/debug/ge_attr_define.h" | |||
| @@ -412,6 +413,8 @@ class DavinciModel { | |||
| /// | |||
| uint64_t GetSessionId() const { return session_id_; } | |||
| const struct ErrorMessage::Context &GetErrorContext() const { return error_context_; } | |||
| /// | |||
| /// @ingroup ge | |||
| /// @brief SetDeviceId | |||
| @@ -536,7 +539,7 @@ class DavinciModel { | |||
| vector<InputOutputDims> &output_dims) const; | |||
| // om file name | |||
| void SetOmName(string om_name) { om_name_ = om_name; } | |||
| void SetOmName(const string &om_name) { om_name_ = om_name; } | |||
| void SetDumpProperties(const DumpProperties &dump_properties) { data_dumper_.SetDumpProperties(dump_properties); } | |||
| const DumpProperties &GetDumpProperties() const { return data_dumper_.GetDumpProperties(); } | |||
| @@ -840,9 +843,6 @@ class DavinciModel { | |||
| Status TransAllVarData(ComputeGraphPtr &graph, uint32_t graph_id); | |||
| // get desc info of graph for profiling | |||
| Status GetComputeGraphInfo(vector<ComputeGraphDescInfo> &graph_desc_info); | |||
| void SetDataDumperArgs(const ComputeGraphPtr &graph, const map<string, OpDescPtr> &variable_by_name); | |||
| Status InitL1DataDumperArgs(); | |||
| @@ -907,7 +907,6 @@ class DavinciModel { | |||
| vector<int64_t> output_memory_size_list_; | |||
| thread thread_id_; | |||
| thread shrink_id_; | |||
| shared_ptr<ModelListener> listener_; | |||
| @@ -960,6 +959,7 @@ class DavinciModel { | |||
| vector<uintptr_t> output_mbuf_list_; // output mbuf created by dequeue task. | |||
| uint64_t session_id_; | |||
| struct ErrorMessage::Context error_context_; | |||
| uint32_t device_id_; | |||
| @@ -985,6 +985,7 @@ class DavinciModel { | |||
| int64_t maxDumpOpNum_; | |||
| // for data dump | |||
| DataDumper data_dumper_; | |||
| OpdebugRegister opdebug_register_; | |||
| uint64_t iterator_count_; | |||
| bool is_l1_fusion_enable_; | |||
| map<OpDescPtr, void *> saved_task_addrs_; // release after DavinciModel::Init | |||
| @@ -1022,8 +1023,6 @@ class DavinciModel { | |||
| // for op debug | |||
| mutex debug_reg_mutex_; | |||
| bool is_op_debug_reg_ = false; | |||
| void *op_debug_addr_ = nullptr; | |||
| void *p2p_debug_addr_ = nullptr; | |||
| bool is_online_infer_dynamic_ = false; | |||
| bool is_getnext_sink_dynamic_ = false; | |||
| vector<int32_t> cur_dynamic_dims_; | |||
| @@ -18,23 +18,15 @@ | |||
| #include <string> | |||
| #include "mmpa/mmpa_api.h" | |||
| #include "aicpu/aicpu_schedule/aicpu_op_type_list.h" | |||
| #include "common/model_parser/model_parser.h" | |||
| #include "common/dump/dump_manager.h" | |||
| #include "common/l2_cache_optimize.h" | |||
| #include "common/profiling/profiling_manager.h" | |||
| #include "common/properties_manager.h" | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "framework/common/util.h" | |||
| #include "graph/common/ge_call_wrapper.h" | |||
| #include "graph/debug/ge_attr_define.h" | |||
| #include "graph/load/model_manager/davinci_model.h" | |||
| #include "graph/load/model_manager/davinci_model_parser.h" | |||
| #include "model/ge_root_model.h" | |||
| #include "graph/common/local_context.h" | |||
| #include "graph/utils/attr_utils.h" | |||
| #include "common/formats/utils/formats_trans_utils.h" | |||
| #include "hybrid/hybrid_davinci_model.h" | |||
| namespace ge { | |||
| thread_local uint32_t device_count = 0; | |||
| @@ -55,6 +47,7 @@ const char *const kDeleteCustOp = "deleteCustOp"; | |||
| const int kTimeSpecNano = 1000000000; | |||
| const int kTimeSpecMiro = 1000000; | |||
| const int kOpNameMaxSize = 100; | |||
| const uint64_t kInferSessionId = 0; | |||
| #pragma pack(push, 1) | |||
| struct CustAicpuSoBuf { | |||
| uint64_t kernelSoBuf; | |||
| @@ -278,13 +271,15 @@ ge::Status ModelManager::SetDynamicSize(uint32_t model_id, const std::vector<uin | |||
| return SUCCESS; | |||
| } | |||
| ge::Status ModelManager::DoLoadHybridModelOnline(uint32_t model_id, const shared_ptr<ge::GeRootModel> &ge_root_model, | |||
| ge::Status ModelManager::DoLoadHybridModelOnline(uint32_t model_id, const string &model_name, | |||
| const shared_ptr<ge::GeRootModel> &ge_root_model, | |||
| const shared_ptr<ModelListener> &listener) { | |||
| auto hybrid_model = hybrid::HybridDavinciModel::Create(ge_root_model); | |||
| GE_CHECK_NOTNULL(hybrid_model); | |||
| hybrid_model->SetListener(listener); | |||
| hybrid_model->SetModelId(model_id); | |||
| hybrid_model->SetDeviceId(GetContext().DeviceId()); | |||
| hybrid_model->SetModelName(model_name); | |||
| GE_CHK_STATUS_RET(hybrid_model->Init(), "Failed to init hybrid model. model_id = %u", model_id); | |||
| auto shared_model = std::shared_ptr<hybrid::HybridDavinciModel>(hybrid_model.release()); | |||
| InsertModel(model_id, shared_model); | |||
| @@ -304,10 +299,11 @@ Status ModelManager::LoadModelOnline(uint32_t &model_id, const shared_ptr<ge::Ge | |||
| } | |||
| bool is_shape_unknown = false; | |||
| string model_name = ""; | |||
| GE_CHK_STATUS_RET(ge_root_model->CheckIsUnknownShape(is_shape_unknown), "CheckIsUnknownShape failed, model id:%u", | |||
| model_id); | |||
| if (is_shape_unknown || GetContext().GetHostExecFlag()) { | |||
| return DoLoadHybridModelOnline(model_id, ge_root_model, listener); | |||
| return DoLoadHybridModelOnline(model_id, model_name, ge_root_model, listener); | |||
| } | |||
| mmTimespec timespec = mmGetTickCount(); | |||
| @@ -321,7 +317,7 @@ Status ModelManager::LoadModelOnline(uint32_t &model_id, const shared_ptr<ge::Ge | |||
| davinci_model->SetId(model_id); | |||
| davinci_model->SetDeviceId(GetContext().DeviceId()); | |||
| const DumpProperties &dump_properties = PropertiesManager::Instance().GetDumpProperties(GetContext().SessionId()); | |||
| const DumpProperties &dump_properties = DumpManager::GetInstance().GetDumpProperties(GetContext().SessionId()); | |||
| davinci_model->SetDumpProperties(dump_properties); | |||
| dump_properties_ = dump_properties; | |||
| @@ -1036,7 +1032,7 @@ Status ModelManager::GenSessionId(uint64_t &session_id) { | |||
| Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model, shared_ptr<ModelListener> listener, | |||
| void *dev_ptr, size_t mem_size, void *weight_ptr, size_t weight_size) { | |||
| GE_CHK_BOOL_RET_STATUS(model.key.empty() || mmAccess2(model.key.c_str(), M_F_OK) == EN_OK, | |||
| ACL_ERROR_GE_PARAM_INVALID, "input key file path %s is invalid, %s", model.key.c_str(), strerror(errno)); | |||
| ACL_ERROR_GE_PARAM_INVALID, "Input key file path %s is invalid, %s", model.key.c_str(), strerror(errno)); | |||
| GenModelId(&model_id); | |||
| mmTimespec timespec = mmGetTickCount(); | |||
| @@ -1053,7 +1049,7 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model | |||
| GE_CHK_STATUS_RET(model_helper.GetGeRootModel()->CheckIsUnknownShape(is_shape_unknown), | |||
| "CheckIsUnknownShape failed, model id:%u", model_id); | |||
| if (is_shape_unknown || GetContext().GetHostExecFlag()) { | |||
| return DoLoadHybridModelOnline(model_id, model_helper.GetGeRootModel(), listener); | |||
| return DoLoadHybridModelOnline(model_id, model.om_name, model_helper.GetGeRootModel(), listener); | |||
| } | |||
| } | |||
| @@ -1081,8 +1077,8 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model | |||
| } | |||
| davinci_model->SetDeviceId(device_id); | |||
| davinci_model->SetOmName(model.om_name); | |||
| if (DumpManager::GetInstance().GetDumpProperties().IsDumpOpen()) { | |||
| davinci_model->SetDumpProperties(DumpManager::GetInstance().GetDumpProperties()); | |||
| if (DumpManager::GetInstance().GetDumpProperties(kInferSessionId).IsDumpOpen()) { | |||
| davinci_model->SetDumpProperties(DumpManager::GetInstance().GetDumpProperties(kInferSessionId)); | |||
| } else { | |||
| davinci_model->SetDumpProperties(dump_properties_); | |||
| } | |||
| @@ -1092,9 +1088,9 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model | |||
| /// Update session_id for infer in load model to avoid the same session_id. | |||
| uint64_t new_session_id; | |||
| ret = GenSessionId(new_session_id); | |||
| GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ret != SUCCESS, break, "Generate session_id for infer failed."); | |||
| GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ret != SUCCESS, break, "Generate session_id for inference failed."); | |||
| ret = davinci_model->UpdateSessionId(new_session_id); | |||
| GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ret != SUCCESS, break, "Update session_id for infer failed."); | |||
| GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ret != SUCCESS, break, "Update session_id for inference failed."); | |||
| ret = davinci_model->Init(dev_ptr, mem_size, weight_ptr, weight_size); | |||
| GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ret != SUCCESS, break, "DavinciInit failed."); | |||
| @@ -1403,7 +1399,7 @@ Status ModelManager::LaunchCustAicpuSo() { | |||
| Status ModelManager::GetModelMemAndWeightSize(const ModelData &model, size_t &mem_size, size_t &weight_size) { | |||
| uint8_t *model_data = nullptr; | |||
| uint32_t model_len = 0; | |||
| Status ret = DavinciModelParser::ParseModelContent(model, model_data, model_len); | |||
| Status ret = ModelParserBase::ParseModelContent(model, model_data, model_len); | |||
| GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(ret != SUCCESS, return ACL_ERROR_GE_PARAM_INVALID, "parse model content failed!"); | |||
| OmFileLoadHelper om_file_helper; | |||
| @@ -73,7 +73,8 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelManager { | |||
| ge::Status LoadModelOnline(uint32_t &model_id, const std::shared_ptr<ge::GeRootModel> &ge_root_model, | |||
| std::shared_ptr<ModelListener> listener); | |||
| ge::Status DoLoadHybridModelOnline(uint32_t model_id, const shared_ptr<ge::GeRootModel> &ge_root_model, | |||
| ge::Status DoLoadHybridModelOnline(uint32_t model_id, const string &model_name, | |||
| const shared_ptr<ge::GeRootModel> &ge_root_model, | |||
| const std::shared_ptr<ModelListener> &listener); | |||
| /// | |||
| @@ -387,7 +387,7 @@ Status ModelUtils::GetVarAddr(const RuntimeParam &model_param, const ConstOpDesc | |||
| GELOGE(PARAM_INVALID, "rdma var addr is invalid, addr=%p", reinterpret_cast<uint8_t *>(offset)); | |||
| return PARAM_INVALID; | |||
| } | |||
| var_addr = reinterpret_cast<uint8_t *>(offset); | |||
| var_addr = reinterpret_cast<uint8_t *>(static_cast<uintptr_t>(offset)); | |||
| break; | |||
| case RT_MEMORY_HBM: | |||
| VALIDATE_MEM_RANGE(op_desc, model_param.var_size, offset - model_param.logic_var_base); | |||
| @@ -28,10 +28,9 @@ const size_t bin_ranges[kNumBins] = {kRoundBlockSize * kKByteSize, | |||
| kBinSizeUnit8 * kMByteSize, | |||
| kBinSizeUnit32 * kMByteSize, | |||
| kBinSizeUnit128 * kMByteSize, | |||
| kGByteSize, | |||
| kBinSizeUnit4 * kGByteSize, | |||
| kBinSizeUnit16 * kGByteSize, | |||
| kBinSizeUnit26 * kGByteSize}; | |||
| kBinSizeUnit256 * kMByteSize, | |||
| kBinSizeUnit512 * kMByteSize, | |||
| kGByteSize}; | |||
| static bool BlockComparator(const Block *left, const Block *right) { | |||
| if (left->size != right->size) { | |||
| @@ -63,7 +62,10 @@ size_t GetBinIndex(size_t size) { | |||
| size_t GetAllocationSize(size_t size) { | |||
| size_t index = GetBinIndex(size); | |||
| return bin_ranges[index]; | |||
| if (bin_ranges[index] >= size) { | |||
| return bin_ranges[index]; | |||
| } | |||
| return kGByteSize * ((size + kGByteSize - 1) / kGByteSize); | |||
| } | |||
| /// | |||
| @@ -83,6 +85,15 @@ bool ShouldSplit(const Block *block, size_t size) { | |||
| return static_cast<double>(size) <= (static_cast<double>(block->size) * kSplitThreshold); | |||
| } | |||
| void IncreaseCount(std::map<size_t, size_t> &count, size_t size) { | |||
| auto it = count.find(size); | |||
| if (it != count.end()) { | |||
| it->second++; | |||
| } else { | |||
| count.emplace(size, 1); | |||
| } | |||
| } | |||
| CachingAllocator::CachingAllocator(rtMemType_t memory_type) : memory_type_(memory_type), memory_allocator_(nullptr) { | |||
| for (uint32_t i = 0; i < kNumBins; ++i) { | |||
| free_block_bins_[i] = nullptr; | |||
| @@ -114,11 +125,13 @@ Status CachingAllocator::Initialize(uint32_t device_id) { | |||
| void CachingAllocator::Finalize(uint32_t device_id) { | |||
| GELOGI("Device id %u", device_id); | |||
| PrintStatics(); | |||
| FreeBlocks(); | |||
| FreeBlockBins(); | |||
| } | |||
| uint8_t *CachingAllocator::Malloc(size_t size, uint8_t *org_ptr, uint32_t device_id) { | |||
| GELOGI("Start malloc pool memory, size = %zu, device id = %u", size, device_id); | |||
| uint8_t *ptr = nullptr; | |||
| size = GetBlockSize(size); | |||
| Block *block = FindFreeBlock(size, org_ptr, device_id); | |||
| @@ -202,8 +215,7 @@ BlockBin *CachingAllocator::GetBlockBin(size_t size) { | |||
| } | |||
| Block *CachingAllocator::FindFreeBlock(size_t size, uint8_t *org_ptr, uint32_t device_id) { | |||
| // org_ptr - 1, try to find ptr same as org_ptr | |||
| Block key(device_id, size, (org_ptr == nullptr ? nullptr : org_ptr - 1)); | |||
| Block key(device_id, size, org_ptr); | |||
| BlockBin *bin = GetBlockBin(size); | |||
| if (bin == nullptr) { | |||
| GELOGE(ge::FAILED, "Get block bin failed size = %zu", size); | |||
| @@ -253,23 +265,28 @@ Block *CachingAllocator::SplitBlock(Block *block, size_t size, BlockBin &bin, ui | |||
| } | |||
| Status CachingAllocator::TryExtendCache(size_t size, uint32_t device_id) { | |||
| GELOGI("Try to extend cache. size = %zu, device id = %u", size, device_id); | |||
| auto memory_size = GetAllocationSize(size); | |||
| const std::string purpose = "Memory for caching."; | |||
| auto memory_addr = memory_allocator_->MallocMemory(purpose, memory_size, device_id); | |||
| // try to free caches and malloc again when malloc memory failed | |||
| if (memory_addr == nullptr) { | |||
| FreeCachedBlocks(); | |||
| size_t free_cached_memory_size = FreeCachedBlocks(); | |||
| memory_addr = memory_allocator_->MallocMemory(purpose, memory_size, device_id); | |||
| if (memory_addr == nullptr) { | |||
| GELOGE(ge::FAILED, "TryExtendCache failed, no enough memory for size = %zu, device_id = %u", memory_size, | |||
| device_id); | |||
| return ge::FAILED; | |||
| } | |||
| GELOGT(TRACE_RUNNING, "Try to free cached memory size:%zu and malloc memory size:%zu success.", | |||
| free_cached_memory_size, memory_size); | |||
| } | |||
| if (AddToBlockBin(memory_addr, memory_size, device_id) != ge::SUCCESS) { | |||
| (void)memory_allocator_->FreeMemory(memory_addr); | |||
| return ge::FAILED; | |||
| } | |||
| PrintStatics(); | |||
| return ge::SUCCESS; | |||
| } | |||
| @@ -290,13 +307,15 @@ Status CachingAllocator::AddToBlockBin(uint8_t *ptr, size_t size, uint32_t devic | |||
| block->size = size; | |||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | |||
| IncreaseCount(malloced_memory_, block->size); | |||
| bin->insert(block); | |||
| return ge::SUCCESS; | |||
| } | |||
| void CachingAllocator::FreeCachedBlocks() { | |||
| size_t CachingAllocator::FreeCachedBlocks() { | |||
| GELOGI("Free cached blocks"); | |||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | |||
| size_t free_cached_memory_size = 0; | |||
| for (uint32_t i = 0; i < kNumBins; ++i) { | |||
| auto pool = free_block_bins_[i]; | |||
| if (pool == nullptr) { | |||
| @@ -307,6 +326,14 @@ void CachingAllocator::FreeCachedBlocks() { | |||
| // free block memory that has not been split | |||
| if ((block != nullptr) && (block->ptr != nullptr) && (block->prev == nullptr) && (block->next == nullptr) && | |||
| (memory_allocator_->FreeMemory(block->ptr) == ge::SUCCESS)) { | |||
| auto itcount = malloced_memory_.find(block->size); | |||
| free_cached_memory_size += block->size; | |||
| if (itcount != malloced_memory_.end()) { | |||
| itcount->second--; | |||
| if (itcount->second == 0) { | |||
| malloced_memory_.erase(itcount); | |||
| } | |||
| } | |||
| pool->erase(it++); | |||
| delete block; | |||
| continue; | |||
| @@ -314,6 +341,7 @@ void CachingAllocator::FreeCachedBlocks() { | |||
| ++it; | |||
| } | |||
| } | |||
| return free_cached_memory_size; | |||
| } | |||
| void CachingAllocator::FreeBlocks() { | |||
| @@ -324,8 +352,7 @@ void CachingAllocator::FreeBlocks() { | |||
| FreeBlock(it.second); | |||
| } | |||
| allocated_blocks_.clear(); | |||
| FreeCachedBlocks(); | |||
| (void) FreeCachedBlocks(); | |||
| } | |||
| void CachingAllocator::FreeBlockBins() { | |||
| @@ -338,4 +365,60 @@ void CachingAllocator::FreeBlockBins() { | |||
| } | |||
| } | |||
| } | |||
| void PrintCount(std::map<size_t, size_t> &count, const std::string &name, size_t total_size, size_t total_count) { | |||
| GELOGI("%6s total[size:%10zu count:%10zu]", name.c_str(), total_size, total_count); | |||
| for (auto &it : count) { | |||
| GELOGI(" |- block[size:%10zu count:%10zu]", it.first, it.second); | |||
| } | |||
| } | |||
| void CachingAllocator::PrintStatics() { | |||
| if (!IsLogEnable(GE_MODULE_NAME, DLOG_INFO)) { | |||
| return; | |||
| } | |||
| size_t total_using_size = 0; | |||
| size_t total_using_count = 0; | |||
| size_t total_free_size = 0; | |||
| size_t total_free_count = 0; | |||
| size_t total_malloc_size = 0; | |||
| size_t total_malloc_count = 0; | |||
| std::map<size_t, size_t> using_block; | |||
| std::map<size_t, size_t> free_block; | |||
| std::map<size_t, size_t> malloc_block; | |||
| do { | |||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | |||
| for (uint32_t i = 0; i < kNumBins; ++i) { | |||
| auto pool = free_block_bins_[i]; | |||
| if (pool == nullptr) { | |||
| continue; | |||
| } | |||
| for (auto it = pool->begin(); it != pool->end(); ++it) { | |||
| if ((*it) != nullptr) { | |||
| total_free_size += (*it)->size; | |||
| IncreaseCount(free_block, (*it)->size); | |||
| total_free_count++; | |||
| } | |||
| } | |||
| } | |||
| for (auto &it : allocated_blocks_) { | |||
| if (it.second != nullptr) { | |||
| total_using_size += it.second->size; | |||
| IncreaseCount(using_block, it.second->size); | |||
| total_using_count++; | |||
| } | |||
| } | |||
| for (auto &it : malloced_memory_) { | |||
| total_malloc_size += it.first * it.second; | |||
| total_malloc_count += it.second; | |||
| malloc_block[it.first] = it.second; | |||
| } | |||
| } while (0); | |||
| PrintCount(malloc_block, "Malloc", total_malloc_size, total_malloc_count); | |||
| PrintCount(using_block, "Using", total_using_size, total_using_count); | |||
| PrintCount(free_block, "Free", total_free_size, total_free_count); | |||
| } | |||
| } // namespace ge | |||
| @@ -36,17 +36,17 @@ namespace ge { | |||
| constexpr size_t kRoundBlockSize = 512; // all block sizes are rounded to at least 512 bytes | |||
| constexpr size_t kBinSizeUnit4 = 4; | |||
| constexpr size_t kBinSizeUnit8 = 8; | |||
| constexpr size_t kBinSizeUnit16 = 16; | |||
| constexpr size_t kBinSizeUnit26 = 26; | |||
| constexpr size_t kBinSizeUnit32 = 32; | |||
| constexpr size_t kBinSizeUnit128 = 128; | |||
| constexpr size_t kBinSizeUnit256 = 256; | |||
| constexpr size_t kBinSizeUnit512 = 512; | |||
| constexpr double kSplitThreshold = 0.75; // split when malloc size <= small block size * kSpliThreshold | |||
| constexpr double kSplitThreshold = 0.5; // split when malloc size <= small block size * kSpliThreshold | |||
| constexpr size_t kKByteSize = 1024; | |||
| constexpr size_t kMByteSize = 1048576; // 1024 * 1024 | |||
| constexpr size_t kGByteSize = 1073741824; // 1024 * 1024 * 1024 | |||
| static const uint32_t kNumBins = 8; | |||
| static const uint32_t kNumBins = 7; | |||
| class MemoryAllocator; | |||
| @@ -143,9 +143,9 @@ class CachingAllocator { | |||
| /// | |||
| /// @ingroup ge_graph | |||
| /// @brief free all cached blocks to right bin and release the memory when memory is not enough | |||
| /// @return void | |||
| /// @return free cached memory size | |||
| /// | |||
| void FreeCachedBlocks(); | |||
| size_t FreeCachedBlocks(); | |||
| /// | |||
| /// @ingroup ge_graph | |||
| @@ -182,6 +182,13 @@ class CachingAllocator { | |||
| /// | |||
| Block *SplitBlock(Block *block, size_t size, BlockBin &bin, uint32_t device_id); | |||
| /// | |||
| /// @ingroup ge_graph | |||
| /// @brief print the memory info in pool | |||
| /// @return void | |||
| /// | |||
| void PrintStatics(); | |||
| private: | |||
| rtMemType_t memory_type_; | |||
| @@ -196,6 +203,9 @@ class CachingAllocator { | |||
| // block bins by different block size | |||
| BlockBin *free_block_bins_[kNumBins]; | |||
| // malloced memorys from device | |||
| std::map<size_t, size_t> malloced_memory_; | |||
| }; | |||
| } // namespace ge | |||
| #endif // GE_GRAPH_MANAGER_GRAPH_CACHING_ALLOCATOR_H_ | |||
| @@ -26,6 +26,7 @@ | |||
| #include "common/math/math_util.h" | |||
| #include "common/thread_pool.h" | |||
| #include "common/dump/dump_manager.h" | |||
| #include "analyzer/analyzer.h" | |||
| #include "graph/common/ge_call_wrapper.h" | |||
| #include "graph/common/local_context.h" | |||
| @@ -141,7 +142,7 @@ ge::Status CheckFpCeilingMode() { | |||
| GELOGI("The parameter fp_ceiling_mode is set to %s.", mode.c_str()); | |||
| return ge::SUCCESS; | |||
| } | |||
| GELOGW("The parameter fp_ceiling_mode is not set."); | |||
| GELOGW("The parameter fp_ceiling_mode is not set"); | |||
| return ge::SUCCESS; | |||
| } | |||
| } // namespace | |||
| @@ -154,6 +155,7 @@ GraphManager::GraphManager() | |||
| } | |||
| Status GraphManager::Initialize(const std::map<string, string> &options) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kInitialize, ErrorMessage::kOther); | |||
| if (init_flag_) { | |||
| GELOGW("[Initialize] GraphManager already initialized."); | |||
| return SUCCESS; | |||
| @@ -293,7 +295,7 @@ Status GraphManager::InitDynamicParams(ComputeGraphPtr &compute_graph) { | |||
| return FAILED; | |||
| } | |||
| if ((op_desc->GetType() == DATA) || (op_type == kGetNextName)) { | |||
| GELOGI("Need to process multi batch for compute graph."); | |||
| GELOGI("Need to process multi batch for compute graph. op_type:%s.", op_desc->GetType().c_str()); | |||
| GetLocalOmgContext().need_multi_batch = true; | |||
| break; | |||
| } | |||
| @@ -542,6 +544,7 @@ Status GraphManager::OptimizeSubGraphWithMultiThreads(ComputeGraphPtr compute_gr | |||
| std::future<Status> f = executor.commit(GraphManager::ProcessSubGraphWithMultiThreads, this, | |||
| compute_graph->GetGraphID(), subgraph, | |||
| compute_graph->GetName(), session_id, | |||
| ErrorManager::GetInstance().GetErrorContext(), | |||
| GetThreadLocalContext()); | |||
| if (!f.valid()) { | |||
| GELOGE(FAILED, "Future is invalid"); | |||
| @@ -558,6 +561,7 @@ Status GraphManager::OptimizeSubGraphWithMultiThreads(ComputeGraphPtr compute_gr | |||
| std::future<Status> f = executor.commit(GraphManager::ProcessSubGraphWithMultiThreads, this, | |||
| compute_graph->GetGraphID(), subgraph, | |||
| compute_graph->GetName(), session_id, | |||
| ErrorManager::GetInstance().GetErrorContext(), | |||
| GetThreadLocalContext()); | |||
| if (!f.valid()) { | |||
| GELOGE(FAILED, "Future is invalid"); | |||
| @@ -663,6 +667,7 @@ Status GraphManager::SetSubgraph(uint64_t session_id, ComputeGraphPtr compute_gr | |||
| Status GraphManager::PreRunOptimizeOriginalGraph(const GraphNodePtr &graph_node, const std::vector<GeTensor> &inputs, | |||
| ge::ComputeGraphPtr &compute_graph, uint64_t session_id) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kPrepareOptimize); | |||
| GE_CHECK_NOTNULL(graph_node); | |||
| GE_CHECK_NOTNULL(compute_graph); | |||
| @@ -671,8 +676,10 @@ Status GraphManager::PreRunOptimizeOriginalGraph(const GraphNodePtr &graph_node, | |||
| GM_RUN_AND_DUMP_PERF("HandleSummaryOp", stages.optimizer.HandleSummaryOp, compute_graph); | |||
| GM_RUN_AND_DUMP_PERF("Prepare", stages.preparer.PrepareDynShape, graph_node, inputs, compute_graph, | |||
| session_id); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOriginOptimize); | |||
| GM_RUN_AND_DUMP_PERF("OptimizeOriginalGraph", stages.optimizer.OptimizeOriginalGraph, compute_graph); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kPrepareOptimize); | |||
| GM_RUN_AND_DUMP_PERF("PrepareRunningFormatRefiner", stages.preparer.PrepareRunningFormatRefiner); | |||
| GM_RUN_AND_DUMP_PERF("RefineRunningFormat", stages.optimizer.OptimizeOriginalGraphJudgeInsert, compute_graph); | |||
| GM_RUN_AND_DUMP_PERF("SubexpressionMigration", SubexpressionMigration, compute_graph); | |||
| @@ -715,6 +722,7 @@ Status GraphManager::PreRunAfterOptimizeSubGraph(const GraphNodePtr &graph_node, | |||
| GE_CHECK_NOTNULL(graph_node); | |||
| GE_CHECK_NOTNULL(compute_graph); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kMergeGraphOptimize); | |||
| CompilerStages &stages = GetCompilerStages(graph_node->GetGraphId()); | |||
| GM_RUN_AND_DUMP_PERF("OptimizeWholeGraph", stages.optimizer.OptimizeWholeGraph, compute_graph); | |||
| GM_RUN_AND_DUMP_PERF("Optimize2", OptimizeStage2, compute_graph); | |||
| @@ -734,8 +742,8 @@ Status GraphManager::PreRunAfterOptimizeSubGraph(const GraphNodePtr &graph_node, | |||
| } | |||
| Status GraphManager::SetRtContext(rtContext_t rt_context, rtCtxMode_t mode, uint64_t session_id, uint32_t graph_id) { | |||
| GELOGD("set rt_context, session id: %lu, graph id: %u, mode %d, device id:%u.", session_id, graph_id, | |||
| static_cast<int>(mode), ge::GetContext().DeviceId()); | |||
| GELOGD("set rt_context: session id: %lu, graph id: %u, mode %d, device id:%u.", | |||
| session_id, graph_id, static_cast<int>(mode), ge::GetContext().DeviceId()); | |||
| rtError_t rt_ret = rtCtxCreate(&rt_context, mode, ge::GetContext().DeviceId()); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| @@ -776,7 +784,7 @@ Status GraphManager::PreRun(const GraphNodePtr &graph_node, const std::vector<Ge | |||
| GE_CHK_STATUS_RET(analyzer_instance->BuildJsonObject(session_id, compute_graph->GetGraphID()), | |||
| "BuildJsonObject Failed") | |||
| GEEVENT("PreRun start, graph node size %zu, session id %lu, graph id %u, graph name %s", | |||
| GEEVENT("PreRun start: graph node size %zu, session id %lu, graph id %u, graph name %s", | |||
| compute_graph->GetDirectNodesSize(), session_id, compute_graph->GetGraphID(), | |||
| compute_graph->GetName().c_str()); | |||
| GE_DUMP(compute_graph, "PreRunBegin"); | |||
| @@ -797,11 +805,12 @@ Status GraphManager::PreRun(const GraphNodePtr &graph_node, const std::vector<Ge | |||
| if (run_optimize_original_graph) { | |||
| Status ret = PreRunOptimizeOriginalGraph(graph_node, inputs, compute_graph, session_id); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Run PreRunOptimizeOriginalGraph failed for graph:%s.", compute_graph->GetName().c_str()); | |||
| GELOGE(ret, "Run PreRunOptimizeOriginalGraph failed for graph:%s", compute_graph->GetName().c_str()); | |||
| return ret; | |||
| } | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kPrepareOptimize); | |||
| ret = PreRunOptimizeSubGraph(graph_node, compute_graph, session_id); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Run PreRunOptimizeSubGraph failed for graph:%s.", compute_graph->GetName().c_str()); | |||
| @@ -823,6 +832,7 @@ Status GraphManager::PreRun(const GraphNodePtr &graph_node, const std::vector<Ge | |||
| } | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| // when set incre build, save om model and var manager | |||
| GeModelPtr ge_model = nullptr; | |||
| auto save_ret = SaveCacheAfterBuild(graph_node->GetGraphId(), compute_graph, ge_model); | |||
| @@ -854,6 +864,7 @@ Status GraphManager::StartForRunGraph(const GraphNodePtr &graph_node, const std: | |||
| // it will not execute graph prreprocess, optimize, parition, build if the graph has built successful. | |||
| Status ret = SUCCESS; | |||
| if (IsGraphNeedBuild(graph_node)) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| if (graph_node->GetBuildFlag()) { | |||
| GELOGE(PARAM_INVALID, | |||
| "The graph %u need to re-build, you should remove it from GE " | |||
| @@ -869,10 +880,11 @@ Status GraphManager::StartForRunGraph(const GraphNodePtr &graph_node, const std: | |||
| // release rts generate context | |||
| RtContextUtil::GetInstance().DestroyRtContexts(session_id, graph_node->GetGraphId()); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "PreRun Failed."); | |||
| GELOGE(ret, "PreRun Failed. graph_id:%u.", graph_node->GetGraphId()); | |||
| return ret; | |||
| } | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelLoad, ErrorMessage::kModelLoad); | |||
| if (!graph_node->IsAsync()) { | |||
| ret = LoadGraph(ge_root_model, graph_node); | |||
| } else { | |||
| @@ -885,6 +897,7 @@ Status GraphManager::StartForRunGraph(const GraphNodePtr &graph_node, const std: | |||
| graph_node->SetBuildFlag(true); | |||
| var_acc_ctrl_.SetGraphBuildEnd(graph_node->GetGraphId()); | |||
| } else if (!graph_node->GetLoadFlag()) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelLoad, ErrorMessage::kModelLoad); | |||
| GeRootModelPtr ge_root_model_ptr = graph_node->GetGeRootModel(); | |||
| if (!graph_node->IsAsync()) { | |||
| ret = LoadGraph(ge_root_model_ptr, graph_node); | |||
| @@ -1042,6 +1055,7 @@ Status GraphManager::InnerRunGraph(GraphNodePtr &graph_node, const GraphId &grap | |||
| Status GraphManager::RunGraph(const GraphId &graph_id, const std::vector<GeTensor> &inputs, | |||
| std::vector<GeTensor> &outputs, uint64_t session_id) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| std::lock_guard<std::mutex> lock(run_mutex_); | |||
| GELOGI("[RunGraph] start to run graph, graph_id = %u, is_train_graph: %d", graph_id, GetTrainFlag()); | |||
| @@ -1094,6 +1108,7 @@ Status GraphManager::RunGraph(const GraphId &graph_id, const std::vector<GeTenso | |||
| return ret; | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelExecute, ErrorMessage::kModelExecute); | |||
| // excute graph | |||
| ret = InnerRunGraph(graph_node, graph_id, inputs, outputs); | |||
| if (ret != SUCCESS) { | |||
| @@ -1209,7 +1224,8 @@ Status GraphManager::BuildGraphForUnregisteredOp(const GraphId &graph_id, const | |||
| Status GraphManager::BuildGraph(const GraphId &graph_id, const std::vector<GeTensor> &inputs, | |||
| GeRootModelPtr &ge_root_model, uint64_t session_id, bool async) { | |||
| GELOGD("[BuildGraph] start to build graph, graph_id=%u.", graph_id); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GELOGD("[BuildGraph] start to build graph, graph_id:%u", graph_id); | |||
| if (inputs.empty()) { | |||
| GELOGW("[BuildGraph] BuildGraph warning: empty GeTensor inputs"); | |||
| } | |||
| @@ -1241,7 +1257,7 @@ Status GraphManager::BuildGraph(const GraphId &graph_id, const std::vector<GeTen | |||
| ret = StartForRunGraph(graph_node, inputs, ge_root_model, session_id); | |||
| graph_node->SetRunFlag(false); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(GE_GRAPH_PRERUN_FAILED, "[BuildGraph] StartForRunGraph failed!"); | |||
| GELOGE(GE_GRAPH_PRERUN_FAILED, "[BuildGraph] StartForRunGraph failed! graph_id:%u.", graph_id); | |||
| return GE_GRAPH_PRERUN_FAILED; | |||
| } | |||
| @@ -1495,7 +1511,7 @@ Status GraphManager::ParseOptions(const std::map<std::string, std::string> &opti | |||
| ParseOption(options, INPUT_SHAPE, options_.input_shape); | |||
| ParseOption(options, kDynamicDims, options_.dynamic_dims); | |||
| ParseOption(options, DYNAMIC_NODE_TYPE, options_.dynamic_node_type); | |||
| GELOGD("Dynamic dims params: input shape is %s, dynamic dims is %s, dynamic node type is %d.", | |||
| GELOGD("Dynamic dims params: input shape is %s, dynamic dims is %s, dynamic node type is %d", | |||
| options_.input_shape.c_str(), options_.dynamic_dims.c_str(), options_.dynamic_node_type); | |||
| // Set Build model and step | |||
| @@ -1508,7 +1524,7 @@ Status GraphManager::ParseOptions(const std::map<std::string, std::string> &opti | |||
| Status GraphManager::ParseTrainGraphFlag(bool &options, bool &option) { | |||
| std::shared_ptr<GELib> ge_instance_ptr = ge::GELib::GetInstance(); | |||
| if (ge_instance_ptr == nullptr) { | |||
| GELOGW("[Initialize] set train_graph_flag_ to 0 when GE is not initialized or finalized."); | |||
| GELOGW("[Initialize] set train_graph_flag to 0 when GE is not initialized or finalized"); | |||
| option = false; | |||
| } else if (!ge_instance_ptr->isTrainMode()) { | |||
| option = false; | |||
| @@ -1525,7 +1541,8 @@ Status GraphManager::ParseTrainGraphFlag(bool &options, bool &option) { | |||
| bool GraphManager::IsPerfLevelInvalid(int32_t perf_level) { | |||
| return ((perf_level != static_cast<int32_t>(GEN_TASK_WITHOUT_L2FUSION)) && | |||
| (perf_level != static_cast<int32_t>(GEN_TASK_WITHOUT_FUSION)) && (perf_level != -1)); | |||
| (perf_level != static_cast<int32_t>(GEN_TASK_WITHOUT_FUSION)) && | |||
| (perf_level != -1)); | |||
| } | |||
| void GraphManager::ParseOption(const std::map<std::string, std::string> &options, const std::string &key, | |||
| @@ -2254,9 +2271,8 @@ Status GraphManager::OptimizeStage2(ge::ComputeGraphPtr &compute_graph) { | |||
| GE_CHK_STATUS_RET(after_merge_passes.AddPass("OptimizeStage2::AfterMergePasses::LinkGenMaskNodesPass", | |||
| new (std::nothrow) | |||
| LinkGenMaskNodesPass(options_.stream_max_parallel_num))); | |||
| GE_CHK_STATUS_RET( | |||
| after_merge_passes.AddPass("OptimizeStage2::HcclContinuousMemcpyPass", | |||
| new (std::nothrow) HcclContinuousMemcpyPass)); | |||
| GE_CHK_STATUS_RET(after_merge_passes.AddPass("OptimizeStage2::HcclContinuousMemcpyPass", | |||
| new (std::nothrow) HcclContinuousMemcpyPass)); | |||
| GE_TIMESTAMP_START(after_merge_passes); | |||
| auto ret = after_merge_passes.Run(compute_graph); | |||
| @@ -2509,8 +2525,10 @@ Status GraphManager::ProcessSubGraphWithMultiThreads(GraphManager *graph_manager | |||
| const SubGraphInfoPtr &sub_graph_info_ptr, | |||
| const std::string &root_graph_name, | |||
| uint64_t session_id, | |||
| const struct ErrorMessage::Context &error_context, | |||
| const GEThreadLocalContext &ge_context) { | |||
| if (sub_graph_info_ptr != nullptr && graph_manager != nullptr) { | |||
| ErrorManager::GetInstance().SetErrorContext(error_context); | |||
| GetContext().SetSessionId(session_id); | |||
| GetThreadLocalContext() = ge_context; | |||
| graph_manager->UpdateLocalOmgContext(root_graph_id); | |||
| @@ -2555,9 +2573,12 @@ Status GraphManager::ProcessSubGraphWithMultiThreads(GraphManager *graph_manager | |||
| // run graph async on session | |||
| Status GraphManager::RunGraphAsync(const GraphId &graph_id, const std::vector<ge::InputTensorInfo> &inputs, | |||
| uint64_t session_id, RunAsyncCallback callback) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelExecute, ErrorMessage::kModelExecute); | |||
| GELOGI("[GraphManager] Start to run graph async, graph_id=%u, inputsSize=%zu.", graph_id, inputs.size()); | |||
| bool ret = prerun_args_q_.Push(PreRunArgs({graph_id, inputs, session_id, GetThreadLocalContext(), callback})); | |||
| bool ret = prerun_args_q_.Push(PreRunArgs({graph_id, inputs, session_id, | |||
| ErrorManager::GetInstance().GetErrorContext(), | |||
| GetThreadLocalContext(), callback})); | |||
| if (!ret) { | |||
| GELOGE(FAILED, "[GraphManager] Run graph async failed, graph_id=%u.", graph_id); | |||
| return FAILED; | |||
| @@ -2644,6 +2665,8 @@ void GraphManager::PreRunThread(GraphManager *graph_manager) { | |||
| GELOGI("A new loop start."); | |||
| ErrorManager::GetInstance().SetErrorContext(args.error_context); | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| GetContext().SetSessionId(args.session_id); | |||
| GetThreadLocalContext() = args.context; | |||
| graph_manager->UpdateLocalOmgContext(args.graph_id); | |||
| @@ -2725,8 +2748,8 @@ void GraphManager::PreRunThread(GraphManager *graph_manager) { | |||
| ge_root_model = graph_node->GetGeRootModel(); | |||
| } | |||
| graph_manager->run_args_q_.Push(RunArgs( { graph_node, args.graph_id, args.session_id, args.input_tensor, | |||
| ge_root_model, GetThreadLocalContext(), args.callback })); | |||
| graph_manager->run_args_q_.Push(RunArgs( { graph_node, args.graph_id, args.session_id, args.error_context, | |||
| args.input_tensor, ge_root_model, GetThreadLocalContext(), args.callback })); | |||
| GELOGI("Loop end."); | |||
| } | |||
| } | |||
| @@ -2812,6 +2835,7 @@ Status GraphManager::ParseInputsDims(const std::vector<InputTensorInfo> &input_t | |||
| } | |||
| void GraphManager::RunThread(GraphManager *graph_manager) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelExecute, ErrorMessage::kModelExecute); | |||
| if (prctl(PR_SET_NAME, ("GE_Run")) != 0) { | |||
| GELOGW("Set thread name failed."); | |||
| } | |||
| @@ -2825,6 +2849,7 @@ void GraphManager::RunThread(GraphManager *graph_manager) { | |||
| GELOGI("A new loop start."); | |||
| ErrorManager::GetInstance().SetErrorContext(args.error_context); | |||
| GetContext().SetSessionId(args.session_id); | |||
| GetThreadLocalContext() = args.context; | |||
| graph_manager->UpdateLocalOmgContext(args.graph_id); | |||
| @@ -2842,6 +2867,7 @@ void GraphManager::RunThread(GraphManager *graph_manager) { | |||
| } | |||
| if (!args.graph_node->GetLoadFlag()) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelLoad, ErrorMessage::kModelLoad); | |||
| ret = graph_manager->LoadGraphAsync(args.ge_root_model, args.graph_node); | |||
| if (ret != SUCCESS || args.ge_root_model == nullptr) { | |||
| StopQueue(graph_manager); | |||
| @@ -2854,6 +2880,7 @@ void GraphManager::RunThread(GraphManager *graph_manager) { | |||
| args.ge_root_model->GetModelId()); | |||
| } | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelExecute, ErrorMessage::kModelExecute); | |||
| if (graph_manager->GetTrainFlag()) { | |||
| ret = graph_manager->graph_executor_.SetGraphContext(graph_manager->GetGraphContext()); | |||
| if (ret != SUCCESS) { | |||
| @@ -3063,6 +3090,15 @@ Status GraphManager::OptimizeSubgraph(const GraphNodePtr &graph_node, ComputeGra | |||
| sub_graph->SetSessionID(session_id); | |||
| sub_graph->SetGraphID(graph_node->GetGraphId()); | |||
| } | |||
| bool off_superkernel = false; | |||
| if (AttrUtils::GetBool(compute_graph, ATTR_NAME_OFF_SUPERKERNEL_ATTR, off_superkernel)) { | |||
| GELOGI("Compute graph %s get superkernel flag %d.", compute_graph->GetName().c_str(), off_superkernel); | |||
| if (!AttrUtils::SetBool(merged_compute_graph, ATTR_NAME_OFF_SUPERKERNEL_ATTR, off_superkernel)) { | |||
| GELOGE(FAILED, "Compute graph %s set superkernel flag %d failed", merged_compute_graph->GetName().c_str(), | |||
| off_superkernel); | |||
| return FAILED; | |||
| } | |||
| } | |||
| GE_TIMESTAMP_EVENT_END(MergeSubgraph, "OptimizeSubgraph::MergeSubGraph"); | |||
| GE_DUMP(merged_compute_graph, "mergedComputeGraph"); | |||
| compute_graph = merged_compute_graph; | |||
| @@ -3101,6 +3137,7 @@ Status GraphManager::ConvertGraphToFile(ComputeGraphPtr &compute_graph, GraphPar | |||
| Status GraphManager::Build(const GraphNodePtr &graph_node, ComputeGraphPtr &compute_graph, | |||
| GeRootModelPtr &ge_root_model, uint64_t session_id) { | |||
| ErrorManager::GetInstance().SetStage(ErrorMessage::kModelCompile, ErrorMessage::kOther); | |||
| // build | |||
| if (compute_graph != nullptr) { | |||
| std::string graph_name = compute_graph->GetName(); | |||
| @@ -3116,7 +3153,7 @@ Status GraphManager::Build(const GraphNodePtr &graph_node, ComputeGraphPtr &comp | |||
| } | |||
| bool is_always_dump = false; | |||
| if (!PropertiesManager::Instance().GetDumpProperties(session_id).GetDumpPath().empty()) { | |||
| if (!DumpManager::GetInstance().GetDumpProperties(session_id).GetDumpPath().empty()) { | |||
| is_always_dump = true; | |||
| } | |||
| @@ -3168,7 +3205,7 @@ Status GraphManager::SaveVariables(const Graph &graph, const std::vector<std::st | |||
| return FAILED; | |||
| } else { | |||
| auto var_tensor = var_results[var_name].GetTensorDesc(); | |||
| var_tensor.SetName(var_name); | |||
| var_tensor.SetName(var_name.c_str()); | |||
| var_results[var_name].SetTensorDesc(var_tensor); | |||
| var_values.emplace_back(var_results[var_name]); | |||
| } | |||
| @@ -3177,7 +3214,7 @@ Status GraphManager::SaveVariables(const Graph &graph, const std::vector<std::st | |||
| for (auto iter = var_results.begin(); iter != var_results.end(); ++iter) { | |||
| string var_name = iter->first; | |||
| auto var_tensor = iter->second.GetTensorDesc(); | |||
| var_tensor.SetName(var_name); | |||
| var_tensor.SetName(var_name.c_str()); | |||
| iter->second.SetTensorDesc(var_tensor); | |||
| var_values.emplace_back(iter->second); | |||
| } | |||
| @@ -196,6 +196,7 @@ class GraphManager { | |||
| GraphId graph_id; | |||
| std::vector<ge::InputTensorInfo> input_tensor; | |||
| uint64_t session_id; | |||
| struct ErrorMessage::Context error_context; | |||
| GEThreadLocalContext context; | |||
| RunAsyncCallback callback; | |||
| }; | |||
| @@ -204,6 +205,7 @@ class GraphManager { | |||
| GraphNodePtr graph_node; | |||
| GraphId graph_id; | |||
| uint64_t session_id; | |||
| struct ErrorMessage::Context error_context; | |||
| std::vector<ge::InputTensorInfo> input_tensor; | |||
| GeRootModelPtr ge_root_model; | |||
| GEThreadLocalContext context; | |||
| @@ -221,6 +223,7 @@ class GraphManager { | |||
| const SubGraphInfoPtr &sub_graph_info_ptr, | |||
| const std::string &root_graph_name, | |||
| uint64_t session_id, | |||
| const struct ErrorMessage::Context &error_context, | |||
| const GEThreadLocalContext &ge_context); | |||
| Status ParseInputsDims(const std::vector<InputTensorInfo> &input_tensor); | |||
| void ParseInputsDimsForData(const std::vector<InputTensorInfo> &input_tensor); | |||
| @@ -26,6 +26,7 @@ | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "framework/common/ge_inner_error_codes.h" | |||
| #include "graph/manager/host_mem_allocator.h" | |||
| #include "graph/node.h" | |||
| #include "runtime/mem.h" | |||
| @@ -139,7 +140,6 @@ class MemoryAllocator { | |||
| using MemoryAllocatorPtr = std::shared_ptr<MemoryAllocator>; | |||
| class CachingAllocator; | |||
| class RdmaPoolAllocator; | |||
| class HostMemAllocator; | |||
| class MemManager { | |||
| public: | |||
| MemManager(); | |||
| @@ -55,7 +55,7 @@ class Params : public Singleton<Params> { | |||
| Params() : target_("MINI") {} | |||
| string target_; | |||
| uint8_t target_8bit_ = 0; | |||
| uint8_t target_8bit_ = TARGET_TYPE_MINI_8BIT; | |||
| }; | |||
| } // namespace ge | |||
| @@ -601,6 +601,8 @@ std::string Cluster::DebugString() const { | |||
| case KNOWN_SHAPE: | |||
| ss << "KNOW"; | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| ss << "[" << id_ << "](size:" << nodes_.size() << ")"; | |||
| ss << "(" << min_ << "," << max_ << ")("; | |||
| @@ -24,9 +24,9 @@ namespace { | |||
| constexpr uint32_t kValidInputNodeOutputNum = 1; | |||
| constexpr int32_t kAssignRefInputIndex = 0; | |||
| constexpr int32_t kAssignValueInputIndex = 1; | |||
| static const std::set<std::string> kNoTaskNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, | |||
| ge::CONSTANT, ge::CONSTANTOP, | |||
| ge::VARIABLE, ge::VARIABLEV2 }; | |||
| const std::set<std::string> kNoTaskNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, | |||
| ge::CONSTANT, ge::CONSTANTOP, | |||
| ge::VARIABLE, ge::VARIABLEV2 }; | |||
| } | |||
| Status AssignRemovePass::Run(NodePtr &node) { | |||
| @@ -167,7 +167,7 @@ bool CastTranslatePass::IsOpSupportedOptimize(NodePtr &cast_node, NodePtr &trans | |||
| trans_op_outdesc->SetDataType(cast_out_datatype); | |||
| } | |||
| if (!TranslateCheckAccuracySupported(trans_op_desc)) { | |||
| if (!TranslateCheckAccuracySupported(trans_node)) { | |||
| if (is_src_cast) { | |||
| trans_op_desc->MutableInputDesc(0)->SetDataType(trans_in_datatype); | |||
| } else { | |||
| @@ -271,7 +271,8 @@ Status CastTranslatePass::FuseDstNTranslates(NodePtr &node) { | |||
| return SUCCESS; | |||
| } | |||
| bool CastTranslatePass::TranslateCheckAccuracySupported(const OpDescPtr &op_desc) { | |||
| bool CastTranslatePass::TranslateCheckAccuracySupported(NodePtr &node) { | |||
| const OpDescPtr &op_desc = node->GetOpDesc(); | |||
| std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
| if ((instance_ptr == nullptr) || (!instance_ptr->InitFlag())) { | |||
| GELOGW("GE is not initialized or is finalized."); | |||
| @@ -293,7 +294,7 @@ bool CastTranslatePass::TranslateCheckAccuracySupported(const OpDescPtr &op_desc | |||
| auto kernel_info_store = kernel_map.find(kernel_name); | |||
| if (kernel_info_store != kernel_map.end()) { | |||
| if (kernel_info_store->second != nullptr && | |||
| kernel_info_store->second->CheckAccuracySupported(op_desc, unsupported_reason)) { | |||
| kernel_info_store->second->CheckAccuracySupported(node, unsupported_reason)) { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -35,7 +35,7 @@ class CastTranslatePass : public BaseNodePass { | |||
| bool IsOpSupportedOptimize(NodePtr &cast_node, NodePtr &trans_node, bool &is_src_cast); | |||
| bool CheckOpSupportOptimize(NodePtr &node, bool &is_src_cast); | |||
| Status FuseDstNTranslates(NodePtr &node); | |||
| bool TranslateCheckAccuracySupported(const OpDescPtr &op_desc); | |||
| bool TranslateCheckAccuracySupported(NodePtr &node); | |||
| }; | |||
| } // namespace ge | |||
| #endif // GE_GRAPH_PASSES_CAST_TRANSLATE_PASS_H_ | |||
| @@ -110,7 +110,7 @@ graphStatus CompileNodesPass::GetSupportedKernel(const NodePtr &node, const std: | |||
| return ge::GE_GRAPH_PARAM_NULLPTR; | |||
| } | |||
| // begin accuracy supported check | |||
| if (!CheckAccuracySupport(kernel_info, instance, op_desc)) { | |||
| if (!CheckAccuracySupport(kernel_info, instance, node)) { | |||
| // if check accuracy support failed , try to go to other engine. | |||
| GELOGD("Check Accuracy Supported return not support, node name is %s. Try to go to other engine.", | |||
| op_desc->GetName().c_str()); | |||
| @@ -123,7 +123,7 @@ graphStatus CompileNodesPass::GetSupportedKernel(const NodePtr &node, const std: | |||
| continue; | |||
| } | |||
| OpsKernelInfoStorePtr tmp_kernel_info = it->second; | |||
| if (CheckAccuracySupport(tmp_kernel_info, instance, op_desc)) { | |||
| if (CheckAccuracySupport(tmp_kernel_info, instance, node)) { | |||
| kernel_lib_name = tmp_kernel_name; | |||
| GELOGD("Find kernel lib %s support node:%s, type:%s , get kernel lib success.", tmp_kernel_name.c_str(), | |||
| node->GetName().c_str(), op_desc->GetType().c_str()); | |||
| @@ -138,14 +138,9 @@ graphStatus CompileNodesPass::GetSupportedKernel(const NodePtr &node, const std: | |||
| } | |||
| bool CompileNodesPass::CheckAccuracySupport(const OpsKernelInfoStorePtr &kernel_info, | |||
| const std::shared_ptr<GELib> instance, OpDescPtr &op_desc) { | |||
| auto ge_desc = MakeShared<ge::OpDescPtr>(op_desc); | |||
| if (ge_desc == nullptr) { | |||
| GELOGE(GE_GRAPH_MEMORY_ALLOC_FAILED, "Fail to malloc op desc."); | |||
| return false; | |||
| } | |||
| const std::shared_ptr<GELib> instance, const NodePtr &node) { | |||
| string reason; | |||
| if (!(kernel_info->CheckAccuracySupported(*ge_desc, reason, true))) { | |||
| if (!(kernel_info->CheckAccuracySupported(node, reason, true))) { | |||
| return false; | |||
| } | |||
| return true; | |||
| @@ -39,7 +39,7 @@ class CompileNodesPass : public GraphPass { | |||
| private: | |||
| graphStatus GetSupportedKernel(const NodePtr &node, const std::shared_ptr<GELib> instance, string &kernel_lib_name); | |||
| bool CheckAccuracySupport(const OpsKernelInfoStorePtr &kernel_info, const std::shared_ptr<GELib> instance, | |||
| OpDescPtr &op_desc); | |||
| const NodePtr &node); | |||
| graphStatus CompileNodes(const std::shared_ptr<GELib> instance, | |||
| std::unordered_map<string, vector<NodePtr>> &kernel_to_compile_nodes); | |||
| }; | |||
| @@ -25,8 +25,9 @@ const uint32_t kElseBranchIndex = 1; | |||
| const uint32_t kTrueIndex = 1; | |||
| const uint32_t kFalseIndex = 0; | |||
| /// Extra 8 bytes store pointer of string | |||
| /// Extra 8 bytes store length of string | |||
| /// Extra 1 byte store '\0' | |||
| const int32_t kStrHeadLen = 9; | |||
| const int32_t kStrHeadLen = sizeof(ge::StringHead) + 1; | |||
| const int32_t kInvalidRetVal = -1; | |||
| } | |||
| @@ -50,13 +50,11 @@ Status RunOpKernelWithCheck(NodePtr &node, | |||
| return FoldingPass::RunOpKernel(node, inputs, outputs); | |||
| } | |||
| const std::map<std::string, std::pair<std::uint64_t, uint64_t>> | |||
| &ConstantFoldingPass::GetGeConstantFoldingPerfStatistic() const { | |||
| const map<string, pair<uint64_t, uint64_t>> &ConstantFoldingPass::GetGeConstantFoldingPerfStatistic() const { | |||
| return statistic_of_ge_constant_folding_; | |||
| } | |||
| const std::map<std::string, std::pair<std::uint64_t, uint64_t>> | |||
| &ConstantFoldingPass::GetOpConstantFoldingPerfStatistic() const { | |||
| const map<string, pair<uint64_t, uint64_t>> &ConstantFoldingPass::GetOpConstantFoldingPerfStatistic() const { | |||
| return statistic_of_op_constant_folding_; | |||
| } | |||
| @@ -29,13 +29,13 @@ const int kRemoveInputIndex = 1; | |||
| Status DimensionAdjustPass::Run(ge::NodePtr &node) { | |||
| if (node == nullptr) { | |||
| GELOGE(PARAM_INVALID, "node is nullptr"); | |||
| GELOGE(PARAM_INVALID, "node is nullptr."); | |||
| return PARAM_INVALID; | |||
| } | |||
| OpDescPtr op_desc_ptr = node->GetOpDesc(); | |||
| if (op_desc_ptr == nullptr) { | |||
| GELOGE(PARAM_INVALID, "GetOpDesc return nullptr"); | |||
| GELOGE(PARAM_INVALID, "GetOpDesc return nullptr."); | |||
| return PARAM_INVALID; | |||
| } | |||
| @@ -33,11 +33,11 @@ Status FlowCtrlPass::Run(ComputeGraphPtr compute_graph) { | |||
| GE_CHECK_NOTNULL(compute_graph); | |||
| if (!PassUtils::IsNeedTrainIteFlowCtrl(compute_graph)) { | |||
| GELOGI("No need FlowCtrl for graph %u", compute_graph->GetGraphID()); | |||
| GELOGI("No need FlowCtrl for graph %u.", compute_graph->GetGraphID()); | |||
| return NOT_CHANGED; | |||
| } | |||
| GELOGI("FlowCtrl pass begin"); | |||
| GELOGI("FlowCtrl pass begin.graph is [%s].", compute_graph->GetName().c_str()); | |||
| bool graph_change = false; | |||
| // 1. Add FP/BP flow ctrl (big cycle) | |||
| for (auto &node : compute_graph->GetDirectNode()) { | |||
| @@ -80,6 +80,16 @@ Status FlowCtrlPass::Run(ComputeGraphPtr compute_graph) { | |||
| graph_change = true; | |||
| } | |||
| } | |||
| // add edge operation below depends on memcpy node in itertor loop set single stream,or may cause block | |||
| for (auto &active_node : active_nodes_in_iter_loop_) { | |||
| auto ret = GraphUtils::AddEdge(active_node->GetOutControlAnchor(), | |||
| assign_add_node_in_fpbp_loop_->GetInControlAnchor()); | |||
| if (ret != GRAPH_SUCCESS) { | |||
| GELOGW("add control edge between iter_loop_node:%s and fpbp_loop_node:%s fail, may cause block", | |||
| active_node->GetName().c_str(), assign_add_node_in_fpbp_loop_->GetName().c_str()); | |||
| } | |||
| } | |||
| GELOGI("FlowCtrl pass end, graph is %s.", graph_change ? "changed" : "not changed"); | |||
| return graph_change ? SUCCESS : NOT_CHANGED; | |||
| } | |||
| @@ -279,16 +289,16 @@ Status FlowCtrlPass::CreateIterCtrlTrueBranch(ComputeGraphPtr &compute_graph, co | |||
| * loopIncrement | |||
| */ | |||
| // Insert AssignAdd node | |||
| NodePtr assign_add_node = | |||
| assign_add_node_in_fpbp_loop_ = | |||
| InsertAssignOp(compute_graph, ASSIGNADD, NODE_NAME_FLOWCTRL_LOOP_ASSIGNADD, loop_cond_node, loop_inc_node); | |||
| if (assign_add_node == nullptr || switch_node == nullptr) { | |||
| if (assign_add_node_in_fpbp_loop_ == nullptr || switch_node == nullptr) { | |||
| GELOGE(PARAM_INVALID, "assign add node or switch node is null"); | |||
| return FAILED; | |||
| } | |||
| string active_name = switch_node->GetName() + "_StreamActive"; | |||
| // add attr for stream assign model to break branch. | |||
| GE_CHK_STATUS_RET(SetStreamLabel(assign_add_node, active_name), "set stream label failed"); | |||
| GE_CHK_STATUS_RET(SetStreamLabel(assign_add_node_in_fpbp_loop_, active_name), "set stream label failed"); | |||
| // used for stream assign to find true branch | |||
| GE_CHK_STATUS_RET(SetActiveLabelList(switch_node, { active_name }), "set active label list failed"); | |||
| @@ -304,13 +314,15 @@ Status FlowCtrlPass::CreateIterCtrlTrueBranch(ComputeGraphPtr &compute_graph, co | |||
| DOMI_LOGE("set ATTR_NAME_IS_LOOP_ACTIVE failed"); return FAILED); | |||
| // add ctrl edges | |||
| graphStatus add_ret = GraphUtils::AddEdge(switch_node->GetOutControlAnchor(), assign_add_node->GetInControlAnchor()); | |||
| graphStatus add_ret = GraphUtils::AddEdge(switch_node->GetOutControlAnchor(), | |||
| assign_add_node_in_fpbp_loop_->GetInControlAnchor()); | |||
| if (add_ret != GRAPH_SUCCESS) { | |||
| GELOGE(FAILED, "Add switch_node to assign_add_node ctrl edge failed, add_ret=%u.", add_ret); | |||
| return FAILED; | |||
| } | |||
| add_ret = GraphUtils::AddEdge(assign_add_node->GetOutControlAnchor(), active_node->GetInControlAnchor()); | |||
| add_ret = GraphUtils::AddEdge(assign_add_node_in_fpbp_loop_->GetOutControlAnchor(), | |||
| active_node->GetInControlAnchor()); | |||
| if (add_ret != GRAPH_SUCCESS) { | |||
| GELOGE(FAILED, "Add assign_add_node to active_node ctrl edge failed, add_ret=%u.", add_ret); | |||
| return FAILED; | |||
| @@ -335,11 +347,11 @@ Status FlowCtrlPass::CreateIterCtrlFalseBranch(ComputeGraphPtr &compute_graph, c | |||
| NodePtr assign_node = | |||
| InsertAssignOp(compute_graph, ASSIGN, NODE_NAME_FLOWCTRL_LOOP_ASSIGN, loop_cond_node, loop_reset_node); | |||
| if (assign_node == nullptr || switch_node == nullptr) { | |||
| GELOGE(PARAM_INVALID, "assign_node or switch node is null"); | |||
| GELOGE(PARAM_INVALID, "assign_node or switch node is null."); | |||
| return FAILED; | |||
| } | |||
| GE_CHK_STATUS_RET(SetStreamLabel(assign_node, switch_node->GetName()), "set stream label failed"); | |||
| GE_CHK_STATUS_RET(SetStreamLabel(assign_node, switch_node->GetName()), "set stream label failed."); | |||
| graphStatus add_ret = GraphUtils::AddEdge(switch_node->GetOutControlAnchor(), assign_node->GetInControlAnchor()); | |||
| if (add_ret != GRAPH_SUCCESS) { | |||
| @@ -358,7 +370,7 @@ Status FlowCtrlPass::CreateIterCtrlFalseBranch(ComputeGraphPtr &compute_graph, c | |||
| } | |||
| GE_CHK_STATUS_RET(SetStreamLabel(active_node, switch_node->GetName()), "set stream label failed"); | |||
| GE_CHK_STATUS_RET(SetSwitchBranchNodeLabel(active_node, switch_node->GetName()), | |||
| "set switch branch node label failed"); | |||
| "set switch branch node label failed."); | |||
| string model_exit_name = switch_node->GetName() + "_ModelExit"; | |||
| GE_CHK_STATUS_RET(SetActiveLabelList(active_node, { model_exit_name }), "set active label list failed"); | |||
| @@ -389,7 +401,7 @@ Status FlowCtrlPass::CreateIterCtrlFalseBranch(ComputeGraphPtr &compute_graph, c | |||
| } | |||
| Status FlowCtrlPass::AddFpBpIteratorCtrl(ComputeGraphPtr &compute_graph, NodePtr &pre_node) { | |||
| GE_IF_BOOL_EXEC(pre_node == nullptr, DOMI_LOGE("pre_node is nullptr"); return FAILED); | |||
| GE_IF_BOOL_EXEC(pre_node == nullptr, DOMI_LOGE("pre_node is nullptr."); return FAILED); | |||
| string pre_node_name = pre_node->GetName(); | |||
| GELOGI("Add FpBp Iterator ctrl, pre node:%s.", pre_node_name.c_str()); | |||
| // 1. Get or add variables | |||
| @@ -465,7 +477,7 @@ Status FlowCtrlPass::AddSpecialNodeIteratorCtrl(ComputeGraphPtr &compute_graph, | |||
| * itersPerLoop loopCond | |||
| */ | |||
| GE_IF_BOOL_EXEC(loop_after_node == nullptr || compute_graph == nullptr, | |||
| DOMI_LOGE("loop after node or compute graph is null"); return FAILED); | |||
| DOMI_LOGE("loop after node or compute graph is null."); return FAILED); | |||
| InDataAnchorPtr in_anchor = loop_after_node->GetInDataAnchor(0); | |||
| if (in_anchor == nullptr || in_anchor->GetPeerOutAnchor() == nullptr) { | |||
| GELOGE(FAILED, "Find %s in data anchor failed.", loop_after_node->GetName().c_str()); | |||
| @@ -486,7 +498,7 @@ Status FlowCtrlPass::AddSpecialNodeIteratorCtrl(ComputeGraphPtr &compute_graph, | |||
| } | |||
| // 2. Add StreamSwitch and edges to switch_node. | |||
| GE_IF_BOOL_EXEC(loop_pre_node == nullptr, DOMI_LOGE("loop pre node is null"); return FAILED); | |||
| GE_IF_BOOL_EXEC(loop_pre_node == nullptr, DOMI_LOGE("loop pre node is null."); return FAILED); | |||
| string switch_name = loop_pre_node->GetName() + "_" + NODE_NAME_STREAM_SWITCH; | |||
| NodePtr switch_node = InsertStreamSwitchOp(compute_graph, switch_name, loop_cond_node, iter_per_loop_node); | |||
| if (switch_node == nullptr) { | |||
| @@ -494,7 +506,7 @@ Status FlowCtrlPass::AddSpecialNodeIteratorCtrl(ComputeGraphPtr &compute_graph, | |||
| return FAILED; | |||
| } | |||
| GE_CHK_STATUS_RET(SetStreamLabel(switch_node, switch_name), "set stream label failed"); | |||
| GE_CHK_STATUS_RET(SetStreamLabel(switch_node, switch_name), "set stream label failed."); | |||
| graphStatus add_ret = GraphUtils::AddEdge(loop_pre_node->GetOutControlAnchor(), switch_node->GetInControlAnchor()); | |||
| if (add_ret != GRAPH_SUCCESS) { | |||
| @@ -517,7 +529,7 @@ Status FlowCtrlPass::AddSpecialNodeIteratorCtrl(ComputeGraphPtr &compute_graph, | |||
| return FAILED; | |||
| } | |||
| GE_CHK_STATUS_RET(SetStreamLabel(active_node, active_name), "set stream label failed"); | |||
| GE_CHK_STATUS_RET(SetStreamLabel(active_node, active_name), "set stream label failed."); | |||
| GE_IF_BOOL_EXEC(!AttrUtils::SetBool(active_node->GetOpDesc(), ATTR_NAME_IS_LOOP_ACTIVE, true), | |||
| DOMI_LOGE("set ATTR_NAME_IS_LOOP_ACTIVE failed"); return FAILED); | |||
| @@ -530,9 +542,10 @@ Status FlowCtrlPass::AddSpecialNodeIteratorCtrl(ComputeGraphPtr &compute_graph, | |||
| } | |||
| // used for stream assign to find true branch | |||
| GE_CHK_STATUS_RET(SetActiveLabelList(switch_node, { active_name }), "set active label list failed"); | |||
| GE_CHK_STATUS_RET(SetActiveLabelList(switch_node, { active_name }), "set active label list failed."); | |||
| // used for stream assign to find active stream | |||
| GE_CHK_STATUS_RET(SetActiveLabelList(active_node, { loop_pre_node->GetName() }), "set active label list failed"); | |||
| active_nodes_in_iter_loop_.push_back(active_node); | |||
| return SUCCESS; | |||
| } | |||
| } // namespace ge | |||
| @@ -142,6 +142,9 @@ class FlowCtrlPass : public GraphPass { | |||
| /// false: only one dataSet exist | |||
| /// | |||
| bool CheckMultiDataSet(ComputeGraphPtr &compute_graph); | |||
| NodePtr assign_add_node_in_fpbp_loop_ = nullptr; | |||
| std::vector<NodePtr> active_nodes_in_iter_loop_; | |||
| }; | |||
| } // namespace ge | |||
| @@ -140,7 +140,8 @@ bool HcclContinuousMemcpyPass::IsDataNode(const std::string& node_type) { | |||
| /// @param [in] ge::OutDataAnchorPtr in_node | |||
| /// @return ge::NodePtr | |||
| /// | |||
| NodePtr HcclContinuousMemcpyPass::CreateIdentityNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_data_anchor) { | |||
| NodePtr HcclContinuousMemcpyPass::CreateIdentityNode(const ComputeGraphPtr &graph, | |||
| const OutDataAnchorPtr &out_data_anchor) { | |||
| GE_CHECK_NOTNULL_EXEC(graph, return nullptr); | |||
| NodePtr pre_node = out_data_anchor->GetOwnerNode(); | |||
| OpDescPtr pre_op_desc = pre_node->GetOpDesc(); | |||
| @@ -205,8 +206,9 @@ std::string HcclContinuousMemcpyPass::CheckDuplicateName(const std::string &node | |||
| /// @param [in] InDataAnchorPtr hccl_in_anchor | |||
| /// @return status | |||
| /// | |||
| Status HcclContinuousMemcpyPass::ModifyEdgeConnection(const ComputeGraphPtr &graph, const OutDataAnchorPtr &src_out_anchor, | |||
| const InDataAnchorPtr &hccl_in_anchor) { | |||
| Status HcclContinuousMemcpyPass::ModifyEdgeConnection(const ComputeGraphPtr &graph, | |||
| const OutDataAnchorPtr &src_out_anchor, | |||
| const InDataAnchorPtr &hccl_in_anchor) { | |||
| GE_CHECK_NOTNULL(src_out_anchor->GetOwnerNode()); | |||
| GE_CHECK_NOTNULL(hccl_in_anchor->GetOwnerNode()); | |||
| @@ -235,8 +237,9 @@ Status HcclContinuousMemcpyPass::ModifyEdgeConnection(const ComputeGraphPtr &gra | |||
| /// @param [in] InDataAnchorPtr hccl_in_anchor | |||
| /// @return status | |||
| /// | |||
| Status HcclContinuousMemcpyPass::InsertIdentityBeforeHccl(const ComputeGraphPtr &graph, const OutDataAnchorPtr &src_out_anchor, | |||
| const InDataAnchorPtr &hccl_in_anchor) { | |||
| Status HcclContinuousMemcpyPass::InsertIdentityBeforeHccl(const ComputeGraphPtr &graph, | |||
| const OutDataAnchorPtr &src_out_anchor, | |||
| const InDataAnchorPtr &hccl_in_anchor) { | |||
| GELOGI("Between op %s and op %s need insert memcpy async op.", src_out_anchor->GetOwnerNode()->GetName().c_str(), | |||
| hccl_in_anchor->GetOwnerNode()->GetName().c_str()); | |||
| NodePtr memcpy_node = CreateIdentityNode(graph, src_out_anchor); | |||
| @@ -274,8 +277,8 @@ Status HcclContinuousMemcpyPass::InsertIdentityBeforeHccl(const ComputeGraphPtr | |||
| /// @return status | |||
| /// | |||
| Status HcclContinuousMemcpyPass::InsertAssignAfterBroadcastIfNeed(const ComputeGraphPtr &graph, | |||
| const OutDataAnchorPtr &var_out_anchor, | |||
| const InDataAnchorPtr &hccl_in_anchor) { | |||
| const OutDataAnchorPtr &var_out_anchor, | |||
| const InDataAnchorPtr &hccl_in_anchor) { | |||
| if (hccl_in_anchor->GetOwnerNode()->GetType() != HCOMBROADCAST) { | |||
| GELOGD("%s not broadcast, no need to insert assign node", hccl_in_anchor->GetOwnerNode()->GetName().c_str()); | |||
| return SUCCESS; | |||
| @@ -354,8 +357,9 @@ Status HcclContinuousMemcpyPass::InsertAssignAfterBroadcastIfNeed(const ComputeG | |||
| /// @param [in] ge::OutDataAnchorPtr variable node out anchor | |||
| /// @return ge::NodePtr | |||
| /// | |||
| NodePtr HcclContinuousMemcpyPass::CreateAssignNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_data_anchor) { | |||
| GE_CHECK_NOTNULL_EXEC(graph , return nullptr); | |||
| NodePtr HcclContinuousMemcpyPass::CreateAssignNode(const ComputeGraphPtr &graph, | |||
| const OutDataAnchorPtr &out_data_anchor) { | |||
| GE_CHECK_NOTNULL_EXEC(graph, return nullptr); | |||
| NodePtr pre_node = out_data_anchor->GetOwnerNode(); | |||
| OpDescPtr pre_op_desc = pre_node->GetOpDesc(); | |||
| if (pre_op_desc == nullptr) { | |||
| @@ -23,9 +23,9 @@ namespace ge { | |||
| namespace { | |||
| constexpr uint32_t kInplaceSupportOutputIndex = 0; | |||
| constexpr uint32_t kInplaceSupportOutputNum = 1; | |||
| static const std::set<std::string> kSrcNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, | |||
| ge::CONSTANT, ge::CONSTANTOP, | |||
| ge::VARIABLE, ge::VARIABLEV2 }; | |||
| const std::set<std::string> kSrcNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, | |||
| ge::CONSTANT, ge::CONSTANTOP, | |||
| ge::VARIABLE, ge::VARIABLEV2 }; | |||
| } | |||
| Status InplaceSupportCheckPass::Run(NodePtr &node) { | |||
| GELOGD("InplaceSupportCheckPass running"); | |||
| @@ -458,7 +458,7 @@ Status NetOutputPass::Run(ge::ComputeGraphPtr graph) { | |||
| GELOGE(GE_GRAPH_PARAM_NULLPTR, "Compute graph is null."); | |||
| return GE_GRAPH_PARAM_NULLPTR; | |||
| } | |||
| GELOGI("NetOutputPass Run."); | |||
| GELOGI("NetOutputPass Run.graph is [%s]", graph->GetName().c_str()); | |||
| NodePtr output_node = graph->FindFirstNodeMatchType(NETOUTPUT); | |||
| // save user targets node | |||
| SaveAndRemoveTargets(graph); | |||
| @@ -82,14 +82,41 @@ Status NoUseReshapeRemovePass::Run(ge::NodePtr &node) { | |||
| } | |||
| } | |||
| if (to_be_deleted) { | |||
| GELOGI("NoUseReshapeRemovePass remove useless node:%s", node->GetName().c_str()); | |||
| auto ret = PassUtils::UnlinkNodeWithControlCopy(node, kReshapeShapeIndex); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "DimensionAdjustPass unlink node with control copy fail."); | |||
| return ret; | |||
| } | |||
| auto ret = TryRemoveConstShapeInput(node); | |||
| GE_CHK_STATUS_RET_NOLOG(ret); | |||
| GELOGI("NoUseReshapeRemovePass remove useless reshape node:%s", node->GetName().c_str()); | |||
| return IsolateAndDeleteNode(node, {kReshapeDataIndex}); | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| Status NoUseReshapeRemovePass::TryRemoveConstShapeInput(ge::NodePtr &reshape_node) { | |||
| auto shape_input_anchor = reshape_node->GetInDataAnchor(kReshapeShapeIndex); | |||
| if (shape_input_anchor == nullptr) { | |||
| return SUCCESS; | |||
| } | |||
| GE_CHECK_NOTNULL(shape_input_anchor->GetPeerOutAnchor()); | |||
| auto shape_input = shape_input_anchor->GetPeerOutAnchor()->GetOwnerNode(); | |||
| GE_CHECK_NOTNULL(shape_input); | |||
| if (shape_input->GetType() != CONSTANT && shape_input->GetType() != CONSTANTOP) { | |||
| return SUCCESS; | |||
| } | |||
| // op(x) const(shape) | |||
| // \ / | |||
| // reshape | |||
| // const input can unlink but should copy control_dependency | |||
| auto ret = PassUtils::UnlinkNodeWithControlCopy(reshape_node, kReshapeShapeIndex); | |||
| if (ret != SUCCESS) { | |||
| GELOGE(ret, "Unlink node %s with control copy failed.", shape_input->GetName().c_str()); | |||
| return ret; | |||
| } | |||
| // remove const without any data_output | |||
| if (shape_input->GetOutDataNodesSize() == 0) { | |||
| auto ret = IsolateAndDeleteNode(shape_input, {}); | |||
| GE_CHK_GRAPH_STATUS_RET(ret, "Fail to remove node %s", shape_input->GetName().c_str()); | |||
| GELOGI("Remove useless shape input const %s.", shape_input->GetName().c_str()); | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| } // namespace ge | |||
| @@ -32,6 +32,9 @@ class NoUseReshapeRemovePass : public BaseNodePass { | |||
| /// @author | |||
| /// | |||
| Status Run(ge::NodePtr &node) override; | |||
| private: | |||
| Status TryRemoveConstShapeInput(NodePtr &reshape_node); | |||
| }; | |||
| } // namespace ge | |||
| @@ -27,12 +27,11 @@ | |||
| namespace ge { | |||
| Status PrunePass::Run(ge::ComputeGraphPtr graph) { | |||
| GELOGD("PrunePass Start"); | |||
| GELOGD("PrunePass Start, graph is [%s]", graph->GetName().c_str()); | |||
| if (graph == nullptr) { | |||
| GELOGE(GE_GRAPH_ISNULL, "input compute graph is NULL."); | |||
| return GE_GRAPH_ISNULL; | |||
| } | |||
| std::vector<NodePtr> out_nodes; | |||
| std::unordered_set<NodePtr> nodes; | |||
| for (NodePtr &node_ptr : graph->GetDirectNode()) { | |||
| @@ -42,7 +41,6 @@ Status PrunePass::Run(ge::ComputeGraphPtr graph) { | |||
| out_nodes.push_back(node_ptr); | |||
| } | |||
| } | |||
| if (out_nodes.empty()) { | |||
| GELOGW("graph [%s] does not contain NETOUTPUT type node,no return value. Do nothing!", graph->GetName().c_str()); | |||
| return ge::SUCCESS; | |||
| @@ -33,7 +33,7 @@ Status ReplaceWithEmptyConstPass::Run(NodePtr &node) { | |||
| GELOGE(PARAM_INVALID, "Param [opDesc] must not be null."); | |||
| return PARAM_INVALID; | |||
| } | |||
| if (node->GetType() == CONSTANT || node->GetType() == CONSTANTOP) { | |||
| if (node->GetType() == CONSTANT || node->GetType() == CONSTANTOP || node->GetType() == DATA) { | |||
| GELOGI("Node %s is const. Ignore current pass.", node->GetName().c_str()); | |||
| return SUCCESS; | |||
| } | |||
| @@ -43,7 +43,7 @@ Status ReshapeRemovePass::Run(NodePtr &node) { | |||
| GE_CHECK_NOTNULL(node); | |||
| GE_CHECK_NOTNULL(node->GetOpDesc()); | |||
| int key = kToBeDeleteOp.find(node->GetType()) == kToBeDeleteOp.end() ? kOpNoDelete : kToBeDeleteOp[node->GetType()]; | |||
| switch(key) { | |||
| switch (key) { | |||
| case kReshapeType: { | |||
| bool is_shape_unknown = false; | |||
| if (NodeUtils::GetNodeUnknownShapeStatus(*node, is_shape_unknown) == GRAPH_SUCCESS) { | |||
| @@ -63,16 +63,17 @@ Status ResourcePairAddControlPass::Run(ComputeGraphPtr graph) { | |||
| NodePtr from_node = prefix_2_node.second; | |||
| GE_CHECK_NOTNULL(from_node); | |||
| auto to_item_prefix_2_node = prefix_2_node_per_type.find(resource_type_pair.second); | |||
| // stackpush and stackpop may exist in two subgraphs, no necessary to report error | |||
| if (to_item_prefix_2_node == prefix_2_node_per_type.end()) { | |||
| GELOGE(PARAM_INVALID, "find peer type node fail, suffix:%s, from_type:%s, to_type:%s", prefix.c_str(), | |||
| GELOGW("find peer type node fail, suffix:%s, from_type:%s, to_type:%s", prefix.c_str(), | |||
| resource_type_pair.first.c_str(), resource_type_pair.second.c_str()); | |||
| return PARAM_INVALID; | |||
| continue; | |||
| } | |||
| auto to_prefix_2_node = to_item_prefix_2_node->second.find(prefix); | |||
| if (to_prefix_2_node == to_item_prefix_2_node->second.end()) { | |||
| GELOGE(PARAM_INVALID, "find peer prefix node fail, suffix:%s, from_type:%s, to_type:%s", prefix.c_str(), | |||
| GELOGW("find peer prefix node fail, suffix:%s, from_type:%s, to_type:%s", prefix.c_str(), | |||
| resource_type_pair.first.c_str(), resource_type_pair.second.c_str()); | |||
| return PARAM_INVALID; | |||
| continue; | |||
| } | |||
| NodePtr to_node = to_prefix_2_node->second; | |||
| GE_CHECK_NOTNULL(to_node); | |||
| @@ -63,16 +63,17 @@ Status ResourcePairRemoveControlPass::Run(ComputeGraphPtr graph) { | |||
| NodePtr from_node = prefix_2_node.second; | |||
| GE_CHECK_NOTNULL(from_node); | |||
| auto to_item_prefix_2_node = prefix_2_node_per_type.find(resource_type_pair.second); | |||
| // stackpush and stackpop may exist in two subgraphs, no necessary to report error | |||
| if (to_item_prefix_2_node == prefix_2_node_per_type.end()) { | |||
| GELOGE(INTERNAL_ERROR, "find peer type node fail, suffix:%s, from_type:%s, to_type:%s", prefix.c_str(), | |||
| GELOGW("find peer type node fail, suffix:%s, from_type:%s, to_type:%s", prefix.c_str(), | |||
| resource_type_pair.first.c_str(), resource_type_pair.second.c_str()); | |||
| return domi::PARAM_INVALID; | |||
| continue; | |||
| } | |||
| auto to_prefix_2_node = to_item_prefix_2_node->second.find(prefix); | |||
| if (to_prefix_2_node == to_item_prefix_2_node->second.end()) { | |||
| GELOGE(INTERNAL_ERROR, "find peer prefix node fail, suffix:%s, from_type:%s, to_type:%s", prefix.c_str(), | |||
| GELOGW("find peer prefix node fail, suffix:%s, from_type:%s, to_type:%s", prefix.c_str(), | |||
| resource_type_pair.first.c_str(), resource_type_pair.second.c_str()); | |||
| return domi::PARAM_INVALID; | |||
| continue; | |||
| } | |||
| NodePtr to_node = to_prefix_2_node->second; | |||
| GE_CHECK_NOTNULL(to_node); | |||
| @@ -67,7 +67,7 @@ OpDescPtr SameTransdataBreadthFusionPass::GetCastOp(const GeTensorDesc &in_desc, | |||
| auto fusion_cast_op_count = atomic_fusion_cast_op_count.fetch_add(1); | |||
| std::stringstream cast_op_name; | |||
| cast_op_name << "fusion_cast_" << fusion_cast_op_count; | |||
| auto node_op = ge::OperatorFactory::CreateOperator(cast_op_name.str(), CAST); | |||
| auto node_op = ge::OperatorFactory::CreateOperator(cast_op_name.str().c_str(), CAST); | |||
| auto cast_op = ge::OpDescUtils::GetOpDescFromOperator(node_op); | |||
| node_op.BreakConnect(); | |||
| if (cast_op == nullptr) { | |||
| @@ -165,14 +165,6 @@ Status SubexpressionMigrationPass::ClassifyDataNodes(const ComputeGraphPtr &grap | |||
| } | |||
| } | |||
| for (const auto &data_nodes : graph_nodes) { | |||
| if (data_nodes.second.size() != graph_nodes.begin()->second.size()) { | |||
| GELOGE(FAILED, "Subgraph %s has invalid Data nodes[%zu != %zu]", | |||
| data_nodes.first->GetName().c_str(), data_nodes.second.size(), graph_nodes.begin()->second.size()); | |||
| return FAILED; | |||
| } | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| @@ -385,7 +385,7 @@ Status SubgraphConstMigrationPass::DetachParallelNode(const ComputeGraphPtr &gra | |||
| // Break Move and follow, Link Data and follow. | |||
| const auto &out_anchor = const_node->GetOutDataAnchor(kZeroIndex); | |||
| const auto in_anchors =out_anchor->GetPeerInDataAnchors(); | |||
| const auto in_anchors = out_anchor->GetPeerInDataAnchors(); | |||
| for (const auto in_anchor : in_anchors) { | |||
| GE_CHK_GRAPH_STATUS_RET(GraphUtils::RemoveEdge(out_anchor, in_anchor), "Remove edge failed"); | |||
| GELOGI("Remove Edge: %s %s", const_node->GetName().c_str(), in_anchor->GetOwnerNode()->GetName().c_str()); | |||
| @@ -86,7 +86,7 @@ Status TransposeTransDataPass::Run(NodePtr &node) { | |||
| if (CheckOneInAndOneOutDataAnchor(out_node)) { | |||
| return FAILED; | |||
| } | |||
| if (!FusionIfNeed(op_desc, out_op_desc)) { | |||
| if (!FusionIfNeed(op_desc, out_node)) { | |||
| continue; | |||
| } | |||
| CopyInputEdges(node, out_node); | |||
| @@ -152,7 +152,8 @@ Status TransposeTransDataPass::RemoveTranspose(NodePtr &node) { | |||
| return SUCCESS; | |||
| } | |||
| bool TransposeTransDataPass::FusionIfNeed(OpDescPtr &op_desc, OpDescPtr &transdata_op_desc) { | |||
| bool TransposeTransDataPass::FusionIfNeed(OpDescPtr &op_desc, NodePtr &node) { | |||
| auto transdata_op_desc = node->GetOpDesc(); | |||
| GE_CHECK_NOTNULL(op_desc); | |||
| GE_CHECK_NOTNULL(transdata_op_desc); | |||
| auto out_input_desc = transdata_op_desc->MutableInputDesc(0); | |||
| @@ -187,7 +188,7 @@ bool TransposeTransDataPass::FusionIfNeed(OpDescPtr &op_desc, OpDescPtr &transda | |||
| out_input_desc->SetFormat(src_format); | |||
| out_input_desc->SetShape(src_shape); | |||
| if (!TransDataCheckAccuracySupported(transdata_op_desc)) { | |||
| if (!TransDataCheckAccuracySupported(node)) { | |||
| out_input_desc->SetFormat(out_input_format); | |||
| out_input_desc->SetShape(out_input_shape); | |||
| return false; | |||
| @@ -224,7 +225,8 @@ void TransposeTransDataPass::CopyInputEdges(NodePtr &origin_node, NodePtr &new_n | |||
| GraphUtils::CopyInCtrlEdges(origin_node, new_node) != GRAPH_SUCCESS, GELOGW("Copy in ctrl edges failed"); return); | |||
| } | |||
| bool TransposeTransDataPass::TransDataCheckAccuracySupported(const OpDescPtr &op_desc) { | |||
| bool TransposeTransDataPass::TransDataCheckAccuracySupported(NodePtr &node) { | |||
| const OpDescPtr &op_desc = node->GetOpDesc(); | |||
| std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
| if ((instance_ptr == nullptr) || (!instance_ptr->InitFlag())) { | |||
| GELOGW("GELib not initialized"); | |||
| @@ -244,7 +246,7 @@ bool TransposeTransDataPass::TransDataCheckAccuracySupported(const OpDescPtr &op | |||
| auto &kernel_name = it.opKernelLib; | |||
| auto kernel_info_store = kernel_map.find(kernel_name); | |||
| if (kernel_info_store != kernel_map.end()) { | |||
| if (kernel_info_store->second->CheckAccuracySupported(op_desc, unsupported_reason, true)) { | |||
| if (kernel_info_store->second->CheckAccuracySupported(node, unsupported_reason, true)) { | |||
| return true; | |||
| } | |||
| } | |||
| @@ -26,9 +26,9 @@ class TransposeTransDataPass : public BaseNodePass { | |||
| private: | |||
| Status CheckOneInAndOneOutDataAnchor(NodePtr &node) const; | |||
| Status RemoveTranspose(NodePtr &node); | |||
| bool FusionIfNeed(OpDescPtr &op_desc, OpDescPtr &transdata_op_desc); | |||
| bool FusionIfNeed(OpDescPtr &op_desc, NodePtr &node); | |||
| void CopyInputEdges(NodePtr &origin_node, NodePtr &new_node); | |||
| bool TransDataCheckAccuracySupported(const OpDescPtr &op_desc); | |||
| bool TransDataCheckAccuracySupported(NodePtr &node); | |||
| }; | |||
| } // namespace ge | |||
| #endif // GE_GRAPH_PASSES_TRANSPOSE_TRANSDATA_PASS_H_ | |||
| @@ -991,7 +991,6 @@ Status ParseDynamicInputShapeRange(const std::string &shape_range, | |||
| Status GetDynamicInputShapeRange(const std::vector<GeTensor> &user_input, const std::map<string, string> &graph_option, | |||
| vector<vector<std::pair<int64_t, int64_t>>> &range_vec) { | |||
| // check both mode and shape_range option are all enabled | |||
| auto mode_iter = graph_option.find(OPTION_EXEC_DYNAMIC_EXECUTE_MODE); | |||
| bool enable_dynamic_execute_mode = (mode_iter != graph_option.end()) && (mode_iter->second == "dynamic_execute"); | |||
| if (!enable_dynamic_execute_mode) { | |||
| @@ -1272,9 +1271,10 @@ Status GraphPrepare::AdjustDataOpOutput(const NodePtr &node) { | |||
| return SUCCESS; | |||
| } | |||
| Status GraphPrepare::UpdateInput(const std::vector<GeTensor> &user_input, const std::map<string,string> &graph_option) { | |||
| Status GraphPrepare::UpdateInput(const std::vector<GeTensor> &user_input, | |||
| const std::map<string, string> &graph_option) { | |||
| // Get shape range of input in dynamic_execute mode | |||
| vector<vector<std::pair<int64_t,int64_t>>> dynamic_shape_range_vec; | |||
| vector<vector<std::pair<int64_t, int64_t>>> dynamic_shape_range_vec; | |||
| auto ret = GetDynamicInputShapeRange(user_input, graph_option, dynamic_shape_range_vec); | |||
| GE_CHK_STATUS_RET(ret, "Graph option is not right on Dynamic execute mode."); | |||
| compute_graph_->SaveDataFormat(ge::TypeUtils::DomiFormatToFormat(GetLocalOmgContext().format)); | |||
| @@ -2012,7 +2012,8 @@ Status GraphPrepare::ProcessNetOutput() { | |||
| return SUCCESS; | |||
| } | |||
| Status GraphPrepare::CheckAndUpdateInput(const std::vector<GeTensor> &user_input,const std::map<string,string> &graph_option) { | |||
| Status GraphPrepare::CheckAndUpdateInput(const std::vector<GeTensor> &user_input, | |||
| const std::map<string, string> &graph_option) { | |||
| compute_graph_->SetInputSize(user_input.size()); | |||
| if (user_input.empty()) { | |||
| return SUCCESS; | |||
| @@ -23,7 +23,7 @@ | |||
| #include <vector> | |||
| #include "common/debug/log.h" | |||
| #include "common/debug/memory_dumper.h" | |||
| #include "common/model_parser/base.h" | |||
| #include "common/model_parser/model_parser.h" | |||
| #include "common/properties_manager.h" | |||
| #include "common/string_util.h" | |||
| #include "common/types.h" | |||
| @@ -63,8 +63,8 @@ class GraphPrepare { | |||
| Status CheckRefOp(); | |||
| Status SetRtContext(rtContext_t rt_context, rtCtxMode_t mode); | |||
| Status AdjustDataOpOutput(const NodePtr &node); | |||
| Status UpdateInput(const std::vector<GeTensor> &user_input, const std::map<string,string> &graph_option); | |||
| Status CheckAndUpdateInput(const std::vector<GeTensor> &user_input, const std::map<string,string> &graph_option); | |||
| Status UpdateInput(const std::vector<GeTensor> &user_input, const std::map<string, string> &graph_option); | |||
| Status CheckAndUpdateInput(const std::vector<GeTensor> &user_input, const std::map<string, string> &graph_option); | |||
| Status CheckConstOp(); | |||
| Status VerifyConstOp(const NodePtr &node); | |||
| Status CheckUserInput(const std::vector<GeTensor> &user_input); | |||
| @@ -600,7 +600,7 @@ Status MultiBatchGraphCopyer::LabelInBatchBranchStatus() { | |||
| for (auto &in_node : node->GetInDataNodes()) { | |||
| if (origin_nodes_status_.find(in_node.get()) != origin_nodes_status_.end()) { | |||
| if (origin_nodes_status_.find(node.get()) == origin_nodes_status_.end()) { | |||
| origin_nodes_status_[node.get()] == kNodeInBatchBranch; | |||
| origin_nodes_status_[node.get()] = kNodeInBatchBranch; | |||
| ResetEnterStatus(frame_enters, node); | |||
| changed = true; | |||
| } | |||
| @@ -105,7 +105,7 @@ GE_FUNC_VISIBILITY bool CheckDynamicBatchShape(const vector<int64_t> &shape, con | |||
| /// @return 0: true/false | |||
| /// | |||
| GE_FUNC_VISIBILITY bool CheckDynamicImageSizeShape(const vector<int64_t> &shape, const string &data_name, | |||
| const std::string &input_format); | |||
| const std::string &input_format); | |||
| } // namespace multibatch | |||
| } // namespace ge | |||
| @@ -111,8 +111,9 @@ void DynamicStitchKernel::ComputeMergedShape(const vector<ConstGeTensorPtr> &inp | |||
| int32_t merged_first_dim = 0; | |||
| int64_t indices_shape_size = 0; | |||
| for (int i = 0; i < n_; i++) { | |||
| indices_shape_size = input[i]->GetTensorDesc().GetShape().GetShapeSize(); | |||
| indices_shape_size = indices_shape_size == 0 ? 1 : indices_shape_size; | |||
| // shape is [] means scalar | |||
| indices_shape_size = | |||
| input[i]->GetTensorDesc().GetShape().GetDims().empty() ? 1 : input[i]->GetTensorDesc().GetShape().GetShapeSize(); | |||
| const int32_t *input_indices = reinterpret_cast<const int32_t *>(input[i]->GetData().data()); | |||
| for (int64_t j = 0; j < indices_shape_size; j++) { | |||
| merged_first_dim = std::max(merged_first_dim, input_indices[j]); | |||
| @@ -16,6 +16,8 @@ | |||
| #include "host_kernels/slice_kernel.h" | |||
| #include <set> | |||
| #include "common/ge_inner_error_codes.h" | |||
| #include "common/op/ge_op_utils.h" | |||
| #include "common/types.h" | |||
| @@ -31,6 +33,30 @@ const size_t kSliceInputSize = 3; | |||
| const size_t kSliceInputIndexX = 0; | |||
| const size_t kSliceInputIndexBegin = 1; | |||
| const size_t kSliceInputIndexSize = 2; | |||
| const std::set<ge::DataType> kSupportedDataTypeToLength = { | |||
| DT_BOOL, | |||
| DT_INT64, | |||
| DT_UINT64, | |||
| DT_FLOAT, | |||
| DT_INT32, | |||
| DT_UINT32, | |||
| DT_INT8, | |||
| DT_UINT8, | |||
| DT_INT16, | |||
| DT_UINT16, | |||
| DT_FLOAT16, | |||
| DT_DOUBLE, | |||
| DT_DUAL, | |||
| DT_DUAL_SUB_INT8, | |||
| DT_DUAL_SUB_UINT8, | |||
| DT_COMPLEX64, | |||
| DT_COMPLEX128, | |||
| DT_QINT8, | |||
| DT_QINT16, | |||
| DT_QINT32, | |||
| DT_QUINT8, | |||
| DT_QUINT16, | |||
| }; | |||
| } // namespace | |||
| Status SliceKernel::Compute(const OpDescPtr attr, const std::vector<ConstGeTensorPtr> &input, | |||
| @@ -56,6 +82,16 @@ Status SliceKernel::Compute(const OpDescPtr attr, const std::vector<ConstGeTenso | |||
| // data type in input_x | |||
| auto data_type = x_->GetTensorDesc().GetDataType(); | |||
| // check supported | |||
| if (kSupportedDataTypeToLength.count(data_type) == 0) { | |||
| GELOGW("input_x data_type is [%s], does not supported!", TypeUtils::DataTypeToSerialString(data_type).c_str()); | |||
| return NOT_CHANGED; | |||
| } | |||
| uint32_t type_size = 0; | |||
| bool is_success = TypeUtils::GetDataTypeLength(data_type, type_size); | |||
| if (!is_success) { | |||
| return NOT_CHANGED; | |||
| } | |||
| // check data type of begin and size | |||
| if (begin->GetTensorDesc().GetDataType() != DT_INT32 || size->GetTensorDesc().GetDataType() != DT_INT32) { | |||
| GELOGW("Data type of begin and size for slice are not DT_INT32."); | |||
| @@ -69,7 +105,7 @@ Status SliceKernel::Compute(const OpDescPtr attr, const std::vector<ConstGeTenso | |||
| GE_CHECK_NOTNULL(begin_data); | |||
| GE_CHECK_NOTNULL(size_data); | |||
| size_t data_size = x_->GetData().size() / sizeof(int32_t); | |||
| size_t data_size = x_->GetData().size() / type_size; | |||
| size_t begin_size = begin->GetData().size() / sizeof(int32_t); | |||
| size_t size_size = size->GetData().size() / sizeof(int32_t); | |||
| const ge::GeShape &x_shape = x_->GetTensorDesc().GetShape(); | |||
| @@ -62,9 +62,9 @@ struct GraphExecutionContext { | |||
| rtStream_t stream = nullptr; | |||
| rtContext_t rt_context = nullptr; | |||
| rtContext_t rt_gen_context = nullptr; | |||
| std::unique_ptr<CallbackManager> callback_manager; | |||
| std::unique_ptr<CallbackManager> callback_manager = nullptr; | |||
| NpuMemoryAllocator *allocator = nullptr; | |||
| mutable std::unique_ptr<HybridProfiler> profiler; | |||
| mutable std::unique_ptr<HybridProfiler> profiler = nullptr; | |||
| DumpProperties dump_properties; | |||
| bool trace_enabled = false; | |||
| bool dump_enabled = false; | |||
| @@ -26,6 +26,7 @@ namespace hybrid { | |||
| namespace { | |||
| const int kDataOutputIndex = 0; | |||
| const size_t kMinimumPiplineStages = 2; | |||
| const int kDefaultLoopCount = 10; | |||
| } | |||
| HybridModelAsyncExecutor::HybridModelAsyncExecutor(HybridModel *model) | |||
| : model_(model), run_flag_(false) { | |||
| @@ -45,6 +46,10 @@ void HybridModelAsyncExecutor::SetModelId(uint32_t model_id) { | |||
| model_id_ = model_id; | |||
| } | |||
| void HybridModelAsyncExecutor::SetModelName(const string &model_name) { | |||
| om_name_ = model_name; | |||
| } | |||
| Status HybridModelAsyncExecutor::EnqueueData(const shared_ptr<InputDataWrapper> &data) { | |||
| GE_CHK_STATUS_EXEC(data_inputer_->Push(data), return domi::DATA_QUEUE_ISFULL, | |||
| "Data queue is full, please call again later, model_id %u ", model_id_); | |||
| @@ -80,6 +85,10 @@ Status HybridModelAsyncExecutor::Stop() { | |||
| ret = future_.get(); | |||
| } | |||
| if (is_op_debug_reg_) { | |||
| op_debug_register_.UnregisterDebugForStream(stream_); | |||
| } | |||
| if (stream_ != nullptr) { | |||
| GE_CHK_RT(rtStreamDestroy(stream_)); | |||
| stream_ = nullptr; | |||
| @@ -96,6 +105,7 @@ Status HybridModelAsyncExecutor::Init() { | |||
| executor_ = std::unique_ptr<HybridModelExecutor>(new(std::nothrow) HybridModelExecutor(model_, device_id_, stream_)); | |||
| GE_CHECK_NOTNULL(executor_); | |||
| GE_CHK_STATUS_RET(executor_->Init(), "Failed to init hybrid engine"); | |||
| GE_CHK_STATUS_RET(DumpOpDebug(),"Dump op debug failed in hybrid engine"); | |||
| GELOGI("HybridModel stage nums:%zu", model_->GetRootGraphItem()->NumGroups()); | |||
| if (model_->GetRootGraphItem()->NumGroups() >= kMinimumPiplineStages) { | |||
| @@ -150,7 +160,7 @@ Status HybridModelAsyncExecutor::RunInternal() { | |||
| GELOGI("HybridModel will execute in pipeline mode"); | |||
| auto iter_per_run = std::getenv("ITER_NUM"); | |||
| if (iter_per_run) { | |||
| args.num_loops = static_cast<int>(strtol(iter_per_run, nullptr, 10)); | |||
| args.num_loops = static_cast<int>(strtol(iter_per_run, nullptr, kDefaultLoopCount)); | |||
| } | |||
| ret = pipe_executor_->Execute(args); | |||
| } else { | |||
| @@ -250,7 +260,8 @@ Status HybridModelAsyncExecutor::PrepareInputs(const InputData ¤t_data, Hy | |||
| if (k >= shape.GetDimNum()) { | |||
| break; | |||
| } | |||
| if (shape.GetDim(k) < range[k].first || shape.GetDim(k) > range[k].second) { | |||
| // range[k].second can be -1 | |||
| if (shape.GetDim(k) < range[k].first || (range[k].second >= 0 && shape.GetDim(k) > range[k].second)) { | |||
| GELOGE(PARAM_INVALID, "Dim out of range, shape idx = %zu, dim idx = %zu, dim = %ld, range = [%ld, %ld]", | |||
| input_index, k, shape.GetDim(k), range[k].first, range[k].second); | |||
| return PARAM_INVALID; | |||
| @@ -452,8 +463,8 @@ Status HybridModelAsyncExecutor::Execute(const std::vector<DataBuffer> &inputs, | |||
| i, outputs[i].length, output_real_size); | |||
| return FAILED; | |||
| } | |||
| GE_CHK_RT_RET(rtMemcpy(outputs[i].data, outputs[i].length, args.outputs[i].GetData(), output_real_size, | |||
| RT_MEMCPY_DEVICE_TO_DEVICE)); | |||
| GE_CHK_RT_RET(rtMemcpy(outputs[i].data, outputs[i].length, args.outputs[i].GetData(), output_real_size, | |||
| RT_MEMCPY_DEVICE_TO_DEVICE)); | |||
| } | |||
| outputs[i].length = output_real_size; | |||
| } | |||
| @@ -502,5 +513,40 @@ Status HybridModelAsyncExecutor::Execute(const vector<GeTensor> &inputs, vector< | |||
| return SUCCESS; | |||
| } | |||
| Status HybridModelAsyncExecutor::DumpOpDebug() { | |||
| const DumpProperties &dump_properties = executor_->GetContext()->dump_properties; | |||
| if (dump_properties.IsOpDebugOpen()) { | |||
| GELOGD("Opdebug is open in hybrid engine"); | |||
| uint32_t op_debug_mode = dump_properties.GetOpDebugMode(); | |||
| GE_CHK_RT_RET(op_debug_register_.RegisterDebugForStream(stream_, op_debug_mode, data_dumper_)); | |||
| is_op_debug_reg_ = true; | |||
| data_dumper_.SetDumpProperties(dump_properties); | |||
| data_dumper_.SetModelName(model_->GetModelName()); | |||
| data_dumper_.SetModelId(model_->GetModelId()); | |||
| data_dumper_.SetDeviceId(model_->GetDeviceId()); | |||
| void *global_step = nullptr; | |||
| TensorValue *varible_global_step = model_->GetVariable(NODE_NAME_GLOBAL_STEP); | |||
| if (varible_global_step != nullptr) { | |||
| global_step = const_cast<void *>(varible_global_step->GetData()); | |||
| } | |||
| void *loop_per_iter = nullptr; | |||
| TensorValue *varible_loop_per_iter = model_->GetVariable(NODE_NAME_FLOWCTRL_LOOP_PER_ITER); | |||
| if (varible_loop_per_iter != nullptr) { | |||
| loop_per_iter = const_cast<void *>(varible_loop_per_iter->GetData()); | |||
| } | |||
| void *loop_cond = nullptr; | |||
| TensorValue *varible_loop_cond = model_->GetVariable(NODE_NAME_FLOWCTRL_LOOP_COND); | |||
| if (varible_loop_cond != nullptr) { | |||
| loop_cond = const_cast<void *>(varible_loop_cond->GetData()); | |||
| } | |||
| data_dumper_.SetLoopAddr(global_step, loop_per_iter, loop_cond); | |||
| GE_CHK_STATUS_RET(data_dumper_.LoadDumpInfo(), "LoadDumpInfo failed in hybrid engine"); | |||
| GELOGD("Dump op debug SUCCESS in hybrid engine"); | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| } // namespace hybrid | |||
| } // namespace ge | |||