Browse Source

Merge remote-tracking branch 'upstream/master' into master

pull/1168/head
chenyemeng 4 years ago
parent
commit
9e3e52edcd
100 changed files with 2118 additions and 1150 deletions
  1. +19
    -2
      cmake/external_libs/gtest.cmake
  2. +6
    -2
      ge/CMakeLists.txt
  3. +10
    -10
      ge/analyzer/analyzer.cc
  4. +34
    -7
      ge/client/ge_api.cc
  5. +1
    -1
      ge/common/CMakeLists.txt
  6. +2
    -2
      ge/common/cust_aicpu_kernel_store.cc
  7. +31
    -17
      ge/common/dump/dump_manager.cc
  8. +5
    -5
      ge/common/dump/dump_manager.h
  9. +3
    -3
      ge/common/dump/dump_op.cc
  10. +5
    -1
      ge/common/dump/dump_properties.cc
  11. +2
    -2
      ge/common/dump/dump_properties.h
  12. +148
    -0
      ge/common/dump/opdebug_register.cc
  13. +44
    -0
      ge/common/dump/opdebug_register.h
  14. +11
    -11
      ge/common/formats/format_transfers/datatype_transfer.cc
  15. +26
    -24
      ge/common/formats/format_transfers/format_transfer_c1hwncoc0_hwcn.cc
  16. +11
    -11
      ge/common/formats/format_transfers/format_transfer_dhwcn_fracz3D.cc
  17. +11
    -11
      ge/common/formats/format_transfers/format_transfer_dhwnc_fracz3D_transpose.cc
  18. +49
    -35
      ge/common/formats/format_transfers/format_transfer_fractal_nz.cc
  19. +28
    -28
      ge/common/formats/format_transfers/format_transfer_fractal_z.cc
  20. +49
    -35
      ge/common/formats/format_transfers/format_transfer_fractal_zz.cc
  21. +25
    -23
      ge/common/formats/format_transfers/format_transfer_fracz_hwcn.cc
  22. +24
    -22
      ge/common/formats/format_transfers/format_transfer_fracz_nchw.cc
  23. +32
    -29
      ge/common/formats/format_transfers/format_transfer_hwcn_c1hwncoc0.cc
  24. +27
    -24
      ge/common/formats/format_transfers/format_transfer_nc1hwc0_nhwc.cc
  25. +45
    -45
      ge/common/formats/format_transfers/format_transfer_nchw_fz_c04.cc
  26. +28
    -26
      ge/common/formats/format_transfers/format_transfer_nchw_nc1hwc0.cc
  27. +34
    -31
      ge/common/formats/format_transfers/format_transfer_nhwc_nc1hwc0.cc
  28. +11
    -11
      ge/common/formats/format_transfers/format_transfer_transpose.cc
  29. +10
    -10
      ge/common/formats/formats.cc
  30. +4
    -11
      ge/common/helper/model_cache_helper.cc
  31. +103
    -14
      ge/common/helper/model_helper.cc
  32. +4
    -7
      ge/common/model_parser/model_parser.cc
  33. +0
    -0
      ge/common/model_parser/model_parser.h
  34. +0
    -20
      ge/common/properties_manager.cc
  35. +0
    -9
      ge/common/properties_manager.h
  36. +1
    -1
      ge/engine_manager/dnnengine_manager.cc
  37. +2
    -1
      ge/executor/CMakeLists.txt
  38. +52
    -12
      ge/executor/ge_executor.cc
  39. +1
    -0
      ge/ge_local_engine/ops_kernel_store/op/ge_deleted_op.cc
  40. +10
    -2
      ge/ge_runtime/runtime_model.cc
  41. +57
    -10
      ge/ge_runtime/task/label_goto_task.cc
  42. +6
    -2
      ge/ge_runtime/task/label_goto_task.h
  43. +96
    -41
      ge/generator/ge_generator.cc
  44. +11
    -1
      ge/graph/build/graph_builder.cc
  45. +35
    -25
      ge/graph/build/logical_stream_allocator.cc
  46. +12
    -3
      ge/graph/build/memory/binary_block_mem_assigner.cc
  47. +111
    -32
      ge/graph/build/memory/block_mem_assigner.cc
  48. +230
    -108
      ge/graph/build/memory/graph_mem_assigner.cc
  49. +1
    -1
      ge/graph/build/memory/graph_mem_assigner.h
  50. +16
    -5
      ge/graph/build/model_builder.cc
  51. +0
    -4
      ge/graph/execute/graph_execute.cc
  52. +3
    -11
      ge/graph/load/graph_loader.cc
  53. +2
    -2
      ge/graph/load/graph_loader.h
  54. +3
    -3
      ge/graph/load/model_manager/data_dumper.cc
  55. +8
    -13
      ge/graph/load/model_manager/data_dumper.h
  56. +95
    -112
      ge/graph/load/model_manager/davinci_model.cc
  57. +10
    -6
      ge/graph/load/model_manager/davinci_model.h
  58. +19
    -25
      ge/graph/load/model_manager/model_manager.cc
  59. +2
    -1
      ge/graph/load/model_manager/model_manager.h
  60. +1
    -1
      ge/graph/load/model_manager/model_utils.cc
  61. +33
    -9
      ge/graph/load/model_manager/task_info/label_goto_ex_task_info.cc
  62. +8
    -6
      ge/graph/load/model_manager/task_info/label_goto_ex_task_info.h
  63. +3
    -3
      ge/graph/load/model_manager/task_info/label_set_task_info.h
  64. +8
    -16
      ge/graph/load/model_manager/task_info/label_switch_by_index_task_info.cc
  65. +9
    -11
      ge/graph/load/model_manager/task_info/label_switch_by_index_task_info.h
  66. +101
    -21
      ge/graph/manager/graph_caching_allocator.cc
  67. +12
    -2
      ge/graph/manager/graph_caching_allocator.h
  68. +84
    -28
      ge/graph/manager/graph_manager.cc
  69. +3
    -3
      ge/graph/manager/graph_manager.h
  70. +3
    -1
      ge/graph/manager/graph_manager_utils.h
  71. +11
    -7
      ge/graph/manager/graph_var_manager.cc
  72. +1
    -1
      ge/graph/optimize/common/params.h
  73. +2
    -0
      ge/graph/partition/dynamic_shape_partition.cc
  74. +4
    -3
      ge/graph/passes/cast_translate_pass.cc
  75. +1
    -1
      ge/graph/passes/cast_translate_pass.h
  76. +4
    -9
      ge/graph/passes/compile_nodes_pass.cc
  77. +1
    -1
      ge/graph/passes/compile_nodes_pass.h
  78. +2
    -1
      ge/graph/passes/cond_remove_pass.cc
  79. +2
    -2
      ge/graph/passes/dimension_adjust_pass.cc
  80. +12
    -12
      ge/graph/passes/flow_ctrl_pass.cc
  81. +2
    -0
      ge/graph/passes/net_output_pass.cc
  82. +1
    -1
      ge/graph/passes/replace_with_empty_const_pass.cc
  83. +5
    -4
      ge/graph/passes/resource_pair_add_control_pass.cc
  84. +5
    -4
      ge/graph/passes/resource_pair_remove_control_pass.cc
  85. +1
    -1
      ge/graph/passes/same_transdata_breadth_fusion_pass.cc
  86. +0
    -8
      ge/graph/passes/subexpression_migration_pass.cc
  87. +7
    -5
      ge/graph/passes/transpose_transdata_pass.cc
  88. +2
    -2
      ge/graph/passes/transpose_transdata_pass.h
  89. +25
    -20
      ge/graph/preprocess/graph_preprocess.cc
  90. +1
    -1
      ge/graph/preprocess/graph_preprocess.h
  91. +1
    -1
      ge/graph/preprocess/multi_batch_copy_graph.cc
  92. +6
    -6
      ge/host_kernels/concat_offset_kernel.cc
  93. +3
    -2
      ge/host_kernels/dynamic_stitch_kernel.cc
  94. +14
    -14
      ge/host_kernels/gather_v2_kernel.cc
  95. +1
    -0
      ge/host_kernels/identity_kernel.cc
  96. +37
    -1
      ge/host_kernels/slice_kernel.cc
  97. +9
    -9
      ge/host_kernels/strided_slice_kernel.cc
  98. +56
    -22
      ge/hybrid/executor/hybrid_model_async_executor.cc
  99. +10
    -0
      ge/hybrid/executor/hybrid_model_async_executor.h
  100. +2
    -1
      ge/hybrid/executor/hybrid_model_executor.cc

+ 19
- 2
cmake/external_libs/gtest.cmake View File

@@ -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)


+ 6
- 2
ge/CMakeLists.txt View File

@@ -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"
@@ -937,6 +937,10 @@ add_library(atc_stub_ge_compiler SHARED

add_dependencies(atc_stub_ge_compiler ge_stub)

target_compile_options(atc_stub_ge_compiler PRIVATE
-fno-common
)

target_link_libraries(atc_stub_ge_compiler PRIVATE
$<BUILD_INTERFACE:intf_pub>
)


+ 10
- 10
ge/analyzer/analyzer.cc View File

@@ -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


+ 34
- 7
ge/client/ge_api.cc View File

@@ -79,14 +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;
}

ErrorManager::GetInstance().GenWorkStreamIdDefault();
// 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);
@@ -101,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) {
@@ -108,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);
@@ -133,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.");
}
@@ -140,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) {
@@ -159,16 +171,17 @@ Status GEInitialize(const std::map<AscendString, AscendString> &options) {

// GE finalize, releasing all resources
Status GEFinalize() {
GELOGT(TRACE_INIT, "GEFinalize start");

ErrorManager::GetInstance().GenWorkStreamIdDefault();
std::lock_guard<std::mutex> lock(g_ge_release_mutex);
// check init status
if (!g_ge_initialized) {
GELOGW("GEFinalize is called before GEInitialize");
GELOGW("[FINAL][FINAL]GEFinalize is called before GEInitialize");
return SUCCESS;
}

std::lock_guard<std::mutex> lock(g_ge_release_mutex);
ErrorManager::GetInstance().SetStage(ErrorMessage::kFinalize, ErrorMessage::kFinalize);
ErrorManager::GetInstance().GenWorkStreamIdDefault();
GELOGT(TRACE_INIT, "GEFinalize start");

// call Finalize
Status ret = SUCCESS;
Status middle_ret;
@@ -217,6 +230,7 @@ std::string GEGetWarningMsg() {

// 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();
@@ -249,6 +263,7 @@ 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();
@@ -292,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) {
@@ -327,12 +343,14 @@ 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();
@@ -352,6 +370,7 @@ 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();
@@ -380,6 +399,7 @@ 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);
@@ -387,6 +407,7 @@ Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph) {

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();
@@ -409,6 +430,7 @@ 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);
@@ -478,6 +500,7 @@ 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);
@@ -521,6 +544,7 @@ 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()) {
@@ -538,6 +562,7 @@ 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()) {
@@ -557,6 +582,7 @@ 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()) {
@@ -573,6 +599,7 @@ 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()) {


+ 1
- 1
ge/common/CMakeLists.txt View File

@@ -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"


+ 2
- 2
ge/common/cust_aicpu_kernel_store.cc View File

@@ -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

+ 31
- 17
ge/common/dump/dump_manager.cc View File

@@ -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

+ 5
- 5
ge/common/dump/dump_manager.h View File

@@ -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_

+ 3
- 3
ge/common/dump/dump_op.cc View File

@@ -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");


+ 5
- 1
ge/common/dump/dump_properties.cc View File

@@ -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_;


+ 2
- 2
ge/common/dump/dump_properties.h View File

@@ -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_;



+ 148
- 0
ge/common/dump/opdebug_register.cc View File

@@ -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

+ 44
- 0
ge/common/dump/opdebug_register.h View File

@@ -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_

+ 11
- 11
ge/common/formats/format_transfers/datatype_transfer.cc View File

@@ -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;


+ 26
- 24
ge/common/formats/format_transfers/format_transfer_c1hwncoc0_hwcn.cc View File

@@ -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)


+ 11
- 11
ge/common/formats/format_transfers/format_transfer_dhwcn_fracz3D.cc View File

@@ -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)


+ 11
- 11
ge/common/formats/format_transfers/format_transfer_dhwnc_fracz3D_transpose.cc View File

@@ -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)


+ 49
- 35
ge/common/formats/format_transfers/format_transfer_fractal_nz.cc View File

@@ -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)


+ 28
- 28
ge/common/formats/format_transfers/format_transfer_fractal_z.cc View File

@@ -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)


+ 49
- 35
ge/common/formats/format_transfers/format_transfer_fractal_zz.cc View File

@@ -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)


+ 25
- 23
ge/common/formats/format_transfers/format_transfer_fracz_hwcn.cc View File

@@ -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)


+ 24
- 22
ge/common/formats/format_transfers/format_transfer_fracz_nchw.cc View File

@@ -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)


+ 32
- 29
ge/common/formats/format_transfers/format_transfer_hwcn_c1hwncoc0.cc View File

@@ -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;
}
}



+ 27
- 24
ge/common/formats/format_transfers/format_transfer_nc1hwc0_nhwc.cc View File

@@ -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
- 45
ge/common/formats/format_transfers/format_transfer_nchw_fz_c04.cc View File

@@ -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)


+ 28
- 26
ge/common/formats/format_transfers/format_transfer_nchw_nc1hwc0.cc View File

@@ -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
- 31
ge/common/formats/format_transfers/format_transfer_nhwc_nc1hwc0.cc View File

@@ -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;
}
}



+ 11
- 11
ge/common/formats/format_transfers/format_transfer_transpose.cc View File

@@ -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;


+ 10
- 10
ge/common/formats/formats.cc View File

@@ -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);


+ 4
- 11
ge/common/helper/model_cache_helper.cc View File

@@ -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;


+ 103
- 14
ge/common/helper/model_helper.cc View File

@@ -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;
@@ -92,12 +87,13 @@ Status ModelHelper::SaveSizeToModelDef(const GeModelPtr &ge_model) {

std::shared_ptr<ModelTaskDef> model_task_def = ge_model->GetModelTaskDefPtr();
if (model_task_def == nullptr) {
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Create model task def ptr failed");
return ACL_ERROR_GE_MEMORY_ALLOCATION;
GELOGD("SaveSizeToModelDef task_info_size is 0.");
om_info.push_back(0);
} else {
size_t partition_task_size = model_task_def->ByteSizeLong();
GELOGD("SaveSizeToModelDef task_info_size is %zu", partition_task_size);
om_info.push_back(partition_task_size);
}
size_t partition_task_size = model_task_def->ByteSizeLong();
GELOGD("SaveSizeToModelDef task_info_size is %zu", partition_task_size);
om_info.push_back(partition_task_size);

GE_CHK_BOOL_EXEC(ge::AttrUtils::SetListInt(*(ge_model.get()), "om_info_list", om_info),
GELOGE(FAILED, "SetListInt of om_info_list failed.");
@@ -464,7 +460,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 +509,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 +875,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

ge/common/model_parser/base.cc → ge/common/model_parser/model_parser.cc View File

@@ -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() {}

ge/common/model_parser/base.h → ge/common/model_parser/model_parser.h View File


+ 0
- 20
ge/common/properties_manager.cc View File

@@ -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

+ 0
- 9
ge/common/properties_manager.h View File

@@ -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



+ 1
- 1
ge/engine_manager/dnnengine_manager.cc View File

@@ -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);


+ 2
- 1
ge/executor/CMakeLists.txt View File

@@ -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"
@@ -212,6 +212,7 @@ target_link_libraries(ge_executor PRIVATE
add_library(ge_executor_shared SHARED ${SRC_LIST} ${PROTO_HDRS})

target_compile_options(ge_executor_shared PRIVATE
-fno-common
-Werror
-O2
-Wno-deprecated-declarations


+ 52
- 12
ge/executor/ge_executor.cc View File

@@ -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,21 +23,15 @@
#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"
#include "graph/opsproto_manager.h"
#include "ge_local_engine/engine/host_cpu_engine.h"

using std::string;
using std::vector;
@@ -56,7 +49,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;
@@ -208,6 +201,33 @@ bool IsDynmaicDimsSizeMatchModel(const vector<uint64_t> cur_dynamic_dims,
namespace ge {
bool GeExecutor::isInit_ = false;

static void InitOpsProtoManager() {
string opsproto_path;
const char *path_env = std::getenv("ASCEND_OPP_PATH");
if (path_env != nullptr) {
string path = path_env;
string file_path = RealPath(path.c_str());
if (file_path.empty()) {
GELOGE(FAILED, "[Check][EnvPath]ASCEND_OPP_PATH path [%s] is invalid.", path.c_str());
REPORT_INPUT_ERROR("E68016", {"ASCEND_OPP_PATH", path});
return;
}
opsproto_path = (path + "/op_proto/custom/" + ":") + (path + "/op_proto/built-in/");
GELOGI("Get opsproto so path from env : %s", path.c_str());
} else {
string path_base = PluginManager::GetPath();
GELOGI("path_base is %s", path_base.c_str());
path_base = path_base.substr(0, path_base.rfind('/'));
path_base = path_base.substr(0, path_base.rfind('/') + 1);
opsproto_path = (path_base + "ops/op_proto/custom/" + ":") + (path_base + "ops/op_proto/built-in/");
}
GELOGI("Get opsproto path is %s", opsproto_path.c_str());
OpsProtoManager *manager = OpsProtoManager::Instance();
map<string, string> option_tmp;
option_tmp.emplace(std::pair<string, string>(string("ge.opsProtoLibPath"), opsproto_path));
(void)manager->Initialize(option_tmp);
}

GeExecutor::GeExecutor() {}

Status GeExecutor::Initialize() {
@@ -217,6 +237,16 @@ Status GeExecutor::Initialize() {
return ge::SUCCESS;
}

OpTilingManager::GetInstance().LoadSo();

Status init_hostcpu_engine_status = HostCpuEngine::GetInstance().Initialize();
if (init_hostcpu_engine_status != SUCCESS) {
GELOGE(init_hostcpu_engine_status, "Failed to initialize HostCpuEngine");
return init_hostcpu_engine_status;
}

InitOpsProtoManager();

std::vector<rtMemType_t> mem_type(1, RT_MEMORY_HBM);
mem_type.push_back(RT_MEMORY_P2P_DDR);
auto ret = MemManager::Instance().Initialize(mem_type);
@@ -931,12 +961,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,


+ 1
- 0
ge/ge_local_engine/ops_kernel_store/op/ge_deleted_op.cc View File

@@ -38,6 +38,7 @@ REGISTER_OP_CREATOR(ExpandDims, GeDeletedOp);
REGISTER_OP_CREATOR(Reshape, GeDeletedOp);
REGISTER_OP_CREATOR(ReFormat, GeDeletedOp);
REGISTER_OP_CREATOR(Squeeze, GeDeletedOp);
REGISTER_OP_CREATOR(Unsqueeze, GeDeletedOp);
REGISTER_OP_CREATOR(Size, GeDeletedOp);
REGISTER_OP_CREATOR(Shape, GeDeletedOp);
REGISTER_OP_CREATOR(ShapeN, GeDeletedOp);


+ 10
- 2
ge/ge_runtime/runtime_model.cc View File

@@ -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]);
}
}



+ 57
- 10
ge/ge_runtime/task/label_goto_task.cc View File

@@ -16,14 +16,12 @@

#include "ge_runtime/task/label_goto_task.h"
#include "ge_runtime/task/task_factory.h"
#include "framework/common/util.h"

namespace ge {
namespace model_runner {
LabelGotoTask::LabelGotoTask(const ModelContext &model_context, const std::shared_ptr<LabelGotoTaskInfo> &task_info)
: TaskRepeater<LabelGotoTaskInfo>(model_context, task_info),
task_info_(task_info),
stream_(nullptr),
label_(nullptr) {
: TaskRepeater<LabelGotoTaskInfo>(model_context, task_info), task_info_(task_info) {
if (task_info_ == nullptr) {
GELOGW("task_info_ is null!");
return;
@@ -42,29 +40,78 @@ LabelGotoTask::LabelGotoTask(const ModelContext &model_context, const std::share
label_ = label_list[label_id];
}

LabelGotoTask::~LabelGotoTask() {}
LabelGotoTask::~LabelGotoTask() {
GE_FREE_RT_LOG(label_info_);
GE_FREE_RT_LOG(index_value_);
}

bool LabelGotoTask::Distribute() {
GELOGI("LabelGotoTask Distribute start.");
if (!CheckParamValid()) {
return false;
}

const std::vector<void *> label_list = { label_ };
rtError_t rt_ret = rtMalloc(&index_value_, sizeof(uint64_t), RT_MEMORY_HBM);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: %#x", rt_ret);
return false;
}

uint64_t branch_index = 0;
rt_ret = rtMemcpy(index_value_, sizeof(uint64_t), &branch_index, sizeof(uint64_t), RT_MEMCPY_HOST_TO_DEVICE);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: %#x", rt_ret);
return false;
}

uint32_t label_info_size = sizeof(rtLabelDevInfo) * label_list.size();
rt_ret = rtMalloc(&label_info_, label_info_size, RT_MEMORY_HBM);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: %#x", rt_ret);
return false;
}

rt_ret = rtLabelListCpy(label_list.data(), label_list.size(), label_info_, label_info_size);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: %#x", rt_ret);
return false;
}

rt_ret = rtLabelSwitchByIndex(index_value_, label_list.size(), label_info_, stream_);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: %#x", rt_ret);
return false;
}

GELOGI("DistributeTask end.");
return true;
}

bool LabelGotoTask::CheckParamValid() {
if (stream_ == nullptr) {
GELOGE(PARAM_INVALID, "stream is null!");
return false;
}

if (label_ == nullptr) {
GELOGE(PARAM_INVALID, "label is null!");
return false;
}
rtError_t rt_ret = rtLabelGotoEx(label_, stream_);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", rt_ret);

if (label_info_ != nullptr) {
GELOGE(PARAM_INVALID, "label_info_ has dirty data.");
return false;
}

if (index_value_ != nullptr) {
GELOGE(PARAM_INVALID, "index_value_ has dirty data.");
return false;
}

GELOGI("DistributeTask end.");
return true;
}

REGISTER_TASK(TaskInfoType::LABEL_GOTO, LabelGotoTask, LabelGotoTaskInfo);

} // namespace model_runner
} // namespace ge

+ 6
- 2
ge/ge_runtime/task/label_goto_task.h View File

@@ -31,9 +31,13 @@ class LabelGotoTask : public TaskRepeater<LabelGotoTaskInfo> {
bool Distribute() override;

private:
bool CheckParamValid();

std::shared_ptr<LabelGotoTaskInfo> task_info_;
void *stream_;
void *label_;
void *stream_{nullptr};
void *label_{nullptr};
void *label_info_{nullptr};
void *index_value_{nullptr};
};
} // namespace model_runner
} // namespace ge


+ 96
- 41
ge/generator/ge_generator.cc View File

@@ -50,9 +50,13 @@ const char *const kFileNameSuffix = "online";
const char *const kAicpuAllshape = "_AllShape";
constexpr char const *kAttrSupportDynamicShape = "support_dynamicshape";
const int64_t kDynamicDimValue = -2;
const int kDefaultDeviceId = 0;
const int kDefaultJobId = 0;

std::map<ge::OpEngineType, std::string> engine_type_map{
{ge::ENGINE_SYS, kEngineNameDefault}, {ge::ENGINE_AICORE, kAIcoreEngine}, {ge::ENGINE_VECTOR, kVectorEngine}};
{ge::ENGINE_SYS, kEngineNameDefault},
{ge::ENGINE_AICORE, kAIcoreEngine},
{ge::ENGINE_VECTOR, kVectorEngine}};

bool ContainsDynamicInpus(const ge::OpDesc &op_desc) {
for (auto &tensor_desc : op_desc.GetAllInputsDescPtr()) {
@@ -66,7 +70,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.");
@@ -82,8 +87,9 @@ static Status CheckEngineTypeSupport(const OpDescPtr &op_desc, OpEngineType engi
} else {
ErrorManager::GetInstance().ATCReportErrMessage("E14001", {"opname", "optype", "value", "reason"},
{op_desc->GetName(), op_desc->GetType(), "engine type",
"it only support kEngineNameDefault/kAIcoreEngine/kVectorEngine"});
GELOGE(FAILED, "CheckEngineType: engine type: %d not support", static_cast<int>(engine_type));
"it only support default/AIcoreEngine/VectorEngine"});
GELOGE(FAILED, "[Check][EngineType]value:%d not support, "
"only support default/AIcoreEngine/VectorEngine now", static_cast<int>(engine_type));
return FAILED;
}

@@ -123,7 +129,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(),
@@ -187,17 +193,20 @@ static Status AddInputs(const ComputeGraphPtr &graph, const NodePtr &node, const

(void)AttrUtils::SetBool(data_op, "_is_single_op", true);

GE_CHK_BOOL_EXEC(data_op->AddInputDesc(tensor) == GRAPH_SUCCESS, return FAILED, "Add input desc fail.");
GE_CHK_BOOL_EXEC(data_op->AddOutputDesc(tensor) == GRAPH_SUCCESS, return FAILED, "Add output desc fail.");
GE_CHK_BOOL_EXEC(data_op->AddInputDesc(tensor) == GRAPH_SUCCESS, return FAILED,
"[Add][InputDesc]fail for node:%s", data_op->GetName().c_str());
GE_CHK_BOOL_EXEC(data_op->AddOutputDesc(tensor) == GRAPH_SUCCESS, return FAILED,
"[Add][OutputDesc]fail for node:%s", data_op->GetName().c_str());
if (attr) {
GE_CHK_BOOL_EXEC(AttrUtils::SetInt(data_op, ATTR_NAME_INDEX, index), return FAILED, "Set index fail.");
GE_CHK_BOOL_EXEC(AttrUtils::SetInt(data_op, ATTR_NAME_INDEX, index), return FAILED,
"[Set][Attr:%s]fail for node:%s", ATTR_NAME_INDEX.c_str(), data_op->GetName().c_str());
}

ge::NodePtr arg_node = graph->AddNode(data_op);
GE_CHK_BOOL_EXEC(arg_node != nullptr, return FAILED, "Insert Data node fail.");
GE_CHK_BOOL_EXEC(arg_node != nullptr, return FAILED, "Insert Data node fail");

GE_CHK_STATUS(GraphUtils::AddEdge(arg_node->GetOutDataAnchor(0), node->GetInDataAnchor(index)),
"Add edge[%s->%s] fail.", data_op->GetName().c_str(), node->GetName().c_str());
"[Add][Edge]fail from node:%s to node:%s", data_op->GetName().c_str(), node->GetName().c_str());

return SUCCESS;
}
@@ -212,20 +221,23 @@ static Status AddOutputs(const ComputeGraphPtr &graph, const NodePtr &node, cons
for (const auto &out_desc : outputs) {
GeTensorDesc tensor = out_desc.GetTensorDesc();
TensorUtils::SetInputTensor(tensor, true);
GE_CHK_BOOL_EXEC(op_desc->AddInputDesc(tensor) == GRAPH_SUCCESS, return FAILED, "Add input desc fail");
GE_CHK_BOOL_EXEC(op_desc->AddInputDesc(tensor) == GRAPH_SUCCESS, return FAILED,
"[Add][InputDesc]fail for node:%s", op_desc->GetName().c_str());

TensorUtils::SetInputTensor(tensor, false);
TensorUtils::SetOutputTensor(tensor, true);
GE_CHK_BOOL_EXEC(op_desc->AddOutputDesc(tensor) == GRAPH_SUCCESS, return FAILED, "Add output desc fail");
GE_CHK_BOOL_EXEC(op_desc->AddOutputDesc(tensor) == GRAPH_SUCCESS, return FAILED,
"[Add][OutputDesc]fail for node:%s", op_desc->GetName().c_str());
count++;
}
GE_CHECK_NOTNULL_EXEC(graph, return PARAM_INVALID);
ge::NodePtr out_node = graph->AddNode(op_desc);
GE_CHK_BOOL_EXEC(out_node != nullptr, return FAILED, "Insert Output node fail.");
GE_CHK_BOOL_EXEC(out_node != nullptr, return FAILED,
"[Add][Node:%s]fail in graph:%u", op_desc->GetName().c_str(), graph->GetGraphID());
GE_CHECK_NOTNULL_EXEC(node, return PARAM_INVALID);
for (int32_t i = 0; i < count; ++i) {
GE_CHK_STATUS(GraphUtils::AddEdge(node->GetOutDataAnchor(i), out_node->GetInDataAnchor(i)),
"Add edge[%s->%s] fail.", node->GetName().c_str(), out_node->GetName().c_str());
"[Add][Edge]fail from node:%s to node:%s", node->GetName().c_str(), out_node->GetName().c_str());
}

return SUCCESS;
@@ -326,6 +338,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 +388,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 +400,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);
}

@@ -548,6 +565,44 @@ bool GeGenerator::Impl::SetOmSystemInfo(AttrHolder &obj) {
return true;
}

Status GeGenerator::SetModelNameForDump(const GeRootModelPtr &ge_root_model) {
bool is_unknown_shape = false;
Status ret = ge_root_model->CheckIsUnknownShape(is_unknown_shape);
if (ret != SUCCESS) {
GELOGE(FAILED, "[Check][IsUnknownShape]Check root model is unknown shape failed, model id:%u",
ge_root_model->GetModelId());
REPORT_CALL_ERROR("E19999", "Check root model is unknown shape failed, model id:%zu",
ge_root_model->GetModelId());
return FAILED;
}
GeModelPtr model_root = nullptr;
if (is_unknown_shape) {
model_root = MakeShared<GeModel>();
GE_CHECK_NOTNULL(model_root);
model_root->SetGraph(GraphUtils::CreateGraphFromComputeGraph(ge_root_model->GetRootGraph()));
ge_root_model->SetSubgraphInstanceNameToModel(ge_root_model->GetRootGraph()->GetName(), model_root);
}

ModelHelper model_helper;
string model_name;
GE_CHECK_NOTNULL(ge_root_model->GetRootGraph());
Status name_ret = model_helper.GetModelNameFromMergedGraphName(ge_root_model->GetRootGraph()->GetName(),
model_name);
if (name_ret != SUCCESS) {
ErrorManager::GetInstance().ATCReportErrMessage("E10000", {"parameter"}, {"output"});
GELOGE(FAILED, "[Check][GetModelNameStep]Get model_name failed. Param --output is invalid, root graph name: %s",
ge_root_model->GetRootGraph()->GetName().c_str());
REPORT_CALL_ERROR("E19999", "Get model_name failed. Param --output is invalid,",
"root graph name: %s", ge_root_model->GetRootGraph()->GetName().c_str());
return PARAM_INVALID;
}
map<string, GeModelPtr> name_to_ge_model = ge_root_model->GetSubgraphInstanceNameToModel();
GeModelPtr &ge_model = name_to_ge_model[ge_root_model->GetRootGraph()->GetName()];
GE_CHECK_NOTNULL(ge_model);
ge_model->SetName(model_name);
return SUCCESS;
}

Status GeGenerator::GenerateModel(const Graph &graph, const string &file_name_prefix, const vector<GeTensor> &inputs,
ModelBufferData &model, bool is_offline) {
rtContext_t ctx = nullptr;
@@ -582,20 +637,10 @@ Status GeGenerator::GenerateModel(const Graph &graph, const string &file_name_pr
}

GE_CHECK_NOTNULL(ge_root_model);
GE_CHECK_NOTNULL(ge_root_model->GetRootGraph());
ModelHelper model_helper;
string model_name = "";
Status name_ret = model_helper.GetModelNameFromMergedGraphName(ge_root_model->GetRootGraph()->GetName(),
model_name);
if (name_ret != SUCCESS) {
ErrorManager::GetInstance().ATCReportErrMessage("E10000", {"parameter"}, {"output"});
GELOGE(FAILED, "Get model_name failed. Param --output is invalid.");
return PARAM_INVALID;
ret = SetModelNameForDump(ge_root_model);
if (ret != SUCCESS) {
return ret;
}
map<string, GeModelPtr> name_to_ge_model = ge_root_model->GetSubgraphInstanceNameToModel();
GeModelPtr &ge_model = name_to_ge_model[ge_root_model->GetRootGraph()->GetName()];
GE_RETURN_WITH_LOG_IF_FALSE(ge_model != nullptr, "ge_model cannot be null");
ge_model->SetName(model_name);
ret = impl_->SaveRootModel(file_name_prefix, ge_root_model, model);
if (ret != SUCCESS) {
GELOGE(ret, "Save model failed");
@@ -692,22 +737,23 @@ 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.");
GELOGE(ret, "[Check][EngineType]value:%d for node:%s not support", engine_type, node->GetName().c_str());
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;
@@ -754,6 +800,7 @@ 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) {
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;
@@ -775,6 +822,7 @@ 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) {
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);
@@ -862,13 +910,12 @@ Status GeGenerator::Impl::SaveRootModel(const string &file_name_prefix, GeRootMo
"ge root model has no sub model")
GeModelPtr model_root = nullptr;
if (is_unknown_shape) {
model_root = make_shared<GeModel>();
model_root->SetGraph(GraphUtils::CreateGraphFromComputeGraph(ge_root_model->GetRootGraph()));
ge_root_model->SetSubgraphInstanceNameToModel(ge_root_model->GetRootGraph()->GetName(), model_root);
model_root->SetName(ge_root_model->GetRootGraph()->GetName());
auto name_to_ge_model = ge_root_model->GetSubgraphInstanceNameToModel();
model_root = name_to_ge_model[ge_root_model->GetRootGraph()->GetName()];
} else {
model_root = ge_root_model->GetSubgraphInstanceNameToModel().begin()->second;
}
GE_CHECK_NOTNULL(model_root);
// set atc version
if (!SetAtcVersionInfo(*(model_root.get()))) {
GELOGW("SetPackageVersionInfo of atc failed!");
@@ -906,12 +953,20 @@ Status GeGenerator::Impl::BuildModel(const Graph &graph, const vector<GeTensor>

static std::atomic<uint64_t> atomic_session_id(0);
auto session_id = atomic_session_id.fetch_add(1);
// This is a temporary add for graph with variable
auto version = static_cast<int32_t>(SessionVersion::ClOUD_VERSION);
ret = VarManager::Instance(session_id)->Init(version, session_id, kDefaultDeviceId, kDefaultJobId);
GELOGI("Start init var instance, session_id %lu", session_id);
if (ret != SUCCESS) {
GELOGW("Failed init var instance, session_id %lu", session_id);
}
if (is_singleop_unregistered_) {
ret = graph_manager_.BuildGraphForUnregisteredOp(graph_id, inputs, ge_root_model, session_id);
} else {
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);


+ 11
- 1
ge/graph/build/graph_builder.cc View File

@@ -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");
@@ -381,7 +387,7 @@ static Status InsertMemcpyNode(const ComputeGraphPtr &graph, const OutDataAnchor
GE_CHECK_NOTNULL(out_anchor);
NodePtr in_node = out_anchor->GetOwnerNode();
GE_CHECK_NOTNULL(in_node);
OpDescBuilder op_desc_builder(name, MEMCPYADDRASYNC);
OpDescBuilder op_desc_builder(name, MEMCPYASYNC);
OpDescPtr op_desc = op_desc_builder.AddInput("x", in_node->GetOpDesc()->GetOutputDesc(0))
.AddOutput("y", in_node->GetOpDesc()->GetOutputDesc(0))
.Build();
@@ -394,6 +400,10 @@ static Status InsertMemcpyNode(const ComputeGraphPtr &graph, const OutDataAnchor
}

static Status GenerateTaskForConstant(const std::shared_ptr<ComputeGraph> &graph) {
if (graph->GetGraphUnknownFlag()) {
GELOGI("Graph %s is unknown graph, ignore gen_task for constant.", graph->GetName().c_str());
return SUCCESS;
}
for (auto &node : graph->GetDirectNode()) {
// CONSTANT not generate task, so insert IDENTITY between CONSTANT and NETOUTPUT
auto op_desc = node->GetOpDesc();


+ 35
- 25
ge/graph/build/logical_stream_allocator.cc View File

@@ -33,13 +33,21 @@ using std::queue;
namespace ge {
LogicalStreamPass::LogicalStreamPass(const string &name) : name_(name) {}

const string &LogicalStreamPass::GetName() const { return name_; }
const string &LogicalStreamPass::GetName() const {
return name_;
}

bool LogicalStreamPass::IsEngineSkip(const Subgraph &subgraph) const { return subgraph.engine_conf.skip_assign_stream; }
bool LogicalStreamPass::IsEngineSkip(const Subgraph &subgraph) const {
return subgraph.engine_conf.skip_assign_stream;
}

bool LogicalStreamPass::IsEngineAttach(const Subgraph &subgraph) const { return subgraph.engine_conf.attach; }
bool LogicalStreamPass::IsEngineAttach(const Subgraph &subgraph) const {
return subgraph.engine_conf.attach;
}

bool LogicalStreamPass::IsEngineIndependent(const Subgraph &subgraph) const { return subgraph.engine_conf.independent; }
bool LogicalStreamPass::IsEngineIndependent(const Subgraph &subgraph) const {
return subgraph.engine_conf.independent;
}

bool LogicalStreamPass::HasStreamLabel(const Subgraph &subgraph) const {
return !subgraph.subgraph_info.GetStreamLabel().empty();
@@ -60,14 +68,14 @@ Status AssignByLabelPass::Run(ComputeGraphPtr graph, const vector<SubgraphPtr> &
// Subgraphs of the same stream_label are assigned to the same stream,
// and different stream_labels are assigned new streams.
auto iter = label_streams.find(stream_label);
if (iter != label_streams.end()) {
subgraph->stream_id = iter->second;
} else {
if (iter == label_streams.end()) {
subgraph->stream_id = next_stream;
GELOGI("Assign new stream %ld for label %s.", next_stream, stream_label.c_str());

label_streams.emplace(stream_label, next_stream);
++next_stream;
next_stream++;
} else {
subgraph->stream_id = iter->second;
}
changed = true;
}
@@ -92,15 +100,15 @@ Status IndependentStreamPass::Run(ComputeGraphPtr graph, const vector<SubgraphPt
const string &stream_label = subgraph->subgraph_info.GetStreamLabel();
auto &label_streams = engine_streams[engine];
auto iter = label_streams.find(stream_label);
if (iter != label_streams.end()) {
subgraph->stream_id = iter->second;
} else {
if (iter == label_streams.end()) {
subgraph->stream_id = next_stream;
GELOGI("Assign new independent stream %ld for engine %s (label: %s).", next_stream, engine.c_str(),
stream_label.c_str());

label_streams.emplace(stream_label, next_stream);
++next_stream;
next_stream++;
} else {
subgraph->stream_id = iter->second;
}
changed = true;
}
@@ -121,7 +129,9 @@ Status AssignByDependencyPass::Run(ComputeGraphPtr graph, const vector<SubgraphP
}

SubgraphPtr reusable_subgraph = GetReusableSubgraph(subgraph, end_subgraph_map, pld_subgraph_map);
if (reusable_subgraph != nullptr) {
if (reusable_subgraph == nullptr) {
(void)AssignNewStream(subgraph);
} else {
if (HasAssignedStream(*reusable_subgraph)) {
subgraph->stream_id = reusable_subgraph->stream_id;
} else {
@@ -140,8 +150,6 @@ Status AssignByDependencyPass::Run(ComputeGraphPtr graph, const vector<SubgraphP
GELOGI("Subgraph %s of engine %s reuses stream of subgraph %s of engine %s.", subgraph->name.c_str(),
subgraph->engine_conf.id.c_str(), reusable_subgraph->name.c_str(),
reusable_subgraph->engine_conf.id.c_str());
} else {
(void)AssignNewStream(subgraph);
}
changed = true;
}
@@ -191,13 +199,15 @@ bool AssignByDependencyPass::CouldReuse(const SubgraphPtr &subgraph, const Subgr
auto iter = pld_subgraph_map.find(end_pld_pair.second);
if (iter != pld_subgraph_map.end()) {
const SubgraphPtr &pred_subgraph_succ = iter->second;
if (pred_subgraph_succ != subgraph && pred_subgraph_succ->engine_conf.id == pred_subgraph->engine_conf.id) {
if ((pred_subgraph_succ != subgraph) &&
(pred_subgraph_succ->engine_conf.id == pred_subgraph->engine_conf.id)) {
return false;
}
}
}

if ((subgraph->engine_conf.id == pred_subgraph->engine_conf.id) || IsEngineAttach(*subgraph)) {
if ((subgraph->engine_conf.id == pred_subgraph->engine_conf.id) ||
IsEngineAttach(*subgraph)) {
return true;
}

@@ -406,7 +416,7 @@ Status UpdateForSkippedEnginePass::Run(ComputeGraphPtr graph, const vector<Subgr
auto op_desc = node->GetOpDesc();
GE_CHECK_NOTNULL(op_desc);
auto stream_id = op_desc->GetStreamId();
if (stream_id != kInvalidStream && !HasStreamLabel(*subgraph)) {
if ((stream_id != kInvalidStream) && !HasStreamLabel(*subgraph)) {
ops_without_label.emplace(op_desc);
}
}
@@ -463,7 +473,7 @@ Status AllReduceParallelPass::Run(ComputeGraphPtr graph, const vector<SubgraphPt

for (const NodePtr &node : graph->GetDirectNode()) {
if (!IsHcomNode(node->GetType()) ||
node->GetInDataNodes().size() <= 1) {
(node->GetInDataNodes().size() <= 1)) {
continue;
}

@@ -575,7 +585,7 @@ Status LogicalStreamAllocator::DoAssign(const ComputeGraphPtr &graph, const Grap
GE_CHECK_NOTNULL(graph);

NodePtr parent_node = graph->GetParentNode();
if (parent_node == nullptr || parent_node->GetOpDesc() == nullptr) {
if ((parent_node == nullptr) || (parent_node->GetOpDesc() == nullptr)) {
context_.default_stream = kInvalidStream;
} else {
context_.default_stream = parent_node->GetOpDesc()->GetStreamId();
@@ -597,7 +607,7 @@ Status LogicalStreamAllocator::DoAssign(const ComputeGraphPtr &graph, const Grap
return status;
}

GELOGD("Subgraphs of graph %s:", graph->GetName().c_str());
GELOGD("Subgraphs of graph %s", graph->GetName().c_str());
for (const auto &subgraph : subgraphs) {
if (subgraph != nullptr) {
GELOGD("subgraph: %s", subgraph->name.c_str());
@@ -686,7 +696,7 @@ void LogicalStreamAllocator::RefreshContinuousStreams(const ComputeGraphPtr &gra
auto op_desc = node->GetOpDesc();
if (op_desc != nullptr) {
int64_t stream_id = op_desc->GetStreamId();
if (stream_id != kInvalidStream && stream_id < stream_num) {
if ((stream_id != kInvalidStream) && (stream_id < stream_num)) {
stream_has_node[stream_id] = true;
}
}
@@ -695,10 +705,10 @@ void LogicalStreamAllocator::RefreshContinuousStreams(const ComputeGraphPtr &gra

context_.next_stream = 0;
vector<int64_t> old_to_new_streams(stream_num, kInvalidStream);
for (size_t old_stream = 0; old_stream < stream_has_node.size(); ++old_stream) {
for (size_t old_stream = 0; old_stream < stream_has_node.size(); old_stream++) {
if (stream_has_node[old_stream]) {
old_to_new_streams[old_stream] = context_.next_stream;
++context_.next_stream;
context_.next_stream++;
}
}

@@ -706,7 +716,7 @@ void LogicalStreamAllocator::RefreshContinuousStreams(const ComputeGraphPtr &gra
auto op_desc = node->GetOpDesc();
if (op_desc != nullptr) {
int64_t stream_id = op_desc->GetStreamId();
if (stream_id != kInvalidStream && stream_id < stream_num) {
if ((stream_id != kInvalidStream) && (stream_id < stream_num)) {
op_desc->SetStreamId(old_to_new_streams[stream_id]);
}
}


+ 12
- 3
ge/graph/build/memory/binary_block_mem_assigner.cc View File

@@ -70,7 +70,10 @@ Status BinaryBlockMemAssigner::GetMemoryRanges(vector<int64_t> &range_ceils) {
return SUCCESS;
}
if ((all_memory_size.front() <= 0) || (log(kLogBase) == 0)) {
GELOGE(FAILED, "Memory size:%ld is invalid.", all_memory_size.front());
GELOGE(FAILED, "[Check][MemRangeStep]first mem_range_step:%ld less than 0,invalid,"
"maybe has dynamic shape in graph", all_memory_size.front());
REPORT_INNER_ERROR("E19999", "first mem_range_step:%ld less than 0,invalid,"
"maybe has dynamic shape in graph", all_memory_size.front());
return FAILED;
}
// Memory size is 512 aligned, so it is not necessary to take less than 512
@@ -81,12 +84,18 @@ Status BinaryBlockMemAssigner::GetMemoryRanges(vector<int64_t> &range_ceils) {
GELOGD("Range number: %zu", range_number);

vector<vector<int64_t>> ranges(range_number);
GE_CHK_BOOL_EXEC((range_number != 0), return PARAM_INVALID, "range_number can't be 0.");
GE_CHK_BOOL_EXEC((range_number != 0),
REPORT_INNER_ERROR("E19999", "inner data[range_number] is 0, judge invalid");
return PARAM_INVALID,
"[Check][RangeNumber]inner data is 0, judge invalid.");
size_t range_number_limit = all_memory_size.size() / range_number;
int64_t range_ceil = min_memory_size;
for (size_t i = 1; i <= range_number; i++) {
GE_IF_BOOL_EXEC(TypeUtils::CheckUint64MulOverflow(static_cast<uint64_t>(range_ceil), kRangeCeilInterval),
GELOGE(FAILED, "Multiply result is out of range.");
GELOGE(FAILED, "[Check][MemRangeCeil]Multiply result is out of range,"
"range_ceil:%ld, interval:%u", range_ceil, kRangeCeilInterval);
REPORT_INNER_ERROR("E19999", "process mem_range_ceil,multiply result out of range,"
"range_ceil:%ld, interval:%u", range_ceil, kRangeCeilInterval);
return FAILED);
range_ceil *= kRangeCeilInterval; // The block size of each interval is doubled every time.
for (auto iter = all_memory_size.begin(); iter != all_memory_size.end();) {


+ 111
- 32
ge/graph/build/memory/block_mem_assigner.cc View File

@@ -30,6 +30,7 @@
#include "graph/utils/node_utils.h"
#include "graph/utils/op_desc_utils.h"
#include "graph/utils/tensor_utils.h"
#include "graph/utils/type_utils.h"

#include "graph/debug/ge_attr_define.h"

@@ -457,7 +458,16 @@ Status GetNoAlignSize(const ge::OpDesc &desc, uint32_t index, size_t &size) {
DataType data_type = output_op_desc->GetDataType();
graphStatus graph_status = TensorUtils::CalcTensorMemSize(shape, format, data_type, tensor_size);
if (graph_status != GRAPH_SUCCESS) {
GELOGE(graph_status, "CalcTensorMemSize failed!");
GELOGE(graph_status, "[Calculate][TensorSize]shape:%s, format:%s, data_type:%s, op:%s, out_index:%u",
shape.ToString().c_str(),
TypeUtils::FormatToSerialString(format).c_str(),
TypeUtils::DataTypeToSerialString(data_type).c_str(),
desc.GetName().c_str(), index);
REPORT_CALL_ERROR("E19999", "CalcTensorMemSize fail, shape:%s, format:%s, data_type:%s, op:%s, out_index:%u",
shape.ToString().c_str(),
TypeUtils::FormatToSerialString(format).c_str(),
TypeUtils::DataTypeToSerialString(data_type).c_str(),
desc.GetName().c_str(), index);
return FAILED;
}
size = static_cast<size_t>(tensor_size);
@@ -586,9 +596,12 @@ void BlockMemAssigner::GetOutAndWorkSpaceMem(vector<int64_t> &all_memory_size) {
GeTensorDesc output_desc = node_op_desc->GetOutputDesc(out_anchor->GetIdx());
int64_t size = 0;
GE_IF_BOOL_EXEC(ge::TensorUtils::GetSize(output_desc, size) != SUCCESS, GELOGI("Get size failed"));
GE_IF_BOOL_EXEC(size < 0, GELOGE(FAILED, "Node:%s size:%ld is invalid, maybe it is unknown shape node.",
node_op_desc->GetName().c_str(), size);
return;);
GE_IF_BOOL_EXEC(size < 0,
GELOGE(FAILED, "[Check][TensorSize]tensor_size:%ld is invalid, maybe it is unknown shape node, Node_name:%s",
size, node_op_desc->GetName().c_str());
REPORT_INNER_ERROR("E19999", "tensor_size:%ld is invalid, maybe it is unknown shape node, Node_name:%s",
size, node_op_desc->GetName().c_str());
return;);
batch_all_memory_size[batch_label].emplace_back(size);
if (batch_total_size.find(batch_label) == batch_total_size.end()) {
batch_total_size[batch_label] = size;
@@ -678,22 +691,34 @@ bool BlockMemAssigner::IsOutNodeSetContinuousInput(const NodePtr &n, uint32_t ou
if (static_cast<size_t>(out_index) < n->GetAllOutDataAnchors().size()) {
auto out_anchor = n->GetOutDataAnchor(out_index);
GE_IF_BOOL_EXEC(out_anchor == nullptr,
GELOGE(FAILED, "Node[%s] output[%u] anchor is null.", n->GetName().c_str(), out_index);
GELOGE(FAILED, "[Check][Anchor]Node[%s] output[%u] anchor is null.",
n->GetName().c_str(), out_index);
REPORT_INNER_ERROR("E19999", "output anchor is null, node_name: %s output_index: %u.",
n->GetName().c_str(), out_index);
return false;);
for (auto const &peer_in_anchor : out_anchor->GetPeerInDataAnchors()) {
GE_IF_BOOL_EXEC(peer_in_anchor == nullptr,
GELOGE(FAILED, "Node[%s] output[%u] peer_in_anchor 0 is null.", n->GetName().c_str(), out_index);
GELOGE(FAILED, "[Check][Anchor]Node[%s] output[%u] peer_in_anchor 0 is null.",
n->GetName().c_str(), out_index);
REPORT_INNER_ERROR("E19999", "output anchor peer is null, node_name: %s output_index: %u.",
n->GetName().c_str(), out_index);
return false;);
auto peer_node = peer_in_anchor->GetOwnerNode();
GE_IF_BOOL_EXEC(peer_node == nullptr,
GELOGE(FAILED, "Node[%s] output[%u] node is null.", n->GetName().c_str(), out_index);
GELOGE(FAILED, "[Check][Node]Node[%s] output[%u] peer node is null.",
n->GetName().c_str(), out_index);
REPORT_INNER_ERROR("E19999", "output anchor peer node is null, node_name: %s output_index: %u.",
n->GetName().c_str(), out_index);
return false;);

// Get the continuous input type of the node, default is false
bool is_input_continuous = false;
auto peer_in_node_desc = peer_node->GetOpDesc();
GE_IF_BOOL_EXEC(peer_in_node_desc == nullptr,
GELOGE(FAILED, "Node[%s] output[%u] nodedesc is null.", n->GetName().c_str(), out_index);
GELOGE(FAILED, "[Check][OpDesc]Node[%s] output[%u] nodedesc is null.",
n->GetName().c_str(), out_index);
REPORT_INNER_ERROR("E19999", "output anchor peer op_desc is null, node_name:%s output_index:%u.",
n->GetName().c_str(), out_index);
return false;);

// If GetBool fail, is_input_continuous is false.
@@ -793,7 +818,10 @@ bool BlockMemAssigner::IsContinuousMemoryReuse(const NodePtr &n, const NodePtr &
if ((in_anchor == nullptr) || (in_anchor->GetPeerOutAnchor() == nullptr) ||
(in_anchor->GetPeerOutAnchor()->GetOwnerNode() == nullptr) ||
(in_anchor->GetPeerOutAnchor()->GetOwnerNode()->GetOpDesc() == nullptr)) {
GELOGE(FAILED, "Node[%s] output[%u] peer input node desc is null.", n->GetName().c_str(), out_index);
GELOGE(FAILED, "[Check][OpDesc]Node[%s] output[%u] peer input node desc is null.",
n->GetName().c_str(), out_index);
REPORT_INNER_ERROR("E19999", "get output anchor peer op_desc fail, node_name: %s output_index: %u.",
n->GetName().c_str(), out_index);
return false;
}
auto peer_out_node_desc = in_anchor->GetPeerOutAnchor()->GetOwnerNode()->GetOpDesc();
@@ -1077,7 +1105,9 @@ MemoryBlock *BlockMemAssigner::ApplyMemory(size_t block_size, size_t real_size,
OpMemoryType mem_type, const NodePtr &n, uint32_t out_index,
const vector<bool> &workspace_reuse_flag, const bool is_op_reuse_mem,
const bool continuous, int64_t memory_type) {
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(n == nullptr, return nullptr, "Input parameter n is null.");
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(n == nullptr,
REPORT_INNER_ERROR("E19999", "Input parameter n(type:node_ptr) is null, apply memory failed");
return nullptr, "[Check][Param]Input parameter n(type:node_ptr) is null.");
auto node_op_desc = n->GetOpDesc();
GE_IF_BOOL_EXEC(node_op_desc == nullptr, return nullptr);
std::string batch_label;
@@ -1129,7 +1159,10 @@ MemoryBlock *BlockMemAssigner::ApplyMemory(size_t block_size, size_t real_size,
}

auto block = new (std::nothrow) MemoryBlock(block_size, node_op_desc->GetStreamId(), is_reuse_memory, memory_type);
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(block == nullptr, return nullptr, "new an object failed.");
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(block == nullptr,
REPORT_INNER_ERROR("E19999", "new a memoryblock object failed. node_name:%s out_index:%u",
n->GetName().c_str(), out_index);
return nullptr, "[New][Object]new MemoryBlock failed, node_name:%s out_index:%u", n->GetName().c_str(), out_index);

// Data and netoutput need zero copy block
block->is_zero_copy_ = IsZeroCopyBlock(n, continuous);
@@ -1188,9 +1221,13 @@ void BlockMemAssigner::ContinuousOutRefCheck(bool &isAllOutputRef, bool &isOutpu

Status BlockMemAssigner::ApplyContinuousMemory(const NodePtr &n, const vector<int64_t> &ranges,
const bool is_op_reuse_mem) {
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(n == nullptr, return INTERNAL_ERROR, "input node is null.");
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(n == nullptr,
REPORT_INNER_ERROR("E19999", "Input parameter n(type:node_ptr) is null");
return INTERNAL_ERROR, "[check][param]Input parameter n(type:NodePtr) is null.");
auto node_op_desc = n->GetOpDesc();
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(node_op_desc == nullptr, return INTERNAL_ERROR, "node_op_desc is null.");
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(node_op_desc == nullptr,
REPORT_INNER_ERROR("E19999", "Input parameter n(type:OpDescPtr) is null");
return INTERNAL_ERROR, "[Check][Param]Input parameter n(type:OpDescPtr) is null");

// continuous output support ref only when all output ref input
bool isAllOutputRef = true;
@@ -1204,7 +1241,9 @@ Status BlockMemAssigner::ApplyContinuousMemory(const NodePtr &n, const vector<in
}

if (!isAllOutputRef && isOutputHasRef) {
GELOGE(INTERNAL_ERROR, "continuous output node ref part input, not support this situation, node_name:%s",
REPORT_INNER_ERROR("E19999", "continuous output node ref part input, not support now. node_name:%s",
n->GetName().c_str());
GELOGE(INTERNAL_ERROR, "[Check][OutRefStatus]continuous output node ref part input, not support, node_name:%s",
n->GetName().c_str());
return INTERNAL_ERROR;
}
@@ -1215,7 +1254,9 @@ Status BlockMemAssigner::ApplyContinuousMemory(const NodePtr &n, const vector<in
for (uint32_t index = 0; index < static_cast<uint32_t>(node_op_desc->GetOutputsSize()); index++) {
auto output_op_desc = node_op_desc->GetOutputDescPtr(index);
if (output_op_desc == nullptr) {
GELOGE(INTERNAL_ERROR, "Get output desc failed, node_name:%s, output_index:%u", n->GetName().c_str(), index);
REPORT_INNER_ERROR("E19999", "get output_desc failed, node_name:%s, output_index:%u",
n->GetName().c_str(), index);
GELOGE(INTERNAL_ERROR, "[Get][OutputDesc]node_name:%s, output_index:%u", n->GetName().c_str(), index);
return INTERNAL_ERROR;
}

@@ -1226,7 +1267,9 @@ Status BlockMemAssigner::ApplyContinuousMemory(const NodePtr &n, const vector<in

int64_t size = 0;
if (ge::TensorUtils::GetSize(*output_op_desc, size) != SUCCESS) {
GELOGE(INTERNAL_ERROR, "Get size failed, node_name:%s, output_index:%u", n->GetName().c_str(), index);
REPORT_CALL_ERROR("E19999", "get tensor_size failed, node_name:%s, output_index:%u",
n->GetName().c_str(), index);
GELOGE(INTERNAL_ERROR, "[Get][TensorSize]node_name:%s, output_index:%u", n->GetName().c_str(), index);
return INTERNAL_ERROR;
}
size_t align_size = static_cast<size_t>(size);
@@ -1266,7 +1309,9 @@ Status BlockMemAssigner::ApplyContinuousMemory(const NodePtr &n, const vector<in
block->last_continuous_block_ = true;
++(block->ref_count_);
} else {
GELOGE(INTERNAL_ERROR, "node apply continuous output memory failed. node_name:%s", n->GetName().c_str());
REPORT_CALL_ERROR("E19999", "apply continuousMemory failed, node_name:%s, total_size:%ld",
n->GetName().c_str(), total_size);
GELOGE(INTERNAL_ERROR, "[Apply][ContinuousMemory]node_name:%s, total_size:%ld", n->GetName().c_str(), total_size);
return INTERNAL_ERROR;
}
return SUCCESS;
@@ -1274,25 +1319,37 @@ Status BlockMemAssigner::ApplyContinuousMemory(const NodePtr &n, const vector<in

MemoryBlock *BlockMemAssigner::ApplyOutMemory(const NodePtr &n, uint32_t index, const vector<int64_t> &ranges,
const bool is_op_reuse_mem, const bool continuous) {
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(n == nullptr, return nullptr, "input node is null.");
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(n == nullptr,
REPORT_INNER_ERROR("E19999", "Input parameter n(type:NodePtr) is null");
return nullptr, "[Check][Param]Input parameter n(type:NodePtr) is null");
auto node_op_desc = n->GetOpDesc();
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(node_op_desc == nullptr, return nullptr, "node_op_desc is null.");
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(node_op_desc == nullptr,
REPORT_INNER_ERROR("E19999", "Input parameter n(type:OpDescPtr) is null");
return nullptr, "[Check][Param]Input parameter n(type:OpDescPtr) is null");
MemoryBlock *block = nullptr;
NodeIndexIO node_index_io(n, index, kOut);
int64_t size = 0;
auto output_op_desc = node_op_desc->GetOutputDescPtr(index);
GE_IF_BOOL_EXEC(output_op_desc == nullptr, return nullptr);
GE_IF_BOOL_EXEC(output_op_desc == nullptr,
REPORT_INNER_ERROR("E19999", "get output_desc failed, node_name:%s, output_index:%u", n->GetName().c_str(), index);
GELOGE(FAILED, "[Get][OutputDesc]node_name:%s, output_index:%u", n->GetName().c_str(), index);
return nullptr);
GE_IF_BOOL_EXEC(ge::TensorUtils::GetSize(*output_op_desc, size) != SUCCESS, GELOGI("Get size failed"));
size_t no_align_size = 0;
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(GetNoAlignSize(*node_op_desc, index, no_align_size) != SUCCESS,
return nullptr, "Get no align size failed");
REPORT_CALL_ERROR("E19999", "Get no align size failed, node_name:%s, output_index:%u", n->GetName().c_str(), index);
return nullptr, "[Get][TensorSize]Get no align size, node_name:%s, output_index:%u", n->GetName().c_str(), index);

std::string symbol;
bool reuse_input = false;
if (IsSymbolExist(node_index_io, symbol)) {
block = symbol_blocks_[symbol];
GE_IF_BOOL_EXEC(block == nullptr, GELOGE(FAILED, "Node %s ref block is nullptr.", node_op_desc->GetName().c_str());
return nullptr);
GE_IF_BOOL_EXEC(block == nullptr,
REPORT_INNER_ERROR("E19999", "get ref block failed, node_name:%s, symbol:%s",
node_op_desc->GetName().c_str(), node_index_io.ToString().c_str());
GELOGE(FAILED, "[Get][RefBlock]node_name:%s, symbol:%s",
node_op_desc->GetName().c_str(), node_index_io.ToString().c_str());
return nullptr);
// reduce old size
size_t align_size = block->Size();
AlignMemOffset(align_size);
@@ -1335,12 +1392,24 @@ MemoryBlock *BlockMemAssigner::ApplyOutMemory(const NodePtr &n, uint32_t index,
vector<bool> workspace_reuse_flag;
block = ApplyMemory(block_size, size, no_align_size, kOutput, n, index,
workspace_reuse_flag, is_op_reuse_mem, continuous, memory_type);
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(block == nullptr,
REPORT_CALL_ERROR("E19999", "apply out Memory failed, node_name:%s, block_size:%ld, out_index:%u",
n->GetName().c_str(), block_size, index);
return nullptr, "[Apply][Memory]node_name:%s, block_size:%ld, out_index:%u",
n->GetName().c_str(), block_size, index);
}
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(block == nullptr, return nullptr, "Block is nullptr.");
int out_count = 0;
GE_IF_BOOL_EXEC(index >= n->GetAllOutDataAnchors().size(), GELOGE(FAILED, "index is out of range."); return nullptr);
GE_IF_BOOL_EXEC(index >= n->GetAllOutDataAnchors().size(),
REPORT_INNER_ERROR("E19999", "out index:%u exceed out_size:%lu, node_name:%s",
index, n->GetAllOutDataAnchors().size(), n->GetName().c_str());
GELOGE(FAILED, "[Check][OutIndex]index:%u exceed out_size:%lu, node_name:%s",
index, n->GetAllOutDataAnchors().size(), n->GetName().c_str());
return nullptr);
auto out_data_anchor = n->GetOutDataAnchor(index);
GE_IF_BOOL_EXEC(out_data_anchor == nullptr, GELOGE(FAILED, "Out data anchor is nullptr."); return nullptr);
GE_IF_BOOL_EXEC(out_data_anchor == nullptr,
REPORT_INNER_ERROR("E19999", "out anchor is null, index:%u, node_name:%s", index, n->GetName().c_str());
GELOGE(FAILED, "[Check][OutAnchor]is null, index:%u, node_name:%s", index, n->GetName().c_str());
return nullptr);
for (const auto &in_anchor : out_data_anchor->GetPeerInDataAnchors()) {
auto owner_node = in_anchor->GetOwnerNode();
auto op_desc = owner_node->GetOpDesc();
@@ -1546,8 +1615,13 @@ Status BlockMemAssigner::AssignOutputMemoryWithReuse(const NodePtr &node, vector
GELOGD("Assign memory node[%s], output size[%zu], output memory type size[%zu]", op_desc->GetName().c_str(),
op_desc->GetOutputsSize(), memorys_type.size());
if (has_mem_type_attr && (memorys_type.size() != op_desc->GetOutputsSize())) {
GELOGE(INTERNAL_ERROR, "fusion: node[%s], output memory size err[outputsize:%zu, memorysize:%zu]",
op_desc->GetName().c_str(), op_desc->GetOutputsSize(), memorys_type.size());
REPORT_INNER_ERROR("E19999", "Attr[%s] size:%zu not equal to node output size:%zu, node_name:%s",
ATTR_NAME_OUTPUT_MEM_TYPE_LIST.c_str(), memorys_type.size(),
op_desc->GetOutputsSize(), op_desc->GetName().c_str());
GELOGE(INTERNAL_ERROR,
"[Check][MemTypeAttr]Attr %s size:%zu not equal to node output size:%zu, node_name:%s",
ATTR_NAME_OUTPUT_MEM_TYPE_LIST.c_str(), memorys_type.size(),
op_desc->GetOutputsSize(), op_desc->GetName().c_str());
return INTERNAL_ERROR;
}

@@ -1673,8 +1747,10 @@ void BlockMemAssigner::AssignMemoryWithReuse(vector<int64_t> &ranges) {
temp.size(), tvm_workspace_memory_type.size());

if (has_tvm_workspace_mem_type_attr && (temp.size() != tvm_workspace_memory_type.size())) {
GELOGE(INTERNAL_ERROR, "fusion: node[%s], tvm workspace memory size error![v_temp:%zu, workspace:%zu]",
n->GetName().c_str(), temp.size(), tvm_workspace_memory_type.size());
REPORT_INNER_ERROR("E19999", "Attr[%s]size:%zu is not equal to workspace size:%zu, node_name:%s",
TVM_ATTR_NAME_WORKSPACE_TYPE.c_str(), tvm_workspace_memory_type.size(), temp.size(), n->GetName().c_str());
GELOGE(INTERNAL_ERROR, "[Check][Attr]Attr %s size:%zu is not equal to workspace size:%zu, node_name:%s",
TVM_ATTR_NAME_WORKSPACE_TYPE.c_str(), tvm_workspace_memory_type.size(), temp.size(), n->GetName().c_str());
return;
}
for (size_t i = 0; i < temp.size(); i++) {
@@ -2083,8 +2159,11 @@ bool BlockMemAssigner::GetWorkSpaceMemoryType(const NodePtr &node, size_t index,
bool has_workspace_mem_type_attr =
ge::AttrUtils::GetListInt(op_desc, TVM_ATTR_NAME_WORKSPACE_TYPE, workspace_memory_type);
if (has_workspace_mem_type_attr && (workspace_memory_type.size() <= index)) {
GELOGE(INTERNAL_ERROR, "node[%s], workspace_memory size error![index:%zu, workspace:%zu]",
node->GetName().c_str(), index, workspace_memory_type.size());
REPORT_INNER_ERROR("E19999", "get workspace mem_type failed, "
"index %zu invalid, bigger than attr %s size:%zu, node_name:%s",
index, TVM_ATTR_NAME_WORKSPACE_TYPE.c_str(), workspace_memory_type.size(), node->GetName().c_str());
GELOGE(INTERNAL_ERROR, "[Get][WorkspaceMemType]index %zu invalid, bigger than attr %s size:%zu, node_name:%s",
index, TVM_ATTR_NAME_WORKSPACE_TYPE.c_str(), workspace_memory_type.size(), node->GetName().c_str());
return false;
}
memory_type = has_workspace_mem_type_attr ? workspace_memory_type[index] : RT_MEMORY_HBM;


+ 230
- 108
ge/graph/build/memory/graph_mem_assigner.cc View File

@@ -99,7 +99,8 @@ Status VariableMemoryAssigner::AssignMemory2HasRefAttrNode() {
Status GraphMemoryAssigner::AssignMemory() {
ge::HybridMemAssignerPtr mem_assigner(new(std::nothrow) HybridMemAssigner(compute_graph_));
if (mem_assigner->Assign() != ge::SUCCESS) {
GELOGE(ge::FAILED, "Memory assigner failed");
GELOGE(ge::FAILED, "[Assign][GraphMem]graph_id:%u, graph_name:%s",
compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return ge::FAILED;
}
MemoryOffset memory_offset(RT_MEMORY_HBM, mem_assigner->GetMemOffset());
@@ -115,7 +116,10 @@ Status GraphMemoryAssigner::AssignMemory() {
auto variable_assigner =
std::unique_ptr<ge::VariableMemoryAssigner>(new(std::nothrow) ge::VariableMemoryAssigner(compute_graph_));
if (variable_assigner == nullptr) {
GELOGE(ge::FAILED, "Alloc VariableMemoryAssigner failed.");
GELOGE(ge::FAILED, "[New][Object:VariableMemoryAssigner]graph_id:%u, graph_name:%s",
compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
REPORT_INNER_ERROR("E19999", "New Object:VariableMemoryAssigner failed when assign graph memory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return ge::FAILED;
}

@@ -134,7 +138,10 @@ ge::Status GraphMemoryAssigner::AssignVarAttr2Nodes() {
auto variable_assigner =
std::unique_ptr<ge::VariableMemoryAssigner>(new(std::nothrow) ge::VariableMemoryAssigner(compute_graph_));
if (variable_assigner == nullptr) {
GELOGE(ge::FAILED, "Alloc VariableMemoryAssigner failed.");
GELOGE(ge::FAILED, "[New][Object:VariableMemoryAssigner]graph_id:%u, graph_name:%s",
compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
REPORT_INNER_ERROR("E19999", "New Object:VariableMemoryAssigner failed when assign graph memory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return ge::FAILED;
}
if (variable_assigner->AssignVarAttr2Nodes() != ge::SUCCESS) {
@@ -147,8 +154,10 @@ ge::Status GraphMemoryAssigner::AssignMemory2HasRefAttrNode() {
auto variable_assigner =
std::unique_ptr<ge::VariableMemoryAssigner>(new(std::nothrow) ge::VariableMemoryAssigner(compute_graph_));
if (variable_assigner == nullptr) {
GELOGE(ge::FAILED, "Alloc VariableMemoryAssigner failed.");
return ge::FAILED;
GELOGE(ge::FAILED, "[New][Object:VariableMemoryAssigner]graph_id:%u, graph_name:%s",
compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
REPORT_INNER_ERROR("E19999", "New Object:VariableMemoryAssigner failed when assign graph memory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
}
if (variable_assigner->AssignMemory2HasRefAttrNode() != ge::SUCCESS) {
return ge::FAILED;
@@ -161,17 +170,18 @@ ge::Status CalculateTensorRealSizeAndOutSize(const ge::ConstGeTensorDescPtr &out
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!");
GELOGE(FAILED, "[Get][TensorSize]");
REPORT_INNER_ERROR("E19999", "New Object:VariableMemoryAssigner failed when assign graph memory");
return FAILED;
}

GeShape output_shape = output_desc->GetShape();
std::vector<int64_t> output_dims = output_shape.GetDims();
if (dim_index >= static_cast<int64_t>(output_dims.size())) {
std::string error = "Invaild value" + FmtToStr(dim_index) +
" of attr _reuse_input_on_dim_index, which is out of data range [0,"
+ std::to_string(output_dims.size()) + ")";
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "Inner param dim_index value:%ld invalid, bigger than dim size:%lu in shape:%s",
dim_index, output_dims.size(), output_shape.ToString().c_str());
GELOGE(FAILED, "[Check][Param:dim_index]value:%ld invalid, bigger than dim size:%lu in shape:%s",
dim_index, output_dims.size(), output_shape.ToString().c_str());
return FAILED;
}

@@ -187,14 +197,23 @@ ge::Status CalculateTensorRealSizeAndOutSize(const ge::ConstGeTensorDescPtr &out

graph_status = ge::TensorUtils::CalcTensorMemSize(output_shape, out_format, data_type, output_mem_size);
if (graph_status != GRAPH_SUCCESS) {
GELOGE(graph_status, "Opdesc CalcTensorMemSize failed!");
GELOGE(graph_status, "[Calc][TensorSize]");
return FAILED;
}

if (output_mem_size < 0) {
std::string error = "After calculating tensor memory size, output_mem_size" + FmtToStr(output_mem_size) +
" is out of data range [0," + std::to_string(INT64_MAX) + "]";
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "After calculating, tensor memory size:%ld invalid, less than 0. "
"shape:%s, format:%s, dtype:%s, maybe has dynamic shape",
output_mem_size,
output_shape.ToString().c_str(),
TypeUtils::FormatToSerialString(out_format).c_str(),
TypeUtils::DataTypeToSerialString(data_type).c_str());
GELOGE(FAILED, "[Check][TensorSize]value:%ld invalid after calc, less than 0. shape:%s, format:%s, dtype:%s, "
"maybe has dynamic shape",
output_mem_size,
output_shape.ToString().c_str(),
TypeUtils::FormatToSerialString(out_format).c_str(),
TypeUtils::DataTypeToSerialString(data_type).c_str());
return FAILED;
}

@@ -203,7 +222,10 @@ ge::Status CalculateTensorRealSizeAndOutSize(const ge::ConstGeTensorDescPtr &out

Status GraphMemoryAssigner::ReAssignMemory(bool is_loop_graph, map<int64_t, size_t> &mem_type_to_offset) {
if (memory_offset_.empty()) {
GELOGE(FAILED, "memory_offset_ is empty.");
REPORT_INNER_ERROR("E19999", "InnerData memory_offset_ empty, not expected when ReAssignMemory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
GELOGE(FAILED, "[Check][InnerData:memory_offset_]empty is not expected, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return ge::FAILED;
}

@@ -218,8 +240,10 @@ Status GraphMemoryAssigner::ReAssignMemory(bool is_loop_graph, map<int64_t, size

auto session_id = compute_graph_->GetSessionID();
if (total_mem_offset > VarManager::Instance(session_id)->GetGraphMemoryMaxSize()) {
GELOGE(ge::FAILED, "Current memoffset %zu is greater than memory manager malloc max size %zu", total_mem_offset,
VarManager::Instance(session_id)->GetGraphMemoryMaxSize());
GELOGE(ge::FAILED, "[Check][TotalMemOffset] %zu is greater than memory manager malloc max size %zu, "
"graph_id:%u, graph_name:%s, reduce your batchsize or scale your model may solve problem",
total_mem_offset, VarManager::Instance(session_id)->GetGraphMemoryMaxSize(),
compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
for (auto iter : mem_type_to_offset) {
ErrorManager::GetInstance().ATCReportErrMessage("E19022", {"memType", "size", "item", "maxsize"},
{std::to_string(iter.first), std::to_string(iter.second), "featuremap",
@@ -234,7 +258,13 @@ Status GraphMemoryAssigner::ReAssignMemory(bool is_loop_graph, map<int64_t, size

Status GraphMemoryAssigner::AssignZeroCopyMemory(map<int64_t, size_t> &mem_offset, size_t &zero_mem_copy_size) {
BlockMemAssignerPtr priority_assigner = std::move(mem_assigner_->GetPriorityAssinger());
GE_IF_BOOL_EXEC(priority_assigner == nullptr, GELOGE(FAILED, "Get priority_assigner failed."); return ge::FAILED;);
if (priority_assigner == nullptr) {
REPORT_INNER_ERROR("E19999", "InnerData priority_assigner nullptr, not expected when AssignZeroCopyMemory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
GELOGE(FAILED, "[Check][InnerData:priority_assigner]nullptr is invalid, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return ge::FAILED;
}

size_t mem_offset_tmp = mem_offset[RT_MEMORY_HBM];

@@ -254,8 +284,11 @@ Status GraphMemoryAssigner::AssignZeroCopyMemory(map<int64_t, size_t> &mem_offse
zero_mem_copy_size = mem_offset[RT_MEMORY_HBM] - mem_offset_tmp;
auto iter = memory_offset_.find(RT_MEMORY_HBM);
if (iter == memory_offset_.end()) {
std::string error = "Memory offset does not have memory type[HBM]";
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "InnerData memory_offset_ does not have type[HBM], "
"not expected when AssignZeroCopyMemory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
GELOGE(FAILED, "[Check][InnerData]memory_offset_ does not have memory type[HBM]"
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return FAILED;
}
iter->second.mem_offset_ = mem_offset[RT_MEMORY_HBM];
@@ -304,7 +337,7 @@ uint32_t GetContinuousMemoryType(const OpDescPtr &op_desc) {
}

if (continuous_type != 0) {
GELOGI("Current node %s continuous type %d.", op_desc->GetName().c_str(), continuous_type);
GELOGI("Current node %s continuous type %d", op_desc->GetName().c_str(), continuous_type);
}
return continuous_type;
}
@@ -312,8 +345,9 @@ uint32_t GetContinuousMemoryType(const OpDescPtr &op_desc) {
Status GetMemorySize(const OpDescPtr &op_desc, const ge::ConstGeTensorDescPtr &output_desc, uint32_t continuous_type,
int64_t &tensor_size, int64_t &nopadding_size) {
if ((op_desc == nullptr) || (output_desc == nullptr)) {
GELOGE(FAILED, "Input para is nullptr.");
return FAILED;
REPORT_INNER_ERROR("E19999", "InnerData param op_desc or output_desc is nullptr, "
"not expected when GetMemorySize");
GELOGE(FAILED, "[Check][Param]op_desc or output_desc is nullptr");
}
tensor_size = 0;
nopadding_size = 0;
@@ -322,7 +356,10 @@ Status GetMemorySize(const OpDescPtr &op_desc, const ge::ConstGeTensorDescPtr &o
int64_t attr_dim_index;
bool get_attr_dim_flag = ge::AttrUtils::GetInt(op_desc, ATTR_NAME_REUSE_INPUT_ON_DIM_INDEX, attr_dim_index);
if (!get_attr_dim_flag) {
GELOGE(FAILED, "Get attr _reuse_input_on_dim_index failed.");
REPORT_INNER_ERROR("E19999", "Get Attr:%s failed when GetMemorySize, op_name:%s",
ATTR_NAME_REUSE_INPUT_ON_DIM_INDEX.c_str(), op_desc->GetName().c_str());
GELOGE(FAILED, "[Get][Attr:%s]fail for op_name:%s",
ATTR_NAME_REUSE_INPUT_ON_DIM_INDEX.c_str(), op_desc->GetName().c_str());
return FAILED;
}

@@ -330,17 +367,25 @@ Status GetMemorySize(const OpDescPtr &op_desc, const ge::ConstGeTensorDescPtr &o
int64_t batch_dim_num = 1;
if (CalculateTensorRealSizeAndOutSize(output_desc, attr_dim_index, nopadding_size, batch_dim_num, tensor_size) !=
SUCCESS) {
GELOGE(FAILED, "CalculateTensorRealSizeAndOutSize failed for node %s.", op_desc->GetName().c_str());
REPORT_CALL_ERROR("E19999", "CalculateTensorRealSizeAndOutSize failed, attr_dim_index:%ld, op_name:%s",
attr_dim_index, op_desc->GetName().c_str());
GELOGE(FAILED, "[Calculate][NopaddingSize]failed for node %s, attr_dim_index:%ld",
op_desc->GetName().c_str(), attr_dim_index);
return FAILED;
}
} else {
if (ge::TensorUtils::GetSize(*output_desc, tensor_size) != ge::SUCCESS) {
GELOGE(FAILED, "GetSize failed.");
REPORT_INNER_ERROR("E19999", "Get Tensor Size failed, op_name:%s", op_desc->GetName().c_str());
GELOGE(FAILED, "[Get][TensorSize]failed in padding case, op_name:%s", op_desc->GetName().c_str());
return FAILED;
}
}
if ((tensor_size < 0) || (nopadding_size < 0)) {
GELOGE(FAILED, "GetMemorySize for node %s failed.", op_desc->GetName().c_str());
REPORT_INNER_ERROR("E19999", "GetMemorySize fail, "
"tensor_size:%ld or nopadding_size:%ld less than 0, invalid, op_name:%s",
tensor_size, nopadding_size, op_desc->GetName().c_str());
GELOGE(FAILED, "[Get][MemorySize]tensor_size:%ld or nopadding_size:%ld less than 0, invalid, op_name:%s",
tensor_size, nopadding_size, op_desc->GetName().c_str());
return FAILED;
}
return SUCCESS;
@@ -374,7 +419,7 @@ bool IsContinuousInputConflict(const ge::NodePtr &node, const OpDescPtr &peer_op
// If GetBool fail, is_peer_reference is false.
(void) AttrUtils::GetBool(peer_op_desc, ATTR_NAME_REFERENCE, is_peer_reference);
GE_IF_BOOL_EXEC(is_peer_reference,
std::string warning = "Current op" + FmtToStr(node->GetOpDesc()->GetName()) +
std::string warning = "[Check][Continuous]Current op" + FmtToStr(node->GetOpDesc()->GetName()) +
" requires continuous input, while the previous op" + FmtToStr(peer_op_desc->GetName()) +
" is ref. There may be conflict between the two.";
GELOGW("%s", warning.c_str());
@@ -404,7 +449,7 @@ Status GraphMemoryAssigner::ReAssignContinuousMemory(bool is_loop_graph) {
if (continuous_input) {
if (AssignContinuousInputMemoryWithAtomicProcessDirectly(node, node_2_continuous_type)) {
GE_CHK_STATUS_RET(AssignContinuousInputMemoryWithAtomicProcess(node, continuous_type),
"Assign node %s continuous input memory failed.", node->GetName().c_str())
"[Assign][Memory:Continuous:Input]fail for node:%s", node->GetName().c_str())
} else {
nodes_stack.push_back(node);
}
@@ -413,10 +458,11 @@ Status GraphMemoryAssigner::ReAssignContinuousMemory(bool is_loop_graph) {
int64_t memory_type = RT_MEMORY_HBM;
bool continuous_output = ((continuous_type & kTypeOutput) != 0) || ((continuous_type & kTypeOutputNoPadding) != 0);
if (continuous_output) {
GE_CHK_STATUS_RET(GetNodeMemoryType(node, memory_type, "output"), "Get node memory type failed.");
GE_CHK_STATUS_RET(GetNodeMemoryType(node, memory_type, "output"),
"[Get][MemType]fail for node:%s", node->GetName().c_str());
ret = AssignContinuousOutputMemory(node, memory_type, continuous_type);
if (ret != ge::SUCCESS) {
GELOGE(ret, "Assign continuous output memory failed!");
GELOGE(ret, "[Assign][Memory:Continuous:Ouput]fail for node:%s", node->GetName().c_str());
return ret;
}
}
@@ -427,14 +473,16 @@ Status GraphMemoryAssigner::ReAssignContinuousMemory(bool is_loop_graph) {
nodes_stack.pop_back();
auto iter = node_2_continuous_type.find(node);
if (iter == node_2_continuous_type.end()) {
GELOGE(FAILED, "node %s has no continuous type!", node->GetName().c_str());
REPORT_INNER_ERROR("E19999", "Inner data error when process continuous memory alloc for node:%s, "
"but has no continuous type", node->GetName().c_str());
GELOGE(FAILED, "[Get][ContinuousType] find fail for node:%s", node->GetName().c_str());
return FAILED;
}
GE_CHK_STATUS_RET(AssignContinuousInputMemoryWithAtomicProcess(node, iter->second, true),
"Assign node %s continuous input memory failed.", node->GetName().c_str())
"[Assign][Memory:Continuous:Input]fail for node:%s.", 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;
@@ -442,11 +490,13 @@ Status GraphMemoryAssigner::ReAssignContinuousMemory(bool is_loop_graph) {

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, bool reverse_refresh) {
GELOGI("Current node %s needs continuous input.", node->GetName().c_str());
GELOGI("Current node %s needs continuous input", node->GetName().c_str());
auto iter = memory_offset_.find(memory_type);
if (iter == memory_offset_.end()) {
std::string error = "Memory offset does not have memory type" + FmtToStr(memory_type);
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "find memory offset fail for mem_type:%ld, "
"when assign continuous input memory for node:%s, ", memory_type, node->GetName().c_str());
GELOGE(FAILED, "[Find][MemOffset]fail for mem_type:%ld, when AssignContinuousInputMemory for node:%s",
memory_type, node->GetName().c_str());
return FAILED;
}
// The head and tail of hcom continuous input should be added 512
@@ -459,8 +509,9 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node,
GE_CHECK_NOTNULL(op_desc);
vector<int64_t> output_list_this = op_desc->GetOutputOffset();
if (output_list_this.empty()) {
std::string error = "node:" + FmtToStr(op_desc->GetName()) + "has no output offset";
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "No output offset in node :%s, not expected when assign continuous input memory",
node->GetName().c_str());
GELOGE(FAILED, "[Get][OutputOffset] empty is invalid, node:%s", node->GetName().c_str());
return FAILED;
}
(void) ge::AttrUtils::GetBool(op_desc, ATTR_NAME_CONTINUOUS_INPUT_ALLOC, is_continuous_input_allocated);
@@ -480,8 +531,9 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node,
lx_fusion = lx_fusion && !offsets_of_fusion.empty();
if (lx_fusion) {
if (peer_out_data_anchor->GetIdx() >= static_cast<int>(offsets_of_fusion.size())) {
std::string error = "fusion: peer node" + FmtToStr(peer_op_desc->GetName()) +
" index" + FmtToStr(peer_out_data_anchor->GetIdx()) + " is out of range.";
std::string error = "fusion: peer node:" + FmtToStr(peer_op_desc->GetName()) +
" anchor_index:" + FmtToStr(peer_out_data_anchor->GetIdx()) +
" is out of range:" + FmtToStr(offsets_of_fusion.size());
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
return FAILED;
}
@@ -497,7 +549,9 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node,
bool is_nopadding = ((continuous_type & kTypeInputNoPadding) != 0) || lx_fusion;
vector<int64_t> output_list = peer_op_desc->GetOutputOffset();
if (peer_out_data_anchor->GetIdx() >= static_cast<int>(output_list.size())) {
std::string error = "index" + FmtToStr(peer_out_data_anchor->GetIdx()) + " is out of range.";
std::string error = "peer node:" + FmtToStr(peer_op_desc->GetName()) +
" anchor_index:" + FmtToStr(peer_out_data_anchor->GetIdx()) +
" is out of range:" + FmtToStr(output_list.size());
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
return FAILED;
}
@@ -506,7 +560,7 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node,
bool is_allocated_first_input = is_continuous_input_allocated && (in_data_anchor->GetIdx() == 0);
if (is_allocated_first_input) {
std::map<int32_t, int32_t> out2ins;
GE_CHK_STATUS_RET(GetAllRef(node, out2ins), "Node: %s get all ref failed", node->GetName().c_str());
GE_CHK_STATUS_RET(GetAllRef(node, out2ins), "[Get][AllRef]fail for node: %s", 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) && (reverse_refresh)) {
auto peer_output_offset = output_list.at(peer_out_data_anchor->GetIdx());
@@ -516,7 +570,7 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node,
out2ins.begin()->first, out2ins.begin()->second, peer_op_desc->GetName().c_str(),
output_list_this.at(out2ins.begin()->first), peer_output_offset);
} else {
GELOGD("Node %s out %d ref in %d input node %s with total ref numbers %zu", node->GetName().c_str(),
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
@@ -542,7 +596,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);
@@ -563,17 +617,32 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node,
Status GetFirstInputPeerOutOutputOffset(const ge::NodePtr &node, int64_t &mem_offset) {
auto in_data_anchor_list = node->GetAllInDataAnchors();
if (in_data_anchor_list.empty()) {
GELOGE(FAILED, "Node %s's in data anchor is empty.", node->GetName().c_str());
REPORT_INNER_ERROR("E19999", "InAnchor list empty in node:%s, not expect when GetFirstInputPeerOutOutputOffset",
node->GetName().c_str());
GELOGE(FAILED, "[Get][InAnchor]empty is invalid, node:%s", node->GetName().c_str());
return FAILED;
}
auto peer_out_data_anchor = in_data_anchor_list.at(0)->GetPeerOutAnchor();
GE_IF_BOOL_EXEC(peer_out_data_anchor == nullptr, GELOGE(ge::FAILED, "peer_out_data_anchor is null.");
GE_IF_BOOL_EXEC(peer_out_data_anchor == nullptr,
REPORT_INNER_ERROR("E19999", "PeerAcnhor is null, "
"not expect when GetFirstInputPeerOutOutputOffset for node:%s",
node->GetName().c_str());
GELOGE(ge::FAILED, "[Check][PeerAnchor]null is invalid, node:%s", node->GetName().c_str());
return ge::FAILED);
auto peer_op_desc = peer_out_data_anchor->GetOwnerNode()->GetOpDesc();
GE_IF_BOOL_EXEC(peer_op_desc == nullptr, GELOGE(ge::FAILED, "peer_op_desc is null."); return ge::FAILED);
GE_IF_BOOL_EXEC(peer_op_desc == nullptr,
REPORT_INNER_ERROR("E19999", "PeerOpDesc is null, "
"not expect when GetFirstInputPeerOutOutputOffset for node:%s",
node->GetName().c_str());
GELOGE(ge::FAILED, "[Check][PeerOpDesc]null is invalid, node:%s", node->GetName().c_str());
return ge::FAILED);
vector<int64_t> in_node_output_offsets = peer_op_desc->GetOutputOffset();
if (peer_out_data_anchor->GetIdx() >= static_cast<int>(in_node_output_offsets.size())) {
GELOGE(FAILED, "Index : %d is out of range.", peer_out_data_anchor->GetIdx());
REPORT_INNER_ERROR("E19999", "PeerAnchorIndex:%d bigger than in_offset size:%lu, "
"judge invalid when GetFirstInputPeerOutOutputOffset for node:%s",
peer_out_data_anchor->GetIdx(), in_node_output_offsets.size(), node->GetName().c_str());
GELOGE(FAILED, "[Check][Index:PeerOutDataAnchor]PeerIndex:%d bigger than in_offset size:%lu, node:%s",
peer_out_data_anchor->GetIdx(), in_node_output_offsets.size(), node->GetName().c_str());
return FAILED;
}
mem_offset = in_node_output_offsets.at(peer_out_data_anchor->GetIdx());
@@ -584,11 +653,18 @@ Status GraphMemoryAssigner::AssignContinuousOutputMemory(const ge::NodePtr &node
uint32_t continuous_type) {
GELOGI("Current node %s needs continuous output.", node->GetName().c_str());
auto out_op_desc = node->GetOpDesc();
GE_IF_BOOL_EXEC(out_op_desc == nullptr, GELOGE(ge::FAILED, "out_op_desc is null."); return ge::FAILED);
GE_IF_BOOL_EXEC(out_op_desc == nullptr,
REPORT_INNER_ERROR("E19999", "OpDesc is null, "
"not expect when AssignContinuousOutputMemory for node:%s",
node->GetName().c_str());
GELOGE(ge::FAILED, "[Check][OpDesc]null is invalid, node:%s", node->GetName().c_str()));
vector<int64_t> output_list = out_op_desc->GetOutputOffset();
if ((out_op_desc->GetOutputsSize() > output_list.size()) || (output_list.size() == 0)) {
GELOGE(ge::FAILED, "The size %zu of node output desc is more than output_list's size %zu.",
out_op_desc->GetOutputsSize(), output_list.size());
REPORT_INNER_ERROR("E19999", "Output size:%zu more than output offset size:%zu, invalid in node:%s, "
"when AssignContinuousOutputMemory",
out_op_desc->GetOutputsSize(), output_list.size(), node->GetName().c_str());
GELOGE(ge::FAILED, "[Check][InnerData]Output size:%zu more than output offset size:%zu, invalid in node:%s",
out_op_desc->GetOutputsSize(), output_list.size(), node->GetName().c_str());
return ge::FAILED;
}

@@ -647,14 +723,18 @@ Status GraphMemoryAssigner::ReAssignAtomicMemory(bool is_loop_graph) {
map<string, vector<NodePtr>> connecting_output_atomic_nodes;
Status status = FilterAtomicNodesForMemoryAssign(normal_atomic_and_clean_nodes_map, connecting_output_atomic_nodes);
if (status != SUCCESS) {
GELOGE(status, "Failed to filter atomic nodes for memory assignment.");
GELOGE(status, "[Filter][AtomicNode]failed in graph_id:%u, graph_name:%s",
compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return status;
}

auto mem_iter = memory_offset_.find(RT_MEMORY_HBM);
if (mem_iter == memory_offset_.end()) {
std::string error = "Memory offset does not have memory type" + FmtToStr(RT_MEMORY_HBM);
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "InnerData memory_offset_ does not have type[HBM], "
"not expected when ReAssignAtomicMemory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
GELOGE(FAILED, "[Check][InnerData]memory_offset_ does not have memory type[HBM]"
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return FAILED;
}

@@ -670,7 +750,7 @@ Status GraphMemoryAssigner::ReAssignAtomicMemory(bool is_loop_graph) {
vector<int64_t> mem_offset_end;
status = AssignAtomicOutputAndWorkspaceMemory(atomic_node, mem_offset_end);
if (status != SUCCESS) {
GELOGE(status, "Assign atomic output and workspace memory failed, node name is %s.",
GELOGE(status, "[Assign][Memory]output atomic mem and workspace mem, fail for node name is %s.",
atomic_node->GetName().c_str());
return status;
}
@@ -679,7 +759,7 @@ Status GraphMemoryAssigner::ReAssignAtomicMemory(bool is_loop_graph) {
int64_t atomic_mem_size = static_cast<int64_t>(mem_iter->second.mem_offset_) - atomic_mem_start;
if (atomic_mem_size != 0) {
GE_CHK_STATUS_RET(SetAtomicCleanAttr(iter.first, {atomic_mem_start}, {atomic_mem_size}, RT_MEMORY_HBM),
"Failed to set attr for atomic addr clean node %s.", iter.first->GetName().c_str());
"[Set][Attr]fail for atomic addr clean node %s.", iter.first->GetName().c_str());
}
}
batch_max_mem_offset = std::max(batch_max_mem_offset, static_cast<int64_t>(mem_iter->second.mem_offset_));
@@ -690,7 +770,8 @@ Status GraphMemoryAssigner::ReAssignAtomicMemory(bool is_loop_graph) {
for (auto &iter_batch : connecting_output_atomic_nodes) {
mem_iter->second.mem_offset_ = batch_atomic_mem_start;
if (AssignConnectNetOutputAtomicMemory(iter_batch.second) != SUCCESS) {
GELOGE(FAILED, "Failed to assign memory of nodes that connect to netoutput.");
GELOGE(FAILED, "[Assign][Memory]for nodes that connect to netoutput failed."
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return FAILED;
}
batch_max_mem_offset = std::max(batch_max_mem_offset, static_cast<int64_t>(mem_iter->second.mem_offset_));
@@ -721,9 +802,10 @@ Status GraphMemoryAssigner::FilterAtomicNodesForMemoryAssign(
// If GetBool fail, is_reference is false.
(void) ge::AttrUtils::GetBool(peer_in_node_desc, ATTR_NAME_REFERENCE, is_reference);
if (is_reference) {
std::string error = "Op" + FmtToStr(peer_in_node_desc->GetName()) +
" cannot have both atomic and is_reference attribute.";
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "Op:%s cannot have both atomic and is_reference attribute, "
"not support now", peer_in_node_desc->GetName().c_str());
GELOGE(FAILED, "[Check][Attr]Op:%s cannot have both atomic and is_reference attribute, "
"not support now", peer_in_node_desc->GetName().c_str());
return ge::PARAM_INVALID;
}

@@ -761,7 +843,7 @@ Status GraphMemoryAssigner::AssignAtomicOutputAndWorkspaceMemory(const ge::NodeP
// Assign atomic node output memory
Status ret = AssignAtomicOutputMemory(node, mem_offset_end);
if (ret != SUCCESS) {
GELOGE(ret, "Failed to assign atomic output memory, node is %s.", node_op_desc->GetName().c_str());
GELOGE(ret, "[Assign][Memory:Ouput:Atomic]Failed for node:%s.", node_op_desc->GetName().c_str());
return ret;
}

@@ -781,7 +863,7 @@ Status GraphMemoryAssigner::AssignAtomicOutputAndWorkspaceMemory(const ge::NodeP
ret = AssignOrdinaryAtomicWorkspaceMemory(node_op_desc, atomic_workspace_info, mem_offset_end);
}
if (ret != SUCCESS) {
GELOGE(ret, "Assign atomic workspace memory failed, node is %s.", node_op_desc->GetName().c_str());
GELOGE(ret, "[Assign][Memory:Atomic:Workspace]fail for node:%s.", node_op_desc->GetName().c_str());
return ret;
}
} else {
@@ -794,8 +876,11 @@ Status GraphMemoryAssigner::AssignAtomicOutputAndWorkspaceMemory(const ge::NodeP
Status GraphMemoryAssigner::AssignConnectNetOutputAtomicMemory(vector<NodePtr> &connect_netoutput_nodes) {
auto iter = memory_offset_.find(RT_MEMORY_HBM);
if (iter == memory_offset_.end()) {
std::string error = "Memory offset does not have memory type" + FmtToStr(RT_MEMORY_HBM);
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "InnerData memory_offset_ does not have type[HBM], "
"not expected when AssignConnectNetOutputAtomicMemory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
GELOGE(FAILED, "[Check][InnerData]memory_offset_ does not have memory type[HBM]"
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return FAILED;
}
for (auto &node : connect_netoutput_nodes) {
@@ -811,13 +896,14 @@ Status GraphMemoryAssigner::AssignConnectNetOutputAtomicMemory(vector<NodePtr> &
node->GetName().c_str(), node->GetOpDesc()->GetType().c_str(), original_atomic_mem_start);
vector<int64_t> mem_offset_end;
if (AssignAtomicOutputAndWorkspaceMemory(node, mem_offset_end) != SUCCESS) {
GELOGE(FAILED, "Assign atomic output and workspace memory failed, node is %s.", node->GetName().c_str());
GELOGE(FAILED, "[Assign][Memory]output atomic mem and workspace mem, fail for node name is %s.",
node->GetName().c_str());
return FAILED;
}

// All atomic nodes use atomic_addr_clean op independently, so we need to set the attr separately.
if (SetIndependentAtomicAttr(node, original_atomic_mem_start, mem_offset_end, RT_MEMORY_HBM) != SUCCESS) {
GELOGE(FAILED, "Failed to set atomic attr separately.");
GELOGE(FAILED, "[Set][Attr:IndependentAtomic]fail for node:%s", node->GetName().c_str());
return FAILED;
}
}
@@ -842,8 +928,11 @@ Status GraphMemoryAssigner::AssignReferenceMemory() {
vector<int64_t> output_list = out_op_desc->GetOutputOffset();

if (out_op_desc->GetOutputsSize() > output_list.size()) {
GELOGE(ge::FAILED, "The size %zu of node output desc is more than output_list's size %zu.",
out_op_desc->GetOutputsSize(), output_list.size());
REPORT_INNER_ERROR("E19999", "Output size:%zu more than output offset size:%zu, judge invalid in node:%s "
"when AssignReferenceMemory",
out_op_desc->GetOutputsSize(), output_list.size(), node->GetName().c_str());
GELOGE(ge::FAILED, "[Check][InnerData]Output size:%zu more than output offset size:%zu, invalid in node:%s",
out_op_desc->GetOutputsSize(), output_list.size(), node->GetName().c_str());
return ge::FAILED;
}

@@ -896,9 +985,12 @@ bool GraphMemoryAssigner::CheckInputIsSupportAtomic(const ge::NodePtr &node) {
}
if ((peer_op_desc->GetType() == CONSTANTOP) || (peer_op_desc->GetType() == AIPP_DATA_TYPE) ||
(peer_op_desc->GetType() == VARIABLE)) {
std::string error = "Op" + FmtToStr(node->GetName()) + "'s peer out node" +
FmtToStr(peer_op_desc->GetName()) + " is invalid, Constant/AippData/Variable is not supported";
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "node(type:%s, name:%s) link to atomic node(name:%s), "
"this situation not supported now",
peer_op_desc->GetType().c_str(), peer_op_desc->GetName().c_str(), node->GetName().c_str());
GELOGE(ge::FAILED, "[Check][Link]node(type:%s, name:%s) link to atomic node(name:%s), "
"this situation not supported now",
peer_op_desc->GetType().c_str(), peer_op_desc->GetName().c_str(), node->GetName().c_str());
return false;
}
}
@@ -918,22 +1010,27 @@ Status GraphMemoryAssigner::AssignAtomicOutputMemory(const ge::NodePtr &node, ve
// Check atomic output
vector<int64_t> output_list = op_desc->GetOutputOffset();
if (atomic_output_index.size() > output_list.size()) {
std::string error = "Op" + FmtToStr(node->GetName()) +
"'s size of atomic_output_index is more than the size of output_list";
std::string error =
"Op:" + FmtToStr(node->GetName()) + "'s size:" + FmtToStr(atomic_output_index.size()) +
" of atomic_output_index is more than the size:" + FmtToStr(output_list.size()) + " of output_list";
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
return ge::FAILED;
}
auto output_list_size = static_cast<int64_t>(output_list.size());
auto iter = memory_offset_.find(RT_MEMORY_HBM);
if (iter == memory_offset_.end()) {
std::string error = "Memory offset does not have memory type" + FmtToStr(RT_MEMORY_HBM);
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "InnerData memory_offset_ does not have type[HBM], "
"not expected when AssignAtomicOutputMemory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
GELOGE(FAILED, "[Check][InnerData]memory_offset_ does not have memory type[HBM]"
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return FAILED;
}
for (auto &output_index : atomic_output_index) {
if (output_index >= output_list_size) {
std::string error = "Op" + FmtToStr(node->GetName()) + "'s output index" + FmtToStr(output_index) +
" is more than the size" + FmtToStr(output_list_size) + " of output_list.";
std::string error =
"Op:" + FmtToStr(node->GetName()) + "'s atomic_output index:" + FmtToStr(output_index) +
" is more than the size:" + FmtToStr(output_list_size) + " of output_list.";
GE_ERRORLOG_AND_ERRORMSG(ge::PARAM_INVALID, error.c_str());
return ge::PARAM_INVALID;
}
@@ -941,7 +1038,8 @@ Status GraphMemoryAssigner::AssignAtomicOutputMemory(const ge::NodePtr &node, ve
// If the input of the cascade op needs to clear the atomic addr, there is no need to clear it separately here
bool is_assigned_mem = false;
if (GetMemoryAssignmentStatus(node, output_index, is_assigned_mem) != SUCCESS) {
GELOGE(ge::FAILED, "Failed to get memory assignment of node %s.", node->GetName().c_str());
GELOGE(ge::FAILED, "[Get][MemoryAssignmentStatus]fail for node %s, out_index:%ld",
node->GetName().c_str(), output_index);
return ge::FAILED;
}

@@ -981,8 +1079,9 @@ Status GraphMemoryAssigner::AssignAtomicOutputMemory(const ge::NodePtr &node, ve
Status GraphMemoryAssigner::GetMemoryAssignmentStatus(const ge::NodePtr &node, int64_t output_index,
bool &is_mem_assigned) {
if (static_cast<size_t>(output_index) >= node->GetAllOutDataAnchors().size()) {
std::string error = "Op" + FmtToStr(node->GetName()) + "'s output index" + FmtToStr(output_index) +
" is more than the size of node's AllOutDataAnchors.";
std::string error =
"Op:" + FmtToStr(node->GetName()) + "'s output index:" + FmtToStr(output_index) +
" is more than the size:" + FmtToStr(node->GetAllOutDataAnchors().size()) + " of node's AllOutDataAnchors.";
GE_ERRORLOG_AND_ERRORMSG(ge::PARAM_INVALID, error.c_str());
return ge::PARAM_INVALID;
}
@@ -1010,8 +1109,11 @@ Status GraphMemoryAssigner::AssignOrdinaryAtomicWorkspaceMemory(const ge::OpDesc
GELOGI("Begin to reassign normal atomic memory, node = %s.", op_desc->GetName().c_str());
auto mem_type_iter = memory_offset_.find(RT_MEMORY_HBM);
if (mem_type_iter == memory_offset_.end()) {
std::string error = "Memory offset does not have memory type" + FmtToStr(RT_MEMORY_HBM);
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "InnerData memory_offset_ does not have type[HBM], "
"not expected when AssignOrdinaryAtomicWorkspaceMemory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
GELOGE(FAILED, "[Check][InnerData]memory_offset_ does not have memory type[HBM]"
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return FAILED;
}
vector<int64_t> workspace_vector = op_desc->GetWorkspace();
@@ -1032,8 +1134,9 @@ Status GraphMemoryAssigner::AssignOrdinaryAtomicWorkspaceMemory(const ge::OpDesc
auto workspace_index = static_cast<uint64_t>(info_iter.first);
auto workspace_size = info_iter.second;
if (workspace_index >= workspace_vector.size()) {
std::string error = "The workspace index" + FmtToStr(workspace_index) +
" is more than the size" + FmtToStr(workspace_vector.size()) + " of workspace vector.";
std::string error = "The workspace index:" + FmtToStr(workspace_index) +
" is more than the size:" + FmtToStr(workspace_vector.size()) + " of workspace vector in op:" +
op_desc->GetName().c_str();
GE_ERRORLOG_AND_ERRORMSG(ge::PARAM_INVALID, error.c_str());
return ge::PARAM_INVALID;
}
@@ -1063,8 +1166,11 @@ Status GraphMemoryAssigner::AssignFusionAtomicWorkspaceMemory(const ge::OpDescPt
GELOGI("Begin to reassign fusion atomic memory, node = %s.", op_desc->GetName().c_str());
auto mem_type_iter = memory_offset_.find(RT_MEMORY_HBM);
if (mem_type_iter == memory_offset_.end()) {
std::string error = "Memory offset does not have memory type" + FmtToStr(RT_MEMORY_HBM);
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
REPORT_INNER_ERROR("E19999", "InnerData memory_offset_ does not have type[HBM], "
"not expected when AssignFusionAtomicWorkspaceMemory, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
GELOGE(FAILED, "[Check][InnerData]memory_offset_ does not have memory type[HBM]"
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
return FAILED;
}
map<string, map<int64_t, int64_t>> sub_node_workspace_offset;
@@ -1095,7 +1201,10 @@ Status GraphMemoryAssigner::AssignFusionAtomicWorkspaceMemory(const ge::OpDescPt
sub_node_workspace_offset.insert(std::make_pair(iter.first, index_offset));
}
if (!(op_desc->SetExtAttr(EXT_ATTR_ATOMIC_WORKSPACE_OFFSET, sub_node_workspace_offset))) {
GELOGE(FAILED, "Set EXT_ATTR_ATOMIC_WORKSPACE_OFFSET failed, op name:%s.", op_desc->GetName().c_str());
REPORT_INNER_ERROR("E19999", "Set Attr:%s fail for node:%s when AssignFusionAtomicWorkspaceMemory",
EXT_ATTR_ATOMIC_WORKSPACE_OFFSET.c_str(), op_desc->GetName().c_str());
GELOGE(FAILED, "[Set][Attr:%s]fail for node:%s.",
EXT_ATTR_ATOMIC_WORKSPACE_OFFSET.c_str(), op_desc->GetName().c_str());
return FAILED;
}

@@ -1106,7 +1215,7 @@ Status GraphMemoryAssigner::CheckOffset() {
std::map<std::string, std::string> anchor_to_symbol;
std::map<std::string, std::list<NodeIndexIO>> symbol_to_anchors;
if (GraphUtils::GetRefMapping(compute_graph_, symbol_to_anchors, anchor_to_symbol) != GRAPH_SUCCESS) {
GELOGE(FAILED, "Get ref-mapping for graph %s failed.", compute_graph_->GetName().c_str());
GELOGE(FAILED, "[Get][RefMapping]fail for graph %s", compute_graph_->GetName().c_str());
return FAILED;
}
for (const ge::NodePtr &node : compute_graph_->GetAllNodes()) {
@@ -1148,7 +1257,6 @@ Status GraphMemoryAssigner::CheckOffset() {
std::string error = "Invalid workspace" + FmtToStr(ge::kInvalidOffset) +
+ " in node" + FmtToStr(node->GetName());
GE_ERRORLOG_AND_ERRORMSG(FAILED, error.c_str());
GELOGE(FAILED, "Invalid workspace in node: %s workspace: %ld.", node->GetName().c_str(), ge::kInvalidOffset);
return FAILED;
}
}
@@ -1158,8 +1266,10 @@ Status GraphMemoryAssigner::CheckOffset() {

ge::Status GraphMemoryAssigner::SetInputOffset() {
if (memory_offset_.empty()) {
GELOGE(FAILED, "memory_offset_ is empty.");
return FAILED;
REPORT_INNER_ERROR("E19999", "InnerData memory_offset_ empty, not expected when SetInputOffset, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
GELOGE(FAILED, "[Check][InnerData:memory_offset_]empty is not expected, "
"graph_id:%u, graph_name:%s", compute_graph_->GetGraphID(), compute_graph_->GetName().c_str());
}
for (auto pair : memory_offset_) {
GEEVENT("[IMAS]AfterAssignMemory : %s memoffset[%zu], memtype[%ld]", compute_graph_->GetName().c_str(),
@@ -1168,7 +1278,7 @@ ge::Status GraphMemoryAssigner::SetInputOffset() {

for (const ge::NodePtr &node : compute_graph_->GetAllNodes()) {
if (UpdateOpInputOffset(node) != ge::SUCCESS) {
GELOGE(ge::FAILED, "Update op input offset failed");
GELOGE(ge::FAILED, "[Update][Offset:Input]fail for op:%s", node->GetName().c_str());
return ge::FAILED;
}
}
@@ -1316,12 +1426,12 @@ ge::Status GraphMemoryAssigner::UpdateOpInputOffset(const NodePtr &node) const {
}
} else if (node->GetType() == DATA_TYPE) {
if (UpdateConstArgsOffset(node, input_list) != SUCCESS) {
GELOGE(FAILED, "Update data: %s args offset failed.", node->GetName().c_str());
GELOGE(FAILED, "[Update][Offset:Input:Const]fail for node:%s ", node->GetName().c_str());
return FAILED;
}
} else {
if (UpdateOpInputOffset(node, input_list) != SUCCESS) {
GELOGE(FAILED, "Update node: %s input offset failed.", node->GetName().c_str());
GELOGE(FAILED, "[Update][Offset:Input]fail for node:%s", node->GetName().c_str());
return FAILED;
}
}
@@ -1361,7 +1471,7 @@ Status GraphMemoryAssigner::SetIndependentAtomicAttr(const ge::NodePtr &node, in
peer_out_node_desc->GetName().c_str(), peer_out_node_desc->GetType().c_str());
if (peer_out_node_desc->GetType() == ATOMICADDRCLEAN) {
if (SetAtomicCleanAttr(peer_out_node, memory_offset_start, memory_offset_size, memory_type) != SUCCESS) {
GELOGE(FAILED, "Set atomic clean attr failed.");
GELOGE(FAILED, "[Set][AtomicCleanAttr]fail for node:%s", peer_out_node->GetName().c_str());
return FAILED;
}
}
@@ -1387,7 +1497,10 @@ ge::Status GraphMemoryAssigner::SetAtomicCleanAttr(const NodePtr &node, const ve
(void) ge::AttrUtils::GetListInt(node_op_desc, ATTR_NAME_AUTOMIC_ADD_START, mem_start_vector);
mem_start_vector.insert(mem_start_vector.end(), atomic_mem_start.begin(), atomic_mem_start.end());
GE_CHK_BOOL_EXEC(ge::AttrUtils::SetListInt(node_op_desc, ATTR_NAME_AUTOMIC_ADD_START, mem_start_vector),
GELOGE(FAILED, "SetListInt failed.");
REPORT_INNER_ERROR("E19999", "Set Attr:%s failed when SetAtomicCleanAttr, op_name:%s",
ATTR_NAME_AUTOMIC_ADD_START.c_str(), node_op_desc->GetName().c_str());
GELOGE(FAILED, "[Set][Attr:%s]fail for op_name:%s",
ATTR_NAME_AUTOMIC_ADD_START.c_str(), node_op_desc->GetName().c_str());
return FAILED);

std::vector<int64_t> mem_size_vector;
@@ -1395,7 +1508,10 @@ ge::Status GraphMemoryAssigner::SetAtomicCleanAttr(const NodePtr &node, const ve
(void) ge::AttrUtils::GetListInt(node_op_desc, ATTR_NAME_AUTOMIC_ADD_MEM_SIZE, mem_size_vector);
mem_size_vector.insert(mem_size_vector.end(), atomic_mem_size.begin(), atomic_mem_size.end());
GE_CHK_BOOL_EXEC(ge::AttrUtils::SetListInt(node_op_desc, ATTR_NAME_AUTOMIC_ADD_MEM_SIZE, mem_size_vector),
GELOGE(FAILED, "SetListInt failed.");
REPORT_INNER_ERROR("E19999", "Set Attr:%s failed when SetAtomicCleanAttr, op_name:%s",
ATTR_NAME_AUTOMIC_ADD_MEM_SIZE.c_str(), node_op_desc->GetName().c_str());
GELOGE(FAILED, "[Set][Attr:%s]fail for op_name:%s",
ATTR_NAME_AUTOMIC_ADD_MEM_SIZE.c_str(), node_op_desc->GetName().c_str());
return FAILED);

std::stringstream ss;
@@ -1437,12 +1553,14 @@ ge::Status GraphMemoryAssigner::GetNodeListMemoryType(const vector<NodePtr> &nod
// In the dynamic batch scenario, the memory attributes of nodes are the same.
for (auto &n : nodes) {
if (mem_reuse_model == kVirtualInputNodeMemoryReuse) {
GE_CHK_STATUS_RET(GetNodeMemoryType(n, memory_type, "input"), "Get node memory type failed.")
GE_CHK_STATUS_RET(GetNodeMemoryType(n, memory_type, "input"),
"[Get][MemType:input]fail for node:%s", n->GetName().c_str())
break;
}

if (mem_reuse_model == kVirtualOutputNodeMemoryReuse) {
GE_CHK_STATUS_RET(GetNodeMemoryType(n, memory_type, "output"), "Get node memory type failed.");
GE_CHK_STATUS_RET(GetNodeMemoryType(n, memory_type, "output"),
"[Get][MemType:output]fail for node:%s", n->GetName().c_str())
break;
}
}
@@ -1478,7 +1596,7 @@ ge::Status GraphMemoryAssigner::GetNodeMemoryType(const NodePtr &node, int64_t &
}

if (!CheckContinuousMemType(mem_type_list)) {
GELOGE(FAILED, "Check continuous memory type failed.");
GELOGE(FAILED, "[Check][MemType:Continuous]fail for node:%s", node->GetName().c_str());
return FAILED;
}
// It is continuous memory and memory type is the same, so use the first memory.
@@ -1526,7 +1644,11 @@ ge::Status GraphMemoryAssigner::GetAllRef(const NodePtr &node, map<int32_t, int3
if (node->GetInDataAnchor(reuse_in_index) != nullptr) {
out2ins.emplace(out_data_anchor->GetIdx(), reuse_in_index);
} else {
GELOGE(FAILED, "Invalid reuse_input value %d on output %d of node %s, please check attr reuse_input",
REPORT_INNER_ERROR("E19999", "Invalid reuse_input value %d on output %d of node %s, "
"please check attr reuse_input",
reuse_in_index, out_data_anchor->GetIdx(), node->GetName().c_str());
GELOGE(FAILED, "[Check][Attr]Invalid reuse_input value %d on output %d of node %s, "
"please check attr reuse_input",
reuse_in_index, out_data_anchor->GetIdx(), node->GetName().c_str());
return FAILED;
}
@@ -1549,7 +1671,7 @@ bool GraphMemoryAssigner::AssignContinuousInputMemoryWithAtomicProcessDirectly(
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;
}
@@ -1559,7 +1681,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;
}
@@ -1575,11 +1697,12 @@ ge::Status GraphMemoryAssigner::AssignContinuousInputMemoryWithAtomicProcess(con
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.");
GE_CHK_STATUS_RET(GetNodeMemoryType(input_continuous_node, memory_type, "input"),
"[Get][MemType]fail for node:%s", input_continuous_node->GetName().c_str());
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!");
GELOGE(ret, "[Assign][Memory:Input:continuous]fail for node:%s", input_continuous_node->GetName().c_str());
return ret;
}

@@ -1590,7 +1713,6 @@ ge::Status GraphMemoryAssigner::AssignContinuousInputMemoryWithAtomicProcess(con
if (!input_indexes.empty() && input_indexes[0] == kAllInputAddrIsAtomic) {
// check whether there is an atomic conflict between the current node and the peer out node
if (!CheckInputIsSupportAtomic(input_continuous_node)) {
GELOGE(ge::FAILED, "There is an atomic conflict between the current node and the peer out node, not supported!");
return ge::FAILED;
}

@@ -1602,7 +1724,7 @@ ge::Status GraphMemoryAssigner::AssignContinuousInputMemoryWithAtomicProcess(con
if (peer_out_node->GetType() == ATOMICADDRCLEAN) {
ret = SetAtomicCleanAttr(peer_out_node, {mem_clean_start}, {mem_clean_size}, memory_type);
if (ret != SUCCESS) {
GELOGE(ret, "Failed to set attr for atomic addr clean node %s.", peer_out_node->GetName().c_str());
GELOGE(ret, "[Set][AtomicCleanAttr]fail for node:%s", peer_out_node->GetName().c_str());
return ret;
}
}


+ 1
- 1
ge/graph/build/memory/graph_mem_assigner.h View File

@@ -131,7 +131,7 @@ class GraphMemoryAssigner {
std::map<NodePtr, uint32_t> &node_2_continuous_type);

ge::Status AssignContinuousInputMemoryWithAtomicProcess(const NodePtr &input_continuous_node,
uint32_t continuous_type, bool reverse_refresh=false);
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);


+ 16
- 5
ge/graph/build/model_builder.cc View File

@@ -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");


+ 0
- 4
ge/graph/execute/graph_execute.cc View File

@@ -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()


+ 3
- 11
ge/graph/load/graph_loader.cc View File

@@ -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) {


+ 2
- 2
ge/graph/load/graph_loader.h View File

@@ -32,9 +32,9 @@
namespace ge {
class GraphLoader {
public:
GraphLoader();
GraphLoader() = default;

virtual ~GraphLoader();
virtual ~GraphLoader() = default;

GraphLoader(const GraphLoader &in) = delete;



+ 3
- 3
ge/graph/load/model_manager/data_dumper.cc View File

@@ -385,7 +385,7 @@ Status DataDumper::DumpRefOutput(const DataDumper::InnerDumpInfo &inner_dump_inf

Status DataDumper::DumpOutputWithTask(const InnerDumpInfo &inner_dump_info, aicpu::dump::Task &task) {
const auto &output_descs = inner_dump_info.op->GetAllOutputsDesc();
const std::vector<void *> output_addrs = ModelUtils::GetOutputDataAddrs(runtime_param_, inner_dump_info.op);
const std::vector<void *> output_addrs = ModelUtils::GetOutputDataAddrs(*runtime_param_, inner_dump_info.op);
if (output_descs.size() != output_addrs.size()) {
GELOGE(PARAM_INVALID, "Invalid output desc addrs size %zu, op %s has %zu output desc.", output_addrs.size(),
inner_dump_info.op->GetName().c_str(), output_descs.size());
@@ -436,7 +436,7 @@ Status DataDumper::DumpOutput(const InnerDumpInfo &inner_dump_info, aicpu::dump:
// else data, const or variable op
aicpu::dump::Output output;
auto output_tensor = inner_dump_info.op->GetOutputDescPtr(inner_dump_info.output_anchor_index);
const std::vector<void *> output_addrs = ModelUtils::GetOutputDataAddrs(runtime_param_, inner_dump_info.op);
const std::vector<void *> output_addrs = ModelUtils::GetOutputDataAddrs(*runtime_param_, inner_dump_info.op);
if (output_tensor == nullptr) {
GELOGE(PARAM_INVALID, "output_tensor is null, index: %d, size: %zu.", inner_dump_info.output_anchor_index,
inner_dump_info.op->GetOutputsSize());
@@ -540,7 +540,7 @@ Status DataDumper::DumpRefInput(const DataDumper::InnerDumpInfo &inner_dump_info
Status DataDumper::DumpInput(const InnerDumpInfo &inner_dump_info, aicpu::dump::Task &task) {
GELOGI("Start dump input");
const auto &input_descs = inner_dump_info.op->GetAllInputsDesc();
const std::vector<void *> input_addrs = ModelUtils::GetInputDataAddrs(runtime_param_, inner_dump_info.op);
const std::vector<void *> input_addrs = ModelUtils::GetInputDataAddrs(*runtime_param_, inner_dump_info.op);
if (input_descs.size() != input_addrs.size()) {
GELOGE(PARAM_INVALID, "Invalid input desc addrs size %zu, op %s has %zu input desc.", input_addrs.size(),
inner_dump_info.op->GetName().c_str(), input_descs.size());


+ 8
- 13
ge/graph/load/model_manager/data_dumper.h View File

@@ -36,7 +36,7 @@
namespace ge {
class DataDumper {
public:
explicit DataDumper(const RuntimeParam &rsh)
explicit DataDumper(RuntimeParam *rsh)
: model_name_(),
model_id_(0),
runtime_param_(rsh),
@@ -106,7 +106,7 @@ class DataDumper {
std::string om_name_;

uint32_t model_id_;
const RuntimeParam &runtime_param_;
RuntimeParam *runtime_param_;
void *dev_mem_load_;
void *dev_mem_unload_;

@@ -125,10 +125,9 @@ class DataDumper {
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
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 +143,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 {


+ 95
- 112
ge/graph/load/model_manager/davinci_model.cc View File

@@ -31,6 +31,7 @@
#include "common/scope_guard.h"
#include "common/thread_pool.h"
#include "framework/common/debug/ge_log.h"
#include "framework/common/util.h"
#include "graph/common/ge_call_wrapper.h"
#include "graph/compute_graph.h"
#include "graph/debug/ge_attr_define.h"
@@ -118,12 +119,13 @@ 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);
}

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;
@@ -183,7 +185,7 @@ DavinciModel::DavinciModel(int32_t priority, const std::shared_ptr<ModelListener
last_execute_mode_(INITIALIZATION),
session_id_(0),
device_id_(0),
maxDumpOpNum_(0), data_dumper_(runtime_param_),
maxDumpOpNum_(0), data_dumper_(&runtime_param_),
iterator_count_(0),
is_l1_fusion_enable_(false),
is_first_execute_(true) {
@@ -213,12 +215,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) {
@@ -231,6 +233,8 @@ DavinciModel::~DavinciModel() {

FreeP2PMem();

OpDebugUnRegister();

if (l1_fusion_addr_ != nullptr) {
GE_CHK_RT(rtFree(l1_fusion_addr_));
}
@@ -241,8 +245,6 @@ DavinciModel::~DavinciModel() {
}
}

OpDebugUnRegister();

ReleaseTask();
CleanTbeHandle();

@@ -277,7 +279,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;
@@ -296,6 +298,11 @@ void DavinciModel::ReleaseTask() {
GE_CHK_STATUS(task->Release(), "Release task failed.");
}
}

for (auto &item : label_goto_args_) {
GE_FREE_RT_LOG(item.second.first);
}
label_goto_args_.clear();
}

Status DavinciModel::Assign(const GeModelPtr &ge_model) {
@@ -363,7 +370,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;
@@ -386,7 +393,7 @@ Status DavinciModel::InitFeatureMapAndP2PMem(void *dev_ptr, size_t mem_size) {
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Alloc feature map memory failed. size: %zu", data_size);
return ACL_ERROR_GE_MEMORY_ALLOCATION;
}
GEEVENT("[IMAS]InitFeatureMapAndP2PMem graph_%u MallocMemory type[F] memaddr[%p] mem_size[%zu].",
GEEVENT("[IMAS]InitFeatureMapAndP2PMem graph_%u MallocMemory type[F] memaddr[%p] mem_size[%zu]",
runtime_param_.graph_id, mem_base_, data_size);

if (!is_inner_weight_base_) {
@@ -407,7 +414,7 @@ Status DavinciModel::InitFeatureMapAndP2PMem(void *dev_ptr, size_t mem_size) {
is_inner_p2p_mem_base_ = true;
}

GE_CHK_STATUS_RET(InitVariableMem(), "Init variable memory failed");
GE_CHK_STATUS_RET(InitVariableMem(), "Init variable memory failed.");
runtime_param_.mem_base = mem_base_;
runtime_param_.weight_base = weights_mem_base_;
runtime_param_.memory_infos[RT_MEMORY_P2P_DDR].memory_base = p2p_mem_base_;
@@ -479,7 +486,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);
@@ -526,12 +533,12 @@ 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");
@@ -557,7 +564,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);
@@ -567,77 +574,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;
@@ -646,9 +597,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);
@@ -658,7 +609,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();
@@ -712,17 +663,17 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size
GE_CHK_STATUS_RET(OpDebugRegister(), "OpDebugRegister failed");

GE_TIMESTAMP_START(TransAllVarData);
GE_CHK_STATUS_RET(TransAllVarData(compute_graph, runtime_param_.graph_id), "TransAllVarData failed.");
GE_CHK_STATUS_RET(TransAllVarData(compute_graph, runtime_param_.graph_id), "TransAllVarData failed");
GE_TIMESTAMP_END(TransAllVarData, "GraphLoader::TransAllVarData");
GE_CHK_STATUS_RET(TransVarDataUtils::CopyVarData(compute_graph, session_id_, device_id_), "copy var data failed.");
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));
data_inputer_ = new (std::nothrow) DataInputer();
GE_CHK_BOOL_RET_STATUS(data_inputer_ != nullptr, MEMALLOC_FAILED, "data_inputer_ is nullptr.");
GE_CHK_BOOL_RET_STATUS(data_inputer_ != nullptr, MEMALLOC_FAILED, "data_inputer_ is nullptr");
}
fixed_mem_base_ = reinterpret_cast<uintptr_t>(mem_base_);
GE_TIMESTAMP_END(InitModelMem, "GraphLoader::InitModelMem");
@@ -735,10 +686,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,
@@ -765,7 +716,7 @@ 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;
}

@@ -1213,7 +1164,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());
}
}
@@ -1282,7 +1233,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;
@@ -1327,7 +1278,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()) {
@@ -1341,7 +1292,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());
@@ -1361,7 +1312,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());
}
@@ -1384,11 +1335,44 @@ 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);
}
}

Status DavinciModel::GetLabelGotoAddr(uint32_t label_index, rtMemType_t mem_type, void *&arg_addr, uint32_t &arg_size) {
std::lock_guard<std::mutex> lock(label_args_mutex_);
auto it = label_goto_args_.find(label_index);
if (it != label_goto_args_.end()) {
arg_addr = it->second.first;
arg_size = it->second.second;
return SUCCESS;
}

if (label_index >= label_list_.size()) {
GELOGE(INTERNAL_ERROR, "Invalid label id:%u, label size:%zu", label_index, label_list_.size());
return INTERNAL_ERROR;
}
GE_CHECK_NOTNULL(label_list_[label_index]);
vector<rtLabel_t> label_used = { label_list_[label_index] };

arg_size = label_used.size() * sizeof(rtLabelDevInfo);
rtError_t rt_ret = rtMalloc(&arg_addr, arg_size, mem_type);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rtMalloc failed, error: %#x", rt_ret);
return RT_ERROR_TO_GE_STATUS(rt_ret);
}

label_goto_args_[label_index] = { arg_addr, arg_size };
rt_ret = rtLabelListCpy(label_used.data(), label_used.size(), arg_addr, arg_size);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rtLabelListCpy failed, error: %#x", rt_ret);
return RT_ERROR_TO_GE_STATUS(rt_ret);
}

return SUCCESS;
}

/// @ingroup ge
/// @brief LabelSet Op Initialize.
/// @param [in] op_desc: LabelSet Op descriptor.
@@ -1427,7 +1411,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;
@@ -1830,7 +1814,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;
}

@@ -1860,7 +1844,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;
}

@@ -1870,7 +1854,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;
}

@@ -1915,7 +1899,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;
@@ -2292,7 +2276,7 @@ Status DavinciModel::SinkTimeProfile(const InputData &current_data) {
model_time_info[kModelName] = name;
model_time_info[kModeleId] = this->Id();
model_time_info[kRequestId] = current_data.request_id;
model_time_info[kThreadId] = GetDataInputTid();
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;
@@ -2574,7 +2558,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;
@@ -2589,7 +2573,7 @@ void *DavinciModel::Run(DavinciModel *model) {
bool seq_end_flag = false;
uint32_t model_id = model->Id();
uint32_t device_id = model->GetDeviceId();
GetContext().SetWorkStreamId(model->GetWorkStreamId());
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));
@@ -2600,6 +2584,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) {
@@ -2722,10 +2707,6 @@ Status DavinciModel::DestroyThread() {
thread_id_.join();
}

if (shrink_id_.joinable()) {
shrink_id_.join();
}

return SUCCESS;
}

@@ -2756,7 +2737,7 @@ Status DavinciModel::ModelRunStart() {
int64_t maxDumpOpNum = std::strtol(opt.c_str(), nullptr, kDecimal);
maxDumpOpNum_ = maxDumpOpNum;

work_stream_id_ = GetContext().WorkStreamId();
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;
@@ -3424,14 +3405,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]",
@@ -3975,7 +3958,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);
@@ -4049,7 +4032,7 @@ 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",
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(),


+ 10
- 6
ge/graph/load/model_manager/davinci_model.h View File

@@ -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"
@@ -272,6 +273,8 @@ class DavinciModel {

const vector<rtLabel_t> &GetLabelList() const { return label_list_; }

Status GetLabelGotoAddr(uint32_t label_index, rtMemType_t memory_type, void *&addr, uint32_t &size);

Status DestroyThread();

// get Op
@@ -412,7 +415,7 @@ class DavinciModel {
///
uint64_t GetSessionId() const { return session_id_; }

uint64_t GetWorkStreamId() const { return work_stream_id_; }
const struct ErrorMessage::Context &GetErrorContext() const { return error_context_; }

///
/// @ingroup ge
@@ -538,7 +541,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(); }
@@ -906,7 +909,6 @@ class DavinciModel {
vector<int64_t> output_memory_size_list_;

thread thread_id_;
thread shrink_id_;

shared_ptr<ModelListener> listener_;

@@ -930,6 +932,9 @@ class DavinciModel {
vector<rtLabel_t> label_list_;
set<uint32_t> label_id_indication_;

mutex label_args_mutex_;
map<uint32_t, pair<void *, uint32_t>> label_goto_args_;

mutex outside_addrs_mutex_;
vector<ZeroCopyTask> zero_copy_tasks_; // Task used Data or NetOutput addr.
set<const void *> copy_only_addrs_; // Address need copy to original place.
@@ -959,7 +964,7 @@ class DavinciModel {
vector<uintptr_t> output_mbuf_list_; // output mbuf created by dequeue task.

uint64_t session_id_;
uint64_t work_stream_id_;
struct ErrorMessage::Context error_context_;

uint32_t device_id_;

@@ -985,6 +990,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 +1028,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_;


+ 19
- 25
ge/graph/load/model_manager/model_manager.cc View File

@@ -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);
@@ -302,12 +297,12 @@ Status ModelManager::LoadModelOnline(uint32_t &model_id, const shared_ptr<ge::Ge
if (model_id == INVALID_MODEL_ID) {
GenModelId(&model_id);
}
bool is_shape_unknown = false;
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);
auto name_to_model = ge_root_model->GetSubgraphInstanceNameToModel();
string model_name = "";
bool is_shape_unknown = ge_root_model->GetRootGraph()->GetGraphUnknownFlag();
// if multi subgraph is known, do hybrid load process
if (is_shape_unknown || GetContext().GetHostExecFlag() || (name_to_model.size() > 1)) {
return DoLoadHybridModelOnline(model_id, model_name, ge_root_model, listener);
}

mmTimespec timespec = mmGetTickCount();
@@ -321,14 +316,13 @@ 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;

auto root_graph = ge_root_model->GetRootGraph();
GE_CHECK_NOTNULL(root_graph);
string root_model_name = root_graph->GetName();
auto name_to_model = ge_root_model->GetSubgraphInstanceNameToModel();
GeModelPtr ge_model = name_to_model[root_model_name];
Status ret = SUCCESS;
do {
@@ -1036,7 +1030,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 +1047,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 +1075,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 +1086,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 +1397,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;


+ 2
- 1
ge/graph/load/model_manager/model_manager.h View File

@@ -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);

///


+ 1
- 1
ge/graph/load/model_manager/model_utils.cc View File

@@ -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);


+ 33
- 9
ge/graph/load/model_manager/task_info/label_goto_ex_task_info.cc View File

@@ -17,9 +17,15 @@
#include "graph/load/model_manager/task_info/label_goto_ex_task_info.h"

#include "graph/load/model_manager/davinci_model.h"
#include "graph/debug/ge_attr_define.h"

namespace ge {
constexpr uint8_t kGotoBranchMax = 1;

LabelGotoExTaskInfo::~LabelGotoExTaskInfo() {
args_ = nullptr;
GE_FREE_RT_LOG(index_value_);
}

Status LabelGotoExTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *davinci_model) {
GELOGI("LabelGotoExTaskInfo Init Start.");
GE_CHECK_NOTNULL(davinci_model);
@@ -28,7 +34,7 @@ Status LabelGotoExTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *da
return FAILED;
}

// Get LabelGoto task def
// Get LabelGotoEx task def
const domi::LabelGotoExDef &label_goto = task_def.label_goto_ex();
OpDescPtr op_desc = davinci_model->GetOpByIndex(label_goto.op_index());
if (op_desc == nullptr) {
@@ -43,20 +49,38 @@ Status LabelGotoExTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *da
return INTERNAL_ERROR;
}

const vector<rtLabel_t> &label_list = davinci_model->GetLabelList();
if (label_index >= label_list.size()) {
GELOGE(PARAM_INVALID, "LabelGotoExTaskInfo: Invalid label id:%u, label size:%zu", label_index, label_list.size());
return INTERNAL_ERROR;
rtMemType_t memory_type = op_desc->HasAttr(ATTR_NAME_MEMORY_TYPE_RANGE) ? RT_MEMORY_TS_4G : RT_MEMORY_HBM;
GELOGI("memory_type: %u", memory_type);

GE_CHK_STATUS_RET_NOLOG(davinci_model->GetLabelGotoAddr(label_index, memory_type, args_, args_size_));

rtError_t rt_ret = rtMalloc(&index_value_, sizeof(uint64_t), memory_type);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rtMalloc failed, error: %#x", rt_ret);
return RT_ERROR_TO_GE_STATUS(rt_ret);
}
label_ = label_list[label_index];

GELOGI("LabelGotoExTaskInfo Init Success, label id:%u, label:%p.", label_index, label_);
uint64_t branch_index = 0;
rt_ret = rtMemcpy(index_value_, sizeof(uint64_t), &branch_index, sizeof(uint64_t), RT_MEMCPY_HOST_TO_DEVICE);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rtMemcpy failed, error: %#x", rt_ret);
return RT_ERROR_TO_GE_STATUS(rt_ret);
}

GELOGI("LabelGotoExTaskInfo Init Success, label id:%u", label_index);
return SUCCESS;
}

Status LabelGotoExTaskInfo::Distribute() {
GELOGI("LabelGotoExTaskInfo Distribute Start.");
rtError_t rt_ret = rtLabelGotoEx(label_, stream_);
GE_CHECK_NOTNULL(args_);
GE_CHECK_NOTNULL(index_value_);
if (args_size_ == 0) {
GELOGE(PARAM_INVALID, "branch max: %u, args size: %u invalid.", kGotoBranchMax, args_size_);
return PARAM_INVALID;
}

rtError_t rt_ret = rtLabelSwitchByIndex(index_value_, kGotoBranchMax, args_, stream_);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", rt_ret);
return RT_ERROR_TO_GE_STATUS(rt_ret);


+ 8
- 6
ge/graph/load/model_manager/task_info/label_goto_ex_task_info.h View File

@@ -14,24 +14,26 @@
* limitations under the License.
*/

#ifndef GE_GRAPH_LOAD_NEW_MODEL_MANAGER_TASK_INFO_LABEL_GOTO_EX_TASK_INFO_H_
#define GE_GRAPH_LOAD_NEW_MODEL_MANAGER_TASK_INFO_LABEL_GOTO_EX_TASK_INFO_H_
#ifndef GE_GRAPH_LOAD_MODEL_MANAGER_TASK_INFO_LABEL_GOTO_EX_TASK_INFO_H_
#define GE_GRAPH_LOAD_MODEL_MANAGER_TASK_INFO_LABEL_GOTO_EX_TASK_INFO_H_

#include "graph/load/model_manager/task_info/task_info.h"

namespace ge {
class LabelGotoExTaskInfo : public TaskInfo {
public:
LabelGotoExTaskInfo() : label_(nullptr) {}
LabelGotoExTaskInfo() = default;

~LabelGotoExTaskInfo() override { label_ = nullptr; }
~LabelGotoExTaskInfo() override;

Status Init(const domi::TaskDef &task_def, DavinciModel *davinci_model) override;

Status Distribute() override;

private:
void *label_;
void *index_value_{nullptr}; // switch index input.
void *args_{nullptr}; // label info memory.
uint32_t args_size_{0}; // label info length.
};
} // namespace ge
#endif // GE_GRAPH_LOAD_NEW_MODEL_MANAGER_TASK_INFO_LABEL_GOTO_EX_TASK_INFO_H_
#endif // GE_GRAPH_LOAD_MODEL_MANAGER_TASK_INFO_LABEL_GOTO_EX_TASK_INFO_H_

+ 3
- 3
ge/graph/load/model_manager/task_info/label_set_task_info.h View File

@@ -14,8 +14,8 @@
* limitations under the License.
*/

#ifndef GE_GRAPH_LOAD_NEW_MODEL_MANAGER_TASK_INFO_LABEL_SET_TASK_INFO_H_
#define GE_GRAPH_LOAD_NEW_MODEL_MANAGER_TASK_INFO_LABEL_SET_TASK_INFO_H_
#ifndef GE_GRAPH_LOAD_MODEL_MANAGER_TASK_INFO_LABEL_SET_TASK_INFO_H_
#define GE_GRAPH_LOAD_MODEL_MANAGER_TASK_INFO_LABEL_SET_TASK_INFO_H_

#include "graph/load/model_manager/task_info/task_info.h"

@@ -34,4 +34,4 @@ class LabelSetTaskInfo : public TaskInfo {
void *label_;
};
} // namespace ge
#endif // GE_GRAPH_LOAD_NEW_MODEL_MANAGER_TASK_INFO_LABEL_SET_TASK_INFO_H_
#endif // GE_GRAPH_LOAD_MODEL_MANAGER_TASK_INFO_LABEL_SET_TASK_INFO_H_

+ 8
- 16
ge/graph/load/model_manager/task_info/label_switch_by_index_task_info.cc View File

@@ -16,20 +16,13 @@

#include "graph/load/model_manager/task_info/label_switch_by_index_task_info.h"

#include "graph/debug/ge_attr_define.h"
#include "graph/load/model_manager/davinci_model.h"

namespace ge {
constexpr uint8_t kLabelSwitchIndexNum = 1;

LabelSwitchByIndexTaskInfo::~LabelSwitchByIndexTaskInfo() {
if (args_ != nullptr) {
rtError_t ret = rtFree(args_);
if (ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", ret);
}
}
args_ = nullptr;
GE_FREE_RT_LOG(args_);
index_value_ = nullptr;
}

@@ -37,13 +30,12 @@ Status LabelSwitchByIndexTaskInfo::Init(const domi::TaskDef &task_def, DavinciMo
GELOGI("LabelSwitchByIndexTaskInfo Init Start.");
GE_CHECK_NOTNULL(davinci_model);

const vector<rtLabel_t> &label_list = davinci_model->GetLabelList();
Status ret = SetStream(task_def.stream_id(), davinci_model->GetStreamList());
if (ret != SUCCESS) {
return FAILED;
}

// Get LabelSwitch task def
// Get LabelSwitchByIndex task def
const domi::LabelSwitchByIndexDef &label_switch = task_def.label_switch_by_index();
OpDescPtr op_desc = davinci_model->GetOpByIndex(label_switch.op_index());
if (op_desc == nullptr) {
@@ -68,7 +60,7 @@ Status LabelSwitchByIndexTaskInfo::Init(const domi::TaskDef &task_def, DavinciMo

davinci_model->DisableZeroCopy(index_value_);

std::vector<uint32_t> label_idx_list;
vector<uint32_t> label_idx_list;
if (!AttrUtils::GetListInt(op_desc, ATTR_NAME_LABEL_SWITCH_LIST, label_idx_list)) {
GELOGE(INTERNAL_ERROR, "LabelSwitchByIndexTaskInfo: %s Get attr %s failed.", op_desc->GetName().c_str(),
ATTR_NAME_LABEL_SWITCH_LIST.c_str());
@@ -81,7 +73,8 @@ Status LabelSwitchByIndexTaskInfo::Init(const domi::TaskDef &task_def, DavinciMo
return INTERNAL_ERROR;
}

label_list_.resize(branch_max_, nullptr);
vector<rtLabel_t> label_used(branch_max_, nullptr);
const vector<rtLabel_t> &label_list = davinci_model->GetLabelList();
for (size_t idx = 0; idx < label_idx_list.size(); ++idx) {
uint32_t label_id = label_idx_list[idx];
if (label_id >= label_list.size()) {
@@ -90,8 +83,7 @@ Status LabelSwitchByIndexTaskInfo::Init(const domi::TaskDef &task_def, DavinciMo
return INTERNAL_ERROR;
}
GE_CHECK_NOTNULL(label_list[label_id]);

label_list_[idx] = label_list[label_id];
label_used[idx] = label_list[label_id];
}

rtMemType_t memory_type = op_desc->HasAttr(ATTR_NAME_MEMORY_TYPE_RANGE) ? RT_MEMORY_TS_4G : RT_MEMORY_HBM;
@@ -103,7 +95,7 @@ Status LabelSwitchByIndexTaskInfo::Init(const domi::TaskDef &task_def, DavinciMo
return RT_ERROR_TO_GE_STATUS(rt_ret);
}

rt_ret = rtLabelListCpy(label_list_.data(), label_list_.size(), args_, args_size_);
rt_ret = rtLabelListCpy(label_used.data(), label_used.size(), args_, args_size_);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", rt_ret);
return RT_ERROR_TO_GE_STATUS(rt_ret);
@@ -125,7 +117,7 @@ Status LabelSwitchByIndexTaskInfo::Distribute() {
rtError_t rt_ret = rtLabelSwitchByIndex(index_value_, branch_max_, args_, stream_);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "Call rt api failed, ret: 0x%X", rt_ret);
return RT_FAILED;
return RT_ERROR_TO_GE_STATUS(rt_ret);
}

GELOGI("LabelSwitchByIndexTaskInfo Distribute Success.");


+ 9
- 11
ge/graph/load/model_manager/task_info/label_switch_by_index_task_info.h View File

@@ -14,16 +14,15 @@
* limitations under the License.
*/

#ifndef GE_GRAPH_LOAD_NEW_MODEL_MANAGER_TASK_INFO_LABEL_SWITCH_BY_INDEX_TASK_INFO_H_
#define GE_GRAPH_LOAD_NEW_MODEL_MANAGER_TASK_INFO_LABEL_SWITCH_BY_INDEX_TASK_INFO_H_
#ifndef GE_GRAPH_LOAD_MODEL_MANAGER_TASK_INFO_LABEL_SWITCH_BY_INDEX_TASK_INFO_H_
#define GE_GRAPH_LOAD_MODEL_MANAGER_TASK_INFO_LABEL_SWITCH_BY_INDEX_TASK_INFO_H_

#include "graph/load/model_manager/task_info/task_info.h"

namespace ge {
class LabelSwitchByIndexTaskInfo : public TaskInfo {
public:
LabelSwitchByIndexTaskInfo()
: index_value_(nullptr), branch_max_(0), args_(nullptr), args_size_(0), fixed_addr_offset_(0) {}
LabelSwitchByIndexTaskInfo() = default;

~LabelSwitchByIndexTaskInfo() override;

@@ -34,12 +33,11 @@ class LabelSwitchByIndexTaskInfo : public TaskInfo {
Status CalculateArgs(const domi::TaskDef &task_def, DavinciModel *davinci_model) override;

private:
void *index_value_; // switch index input.
uint32_t branch_max_; // max branch count.
void *args_; // label info memory.
uint32_t args_size_; // label info length.
std::vector<rtLabel_t> label_list_;
int64_t fixed_addr_offset_;
void *index_value_{nullptr}; // switch index input.
uint32_t branch_max_{0}; // max branch count.
void *args_{nullptr}; // label info memory.
uint32_t args_size_{0}; // label info length.
int64_t fixed_addr_offset_{0};
};
} // namespace ge
#endif // GE_GRAPH_LOAD_NEW_MODEL_MANAGER_TASK_INFO_LABEL_SWITCH_BY_INDEX_TASK_INFO_H_
#endif // GE_GRAPH_LOAD_MODEL_MANAGER_TASK_INFO_LABEL_SWITCH_BY_INDEX_TASK_INFO_H_

+ 101
- 21
ge/graph/manager/graph_caching_allocator.cc View File

@@ -40,7 +40,7 @@ static bool BlockComparator(const Block *left, const Block *right) {
}

bool CanMerge(Block *block) {
if (block == nullptr || block->allocated || !block->IsSplit()) {
if ((block == nullptr) || block->allocated || !block->IsSplit()) {
return false;
}
return true;
@@ -52,7 +52,7 @@ size_t GetBinIndex(size_t size) {
if (size <= range) {
break;
}
++index;
index++;
}
if (index > kNumBins - 1) {
index = kNumBins - 1;
@@ -85,8 +85,17 @@ 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()) {
count.emplace(size, 1);
} else {
it->second++;
}
}

CachingAllocator::CachingAllocator(rtMemType_t memory_type) : memory_type_(memory_type), memory_allocator_(nullptr) {
for (uint32_t i = 0; i < kNumBins; ++i) {
for (uint32_t i = 0; i < kNumBins; i++) {
free_block_bins_[i] = nullptr;
}
}
@@ -96,7 +105,7 @@ Status CachingAllocator::Initialize(uint32_t device_id) {
// when redo Initialize free old memory
FreeBlocks();
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (uint32_t i = 0; i < kNumBins; ++i) {
for (uint32_t i = 0; i < kNumBins; i++) {
if (free_block_bins_[i] != nullptr) {
continue;
}
@@ -116,24 +125,25 @@ 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);
uint8_t *ptr = nullptr;
Block *block = FindFreeBlock(size, org_ptr, device_id);
if (block != nullptr) {
ptr = block->ptr;
} else {
if (block == nullptr) {
if (ge::SUCCESS == TryExtendCache(size, device_id)) {
block = FindFreeBlock(size, org_ptr, device_id);
if (block != nullptr) {
ptr = block->ptr;
}
}
} else {
ptr = block->ptr;
}
if (ptr == nullptr) {
GELOGE(FAILED, "Malloc failed device id = %u, size= %zu", device_id, size);
@@ -161,7 +171,7 @@ Status CachingAllocator::Free(uint8_t *ptr, uint32_t device_id) {
}

void CachingAllocator::FreeBlock(Block *block) {
if (block == nullptr || !block->allocated) {
if ((block == nullptr) || !block->allocated) {
return;
}
GELOGI("Free block size = %zu", block->size);
@@ -177,7 +187,7 @@ void CachingAllocator::FreeBlock(Block *block) {
}

void CachingAllocator::MergeBlocks(Block *dst, Block *src, BlockBin &bin) {
if (!CanMerge(dst) || !CanMerge(src)) {
if (!CanMerge(src) || !CanMerge(dst)) {
return;
}

@@ -205,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);
@@ -262,18 +271,22 @@ Status CachingAllocator::TryExtendCache(size_t size, uint32_t device_id) {
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;
}

@@ -294,14 +307,16 @@ 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_);
for (uint32_t i = 0; i < kNumBins; ++i) {
size_t free_cached_memory_size = 0;
for (uint32_t i = 0; i < kNumBins; i++) {
auto pool = free_block_bins_[i];
if (pool == nullptr) {
continue;
@@ -309,8 +324,17 @@ void CachingAllocator::FreeCachedBlocks() {
for (auto it = pool->begin(); it != pool->end();) {
Block *block = *it;
// free block memory that has not been split
if ((block != nullptr) && (block->ptr != nullptr) && (block->prev == nullptr) && (block->next == nullptr) &&
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;
@@ -318,28 +342,84 @@ void CachingAllocator::FreeCachedBlocks() {
++it;
}
}
return free_cached_memory_size;
}

void CachingAllocator::FreeBlocks() {
GELOGI("Free blocks");
GELOGI("Free blocks.");
std::lock_guard<std::recursive_mutex> lock(mutex_);
// free allocated blocks and put to cache
for (auto &it : allocated_blocks_) {
FreeBlock(it.second);
}
allocated_blocks_.clear();

FreeCachedBlocks();
(void) FreeCachedBlocks();
}

void CachingAllocator::FreeBlockBins() {
GELOGI("Free block bins");
GELOGI("Free block bins.");
std::lock_guard<std::recursive_mutex> lock(mutex_);
for (uint32_t i = 0; i < kNumBins; ++i) {
for (uint32_t i = 0; i < kNumBins; i++) {
if (free_block_bins_[i] != nullptr) {
delete free_block_bins_[i];
free_block_bins_[i] = nullptr;
}
}
}

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_stat;
std::map<size_t, size_t> free_block_stat;
std::map<size_t, size_t> malloc_block_stat;
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_stat, (*it)->size);
total_free_count++;
}
}
}

for (auto &it : allocated_blocks_) {
if (it.second != nullptr) {
total_using_size += it.second->size;
IncreaseCount(using_block_stat, 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_stat[it.first] = it.second;
}
} while (0);

PrintCount(malloc_block_stat, "Malloc", total_malloc_size, total_malloc_count);
PrintCount(using_block_stat, "Using", total_using_size, total_using_count);
PrintCount(free_block_stat, "Free", total_free_size, total_free_count);
}
} // namespace ge

+ 12
- 2
ge/graph/manager/graph_caching_allocator.h View File

@@ -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_

+ 84
- 28
ge/graph/manager/graph_manager.cc View File

@@ -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. op_type:%s", op_desc->GetType().c_str());
GELOGI("Need to process multi batch for compute graph. op_type:%s.", op_desc->GetType().c_str());
GetLocalOmgContext().need_multi_batch = true;
break;
}
@@ -348,7 +350,7 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph,
for (auto &subgraph : compute_graph->GetAllSubgraphs()) {
(void)AttrUtils::SetStr(*subgraph, ATTR_NAME_SESSION_GRAPH_ID, session_graph_id);
}
GELOGD("Get graph session_graph_id attr failed, set session id to default value: [0].");
GELOGD("Get graph session_graph_id attr failed, set session id to default value: [0]");
}

GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id);
@@ -357,7 +359,10 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph,
std::shared_ptr<Graph> graph_ptr = MakeShared<ge::Graph>(graph);
GE_IF_BOOL_EXEC(graph_ptr == nullptr, GELOGE(FAILED, "GraphPtr make shared failed");
return FAILED);

// update option about tuning graph
ParseOption(options, BUILD_MODE, options_.build_mode);
ParseOption(options, BUILD_STEP, options_.build_step);
ParseOption(options, TUNING_PATH, options_.tuning_path);
graph_node->SetGraph(graph_ptr);
graph_node->SetOptions(options);
AddGraphNode(graph_id, graph_node);
@@ -431,6 +436,10 @@ Status GraphManager::AddGraphWithCopy(const GraphId &graph_id, const Graph &grap
GELOGE(FAILED, "GraphPtr make shared failed");
return FAILED;
}
// update option about tuning graph
ParseOption(options, BUILD_MODE, options_.build_mode);
ParseOption(options, BUILD_STEP, options_.build_step);
ParseOption(options, TUNING_PATH, options_.tuning_path);

graph_node->SetGraph(graph_ptr);
graph_node->SetOptions(options);
@@ -541,7 +550,8 @@ Status GraphManager::OptimizeSubGraphWithMultiThreads(ComputeGraphPtr compute_gr
}
std::future<Status> f = executor.commit(GraphManager::ProcessSubGraphWithMultiThreads, this,
compute_graph->GetGraphID(), subgraph,
compute_graph->GetName(), session_id, GetContext().WorkStreamId(),
compute_graph->GetName(), session_id,
ErrorManager::GetInstance().GetErrorContext(),
GetThreadLocalContext());
if (!f.valid()) {
GELOGE(FAILED, "Future is invalid");
@@ -557,7 +567,8 @@ Status GraphManager::OptimizeSubGraphWithMultiThreads(ComputeGraphPtr compute_gr
}
std::future<Status> f = executor.commit(GraphManager::ProcessSubGraphWithMultiThreads, this,
compute_graph->GetGraphID(), subgraph,
compute_graph->GetName(), session_id, GetContext().WorkStreamId(),
compute_graph->GetName(), session_id,
ErrorManager::GetInstance().GetErrorContext(),
GetThreadLocalContext());
if (!f.valid()) {
GELOGE(FAILED, "Future is invalid");
@@ -663,6 +674,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 +683,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 +729,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,7 +749,7 @@ 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.",
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());
@@ -758,7 +773,7 @@ Status GraphManager::RunCustomPass(const GraphNodePtr &graph_node) {

GE_TIMESTAMP_START(RunCustomPass);
GraphPtr graph = std::const_pointer_cast<Graph>(const_graph);
GE_CHK_STATUS_RET(CustomPassHelper::Instance().Run(graph), "Graph[%s] run custom pass fail",
GE_CHK_STATUS_RET(CustomPassHelper::Instance().Run(graph), "Graph[%s] run custom pass fail.",
comp_graph->GetName().c_str());
GE_TIMESTAMP_END(RunCustomPass, "GraphBuilder::RunCustomPass");
return SUCCESS;
@@ -776,7 +791,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");
@@ -802,6 +817,7 @@ Status GraphManager::PreRun(const GraphNodePtr &graph_node, const std::vector<Ge
}
}

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 +839,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 +871,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 +887,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. graph_id:%u", graph_node->GetGraphId());
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 +904,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 +1062,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 +1115,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 +1231,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 +1264,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! graph_id:%u", graph_id);
GELOGE(GE_GRAPH_PRERUN_FAILED, "[BuildGraph] StartForRunGraph failed! graph_id:%u.", graph_id);
return GE_GRAPH_PRERUN_FAILED;
}

@@ -1450,6 +1473,10 @@ Status GraphManager::ParseOptions(const std::map<std::string, std::string> &opti
GE_IF_BOOL_EXEC(ret != SUCCESS,
GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.compressFlag value is invalid, must be 0 or 1.");
return GE_GRAPH_OPTIONS_INVALID);
// Set Build model and step
ParseOption(options, BUILD_MODE, options_.build_mode);
ParseOption(options, BUILD_STEP, options_.build_step);
ParseOption(options, BUILD_STEP, options_.tuning_path);

// ge.graphType.
options_.run_graph_flag = true;
@@ -1495,20 +1522,16 @@ 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
ParseOption(options, BUILD_MODE, options_.build_mode);
ParseOption(options, BUILD_STEP, options_.build_step);

return SUCCESS;
}

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,13 +1548,15 @@ 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,
std::string &option) {
auto iter = options.find(key);
if (iter != options.end()) {
GELOGD("Set option %s from value %s to value%s", key.c_str(), option.c_str(), iter->second.c_str());
option = iter->second;
}
}
@@ -2508,10 +2533,10 @@ Status GraphManager::ProcessSubGraphWithMultiThreads(GraphManager *graph_manager
const SubGraphInfoPtr &sub_graph_info_ptr,
const std::string &root_graph_name,
uint64_t session_id,
uint64_t work_stream_id,
const struct ErrorMessage::Context &error_context,
const GEThreadLocalContext &ge_context) {
if (sub_graph_info_ptr != nullptr && graph_manager != nullptr) {
GetContext().SetWorkStreamId(work_stream_id);
ErrorManager::GetInstance().SetErrorContext(error_context);
GetContext().SetSessionId(session_id);
GetThreadLocalContext() = ge_context;
graph_manager->UpdateLocalOmgContext(root_graph_id);
@@ -2556,10 +2581,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,
GetContext().WorkStreamId(), GetThreadLocalContext(), callback}));
ErrorManager::GetInstance().GetErrorContext(),
GetThreadLocalContext(), callback}));
if (!ret) {
GELOGE(FAILED, "[GraphManager] Run graph async failed, graph_id=%u.", graph_id);
return FAILED;
@@ -2646,7 +2673,8 @@ void GraphManager::PreRunThread(GraphManager *graph_manager) {

GELOGI("A new loop start.");

GetContext().SetWorkStreamId(args.work_stream_id);
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);
@@ -2728,7 +2756,7 @@ 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.work_stream_id,
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.");
}
@@ -2815,6 +2843,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.");
}
@@ -2828,7 +2857,7 @@ void GraphManager::RunThread(GraphManager *graph_manager) {

GELOGI("A new loop start.");

GetContext().SetWorkStreamId(args.work_stream_id);
ErrorManager::GetInstance().SetErrorContext(args.error_context);
GetContext().SetSessionId(args.session_id);
GetThreadLocalContext() = args.context;
graph_manager->UpdateLocalOmgContext(args.graph_id);
@@ -2846,6 +2875,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);
@@ -2858,6 +2888,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) {
@@ -3067,6 +3098,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;
@@ -3100,11 +3140,27 @@ Status GraphManager::ConvertGraphToFile(ComputeGraphPtr &compute_graph, GraphPar
non_tuning_subgraphs.push_back(sub_graph_tmp);
}
}
// for function graphs to tune
for (auto &function_graph : compute_graph->GetAllSubgraphs()) {
auto subgraph_list = sub_graph_map[function_graph];
for (const auto &sub_graph_info_ptr : subgraph_list) {
GE_CHECK_NOTNULL(sub_graph_info_ptr);
ComputeGraphPtr sub_graph_tmp = sub_graph_info_ptr->GetSubGraph();
// need to tuning
if (sub_graph_info_ptr->GetEngineName() == kVectorEngine ||
sub_graph_info_ptr->GetEngineName() == kAIcoreEngine) {
tuning_subgraphs.push_back(sub_graph_tmp);
} else {
non_tuning_subgraphs.push_back(sub_graph_tmp);
}
}
}
return TuningUtils::ConvertGraphToFile(tuning_subgraphs, non_tuning_subgraphs, exe_flag, path);
}

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();
@@ -3120,7 +3176,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;
}

@@ -3172,7 +3228,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]);
}
@@ -3181,7 +3237,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);
}


+ 3
- 3
ge/graph/manager/graph_manager.h View File

@@ -196,7 +196,7 @@ class GraphManager {
GraphId graph_id;
std::vector<ge::InputTensorInfo> input_tensor;
uint64_t session_id;
uint64_t work_stream_id;
struct ErrorMessage::Context error_context;
GEThreadLocalContext context;
RunAsyncCallback callback;
};
@@ -205,7 +205,7 @@ class GraphManager {
GraphNodePtr graph_node;
GraphId graph_id;
uint64_t session_id;
uint64_t work_stream_id;
struct ErrorMessage::Context error_context;
std::vector<ge::InputTensorInfo> input_tensor;
GeRootModelPtr ge_root_model;
GEThreadLocalContext context;
@@ -223,7 +223,7 @@ class GraphManager {
const SubGraphInfoPtr &sub_graph_info_ptr,
const std::string &root_graph_name,
uint64_t session_id,
uint64_t work_stream_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);


+ 3
- 1
ge/graph/manager/graph_manager_utils.h View File

@@ -249,6 +249,7 @@ struct GraphManagerOptions {
std::string save_original_model;
std::string build_mode;
std::string build_step;
std::string tuning_path;
std::string input_shape;
std::string dynamic_dims;
int32_t dynamic_node_type = -1;
@@ -275,7 +276,8 @@ struct GraphManagerOptions {
is_single_op(false),
save_original_model("false"),
build_mode(""),
build_step("") {}
build_step(""),
tuning_path(""){}
};
} // namespace ge



+ 11
- 7
ge/graph/manager/graph_var_manager.cc View File

@@ -347,14 +347,18 @@ ge::Status VarManager::Init(const uint32_t &version, const uint64_t &session_id,
const uint64_t &job_id) {
std::lock_guard<std::recursive_mutex> lock(mutex_);
GELOGI("VarManager::Init, session id = %lu.", session_id);
version_ = version;
device_id_ = device_id;
session_id_ = session_id;
job_id_ = job_id;
var_resource_ = std::unique_ptr<VarResource>(new (std::nothrow) VarResource(session_id_));
if (var_resource_ == nullptr) {
GELOGW("VarManager has not been init.");
return ge::INTERNAL_ERROR;
version_ = version;
device_id_ = device_id;
session_id_ = session_id;
job_id_ = job_id;
var_resource_ = std::unique_ptr<VarResource>(new (std::nothrow) VarResource(session_id_));
if (var_resource_ == nullptr) {
GELOGW("VarManager init failed session id = %lu.", session_id);
return ge::INTERNAL_ERROR;
}
} else {
GELOGW("VarManager::has been inited, session id = %lu.", session_id);
}
return SUCCESS;
}


+ 1
- 1
ge/graph/optimize/common/params.h View File

@@ -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



+ 2
- 0
ge/graph/partition/dynamic_shape_partition.cc View File

@@ -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_ << ")(";


+ 4
- 3
ge/graph/passes/cast_translate_pass.cc View File

@@ -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;
}
}


+ 1
- 1
ge/graph/passes/cast_translate_pass.h View File

@@ -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_

+ 4
- 9
ge/graph/passes/compile_nodes_pass.cc View File

@@ -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;


+ 1
- 1
ge/graph/passes/compile_nodes_pass.h View File

@@ -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);
};


+ 2
- 1
ge/graph/passes/cond_remove_pass.cc View File

@@ -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;
}



+ 2
- 2
ge/graph/passes/dimension_adjust_pass.cc View File

@@ -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;
}



+ 12
- 12
ge/graph/passes/flow_ctrl_pass.cc View File

@@ -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.graph is [%s]", compute_graph->GetName().c_str());
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()) {
@@ -87,7 +87,7 @@ Status FlowCtrlPass::Run(ComputeGraphPtr compute_graph) {
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());
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");
@@ -347,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) {
@@ -370,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");
@@ -401,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
@@ -477,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());
@@ -498,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) {
@@ -506,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) {
@@ -529,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);
@@ -542,7 +542,7 @@ 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);


+ 2
- 0
ge/graph/passes/net_output_pass.cc View File

@@ -555,6 +555,8 @@ void NetOutputPass::AddInOutForNetOutputOp(const ComputeGraphPtr &graph, OpDescP
return;
}
ge::GeTensorDesc out_desc = src_node->GetOpDesc()->GetOutputDesc(src_index);
out_desc.SetFormat(FORMAT_ND);
out_desc.SetOriginFormat(FORMAT_ND);
GE_IF_BOOL_EXEC(net_output_desc->AddInputDesc(out_desc) != SUCCESS, GELOGW("add input desc failed"); return );
is_input_const.push_back(PassUtils::IsConstant(src_node));
++iter;


+ 1
- 1
ge/graph/passes/replace_with_empty_const_pass.cc View File

@@ -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;
}


+ 5
- 4
ge/graph/passes/resource_pair_add_control_pass.cc View File

@@ -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);


+ 5
- 4
ge/graph/passes/resource_pair_remove_control_pass.cc View File

@@ -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);


+ 1
- 1
ge/graph/passes/same_transdata_breadth_fusion_pass.cc View File

@@ -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) {


+ 0
- 8
ge/graph/passes/subexpression_migration_pass.cc View File

@@ -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;
}



+ 7
- 5
ge/graph/passes/transpose_transdata_pass.cc View File

@@ -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;
}
}


+ 2
- 2
ge/graph/passes/transpose_transdata_pass.h View File

@@ -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_


+ 25
- 20
ge/graph/preprocess/graph_preprocess.cc View File

@@ -23,6 +23,7 @@
#include "common/formats/format_transfers/format_transfer_nhwc_nc1hwc0.h"
#include "common/formats/format_transfers/format_transfer_transpose.h"
#include "common/formats/utils/formats_trans_utils.h"
#include "common/util/error_manager/error_manager.h"
#include "common/helper/model_helper.h"
#include "common/math/math_util.h"
#include "common/op/ge_op_utils.h"
@@ -1304,7 +1305,8 @@ Status GraphPrepare::UpdateInput(const std::vector<GeTensor> &user_input,
auto format = desc.GetFormat();
auto origin_format = desc.GetOriginFormat();
// data maybe internal format [FRACTAL_NZ] at singleop process such as GEMM.
bool need_check_internal_format = (!IsTansDataOpData(input_node)) && (!options_.is_single_op);
auto tune_flag = (options_.build_mode == BUILD_MODE_TUNING) && (options_.build_step == BUILD_STEP_AFTER_BUILDER);
bool need_check_internal_format = (!IsTansDataOpData(input_node)) && (!options_.is_single_op) && (!tune_flag);
if (need_check_internal_format) {
bool is_internal = TypeUtils::IsInternalFormat(format) || TypeUtils::IsInternalFormat(origin_format);
if (is_internal) {
@@ -1346,19 +1348,22 @@ Status GraphPrepare::UpdateInput(const std::vector<GeTensor> &user_input,
return FAILED;
}
ge::TensorUtils::SetSize(desc, shape_size);
graphStatus graph_ret = op->UpdateInputDesc(0, desc);
if (graph_ret != GRAPH_SUCCESS) {
GELOGE(graph_ret, "UpdateInputDesc fail, graph_ret:%u", graph_ret);
return graph_ret;
}
// Size will be recalculated in the build stage
ge::TensorUtils::SetSize(desc, 0);
graph_ret = op->UpdateOutputDesc(0, desc);
if (graph_ret != GRAPH_SUCCESS) {
GELOGE(graph_ret, "UpdateOutputDesc fail, graph_ret:%u", graph_ret);
return graph_ret;
if (!tune_flag) {
graphStatus graph_ret = op->UpdateInputDesc(0, desc);
if (graph_ret != GRAPH_SUCCESS) {
GELOGE(graph_ret, "UpdateInputDesc fail, graph_ret:%u", graph_ret);
return graph_ret;
}
// Size will be recalculated in the build stage
ge::TensorUtils::SetSize(desc, 0);
graph_ret = op->UpdateOutputDesc(0, desc);
if (graph_ret != GRAPH_SUCCESS) {
GELOGE(graph_ret, "UpdateOutputDesc fail, graph_ret:%u", graph_ret);
return graph_ret;
}
} else {
GELOGI("data %s skip update info in tune mode", op->GetName().c_str());
}

if (!dynamic_shape_range_vec.empty()) {
ret = UpdateDynamicInputShapeRange(index, dynamic_shape_range_vec, op, desc);
GE_CHK_STATUS_RET(ret, "Fail to update dynamic input shape range on %s.", op->GetName().c_str());
@@ -1763,13 +1768,13 @@ Status GraphPrepare::CheckUserInput(const std::vector<GeTensor> &user_input) {
GeTensorDesc desc(user_input[index].GetTensorDesc());

for (size_t i = 0; i < desc.GetShape().GetDimNum(); ++i) {
if (desc.GetShape().GetDim(i) < 0) {
std::string situation = "data dim[" + std::to_string(i) + "][" +
std::to_string(desc.GetShape().GetDim(i)) + "]" ;
std::string reason = "it need >= 0";
ErrorManager::GetInstance().ATCReportErrMessage("E19025", {"situation", "reason"}, {situation, reason});
GELOGE(GE_GRAPH_INIT_FAILED, "data dim %zu is not supported, need >= 0, real:%ld.", i,
desc.GetShape().GetDim(i));
int64_t dim = desc.GetShape().GetDim(i);
if (dim < UNKNOWN_DIM_NUM) {
std::string situation = "data dim[" + std::to_string(i) + "][" + std::to_string(dim) + "]" ;
std::string reason = "it need >= -2";
REPORT_INPUT_ERROR(
"E19025", std::vector<std::string>({"situation", "reason"}),std::vector<std::string>({situation, reason}));
GELOGE(GE_GRAPH_INIT_FAILED, "[Check][InputDim]data dim %zu is not supported, need >= -2, real:%ld.", i, dim);
return GE_GRAPH_INIT_FAILED;
}
}


+ 1
- 1
ge/graph/preprocess/graph_preprocess.h View File

@@ -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"


+ 1
- 1
ge/graph/preprocess/multi_batch_copy_graph.cc View File

@@ -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;
}


+ 6
- 6
ge/host_kernels/concat_offset_kernel.cc View File

@@ -33,7 +33,7 @@ const int kNumOne = 1;
} // namespace
Status ConcatOffsetKernel::Compute(const OpDescPtr op_desc_ptr, const vector<ConstGeTensorPtr> &input,
vector<GeTensorPtr> &v_output) {
GELOGI("ConcatOffsetKernel in.");
GELOGD("ConcatOffsetKernel in");
if (op_desc_ptr == nullptr) {
GELOGE(PARAM_INVALID, "input opdesc is nullptr.");
return PARAM_INVALID;
@@ -41,7 +41,7 @@ Status ConcatOffsetKernel::Compute(const OpDescPtr op_desc_ptr, const vector<Con
// validate attrs
int N = 0;
if (!(AttrUtils::GetInt(op_desc_ptr, "N", N))) {
GELOGW("Attr %s does not exist.", "N");
GELOGW("Attr %s does not exist", "N");
return NOT_CHANGED;
}
// follow IR def, the first input is concat_dim
@@ -50,7 +50,7 @@ Status ConcatOffsetKernel::Compute(const OpDescPtr op_desc_ptr, const vector<Con
int32_t concat_dim = *(const_cast<int32_t *>(reinterpret_cast<const int32_t *>(input_0->GetData().data())));
// validate inputs
if ((static_cast<int>(input.size()) != (N + kNumOne)) || (input.size() <= kConcatOffsetInputIndexOne)) {
GELOGW("The number of input for concat offset must be equal to %d, and must be more than one.", (N + kNumOne));
GELOGW("The number of input for concat offset must be equal to %d, and must be more than one", (N + kNumOne));
return NOT_CHANGED;
}

@@ -61,7 +61,7 @@ Status ConcatOffsetKernel::Compute(const OpDescPtr op_desc_ptr, const vector<Con
GELOGW("Concat dim is bigger than the size of output_shape.");
return NOT_CHANGED;
}
GELOGI("Output shape size is %ld", output_size);
GELOGI("Output shape size is %ld.", output_size);
int32_t offset = 0;
if (output_size < 0) {
GELOGE(FAILED, "Index is negative.");
@@ -86,7 +86,7 @@ Status ConcatOffsetKernel::Compute(const OpDescPtr op_desc_ptr, const vector<Con
output_ptr->MutableTensorDesc().SetShape(output_shape);
GE_IF_BOOL_EXEC(output_ptr->SetData(reinterpret_cast<uint8_t *>(buf.get()),
static_cast<size_t>(sizeof(DT_INT32) * output_size)) != GRAPH_SUCCESS,
GELOGW("set data failed");
GELOGW("set data failed.");
return NOT_CHANGED);
v_output.push_back(output_ptr);
// caculate offset
@@ -99,7 +99,7 @@ Status ConcatOffsetKernel::Compute(const OpDescPtr op_desc_ptr, const vector<Con
}
offset += input_dim;
}
GELOGI("ConcatOffsetKernel success.");
GELOGD("ConcatOffsetKernel success");
return SUCCESS;
}
REGISTER_KERNEL(CONCATOFFSET, ConcatOffsetKernel);


+ 3
- 2
ge/host_kernels/dynamic_stitch_kernel.cc View File

@@ -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]);


+ 14
- 14
ge/host_kernels/gather_v2_kernel.cc View File

@@ -278,7 +278,7 @@ Status GatherV2Kernel::SaveIndicesByDataType(ConstGeTensorPtr indices_tensor_ptr
auto indices_ptr = const_cast<int32_t *>(reinterpret_cast<const int32_t *>(indices_tensor_ptr->GetData().data()));
for (int64_t i = 0; i < indices_shape.GetShapeSize(); i++) {
if (*(indices_ptr + i) < 0 || *(indices_ptr + i) >= x_shape.GetDim(axis)) {
GELOGW("indices %ld value is not in range [0, %ld)", i, x_shape.GetDim(axis));
GELOGW("indices %ld value is not in range [0, %ld).", i, x_shape.GetDim(axis));
return NOT_CHANGED;
}
indicates_.push_back(*(indices_ptr + i));
@@ -288,7 +288,7 @@ Status GatherV2Kernel::SaveIndicesByDataType(ConstGeTensorPtr indices_tensor_ptr
auto indices_ptr = const_cast<int64_t *>(reinterpret_cast<const int64_t *>(indices_tensor_ptr->GetData().data()));
for (int64_t i = 0; i < indices_shape.GetShapeSize(); i++) {
if (*(indices_ptr + i) < 0 || *(indices_ptr + i) >= x_shape.GetDim(axis)) {
GELOGW("indices %ld value is not in range [0, %ld)", i, x_shape.GetDim(axis));
GELOGW("indices %ld value is not in range [0, %ld).", i, x_shape.GetDim(axis));
return NOT_CHANGED;
}
indicates_.push_back(*(indices_ptr + i));
@@ -344,42 +344,42 @@ Status GatherV2Kernel::Check(const OpDescPtr &op_desc_ptr, const vector<ConstGeT
auto indices_data_type = tensor1->GetTensorDesc().GetDataType();
bool is_valid_indices_data_type = indices_data_type == DT_INT32 || indices_data_type == DT_INT64;
if (!is_valid_indices_data_type) {
GELOGW("indices datatype must be DT_INT32 or DT_INT64");
GELOGW("indices datatype must be DT_INT32 or DT_INT64.");
return NOT_CHANGED;
}
if (indices_shape.GetDimNum() > kMaxIndicatesDims) {
GELOGW("indices input only support 0 or 1 dims");
GELOGW("indices input only support 0 or 1 dims.");
return NOT_CHANGED;
}
return SUCCESS;
}
void GatherV2Kernel::DebugPrint(int64_t axis, const GeShape &x_shape, const GeShape &indices_shape,
const std::vector<int64_t> &y_shape) {
GELOGD("GatherV2Kernel axis:%ld x_shape:%zu indices_shape:%zu y_shape:%zu", axis, x_shape.GetDimNum(),
GELOGD("GatherV2Kernel axis:%ld x_shape:%zu indices_shape:%zu y_shape:%zu.", axis, x_shape.GetDimNum(),
indices_shape.GetDimNum(), y_shape.size());
for (size_t i = 0; i < x_shape.GetDimNum(); i++) {
GELOGD("GatherV2Kernel x_shape[%zu]: %ld", i, x_shape.GetDim(i));
GELOGD("GatherV2Kernel x_shape[%zu]: %ld.", i, x_shape.GetDim(i));
}
for (size_t i = 0; i < indices_shape.GetDimNum(); i++) {
GELOGD("GatherV2Kernel indices_shape[%zu]: %ld", i, indices_shape.GetDim(i));
GELOGD("GatherV2Kernel indices_shape[%zu]: %ld.", i, indices_shape.GetDim(i));
}
for (size_t i = 0; i < y_shape.size(); i++) {
GELOGD("GatherV2Kernel y_shape[%zu]: %ld", i, y_shape[i]);
GELOGD("GatherV2Kernel y_shape[%zu]: %ld.", i, y_shape[i]);
}
for (auto ele : indicates_) {
GELOGD("GatherV2Kernel indices:%ld", ele);
GELOGD("GatherV2Kernel indices:%ld.", ele);
}
}

Status GatherV2Kernel::Compute(const OpDescPtr op_desc_ptr, const vector<ConstGeTensorPtr> &input,
vector<GeTensorPtr> &v_output) {
GELOGI("Enter GatherV2Kernel Process.");
GELOGI("Enter GatherV2Kernel Process");
Status ret = Check(op_desc_ptr, input, v_output);
if (ret != SUCCESS) {
GELOGW("param check failed.");
GELOGW("param check failed");
return NOT_CHANGED;
}
GELOGI("GatherV2Kernel[%s] start Process.", op_desc_ptr->GetName().c_str());
GELOGI("GatherV2Kernel[%s] start Process", op_desc_ptr->GetName().c_str());
ConstGeTensorPtr tensor0 = input.at(kGatherV2InputIndexZero);
ConstGeTensorPtr tensor1 = input.at(kGatherV2InputIndexOne);
ConstGeTensorPtr tensor2 = input.at(kGatherV2InputIndexTwo);
@@ -394,7 +394,7 @@ Status GatherV2Kernel::Compute(const OpDescPtr op_desc_ptr, const vector<ConstGe
axis = axis >= 0 ? axis : axis + x_shape.GetDimNum();
// check axis value
if (axis < 0 || (axis + 1) > static_cast<int64_t>(x_shape.GetDimNum())) {
GELOGW("axis is invalid");
GELOGW("axis is invalid!");
return NOT_CHANGED;
}
auto indices_data_type = tensor1->GetTensorDesc().GetDataType();
@@ -407,7 +407,7 @@ Status GatherV2Kernel::Compute(const OpDescPtr op_desc_ptr, const vector<ConstGe
// check input data type
auto x_data_type = tensor0->GetTensorDesc().GetDataType();
if (supported_type.find(x_data_type) == supported_type.end()) {
GELOGI("GatherV2Kernel does not support this Data type:%s", TypeUtils::DataTypeToSerialString(x_data_type).c_str());
GELOGI("GatherV2Kernel does not support this Data type:%s.", TypeUtils::DataTypeToSerialString(x_data_type).c_str());
return NOT_CHANGED;
}
// calc output shape


+ 1
- 0
ge/host_kernels/identity_kernel.cc View File

@@ -61,4 +61,5 @@ Status IdentityKernel::Compute(const ge::OpDescPtr op_desc, const std::vector<ge
return SUCCESS;
}
REGISTER_KERNEL(IDENTITY, IdentityKernel);
REGISTER_KERNEL(PLACEHOLDERWITHDEFAULT, IdentityKernel);
} // namespace ge

+ 37
- 1
ge/host_kernels/slice_kernel.cc View File

@@ -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();


+ 9
- 9
ge/host_kernels/strided_slice_kernel.cc View File

@@ -84,14 +84,14 @@ void GetOriginStrideVec(const std::vector<ge::ConstGeTensorPtr> &input, vector<i
} // namespace
Status StridedSliceKernel::Compute(const ge::OpDescPtr attr, const std::vector<ge::ConstGeTensorPtr> &input,
vector<ge::GeTensorPtr> &v_output) {
GELOGD("StridedSliceKernel in.");
GELOGD("StridedSliceKernel in");
// 1.Check input and attrs
if (CheckAndGetAttr(attr) != SUCCESS) {
GELOGW("Check and get attrs failed.Ignore kernel.");
GELOGW("Check and get attrs failed.Ignore kernel");
return NOT_CHANGED;
}
if (CheckInputParam(input) != SUCCESS) {
GELOGW("Check input params failed.Ignore kernel.");
GELOGW("Check input params failed.Ignore kernel");
return NOT_CHANGED;
}
// 2.Init param with mask attrs.
@@ -120,7 +120,7 @@ Status StridedSliceKernel::Compute(const ge::OpDescPtr attr, const std::vector<g
auto ret = OpUtils::SetOutputSliceData(data, static_cast<int64_t>(data_size), data_type, input_dims, begin_vec,
output_dims, output_ptr.get(), stride_vec);
if (ret != SUCCESS) {
GELOGE(INTERNAL_ERROR, "SetOutputSliceData failed.");
GELOGE(INTERNAL_ERROR, "SetOutputSliceData failed");
return NOT_CHANGED;
}

@@ -133,7 +133,7 @@ Status StridedSliceKernel::Compute(const ge::OpDescPtr attr, const std::vector<g
GetOutputDims(final_dim_size, output_dims, v_dims);
t_d.SetShape(GeShape(v_dims));
v_output.push_back(output_ptr);
GELOGI("StridedSliceKernel success.");
GELOGI("StridedSliceKernel success");
return SUCCESS;
}
Status StridedSliceKernel::CheckAndGetAttr(const OpDescPtr &attr) {
@@ -144,7 +144,7 @@ Status StridedSliceKernel::CheckAndGetAttr(const OpDescPtr &attr) {
// Get all op attr value of strided_slice
for (auto &attr_2_value : attr_value_map_) {
if (!AttrUtils::GetInt(attr, attr_2_value.first, attr_2_value.second)) {
GELOGE(PARAM_INVALID, "Get %s attr failed.", attr_2_value.first.c_str());
GELOGE(PARAM_INVALID, "Get %s attr failed", attr_2_value.first.c_str());
return PARAM_INVALID;
}
}
@@ -182,7 +182,7 @@ Status StridedSliceKernel::CheckInputParam(const std::vector<ConstGeTensorPtr> &
return PARAM_INVALID;
}
if (kIndexNumberType.find(begin_tensor_desc.GetDataType()) == kIndexNumberType.end()) {
GELOGW("Data type of StridedSlice OP(begin,end,strides) must be int32 or int64.");
GELOGW("Data type of StridedSlice OP(begin,end,strides) must be int32 or int64");
return PARAM_INVALID;
}

@@ -250,7 +250,7 @@ Status StridedSliceKernel::InitParamWithAttrs(const std::vector<ConstGeTensorPtr
end_i = x_dims.at(i);
stride_i = 1;
}
GELOGD("Before mask calculate. Begin is : %ld\t,end is : %ld\t stride is : %ld\t x_dim_i is : %ld.",
GELOGD("Before mask calculate. Begin is : %ld\t,end is : %ld\t stride is : %ld\t x_dim_i is : %ld",
begin_i, end_i, stride_i, x_dims.at(i));
auto ret = MaskCal(i, begin_i, end_i, x_dims.at(i));
if (ret != SUCCESS) {
@@ -258,7 +258,7 @@ Status StridedSliceKernel::InitParamWithAttrs(const std::vector<ConstGeTensorPtr
return NOT_CHANGED;
}
int64_t dim_final;
GELOGD("Before stride calculate. Begin is : %ld\t,end is : %ld\t stride is : %ld\t x_dim_i is : %ld.",
GELOGD("Before stride calculate. Begin is : %ld\t,end is : %ld\t stride is : %ld\t x_dim_i is : %ld",
begin_i, end_i, stride_i, x_dims.at(i));
(void) StrideCal(x_dims.at(i), begin_i, end_i, stride_i, dim_final);
output_dims.push_back(dim_final);


+ 56
- 22
ge/hybrid/executor/hybrid_model_async_executor.cc View File

@@ -29,7 +29,7 @@ const size_t kMinimumPiplineStages = 2;
const int kDefaultLoopCount = 10;
}
HybridModelAsyncExecutor::HybridModelAsyncExecutor(HybridModel *model)
: model_(model), run_flag_(false) {
: model_(model), run_flag_(false), data_dumper_(nullptr) {
}

HybridModelAsyncExecutor::~HybridModelAsyncExecutor() {
@@ -46,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_);
@@ -81,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;
@@ -97,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) {
@@ -251,7 +260,8 @@ Status HybridModelAsyncExecutor::PrepareInputs(const InputData &current_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;
@@ -434,31 +444,20 @@ Status HybridModelAsyncExecutor::Execute(const std::vector<DataBuffer> &inputs,
TensorValue tensor_value(inputs[i].data, inputs[i].length);
args.inputs[i] = tensor_value;
}
for (size_t i = 0; i < outputs.size(); ++i) {
args.outputs.emplace_back(TensorValue(outputs[i].data, outputs[i].length));
}
// usr must designate input tensorDesc when input shape is dynamic in inference
for (size_t i = 0; i < input_desc.size(); ++i) {
ConstGeTensorDescPtr tensor_desc_ptr = MakeShared<GeTensorDesc>(input_desc[i]);
args.input_desc.emplace_back(tensor_desc_ptr);
}

GE_CHK_STATUS_RET(executor_->Execute(args), "Failed to execute model.");
for (const auto &output_tensor_desc : args.output_desc) {
output_desc.emplace_back(*output_tensor_desc);
}

for (size_t i = 0; i < args.outputs.size(); ++i) {
int64_t output_real_size = 0;
ge::graphStatus graph_status = TensorUtils::GetTensorSizeInBytes(output_desc[i], output_real_size);
if (graph_status != GRAPH_SUCCESS) {
GELOGE(FAILED, "Get tensor size in bytes failed.");
return FAILED;
}
if (output_real_size > 0) {
if (outputs[i].length < static_cast<uint64_t>(output_real_size)) {
GELOGE(FAILED, "output idx[%zu], the memory size of output[%lu] given by "
"user should be greater than or equal to the real size of output[%ld]",
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));
}
outputs[i].length = output_real_size;
}

return SUCCESS;
}

@@ -503,5 +502,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

+ 10
- 0
ge/hybrid/executor/hybrid_model_async_executor.h View File

@@ -21,7 +21,9 @@
#include <future>
#include "external/ge/ge_api_error_codes.h"
#include "external/ge/ge_api_types.h"
#include "common/dump/opdebug_register.h"
#include "graph/load/model_manager/data_inputer.h"
#include "graph/load/model_manager/data_dumper.h"
#include "hybrid/executor/hybrid_model_executor.h"
#include "hybrid/executor/hybrid_model_pipeline_executor.h"
#include "runtime/stream.h"
@@ -49,6 +51,8 @@ class HybridModelAsyncExecutor {

void SetModelId(uint32_t model_id);

void SetModelName(const string &model_name);

Status Stop();

Status EnqueueData(const std::shared_ptr<InputDataWrapper> &data);
@@ -75,6 +79,8 @@ class HybridModelAsyncExecutor {

Status PrepareInputs(const InputData &current_data, HybridModelExecutor::ExecuteArgs &args);

Status DumpOpDebug();

std::mutex mu_;
HybridModel *model_;
uint32_t device_id_ = 0U;
@@ -91,6 +97,10 @@ class HybridModelAsyncExecutor {
std::map<uint32_t, GeTensorDescPtr> input_tensor_desc_;
std::vector<bool> is_input_dynamic_;
std::shared_ptr<ModelListener> listener_;
string om_name_;
DataDumper data_dumper_;
bool is_op_debug_reg_ = false;
OpdebugRegister op_debug_register_;
};
} // namespace hybrid
} // namespace ge


+ 2
- 1
ge/hybrid/executor/hybrid_model_executor.cc View File

@@ -17,6 +17,7 @@
#include "hybrid_model_executor.h"
#include "graph/ge_context.h"
#include "graph/runtime_inference_context.h"
#include "common/dump/dump_manager.h"

namespace ge {
namespace hybrid {
@@ -107,7 +108,7 @@ Status HybridModelExecutor::InitExecutionContext() {
GE_CHECK_NOTNULL(context_.allocator);
context_.callback_manager = std::unique_ptr<CallbackManager>(new(std::nothrow)CallbackManager());
GE_CHECK_NOTNULL(context_.callback_manager);
context_.dump_properties = PropertiesManager::Instance().GetDumpProperties(context_.session_id);
context_.dump_properties = DumpManager::GetInstance().GetDumpProperties(context_.session_id);
const char *profiling_level = std::getenv(kEnvProfilingLevel);
if (profiling_level != nullptr) {
context_.profiling_level = std::strtol(profiling_level, nullptr, kIntBase);


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save