From df124c9313a510575a9bf4590704cf10feef0fa6 Mon Sep 17 00:00:00 2001 From: BoarQing Date: Fri, 18 Aug 2023 03:30:03 +0800 Subject: [PATCH] [VITISAI] 1. Fix reading .dat and .onnx on Linux 2. Fix issue of compiling graph twice (#17108) ### Description 1. Fix reading .dat and .onnx on Linux 2. Fix issue of compiling graph twice ### Motivation and Context 1. Previous we have not tested large model on Linux. When the model is sperate into .dat and .onnx, it failed to load the model. 2. Check if the provider pointer is already existed. If existed, do not create again. --- onnxruntime/core/providers/vitisai/imp/graph.cc | 3 +++ onnxruntime/core/providers/vitisai/imp/tensor_proto.cc | 2 +- .../core/providers/vitisai/vitisai_execution_provider.cc | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/vitisai/imp/graph.cc b/onnxruntime/core/providers/vitisai/imp/graph.cc index e711fa84d5..4df11c2224 100644 --- a/onnxruntime/core/providers/vitisai/imp/graph.cc +++ b/onnxruntime/core/providers/vitisai/imp/graph.cc @@ -195,6 +195,9 @@ Node& graph_fuse(Graph& graph, const std::string& name, *proto.mutable_name() = name; fused_node.AddAttribute("body", proto); } + for (auto&& o : fused_node.OutputDefs()) { + graph.UpdateProducerNode(o->Name(), fused_node.Index()); + } return fused_node; } } // namespace vaip diff --git a/onnxruntime/core/providers/vitisai/imp/tensor_proto.cc b/onnxruntime/core/providers/vitisai/imp/tensor_proto.cc index edb14eda14..6ee148bc6a 100644 --- a/onnxruntime/core/providers/vitisai/imp/tensor_proto.cc +++ b/onnxruntime/core/providers/vitisai/imp/tensor_proto.cc @@ -14,7 +14,7 @@ gsl::span tensor_proto_as_raw( auto& mut_tensor = const_cast(tensor); if (!tensor.has_raw_data()) { std::vector unpacked_tensor; - auto s = onnxruntime::utils::UnpackInitializerData(tensor, unpacked_tensor); + auto s = onnxruntime::utils::UnpackInitializerData(tensor, onnxruntime::Path(), unpacked_tensor); mut_tensor.mutable_raw_data()->resize(unpacked_tensor.size()); memcpy(mut_tensor.mutable_raw_data()->data(), unpacked_tensor.data(), unpacked_tensor.size()); } diff --git a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc index 8afe83098c..32ee6ff652 100644 --- a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc +++ b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc @@ -96,6 +96,10 @@ VitisAIExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph, // VITIS AI EP not support sungraph. Assigned to CPU. return {}; } + if (execution_providers_) { + // Only compiling a model once is currently supported + return {}; + } auto opt_str = info_.get_json_config_str(); // String execution_providers_ = std::make_unique(compile_onnx_model(graph, *GetLogger(), opt_str));