mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-30 20:18:08 +00:00
[VitisAI] support run_options in vitisai EP end (#22029)
### Description add OnRunStart() method for Vitis AI execution provider ### Motivation and Context To dynamically obtain some runtime parameters during execution, use run_options within the Vitis AI execution provider (EP).
This commit is contained in:
parent
7727b4b909
commit
61996332ad
4 changed files with 36 additions and 1 deletions
|
|
@ -49,6 +49,9 @@ struct OrtVitisAIEpAPI {
|
|||
void (*create_ep_context_nodes)(
|
||||
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,
|
||||
vaip_core::DllSafe<std::vector<Node*>>* ret_value) = nullptr;
|
||||
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;
|
||||
void Ensure() {
|
||||
if (handle_)
|
||||
return;
|
||||
|
|
@ -73,6 +76,7 @@ struct OrtVitisAIEpAPI {
|
|||
std::ignore = env.GetSymbolFromLibrary(handle_, "vaip_get_version",
|
||||
(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));
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -105,6 +109,15 @@ std::optional<std::vector<Node*>> create_ep_context_nodes(
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
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)) {
|
||||
if (s_library_vitisaiep.vitisai_ep_on_run_start) {
|
||||
return s_library_vitisaiep.vitisai_ep_on_run_start(eps, state, get_config_entry);
|
||||
}
|
||||
return 100;
|
||||
}
|
||||
|
||||
struct MyCustomOpKernel : OpKernel {
|
||||
MyCustomOpKernel(const OpKernelInfo& info, const OrtCustomOp& op) : OpKernel(info), op_(op) {
|
||||
op_kernel_ =
|
||||
|
|
|
|||
|
|
@ -16,3 +16,7 @@ std::shared_ptr<onnxruntime::KernelRegistry> get_kernel_registry_vitisaiep();
|
|||
const std::vector<OrtCustomOpDomain*>& get_domains_vitisaiep();
|
||||
std::optional<std::vector<onnxruntime::Node*>> create_ep_context_nodes(
|
||||
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps);
|
||||
|
||||
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));
|
||||
|
|
|
|||
|
|
@ -97,4 +97,22 @@ common::Status VitisAIExecutionProvider::Compile(const std::vector<FusedNodeAndG
|
|||
return Status::OK();
|
||||
}
|
||||
|
||||
common::Status VitisAIExecutionProvider::OnRunStart(const onnxruntime::RunOptions& run_options) {
|
||||
InlinedVector<const Node*> ep_context_node_ptrs;
|
||||
auto get_config_entry = [](const void* state, const char* entry_name) -> vaip_core::DllSafe<std::string> {
|
||||
const onnxruntime::RunOptions& run_options = *static_cast<const onnxruntime::RunOptions*>(state);
|
||||
auto ret = run_options.GetConfigOptions().GetConfigEntry(std::string(entry_name));
|
||||
if (ret) {
|
||||
return vaip_core::DllSafe<std::string>(new std::string(ret.value()));
|
||||
} else {
|
||||
return {};
|
||||
};
|
||||
};
|
||||
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));
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
} // namespace onnxruntime
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class VitisAIExecutionProvider : public IExecutionProvider {
|
|||
const IKernelLookup& /*kernel_lookup*/) const override;
|
||||
|
||||
int GetDeviceId() const { return 0; }
|
||||
|
||||
common::Status OnRunStart(const onnxruntime::RunOptions& /*run_options*/) override;
|
||||
common::Status Compile(const std::vector<FusedNodeAndGraph>& fused_nodes_and_graphs,
|
||||
std::vector<NodeComputeInfo>& node_compute_funcs) override;
|
||||
std::shared_ptr<KernelRegistry> GetKernelRegistry() const override;
|
||||
|
|
|
|||
Loading…
Reference in a new issue