// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once #include #include "core/common/inlined_containers_fwd.h" #include "core/session/onnxruntime_c_api.h" #include "core/framework/allocator.h" #include "core/framework/data_types.h" #include "core/framework/error_code_helper.h" #include "core/framework/kernel_def_builder.h" #include "core/framework/kernel_registry.h" #include "core/framework/op_kernel.h" #include "core/framework/prepacked_weights.h" /// /// Implementation of the public C API opaque type OrtSharedPrePackedWeightCache used by plugin EP kernels. /// This wraps and fills out an instance of onnxruntime::PrePackedWeights via the /// C API SharedPrePackedWeightCache_StoreWeightData. /// struct OrtSharedPrePackedWeightCache { /// /// Constructs an OrtSharedPrePackedWeightCache that will fill out the provided PrePackedWeights object. /// /// The PrePackedWeights container to fill out. /// The allocator that will be used to free buffers set by the call to SetBuffers(). OrtSharedPrePackedWeightCache(onnxruntime::PrePackedWeights& container, onnxruntime::AllocatorPtr allocator); /// /// Sets data buffers for the shared weight. Ownership of the buffers is transferred to this class's contained /// PrePackedWeights instance, which will delete the buffers with `this->allocator_`. /// The buffer data is required to have been allocated with `this->allocator_`. /// Refer to OrtKernelImpl::PrePackWeight and OrtEpApi::SharedPrePackedWeightCache_StoreWeightData. /// /// /// /// void SetBuffers(void** data_ptrs, size_t* data_sizes, size_t num_buffers); /// /// Returns true if this instance has any weight buffer data. /// /// bool HasData() const noexcept; /// /// Releases all buffer data. /// Used within OrtEpApi::SharedPrePackedWeightCache_StoreWeightData() if an error occurs and ORT wants to /// release all data to allow caller to retain ownership of data. /// void ReleaseAllData() noexcept; private: onnxruntime::PrePackedWeights& container_; onnxruntime::AllocatorPtr allocator_; }; namespace onnxruntime { /// /// Make a KernelCreateInfo for a plugin EP's kernel. A KernelCreateInfo contains the function and state /// necessary to create a kernel. /// /// /// /// /// KernelCreateInfo MakePluginEpKernelCreateInfo(const KernelDef* kernel_def, OrtKernelCreateFunc kernel_create_func, void* kernel_create_func_state); /// /// Gets the kernel registry for a plugin EP. /// /// The OrtEp instance. /// Output parameter set to the EP's registry. /// A status indicating success or an error Status GetPluginEpKernelRegistry(OrtEp& ort_ep, /*out*/ std::shared_ptr& kernel_registry); } // namespace onnxruntime