From 5c26b1708405df73554900abba97c2ada9b2d5e8 Mon Sep 17 00:00:00 2001 From: lidaoming1 Date: Wed, 15 Oct 2025 18:37:25 +0800 Subject: [PATCH 1/2] test --- tf_adapter_2.x/npu_device/core/npu_device.cpp | 3 ++- tf_adapter_2.x/tests/stub/include/ge/ge_api.h | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) 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 be0a990e9..58608885a 100644 --- a/tf_adapter_2.x/npu_device/core/npu_device.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_device.cpp @@ -936,7 +936,8 @@ void NpuDevice::TransTfInputs2GeInputs(int num_inputs, TFE_TensorHandle **inputs dims.emplace_back(dim_size); } input.SetTensorDesc(ge::TensorDesc(ge::Shape(dims), ge::FORMAT_ND, ge_type)); - input.SetData(static_cast(tensor->data()), tensor->TotalBytes(), [](uint8_t *) {}); + // input.SetData(static_cast(tensor->data()), tensor->TotalBytes(), [](uint8_t *) {}); + input.SetData(static_cast(tensor->data()), tensor->TotalBytes()); ge_inputs.emplace_back(input); DLOG() << " input " << i << " ge enum " << ge_type << " tf type " << tensorflow::DataTypeString(tensor->dtype()) << VecToString(dims); 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 23a37692d..4b0b27c2e 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 @@ -87,18 +87,19 @@ class Tensor { std::unique_ptr ResetData() { return std::move(data_); } graphStatus SetData(const uint8_t *data, size_t size) { const static DeleteFunc deleter = [](uint8_t *p) { delete[] p; }; - data_ = std::unique_ptr(new uint8_t[size], deleter); + REQUIRES_ACL_STATUS_OK(aclrtMallocHost(data_, size), aclrtMallocHost); + // data_ = std::unique_ptr(new uint8_t[size], deleter); std::memcpy(data_.get(), data, size); size_ = size; return GRAPH_SUCCESS; } - graphStatus SetData(uint8_t *data, size_t size, const Tensor::DeleteFunc &deleter_func) { - data_ = std::unique_ptr(new uint8_t[2], deleter_func); - data_.reset(data); - size_ = size; - return GRAPH_SUCCESS; - } + // graphStatus SetData(uint8_t *data, size_t size, const Tensor::DeleteFunc &deleter_func) { + // data_ = std::unique_ptr(new uint8_t[2], deleter_func); + // data_.reset(data); + // size_ = size; + // return GRAPH_SUCCESS; + // } private: TensorDesc desc_; -- Gitee From b24a7640ce4d7d826860dfe97fa2311454b93176 Mon Sep 17 00:00:00 2001 From: lidaoming1 Date: Thu, 16 Oct 2025 14:31:05 +0800 Subject: [PATCH 2/2] test 1 --- tf_adapter_2.x/npu_device/core/npu_device.cpp | 15 ++++++++++++++- tf_adapter_2.x/tests/stub/include/ge/ge_api.h | 12 ++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) 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 58608885a..64df7d1d7 100644 --- a/tf_adapter_2.x/npu_device/core/npu_device.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_device.cpp @@ -30,6 +30,7 @@ #include "npu_managed_buffer.h" #include "npu_tensor.h" #include "npu_utils.h" +#include "acl/acl_rt.h" #include "optimizers/npu_optimizer_manager.h" @@ -936,8 +937,20 @@ void NpuDevice::TransTfInputs2GeInputs(int num_inputs, TFE_TensorHandle **inputs dims.emplace_back(dim_size); } input.SetTensorDesc(ge::TensorDesc(ge::Shape(dims), ge::FORMAT_ND, ge_type)); + void *host_memory; + auto ret = aclrtMallocHost(&host_memory, tensor->TotalBytes()); + if (ret != ACL_SUCCESS) { + status.status = tensorflow::errors::Internal("Call aclrtMallocHost failed"); + return; + } + ret = aclrtMemcpy(host_memory, tensor->TotalBytes(), tensor->data(), tensor->TotalBytes(), ACL_MEMCPY_HOST_TO_HOST); + if (ret != ACL_SUCCESS) { + status.status = tensorflow::errors::Internal("Call aclrtMemcpy failed"); + return; + } + input.SetData(static_cast(host_memory), tensor->TotalBytes(), [](uint8_t *ptr) {aclrtFreeHost(ptr);}); // input.SetData(static_cast(tensor->data()), tensor->TotalBytes(), [](uint8_t *) {}); - input.SetData(static_cast(tensor->data()), tensor->TotalBytes()); + // input.SetData(static_cast(tensor->data()), tensor->TotalBytes()); ge_inputs.emplace_back(input); DLOG() << " input " << i << " ge enum " << ge_type << " tf type " << tensorflow::DataTypeString(tensor->dtype()) << VecToString(dims); 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 4b0b27c2e..ae7c5275d 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 @@ -94,12 +94,12 @@ class Tensor { return GRAPH_SUCCESS; } - // graphStatus SetData(uint8_t *data, size_t size, const Tensor::DeleteFunc &deleter_func) { - // data_ = std::unique_ptr(new uint8_t[2], deleter_func); - // data_.reset(data); - // size_ = size; - // return GRAPH_SUCCESS; - // } + graphStatus SetData(uint8_t *data, size_t size, const Tensor::DeleteFunc &deleter_func) { + data_ = std::unique_ptr(new uint8_t[2], deleter_func); + data_.reset(data); + size_ = size; + return GRAPH_SUCCESS; + } private: TensorDesc desc_; -- Gitee