diff --git a/tf_adapter/tests/depends/ascendcl/src/ascendcl_stub.cc b/tf_adapter/tests/depends/ascendcl/src/ascendcl_stub.cc index 70df5cd0044d37ba814af4ea72efe1d82a30aaec..76c561b0f621b610634a1efe05c6f8b35c860148 100644 --- a/tf_adapter/tests/depends/ascendcl/src/ascendcl_stub.cc +++ b/tf_adapter/tests/depends/ascendcl/src/ascendcl_stub.cc @@ -195,7 +195,7 @@ aclError acltdtReceiveTensor(const acltdtChannelHandle *handle, } } } else { - std::string vaue_str = "print message!!"; + static std::string vaue_str = "print message!!"; std::string *value = &vaue_str; // for scalar type, *dims is nullptr and dim_num is 0 acltdtDataItem *acl_data = acltdtCreateDataItem( @@ -215,7 +215,7 @@ aclError acltdtReceiveTensor(const acltdtChannelHandle *handle, return ACL_ERROR_FAILURE; } } - const std::vector dims {1, 0, 3}; + static const std::vector dims {1, 0, 3}; acltdtDataItem *acl_empty_tensor = acltdtCreateDataItem( ACL_TENSOR_DATA_TENSOR, dims.data(), dims.size(), ACL_INT32, nullptr, 0); @@ -622,7 +622,7 @@ void SetOutputNeedNull(const bool feed_null) { void *aclGetDataBufferAddr(const aclDataBuffer *dataBuffer) { if (g_set_output_feed_null) { - void* p = malloc(8); + void* p = malloc(16); return p; } return dataBuffer->data; 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 adfdbe3d87f87228fadce8e576581024f1a7a7b9..95771063f116b5d64158a08f58221fdf26db01ef 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 @@ -463,13 +463,13 @@ std::size_t Buffer::GetSize() const { } std::uint8_t *Buffer::GetData() { - std::string *buf_ = new std::string("_external_model"); - return reinterpret_cast (buf_); + static std::string str("_external_model"); + return reinterpret_cast (const_cast(str.c_str())); } const std::uint8_t *Buffer::GetData() const { - std::string *buf_ = new std::string("_external_model"); - return reinterpret_cast (buf_); + static std::string str("_external_model"); + return reinterpret_cast (str.c_str()); } Model::Model() {} diff --git a/tf_adapter/tests/depends/runtime/src/runtime_stub.cc b/tf_adapter/tests/depends/runtime/src/runtime_stub.cc index 5d756009f8f9ceffbd69c498473bc3d178004d2d..7d5bd24d807ddf0644472bd0a9edb523a899f878 100644 --- a/tf_adapter/tests/depends/runtime/src/runtime_stub.cc +++ b/tf_adapter/tests/depends/runtime/src/runtime_stub.cc @@ -124,7 +124,7 @@ rtError_t rtMbufAlloc(rtMbufPtr_t *mbuf, uint64_t size) { rtError_t rtMbufFree(rtMbufPtr_t mbuf) { free(((rtMbuf *)mbuf)->data); - free((rtMbuf *)mbuf); + delete (rtMbuf *)mbuf; return RT_ERROR_NONE; } 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 1ca595eea2975fd83669ec8824047a6dffd1c941..7af0dc2aa1efeb00f71fe8439761c6d28d979d78 100644 --- a/tf_adapter/tests/st/kernels/testcase/geop_npu_test.cc +++ b/tf_adapter/tests/st/kernels/testcase/geop_npu_test.cc @@ -142,8 +142,8 @@ Status GeOpRunGraphAsync(std::string example_path, gtl::InlinedVector(¶ms); AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; async_op->ComputeAsync(ctx.get(), done); + auto ctx1 = absl::make_unique(¶ms); if (!only_run_once) { - auto ctx1 = absl::make_unique(¶ms); async_op->ComputeAsync(ctx1.get(), done); } while (CallbackExecutor::GetInstance().GetRunNum() > 0) { @@ -187,10 +187,10 @@ Status GeOpRunGraphAsyncMultiStep(std::string example_path, std::vectorGetFLR(ProcessFunctionLibraryRuntime::kDefaultFLRDevice); params.function_library = flr; AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; + auto ctx = absl::make_unique(¶ms); for (size_t i = 0UL; i < inputs.size(); i++) { LOG(INFO) << "Step: " << i; params.inputs = &inputs[i]; - auto ctx = absl::make_unique(¶ms); async_op->ComputeAsync(ctx.get(), done); while (CallbackExecutor::GetInstance().GetRunNum() > 0) { usleep(100); @@ -259,6 +259,26 @@ TEST_F(GeOpTest, GeOpVarInitGraphTest) { gtl::InlinedVector inputs; EXPECT_TRUE(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp14_0").ok()); } +TEST_F(GeOpTest, GeOpJitCompileFalseTest) { + NodeDef node_def; + std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_jit_compile_true.pbtxt"; + std::vector ge_output1_dims{2, 2}; + auto getnext_output1_info = + std::unique_ptr(new NpuGetNextOutputInfo(ge::kPlacementDevice, ge_output1_dims, 8, nullptr)); + Allocator* allocator1 = NpuHostGetNextAllocator::Create(std::move(getnext_output1_info)); + Tensor a(allocator1, DT_INT64, TensorShape({2, 2})); + std::vector ge_output2_dims{2, 2}; + auto getnext_output2_info = + std::unique_ptr(new NpuGetNextOutputInfo(ge::kPlacementDevice, ge_output2_dims, 8, nullptr)); + Allocator* allocator2 = NpuHostGetNextAllocator::Create(std::move(getnext_output2_info)); + 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(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp11_1", false).ok()); + Tensor d(DT_INT32, TensorShape({4})); + gtl::InlinedVector inputs2{TensorValue(&a), TensorValue(&b), TensorValue(&d)}; + EXPECT_TRUE(GeOpRunGraphAsyncMultiStep(graph_def_path, {inputs, inputs2}, node_def, "GeOp11_1").ok()); +} TEST_F(GeOpTest, GeOpDynamicInputTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_dynamic_input_lazy_recompile.pbtxt"; @@ -367,6 +387,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { GraphDef train_graph_def; std::string train_graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_aoe_tuning.pbtxt"; ReadTextProto(env, train_graph_def_path, &train_graph_def); + std::unique_ptr device1; + std::unique_ptr ctx1; for (int i = 0; i < train_graph_def.node_size(); i++) { NodeDef* node_def = train_graph_def.mutable_node(i); if (node_def->name() == "GeOp2_0") { @@ -374,11 +396,10 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { EXPECT_TRUE(attrs.find("_aoe_mode") != attrs.end()); EXPECT_TRUE(!attrs["_aoe_mode"].s().empty()); EXPECT_TRUE(attrs.find("_work_path") != attrs.end()); - for (auto attr : node_def->attr()) OpKernelContext::Params params; params.record_tensor_accesses = false; - auto device = absl::make_unique(env, params.record_tensor_accesses); - params.device = device.get(); + device1 = absl::make_unique(env, params.record_tensor_accesses); + params.device = device1.get(); Status status; std::unique_ptr op(CreateOpKernel(DEVICE_CPU, params.device, cpu_allocator(), *node_def, TF_GRAPH_DEF_VERSION, &status)); @@ -401,10 +422,11 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { params.function_library = flr; int forward_from = 0; params.forward_from_array = &forward_from; - auto ctx = absl::make_unique(¶ms); + ctx1 = absl::make_unique(¶ms); AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; - async_op->ComputeAsync(ctx.get(), done); - EXPECT_EQ(ctx->status().ok(), true); + static_cast(async_op)->session_id_ = 0; + async_op->ComputeAsync(ctx1.get(), done); + EXPECT_EQ(ctx1->status().ok(), true); } } } @@ -460,27 +482,6 @@ TEST_F(GeOpTest, GeOpAoeTuningTest_fail) { } } -TEST_F(GeOpTest, GeOpJitCompileFalseTest) { - NodeDef node_def; - std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_jit_compile_true.pbtxt"; - std::vector ge_output1_dims{2, 2}; - auto getnext_output1_info = - std::unique_ptr(new NpuGetNextOutputInfo(ge::kPlacementDevice, ge_output1_dims, 8, nullptr)); - Allocator* allocator1 = NpuHostGetNextAllocator::Create(std::move(getnext_output1_info)); - Tensor a(allocator1, DT_INT64, TensorShape({2, 2})); - std::vector ge_output2_dims{2, 2}; - auto getnext_output2_info = - std::unique_ptr(new NpuGetNextOutputInfo(ge::kPlacementDevice, ge_output2_dims, 8, nullptr)); - Allocator* allocator2 = NpuHostGetNextAllocator::Create(std::move(getnext_output2_info)); - 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(GeOpRunGraphAsync(graph_def_path, inputs, node_def, "GeOp11_1", false).ok()); - Tensor d(DT_INT32, TensorShape({4})); - gtl::InlinedVector inputs2{TensorValue(&a), TensorValue(&b), TensorValue(&d)}; - EXPECT_TRUE(GeOpRunGraphAsyncMultiStep(graph_def_path, {inputs, inputs2}, node_def, "GeOp11_1").ok()); -} - TEST_F(GeOpTest, GeOpFuncSubGraphTest) { NodeDef node_def; std::string graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_node_func_subgraph.pbtxt"; @@ -600,7 +601,7 @@ TEST_F(GeOpTest, GeOpNpuStringMaxSizeTest) { auto buff = reinterpret_cast(malloc(SECUREC_MEM_MAX_LEN + 1)); memset_s(buff, SECUREC_MEM_MAX_LEN, '*', SECUREC_MEM_MAX_LEN); - buff[SECUREC_MEM_MAX_LEN] = '*'; + buff[SECUREC_MEM_MAX_LEN] = '\0'; Tensor in(DT_STRING, TensorShape({1,})); in.scalar()() = buff; gtl::InlinedVector inputs{TensorValue(&in)}; diff --git a/tf_adapter/tests/st/util/testcase/util_test.cc b/tf_adapter/tests/st/util/testcase/util_test.cc index c45ecc24907dc55f09c9b0ded562c36aafbcec54..1a4a546147f9bac797801349651cf80087d06cc4 100644 --- a/tf_adapter/tests/st/util/testcase/util_test.cc +++ b/tf_adapter/tests/st/util/testcase/util_test.cc @@ -59,6 +59,9 @@ TEST_F(UtilTest , MappingDtStringTensor2AclDataItemTest) { EXPECT_EQ(tmp, std::to_string(i)); } EXPECT_EQ(offset, acltdtGetDataSizeFromItem(acl_data1)); + + acltdtDestroyDataItem(acl_data0); + acltdtDestroyDataItem(acl_data1); } } -} // end tensorflow \ No newline at end of file +} // end tensorflow 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 1a01693bde4b080e631f6510fe33e16872824562..43b579fc5f3d893d892030399b1a7ea987dc36e9 100644 --- a/tf_adapter/tests/ut/kernels/testcase/geop_npu_test.cc +++ b/tf_adapter/tests/ut/kernels/testcase/geop_npu_test.cc @@ -144,8 +144,8 @@ Status GeOpRunGraphAsync(std::string example_path, gtl::InlinedVector(¶ms); AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; async_op->ComputeAsync(ctx.get(), done); + auto ctx1 = absl::make_unique(¶ms); if (!only_run_once) { - auto ctx1 = absl::make_unique(¶ms); async_op->ComputeAsync(ctx1.get(), done); } while (CallbackExecutor::GetInstance().GetRunNum() > 0) { @@ -189,10 +189,10 @@ Status GeOpRunGraphAsyncMultiStep(std::string example_path, std::vectorGetFLR(ProcessFunctionLibraryRuntime::kDefaultFLRDevice); params.function_library = flr; AsyncOpKernel::DoneCallback done = []() { LOG(INFO) << "DONE DoneCallback"; }; + auto ctx = absl::make_unique(¶ms); for (size_t i = 0UL; i < inputs.size(); i++) { LOG(INFO) << "Step: " << i; params.inputs = &inputs[i]; - auto ctx = absl::make_unique(¶ms); async_op->ComputeAsync(ctx.get(), done); } while (CallbackExecutor::GetInstance().GetRunNum() > 0) { @@ -432,6 +432,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { GraphDef train_graph_def; std::string train_graph_def_path = "tf_adapter/tests/ut/kernels/pbtxt/geop_aoe_tuning.pbtxt"; ReadTextProto(env, train_graph_def_path, &train_graph_def); + std::unique_ptr device1; + std::unique_ptr ctx1; for (int i = 0; i < train_graph_def.node_size(); i++) { NodeDef* node_def = train_graph_def.mutable_node(i); if (node_def->name() == "GeOp2_0") { @@ -441,8 +443,8 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { EXPECT_TRUE(attrs.find("_work_path") != attrs.end()); OpKernelContext::Params params; params.record_tensor_accesses = false; - auto device = absl::make_unique(env, params.record_tensor_accesses); - params.device = device.get(); + device1 = absl::make_unique(env, params.record_tensor_accesses); + params.device = device1.get(); Status status; std::unique_ptr op( CreateOpKernel(DEVICE_CPU, params.device, cpu_allocator(), *node_def, TF_GRAPH_DEF_VERSION, &status)); @@ -464,11 +466,11 @@ TEST_F(GeOpTest, GeOpAoeTuningTest) { params.function_library = flr; int forward_from = 0; params.forward_from_array = &forward_from; - auto ctx = absl::make_unique(¶ms); + ctx1 = absl::make_unique(¶ms); 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); + async_op->ComputeAsync(ctx1.get(), done); + EXPECT_EQ(ctx1->status().ok(), true); } } } @@ -616,7 +618,7 @@ TEST_F(GeOpTest, GeOpNpuStringMaxSizeTest) { auto buff = reinterpret_cast(malloc(SECUREC_MEM_MAX_LEN + 1)); memset_s(buff, SECUREC_MEM_MAX_LEN, '*', SECUREC_MEM_MAX_LEN); - buff[SECUREC_MEM_MAX_LEN] = '*'; + buff[SECUREC_MEM_MAX_LEN] = '\0'; Tensor in(DT_STRING, TensorShape({1,})); in.scalar()() = buff; gtl::InlinedVector inputs{TensorValue(&in)}; diff --git a/tf_adapter/tests/ut/kernels/testcase/hccl_op_test.cc b/tf_adapter/tests/ut/kernels/testcase/hccl_op_test.cc index 99ec6317e853bff0143dfccaf8262b00cad5d18c..c3f67ec0544738bfad25f5ca8484d2f659933382 100644 --- a/tf_adapter/tests/ut/kernels/testcase/hccl_op_test.cc +++ b/tf_adapter/tests/ut/kernels/testcase/hccl_op_test.cc @@ -136,6 +136,9 @@ TEST(HcclOpTest, TestHcomAllToAllVCOpKernel) { hcomAllToAllVCOpKernel->Compute(context2); delete context; delete hcomAllToAllVCOpKernel; + delete op_def; + delete node_def; + delete device; } } // namespace -} // namespace tensorflow \ No newline at end of file +} // namespace tensorflow diff --git a/tf_adapter/tests/ut/kernels/testcase/lru_cache_v2_ops_test.cc b/tf_adapter/tests/ut/kernels/testcase/lru_cache_v2_ops_test.cc index 8395862c0da2027a61f369f90949c44ebcf02334..9b6da0a8f9fedb693b8371397610fd673b6d9816 100644 --- a/tf_adapter/tests/ut/kernels/testcase/lru_cache_v2_ops_test.cc +++ b/tf_adapter/tests/ut/kernels/testcase/lru_cache_v2_ops_test.cc @@ -64,7 +64,7 @@ TEST(LruCacheV2Test, TestLruCacheV2) { .Finalize(&def)); shape_inference::InferenceContext c( 0, &def, op_def1, - {TShape({1})}, {}, {}, {}); + {TShape({1}), TShape({1}), TShape({1}), TShape({1})}, {}, {}, {}); TF_CHECK_OK(reg->shape_inference_fn(&c)); } diff --git a/tf_adapter/tests/ut/util/testcase/util_test.cc b/tf_adapter/tests/ut/util/testcase/util_test.cc index c45ecc24907dc55f09c9b0ded562c36aafbcec54..1a4a546147f9bac797801349651cf80087d06cc4 100644 --- a/tf_adapter/tests/ut/util/testcase/util_test.cc +++ b/tf_adapter/tests/ut/util/testcase/util_test.cc @@ -59,6 +59,9 @@ TEST_F(UtilTest , MappingDtStringTensor2AclDataItemTest) { EXPECT_EQ(tmp, std::to_string(i)); } EXPECT_EQ(offset, acltdtGetDataSizeFromItem(acl_data1)); + + acltdtDestroyDataItem(acl_data0); + acltdtDestroyDataItem(acl_data1); } } -} // end tensorflow \ No newline at end of file +} // end tensorflow