Skip to content

Commit f0cc191

Browse files
authored
Add back DxCore support to WinMLRunner (#217)
* Add back DxCore support to winmlrunner * Add delay load * Dynamic allocate description str * Fix spacing * Make adaptername comparison simpler * remove adapter index selection because there is no guarantee deterministic indexes * Updated readme
1 parent ea0ac8b commit f0cc191

File tree

6 files changed

+192
-37
lines changed

6 files changed

+192
-37
lines changed

Tools/WinMLRunner/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Required command-Line arguments:
3535
-GPU : run model on default GPU
3636
-GPUHighPerformance : run model on GPU with highest performance
3737
-GPUMinPower : run model on GPU with the least power
38+
-GPUAdapterName <adapter name substring>: run model on GPU specified by its name. NOTE: Please only use this flag on DXCore supported machines.
3839
-CreateDeviceOnClient : create the D3D device on the client and pass it to WinML to create session
3940
-CreateDeviceInWinML : create the device inside WinML
4041
-CPUBoundInput : bind the input to the CPU

Tools/WinMLRunner/WinMLRunner.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<SubSystem>Console</SubSystem>
161161
<GenerateDebugInformation>true</GenerateDebugInformation>
162162
<AdditionalDependencies>WindowsApp.lib; mincore.lib; DXGI.lib</AdditionalDependencies>
163+
<DelayLoadDLLs>"ext-ms-win-dxcore-l1-1-0.dll"</DelayLoadDLLs>
163164
</Link>
164165
<PreBuildEvent>
165166
<Command>$(ProjectDir)src\GenerateVersionStrings.cmd $(ProjectDir) $(IntDir)</Command>
@@ -185,6 +186,7 @@
185186
<SubSystem>Console</SubSystem>
186187
<GenerateDebugInformation>true</GenerateDebugInformation>
187188
<AdditionalDependencies>WindowsApp.lib; mincore.lib; DXGI.lib</AdditionalDependencies>
189+
<DelayLoadDLLs>"ext-ms-win-dxcore-l1-1-0.dll"</DelayLoadDLLs>
188190
</Link>
189191
<ResourceCompile>
190192
<AdditionalIncludeDirectories>$(IntDir)</AdditionalIncludeDirectories>
@@ -211,6 +213,7 @@
211213
<SubSystem>Console</SubSystem>
212214
<GenerateDebugInformation>true</GenerateDebugInformation>
213215
<AdditionalDependencies>WindowsApp.lib; mincore.lib; DXGI.lib</AdditionalDependencies>
216+
<DelayLoadDLLs>"ext-ms-win-dxcore-l1-1-0.dll"</DelayLoadDLLs>
214217
</Link>
215218
<ResourceCompile>
216219
<AdditionalIncludeDirectories>$(IntDir)</AdditionalIncludeDirectories>
@@ -241,6 +244,7 @@
241244
<OptimizeReferences>true</OptimizeReferences>
242245
<GenerateDebugInformation>true</GenerateDebugInformation>
243246
<AdditionalDependencies>WindowsApp.lib; mincore.lib; DXGI.lib</AdditionalDependencies>
247+
<DelayLoadDLLs>"ext-ms-win-dxcore-l1-1-0.dll"</DelayLoadDLLs>
244248
</Link>
245249
<ResourceCompile>
246250
<AdditionalIncludeDirectories>$(IntDir)</AdditionalIncludeDirectories>
@@ -272,6 +276,7 @@
272276
<OptimizeReferences>true</OptimizeReferences>
273277
<GenerateDebugInformation>true</GenerateDebugInformation>
274278
<AdditionalDependencies>WindowsApp.lib; mincore.lib; DXGI.lib</AdditionalDependencies>
279+
<DelayLoadDLLs>"ext-ms-win-dxcore-l1-1-0.dll"</DelayLoadDLLs>
275280
</Link>
276281
<ResourceCompile>
277282
<AdditionalIncludeDirectories>$(IntDir)</AdditionalIncludeDirectories>
@@ -304,6 +309,7 @@
304309
<OptimizeReferences>true</OptimizeReferences>
305310
<GenerateDebugInformation>true</GenerateDebugInformation>
306311
<AdditionalDependencies>WindowsApp.lib; mincore.lib; DXGI.lib</AdditionalDependencies>
312+
<DelayLoadDLLs>"ext-ms-win-dxcore-l1-1-0.dll"</DelayLoadDLLs>
307313
</Link>
308314
<PreBuildEvent>
309315
<Command>$(ProjectDir)src\GenerateVersionStrings.cmd $(ProjectDir) $(IntDir)</Command>

Tools/WinMLRunner/src/CommandLineArgs.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ void CommandLineArgs::PrintUsage()
1919
std::cout << " -GPU : run model on default GPU" << std::endl;
2020
std::cout << " -GPUHighPerformance : run model on GPU with highest performance" << std::endl;
2121
std::cout << " -GPUMinPower : run model on GPU with the least power" << std::endl;
22+
#ifdef DXCORE_SUPPORTED_BUILD
23+
std::cout << " -GPUAdapterName <adapter name substring>: run model on GPU specified by its name. NOTE: Please only use this flag on DXCore supported machines."
24+
<< std::endl;
25+
#endif
2226
std::cout << " -CreateDeviceOnClient : create the D3D device on the client and pass it to WinML to create session" << std::endl;
2327
std::cout << " -CreateDeviceInWinML : create the device inside WinML" << std::endl;
2428
std::cout << " -CPUBoundInput : bind the input to the CPU" << std::endl;
@@ -87,6 +91,22 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
8791
{
8892
m_useGPUMinPower = true;
8993
}
94+
#ifdef DXCORE_SUPPORTED_BUILD
95+
else if ((_wcsicmp(args[i].c_str(), L"-GPUAdapterName") == 0) || (_wcsicmp(args[i].c_str(), L"-GPUAdapterIndex") == 0))
96+
{
97+
CheckNextArgument(args, i);
98+
HMODULE library = nullptr;
99+
library = LoadLibrary(L"dxcore.dll");
100+
if (!library)
101+
{
102+
throw hresult_invalid_argument(
103+
L"ERROR: DXCORE isn't supported on this machine. "
104+
L"GpuAdapterName flag should only be used with DXCore supported machines.");
105+
}
106+
m_adapterName = args[++i];
107+
m_useGPU = true;
108+
}
109+
#endif
90110
else if ((_wcsicmp(args[i].c_str(), L"-CreateDeviceOnClient") == 0))
91111
{
92112
m_createDeviceOnClient = true;

Tools/WinMLRunner/src/CommandLineArgs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class CommandLineArgs
3030
const std::wstring& FolderPath() const { return m_modelFolderPath; }
3131
const std::wstring& ModelPath() const { return m_modelPath; }
3232
const std::wstring& TensorOutputPath() const { return m_tensorOutputPath; }
33+
#ifdef DXCORE_SUPPORTED_BUILD
34+
const std::wstring& GetGPUAdapterName() const { return m_adapterName; }
35+
#endif
3336

3437
bool UseRGB() const
3538
{
@@ -139,6 +142,9 @@ class CommandLineArgs
139142
std::wstring m_imagePath;
140143
std::wstring m_csvData;
141144
std::wstring m_inputData;
145+
#ifdef DXCORE_SUPPORTED_BUILD
146+
std::wstring m_adapterName;
147+
#endif
142148
std::wstring m_perfOutputPath;
143149
std::wstring m_tensorOutputPath;
144150
uint32_t m_numIterations = 1;

Tools/WinMLRunner/src/Common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
#include "TimerHelper.h"
2626
#include "DirectXPackedVector.h"
2727

28+
#if __has_include("dxcore.h")
29+
#include <initguid.h>
30+
#include <dxcore.h>
31+
#define DXCORE_SUPPORTED_BUILD
32+
#endif
33+
2834
enum WINML_MODEL_TEST_PERF
2935
{
3036
ENTIRE_TEST = 0,

0 commit comments

Comments
 (0)