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 
31 extern "C" {
32 
33 enum OrtDmlDeviceFilter : uint32_t {
34 #ifdef ENABLE_NPU_ADAPTER_ENUMERATION
35  Any = 0xffffffff,
36  Gpu = 1 << 0,
37  Npu = 1 << 1,
38 #else
39  Gpu = 1 << 0,
40 #endif
41 };
42 
47 inline OrtDmlDeviceFilter& operator|=(OrtDmlDeviceFilter& a, OrtDmlDeviceFilter b) { return (OrtDmlDeviceFilter&)((int&)a |= (int)b); }
48 inline OrtDmlDeviceFilter& operator&=(OrtDmlDeviceFilter& a, OrtDmlDeviceFilter b) { return (OrtDmlDeviceFilter&)((int&)a &= (int)b); }
49 inline OrtDmlDeviceFilter& operator^=(OrtDmlDeviceFilter& a, OrtDmlDeviceFilter b) { return (OrtDmlDeviceFilter&)((int&)a ^= (int)b); }
50 
51 #else
52 
53 typedef enum OrtDmlDeviceFilter {
54 #ifdef ENABLE_NPU_ADAPTER_ENUMERATION
55  Any = 0xffffffff,
56  Gpu = 1 << 0,
57  Npu = 1 << 1,
58 #else
59  Gpu = 1 << 0,
60 #endif
62 
63 #endif
64 
66  Default = 0,
70 
74 };
75 
77 
78 /**
79  * [[deprecated]]
80  * This export is deprecated.
81  * The OrtSessionOptionsAppendExecutionProvider_DML export on the OrtDmlApi should be used instead.
82  *
83  * Creates a DirectML Execution Provider which executes on the hardware adapter with the given device_id, also known as
84  * the adapter index. The device ID corresponds to the enumeration order of hardware adapters as given by
85  * IDXGIFactory::EnumAdapters. A device_id of 0 always corresponds to the default adapter, which is typically the
86  * primary display GPU installed on the system. A negative device_id is invalid.
87  */
88 ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id);
89 
90 /**
91  * [[deprecated]]
92  * This export is deprecated.
93  * The OrtSessionOptionsAppendExecutionProvider_DML1 export on the OrtDmlApi should be used instead.
94  *
95  * Creates a DirectML Execution Provider using the given DirectML device, and which executes work on the supplied D3D12
96  * command queue. The DirectML device and D3D12 command queue must have the same parent ID3D12Device, or an error will
97  * be returned. The D3D12 command queue must be of type DIRECT or COMPUTE (see D3D12_COMMAND_LIST_TYPE). If this
98  * function succeeds, the inference session maintains a strong reference on both the dml_device and the command_queue
99  * objects.
100  * See also: DMLCreateDevice
101  * See also: ID3D12Device::CreateCommandQueue
102  */
103 ORT_API_STATUS(OrtSessionOptionsAppendExecutionProviderEx_DML, _In_ OrtSessionOptions* options,
104  _In_ IDMLDevice* dml_device, _In_ ID3D12CommandQueue* cmd_queue);
105 
106 struct OrtDmlApi;
107 typedef struct OrtDmlApi OrtDmlApi;
108 
109 struct OrtDmlApi {
110  /**
111  * Creates a DirectML Execution Provider which executes on the hardware adapter with the given device_id, also known as
112  * the adapter index. The device ID corresponds to the enumeration order of hardware adapters as given by
113  * IDXGIFactory::EnumAdapters. A device_id of 0 always corresponds to the default adapter, which is typically the
114  * primary display GPU installed on the system. A negative device_id is invalid.
115  */
116  ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id);
117 
118  /**
119  * Creates a DirectML Execution Provider using the given DirectML device, and which executes work on the supplied D3D12
120  * command queue. The DirectML device and D3D12 command queue must have the same parent ID3D12Device, or an error will
121  * be returned. The D3D12 command queue must be of type DIRECT or COMPUTE (see D3D12_COMMAND_LIST_TYPE). If this
122  * function succeeds, the inference session maintains a strong reference on both the dml_device and the command_queue
123  * objects.
124  * See also: DMLCreateDevice
125  * See also: ID3D12Device::CreateCommandQueue
126  */
127  ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML1, _In_ OrtSessionOptions* options,
128  _In_ IDMLDevice* dml_device, _In_ ID3D12CommandQueue* cmd_queue);
129 
130  /**
131  * CreateGPUAllocationFromD3DResource
132  * This API creates a DML EP resource based on a user-specified D3D12 resource.
133  */
134  ORT_API2_STATUS(CreateGPUAllocationFromD3DResource, _In_ ID3D12Resource* d3d_resource, _Out_ void** dml_resource);
135 
136  /**
137  * FreeGPUAllocation
138  * This API frees the DML EP resource created by CreateGPUAllocationFromD3DResource.
139  */
140  ORT_API2_STATUS(FreeGPUAllocation, _In_ void* dml_resource);
141 
142  /**
143  * GetD3D12ResourceFromAllocation
144  * This API gets the D3D12 resource when an OrtValue has been allocated by the DML EP.
145  */
146  ORT_API2_STATUS(GetD3D12ResourceFromAllocation, _In_ OrtAllocator* provider, _In_ void* dml_resource, _Out_ ID3D12Resource** d3d_resource);
147 
148  /**
149  * SessionOptionsAppendExecutionProvider_DML2
150  * Creates a DirectML Execution Provider given the supplied device options that contain a performance preference
151  * (high power, low power, or default) and a device filter (None, GPU, or NPU).
152  */
153  ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML2, _In_ OrtSessionOptions* options, OrtDmlDeviceOptions* device_opts);
154 };
155 
156 #ifdef __cplusplus
157 }
158 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
const TypeMask operator~(const TypeMask &m1)
Definition: GA_PrimCompat.h:95
OrtDmlPerformancePreference Preference
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
std::enable_if< UT_EnableBitMask< T >::enable, T & >::type operator&=(T &lhs, T rhs)
Definition: UT_EnumHelper.h:57
OrtDmlDeviceFilter
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions *options, int device_id)
const TypeMask operator|(const TypeMask &m1, const TypeMask &m2)
Definition: GA_PrimCompat.h:79
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
const TypeMask operator&(const TypeMask &m1, const TypeMask &m2)
Definition: GA_PrimCompat.h:84
struct IDMLDevice IDMLDevice
OrtDmlDeviceFilter Filter
std::enable_if< UT_EnableBitMask< T >::enable, T & >::type operator^=(T &lhs, T rhs)
Definition: UT_EnumHelper.h:76
OrtDmlPerformancePreference
ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions *options, int device_id)
std::enable_if< UT_EnableBitMask< T >::enable, T & >::type operator|=(T &lhs, T rhs)
Definition: UT_EnumHelper.h:37
const TypeMask operator^(const TypeMask &m1, const TypeMask &m2)
Definition: GA_PrimCompat.h:90