Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for NPU Device Selection in the DML EP #17612

Merged
merged 36 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4679d85
Add API
nums11 Sep 11, 2023
552a97b
Updates
nums11 Sep 15, 2023
3625fe3
Updates
nums11 Sep 19, 2023
4d1b6ae
Remove comments
nums11 Sep 19, 2023
d3cd274
Remove new lines
nums11 Sep 19, 2023
6595e84
Use vectors
nums11 Sep 19, 2023
d8d3d8c
Change device option names
nums11 Sep 19, 2023
a4498f6
Explicitly assign flag values
nums11 Sep 19, 2023
9e1fff5
Remove extra code
nums11 Sep 19, 2023
f103283
Fix function casing
nums11 Sep 19, 2023
1ecd83c
Add IsGPU and IsNPU
nums11 Sep 19, 2023
86c9ec3
Move hardware adapter check
nums11 Sep 19, 2023
3f67ae4
Use snake case
nums11 Sep 19, 2023
bd8200c
Pass by pointer
nums11 Sep 19, 2023
9a32189
Change implementation
nums11 Sep 20, 2023
ff87aa2
Change API Name
nums11 Sep 21, 2023
1acc7c8
Use Enum instead of Enum class
nums11 Sep 21, 2023
566f309
Use statics
nums11 Sep 21, 2023
7160188
Update sorting policy
nums11 Sep 21, 2023
de6aa17
Updates
nums11 Sep 21, 2023
ebdb6b0
Link DXCore
nums11 Sep 21, 2023
4f2349f
Combine Create functions
nums11 Sep 22, 2023
142150f
Merge branch 'main' into npu_with_dml_ep
Oct 6, 2023
ffa7d7e
refactor
Oct 9, 2023
1dc12ef
extra param unused
Oct 10, 2023
1b6653a
snake case
Oct 10, 2023
41a7e4f
nullcheck device options
Oct 10, 2023
c7cdb56
&
Oct 10, 2023
02808d6
add todo
Oct 10, 2023
16f857a
Merge branch 'main' into npu_with_dml_ep
Oct 10, 2023
df4f554
non-const
Oct 10, 2023
463f3db
lint
Oct 10, 2023
76b6cf1
ifdef dml and readd missing dxcore link
Oct 10, 2023
3d4267e
DirectML->DML
Oct 10, 2023
e5bf35f
lintrunner
Oct 11, 2023
b535f4b
lint
Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/onnxruntime_providers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@ endif()

if (onnxruntime_USE_AZURE)
include(onnxruntime_providers_azure.cmake)
endif()
endif()
6 changes: 3 additions & 3 deletions cmake/onnxruntime_providers_dml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
if (GDK_PLATFORM STREQUAL Scarlett)
target_link_libraries(onnxruntime_providers_dml PRIVATE ${gdk_dx_libs})
else()
target_link_libraries(onnxruntime_providers_dml PRIVATE dxguid.lib d3d12.lib dxgi.lib)
target_link_libraries(onnxruntime_providers_dml PRIVATE dxguid.lib d3d12.lib dxgi.lib dxcore.lib)
endif()

target_link_libraries(onnxruntime_providers_dml PRIVATE delayimp.lib)

if (NOT GDK_PLATFORM)
set(onnxruntime_DELAYLOAD_FLAGS "${onnxruntime_DELAYLOAD_FLAGS} /DELAYLOAD:DirectML.dll /DELAYLOAD:d3d12.dll /DELAYLOAD:dxgi.dll /DELAYLOAD:api-ms-win-core-com-l1-1-0.dll /DELAYLOAD:shlwapi.dll /DELAYLOAD:oleaut32.dll /ignore:4199")
set(onnxruntime_DELAYLOAD_FLAGS "${onnxruntime_DELAYLOAD_FLAGS} /DELAYLOAD:DirectML.dll /DELAYLOAD:d3d12.dll /DELAYLOAD:dxgi.dll /DELAYLOAD:api-ms-win-core-com-l1-1-0.dll /DELAYLOAD:shlwapi.dll /DELAYLOAD:oleaut32.dll /DELAYLOAD:ext-ms-win-dxcore-l1-*.dll /ignore:4199")
endif()

target_compile_definitions(onnxruntime_providers_dml
Expand All @@ -88,4 +88,4 @@
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
endif()
32 changes: 32 additions & 0 deletions include/onnxruntime/core/providers/dml/dml_provider_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ typedef struct IDMLDevice IDMLDevice;
extern "C" {
#endif

enum OrtDmlPerformancePreference {
Default = 0,
HighPerformance = 1,
MinimumPower = 2
};

enum OrtDmlDeviceFilter : uint32_t {
Any = 0xffffffff,
Gpu = 1 << 0,
Npu = 1 << 1,
};

inline OrtDmlDeviceFilter operator~(OrtDmlDeviceFilter a) { return (OrtDmlDeviceFilter) ~(int)a; }
inline OrtDmlDeviceFilter operator|(OrtDmlDeviceFilter a, OrtDmlDeviceFilter b) { return (OrtDmlDeviceFilter)((int)a | (int)b); }
inline OrtDmlDeviceFilter operator&(OrtDmlDeviceFilter a, OrtDmlDeviceFilter b) { return (OrtDmlDeviceFilter)((int)a & (int)b); }
inline OrtDmlDeviceFilter operator^(OrtDmlDeviceFilter a, OrtDmlDeviceFilter b) { return (OrtDmlDeviceFilter)((int)a ^ (int)b); }
inline OrtDmlDeviceFilter& operator|=(OrtDmlDeviceFilter& a, OrtDmlDeviceFilter b) { return (OrtDmlDeviceFilter&)((int&)a |= (int)b); }
inline OrtDmlDeviceFilter& operator&=(OrtDmlDeviceFilter& a, OrtDmlDeviceFilter b) { return (OrtDmlDeviceFilter&)((int&)a &= (int)b); }
inline OrtDmlDeviceFilter& operator^=(OrtDmlDeviceFilter& a, OrtDmlDeviceFilter b) { return (OrtDmlDeviceFilter&)((int&)a ^= (int)b); }

struct OrtDmlDeviceOptions {
OrtDmlPerformancePreference Preference;
OrtDmlDeviceFilter Filter;
};

/**
* [[deprecated]]
* This export is deprecated.
Expand Down Expand Up @@ -99,6 +124,13 @@ struct OrtDmlApi {
* This API gets the D3D12 resource when an OrtValue has been allocated by the DML EP.
*/
ORT_API2_STATUS(GetD3D12ResourceFromAllocation, _In_ OrtAllocator* provider, _In_ void* dml_resource, _Out_ ID3D12Resource** d3d_resource);

/**
* SessionOptionsAppendExecutionProvider_DML2
* Creates a DirectML Execution Provider given the supplied device options that contain a performance preference
* (high power, low power, or defult) and a device filter (None, GPU, or NPU).
*/
ORT_API2_STATUS(SessionOptionsAppendExecutionProvider_DML2, _In_ OrtSessionOptions* options, OrtDmlDeviceOptions* device_opts);
};

#ifdef __cplusplus
Expand Down
Loading