From e7399f0623661614c3ad7ead846e659aa391b542 Mon Sep 17 00:00:00 2001 From: Zhenze Wang Date: Tue, 10 Sep 2024 03:14:18 +0000 Subject: [PATCH 01/14] fallback --- onnxruntime/core/providers/vitisai/include/vaip/custom_op.h | 2 +- .../core/providers/vitisai/vitisai_execution_provider.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h index 5d020e00ff5b7..25b855183400a 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h @@ -45,7 +45,7 @@ class CustomOp { VAIP_DLL_SPEC virtual ~CustomOp(); public: - virtual void Compute(const OrtApi* api, OrtKernelContext* context) const = 0; + virtual void Compute_base(const OrtApi* api, OrtKernelContext* context) const = 0; }; } // namespace vaip_core diff --git a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc index 57c3e21b70104..e9cceec715834 100644 --- a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc +++ b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc @@ -89,7 +89,7 @@ common::Status VitisAIExecutionProvider::Compile(const std::vector(state)->Compute(api, context); + reinterpret_cast(state)->Compute_base(api, context); return Status::OK(); }; node_compute_funcs.push_back(compute_info); From ee52e33173f862a4833a9ffe38e35fd070707afb Mon Sep 17 00:00:00 2001 From: Zhenze Wang Date: Tue, 10 Sep 2024 10:10:13 +0000 Subject: [PATCH 02/14] stash --- .../core/providers/vitisai/include/vaip/custom_op.h | 11 +++++++++++ .../providers/vitisai/vitisai_execution_provider.cc | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h index 25b855183400a..1157c81a08371 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h @@ -46,6 +46,17 @@ class CustomOp { public: virtual void Compute_base(const OrtApi* api, OrtKernelContext* context) const = 0; + + public: + inline void set_subgraph(const onnxruntime::Graph* subgraph) { + subgraph_ = subgraph; + } + inline const onnxruntime::Graph* get_subgraph() const { + return subgraph_; + } + + private: + const onnxruntime::Graph* subgraph_ = nullptr; }; } // namespace vaip_core diff --git a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc index e9cceec715834..4e0d971a601e5 100644 --- a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc +++ b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc @@ -7,6 +7,7 @@ #include #include #include +#include // 1st-party headers/libs. #include "core/platform/env_var_utils.h" @@ -77,8 +78,9 @@ common::Status VitisAIExecutionProvider::Compile(const std::vectorexecution_providers_)[index]->set_fused_node(&fused_node_graph.fused_node.get()); - compute_info.create_state_func = [this, index](ComputeContext* context, FunctionState* state) { + compute_info.create_state_func = [this, index,fused_node_graph](ComputeContext* context, FunctionState* state) { auto* p = (**this->execution_providers_)[index]->compile().release(); + p->set_subgraph(&fused_node_graph.filtered_graph.get().GetGraph()); *state = p; return 0; }; From db329cdad480139ce990479a199ec599c86f67a3 Mon Sep 17 00:00:00 2001 From: zhenzew Date: Wed, 11 Sep 2024 00:35:34 -0700 Subject: [PATCH 03/14] first good --- .../shared_library/provider_interfaces.h | 1 + .../shared_library/provider_wrappedtypes.h | 1 + .../vitisai/include/vaip/custom_op.h | 21 +++++++------------ .../vitisai/vitisai_execution_provider.cc | 19 +++++++++++++---- .../vitisai/vitisai_execution_provider.h | 1 - .../core/session/provider_bridge_ort.cc | 1 + 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/onnxruntime/core/providers/shared_library/provider_interfaces.h b/onnxruntime/core/providers/shared_library/provider_interfaces.h index 4f062efb09e7f..b8218d6633a5c 100644 --- a/onnxruntime/core/providers/shared_library/provider_interfaces.h +++ b/onnxruntime/core/providers/shared_library/provider_interfaces.h @@ -993,6 +993,7 @@ struct ProviderHost { bool include_outer_scope_args, int execution_order) noexcept = 0; virtual const Node* GraphViewer__GetProducerNode(const GraphViewer* p, const std::string& node_arg_name) const = 0; + virtual IOnnxRuntimeOpSchemaCollectionPtr GraphViewer__GetSchemaRegistry(const GraphViewer* p) const = 0; // OpKernel virtual const Node& OpKernel__Node(const OpKernel* p) = 0; diff --git a/onnxruntime/core/providers/shared_library/provider_wrappedtypes.h b/onnxruntime/core/providers/shared_library/provider_wrappedtypes.h index 63ef36b0a7942..996c89c1cbd0f 100644 --- a/onnxruntime/core/providers/shared_library/provider_wrappedtypes.h +++ b/onnxruntime/core/providers/shared_library/provider_wrappedtypes.h @@ -1064,6 +1064,7 @@ class GraphViewer final { g_host->GraphViewer__ToProto(this, graph_proto, include_initializers, include_outer_scope_args, execution_order); } const Node* GetProducerNode(const std::string& node_arg_name) const { return g_host->GraphViewer__GetProducerNode(this, node_arg_name); } + IOnnxRuntimeOpSchemaCollectionPtr GetSchemaRegistry() const { return g_host->GraphViewer__GetSchemaRegistry(this); } GraphViewer() = delete; GraphViewer(const GraphViewer&) = delete; diff --git a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h index 1157c81a08371..1f9bd705f5727 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h @@ -28,15 +28,14 @@ class ExecutionProvider { virtual std::unique_ptr compile() const = 0; public: - inline void set_fused_node(const onnxruntime::Node* fused_node) { - fused_node_ = fused_node; - } - inline const onnxruntime::Node* get_fused_node() const { - return fused_node_; - } + inline void set_fused_node(const onnxruntime::Node* fused_node) { fused_node_ = fused_node; } + inline const onnxruntime::Node* get_fused_node() const { return fused_node_; } + inline void set_model(onnxruntime::Model* model) { model_ = model; } + inline onnxruntime::Model* get_model() const { return model_; } private: const onnxruntime::Node* fused_node_ = nullptr; + onnxruntime::Model* model_ = nullptr; }; class CustomOp { @@ -48,15 +47,11 @@ class CustomOp { virtual void Compute_base(const OrtApi* api, OrtKernelContext* context) const = 0; public: - inline void set_subgraph(const onnxruntime::Graph* subgraph) { - subgraph_ = subgraph; - } - inline const onnxruntime::Graph* get_subgraph() const { - return subgraph_; - } + inline void set_model(onnxruntime::Model* model) { model_ = model; } + inline onnxruntime::Model* get_model() const { return model_; } private: - const onnxruntime::Graph* subgraph_ = nullptr; + onnxruntime::Model* model_ = nullptr; }; } // namespace vaip_core diff --git a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc index 4e0d971a601e5..d329c9aa59f0f 100644 --- a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc +++ b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc @@ -77,10 +77,21 @@ common::Status VitisAIExecutionProvider::Compile(const std::vectorexecution_providers_)[index]->set_fused_node(&fused_node_graph.fused_node.get()); - compute_info.create_state_func = [this, index,fused_node_graph](ComputeContext* context, FunctionState* state) { - auto* p = (**this->execution_providers_)[index]->compile().release(); - p->set_subgraph(&fused_node_graph.filtered_graph.get().GetGraph()); + auto& ep = (**this->execution_providers_)[index]; + ep->set_fused_node(&fused_node_graph.fused_node.get()); + { + auto& subgraph = fused_node_graph.filtered_graph.get(); + auto& logger = logging::LoggingManager::DefaultLogger(); + auto model_proto = subgraph.CreateModel(logger)->ToProto(); + subgraph.ToProto(*model_proto->mutable_graph(), true, true); + auto local_registries = IOnnxRuntimeOpSchemaRegistryList{subgraph.GetSchemaRegistry()}; + auto model = Model::Create(std::move(*model_proto), subgraph.ModelPath(), &local_registries, logger); + ep->set_model(model.release()); + } + compute_info.create_state_func = [this, index](ComputeContext* context, FunctionState* state) { + auto& ep = (**this->execution_providers_)[index]; + auto* p = ep->compile().release(); + p->set_model(ep->get_model()); *state = p; return 0; }; diff --git a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.h b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.h index 24692dd45ca49..20a77ac57b53c 100644 --- a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.h +++ b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.h @@ -48,7 +48,6 @@ class VitisAIExecutionProvider : public IExecutionProvider { ProviderOptions info_; std::vector custom_op_domains_; std::shared_ptr registry_; - std::set vitisai_optypes_; // EP context related. bool ep_ctx_enabled_ = false; bool ep_ctx_embed_mode_ = true; diff --git a/onnxruntime/core/session/provider_bridge_ort.cc b/onnxruntime/core/session/provider_bridge_ort.cc index 8e807c375143e..58e3304d6461e 100644 --- a/onnxruntime/core/session/provider_bridge_ort.cc +++ b/onnxruntime/core/session/provider_bridge_ort.cc @@ -1203,6 +1203,7 @@ struct ProviderHostImpl : ProviderHost { GraphViewerToProto(*p, graph_proto, include_initializers, include_outer_scope_args, static_cast(execution_order)); } const Node* GraphViewer__GetProducerNode(const GraphViewer* p, const std::string& node_arg_name) const override { return p->GetProducerNode(node_arg_name); } + IOnnxRuntimeOpSchemaCollectionPtr GraphViewer__GetSchemaRegistry(const GraphViewer* p) const { return p->GetSchemaRegistry(); } // OpKernel (direct) const Node& OpKernel__Node(const OpKernel* p) override { return p->OpKernel::Node(); } From ccd9e37e510a3f9c243ee7ac5efe4aa83a3cc617 Mon Sep 17 00:00:00 2001 From: zhenzew Date: Wed, 11 Sep 2024 01:08:51 -0700 Subject: [PATCH 04/14] use model_proto_serialize_as_string --- onnxruntime/core/providers/vitisai/imp/global_api.cc | 4 ++++ onnxruntime/core/providers/vitisai/include/vaip/my_ort.h | 2 ++ .../core/providers/vitisai/include/vaip/vaip_ort_api.h | 2 ++ 3 files changed, 8 insertions(+) diff --git a/onnxruntime/core/providers/vitisai/imp/global_api.cc b/onnxruntime/core/providers/vitisai/imp/global_api.cc index 6f8e153cd1232..c2a29d557552e 100644 --- a/onnxruntime/core/providers/vitisai/imp/global_api.cc +++ b/onnxruntime/core/providers/vitisai/imp/global_api.cc @@ -406,6 +406,10 @@ vaip_core::OrtApiForVaip* create_org_api_hook() { graph.SetInputs(inputs); }; the_global_api.node_arg_external_location = vaip::node_arg_external_location; + the_global_api.model_to_proto = [](onnxruntime::Model& model){ return model.ToProto().release(); }; + the_global_api.model_proto_serialize_as_string = [](ONNX_NAMESPACE::ModelProto& model_proto) { + return vaip_core::DllSafe(model_proto.SerializeAsString()); + }; if (!s_library_vitisaiep.vaip_get_version) { return reinterpret_cast(&(the_global_api.host_)); } else { diff --git a/onnxruntime/core/providers/vitisai/include/vaip/my_ort.h b/onnxruntime/core/providers/vitisai/include/vaip/my_ort.h index 74482d8e9ee0e..79eaaacc4a235 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/my_ort.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/my_ort.h @@ -20,6 +20,7 @@ struct NodeAttributes; namespace ONNX_NAMESPACE { struct AttributeProto; struct TensorProto; +struct ModelProto; #ifndef USE_VITISAI enum TensorProto_DataType : int { TensorProto_DataType_UNDEFINED = 0, @@ -71,6 +72,7 @@ namespace vaip_core { class GraphHolder; using ONNX_NAMESPACE::AttributeProto; using ONNX_NAMESPACE::TensorProto; +using ONNX_NAMESPACE::ModelProto; using onnxruntime::Graph; using onnxruntime::GraphViewer; using onnxruntime::Model; diff --git a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h index a75c5553c7b3b..25f8cc4ba9a90 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h @@ -230,6 +230,8 @@ struct OrtApiForVaip { void (*graph_set_inputs)(Graph& graph, gsl::span inputs); // [92] int (*node_arg_external_location)(const Graph& graph, const NodeArg& node_arg, std::string& file, size_t& offset, size_t& size, size_t& checksum); // [93] + ModelProto* (*model_to_proto)(Model& model); //[94] + DllSafe(*model_proto_serialize_as_string)(ModelProto& model_proto);//[95] }; #ifndef USE_VITISAI From f7a9602e1a3436ae3f7465911c9e6dfe81e44e7e Mon Sep 17 00:00:00 2001 From: zhenzew Date: Wed, 11 Sep 2024 01:30:55 -0700 Subject: [PATCH 05/14] lint --- onnxruntime/core/providers/vitisai/imp/global_api.cc | 4 ++-- onnxruntime/core/providers/vitisai/include/vaip/my_ort.h | 2 +- .../core/providers/vitisai/include/vaip/vaip_ort_api.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/onnxruntime/core/providers/vitisai/imp/global_api.cc b/onnxruntime/core/providers/vitisai/imp/global_api.cc index c2a29d557552e..3560f61432d20 100644 --- a/onnxruntime/core/providers/vitisai/imp/global_api.cc +++ b/onnxruntime/core/providers/vitisai/imp/global_api.cc @@ -406,10 +406,10 @@ vaip_core::OrtApiForVaip* create_org_api_hook() { graph.SetInputs(inputs); }; the_global_api.node_arg_external_location = vaip::node_arg_external_location; - the_global_api.model_to_proto = [](onnxruntime::Model& model){ return model.ToProto().release(); }; + the_global_api.model_to_proto = [](onnxruntime::Model& model) { return model.ToProto().release(); }; the_global_api.model_proto_serialize_as_string = [](ONNX_NAMESPACE::ModelProto& model_proto) { return vaip_core::DllSafe(model_proto.SerializeAsString()); - }; + }; if (!s_library_vitisaiep.vaip_get_version) { return reinterpret_cast(&(the_global_api.host_)); } else { diff --git a/onnxruntime/core/providers/vitisai/include/vaip/my_ort.h b/onnxruntime/core/providers/vitisai/include/vaip/my_ort.h index 79eaaacc4a235..7628e45d2b933 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/my_ort.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/my_ort.h @@ -71,8 +71,8 @@ enum AttributeProto_AttributeType : int { namespace vaip_core { class GraphHolder; using ONNX_NAMESPACE::AttributeProto; -using ONNX_NAMESPACE::TensorProto; using ONNX_NAMESPACE::ModelProto; +using ONNX_NAMESPACE::TensorProto; using onnxruntime::Graph; using onnxruntime::GraphViewer; using onnxruntime::Model; diff --git a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h index 25f8cc4ba9a90..8d22304a709e9 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h @@ -230,8 +230,8 @@ struct OrtApiForVaip { void (*graph_set_inputs)(Graph& graph, gsl::span inputs); // [92] int (*node_arg_external_location)(const Graph& graph, const NodeArg& node_arg, std::string& file, size_t& offset, size_t& size, size_t& checksum); // [93] - ModelProto* (*model_to_proto)(Model& model); //[94] - DllSafe(*model_proto_serialize_as_string)(ModelProto& model_proto);//[95] + ModelProto* (*model_to_proto)(Model& model); //[94] + DllSafe (*model_proto_serialize_as_string)(ModelProto& model_proto); //[95] }; #ifndef USE_VITISAI From 223a0c3a12b1807c5cb26a76150c9e2f5e369a94 Mon Sep 17 00:00:00 2001 From: zhenzew Date: Wed, 11 Sep 2024 01:57:39 -0700 Subject: [PATCH 06/14] mv model_ to vaip --- .../core/providers/vitisai/include/vaip/custom_op.h | 7 ------- .../core/providers/vitisai/vitisai_execution_provider.cc | 5 +---- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h index 1f9bd705f5727..e9d632b5f54ee 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h @@ -45,13 +45,6 @@ class CustomOp { public: virtual void Compute_base(const OrtApi* api, OrtKernelContext* context) const = 0; - - public: - inline void set_model(onnxruntime::Model* model) { model_ = model; } - inline onnxruntime::Model* get_model() const { return model_; } - - private: - onnxruntime::Model* model_ = nullptr; }; } // namespace vaip_core diff --git a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc index d329c9aa59f0f..035c03150d544 100644 --- a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc +++ b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc @@ -7,7 +7,6 @@ #include #include #include -#include // 1st-party headers/libs. #include "core/platform/env_var_utils.h" @@ -89,9 +88,7 @@ common::Status VitisAIExecutionProvider::Compile(const std::vectorset_model(model.release()); } compute_info.create_state_func = [this, index](ComputeContext* context, FunctionState* state) { - auto& ep = (**this->execution_providers_)[index]; - auto* p = ep->compile().release(); - p->set_model(ep->get_model()); + auto* p = (**this->execution_providers_)[index]->compile().release(); *state = p; return 0; }; From beeaf2f598f3f2c1ebb5c314df4456b60af7294e Mon Sep 17 00:00:00 2001 From: zhenzew Date: Fri, 13 Sep 2024 01:13:12 -0700 Subject: [PATCH 07/14] update --- cmake/onnxruntime_providers_vitisai.cmake | 1 + onnxruntime/core/providers/vitisai/include/vaip/custom_op.h | 3 ++- .../core/providers/vitisai/include/vaip/vaip_ort_api.h | 2 +- .../core/providers/vitisai/vitisai_execution_provider.cc | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmake/onnxruntime_providers_vitisai.cmake b/cmake/onnxruntime_providers_vitisai.cmake index 764cde9491da8..561a323533f48 100644 --- a/cmake/onnxruntime_providers_vitisai.cmake +++ b/cmake/onnxruntime_providers_vitisai.cmake @@ -12,6 +12,7 @@ file(GLOB onnxruntime_providers_vitisai_cc_srcs CONFIGURE_DEPENDS "${ONNXRUNTIME_ROOT}/core/providers/vitisai/*.cc" "${ONNXRUNTIME_ROOT}/core/providers/vitisai/*.h" + "${ONNXRUNTIME_ROOT}/core/providers/vitisai/include/vaip/*.h" "${ONNXRUNTIME_ROOT}/core/providers/vitisai/imp/*.cc" "${ONNXRUNTIME_ROOT}/core/providers/vitisai/imp/*.h" "${ONNXRUNTIME_ROOT}/core/providers/shared_library/*.h" diff --git a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h index e9d632b5f54ee..785bfa5eb1675 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h @@ -25,6 +25,7 @@ class ExecutionProvider { virtual DllSafe> get_meta_def_nodes() const = 0; virtual DllSafe> get_meta_def_constant_initializer() const = 0; + virtual bool get_meta_def_fallback_CPU() const = 0; virtual std::unique_ptr compile() const = 0; public: @@ -44,7 +45,7 @@ class CustomOp { VAIP_DLL_SPEC virtual ~CustomOp(); public: - virtual void Compute_base(const OrtApi* api, OrtKernelContext* context) const = 0; + virtual void Compute(const OrtApi* api, OrtKernelContext* context) const = 0; }; } // namespace vaip_core diff --git a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h index 8d22304a709e9..92d095d127cac 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h @@ -13,7 +13,7 @@ struct OrtApi; namespace vaip_core { -#define VAIP_ORT_API_MAJOR (9u) +#define VAIP_ORT_API_MAJOR (10u) #define VAIP_ORT_API_MINOR (0u) #define VAIP_ORT_API_PATCH (0u) struct OrtApiForVaip { diff --git a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc index 035c03150d544..d882314c9e39d 100644 --- a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc +++ b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc @@ -78,7 +78,7 @@ common::Status VitisAIExecutionProvider::Compile(const std::vectorexecution_providers_)[index]; ep->set_fused_node(&fused_node_graph.fused_node.get()); - { + if (ep->get_meta_def_fallback_CPU()) { auto& subgraph = fused_node_graph.filtered_graph.get(); auto& logger = logging::LoggingManager::DefaultLogger(); auto model_proto = subgraph.CreateModel(logger)->ToProto(); @@ -99,7 +99,7 @@ common::Status VitisAIExecutionProvider::Compile(const std::vector(state)->Compute_base(api, context); + reinterpret_cast(state)->Compute(api, context); return Status::OK(); }; node_compute_funcs.push_back(compute_info); From 0053edc5e312ccbe31fcc34c4ad9b4382b3fbbd8 Mon Sep 17 00:00:00 2001 From: zhenzew Date: Fri, 13 Sep 2024 01:20:19 -0700 Subject: [PATCH 08/14] return false --- onnxruntime/core/providers/vitisai/include/vaip/custom_op.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h index 785bfa5eb1675..64cf52ec0a404 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h @@ -25,7 +25,7 @@ class ExecutionProvider { virtual DllSafe> get_meta_def_nodes() const = 0; virtual DllSafe> get_meta_def_constant_initializer() const = 0; - virtual bool get_meta_def_fallback_CPU() const = 0; + virtual bool get_meta_def_fallback_CPU() const { return false; }; virtual std::unique_ptr compile() const = 0; public: From 542f0266158e273f05345ece26c8a6e480e97126 Mon Sep 17 00:00:00 2001 From: Zhenze Wang Date: Sat, 14 Sep 2024 05:24:33 +0000 Subject: [PATCH 09/14] add model_proto_delete --- onnxruntime/core/providers/vitisai/imp/global_api.cc | 1 + .../providers/vitisai/include/vaip/vaip_ort_api.h | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/onnxruntime/core/providers/vitisai/imp/global_api.cc b/onnxruntime/core/providers/vitisai/imp/global_api.cc index 3560f61432d20..6c1e92a0599ff 100644 --- a/onnxruntime/core/providers/vitisai/imp/global_api.cc +++ b/onnxruntime/core/providers/vitisai/imp/global_api.cc @@ -410,6 +410,7 @@ vaip_core::OrtApiForVaip* create_org_api_hook() { the_global_api.model_proto_serialize_as_string = [](ONNX_NAMESPACE::ModelProto& model_proto) { return vaip_core::DllSafe(model_proto.SerializeAsString()); }; + the_global_api.model_proto_delete = [](ONNX_NAMESPACE::ModelProto* p) { delete p; }; if (!s_library_vitisaiep.vaip_get_version) { return reinterpret_cast(&(the_global_api.host_)); } else { diff --git a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h index 92d095d127cac..4b361c491e720 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h @@ -227,11 +227,12 @@ struct OrtApiForVaip { const std::vector& data); // [89] const std::filesystem::path& (*get_model_path)(const Graph& graph); // [90] Model* (*create_empty_model)(const std::filesystem::path& path, const std::vector>& opset); //[91] - void (*graph_set_inputs)(Graph& graph, - gsl::span inputs); // [92] - int (*node_arg_external_location)(const Graph& graph, const NodeArg& node_arg, std::string& file, size_t& offset, size_t& size, size_t& checksum); // [93] - ModelProto* (*model_to_proto)(Model& model); //[94] - DllSafe (*model_proto_serialize_as_string)(ModelProto& model_proto); //[95] + void (*graph_set_inputs)(Graph& graph, gsl::span inputs); // [92] + int (*node_arg_external_location)(const Graph& graph, const NodeArg& node_arg, std::string& file, + size_t& offset, size_t& size, size_t& checksum); // [93] + ModelProto* (*model_to_proto)(Model& model); //[94] + DllSafe (*model_proto_serialize_as_string)(ModelProto& model_proto); //[95] + void (*model_proto_delete)(ModelProto* p); // [96] }; #ifndef USE_VITISAI From bb29d71bd7bf46bd73b6fbc06545874c1243a58c Mon Sep 17 00:00:00 2001 From: Zhenze Wang Date: Sat, 14 Sep 2024 05:27:46 +0000 Subject: [PATCH 10/14] lint --- onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h index 4b361c491e720..cf50e0580facc 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h @@ -232,7 +232,7 @@ struct OrtApiForVaip { size_t& offset, size_t& size, size_t& checksum); // [93] ModelProto* (*model_to_proto)(Model& model); //[94] DllSafe (*model_proto_serialize_as_string)(ModelProto& model_proto); //[95] - void (*model_proto_delete)(ModelProto* p); // [96] + void (*model_proto_delete)(ModelProto* p); // [96] }; #ifndef USE_VITISAI From 89d829000bc73319ff3e9c6da55bc83cfd97bca4 Mon Sep 17 00:00:00 2001 From: Zhenze Wang Date: Tue, 10 Sep 2024 03:14:18 +0000 Subject: [PATCH 11/14] fallback --- onnxruntime/core/providers/vitisai/include/vaip/custom_op.h | 2 +- .../core/providers/vitisai/vitisai_execution_provider.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h index 5d020e00ff5b7..25b855183400a 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h @@ -45,7 +45,7 @@ class CustomOp { VAIP_DLL_SPEC virtual ~CustomOp(); public: - virtual void Compute(const OrtApi* api, OrtKernelContext* context) const = 0; + virtual void Compute_base(const OrtApi* api, OrtKernelContext* context) const = 0; }; } // namespace vaip_core diff --git a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc index 57c3e21b70104..e9cceec715834 100644 --- a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc +++ b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc @@ -89,7 +89,7 @@ common::Status VitisAIExecutionProvider::Compile(const std::vector(state)->Compute(api, context); + reinterpret_cast(state)->Compute_base(api, context); return Status::OK(); }; node_compute_funcs.push_back(compute_info); From 191304a43a24e9d80aeab9113255d6947038e169 Mon Sep 17 00:00:00 2001 From: Zhenze Wang Date: Thu, 19 Sep 2024 01:46:46 +0000 Subject: [PATCH 12/14] use VAIP_ORT_API_MAJOR 11 --- onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h index cf50e0580facc..1a7cc45f800e2 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/vaip_ort_api.h @@ -13,7 +13,7 @@ struct OrtApi; namespace vaip_core { -#define VAIP_ORT_API_MAJOR (10u) +#define VAIP_ORT_API_MAJOR (11u) #define VAIP_ORT_API_MINOR (0u) #define VAIP_ORT_API_PATCH (0u) struct OrtApiForVaip { From f43f8daf83aae22c81b82ac6b7c1f6cdc601be48 Mon Sep 17 00:00:00 2001 From: Zhenze Wang Date: Thu, 19 Sep 2024 03:16:11 +0000 Subject: [PATCH 13/14] Revert "fallback" This reverts commit 89d829000bc73319ff3e9c6da55bc83cfd97bca4. --- onnxruntime/core/providers/vitisai/include/vaip/custom_op.h | 2 +- .../core/providers/vitisai/vitisai_execution_provider.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h index 09f3782b5642f..64cf52ec0a404 100644 --- a/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h +++ b/onnxruntime/core/providers/vitisai/include/vaip/custom_op.h @@ -45,7 +45,7 @@ class CustomOp { VAIP_DLL_SPEC virtual ~CustomOp(); public: - virtual void Compute_base(const OrtApi* api, OrtKernelContext* context) const = 0; + virtual void Compute(const OrtApi* api, OrtKernelContext* context) const = 0; }; } // namespace vaip_core diff --git a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc index 2fc1bd37eb2f6..d882314c9e39d 100644 --- a/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc +++ b/onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc @@ -99,7 +99,7 @@ common::Status VitisAIExecutionProvider::Compile(const std::vector(state)->Compute_base(api, context); + reinterpret_cast(state)->Compute(api, context); return Status::OK(); }; node_compute_funcs.push_back(compute_info); From 0632da5e017a3f070526510a0e947e00133b801e Mon Sep 17 00:00:00 2001 From: zz002 Date: Wed, 25 Sep 2024 11:43:34 +0800 Subject: [PATCH 14/14] Update provider_bridge_ort.cc --- onnxruntime/core/session/provider_bridge_ort.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/session/provider_bridge_ort.cc b/onnxruntime/core/session/provider_bridge_ort.cc index 58e3304d6461e..4eccf42f51b87 100644 --- a/onnxruntime/core/session/provider_bridge_ort.cc +++ b/onnxruntime/core/session/provider_bridge_ort.cc @@ -1203,7 +1203,7 @@ struct ProviderHostImpl : ProviderHost { GraphViewerToProto(*p, graph_proto, include_initializers, include_outer_scope_args, static_cast(execution_order)); } const Node* GraphViewer__GetProducerNode(const GraphViewer* p, const std::string& node_arg_name) const override { return p->GetProducerNode(node_arg_name); } - IOnnxRuntimeOpSchemaCollectionPtr GraphViewer__GetSchemaRegistry(const GraphViewer* p) const { return p->GetSchemaRegistry(); } + IOnnxRuntimeOpSchemaCollectionPtr GraphViewer__GetSchemaRegistry(const GraphViewer* p) const override { return p->GetSchemaRegistry(); } // OpKernel (direct) const Node& OpKernel__Node(const OpKernel* p) override { return p->OpKernel::Node(); }