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 
33 /**
34  * [[deprecated]]
35  * This export is deprecated.
36  * The OrtSessionOptionsAppendExecutionProvider_DML export on the OrtDmlApi should be used instead.
37  *
38  * Creates a DirectML Execution Provider which executes on the hardware adapter with the given device_id, also known as
39  * the adapter index. The device ID corresponds to the enumeration order of hardware adapters as given by
40  * IDXGIFactory::EnumAdapters. A device_id of 0 always corresponds to the default adapter, which is typically the
41  * primary display GPU installed on the system. A negative device_id is invalid.
42  */
43 ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id);
44 
45 /**
46  * [[deprecated]]
47  * This export is deprecated.
48  * The OrtSessionOptionsAppendExecutionProvider_DML1 export on the OrtDmlApi should be used instead.
49  *
50  * Creates a DirectML Execution Provider using the given DirectML device, and which executes work on the supplied D3D12
51  * command queue. The DirectML device and D3D12 command queue must have the same parent ID3D12Device, or an error will
52  * be returned. The D3D12 command queue must be of type DIRECT or COMPUTE (see D3D12_COMMAND_LIST_TYPE). If this
53  * function succeeds, the inference session maintains a strong reference on both the dml_device and the command_queue
54  * objects.
55  * See also: DMLCreateDevice
56  * See also: ID3D12Device::CreateCommandQueue
57  */
58 ORT_API_STATUS(OrtSessionOptionsAppendExecutionProviderEx_DML, _In_ OrtSessionOptions* options,
59  _In_ IDMLDevice* dml_device, _In_ ID3D12CommandQueue* cmd_queue);
60 
61 
62 struct OrtDmlApi;
63 typedef struct OrtDmlApi OrtDmlApi;
64 
65 struct OrtDmlApi {
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_API2_STATUS(SessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions* options, int device_id);
73 
74  /**
75  * Creates a DirectML Execution Provider using the given DirectML device, and which executes work on the supplied D3D12
76  * command queue. The DirectML device and D3D12 command queue must have the same parent ID3D12Device, or an error will
77  * be returned. The D3D12 command queue must be of type DIRECT or COMPUTE (see D3D12_COMMAND_LIST_TYPE). If this
78  * function succeeds, the inference session maintains a strong reference on both the dml_device and the command_queue
79  * objects.
80  * See also: DMLCreateDevice
81  * See also: ID3D12Device::CreateCommandQueue
82  */
83  ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML1, _In_ OrtSessionOptions* options,
84  _In_ IDMLDevice* dml_device, _In_ ID3D12CommandQueue* cmd_queue);
85 
86  /**
87  * CreateGPUAllocationFromD3DResource
88  * This API creates a DML EP resource based on a user-specified D3D12 resource.
89  */
90  ORT_API2_STATUS(CreateGPUAllocationFromD3DResource, _In_ ID3D12Resource* d3d_resource, _Out_ void** dml_resource);
91 
92  /**
93  * FreeGPUAllocation
94  * This API frees the DML EP resource created by CreateGPUAllocationFromD3DResource.
95  */
96  ORT_API2_STATUS(FreeGPUAllocation, _In_ void* dml_resource);
97 
98  /**
99  * GetD3D12ResourceFromAllocation
100  * This API gets the D3D12 resource when an OrtValue has been allocated by the DML EP.
101  */
102  ORT_API2_STATUS(GetD3D12ResourceFromAllocation, _In_ OrtAllocator* provider, _In_ void* dml_resource, _Out_ ID3D12Resource** d3d_resource);
103 };
104 
105 #ifdef __cplusplus
106 }
107 #endif
#define _In_
ORT_API_STATUS(OrtSessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions *options, int device_id)
struct IDMLDevice IDMLDevice
#define _Out_
Memory allocation interface.
ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML, _In_ OrtSessionOptions *options, int device_id)