// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once #include "core/session/onnxruntime_c_api.h" namespace OrtExecutionProviderApi { // implementation that returns the API struct ORT_API(const OrtEpApi*, GetEpApi); ORT_API_STATUS_IMPL(CreateEpDevice, _In_ OrtEpFactory* ep_factory, _In_ const OrtHardwareDevice* hardware_device, _In_opt_ const OrtKeyValuePairs* ep_metadata, _In_opt_ const OrtKeyValuePairs* ep_options, _Out_ OrtEpDevice** ep_device); ORT_API(void, ReleaseEpDevice, _Frees_ptr_opt_ OrtEpDevice* device); ORT_API_STATUS_IMPL(SessionOptionsGetEpContextConfig, _In_ const OrtSessionOptions* session_options, _Outptr_ OrtEpContextConfig** config); ORT_API(void, ReleaseEpContextConfig, _Frees_ptr_opt_ OrtEpContextConfig* config); ORT_API_STATUS_IMPL(EpContextConfigGetEpContextDataReadFunc, _In_ const OrtEpContextConfig* config, _Out_ OrtReadNamedBufferFunc* read_func, _Out_ void** state); ORT_API_STATUS_IMPL(EpContextConfigGetEpContextDataWriteFunc, _In_ const OrtEpContextConfig* config, _Out_ OrtWriteNamedBufferFunc* write_func, _Out_ void** state); ORT_API_STATUS_IMPL(EpGraphSupportInfo_AddNodesToFuse, _In_ OrtEpGraphSupportInfo* graph_support_info, _In_reads_(num_nodes) const OrtNode* const* nodes, _In_ size_t num_nodes, _In_opt_ const OrtNodeFusionOptions* node_fusion_options); ORT_API_STATUS_IMPL(EpGraphSupportInfo_AddSingleNode, _In_ OrtEpGraphSupportInfo* graph_support_info, _In_ const OrtNode* node); ORT_API(const char*, NodeComputeContext_NodeName, _In_ const OrtNodeComputeContext* context); ORT_API_STATUS_IMPL(EpDevice_AddAllocatorInfo, _In_ OrtEpDevice* ep_device, _In_ const OrtMemoryInfo* allocator_memory_info); ORT_API(const OrtMemoryDevice*, MemoryInfo_GetMemoryDevice, _In_ const OrtMemoryInfo* memory_info); ORT_API(const OrtMemoryDevice*, Value_GetMemoryDevice, _In_ const OrtValue* value); ORT_API(bool, MemoryDevice_AreEqual, _In_ const OrtMemoryDevice* a, _In_ const OrtMemoryDevice* b); ORT_API(OrtMemoryInfoDeviceType, MemoryDevice_GetDeviceType, _In_ const OrtMemoryDevice* memory_device); ORT_API(OrtDeviceMemoryType, MemoryDevice_GetMemoryType, _In_ const OrtMemoryDevice* memory_device); ORT_API(uint32_t, MemoryDevice_GetVendorId, _In_ const OrtMemoryDevice* memory_device); ORT_API(uint32_t, MemoryDevice_GetDeviceId, _In_ const OrtMemoryDevice* memory_device); ORT_API(const OrtSyncStreamImpl*, SyncStream_GetImpl, _In_ const OrtSyncStream* stream); ORT_API(uint64_t, SyncStream_GetSyncId, _In_ const OrtSyncStream* stream); ORT_API(uint64_t, GetSyncIdForLastWaitOnSyncStream, _In_ const OrtSyncStream* producer_stream, _In_ const OrtSyncStream* consumer_stream); ORT_API_STATUS_IMPL(CreateHardwareDevice, _In_ OrtHardwareDeviceType type, _In_ uint32_t vendor_id, _In_ uint32_t device_id, _In_ const char* vendor_name, _In_opt_ const OrtKeyValuePairs* metadata, _Out_ OrtHardwareDevice** hardware_device); ORT_API(void, ReleaseHardwareDevice, _Frees_ptr_opt_ OrtHardwareDevice* device); // OrtKernelRegistry ORT_API_STATUS_IMPL(CreateKernelRegistry, _Outptr_ OrtKernelRegistry** kernel_registry); ORT_API(void, ReleaseKernelRegistry, _Frees_ptr_opt_ OrtKernelRegistry* kernel_registry); ORT_API_STATUS_IMPL(KernelRegistry_AddKernel, _In_ OrtKernelRegistry* kernel_registry, _In_ const OrtKernelDef* kernel_def, _In_ OrtKernelCreateFunc kernel_create_func, _In_ void* kernel_create_func_state); // OrtKernelDefBuilder ORT_API_STATUS_IMPL(CreateKernelDefBuilder, _Outptr_ OrtKernelDefBuilder** kernel_def_builder_out); ORT_API(void, ReleaseKernelDefBuilder, _Frees_ptr_opt_ OrtKernelDefBuilder* kernel_def_builder); ORT_API_STATUS_IMPL(KernelDefBuilder_SetOperatorType, _In_ OrtKernelDefBuilder* kernel_def_builder, _In_ const char* op_type); ORT_API_STATUS_IMPL(KernelDefBuilder_SetDomain, _In_ OrtKernelDefBuilder* kernel_def_builder, _In_ const char* domain); ORT_API_STATUS_IMPL(KernelDefBuilder_SetSinceVersion, _In_ OrtKernelDefBuilder* kernel_def_builder, _In_ int since_version_start, _In_ int since_version_end); ORT_API_STATUS_IMPL(KernelDefBuilder_SetExecutionProvider, _In_ OrtKernelDefBuilder* kernel_def_builder, _In_ const char* ep_name); ORT_API_STATUS_IMPL(KernelDefBuilder_SetInputMemType, _In_ OrtKernelDefBuilder* kernel_def_builder, _In_ size_t input_index, _In_ OrtMemType mem_type); ORT_API_STATUS_IMPL(KernelDefBuilder_SetOutputMemType, _In_ OrtKernelDefBuilder* kernel_def_builder, _In_ size_t output_index, _In_ OrtMemType mem_type); ORT_API_STATUS_IMPL(KernelDefBuilder_AddTypeConstraint, _In_ OrtKernelDefBuilder* kernel_def_builder, _In_ const char* arg_name, _In_reads_(num_types) const OrtDataType* const* types, _In_ size_t num_types); ORT_API_STATUS_IMPL(KernelDefBuilder_AddInputOutputAliases, _In_ OrtKernelDefBuilder* kernel_def_builder, _In_reads_(num_io_indices) int const* input_indices, _In_reads_(num_io_indices) int const* output_indices, _In_ size_t num_io_indices); ORT_API_STATUS_IMPL(KernelDefBuilder_AddInputOutputMutableAliases, _In_ OrtKernelDefBuilder* kernel_def_builder, _In_reads_(num_io_indices) int const* input_indices, _In_reads_(num_io_indices) int const* output_indices, _In_ size_t num_io_indices); ORT_API_STATUS_IMPL(KernelDefBuilder_Build, _In_ OrtKernelDefBuilder* kernel_def_builder, _Outptr_ OrtKernelDef** kernel_def_out); // OrtKernelDef ORT_API(void, ReleaseKernelDef, _Frees_ptr_opt_ OrtKernelDef* kernel_def); ORT_API(const char*, KernelDef_GetOperatorType, _In_ const OrtKernelDef* kernel_def); ORT_API(const char*, KernelDef_GetDomain, _In_ const OrtKernelDef* kernel_def); ORT_API_STATUS_IMPL(KernelDef_GetSinceVersion, _In_ const OrtKernelDef* kernel_def, _Out_ int* start_version, _Out_ int* end_version); ORT_API(const char*, KernelDef_GetExecutionProvider, _In_ const OrtKernelDef* kernel_def); ORT_API_STATUS_IMPL(KernelDef_GetInputMemType, _In_ const OrtKernelDef* kernel_def, _In_ size_t input_index, _Out_ OrtMemType* mem_type); ORT_API_STATUS_IMPL(KernelDef_GetOutputMemType, _In_ const OrtKernelDef* kernel_def, _In_ size_t output_index, _Out_ OrtMemType* mem_type); ORT_API_STATUS_IMPL(GetTensorDataType, _In_ ONNXTensorElementDataType elem_type, _Outptr_ const OrtDataType** out); ORT_API_STATUS_IMPL(EpGraphSupportInfo_LookUpKernel, _In_ OrtEpGraphSupportInfo* graph_support_info, _In_ const OrtNode* node, _Outptr_result_maybenull_ const OrtKernelDef** out_kernel_def); ORT_API_STATUS_IMPL(SharedPrePackedWeightCache_StoreWeightData, _In_ OrtSharedPrePackedWeightCache* prepacked_weight_cache, _In_reads_(num_buffers) void** buffer_data_ptrs, _In_reads_(num_buffers) size_t* buffer_data_sizes, _In_ size_t num_buffers); // KernelInfo ORT_API_STATUS_IMPL(KernelInfo_GetEp, _In_ const OrtKernelInfo* info, _Outptr_ const OrtEp** ep); // Control flow kernel APIs ORT_API_STATUS_IMPL(CreateIfKernel, _In_ const OrtKernelInfo* kernel_info, _Outptr_ OrtKernelImpl** kernel_out); ORT_API_STATUS_IMPL(CreateLoopKernel, _In_ const OrtKernelInfo* kernel_info, _In_ OrtLoopKernelHelper* helper, _Outptr_ OrtKernelImpl** kernel_out); ORT_API_STATUS_IMPL(CreateScanKernel, _In_ const OrtKernelInfo* kernel_info, _In_ OrtScanKernelHelper* helper, _Outptr_ OrtKernelImpl** kernel_out); ORT_API(void, ReleaseKernelImpl, _Frees_ptr_opt_ OrtKernelImpl* kernel_impl); // Env config entries ORT_API_STATUS_IMPL(GetEnvConfigEntries, _Outptr_ OrtKeyValuePairs** config_entries); // OpSchema APIs ORT_API_STATUS_IMPL(GetOpSchema, _In_ const char* name, _In_ int max_inclusive_version, _In_ const char* domain, _Outptr_result_maybenull_ OrtOpSchema** out_schema); ORT_API(void, ReleaseOpSchema, _Frees_ptr_opt_ OrtOpSchema* schema); ORT_API_STATUS_IMPL(OpSchema_GetSinceVersion, _In_ const OrtOpSchema* schema, _Out_ int* out); ORT_API_STATUS_IMPL(OpSchema_GetNumInputs, _In_ const OrtOpSchema* schema, _Out_ size_t* out); ORT_API_STATUS_IMPL(OpSchema_GetInputName, _In_ const OrtOpSchema* schema, _In_ size_t index, _Outptr_ const char** out); ORT_API_STATUS_IMPL(OpSchema_GetInputTypeConstraint, _In_ const OrtOpSchema* schema, _In_ size_t index, _Outptr_result_maybenull_ const OrtOpSchemaTypeConstraint** out); ORT_API_STATUS_IMPL(OpSchema_GetNumOutputs, _In_ const OrtOpSchema* schema, _Out_ size_t* out); ORT_API_STATUS_IMPL(OpSchema_GetOutputName, _In_ const OrtOpSchema* schema, _In_ size_t index, _Outptr_ const char** out); ORT_API_STATUS_IMPL(OpSchema_GetOutputTypeConstraint, _In_ const OrtOpSchema* schema, _In_ size_t index, _Outptr_result_maybenull_ const OrtOpSchemaTypeConstraint** out); ORT_API_STATUS_IMPL(OpSchema_GetTypeConstraintCount, _In_ const OrtOpSchema* schema, _Out_ size_t* out); ORT_API_STATUS_IMPL(OpSchema_GetTypeConstraint, _In_ const OrtOpSchema* schema, _In_ size_t index, _Outptr_ const OrtOpSchemaTypeConstraint** out); ORT_API_STATUS_IMPL(OpSchemaTypeConstraint_GetTypeParamName, _In_ const OrtOpSchemaTypeConstraint* type_constraint, _Outptr_ const char** out); ORT_API_STATUS_IMPL(OpSchemaTypeConstraint_GetAllowedTypes, _In_ const OrtOpSchemaTypeConstraint* type_constraint, _Outptr_ const char* const** out_types, _Out_ size_t* num_types); ORT_API_STATUS_IMPL(OpSchemaTypeConstraint_GetInputIndices, _In_ const OrtOpSchemaTypeConstraint* type_constraint, _Outptr_ const size_t** out_indices, _Out_ size_t* count); ORT_API_STATUS_IMPL(OpSchemaTypeConstraint_GetOutputIndices, _In_ const OrtOpSchemaTypeConstraint* type_constraint, _Outptr_ const size_t** out_indices, _Out_ size_t* count); // EP profiling events container ORT_API_STATUS_IMPL(ProfilingEventsContainer_AddEvents, _In_ OrtProfilingEventsContainer* events_container, _In_reads_(num_events) const OrtProfilingEvent* const* events, _In_ size_t num_events); // EP profiling event creation/release ORT_API_STATUS_IMPL(CreateProfilingEvent, _In_ OrtProfilingEventCategory category, _In_ int32_t process_id, _In_ int32_t thread_id, _In_ const char* event_name, _In_ int64_t timestamp_us, _In_ int64_t duration_us, _In_reads_(num_args) const char* const* arg_keys, _In_reads_(num_args) const char* const* arg_values, _In_ size_t num_args, _Outptr_ OrtProfilingEvent** out); ORT_API(void, ReleaseProfilingEvent, _Frees_ptr_opt_ OrtProfilingEvent* event); // Profiling event accessors ORT_API_STATUS_IMPL(ProfilingEvent_GetCategory, _In_ const OrtProfilingEvent* event, _Out_ OrtProfilingEventCategory* out); ORT_API_STATUS_IMPL(ProfilingEvent_GetName, _In_ const OrtProfilingEvent* event, _Outptr_ const char** out); ORT_API_STATUS_IMPL(ProfilingEvent_GetTimestampUs, _In_ const OrtProfilingEvent* event, _Out_ int64_t* out); ORT_API_STATUS_IMPL(ProfilingEvent_GetDurationUs, _In_ const OrtProfilingEvent* event, _Out_ int64_t* out); ORT_API_STATUS_IMPL(ProfilingEvent_GetArgValue, _In_ const OrtProfilingEvent* event, _In_ const char* key, _Outptr_result_maybenull_ const char** out); // Weightless source model getter ORT_API_STATUS_IMPL(SessionOptionsGetWeightlessSourceModelBuffer, _In_ const OrtSessionOptions* session_options, _Outptr_result_maybenull_ const void** source_model_data, _Out_ size_t* source_model_data_length); } // namespace OrtExecutionProviderApi