Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions onnxruntime/core/providers/vitisai/imp/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,30 @@
}
auto ORT_MEM_ADDR_tag = process_ext_address(*original_tensor);
if (!ORT_MEM_ADDR_tag.empty()) {
cloned_tensor->set_data_location(ONNX_NAMESPACE::TensorProto_DataLocation_EXTERNAL);
auto external_data = cloned_tensor->mutable_external_data();
auto p = external_data->Add();
*p->mutable_key() = "location";
*p->mutable_value() = std::string("<") + graph_ptr;
} else if (size >= external_data_threshold) {
cloned_tensor->set_data_location(ONNX_NAMESPACE::TensorProto_DataLocation_EXTERNAL);
auto external_data = cloned_tensor->mutable_external_data();
auto p = external_data->Add();
*p->mutable_key() = "location";
*p->mutable_value() = std::string("<") + graph_ptr;
// ORT 1.23 intializer handling
if (size >= external_data_threshold) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (size >= external_data_threshold) {

Use utils::HasExternalDataInMemory() to see if data is in OrtValue.

cloned_tensor->set_data_location(ONNX_NAMESPACE::TensorProto_DataLocation_EXTERNAL);
auto external_data = cloned_tensor->mutable_external_data();
auto p = external_data->Add();
*p->mutable_key() = "location";
*p->mutable_value() = std::string("<") + graph_ptr;
} else {
// Under threshold: get the data from ORT_MEM_ADDR and add it to cloned graph
Copy link
Member

@yuslepukhin yuslepukhin Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Under threshold: get the data from ORT_MEM_AD

Do not rely on threshold. Some big initializers may not be converted. Use utils to test if the data is external.

We generally do not want YOU to make the decision of what is expected to be an external data in memory.

Use utilities to test and convert.

You can also get a corresponding OrtValue from the graph.

std::unique_ptr<ONNX_NAMESPACE::TensorProto> tensor_proto;

Check warning on line 323 in onnxruntime/core/providers/vitisai/imp/graph.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <memory> for unique_ptr<> [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/vitisai/imp/graph.cc:323: Add #include <memory> for unique_ptr<> [build/include_what_you_use] [4]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tensor_proto;

If it is not in memory, then this is going to be nullptr

ORT_THROW_IF_ERROR(utils::GetTensorProtoWithDataIfInMemory(*original_tensor, tensor_proto));
*cloned_tensor = *tensor_proto;
}
} else {
*cloned_tensor = *original_tensor;
// ORT 1.22 or ealier intializer handling

Check warning on line 328 in onnxruntime/core/providers/vitisai/imp/graph.cc

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "ealier" is a misspelling of "earlier" Raw Output: ./onnxruntime/core/providers/vitisai/imp/graph.cc:328:21: "ealier" is a misspelling of "earlier"
Copy link
Member

@yuslepukhin yuslepukhin Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// ORT 1.22 or ealier intializer handling

What is the perceived difference? It is inline or not.

if (size >= external_data_threshold) {
cloned_tensor->set_data_location(ONNX_NAMESPACE::TensorProto_DataLocation_EXTERNAL);
auto external_data = cloned_tensor->mutable_external_data();
auto p = external_data->Add();
*p->mutable_key() = "location";
*p->mutable_value() = std::string("<") + graph_ptr;
} else {
*cloned_tensor = *original_tensor;
}
}
}
auto ret = Model::Create(std::move(*model_proto), file_path, &local_registries, logger);
Expand Down
Loading