From 65b1958f4329599159f50484ffab23264096e8c7 Mon Sep 17 00:00:00 2001 From: guopeian Date: Tue, 21 Nov 2023 16:46:02 +0800 Subject: [PATCH 1/4] addAscendString --- tf_adapter/kernels/aicpu/dataset_function.cc | 11 ++++---- tf_adapter/kernels/geop_npu.cc | 22 ++++++++------- tf_adapter/kernels/geop_npu.h | 4 +-- .../depends/ge_runner/src/ge_runner_stub.cc | 28 +++++++++---------- tf_adapter/util/ge_plugin.cc | 9 ++++-- tf_adapter/util/npu_attrs.cc | 10 +++++++ tf_adapter/util/npu_attrs.h | 3 ++ tf_adapter/util/session_manager.cc | 3 +- tf_adapter_2.x/npu_device/core/npu_device.cpp | 18 ++++++------ tf_adapter_2.x/npu_device/core/npu_utils.cpp | 14 ++++++++-- tf_adapter_2.x/npu_device/core/npu_utils.h | 7 +++-- .../npu_device/core/npu_wrapper.cpp | 4 ++- tf_adapter_2.x/tests/stub/ge_stub.cpp | 4 +-- .../framework/omg/parser/model_parser.h | 8 +++--- .../include/framework/omg/parser/parser_api.h | 2 +- tf_adapter_2.x/tests/stub/include/ge/ge_api.h | 4 +-- .../tests/stub/include/stub/defines.h | 2 +- tf_adapter_2.x/tests/stub/parser_stub.cpp | 18 ++++++------ 18 files changed, 104 insertions(+), 67 deletions(-) diff --git a/tf_adapter/kernels/aicpu/dataset_function.cc b/tf_adapter/kernels/aicpu/dataset_function.cc index 484f5d032..8b137b636 100644 --- a/tf_adapter/kernels/aicpu/dataset_function.cc +++ b/tf_adapter/kernels/aicpu/dataset_function.cc @@ -918,10 +918,10 @@ Status DatasetFunction::CreateGeGraph(const std::shared_ptr & ge::ComputeGraphPtr compute_graph = std::make_shared(funcName_); DATASET_REQUIRES(model_parser != nullptr, errors::Internal("Create compute graph failed.")); - auto build_sub_graph = [this, &flib_def](const std::string &graph_name) -> std::string { + auto build_sub_graph = [this, &flib_def](const ge::AscendString &graph_name) -> ge::AscendString { Graph sub_graph(&flib_def); - TF_CHECK_OK(this->BuildSubGraph(flib_def, sub_graph, graph_name)); - return this->SerializeGraph(sub_graph); + TF_CHECK_OK(this->BuildSubGraph(flib_def, sub_graph, graph_name.GetString())); + return ge::AscendString(this->SerializeGraph(sub_graph).c_str()); }; std::string graph_def; @@ -939,7 +939,7 @@ Status DatasetFunction::CreateGeGraph(const std::shared_ptr & run_split_graph_ = true; } - ge::Status ge_status = model_parser->ParseProtoWithSubgraph(graph_def, build_sub_graph, compute_graph); + ge::Status ge_status = model_parser->ParseProtoWithSubgraph(ge::AscendString(graph_def), build_sub_graph, compute_graph); DATASET_REQUIRES(ge_status == ge::SUCCESS, GeError("Parse proto with graph failed.", ge_status)); // add performance priority tag for each node @@ -1054,7 +1054,8 @@ Status DatasetFunction::Initialize(const std::map &ses [&model_parser](const DataType type) { return model_parser->ConvertToGeDataType(static_cast(type)); }); LogOptions(session_options); - ge_session_.reset(new (std::nothrow)ge::Session(session_options)); + const auto session_options_ascend_string = ChangeStringToAscendString(session_options); + ge_session_.reset(new (std::nothrow)ge::Session(session_options_ascend_string)); Status status = InitGeGraph(flib_def); DATASET_REQUIRES(status.ok(), status); diff --git a/tf_adapter/kernels/geop_npu.cc b/tf_adapter/kernels/geop_npu.cc index 4ab462178..41533f65c 100644 --- a/tf_adapter/kernels/geop_npu.cc +++ b/tf_adapter/kernels/geop_npu.cc @@ -1027,15 +1027,16 @@ Status GeOp::DoGraphParser(ge::ComputeGraphPtr &compute_graph, FunctionLibraryDe domi::ModelParserFactory::Instance()->CreateModelParser(domi::FrameworkType::TENSORFLOW); REQUIRES_NOT_NULL(model_parser); - std::map const_value_map; - std::vector partition_graph; + std::map const_value_map; + std::vector partition_graph; auto tf_status = SeparateGraphDef(ori_graph_def, partition_graph, const_value_map); if (!tf_status.ok()) { return tf_status; } - auto build_sub_graph = [this, flib_def](const std::string &graph) -> std::string { - return this->BuildSubGraph(flib_def, graph); + auto build_sub_graph = [this, flib_def](const ge::AscendString &graph) -> ge::AscendString { + return ge::AscendString(this->BuildSubGraph(flib_def, graph.GetString()).c_str()); }; + ge::Status status = model_parser->ParseProtoWithSubgraph(partition_graph, const_value_map, build_sub_graph, compute_graph); if (status != ge::SUCCESS) { @@ -1263,7 +1264,8 @@ void GeOp::ComputeAsync(OpKernelContext *ctx, DoneCallback done) { ADP_LOG(EVENT) << "[GEOP] call ge session add graph jit_compile: " << jit_compile_; graph_options["ge.exec.graphIOMemAllocMode"] = "ByGE"; OP_REQUIRES_OK_ASYNC(ctx, CreateGeSession(), done); - auto status = ge_session_->AddGraph(cache_graph_id, ge_graph, graph_options); + auto const graph_option_ascend_string = ChangeStringToAscendString(graph_options); + auto status = ge_session_->AddGraph(cache_graph_id, ge_graph, graph_option_ascend_string); std::stringstream ss; if (status != ge::SUCCESS) { std::this_thread::sleep_for(std::chrono::milliseconds(kFatalSleepTime)); @@ -1739,11 +1741,11 @@ Status GeOp::BuildGraphDef(FunctionLibraryDefinition &flib_def, const std::vecto } Status GeOp::SeparateGraphDef(GraphDef &ori_graph_def, - std::vector &partition_graph, - std::map &const_value_map) { + std::vector &partition_graph, + std::map &const_value_map) { std::string graph_def_str = ori_graph_def.SerializeAsString(); if (!graph_def_str.empty()) { - partition_graph.push_back(graph_def_str); + partition_graph.push_back(ge::AscendString(graph_def_str.c_str())); return Status::OK(); } LOG(INFO) << "GraphDef is beyond 2G, which is need separate weight from model"; @@ -1758,12 +1760,12 @@ Status GeOp::SeparateGraphDef(GraphDef &ori_graph_def, } TensorProto *tensor = iter->second.mutable_tensor(); std::string tensor_content = tensor->tensor_content(); - const_value_map.insert({node_name, tensor_content}); + const_value_map.insert({ge::AscendString(node_name.c_str()), ge::AscendString(tensor_content.c_str())}); tensor->set_tensor_content(""); } } graph_def_str = ori_graph_def.SerializeAsString(); - partition_graph.push_back(graph_def_str); + partition_graph.push_back(ge::AscendString(graph_def_str.c_str())); return Status::OK(); } diff --git a/tf_adapter/kernels/geop_npu.h b/tf_adapter/kernels/geop_npu.h index c85be81bf..86bd5f317 100644 --- a/tf_adapter/kernels/geop_npu.h +++ b/tf_adapter/kernels/geop_npu.h @@ -81,8 +81,8 @@ public: Status BuildGraphDef(FunctionLibraryDefinition &flib_def, const std::vector &input_vec, GraphDef &graph_def, bool &is_initialize, bool &is_allreduce); Status SeparateGraphDef(GraphDef &ori_graph_def, - std::vector &partition_graph, - std::map &const_value_map); + std::vector &partition_graph, + std::map &const_value_map); // Analyze sting input data Status AnalyzeStringInput(ge::Tensor &input, uint64_t count, const std::string *string_vector) const; diff --git a/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc b/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc index dc2bed154..b8d658727 100644 --- a/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc +++ b/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc @@ -109,12 +109,12 @@ class TensorFlowModelParser : public domi::ModelParser { Status ParseProtoWithSubgraph(const google::protobuf::Message *proto, domi::GetGraphCallback callback, ge::ComputeGraphPtr &graph) override; - Status ParseProtoWithSubgraph(const std::string &serialized_proto, domi::GetGraphCallbackV2 callback, + Status ParseProtoWithSubgraph(const ge::AscendString &serialized_proto, domi::GetGraphCallbackV3 callback, ge::ComputeGraphPtr &graph) override; - Status ParseProtoWithSubgraph(const std::vector &partitioned_serialized, - const std::map &const_value_map, - domi::GetGraphCallbackV2 callback, + Status ParseProtoWithSubgraph(const std::vector &partitioned_serialized, + const std::map &const_value_map, + domi::GetGraphCallbackV3 callback, ge::ComputeGraphPtr &graph) override; ge::DataType ConvertToGeDataType(const uint32_t type) override; @@ -138,11 +138,11 @@ Status TensorFlowModelParser::ToJson(const char *model_file, const char *json_fi Status TensorFlowModelParser::ParseProto(const google::protobuf::Message *proto, ge::ComputeGraphPtr &graph) { return ge::SUCCESS; } -Status TensorFlowModelParser::ParseProtoWithSubgraph(const std::string &serialized_proto, - domi::GetGraphCallbackV2 callback, +Status TensorFlowModelParser::ParseProtoWithSubgraph(const ge::AscendString &serialized_proto, + domi::GetGraphCallbackV3 callback, ge::ComputeGraphPtr &graph) { - std::vector partitioned_serialized{serialized_proto}; - std::map const_value_map; + std::vector partitioned_serialized{serialized_proto}; + std::map const_value_map; return ParseProtoWithSubgraph(partitioned_serialized, const_value_map, callback, graph); } @@ -152,9 +152,9 @@ void SetParseRootGraph(bool is_root) { g_parse_root_graph = is_root; } -Status TensorFlowModelParser::ParseProtoWithSubgraph(const std::vector &partitioned_serialized, - const std::map &const_value_map, - domi::GetGraphCallbackV2 callback, +Status TensorFlowModelParser::ParseProtoWithSubgraph(const std::vector &partitioned_serialized, + const std::map &const_value_map, + domi::GetGraphCallbackV3 callback, ge::ComputeGraphPtr &graph) { if (!g_parse_root_graph) { callback("finall_branch1_Y3CNZMF9Vv8"); @@ -200,7 +200,7 @@ GE_FUNC_VISIBILITY Status GetVarBaseAddrAndSize(const std::string &var_name, uin return ge::SUCCESS; } -GE_FUNC_VISIBILITY Status GEInitialize(const std::map &options) { +GE_FUNC_VISIBILITY Status GEInitialize(const std::map &options) { if (options.empty()) { return ge::FAILED; } @@ -218,7 +218,7 @@ GE_FUNC_VISIBILITY Status GEFinalize() { return ge::SUCCESS; } -Status ParserInitialize(const std::map &options) { +Status ParserInitialize(const std::map &options) { if (options.empty()) { return ge::FAILED; } @@ -258,7 +258,7 @@ bool Session::IsGraphNeedRebuild(uint32_t graphId) { return true; } -Status Session::AddGraph(uint32_t graphId, const Graph &graph, const std::map &options) { +Status Session::AddGraph(uint32_t graphId, const Graph &graph, const std::map &options) { auto ret = graphs_map.find(graphId); if (ret != graphs_map.end()) { return ge::FAILED; diff --git a/tf_adapter/util/ge_plugin.cc b/tf_adapter/util/ge_plugin.cc index 34da1924f..9d0659831 100644 --- a/tf_adapter/util/ge_plugin.cc +++ b/tf_adapter/util/ge_plugin.cc @@ -305,7 +305,8 @@ void GePlugin::Init(std::map &init_options, const bool init_options["ge.optionNameMap"] = option_name_map.dump(); // parser Initialize - ge::Status status_parser = ge::ParserInitialize(init_options); + auto const init_options_ascend_string = ChangeStringToAscendString(init_options); + ge::Status status_parser = ge::ParserInitialize(init_options_ascend_string); if (status_parser != ge::SUCCESS) { std::this_thread::sleep_for(std::chrono::milliseconds(kFatalSleepTime)); ADP_LOG(FATAL) << "[GePlugin] Initialize parser failed, ret : " << ToString(status_parser); @@ -320,14 +321,16 @@ void GePlugin::Init(std::map &init_options, const bool future_ = std::async( std::launch::async, [this](const std::map &init_options) -> ge::Status { - const auto ret = ge::GEInitialize(init_options); + const auto init_ascend_string_options = ChangeStringToAscendString(init_options); + const auto ret = ge::GEInitialize(init_ascend_string_options); error_message_ = ge::GEGetErrorMsg(); return ret; }, init_options) .share(); } else { - ge::Status status = ge::GEInitialize(init_options); + const auto init_ascend_string_options = ChangeStringToAscendString(init_options); + ge::Status status = ge::GEInitialize(init_ascend_string_options); if (status != ge::SUCCESS) { std::this_thread::sleep_for(std::chrono::milliseconds(kFatalSleepTime)); ADP_LOG(FATAL) << "[GePlugin] Initialize ge failed, ret : " << ToString(status); diff --git a/tf_adapter/util/npu_attrs.cc b/tf_adapter/util/npu_attrs.cc index 03d1f71f1..85614a722 100644 --- a/tf_adapter/util/npu_attrs.cc +++ b/tf_adapter/util/npu_attrs.cc @@ -107,6 +107,16 @@ extern const bool kIsHeterogeneous = []() -> bool { return is_heterogeneous == kRuntimeTypeHeterogeneous; }(); +std::map ChangeStringToAscendString( + const std::map &string_map) { + std::map ascend_string_map; + for (const auto &string_pair : string_map) { + ascend_string_map.emplace(std::make_pair(ge::AscendString(string_pair.first.c_str()), + ge::AscendString(string_pair.second.c_str()))); + } + return ascend_string_map; +} + std::string GetDumpPath() { std::string npu_collect_path; (void) ReadStringFromEnvVar("NPU_COLLECT_PATH", "", &npu_collect_path); diff --git a/tf_adapter/util/npu_attrs.h b/tf_adapter/util/npu_attrs.h index 1c43ce4cf..af79b632f 100644 --- a/tf_adapter/util/npu_attrs.h +++ b/tf_adapter/util/npu_attrs.h @@ -24,6 +24,7 @@ #include #include #include "ge/ge_api_types.h" +#include "graph/ascend_string.h" #include "tensorflow/core/common_runtime/optimization_registry.h" #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/graph/graph.h" @@ -39,6 +40,8 @@ Status GetDeviceID(uint32_t &device_id); Status GetStepFromEnv(const std::string &env_name, uint32_t &step); Status GetLossFromEnv(const std::string &env_name, float &loss); void Split(const std::string &s, std::vector &result, const char *delchar = " "); +std::map ChangeStringToAscendString( + const std::map &string_map); extern const bool kDumpGraph; extern const bool kIsHeterogeneous; diff --git a/tf_adapter/util/session_manager.cc b/tf_adapter/util/session_manager.cc index b5b280377..781ff0181 100644 --- a/tf_adapter/util/session_manager.cc +++ b/tf_adapter/util/session_manager.cc @@ -84,7 +84,8 @@ bool SessionManager::CreateGeSession(const std::string &tf_session, ge::Session // stream max parallel num ADP_LOG(INFO) << "[GEOP] stream_max_parallel_num :" << sess_options[ge::STREAM_MAX_PARALLEL_NUM]; - ge_session = new (std::nothrow) ge::Session(sess_options); + const auto sess_options_ascend_string = ChangeStringToAscendString(sess_options); + ge_session = new (std::nothrow) ge::Session(sess_options_ascend_string); if (ge_session == nullptr) { ADP_LOG(ERROR) << "tf session " << tf_session << " create ge session failed."; LOG(ERROR) << "tf session " << tf_session << " create ge session failed."; diff --git a/tf_adapter_2.x/npu_device/core/npu_device.cpp b/tf_adapter_2.x/npu_device/core/npu_device.cpp index f95312c1f..e434857a6 100644 --- a/tf_adapter_2.x/npu_device/core/npu_device.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_device.cpp @@ -206,7 +206,8 @@ void NpuDevice::EraseIteratorProvider(const TFE_Context *const context, const te */ std::string NpuDevice::CreateDevice(const char *name, int device_index, const std::map &options, NpuDevice **device) { - auto *ge_session = new (std::nothrow) ge::Session(options); + const auto options_ascend_string = StringToAscendString(options); + auto *ge_session = new (std::nothrow) ge::Session(options_ascend_string); if (ge_session == nullptr) { return "Failed init graph engine: create new session failed"; } @@ -978,6 +979,7 @@ uint64_t NpuDevice::AddGeGraphInner(TFE_Context *context, uint64_t graph_id, con } } options["ge.exec.graphIOMemAllocMode"] = "ByGE"; + const auto options_ascend_string = StringToAscendString(options); NPU_CTX_REQUIRES_GE_OK_RETURN(status, "Graph engine Add graph", GeSession()->AddGraph(graph_id, ge_graph, options), graph_id); return graph_id; @@ -990,10 +992,10 @@ tensorflow::Status NpuDevice::TransTfGraph2GeGraph(TFE_Context *context, const s domi::ModelParserFactory::Instance()->CreateModelParser(domi::FrameworkType::TENSORFLOW); NPU_REQUIRES(parser != nullptr, tensorflow::errors::Internal("NPU Create new tensorflow model parser failed")); - auto request_subgraph = [name, context](const std::string &fn) -> std::string { - DLOG() << "Tensorflow model parser requesting subgraph " << fn << " for ge graph " << name; + auto request_subgraph = [name, context](const ge::AscendString &fn) -> ge::AscendString { + DLOG() << "Tensorflow model parser requesting subgraph " << fn.GetString() << " for ge graph " << name; tensorflow::FunctionLibraryDefinition *lib_def = npu::UnwrapCtx(context)->FuncLibDef(); - const tensorflow::FunctionDef *fdef = lib_def->Find(fn); + const tensorflow::FunctionDef *fdef = lib_def->Find(fn.GetString()); if (fdef == nullptr) { return ""; } @@ -1016,13 +1018,13 @@ tensorflow::Status NpuDevice::TransTfGraph2GeGraph(TFE_Context *context, const s AssembleParserAddons(context, graph.get()); if (kDumpExecutionDetail || kDumpGraph) { - WriteTextProto(tensorflow::Env::Default(), name + "_subgraph_" + fn + ".pbtxt", graph->ToGraphDefDebug()); + WriteTextProto(tensorflow::Env::Default(), name + "_subgraph_" + fn.GetString() + ".pbtxt", graph->ToGraphDefDebug()); } - return graph->ToGraphDefDebug().SerializeAsString(); + return ge::AscendString(graph->ToGraphDefDebug().SerializeAsString().c_str()); }; - std::map const_value_map; - std::vector partition_graph; + std::map const_value_map; + std::vector partition_graph; NPU_REQUIRES_OK(SeparateGraphDef(const_cast(&def), partition_graph, const_value_map)); NPU_REQUIRES( parser->ParseProtoWithSubgraph(partition_graph, const_value_map, request_subgraph, ge_compute_graph) == ge::SUCCESS, diff --git a/tf_adapter_2.x/npu_device/core/npu_utils.cpp b/tf_adapter_2.x/npu_device/core/npu_utils.cpp index dd958cd7c..5fdffa00b 100644 --- a/tf_adapter_2.x/npu_device/core/npu_utils.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_utils.cpp @@ -510,8 +510,8 @@ void NpuCustomizedOptimizeGraph(tensorflow::FunctionLibraryRuntime &lib, std::un } tensorflow::Status SeparateGraphDef(tensorflow::GraphDef *def, - std::vector &partition_graph, - std::map &const_value_map) { + std::vector &partition_graph, + std::map &const_value_map) { std::string def_str = def->SerializeAsString(); if (!def_str.empty()) { partition_graph.push_back(def_str); @@ -558,6 +558,16 @@ tensorflow::Status LoopCopy(char *dst_ptr, size_t dst_size, char *src_ptr, size_ return tensorflow::Status::OK(); } +std::map StringToAscendString( + const std::map &string_map) { + std::map ascend_string_map; + for (const auto &string_pair : string_map) { + ascend_string_map.emplace(std::make_pair(ge::AscendString(string_pair.first.c_str()), + ge::AscendString(string_pair.second.c_str()))); + } + return ascend_string_map; +} + int64_t CreateChannelCapacity(const npu::TensorPartialShapes &shapes, const npu::TensorDataTypes &types) { const int64_t kMaxChannelCapacity = 128L; const int64_t kStringTypeCapacity = 64L; diff --git a/tf_adapter_2.x/npu_device/core/npu_utils.h b/tf_adapter_2.x/npu_device/core/npu_utils.h index 41945620c..bf544c5ea 100644 --- a/tf_adapter_2.x/npu_device/core/npu_utils.h +++ b/tf_adapter_2.x/npu_device/core/npu_utils.h @@ -49,8 +49,8 @@ class ScopeTensorHandleDeleter { tensorflow::Status MapGeType2Tf(ge::DataType ge_type, tensorflow::DataType &tf_type); tensorflow::Status SeparateGraphDef(tensorflow::GraphDef *def, - std::vector &partition_graph, - std::map &const_value_map); + std::vector &partition_graph, + std::map &const_value_map); /** * @brief: map tf type to ge @@ -96,6 +96,9 @@ std::string VecToString(std::vector vec) { return s + "]"; } +std::map StringToAscendString( + const std::map &string_map); + std::string SetToString(const std::set &vec); struct ResourceCompare { diff --git a/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp b/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp index 3aa311d51..6f72bc4b3 100644 --- a/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp @@ -217,12 +217,14 @@ PYBIND11_MODULE(_npu_device_backends, m) { json option_name_map; SetOptionNameMap(option_name_map); global_options["ge.optionNameMap"] = option_name_map.dump(); + auto ge_status = ge::GEInitialize(global_options); if (ge_status != ge::SUCCESS) { return "Failed start graph engine:" + ge::GEGetErrorMsg(); } LOG(INFO) << "Start graph engine succeed"; - ge_status = ge::ParserInitialize(global_options); + const auto global_options_ascend_string = StringToAscendString(global_options); + ge_status = ge::ParserInitialize(global_options_ascend_string); if (ge_status != ge::SUCCESS) { return "Failed start tensorflow model parser:" + ge::GEGetErrorMsg(); } diff --git a/tf_adapter_2.x/tests/stub/ge_stub.cpp b/tf_adapter_2.x/tests/stub/ge_stub.cpp index 2dfddb067..af2ddf1f7 100644 --- a/tf_adapter_2.x/tests/stub/ge_stub.cpp +++ b/tf_adapter_2.x/tests/stub/ge_stub.cpp @@ -34,7 +34,7 @@ Status Session::AddGraph(uint32_t graphId, const Graph &graph) { return SUCCESS; } -Status Session::AddGraph(uint32_t graphId, const Graph &graph, const std::map &options) { +Status Session::AddGraph(uint32_t graphId, const Graph &graph, const std::map &options) { graphs_[graphId] = graph.graph; graph_need_rebuild_[graphId] = false; return SUCCESS; @@ -110,7 +110,7 @@ size_t ComputeGraph::GetOutputSize() const { return 1U; } std::string GEGetErrorMsg() { return ""; } -Status GEInitialize(const std::map &options) { return SUCCESS; } +Status GEInitialize(const std::map &options) { return SUCCESS; } Status GEFinalize() { return SUCCESS; } diff --git a/tf_adapter_2.x/tests/stub/include/framework/omg/parser/model_parser.h b/tf_adapter_2.x/tests/stub/include/framework/omg/parser/model_parser.h index c7d9b4d07..cb88731ee 100644 --- a/tf_adapter_2.x/tests/stub/include/framework/omg/parser/model_parser.h +++ b/tf_adapter_2.x/tests/stub/include/framework/omg/parser/model_parser.h @@ -9,12 +9,12 @@ class GE_FUNC_VISIBILITY ModelParser { ModelParser() = default; ~ModelParser() = default; ge::DataType ConvertToGeDataType(const uint32_t type); - Status ParseProtoWithSubgraph(const std::string &serialized_proto, GetGraphCallbackV2 callback, + Status ParseProtoWithSubgraph(const ge::AscendString &serialized_proto, GetGraphCallbackV3 callback, ge::ComputeGraphPtr &graph); - Status ParseProtoWithSubgraph(const std::vector &partitioned_serialized, - const std::map &const_value_map, - GetGraphCallbackV2 callback, + Status ParseProtoWithSubgraph(const std::vector &partitioned_serialized, + const std::map &const_value_map, + GetGraphCallbackV3 callback, ge::ComputeGraphPtr &graph); }; } // namespace domi diff --git a/tf_adapter_2.x/tests/stub/include/framework/omg/parser/parser_api.h b/tf_adapter_2.x/tests/stub/include/framework/omg/parser/parser_api.h index 276e86d9d..fd311356a 100644 --- a/tf_adapter_2.x/tests/stub/include/framework/omg/parser/parser_api.h +++ b/tf_adapter_2.x/tests/stub/include/framework/omg/parser/parser_api.h @@ -20,7 +20,7 @@ #include "stub/defines.h" namespace ge { -Status ParserInitialize(const std::map& options); +Status ParserInitialize(const std::map& options); Status ParserFinalize(); } // namespace ge diff --git a/tf_adapter_2.x/tests/stub/include/ge/ge_api.h b/tf_adapter_2.x/tests/stub/include/ge/ge_api.h index c90793999..60dddd17f 100644 --- a/tf_adapter_2.x/tests/stub/include/ge/ge_api.h +++ b/tf_adapter_2.x/tests/stub/include/ge/ge_api.h @@ -27,7 +27,7 @@ #include "tensorflow/core/graph/graph.h" namespace ge { -Status GEInitialize(const std::map &options); +Status GEInitialize(const std::map &options); Status GEFinalize(); @@ -127,7 +127,7 @@ class Session { Status AddGraph(uint32_t graphId, const Graph &graph); - Status AddGraph(uint32_t graphId, const Graph &graph, const std::map &options); + Status AddGraph(uint32_t graphId, const Graph &graph, const std::map &options); Status RemoveGraph(uint32_t graphId); diff --git a/tf_adapter_2.x/tests/stub/include/stub/defines.h b/tf_adapter_2.x/tests/stub/include/stub/defines.h index b5fbeb0e0..445b50491 100644 --- a/tf_adapter_2.x/tests/stub/include/stub/defines.h +++ b/tf_adapter_2.x/tests/stub/include/stub/defines.h @@ -324,7 +324,7 @@ const graphStatus GRAPH_NODE_NEED_REPASS = 50331647; namespace domi { using Status = uint32_t; -using GetGraphCallbackV2 = std::function; +using GetGraphCallbackV3 = std::function; enum FrameworkType { CAFFE = 0, MINDSPORE = 1, diff --git a/tf_adapter_2.x/tests/stub/parser_stub.cpp b/tf_adapter_2.x/tests/stub/parser_stub.cpp index a1a081556..a6775826d 100644 --- a/tf_adapter_2.x/tests/stub/parser_stub.cpp +++ b/tf_adapter_2.x/tests/stub/parser_stub.cpp @@ -78,18 +78,18 @@ ge::DataType ModelParser::ConvertToGeDataType(const uint32_t type) { } } -Status ModelParser::ParseProtoWithSubgraph(const std::string &serialized_proto, GetGraphCallbackV2 callback, +Status ModelParser::ParseProtoWithSubgraph(const ge::AscendString &serialized_proto, GetGraphCallbackV3 callback, ge::ComputeGraphPtr &graph) { - std::vector partitioned_serialized{serialized_proto}; - std::map const_value_map; + std::vector partitioned_serialized{serialized_proto}; + std::map const_value_map; return ParseProtoWithSubgraph(partitioned_serialized, const_value_map, callback, graph); } -Status ModelParser::ParseProtoWithSubgraph(const std::vector &partitioned_serialized, - const std::map &const_value_map, - GetGraphCallbackV2 callback, +Status ModelParser::ParseProtoWithSubgraph(const std::vector &partitioned_serialized, + const std::map &const_value_map, + GetGraphCallbackV3 callback, ge::ComputeGraphPtr &graph) { - std::string graph_def_str = partitioned_serialized[0]; + std::string graph_def_str = partitioned_serialized[0].GetString(); tensorflow::GraphDef graph_def; graph_def.ParseFromString(graph_def_str); @@ -117,7 +117,7 @@ Status ModelParser::ParseProtoWithSubgraph(const std::vector &parti for (const auto &node : graph->graph->op_nodes()) { for (const auto &attr : node->attrs()) { if (attr.second.has_func()) { - callback(attr.second.func().name()); + callback(ge::AscendString(attr.second.func().name().c_str())); } } } @@ -126,7 +126,7 @@ Status ModelParser::ParseProtoWithSubgraph(const std::vector &parti } // namespace domi namespace ge { -Status ParserInitialize(const std::map &options) { return SUCCESS; } +Status ParserInitialize(const std::map &options) { return SUCCESS; } Status ParserFinalize() { return SUCCESS; } } // namespace ge \ No newline at end of file -- Gitee From 1977d9d6d3c0e0788f4306d96f397667d0f7ee70 Mon Sep 17 00:00:00 2001 From: guopeian Date: Wed, 22 Nov 2023 11:00:03 +0800 Subject: [PATCH 2/4] us --- tf_adapter/kernels/aicpu/dataset_function.cc | 6 +++--- tf_adapter/kernels/geop_npu.cc | 18 +++++++++--------- .../depends/ge_runner/src/ge_runner_stub.cc | 2 +- tf_adapter/util/acl_channel.cc | 2 +- tf_adapter/util/ge_plugin.cc | 8 ++++---- tf_adapter_2.x/npu_device/core/npu_device.cpp | 2 +- tf_adapter_2.x/npu_device/core/npu_micros.h | 4 ++-- tf_adapter_2.x/npu_device/core/npu_utils.cpp | 6 +++--- tf_adapter_2.x/npu_device/core/npu_utils.h | 1 + tf_adapter_2.x/npu_device/core/npu_wrapper.cpp | 10 ++++++---- tf_adapter_2.x/tests/stub/ge_stub.cpp | 3 +-- tf_adapter_2.x/tests/stub/include/ge/ge_api.h | 2 +- 12 files changed, 33 insertions(+), 31 deletions(-) diff --git a/tf_adapter/kernels/aicpu/dataset_function.cc b/tf_adapter/kernels/aicpu/dataset_function.cc index 8b137b636..3e0b17c5a 100644 --- a/tf_adapter/kernels/aicpu/dataset_function.cc +++ b/tf_adapter/kernels/aicpu/dataset_function.cc @@ -465,7 +465,7 @@ Status DatasetFunction::GeError(std::string errorDesc, ge::Status status) const std::stringstream error; error << errorDesc << " ret : " << status << std::endl << "Error message is : " << std::endl - << ge::GEGetErrorMsg(); + << ge::GEGetErrorMsgAscendString().GetString(); return errors::Internal(error.str()); } @@ -930,7 +930,7 @@ Status DatasetFunction::CreateGeGraph(const std::shared_ptr & Status status = InitAccelateOpList(acc_while_list); if (!status.ok()) { ADP_LOG(WARNING) << "Init acc_while_list failed, run whole sub graph. " << status.ToString(); - graph_def = build_sub_graph(funcName_); + graph_def = build_sub_graph(ge::AscendString(funcName_.c_str())).GetString(); } else { ADP_LOG(WARNING) << "Init acc_while_list success, run split graph process."; // split graph, and run part graph on device @@ -939,7 +939,7 @@ Status DatasetFunction::CreateGeGraph(const std::shared_ptr & run_split_graph_ = true; } - ge::Status ge_status = model_parser->ParseProtoWithSubgraph(ge::AscendString(graph_def), build_sub_graph, compute_graph); + ge::Status ge_status = model_parser->ParseProtoWithSubgraph(ge::AscendString(graph_def.c_str()), build_sub_graph, compute_graph); DATASET_REQUIRES(ge_status == ge::SUCCESS, GeError("Parse proto with graph failed.", ge_status)); // add performance priority tag for each node diff --git a/tf_adapter/kernels/geop_npu.cc b/tf_adapter/kernels/geop_npu.cc index 41533f65c..27951b583 100644 --- a/tf_adapter/kernels/geop_npu.cc +++ b/tf_adapter/kernels/geop_npu.cc @@ -835,7 +835,7 @@ int32_t GeOp::InitRebuildFlag(uint32_t cache_graph_id) { auto ret = ge_session_->RemoveGraph(cache_graph_id); if (ret != ge::SUCCESS) { ADP_LOG(ERROR) << "[GEOP] Failed to remove graph " << cache_graph_id << " from ge, error code " << ret; - std::string error_message = ge::GEGetErrorMsg(); + std::string error_message = ge::GEGetErrorMsgAscendString().GetString(); LOG(ERROR) << "[GEOP] Failed to remove graph " << cache_graph_id << " from ge, error code " << ret << std::endl << "Error Message is : " << std::endl << error_message; @@ -1040,7 +1040,7 @@ Status GeOp::DoGraphParser(ge::ComputeGraphPtr &compute_graph, FunctionLibraryDe ge::Status status = model_parser->ParseProtoWithSubgraph(partition_graph, const_value_map, build_sub_graph, compute_graph); if (status != ge::SUCCESS) { - std::string error_message = ge::GEGetErrorMsg(); + std::string error_message = ge::GEGetErrorMsgAscendString().GetString(); std::stringstream ss; ss << "graph parse failed. ret : " << status << std::endl << "Error Message is : " << std::endl << error_message; return errors::Internal(ss.str()); @@ -1136,7 +1136,7 @@ void GeOp::ComputeAsync(OpKernelContext *ctx, DoneCallback done) { auto input_vec_aoe = input_vec; if (RunTuning(input_vec_aoe, inputs, ctx) != 0) { ADP_LOG(ERROR) << "RunTuning fail."; - std::string error_message = ge::GEGetErrorMsg(); + std::string error_message = ge::GEGetErrorMsgAscendString().GetString(); std::stringstream ss; ss << std::endl << error_message; OP_REQUIRES_ASYNC(ctx, false, errors::Internal(ss.str()), done); @@ -1272,7 +1272,7 @@ void GeOp::ComputeAsync(OpKernelContext *ctx, DoneCallback done) { ADP_LOG(FATAL) << "[GEOP] call ge session add graph failed, kernel: " << geop_name << " ,tf session: " << tf_session_ << ", graph id: " << cache_graph_id; - std::string error_message = ge::GEGetErrorMsg(); + std::string error_message = ge::GEGetErrorMsgAscendString().GetString(); ss << "[GEOP] call ge session add graph failed, kernel: " << geop_name << ", tf session: " << tf_session_ << ", graph id: " << cache_graph_id << std::endl << "Error Message is : " << std::endl @@ -1292,7 +1292,7 @@ void GeOp::ComputeAsync(OpKernelContext *ctx, DoneCallback done) { ge::Status build_graph_status = ge_session_->BuildGraph(cache_graph_id, inputs); std::stringstream ss; if (build_graph_status != ge::SUCCESS) { - std::string error_message = ge::GEGetErrorMsg(); + std::string error_message = ge::GEGetErrorMsgAscendString().GetString(); ss << "[GEOP] GE session build graph failed, domi_ret : " << build_graph_status << std::endl << "Error Message is : " << std::endl << error_message; @@ -1319,7 +1319,7 @@ void GeOp::ComputeAsync(OpKernelContext *ctx, DoneCallback done) { if (ge_status == ge::SUCCESS) { if (BuildOutputTensorInfo(ctx, outputs) != Status::OK()) { ADP_LOG(FATAL) << ctx->op_kernel().name() << " GEOP::DoRunAsync get output failed."; - std::string error_message = ge::GEGetErrorMsg(); + std::string error_message = ge::GEGetErrorMsgAscendString().GetString(); std::stringstream ss; ss << ctx->op_kernel().name() << "GEOP::DoRunAsync get output failed." << std::endl << "Error Message is : " << std::endl @@ -1334,7 +1334,7 @@ void GeOp::ComputeAsync(OpKernelContext *ctx, DoneCallback done) { } else if (ge_status != ge::SUCCESS) { std::this_thread::sleep_for(std::chrono::milliseconds(kFatalSleepTime)); ADP_LOG(FATAL) << ctx->op_kernel().name() << "GEOP::::DoRunAsync Failed"; - std::string error_message = ge::GEGetErrorMsg(); + std::string error_message = ge::GEGetErrorMsgAscendString().GetString(); std::stringstream ss; ss << ctx->op_kernel().name() << "GEOP::::DoRunAsync Failed" << std::endl << "Error Message is : " << std::endl << error_message; @@ -1356,7 +1356,7 @@ void GeOp::ComputeAsync(OpKernelContext *ctx, DoneCallback done) { std::this_thread::sleep_for(std::chrono::milliseconds(kFatalSleepTime)); ADP_LOG(FATAL) << "[GEOP] call ge session RunGraphAsync Failed, kernel:" << geop_name << " ,tf session: " << tf_session_ << " ,graph id: " << cache_graph_id; - std::string error_message = ge::GEGetErrorMsg(); + std::string error_message = ge::GEGetErrorMsgAscendString().GetString(); ss << "[GEOP] call ge session RunGraphAsync Failed, kernel:" << geop_name << ", tf session: " << tf_session_ << ", graph id: " << cache_graph_id << std::endl << "Error Message is : " << std::endl @@ -1793,7 +1793,7 @@ Status GeOp::ParseOnnxGraphOpAttr(Node *&node) const { std::stringstream ss; ss << "[GEOP] node: " << node->name() << ": Onnx model parse failed, ret: " << ToString(status) << std::endl << "Error Message is : " << std::endl - << ge::GEGetErrorMsg(); + << ge::GEGetErrorMsgAscendString().GetString(); return errors::Internal(ss.str()); } diff --git a/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc b/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc index b8d658727..a349ea61b 100644 --- a/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc +++ b/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc @@ -233,7 +233,7 @@ Status ParserFinalize() { return ge::SUCCESS; } -GE_FUNC_VISIBILITY std::string GEGetErrorMsg() { return "ERROR";} +GE_FUNC_VISIBILITY ge::AscendString GEGetErrorMsgAscendString() { return ge::AscendString("ERROR");} Session::Session(const std::map &options) {} diff --git a/tf_adapter/util/acl_channel.cc b/tf_adapter/util/acl_channel.cc index 43fdfaf41..8500b5691 100644 --- a/tf_adapter/util/acl_channel.cc +++ b/tf_adapter/util/acl_channel.cc @@ -245,7 +245,7 @@ Status SendTensorsByAcl(const acltdtChannelHandle *acl_handle, acltdtTensorType } if (acl_status != ACL_ERROR_NONE) { sleep(kWaitingForLogRecord); - std::string error_message = ge::GEGetErrorMsg(); + std::string error_message = ge::GEGetErrorMsgAscendString().GetString(); LOG(FATAL) << "Failed to send data by acl, error code : "<< acl_status << std::endl << "Error Message is " << std::endl << error_message; diff --git a/tf_adapter/util/ge_plugin.cc b/tf_adapter/util/ge_plugin.cc index 9d0659831..811694ee9 100644 --- a/tf_adapter/util/ge_plugin.cc +++ b/tf_adapter/util/ge_plugin.cc @@ -49,7 +49,7 @@ void GeFinalize() { ge::Status status = ge::GEFinalize(); if (status != ge::SUCCESS) { ADP_LOG(ERROR) << "[GePlugin] GE finalize failed, ret : " << ToString(status); - std::string error_message = ge::GEGetErrorMsg(); + std::string error_message = ge::GEGetErrorMsgAscendString().GetString(); LOG(ERROR) << "[GePlugin] GE finalize failed, ret : " << ToString(status) << std::endl << "Error Message is : " << std::endl << error_message; @@ -323,7 +323,7 @@ void GePlugin::Init(std::map &init_options, const bool [this](const std::map &init_options) -> ge::Status { const auto init_ascend_string_options = ChangeStringToAscendString(init_options); const auto ret = ge::GEInitialize(init_ascend_string_options); - error_message_ = ge::GEGetErrorMsg(); + error_message_ = ge::GEGetErrorMsgAscendString().GetString(); return ret; }, init_options) @@ -334,7 +334,7 @@ void GePlugin::Init(std::map &init_options, const bool if (status != ge::SUCCESS) { std::this_thread::sleep_for(std::chrono::milliseconds(kFatalSleepTime)); ADP_LOG(FATAL) << "[GePlugin] Initialize ge failed, ret : " << ToString(status); - error_message_ = ge::GEGetErrorMsg(); + error_message_ = ge::GEGetErrorMsgAscendString().GetString(); LOG(FATAL) << "[GePlugin] Initialize ge failed, ret : " << ToString(status) << std::endl << "Error Message is : " << std::endl << error_message_; @@ -562,7 +562,7 @@ int32_t RdmaInitAndRegister(const std::vector &var_info, size_t } int32_t GetVarAddrAndSize(const string &var_name, uint64_t &base_addr, uint64_t &var_size) { - ge::Status ret = ge::GetVarBaseAddrAndSize(var_name, base_addr, var_size); + ge::Status ret = ge::GetVarBaseAddrAndSize(ge::AscendString(var_name.c_str()), base_addr, var_size); if (ret != ge::SUCCESS) { ADP_LOG(ERROR) << "[GePlugin] get " << var_name << " base addr and size failed, ret : " << ToString(ret); LOG(ERROR) << "[GePlugin] get " << var_name << " base addr and size failed, ret : " << ToString(ret); diff --git a/tf_adapter_2.x/npu_device/core/npu_device.cpp b/tf_adapter_2.x/npu_device/core/npu_device.cpp index e434857a6..bf51f1736 100644 --- a/tf_adapter_2.x/npu_device/core/npu_device.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_device.cpp @@ -833,7 +833,7 @@ void NpuDevice::RunGeGraphAsync(TFE_Context *context, uint64_t graph_id, int num done(tensorflow::errors::OutOfRange("Graph engine process graph ", graph_id, " reach end of sequence")); return; } else if (s != ge::SUCCESS) { - std::string err_msg = ge::GEGetErrorMsg(); + std::string err_msg = ge::GEGetErrorMsgAscendString().GetString(); if (err_msg.empty()) { err_msg = " code:" + std::to_string(s); } diff --git a/tf_adapter_2.x/npu_device/core/npu_micros.h b/tf_adapter_2.x/npu_device/core/npu_micros.h index 933ef44a8..aaa4cdf46 100644 --- a/tf_adapter_2.x/npu_device/core/npu_micros.h +++ b/tf_adapter_2.x/npu_device/core/npu_micros.h @@ -75,7 +75,7 @@ do { \ ge::Status _status = (__VA_ARGS__); \ if (TF_PREDICT_FALSE(_status != ge::SUCCESS)) { \ - std::string err_msg = ge::GEGetErrorMsg(); \ + std::string err_msg = ge::GEGetErrorMsgAscendString().GetString(); \ if (err_msg.empty()) { \ err_msg = " code:" + std::to_string(_status); \ } \ @@ -89,7 +89,7 @@ do { \ ge::Status _status = (EXP); \ if (TF_PREDICT_FALSE(_status != ge::SUCCESS)) { \ - std::string err_msg = ge::GEGetErrorMsg(); \ + std::string err_msg = ge::GEGetErrorMsgAscendString().GetString(); \ if (err_msg.empty()) { \ err_msg = " code:" + std::to_string(_status); \ } \ diff --git a/tf_adapter_2.x/npu_device/core/npu_utils.cpp b/tf_adapter_2.x/npu_device/core/npu_utils.cpp index 5fdffa00b..e62e02696 100644 --- a/tf_adapter_2.x/npu_device/core/npu_utils.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_utils.cpp @@ -514,7 +514,7 @@ tensorflow::Status SeparateGraphDef(tensorflow::GraphDef *def, std::map &const_value_map) { std::string def_str = def->SerializeAsString(); if (!def_str.empty()) { - partition_graph.push_back(def_str); + partition_graph.push_back(ge::AscendString(def_str.c_str())); return tensorflow::Status::OK(); } LOG(INFO) << "GraphDef is beyond 2G, which is need separate weight from model"; @@ -529,12 +529,12 @@ tensorflow::Status SeparateGraphDef(tensorflow::GraphDef *def, } tensorflow::TensorProto *tensor = iter->second.mutable_tensor(); std::string tensor_content = tensor->tensor_content(); - const_value_map.insert({node_name, tensor_content}); + const_value_map.insert({ge::AscendString(node_name.c_str()), ge::AscendString(tensor_content.c_str())}); tensor->set_tensor_content(""); } } def_str = def->SerializeAsString(); - partition_graph.push_back(def_str); + partition_graph.push_back(ge::AscendString(def_str.c_str())); return tensorflow::Status::OK(); } diff --git a/tf_adapter_2.x/npu_device/core/npu_utils.h b/tf_adapter_2.x/npu_device/core/npu_utils.h index bf544c5ea..937ee2648 100644 --- a/tf_adapter_2.x/npu_device/core/npu_utils.h +++ b/tf_adapter_2.x/npu_device/core/npu_utils.h @@ -26,6 +26,7 @@ #include "acl/acl_base.h" #include "graph/types.h" +#include "graph/ascend_string.h" #include "npu_types.h" diff --git a/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp b/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp index 6f72bc4b3..30df019c6 100644 --- a/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp @@ -220,13 +220,15 @@ PYBIND11_MODULE(_npu_device_backends, m) { auto ge_status = ge::GEInitialize(global_options); if (ge_status != ge::SUCCESS) { - return "Failed start graph engine:" + ge::GEGetErrorMsg(); + return "Failed start graph engine:" + + std::string(ge::GEGetErrorMsgAscendString().GetString()); } LOG(INFO) << "Start graph engine succeed"; const auto global_options_ascend_string = StringToAscendString(global_options); ge_status = ge::ParserInitialize(global_options_ascend_string); if (ge_status != ge::SUCCESS) { - return "Failed start tensorflow model parser:" + ge::GEGetErrorMsg(); + return "Failed start tensorflow model parser:" + + std::string(ge::GEGetErrorMsgAscendString().GetString()); } LOG(INFO) << "Start tensorflow model parser succeed"; @@ -273,7 +275,7 @@ PYBIND11_MODULE(_npu_device_backends, m) { if (graph_engine_started.exchange(false)) { auto ge_status = ge::ParserFinalize(); if (ge_status != ge::SUCCESS) { - LOG(ERROR) << "Failed stop tensorflow model parser:" << ge::GEGetErrorMsg(); + LOG(ERROR) << "Failed stop tensorflow model parser:" << ge::GEGetErrorMsgAscendString().GetString(); } else { LOG(INFO) << "Stop tensorflow model parser succeed"; } @@ -283,7 +285,7 @@ PYBIND11_MODULE(_npu_device_backends, m) { ge_status = ge::GEFinalize(); if (ge_status != ge::SUCCESS) { - LOG(ERROR) << "Failed stop graph engine:" << ge::GEGetErrorMsg(); + LOG(ERROR) << "Failed stop graph engine:" << ge::GEGetErrorMsgAscendString().GetString(); } else { LOG(INFO) << "Stop graph engine succeed"; } diff --git a/tf_adapter_2.x/tests/stub/ge_stub.cpp b/tf_adapter_2.x/tests/stub/ge_stub.cpp index af2ddf1f7..788839374 100644 --- a/tf_adapter_2.x/tests/stub/ge_stub.cpp +++ b/tf_adapter_2.x/tests/stub/ge_stub.cpp @@ -107,8 +107,7 @@ bool Session::IsGraphNeedRebuild(uint32_t graphId) { return graph_need_rebuild_[ size_t ComputeGraph::GetAllNodesSize() const { return graph->num_op_nodes(); } size_t ComputeGraph::GetInputSize() const { return 1U; } size_t ComputeGraph::GetOutputSize() const { return 1U; } - -std::string GEGetErrorMsg() { return ""; } +ge::AscendString GEGetErrorMsgAscendString() { return ge::AscendString(""); } Status GEInitialize(const std::map &options) { return SUCCESS; } diff --git a/tf_adapter_2.x/tests/stub/include/ge/ge_api.h b/tf_adapter_2.x/tests/stub/include/ge/ge_api.h index 60dddd17f..79c657e29 100644 --- a/tf_adapter_2.x/tests/stub/include/ge/ge_api.h +++ b/tf_adapter_2.x/tests/stub/include/ge/ge_api.h @@ -31,7 +31,7 @@ Status GEInitialize(const std::map &options) Status GEFinalize(); -std::string GEGetErrorMsg(); +ge::AscendString GEGetErrorMsgAscendString(); class Shape { public: -- Gitee From ecf921a470c40a9b2a0a598a539c33a4ecc25831 Mon Sep 17 00:00:00 2001 From: guopeian Date: Thu, 23 Nov 2023 15:10:23 +0800 Subject: [PATCH 3/4] Splite --- tf_adapter/kernels/aicpu/dataset_function.cc | 6 ++--- tf_adapter/kernels/geop_npu.cc | 20 +++++++++------- .../depends/ge_runner/src/ge_runner_stub.cc | 8 +++---- tf_adapter/util/ge_plugin.cc | 2 +- tf_adapter/util/npu_ops_identifier.cc | 24 ++++++++++++------- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/tf_adapter/kernels/aicpu/dataset_function.cc b/tf_adapter/kernels/aicpu/dataset_function.cc index 3e0b17c5a..0fe92a0d1 100644 --- a/tf_adapter/kernels/aicpu/dataset_function.cc +++ b/tf_adapter/kernels/aicpu/dataset_function.cc @@ -456,8 +456,8 @@ void DatasetFunction::DumpGeComputeGraph(const std::string &procPrifex, const st const ge::ComputeGraphPtr &graph) const { if (kDumpGraph) { const std::string fileName = GetPrefix() + "_" + procPrifex + "_ge_" + func_name; - ge::GraphUtils::DumpGEGraph(graph, fileName); - ge::GraphUtils::DumpGEGraphToOnnx(*graph, fileName); + ge::GraphUtils::DumpGEGraph(graph, ge::AscendString(fileName.c_str()), ge::AscendString("")); + ge::GraphUtils::DumpGEGraphToOnnx(ge::AscendString(fileName.c_str()), *graph); } } @@ -946,7 +946,7 @@ Status DatasetFunction::CreateGeGraph(const std::shared_ptr & for (const auto &node : compute_graph->GetDirectNode()) { ge::OpDescPtr op_desc = node->GetOpDesc(); DATASET_REQUIRES(op_desc != nullptr, errors::Internal("Param op_desc is nullptr, check invalid.")); - (void)ge::AttrUtils::SetBool(op_desc, "_performance_prior", true); + (void)ge::AttrUtils::SetBool(op_desc, true, ge::AscendString("_performance_prior")); } DumpGeComputeGraph(std::string("Build"), funcName_, compute_graph); diff --git a/tf_adapter/kernels/geop_npu.cc b/tf_adapter/kernels/geop_npu.cc index 27951b583..37996bec0 100644 --- a/tf_adapter/kernels/geop_npu.cc +++ b/tf_adapter/kernels/geop_npu.cc @@ -706,14 +706,15 @@ Status GeOp::ParserAccelerateTrain(const std::string &accelerate_train_mode) { } accelerate_info_.iteration_per_loop_ = iteration_per_loop_; // format like "fast|step|0.9" or "fast|step" - std::vector infos = ge::StringUtils::Split(accelerate_train_mode, '|'); + std::vector infos = + ge::StringUtils::SplitAscendString(ge::AscendString(accelerate_train_mode.c_str()), '|'); std::stringstream ss; if ((infos.size() != 2U) && (infos.size() != 3U)) { ss << "Format of accelerate_train_mode is invalid: " << accelerate_train_mode; ADP_LOG(ERROR) << ss.str(); return errors::Internal(ss.str()); } - const auto &fast_value = infos[0U]; + const auto &fast_value = infos[0U].GetString(); const auto &iter = fast_value_string_2_eunm.find(fast_value); if (iter == fast_value_string_2_eunm.end()) { const std::string valid_values = @@ -727,14 +728,14 @@ Status GeOp::ParserAccelerateTrain(const std::string &accelerate_train_mode) { return errors::Internal(ss.str()); } accelerate_info_.fast_value_ = iter->second; - REQUIRES_STATUS_OK(CheckAndSetAccelarateMode(infos[1U])); - if ((infos.size() != 3U) || (infos[2U].empty())) { + REQUIRES_STATUS_OK(CheckAndSetAccelarateMode(infos[1U].GetString())); + if ((infos.size() != 3U) || (infos[2U].GetLength() == 0UL)) { accelerate_info_.fast_ratio_ = accelerate_info_.fast_mode_ == kModeValueStep ? kDefaultStepRatio : kDefaultLossRatio; accelerate_info_.is_inited_ = true; return Status::OK(); } - REQUIRES_STATUS_OK(CheckAndSetAccelarateRatio(accelerate_info_.fast_mode_, infos[2U])); + REQUIRES_STATUS_OK(CheckAndSetAccelarateRatio(accelerate_info_.fast_mode_, infos[2U].GetString())); accelerate_info_.is_inited_ = true; return Status::OK(); } @@ -1783,7 +1784,8 @@ Status GeOp::ParseOnnxGraphOpAttr(Node *&node) const { node_def.mutable_attr()->insert({"_output_num", ot_value}); std::string model_path = node_def.attr().find("model_path")->second.s(); - ge::Graph sub_graph("onnx_compute_graph_" + node->name()); + std::string graph_name = "onnx_compute_graph_" + node->name(); + ge::Graph sub_graph(graph_name.c_str()); std::map parser_params; std::string subgrph_name("onnx_compute_graph_" + node->name() + '_' + CurrentTimeInStr()); parser_params.insert({ge::AscendString(ge::ir_option::OUTPUT), ge::AscendString(subgrph_name.c_str())}); @@ -1804,8 +1806,10 @@ Status GeOp::ParseOnnxGraphOpAttr(Node *&node) const { auto modi_name = node->name() + '_' + orig_name; snode->GetOpDesc()->SetName(modi_name); } - - ge::Model onnx_model("onnx_compute_model_" + node->name(), ""); + const uint32_t default_version = 1; + std::string model_name = "onnx_compute_model_" + node->name(); + ge::Model onnx_model(model_name.c_str(), + default_version, ""); onnx_model.SetGraph(ge::GraphUtilsEx::GetComputeGraph(sub_graph)); ge::Buffer model_buf; NPU_REQUIRES(onnx_model.Save(model_buf, false) == ge::SUCCESS, diff --git a/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc b/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc index a349ea61b..5e32db6b6 100644 --- a/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc +++ b/tf_adapter/tests/depends/ge_runner/src/ge_runner_stub.cc @@ -395,13 +395,13 @@ ComputeGraphPtr GraphUtilsEx::GetComputeGraph(const ge::Graph &graph) { } void GraphUtils::DumpGEGraph(const ComputeGraphPtr &graph, - const std::string &suffix, - bool is_always_dump, - const std::string &user_graph_name) { + const ge::AscendString &suffix, + const ge::AscendString &user_graph_name, + bool is_always_dump) { return; } -void GraphUtils::DumpGEGraphToOnnx(const ComputeGraph &compute_graph, const std::string &suffix) { +void GraphUtils::DumpGEGraphToOnnx(const ge::AscendString &suffix, const ComputeGraph &compute_graph) { return; } diff --git a/tf_adapter/util/ge_plugin.cc b/tf_adapter/util/ge_plugin.cc index 811694ee9..614307576 100644 --- a/tf_adapter/util/ge_plugin.cc +++ b/tf_adapter/util/ge_plugin.cc @@ -562,7 +562,7 @@ int32_t RdmaInitAndRegister(const std::vector &var_info, size_t } int32_t GetVarAddrAndSize(const string &var_name, uint64_t &base_addr, uint64_t &var_size) { - ge::Status ret = ge::GetVarBaseAddrAndSize(ge::AscendString(var_name.c_str()), base_addr, var_size); + ge::Status ret = ge::GetVarBaseAddrAndSize(base_addr, var_size, ge::AscendString(var_name.c_str())); if (ret != ge::SUCCESS) { ADP_LOG(ERROR) << "[GePlugin] get " << var_name << " base addr and size failed, ret : " << ToString(ret); LOG(ERROR) << "[GePlugin] get " << var_name << " base addr and size failed, ret : " << ToString(ret); diff --git a/tf_adapter/util/npu_ops_identifier.cc b/tf_adapter/util/npu_ops_identifier.cc index ada3082f3..56c7aa680 100644 --- a/tf_adapter/util/npu_ops_identifier.cc +++ b/tf_adapter/util/npu_ops_identifier.cc @@ -64,17 +64,23 @@ bool NpuOpsIdentifier::GetOppPluginVendors(const std::string &vendors_config, st ADP_LOG(ERROR) << "Content of file '" << vendors_config << "' is empty!"; return false; } - std::vector v_parts = ge::StringUtils::Split(content, '='); + std::vector v_parts = + ge::StringUtils::SplitAscendString(ge::AscendString(content.c_str()), '='); if (v_parts.size() != kVendorConfigPartsCount) { ADP_LOG(ERROR) << "Format of file content is invalid!"; return false; } - vendors = ge::StringUtils::Split(v_parts[1], ','); + std::vector vendors_ascend_string = + ge::StringUtils::SplitAscendString(v_parts[1], ','); if (vendors.empty()) { ADP_LOG(ERROR) << "Format of file content is invalid!"; return false; } - (void) for_each(vendors.begin(), vendors.end(), &ge::StringUtils::Trim); + (void) for_each(vendors_ascend_string.begin(), vendors_ascend_string.end(), &ge::StringUtils::TrimAscendString); + vendors.clear(); + for (const auto &vendor : vendors_ascend_string) { + vendors.emplace_back(std::string(vendor.GetString())); + } return true; } @@ -96,13 +102,15 @@ void NpuOpsIdentifier::GetCustomOpPathFromCustomOppPath(std::vector return; } ADP_LOG(INFO) << "value of env ASCEND_CUSTOM_OPP_PATH is " << custom_opp_path << "."; - std::vector custom_paths = ge::StringUtils::Split(custom_opp_path, ':'); + std::vector custom_paths = + ge::StringUtils::SplitAscendString(ge::AscendString(custom_opp_path.c_str()), ':'); for (const auto &custom_path : custom_paths) { - if ((!custom_path.empty()) && (mmIsDir(custom_path.c_str()) == EN_OK)) { - custom_ops_json_path_vec.push_back(custom_path + kCustomOpsInfoJsonV03); - ADP_LOG(INFO) << "custom_path '" << custom_path << "' is valid."; + std::string custom_path_str(custom_path.GetString()); + if ((!custom_path_str.empty()) && (mmIsDir(custom_path_str.c_str()) == EN_OK)) { + custom_ops_json_path_vec.push_back(custom_path_str + kCustomOpsInfoJsonV03); + ADP_LOG(INFO) << "custom_path '" << custom_path_str << "' is valid."; } else { - ADP_LOG(INFO) << "custom_path '" << custom_path << "' is invalid, which is skipped."; + ADP_LOG(INFO) << "custom_path '" << custom_path_str << "' is invalid, which is skipped."; } } std::string json_paths; -- Gitee From d74aa3816b653aa9ee596e1e34204dbfce5e8a65 Mon Sep 17 00:00:00 2001 From: guopeian Date: Thu, 23 Nov 2023 17:20:24 +0800 Subject: [PATCH 4/4] abi --- CMakeLists.txt | 2 +- tf_adapter_2.x/CMakeLists.txt | 4 ++-- tf_adapter_2.x/npu_device/core/npu_device.cpp | 2 +- tf_adapter_2.x/npu_device/core/npu_wrapper.cpp | 5 ++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 808e9b252..25df7bd6a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ if (ENABLE_OPEN_SRC) set(CMAKE_C_FLAGS "-O2 -DNDEBUG -Werror -Wno-class-memaccess -Wno-float-equal -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-comment -Wno-deprecated-declarations -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -s -pipe -fno-strict-aliasing -Wdate-time -Wformat=2 -Wno-shadow -Wno-undef -Wunused -Wstrict-prototypes ${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "-std=c++11 -O2 -DNDEBUG -Werror -Wno-class-memaccess -Wno-float-equal -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-comment -Wno-deprecated-declarations -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -s -pipe -fno-strict-aliasing -Wdate-time -Wformat=2 -Wno-shadow -Wno-undef -Wunused -Wdelete-non-virtual-dtor -Wnon-virtual-dtor -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}") - add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) + add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1) # build external prjects if(DEFINED ENV{D_PKG_SERVER}) diff --git a/tf_adapter_2.x/CMakeLists.txt b/tf_adapter_2.x/CMakeLists.txt index fe80f7db0..fe22e6154 100644 --- a/tf_adapter_2.x/CMakeLists.txt +++ b/tf_adapter_2.x/CMakeLists.txt @@ -12,8 +12,8 @@ IF (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) ENDIF () if (DEFINED ASCEND_CI_BUILD_DIR) - set(CMAKE_C_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0 ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0 ${CMAKE_CXX_FLAGS}") + set(CMAKE_C_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=1 ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=1 ${CMAKE_CXX_FLAGS}") include_directories(${PYTHON_INCLUDE_DIR}) add_definitions(-DASCEND_CI_LIMITED_PY37) else () diff --git a/tf_adapter_2.x/npu_device/core/npu_device.cpp b/tf_adapter_2.x/npu_device/core/npu_device.cpp index bf51f1736..1934bac3d 100644 --- a/tf_adapter_2.x/npu_device/core/npu_device.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_device.cpp @@ -980,7 +980,7 @@ uint64_t NpuDevice::AddGeGraphInner(TFE_Context *context, uint64_t graph_id, con } options["ge.exec.graphIOMemAllocMode"] = "ByGE"; const auto options_ascend_string = StringToAscendString(options); - NPU_CTX_REQUIRES_GE_OK_RETURN(status, "Graph engine Add graph", GeSession()->AddGraph(graph_id, ge_graph, options), + NPU_CTX_REQUIRES_GE_OK_RETURN(status, "Graph engine Add graph", GeSession()->AddGraph(graph_id, ge_graph, options_ascend_string), graph_id); return graph_id; } diff --git a/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp b/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp index 30df019c6..502982668 100644 --- a/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp @@ -217,14 +217,13 @@ PYBIND11_MODULE(_npu_device_backends, m) { json option_name_map; SetOptionNameMap(option_name_map); global_options["ge.optionNameMap"] = option_name_map.dump(); - - auto ge_status = ge::GEInitialize(global_options); + const auto global_options_ascend_string = StringToAscendString(global_options); + auto ge_status = ge::GEInitialize(global_options_ascend_string); if (ge_status != ge::SUCCESS) { return "Failed start graph engine:" + std::string(ge::GEGetErrorMsgAscendString().GetString()); } LOG(INFO) << "Start graph engine succeed"; - const auto global_options_ascend_string = StringToAscendString(global_options); ge_status = ge::ParserInitialize(global_options_ascend_string); if (ge_status != ge::SUCCESS) { return "Failed start tensorflow model parser:" + -- Gitee