Skip to content

Commit

Permalink
[VitisAI] Vitis ai ep support dynamic options (microsoft#22386)
Browse files Browse the repository at this point in the history
### Description
relate to microsoft#22282. Let Vitis ai ep handles dynamic_options



### Motivation and Context

---------

Co-authored-by: genmingz <[email protected]>
  • Loading branch information
danyue333 and genmingz authored Oct 22, 2024
1 parent 88676e6 commit 34a61e2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions onnxruntime/core/providers/vitisai/imp/global_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ struct OrtVitisAIEpAPI {
int (*vitisai_ep_on_run_start)(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps, const void* state,
vaip_core::DllSafe<std::string> (*get_config_entry)(const void* state, const char* entry_name)) = nullptr;
int (*vitisai_ep_set_ep_dynamic_options)(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,
const char* const* keys,
const char* const* values, size_t kv_len) = nullptr;
void Ensure() {
if (handle_)
return;
Expand All @@ -79,6 +83,7 @@ struct OrtVitisAIEpAPI {
(void**)&vaip_get_version);
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(handle_, "create_ep_context_nodes", (void**)&create_ep_context_nodes));
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(handle_, "vitisai_ep_on_run_start", (void**)&vitisai_ep_on_run_start));
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(handle_, "vitisai_ep_set_ep_dynamic_options", (void**)&vitisai_ep_set_ep_dynamic_options));
}

private:
Expand Down Expand Up @@ -120,6 +125,15 @@ int vitisai_ep_on_run_start(
return 100;
}

int vitisai_ep_set_ep_dynamic_options(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps, const char* const* keys,
const char* const* values, size_t kv_len) {
if (s_library_vitisaiep.vitisai_ep_set_ep_dynamic_options) {
return s_library_vitisaiep.vitisai_ep_set_ep_dynamic_options(eps, keys, values, kv_len);
}
return 100;
}

struct MyCustomOpKernel : OpKernel {
MyCustomOpKernel(const OpKernelInfo& info, const OrtCustomOp& op) : OpKernel(info), op_(op) {
op_kernel_ =
Expand Down
4 changes: 4 additions & 0 deletions onnxruntime/core/providers/vitisai/include/vaip/global_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ std::optional<std::vector<onnxruntime::Node*>> create_ep_context_nodes(
int vitisai_ep_on_run_start(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps, const void* state,
vaip_core::DllSafe<std::string> (*get_config_entry)(const void* state, const char* entry_name));
int vitisai_ep_set_ep_dynamic_options(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,
const char* const* keys,
const char* const* values, size_t kv_len);
12 changes: 11 additions & 1 deletion onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,19 @@ common::Status VitisAIExecutionProvider::OnRunStart(const onnxruntime::RunOption
};
auto error_code = vitisai_ep_on_run_start(**execution_providers_, (const void*)&run_options, get_config_entry);
if (error_code) {
return Status(onnxruntime::common::ONNXRUNTIME, onnxruntime::common::StatusCode::FAIL, std::to_string(error_code));
std::string error_msg = "vitisai_ep_on_run_start ret: " + std::to_string(error_code);
return Status(onnxruntime::common::ONNXRUNTIME, onnxruntime::common::StatusCode::FAIL, error_msg);
}
return Status::OK();
}

common::Status VitisAIExecutionProvider::SetEpDynamicOptions(gsl::span<const char* const> keys,
gsl::span<const char* const> values) {
auto error_code = vitisai_ep_set_ep_dynamic_options(**execution_providers_, keys.data(), values.data(), std::min(keys.size(), values.size()));
if (error_code) {
std::string error_msg = "vitisai_ep_set_ep_dynamic_options ret: " + std::to_string(error_code);
return Status(onnxruntime::common::ONNXRUNTIME, onnxruntime::common::StatusCode::FAIL, error_msg);
}
return Status::OK();
}
} // namespace onnxruntime
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class VitisAIExecutionProvider : public IExecutionProvider {
// This method is called after both `GetComputeCapabilityOps()` and `Compile()`.
// This timing is required to work with both compliation-based EPs and non-compilation-based EPs.
const InlinedVector<const Node*> GetEpContextNodes() const override;
virtual common::Status SetEpDynamicOptions(gsl::span<const char* const> /*keys*/,
gsl::span<const char* const> /*values*/) override;

private:
using my_ep_t = vaip_core::DllSafe<std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>>;
Expand Down

0 comments on commit 34a61e2

Please sign in to comment.