Skip to content

Commit 72bd6dc

Browse files
wcy123mingyueliuh
authored andcommitted
[VitisAI] bugfix model_clone optimization (microsoft#25629)
### Description It is related to microsoft#25320 microsoft#23979. Enable tensor raw data sharing for externalized tensor proto with kTensorProtoMemoryAddressTag ### Motivation and Context With microsoft#25320 microsoft#23979, all initialized tensor protos are associated with OrtValue, VitisiAI EP need to adapt to this change. Co-authored-by: mingyue <[email protected]>
1 parent 1956dff commit 72bd6dc

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

onnxruntime/core/providers/vitisai/imp/graph.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "vaip/node.h"
1717
#include "vaip/node_arg.h"
18-
18+
#include "./tensor_proto.h"
1919
namespace vaip {
2020

2121
struct NodeEdgeT {
@@ -309,7 +309,14 @@ Model* model_clone(const Model& original_model, int64_t external_data_threshold)
309309
cloned_tensor->add_dims(dim);
310310
size = size * dim;
311311
}
312-
if (size >= external_data_threshold) {
312+
auto ORT_MEM_ADDR_tag = process_ext_address(*original_tensor);
313+
if (!ORT_MEM_ADDR_tag.empty()) {
314+
cloned_tensor->set_data_location(ONNX_NAMESPACE::TensorProto_DataLocation_EXTERNAL);
315+
auto external_data = cloned_tensor->mutable_external_data();
316+
auto p = external_data->Add();
317+
*p->mutable_key() = "location";
318+
*p->mutable_value() = std::string("<") + graph_ptr;
319+
} else if (size >= external_data_threshold) {
313320
cloned_tensor->set_data_location(ONNX_NAMESPACE::TensorProto_DataLocation_EXTERNAL);
314321
auto external_data = cloned_tensor->mutable_external_data();
315322
auto p = external_data->Add();

onnxruntime/core/providers/vitisai/imp/tensor_proto.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace vaip {
1111
using namespace onnxruntime;
1212

13-
static gsl::span<const char> process_ext_address(const ONNX_NAMESPACE::TensorProto& tensor) {
13+
gsl::span<const char> process_ext_address(const ONNX_NAMESPACE::TensorProto& tensor) {
1414
auto tensor_proto = const_cast<ONNX_NAMESPACE::TensorProto*>(&tensor);
1515
auto file = std::string();
1616
uintptr_t offset = 0;

onnxruntime/core/providers/vitisai/imp/tensor_proto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ ONNX_NAMESPACE::TensorProto* tensor_proto_new_fp16(const std::string& name, cons
3737
const std::vector<int16_t>& data);
3838
ONNX_NAMESPACE::TensorProto* tensor_proto_new_doubles(const std::string& name, const std::vector<int64_t>& shape,
3939
const std::vector<double>& data);
40+
gsl::span<const char> process_ext_address(const ONNX_NAMESPACE::TensorProto& tensor);
4041
} // namespace vaip

0 commit comments

Comments
 (0)