HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dml_provider_factory.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3 
4 #pragma once
5 
6 #pragma warning(push)
7 #pragma warning(disable : 4201) // nonstandard extension used: nameless struct/union
8 #ifdef _GAMING_XBOX_SCARLETT
9 #include <d3d12_xs.h>
10 #elif defined(_GAMING_XBOX_XBOXONE)
11 #include <d3d12_x.h>
12 #else
13 #include <d3d12.h>
14 #endif
15 #pragma warning(pop)
16 
17 #ifdef __cplusplus
18 #include <DirectML.h>
19 #else
20 struct IDMLDevice;
21 typedef struct IDMLDevice IDMLDevice;
22 #endif
23 
24 // Windows pollutes the macro space, causing a build break in constants.h.
25 #undef OPTIONAL
26 
27 #include "onnxruntime_c_api.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
34  Default = 0,
37 };
38 
39 enum OrtDmlDeviceFilter : uint32_t {
40 #ifdef ENABLE_NPU_ADAPTER_ENUMERATION
41  Any = 0xffffffff,
42  Gpu = 1 << 0,
43  Npu = 1 << 1,
44 #else
45  Gpu = 1 << 0,
46 #endif
47 };
48 
56 
60 };
61 
62 /**
63  * [[deprecated]]
64  * This export is deprecated.
65  * The OrtSessionOptionsAppendExecutionProvider_DML export on the OrtDmlApi should be used instead.
66  *
67  * Creates a DirectML Execution Provider which executes on the hardware adapter with the given device_id, also known as
68  * the adapter index. The device ID corresponds to the enumeration order of hardware adapters as given by
69  * IDXGIFactory::EnumAdapters. A device_id of 0 always corresponds to the default adapter, which is typically the
70  * primary display GPU installed on the system. A negative device_id is invalid.
71  */
72 ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id);
73 
74 /**
75  * [[deprecated]]
76  * This export is deprecated.
77  * The OrtSessionOptionsAppendExecutionProvider_DML1 export on the OrtDmlApi should be used instead.
78  *
79  * Creates a DirectML Execution Provider using the given DirectML device, and which executes work on the supplied D3D12
80  * command queue. The DirectML device and D3D12 command queue must have the same parent ID3D12Device, or an error will
81  * be returned. The D3D12 command queue must be of type DIRECT or COMPUTE (see D3D12_COMMAND_LIST_TYPE). If this
82  * function succeeds, the inference session maintains a strong reference on both the dml_device and the command_queue
83  * objects.
84  * See also: DMLCreateDevice
85  * See also: ID3D12Device::CreateCommandQueue
86  */
87 ORT_API_STATUS(OrtSessionOptionsAppendExecutionProviderEx_DML, _In_ OrtSessionOptions* options,
88  _In_ IDMLDevice* dml_device, _In_ ID3D12CommandQueue* cmd_queue);
89 
90 struct OrtDmlApi;
91 typedef struct OrtDmlApi OrtDmlApi;
92 
93 struct OrtDmlApi {
94  /**
95  * Creates a DirectML Execution Provider which executes on the hardware adapter with the given device_id, also known as
96  * the adapter index. The device ID corresponds to the enumeration order of hardware adapters as given by
97  * IDXGIFactory::EnumAdapters. A device_id of 0 always corresponds to the default adapter, which is typically the
98  * primary display GPU installed on the system. A negative device_id is invalid.
99  */
100  ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id);
101 
102  /**
103  * Creates a DirectML Execution Provider using the given DirectML device, and which executes work on the supplied D3D12
104  * command queue. The DirectML device and D3D12 command queue must have the same parent ID3D12Device, or an error will
105  * be returned. The D3D12 command queue must be of type DIRECT or COMPUTE (see D3D12_COMMAND_LIST_TYPE). If this
106  * function succeeds, the inference session maintains a strong reference on both the dml_device and the command_queue
107  * objects.
108  * See also: DMLCreateDevice
109  * See also: ID3D12Device::CreateCommandQueue
110  */
111  ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML1, _In_ OrtSessionOptions* options,
112  _In_ IDMLDevice* dml_device, _In_ ID3D12CommandQueue* cmd_queue);
113 
114  /**
115  * CreateGPUAllocationFromD3DResource
116  * This API creates a DML EP resource based on a user-specified D3D12 resource.
117  */
118  ORT_API2_STATUS(CreateGPUAllocationFromD3DResource, _In_ ID3D12Resource* d3d_resource, _Out_ void** dml_resource);
119 
120  /**
121  * FreeGPUAllocation
122  * This API frees the DML EP resource created by CreateGPUAllocationFromD3DResource.
123  */
124  ORT_API2_STATUS(FreeGPUAllocation, _In_ void* dml_resource);
125 
126  /**
127  * GetD3D12ResourceFromAllocation
128  * This API gets the D3D12 resource when an OrtValue has been allocated by the DML EP.
129  */
130  ORT_API2_STATUS(GetD3D12ResourceFromAllocation, _In_ OrtAllocator* provider, _In_ void* dml_resource, _Out_ ID3D12Resource** d3d_resource);
131 
132  /**
133  * SessionOptionsAppendExecutionProvider_DML2
134  * Creates a DirectML Execution Provider given the supplied device options that contain a performance preference
135  * (high power, low power, or default) and a device filter (None, GPU, or NPU).
136  */
137  ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML2, _In_ OrtSessionOptions* options, OrtDmlDeviceOptions* device_opts);
138 };
139 
140 #ifdef __cplusplus
141 }
142 #endif
OrtDmlDeviceFilter operator|(OrtDmlDeviceFilter a, OrtDmlDeviceFilter b)
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
OrtDmlDeviceFilter & operator^=(OrtDmlDeviceFilter &a, OrtDmlDeviceFilter b)
OrtDmlPerformancePreference Preference
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions *options, int device_id)
OrtDmlDeviceFilter operator&(OrtDmlDeviceFilter a, OrtDmlDeviceFilter b)
OrtDmlDeviceFilter
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
struct IDMLDevice IDMLDevice
OrtDmlDeviceFilter Filter
OrtDmlDeviceFilter & operator&=(OrtDmlDeviceFilter &a, OrtDmlDeviceFilter b)
OrtDmlDeviceFilter operator~(OrtDmlDeviceFilter a)
OrtDmlPerformancePreference
ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions *options, int device_id)
OrtDmlDeviceFilter operator^(OrtDmlDeviceFilter a, OrtDmlDeviceFilter b)
OrtDmlDeviceFilter & operator|=(OrtDmlDeviceFilter &a, OrtDmlDeviceFilter b)