diff --git a/tf_adapter/common/adapter_logger.h b/tf_adapter/common/adapter_logger.h index 01cdb5dbcdfc6630ad0428bf85439e1ab796b221..b0ed890c0da78a4a7089799a20ea0b7d67486ac7 100644 --- a/tf_adapter/common/adapter_logger.h +++ b/tf_adapter/common/adapter_logger.h @@ -18,7 +18,6 @@ #define TENSORFLOW_ADP_LOGGER_H #include -#include "mmpa/mmpa_api.h" #define FMK_MODULE_NAME static_cast(FMK) @@ -52,17 +51,14 @@ const int ADP_EVENT = 16; const int ADP_FATAL = 32; class AdapterLogger : public std::basic_ostringstream { - public: +public: AdapterLogger(const char *fname, int line, int severity) : severity_(severity) { - *this << " [" << fname << ":" << line << "]" << GetTid() << " "; + *this << " [" << fname << ":" << line << "]" + << " "; } ~AdapterLogger() override; - private: - mmPid_t GetTid() { - static const thread_local mmPid_t tid = static_cast(mmGetTid()); - return tid; - } +private: int severity_; }; } // namespace npu diff --git a/tf_adapter/kernels/geop_npu.cc b/tf_adapter/kernels/geop_npu.cc index 0b3e62d47ece6bb3f4fbd7d5feb159a6ac3d1e03..95af7690d955fa357ac724f3905650539327fa0d 100644 --- a/tf_adapter/kernels/geop_npu.cc +++ b/tf_adapter/kernels/geop_npu.cc @@ -322,7 +322,7 @@ const int kFatalSleepTime = 3000; const std::string kAllReduce = "HcomAllReduce"; GeOp::GeOp(OpKernelConstruction *ctx) - : OpKernel(ctx), init_flag_(false), build_flag_(false), add_graph_flag_(false), sess_init_flag_(false), + : AsyncOpKernel(ctx), init_flag_(false), build_flag_(false), add_graph_flag_(false), sess_init_flag_(false), compute_graph_empty_(false), is_input_convert_(false), data_format_(""), graph_id_(0), is_initialized_graph_(false), need_iteration_(false), tf_session_(""), ge_session_(nullptr), job_type_(""), is_host_graph_(false), handle_(nullptr), need_compile_graph_first_(false), tuned_flag_(ATOMIC_FLAG_INIT), @@ -760,10 +760,9 @@ Status GeOp::DoGraphParser(ge::ComputeGraphPtr &compute_graph, FunctionLibraryDe return Status::OK(); } -void GeOp::Compute(OpKernelContext *ctx) { +void GeOp::ComputeAsync(OpKernelContext *ctx, DoneCallback done) { // ctx is not nullptr - mutex_lock lock{run_mtx_}; - OP_REQUIRES(ctx, init_flag_, errors::InvalidArgument("GeOp not Initialize success.")); + OP_REQUIRES_ASYNC(ctx, init_flag_, errors::InvalidArgument("GeOp not Initialize success."), done); if (!sess_init_flag_) { if (job_type_ != "localhost") { // in ps mode : ctx->session_handle() is empty tf_session_ = "ps_worker_session"; @@ -773,12 +772,16 @@ void GeOp::Compute(OpKernelContext *ctx) { tf_session_ = ctx->session_handle(); ADP_LOG(INFO) << "[GEOP] get tf session " << tf_session_ << " from session handle."; } - OP_REQUIRES(ctx, IncrementGraphIdCount(graph_id_), errors::Unavailable("Get ge session failed.")); + bool res = IncrementGraphIdCount(graph_id_); + if (!res) { + OP_REQUIRES_ASYNC(ctx, false, errors::Unavailable("Get ge session failed."), done); + return; + } ADP_LOG(INFO) << "[GEOP] Node name: " << ctx->op_kernel().name() << " , tf session: " << tf_session_; if (!init_options_["ge.jobType"].empty() && !init_options_["ge.tuningPath"].empty()) { uint32_t device_id = 0; - OP_REQUIRES_OK(ctx, GetEnvDeviceID(device_id)); + OP_REQUIRES_OK_ASYNC(ctx, GetEnvDeviceID(device_id), done); ADP_LOG(INFO) << "[GEOP] in tuning func, aoe_mode:" << init_options_["ge.jobType"] << ", work_path:" << init_options_["ge.tuningPath"] << ", distribute_config:" << init_options_["distribute_config"]; @@ -796,15 +799,15 @@ void GeOp::Compute(OpKernelContext *ctx) { global_options.insert({ge::AscendString("ge.resourceConfigPath"), ge::AscendString(sess_options_["ge.resourceConfigPath"].c_str())}); AoeStatus init_ret = (*aoe_initialize_)(global_options); - OP_REQUIRES(ctx, init_ret == Aoe::AOE_SUCCESS, - errors::Internal("[GEOP] exec aoe initialize func failed[", init_ret, "].")); + OP_REQUIRES_ASYNC(ctx, init_ret == Aoe::AOE_SUCCESS, + errors::Internal("[GEOP] exec aoe initialize func failed[", init_ret, "]."), done); tuned_initialize_flag_ = true; } } } // convert input to const - OP_REQUIRES_OK(ctx, GraphInputConvertToConst(ctx)); + OP_REQUIRES_OK_ASYNC(ctx, GraphInputConvertToConst(ctx), done); std::string geop_name = ctx->op_kernel().name(); uint32_t num_inputs = static_cast(ctx->num_inputs()); ADP_LOG(INFO) << "[GEOP] Begin GeOp::ComputeAsync" @@ -829,7 +832,7 @@ void GeOp::Compute(OpKernelContext *ctx) { std::vector input_vec; std::vector input_shapes; std::vector inputs; - OP_REQUIRES_OK(ctx, (BuildInputTensorInfo(ctx, input_vec, input_shapes, inputs))); + OP_REQUIRES_OK_ASYNC(ctx, (BuildInputTensorInfo(ctx, input_vec, input_shapes, inputs)), done); // if input shapes changed, cache graphs uint32_t cache_graph_id = graph_id_; @@ -841,7 +844,7 @@ void GeOp::Compute(OpKernelContext *ctx) { if (is_aoe_) { if (is_set_dynamic_config) { ADP_LOG(ERROR) << "dynamic input config can not use with mstuning."; - OP_REQUIRES(ctx, false, errors::Internal("dynamic input config can not use with mstuning.")); + OP_REQUIRES_ASYNC(ctx, false, errors::Internal("dynamic input config can not use with mstuning."), done); return; } auto input_vec_aoe = input_vec; @@ -850,36 +853,47 @@ void GeOp::Compute(OpKernelContext *ctx) { std::string error_message = ge::GEGetErrorMsg(); std::stringstream ss; ss << std::endl << error_message; - OP_REQUIRES(ctx, false, errors::Internal(ss.str())); + OP_REQUIRES_ASYNC(ctx, false, errors::Internal(ss.str()), done); + } + if (InitRebuildFlag(cache_graph_id) != 0) { + OP_REQUIRES_ASYNC(ctx, false, errors::Internal("Failed to check rebuild flag"), done); + return; } - OP_REQUIRES(ctx, !InitRebuildFlag(cache_graph_id), errors::Internal("Failed to check rebuild flag")); ADP_LOG(INFO) << geop_name << " RunTuning finish."; } else if (is_set_dynamic_config) { - OP_REQUIRES(ctx, !InitRebuildFlag(cache_graph_id), errors::Internal("Failed to check rebuild flag")); + if (InitRebuildFlag(cache_graph_id) != 0) { + OP_REQUIRES_ASYNC(ctx, false, errors::Internal("Failed to check rebuild flag"), done); + return; + } } else { // in dynamic input mode, cache graphs. if (is_lazy_recompile_mode) { GetExecGraphId(cache_graph_id, input_shapes); } - OP_REQUIRES(ctx, !InitRebuildFlag(cache_graph_id), errors::Internal("Failed to check rebuild flag")); + if (InitRebuildFlag(cache_graph_id) != 0) { + OP_REQUIRES_ASYNC(ctx, false, errors::Internal("Failed to check rebuild flag"), done); + return; + } } if (!build_flag_) { // Get Graph - OP_REQUIRES(ctx, ctx->function_library() != nullptr, errors::Internal("function library is nullptr")); + OP_REQUIRES_ASYNC(ctx, ctx->function_library() != nullptr, errors::Internal("function library is nullptr"), done); FunctionLibraryDefinition *flib_def = const_cast(ctx->function_library()->GetFunctionLibraryDefinition()); - OP_REQUIRES(ctx, flib_def != nullptr, errors::Internal("flib_def is nullptr")); + OP_REQUIRES_ASYNC(ctx, flib_def != nullptr, errors::Internal("flib_def is nullptr"), done); // Build GraphDef from FunctionDef GraphDef ori_graph_def; bool is_allreduce = false; - OP_REQUIRES_OK(ctx, BuildGraphDef(*flib_def, input_vec, ori_graph_def, is_initialized_graph_, is_allreduce)); + OP_REQUIRES_OK_ASYNC(ctx, BuildGraphDef(*flib_def, input_vec, ori_graph_def, is_initialized_graph_, is_allreduce), + done); /* if graph is init verify graph, return */ if (this->is_initialized_graph_) { Tensor initialized_tensor(ctx->expected_output_dtype(0), TensorShape({0})); ctx->set_output(0, initialized_tensor); + done(); return; } if (kDumpGraph) { @@ -892,10 +906,14 @@ void GeOp::Compute(OpKernelContext *ctx) { ADP_LOG(INFO) << "[GEOP] TFadpter process graph success, GE parser begin, kernel_name: " << geop_name << " , tf session: " << tf_session_ << " , graph id: " << cache_graph_id; ge::ComputeGraphPtr compute_graph = nullptr; - compute_graph = std::make_shared("ge_default_" + CurrentTimeInStr()); - OP_REQUIRES(ctx, compute_graph != nullptr, errors::InvalidArgument("create ComputeGraph failed")); + try { + compute_graph = std::make_shared("ge_default_" + CurrentTimeInStr()); + } catch (...) { + OP_REQUIRES_ASYNC(ctx, false, errors::Internal("make shared failed"), done); + } + OP_REQUIRES_ASYNC(ctx, compute_graph != nullptr, errors::InvalidArgument("create ComputeGraph failed"), done); // parser, tensorflow graph to ge graph - OP_REQUIRES_OK(ctx, DoGraphParser(compute_graph, flib_def, ori_graph_def)); + OP_REQUIRES_OK_ASYNC(ctx, DoGraphParser(compute_graph, flib_def, ori_graph_def), done); ADP_LOG(INFO) << "[GEOP] Tensorflow graph parse to ge graph success, kernel_name: " << geop_name << ", tf session: " << tf_session_ << " , graph id: " << cache_graph_id << ", iteration_per_loop: " << iteration_per_loop_ << ", need iteration: " << this->need_iteration_; @@ -907,6 +925,7 @@ void GeOp::Compute(OpKernelContext *ctx) { ADP_LOG(INFO) << "[GEOP] End GeOp::ComputeAsync, compute_graph is empty, kernel_name:" << geop_name << ", ret_status:" << ToString(ge::SUCCESS) << " , tf session: " << tf_session_ << " ,graph id: " << cache_graph_id << " [" << ((endTime - startTime) / kMicrosToMillis) << " ms]"; + done(); return; } // convert to ge::graph @@ -955,7 +974,7 @@ void GeOp::Compute(OpKernelContext *ctx) { SetReuseOptions("ge.exec.outputReuseMemIndexes", ctx->num_outputs(), sess_options_, init_options_, graph_options); ADP_LOG(EVENT) << "[GEOP] call ge session add graph jit_compile: " << jit_compile_; graph_options["ge.exec.graphIOMemAllocMode"] = "ByGE"; - OP_REQUIRES_OK(ctx, CreateGeSession()); + OP_REQUIRES_OK_ASYNC(ctx, CreateGeSession(), done); auto status = ge_session_->AddGraph(cache_graph_id, ge_graph, graph_options); if (status != ge::SUCCESS) { std::this_thread::sleep_for(std::chrono::milliseconds(kFatalSleepTime)); @@ -968,7 +987,7 @@ void GeOp::Compute(OpKernelContext *ctx) { << ", graph id: " << cache_graph_id << std::endl << "Error Message is : " << std::endl << error_message; - OP_REQUIRES(ctx, status == ge::SUCCESS, errors::Unavailable(ss.str())); + OP_REQUIRES_ASYNC(ctx, status == ge::SUCCESS, errors::Unavailable(ss.str()), done); } else { add_graph_flag_ = true; ADP_LOG(INFO) << "[GEOP] Add graph to ge session success, kernel_name: " << geop_name @@ -987,10 +1006,11 @@ void GeOp::Compute(OpKernelContext *ctx) { ss << "[GEOP] GE session build graph failed, domi_ret : " << build_graph_status << std::endl << "Error Message is : " << std::endl << error_message; - OP_REQUIRES(ctx, build_graph_status == ge::SUCCESS, errors::Unavailable(ss.str())); + OP_REQUIRES_ASYNC(ctx, build_graph_status == ge::SUCCESS, errors::Unavailable(ss.str()), done); } ADP_LOG(INFO) << "[GEOP] Build graph success."; + done(); return; } LOG(INFO) << "The model has been compiled on the Ascend AI processor, current graph id is: " << cache_graph_id; @@ -1000,19 +1020,13 @@ void GeOp::Compute(OpKernelContext *ctx) { ADP_LOG(INFO) << "[GEOP] End GeOp::ComputeAsync, compute_graph is empty, kernel_name:" << geop_name << ", ret_status:" << ToString(ge::SUCCESS) << " , tf session: " << tf_session_ << " ,graph id: " << cache_graph_id << " [" << ((endTime - startTime) / kMicrosToMillis) << " ms]"; + done(); return; } } int64 run_start_time = InferShapeUtil::GetCurrentTimestap(); - tensorflow::Notification notification; - tensorflow::Status status; - auto done = [&status, ¬ification](tensorflow::Status s) { - status = std::move(s); - notification.Notify(); - }; auto callback = [done, ctx, run_start_time](ge::Status ge_status, std::vector &outputs) { - tensorflow::Status status = tensorflow::Status::OK(); if (ge_status == ge::SUCCESS) { if (BuildOutputTensorInfo(ctx, outputs) != Status::OK()) { ADP_LOG(FATAL) << ctx->op_kernel().name() << " GEOP::DoRunAsync get output failed."; @@ -1021,10 +1035,11 @@ void GeOp::Compute(OpKernelContext *ctx) { ss << ctx->op_kernel().name() << "GEOP::DoRunAsync get output failed." << std::endl << "Error Message is : " << std::endl << error_message; - status = errors::Internal(ss.str()); + OP_REQUIRES_ASYNC(ctx, false, errors::Internal(ss.str()), done); + return; } } else if (ge_status == ge::END_OF_SEQUENCE) { - status = errors::OutOfRange("End of sequence"); + ctx->SetStatus(errors::OutOfRange("End of sequence")); ADP_LOG(WARNING) << "[GEOP] Out of range: End of sequence."; LOG(WARNING) << "[GEOP] Out of range: End of sequence."; } else if (ge_status != ge::SUCCESS) { @@ -1034,13 +1049,13 @@ void GeOp::Compute(OpKernelContext *ctx) { std::stringstream ss; ss << ctx->op_kernel().name() << "GEOP::::DoRunAsync Failed" << std::endl << "Error Message is : " << std::endl << error_message; - status = errors::Internal(ss.str()); + OP_REQUIRES_ASYNC(ctx, false, errors::Internal(ss.str()), done); + return; } int64 run_end_time = InferShapeUtil::GetCurrentTimestap(); ADP_LOG(EVENT) << "[GEOP] RunGraphAsync callback, status:" << ge_status << ", kernel_name:" << ctx->op_kernel().name() << "[ " << (run_end_time - run_start_time) << "us]"; - ctx->SetStatus(status); - done(status); + done(); }; // call ge session runGraphAsync api @@ -1057,10 +1072,8 @@ void GeOp::Compute(OpKernelContext *ctx) { << ", graph id: " << cache_graph_id << std::endl << "Error Message is : " << std::endl << error_message; - OP_REQUIRES(ctx, run_graph_status == ge::SUCCESS, errors::Unavailable(ss.str())); + OP_REQUIRES_ASYNC(ctx, run_graph_status == ge::SUCCESS, errors::Unavailable(ss.str()), done); } - notification.WaitForNotification(); - OP_REQUIRES_OK(ctx, status); endTime = InferShapeUtil::GetCurrentTimestap(); ADP_LOG(EVENT) << "[GEOP] End GeOp::ComputeAsync, kernel_name: " << geop_name diff --git a/tf_adapter/kernels/geop_npu.h b/tf_adapter/kernels/geop_npu.h index 6ae3813a715268c67a537ed65142cdcbfd39514a..0c290219d7507d3852be6a4f3f8e312d90e34522 100644 --- a/tf_adapter/kernels/geop_npu.h +++ b/tf_adapter/kernels/geop_npu.h @@ -46,11 +46,11 @@ using AoeSetTuningGraphInputFunc = AoeStatus (*)(SessionId, std::vector &); -class GeOp : public OpKernel { +class GeOp : public AsyncOpKernel { public: explicit GeOp(OpKernelConstruction *ctx); ~GeOp() override; - void Compute(OpKernelContext *ctx) override; + void ComputeAsync(OpKernelContext *ctx, DoneCallback done) override; private: void Initialize(OpKernelConstruction *ctx); @@ -217,7 +217,6 @@ private: AoeTuningGraphFunc aoe_tuning_graph_; AoeSetDependGraphsInputsFunc aoe_set_depend_graphs_inputs_; AoeSetTuningGraphInputFunc aoe_set_tuning_graph_input_; - mutex run_mtx_; }; } // namespace tensorflow #endif // TENSORFLOW_KERNELS_GEOP_NPU_H_ diff --git a/tf_adapter/tests/depends/mmpa/src/mmpa_stub.cc b/tf_adapter/tests/depends/mmpa/src/mmpa_stub.cc index a5e69758cf1ff85d853954b2ab0779ea2ae10472..5fb4bee2fd6e88ce6fe77dc2c5a8958778f9b051 100644 --- a/tf_adapter/tests/depends/mmpa/src/mmpa_stub.cc +++ b/tf_adapter/tests/depends/mmpa/src/mmpa_stub.cc @@ -82,14 +82,4 @@ INT32 mmDlclose(VOID *handle) { INT32 mmSleep(UINT32 milliSecond) { return EN_OK; -} - -INT32 mmGetTid() { - INT32 ret = (INT32)syscall(SYS_gettid); - - if (ret < MMPA_ZERO) { - return EN_ERROR; - } - - return ret; } \ No newline at end of file diff --git a/tf_adapter/tests/st/kernels/testcase/geop_npu_test.cc b/tf_adapter/tests/st/kernels/testcase/geop_npu_test.cc index c0bd610c4546f667ccd0b98032f4ab8a5898a927..f779766280f73b4d58f07fbdd26caeb7144b3c1f 100644 --- a/tf_adapter/tests/st/kernels/testcase/geop_npu_test.cc +++ b/tf_adapter/tests/st/kernels/testcase/geop_npu_test.cc @@ -62,7 +62,7 @@ class DummyDevice : public DeviceBase { bool save_; }; -Status GeOpRunGraph(std::string example_path, gtl::InlinedVector inputs, +Status GeOpRunGraphAsync(std::string example_path, gtl::InlinedVector inputs, NodeDef &geop_node_def, std::string node_name, bool only_run_once = true) { Env* env = Env::Default(); GraphDef graph_def; @@ -80,7 +80,8 @@ Status GeOpRunGraph(std::string example_path, gtl::InlinedVector std::unique_ptr op(CreateOpKernel(DEVICE_CPU, params.device, cpu_allocator(), *node_def, TF_GRAPH_DEF_VERSION, &status)); EXPECT_TRUE(status.ok()); - params.op_kernel = op.get(); + AsyncOpKernel* async_op = op->AsAsync(); + params.op_kernel = async_op; params.session_handle = "session_0"; params.inputs = &inputs; @@ -95,10 +96,11 @@ Status GeOpRunGraph(std::string example_path, gtl::InlinedVector FunctionLibraryRuntime* flr = proc_flr->GetFLR(ProcessFunctionLibraryRuntime::kDefaultFLRDevice); params.function_library = flr; auto ctx = absl::make_unique(¶ms); - op->Compute(ctx.get()); + AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; + async_op->ComputeAsync(ctx.get(), done); if (!only_run_once) { auto ctx1 = absl::make_unique(¶ms); - op->Compute(ctx1.get()); + async_op->ComputeAsync(ctx1.get(), done); } } } @@ -110,7 +112,7 @@ TEST_F(GeOpTest, GeOpInitTest) { std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop.pbtxt"; gtl::InlinedVector inputs; ge::g_geinit_fore_return_fail = true; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp1_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp1_0").ok()); ge::g_geinit_fore_return_fail = false; PluginFinalize(); } @@ -119,25 +121,25 @@ TEST_F(GeOpTest, GeOpFuncTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp1_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp1_0").ok()); } TEST_F(GeOpTest, GeDynamicConfigError) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_config.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp61_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp61_0").ok()); } TEST_F(GeOpTest, GeOpOutputError) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_output_error.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp51_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp51_0").ok()); } TEST_F(GeOpTest, GeOpVarInitGraphTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_var_init_graph.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp14_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp14_0").ok()); } TEST_F(GeOpTest, GeOpDynamicInputTest) { NodeDef node_def; @@ -155,7 +157,7 @@ TEST_F(GeOpTest, GeOpDynamicInputTest) { Tensor c(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a), TensorValue(&b), TensorValue(&c)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp11_1", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp11_1", false).ok()); auto attrs = node_def.attr(); EXPECT_TRUE(attrs.find("_dynamic_input") != attrs.end()); EXPECT_TRUE(!attrs["_dynamic_input"].s().empty()); @@ -164,14 +166,14 @@ TEST_F(GeOpTest, GeOpDynamicInputGetNextTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_input_lazy_recompile.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp11_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp11_0").ok()); } TEST_F(GeOpTest, GeOpDynamicInput1Test) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_execute.pbtxt"; Tensor a(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp14_0", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp14_0", false).ok()); auto attrs = node_def.attr(); EXPECT_TRUE(attrs.find("_dynamic_input") != attrs.end()); EXPECT_TRUE(!attrs["_dynamic_input"].s().empty()); @@ -189,7 +191,7 @@ TEST_F(GeOpTest, GeOpGetNextStringTest) { in.scalar()() = "ABC"; Tensor d(DT_INT32, TensorShape({2, 2})); gtl::InlinedVector inputs{TensorValue(&a), TensorValue(&in), TensorValue(&d)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp14_0", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp14_0", false).ok()); } TEST_F(GeOpTest, GeOpAoeTuningAndDynamicDimsTest) { NodeDef node_def; @@ -197,7 +199,7 @@ TEST_F(GeOpTest, GeOpAoeTuningAndDynamicDimsTest) { Tensor a(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a)}; setenv("ENABLE_FORCE_V2_CONTROL", "1", true); - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp13_0", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp13_0", false).ok()); } TEST_F(GeOpTest, GeOpAoeTuningTest) { Env* env = Env::Default(); @@ -219,7 +221,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { std::unique_ptr op(CreateOpKernel(DEVICE_CPU, params.device, cpu_allocator(), *node_def, TF_GRAPH_DEF_VERSION, &status)); EXPECT_TRUE(status.ok()); - params.op_kernel = op.get(); + AsyncOpKernel* async_op = op->AsAsync(); + params.op_kernel = async_op; params.session_handle = "session_0"; gtl::InlinedVector inputs; params.inputs = &inputs; @@ -237,7 +240,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { int forward_from = 0; params.forward_from_array = &forward_from; auto ctx = absl::make_unique(¶ms); - op->Compute(ctx.get()); + AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; + async_op->ComputeAsync(ctx.get(), done); EXPECT_EQ(ctx->status().ok(), true); // another graph @@ -260,7 +264,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { std::unique_ptr op(CreateOpKernel(DEVICE_CPU, params.device, cpu_allocator(), *node_def, TF_GRAPH_DEF_VERSION, &status)); EXPECT_TRUE(status.ok()); - params.op_kernel = op.get(); + AsyncOpKernel* async_op = op->AsAsync(); + params.op_kernel = async_op; params.session_handle = "session_0"; gtl::InlinedVector inputs; params.inputs = &inputs; @@ -278,7 +283,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { int forward_from = 0; params.forward_from_array = &forward_from; auto ctx = absl::make_unique(¶ms); - op->Compute(ctx.get()); + AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; + async_op->ComputeAsync(ctx.get(), done); EXPECT_EQ(ctx->status().ok(), true); } } @@ -307,7 +313,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest_fail) { std::unique_ptr op(CreateOpKernel(DEVICE_CPU, params.device, cpu_allocator(), *node_def, TF_GRAPH_DEF_VERSION, &status)); EXPECT_TRUE(status.ok()); - params.op_kernel = op.get(); + AsyncOpKernel* async_op = op->AsAsync(); + params.op_kernel = async_op; params.session_handle = "session_0"; gtl::InlinedVector inputs; params.inputs = &inputs; @@ -325,9 +332,10 @@ TEST_F(GeOpTest, GeOpAoeTuningTest_fail) { int forward_from = 0; params.forward_from_array = &forward_from; auto ctx = absl::make_unique(¶ms); + AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; - static_cast(op.get())->session_id_ = 9999; - op->Compute(ctx.get()); + static_cast(async_op)->session_id_ = 9999; + async_op->ComputeAsync(ctx.get(), done); EXPECT_EQ(ctx->status().ok(), false); } } @@ -337,7 +345,7 @@ TEST_F(GeOpTest, GeOpFuncSubGraphTest) { std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_node_func_subgraph.pbtxt"; Tensor a(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp12_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp12_0").ok()); } TEST_F(GeOpTest, GeOpDynamicDimsTest) { @@ -345,7 +353,7 @@ TEST_F(GeOpTest, GeOpDynamicDimsTest) { std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_dims.pbtxt"; Tensor a(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp13_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp13_0").ok()); auto attrs = node_def.attr(); EXPECT_TRUE(attrs.find("_input_shape") != attrs.end()); EXPECT_TRUE(!attrs["_input_shape"].s().empty()); @@ -356,7 +364,7 @@ TEST_F(GeOpTest, GeOpDynamicDimsNodeType1Test) { std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_dims_node_type1.pbtxt"; Tensor a(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp13_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp13_0").ok()); auto attrs = node_def.attr(); EXPECT_TRUE(attrs.find("_input_shape") != attrs.end()); EXPECT_TRUE(!attrs["_input_shape"].s().empty()); @@ -366,7 +374,7 @@ TEST_F(GeOpTest, GeOpWhileLoopV1Test) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_while_loop.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp13_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp13_0").ok()); } TEST_F(GeOpTest, GeOpWhileLoopV2Test) { @@ -374,7 +382,7 @@ TEST_F(GeOpTest, GeOpWhileLoopV2Test) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_while_loop.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp13_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp13_0").ok()); } TEST_F(GeOpTest, GeOpNpuOnnxGraphOpTest) { @@ -383,7 +391,7 @@ TEST_F(GeOpTest, GeOpNpuOnnxGraphOpTest) { Tensor in(DT_FLOAT, TensorShape({1,1,5,5})); gtl::InlinedVector inputs{TensorValue(&in)}; - EXPECT_TRUE(GeOpRunGraph(grph_pbtxt_path, inputs, node_def, "GeOp91_0", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(grph_pbtxt_path, inputs, node_def, "GeOp91_0", false).ok()); } TEST_F(GeOpTest, GeOpNpuOnnxGraphOpNoModelTest) { @@ -392,13 +400,13 @@ TEST_F(GeOpTest, GeOpNpuOnnxGraphOpNoModelTest) { Tensor in(DT_FLOAT, TensorShape({1,1,5,5})); gtl::InlinedVector inputs{TensorValue(&in)}; - EXPECT_TRUE(GeOpRunGraph(grph_pbtxt_path, inputs, node_def, "GeOp91_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(grph_pbtxt_path, inputs, node_def, "GeOp91_0").ok()); } TEST_F(GeOpTest, GeOpDpOpTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dpop.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp1_0_dp").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp1_0_dp").ok()); } TEST_F(GeOpTest, GeOpNpuStringMaxSizeTest) { NodeDef node_def; @@ -410,7 +418,7 @@ TEST_F(GeOpTest, GeOpNpuStringMaxSizeTest) { Tensor in(DT_STRING, TensorShape({1,})); in.scalar()() = buff; gtl::InlinedVector inputs{TensorValue(&in)}; - EXPECT_TRUE(GeOpRunGraph(grph_pbtxt_path, inputs, node_def, "GeOp91_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(grph_pbtxt_path, inputs, node_def, "GeOp91_0").ok()); free(buff); buff = nullptr; } @@ -463,7 +471,7 @@ TEST_F(GeOpTest, BuildOutputTensorInfo) { Tensor in(DT_STRING, TensorShape({1})); in.scalar()() = "ABC"; gtl::InlinedVector inputs{TensorValue(&in)}; - EXPECT_TRUE(GeOpRunGraph(graph_pbtxt_path, inputs, node_def, "GeOp1_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_pbtxt_path, inputs, node_def, "GeOp1_0").ok()); } TEST_F(GeOpTest, test_MakeCompatShape) { GeOp *geop_node = reinterpret_cast(0x100); diff --git a/tf_adapter/tests/ut/kernels/testcase/geop_npu_test.cc b/tf_adapter/tests/ut/kernels/testcase/geop_npu_test.cc index 61249630b540e0f773af5cd0a49fe38f3a50c9d0..f7a5d0ff3ea009a9381085f1bbfbb009144661f9 100644 --- a/tf_adapter/tests/ut/kernels/testcase/geop_npu_test.cc +++ b/tf_adapter/tests/ut/kernels/testcase/geop_npu_test.cc @@ -66,7 +66,7 @@ class DummyDevice : public DeviceBase { bool save_; }; -Status GeOpRunGraph(std::string example_path, gtl::InlinedVector inputs, NodeDef& geop_node_def, +Status GeOpRunGraphAsync(std::string example_path, gtl::InlinedVector inputs, NodeDef& geop_node_def, std::string node_name, bool only_run_once = true) { Env* env = Env::Default(); GraphDef graph_def; @@ -84,7 +84,8 @@ Status GeOpRunGraph(std::string example_path, gtl::InlinedVector std::unique_ptr op( CreateOpKernel(DEVICE_CPU, params.device, cpu_allocator(), *node_def, TF_GRAPH_DEF_VERSION, &status)); EXPECT_TRUE(status.ok()); - params.op_kernel = op.get(); + AsyncOpKernel* async_op = op->AsAsync(); + params.op_kernel = async_op; params.session_handle = "session_0"; params.inputs = &inputs; @@ -98,10 +99,11 @@ Status GeOpRunGraph(std::string example_path, gtl::InlinedVector FunctionLibraryRuntime* flr = proc_flr->GetFLR(ProcessFunctionLibraryRuntime::kDefaultFLRDevice); params.function_library = flr; auto ctx = absl::make_unique(¶ms); - op->Compute(ctx.get()); + AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; + async_op->ComputeAsync(ctx.get(), done); if (!only_run_once) { auto ctx1 = absl::make_unique(¶ms); - op->Compute(ctx1.get()); + async_op->ComputeAsync(ctx1.get(), done); } } } @@ -114,7 +116,7 @@ TEST_F(GeOpTest, GeOpInitTest) { std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop.pbtxt"; gtl::InlinedVector inputs; ge::g_geinit_fore_return_fail = true; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp1_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp1_0").ok()); ge::g_geinit_fore_return_fail = false; PluginFinalize(); } @@ -124,26 +126,26 @@ TEST_F(GeOpTest, GeOpFuncTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp1_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp1_0").ok()); } TEST_F(GeOpTest, GeDynamicConfigError) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_config.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp61_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp61_0").ok()); } TEST_F(GeOpTest, GeOpOutputError) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_output_error.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp51_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp51_0").ok()); } TEST_F(GeOpTest, GeOpVarInitGraphTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_var_init_graph.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp14_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp14_0").ok()); } TEST_F(GeOpTest, GeOpJitCompileFalseTest) { NodeDef node_def; @@ -162,7 +164,7 @@ TEST_F(GeOpTest, GeOpJitCompileFalseTest) { gtl::InlinedVector inputs{TensorValue(&a), TensorValue(&b), TensorValue(&c)}; Tensor d(DT_INT32, TensorShape({2,})); gtl::InlinedVector inputs2{TensorValue(&a), TensorValue(&b), TensorValue(&d)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs2, node_def, "GeOp11_1", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs2, node_def, "GeOp11_1", false).ok()); } TEST_F(GeOpTest, GeOpDynamicInputTest) { NodeDef node_def; @@ -179,7 +181,7 @@ TEST_F(GeOpTest, GeOpDynamicInputTest) { Tensor b(allocator2, DT_INT64, TensorShape({2, 2})); Tensor c(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a), TensorValue(&b), TensorValue(&c)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp11_1", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp11_1", false).ok()); auto attrs = node_def.attr(); EXPECT_TRUE(attrs.find("_dynamic_input") != attrs.end()); EXPECT_TRUE(!attrs["_dynamic_input"].s().empty()); @@ -188,14 +190,14 @@ TEST_F(GeOpTest, GeOpDynamicInputGetNextTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_input_lazy_recompile.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp11_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp11_0").ok()); } TEST_F(GeOpTest, GeOpDynamicInput1Test) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_execute.pbtxt"; Tensor a(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp14_0", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp14_0", false).ok()); auto attrs = node_def.attr(); EXPECT_TRUE(attrs.find("_dynamic_input") != attrs.end()); EXPECT_TRUE(!attrs["_dynamic_input"].s().empty()); @@ -213,7 +215,7 @@ TEST_F(GeOpTest, GeOpGetNextStringTest) { in.scalar()() = "ABC"; Tensor d(DT_INT32, TensorShape({2, 2})); gtl::InlinedVector inputs{TensorValue(&a), TensorValue(&in), TensorValue(&d)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp14_0", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp14_0", false).ok()); } TEST_F(GeOpTest, GeOpAoeTuningAndDynamicDimsTest) { NodeDef node_def; @@ -221,7 +223,7 @@ TEST_F(GeOpTest, GeOpAoeTuningAndDynamicDimsTest) { Tensor a(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a)}; setenv("ENABLE_FORCE_V2_CONTROL", "1", true); - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp13_0", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp13_0", false).ok()); } TEST_F(GeOpTest, GeOpAoeTuningTest) { Env* env = Env::Default(); @@ -243,7 +245,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { std::unique_ptr op( CreateOpKernel(DEVICE_CPU, params.device, cpu_allocator(), *node_def, TF_GRAPH_DEF_VERSION, &status)); EXPECT_TRUE(status.ok()); - params.op_kernel = op.get(); + AsyncOpKernel* async_op = op->AsAsync(); + params.op_kernel = async_op; params.session_handle = "session_0"; gtl::InlinedVector inputs; params.inputs = &inputs; @@ -260,7 +263,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { int forward_from = 0; params.forward_from_array = &forward_from; auto ctx = absl::make_unique(¶ms); - op->Compute(ctx.get()); + AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; + async_op->ComputeAsync(ctx.get(), done); EXPECT_EQ(ctx->status().ok(), true); // another graph @@ -282,7 +286,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { std::unique_ptr op( CreateOpKernel(DEVICE_CPU, params.device, cpu_allocator(), *node_def, TF_GRAPH_DEF_VERSION, &status)); EXPECT_TRUE(status.ok()); - params.op_kernel = op.get(); + AsyncOpKernel* async_op = op->AsAsync(); + params.op_kernel = async_op; params.session_handle = "session_0"; gtl::InlinedVector inputs; params.inputs = &inputs; @@ -299,8 +304,9 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { int forward_from = 0; params.forward_from_array = &forward_from; auto ctx = absl::make_unique(¶ms); - static_cast(op.get())->session_id_ = 0; - op->Compute(ctx.get()); + AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; + static_cast(async_op)->session_id_ = 0; + async_op->ComputeAsync(ctx.get(), done); EXPECT_EQ(ctx->status().ok(), true); } } @@ -329,7 +335,8 @@ TEST_F(GeOpTest, GeOpAoeTuningOtherTest) { std::unique_ptr op( CreateOpKernel(DEVICE_CPU, params.device, cpu_allocator(), *node_def, TF_GRAPH_DEF_VERSION, &status)); EXPECT_TRUE(status.ok()); - params.op_kernel = op.get(); + AsyncOpKernel* async_op = op->AsAsync(); + params.op_kernel = async_op; params.session_handle = "session_0"; gtl::InlinedVector inputs; params.inputs = &inputs; @@ -346,8 +353,9 @@ TEST_F(GeOpTest, GeOpAoeTuningOtherTest) { int forward_from = 0; params.forward_from_array = &forward_from; auto ctx = absl::make_unique(¶ms); - static_cast(op.get())->session_id_ = 9999; - op->Compute(ctx.get()); + AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; + static_cast(async_op)->session_id_ = 9999; + async_op->ComputeAsync(ctx.get(), done); EXPECT_EQ(ctx->status().ok(), false); } } @@ -357,7 +365,7 @@ TEST_F(GeOpTest, GeOpDpOpTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dpop.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp1_0_dp").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp1_0_dp").ok()); } TEST_F(GeOpTest, GeOpFuncSubGraphTest) { @@ -365,14 +373,14 @@ TEST_F(GeOpTest, GeOpFuncSubGraphTest) { std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_node_func_subgraph.pbtxt"; Tensor a(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp12_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp12_0").ok()); } TEST_F(GeOpTest, GeOpDynamicDimsTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_dims.pbtxt"; Tensor a(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp13_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp13_0").ok()); auto attrs = node_def.attr(); EXPECT_TRUE(attrs.find("_input_shape") != attrs.end()); EXPECT_TRUE(!attrs["_input_shape"].s().empty()); @@ -382,7 +390,7 @@ TEST_F(GeOpTest, GeOpDynamicDimsNodeType1Test) { std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_dims_node_type1.pbtxt"; Tensor a(DT_INT32, TensorShape({1,})); gtl::InlinedVector inputs{TensorValue(&a)}; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp13_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp13_0").ok()); auto attrs = node_def.attr(); EXPECT_TRUE(attrs.find("_input_shape") != attrs.end()); EXPECT_TRUE(!attrs["_input_shape"].s().empty()); @@ -391,14 +399,14 @@ TEST_F(GeOpTest, GeOpWhileLoopV1Test) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_while_loop.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp13_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp13_0").ok()); } TEST_F(GeOpTest, GeOpWhileLoopV2Test) { setenv("ENABLE_FORCE_V2_CONTROL", "1", true); NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_while_loop.pbtxt"; gtl::InlinedVector inputs; - EXPECT_TRUE(GeOpRunGraph(graph_def_path, inputs, node_def, "GeOp13_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp13_0").ok()); } TEST_F(GeOpTest, GeOpNpuOnnxGraphOpTest) { NodeDef node_def; @@ -406,7 +414,7 @@ TEST_F(GeOpTest, GeOpNpuOnnxGraphOpTest) { Tensor in(DT_FLOAT, TensorShape({1, 1, 5, 5})); gtl::InlinedVector inputs{TensorValue(&in)}; - EXPECT_TRUE(GeOpRunGraph(grph_pbtxt_path, inputs, node_def, "GeOp91_0", false).ok()); + EXPECT_TRUE(GeOpRunGraphAsync(grph_pbtxt_path, inputs, node_def, "GeOp91_0", false).ok()); } TEST_F(GeOpTest, GeOpNpuOnnxGraphOpNoModelTest) { NodeDef node_def; @@ -414,7 +422,7 @@ TEST_F(GeOpTest, GeOpNpuOnnxGraphOpNoModelTest) { Tensor in(DT_FLOAT, TensorShape({1, 1, 5, 5})); gtl::InlinedVector inputs{TensorValue(&in)}; - EXPECT_TRUE(GeOpRunGraph(grph_pbtxt_path, inputs, node_def, "GeOp91_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(grph_pbtxt_path, inputs, node_def, "GeOp91_0").ok()); } TEST_F(GeOpTest, DomiFormatFromStringTest) { GeOp* geop_node; @@ -452,7 +460,7 @@ TEST_F(GeOpTest, GeOpNpuStringMaxSizeTest) { Tensor in(DT_STRING, TensorShape({1,})); in.scalar()() = buff; gtl::InlinedVector inputs{TensorValue(&in)}; - EXPECT_TRUE(GeOpRunGraph(grph_pbtxt_path, inputs, node_def, "GeOp91_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(grph_pbtxt_path, inputs, node_def, "GeOp91_0").ok()); free(buff); buff = nullptr; } @@ -506,7 +514,7 @@ TEST_F(GeOpTest, BuildOutputTensorInfo) { Tensor in(DT_STRING, TensorShape({1})); in.scalar()() = "ABC"; gtl::InlinedVector inputs{TensorValue(&in)}; - EXPECT_TRUE(GeOpRunGraph(graph_pbtxt_path, inputs, node_def, "GeOp1_0").ok()); + EXPECT_TRUE(GeOpRunGraphAsync(graph_pbtxt_path, inputs, node_def, "GeOp1_0").ok()); } TEST_F(GeOpTest, test_MakeCompatShape) { GeOp *geop_node;