Skip to content

Commit 9611084

Browse files
author
Ryan Lai
authored
Merge MCDM GPUAdapterIndex selection into master (#155)
* Update GPUAdapterIndex option * Support MCDM but use DIRECT command queue to allow GPU tensorization of image * Test out DXCore * Compatibility: Use DXGI adapter, 11_0 feature level and DIRECT command queue for regular GPU * Use delay-load for dxgi and d3d11, use 18298 SDK and use static lib for debug build * Remove dependency on kernel32.dll * Support WCOSHeadless which doesn't have DXGI and D3D11 * Handle exception from delayed load * Generate full PDB for debug build * Handle delayed load SEH in a CreateDXGIFactorySEH * Removing workaround for X86 DXCore, fix is grfx_dev 18318 and EEAP rs_prerelease 18323.1000.190119-1745 or newer * Fix merge erros * Delayload dxcore * Throws error message if dxcore isn't supported * Added extra checking for gpuadapter index flag argument * Removed unnecessary files * Added IsApiSetIMplemented * Static link onecore on other architectures as well * Added error checking to see if dxcore is available * Prints out all adapter enumerations * Added extra warning information about dxcore support.NEeds SDKat least 18323
1 parent 2223c71 commit 9611084

File tree

10 files changed

+235
-31
lines changed

10 files changed

+235
-31
lines changed

Testing/WinMLRunnerTest/WinMLRunnerTest.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ProjectGuid>{E9D4AC92-8295-4FB4-BF7D-3FAF74B564E8}</ProjectGuid>
2424
<Keyword>Win32Proj</Keyword>
2525
<RootNamespace>WinMLRunnerTest</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0.18323.0</WindowsTargetPlatformVersion>
2727
<ProjectSubType>NativeUnitTestProject</ProjectSubType>
2828
</PropertyGroup>
2929
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

Tools/WinMLRunner/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The WinMLRunner is a command-line based tool that can run .onnx or .pb models wh
66
## Prerequisites
77
- [Visual Studio 2017 Version 15.7.4 or Newer](https://developer.microsoft.com/en-us/windows/downloads)
88
- [Windows 10 - Build 17763 or higher](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewiso)
9-
- [Windows SDK - Build 17763 or higher](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewSDK)
9+
- [Windows SDK - Build 18323 or higher](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewSDK)
1010

1111
## Build the tool
1212

@@ -28,6 +28,7 @@ Required command-Line arguments:
2828
-GPU : Will create a session on the GPU.
2929
-GPUHighPerformance : Will create a session with the most powerful GPU device available.
3030
-GPUMinPower : Will create a session with GPU with the least power.
31+
-GPUAdapterIndex : run model on GPU specified by its index in DXGI enumeration. NOTE: Please only use this flag on DXCore supported machines.
3132
-CreateDeviceOnClient : Will create the device on the client and explicitly pass it to WinML via the API. GPU runs using this flag will usually be faster than -CreateDeviceInWinML since we avoid a cross-device copy by creating the video frame on the same device that DML uses to bind inputs.
3233
-CreateDeviceInWinML : Will create the device inside WinML. GPU runs using this flag will usually be slower than -CreateDeviceOnClient since we have to copy the video frame to a different device.
3334
-CPUBoundInput : Will bind the input to the CPU.

Tools/WinMLRunner/WinMLRunner.vcxproj

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<ProjectGuid>{31653A2F-02CC-4A95-9880-BF86965FB262}</ProjectGuid>
4646
<Keyword>Win32Proj</Keyword>
4747
<RootNamespace>WinMLRunner</RootNamespace>
48-
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
48+
<WindowsTargetPlatformVersion>10.0.18323.0</WindowsTargetPlatformVersion>
4949
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
5050
</PropertyGroup>
5151
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@@ -74,6 +74,7 @@
7474
<PlatformToolset>v141</PlatformToolset>
7575
<WholeProgramOptimization>true</WholeProgramOptimization>
7676
<CharacterSet>Unicode</CharacterSet>
77+
<WindowsAppContainer>false</WindowsAppContainer>
7778
</PropertyGroup>
7879
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
7980
<ConfigurationType>Application</ConfigurationType>
@@ -144,6 +145,7 @@
144145
<WarningLevel>Level3</WarningLevel>
145146
<Optimization>Disabled</Optimization>
146147
<SDLCheck>true</SDLCheck>
148+
<ShowIncludes>true</ShowIncludes>
147149
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
148150
<ConformanceMode>true</ConformanceMode>
149151
<PrecompiledHeaderFile>
@@ -154,8 +156,14 @@
154156
</ClCompile>
155157
<Link>
156158
<SubSystem>Console</SubSystem>
157-
<GenerateDebugInformation>true</GenerateDebugInformation>
158-
<AdditionalDependencies>WindowsApp.lib</AdditionalDependencies>
159+
<AdditionalDependencies>mincore.lib;windowsapp.lib;d3d12.lib;dxgi.lib;d3d11.lib;onecore.lib</AdditionalDependencies>
160+
<AdditionalOptions>
161+
</AdditionalOptions>
162+
<DelayLoadDLLs>dxgi.dll;d3d11.dll; ext-ms-win-dxcore-l1-1-0.dll</DelayLoadDLLs>
163+
<IgnoreAllDefaultLibraries>
164+
</IgnoreAllDefaultLibraries>
165+
<IgnoreSpecificDefaultLibraries>kernel32.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
166+
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
159167
</Link>
160168
</ItemDefinitionGroup>
161169
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@@ -170,11 +178,18 @@
170178
</PrecompiledHeaderFile>
171179
<PrecompiledHeaderOutputFile />
172180
<LanguageStandard>stdcpp17</LanguageStandard>
181+
<ConformanceMode>true</ConformanceMode>
173182
</ClCompile>
174183
<Link>
175184
<SubSystem>Console</SubSystem>
176-
<GenerateDebugInformation>true</GenerateDebugInformation>
177-
<AdditionalDependencies>WindowsApp.lib</AdditionalDependencies>
185+
<AdditionalDependencies>mincore.lib;windowsapp.lib;d3d12.lib;dxgi.lib;d3d11.lib;onecore.lib</AdditionalDependencies>
186+
<AdditionalOptions>
187+
</AdditionalOptions>
188+
<DelayLoadDLLs>dxgi.dll;d3d11.dll; ext-ms-win-dxcore-l1-1-0.dll</DelayLoadDLLs>
189+
<IgnoreAllDefaultLibraries>
190+
</IgnoreAllDefaultLibraries>
191+
<IgnoreSpecificDefaultLibraries>kernel32.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
192+
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
178193
</Link>
179194
</ItemDefinitionGroup>
180195
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
@@ -193,8 +208,14 @@
193208
</ClCompile>
194209
<Link>
195210
<SubSystem>Console</SubSystem>
196-
<GenerateDebugInformation>true</GenerateDebugInformation>
197-
<AdditionalDependencies>WindowsApp.lib</AdditionalDependencies>
211+
<AdditionalDependencies>mincore.lib;windowsapp.lib;d3d12.lib;dxgi.lib;d3d11.lib;onecore.lib</AdditionalDependencies>
212+
<AdditionalOptions>
213+
</AdditionalOptions>
214+
<DelayLoadDLLs>dxgi.dll;d3d11.dll; ext-ms-win-dxcore-l1-1-0.dll</DelayLoadDLLs>
215+
<IgnoreAllDefaultLibraries>
216+
</IgnoreAllDefaultLibraries>
217+
<IgnoreSpecificDefaultLibraries>kernel32.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
218+
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
198219
</Link>
199220
</ItemDefinitionGroup>
200221
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -205,6 +226,7 @@
205226
<FunctionLevelLinking>true</FunctionLevelLinking>
206227
<IntrinsicFunctions>true</IntrinsicFunctions>
207228
<SDLCheck>true</SDLCheck>
229+
<ShowIncludes>true</ShowIncludes>
208230
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
209231
<ConformanceMode>true</ConformanceMode>
210232
<PrecompiledHeaderFile>
@@ -214,11 +236,16 @@
214236
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
215237
</ClCompile>
216238
<Link>
217-
<SubSystem>Console</SubSystem>
218239
<EnableCOMDATFolding>true</EnableCOMDATFolding>
219240
<OptimizeReferences>true</OptimizeReferences>
220-
<GenerateDebugInformation>true</GenerateDebugInformation>
221-
<AdditionalDependencies>WindowsApp.lib</AdditionalDependencies>
241+
<SubSystem>Console</SubSystem>
242+
<AdditionalDependencies>mincore.lib;windowsapp.lib;d3d12.lib;dxgi.lib;d3d11.lib;onecore.lib</AdditionalDependencies>
243+
<AdditionalOptions>
244+
</AdditionalOptions>
245+
<DelayLoadDLLs>dxgi.dll;d3d11.dll; ext-ms-win-dxcore-l1-1-0.dll</DelayLoadDLLs>
246+
<IgnoreAllDefaultLibraries>
247+
</IgnoreAllDefaultLibraries>
248+
<IgnoreSpecificDefaultLibraries>kernel32.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
222249
</Link>
223250
</ItemDefinitionGroup>
224251
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
@@ -239,11 +266,16 @@
239266
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
240267
</ClCompile>
241268
<Link>
242-
<SubSystem>Console</SubSystem>
243269
<EnableCOMDATFolding>true</EnableCOMDATFolding>
244270
<OptimizeReferences>true</OptimizeReferences>
245-
<GenerateDebugInformation>true</GenerateDebugInformation>
246-
<AdditionalDependencies>WindowsApp.lib</AdditionalDependencies>
271+
<SubSystem>Console</SubSystem>
272+
<AdditionalDependencies>mincore.lib;windowsapp.lib;d3d12.lib;dxgi.lib;d3d11.lib;onecore.lib</AdditionalDependencies>
273+
<AdditionalOptions>
274+
</AdditionalOptions>
275+
<DelayLoadDLLs>dxgi.dll;d3d11.dll; ext-ms-win-dxcore-l1-1-0.dll</DelayLoadDLLs>
276+
<IgnoreAllDefaultLibraries>
277+
</IgnoreAllDefaultLibraries>
278+
<IgnoreSpecificDefaultLibraries>kernel32.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
247279
</Link>
248280
</ItemDefinitionGroup>
249281
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -264,11 +296,16 @@
264296
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
265297
</ClCompile>
266298
<Link>
267-
<SubSystem>Console</SubSystem>
268299
<EnableCOMDATFolding>true</EnableCOMDATFolding>
269300
<OptimizeReferences>true</OptimizeReferences>
270-
<GenerateDebugInformation>true</GenerateDebugInformation>
271-
<AdditionalDependencies>WindowsApp.lib</AdditionalDependencies>
301+
<SubSystem>Console</SubSystem>
302+
<AdditionalDependencies>mincore.lib;windowsapp.lib;d3d12.lib;dxgi.lib;d3d11.lib;onecore.lib</AdditionalDependencies>
303+
<AdditionalOptions>
304+
</AdditionalOptions>
305+
<DelayLoadDLLs>dxgi.dll;d3d11.dll; ext-ms-win-dxcore-l1-1-0.dll</DelayLoadDLLs>
306+
<IgnoreAllDefaultLibraries>
307+
</IgnoreAllDefaultLibraries>
308+
<IgnoreSpecificDefaultLibraries>kernel32.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
272309
</Link>
273310
</ItemDefinitionGroup>
274311
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

Tools/WinMLRunner/WinMLRunnerStaticLib.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<ProjectGuid>{C3BCBEA1-90E6-426F-88AC-64C274BCEF45}</ProjectGuid>
4949
<Keyword>Win32Proj</Keyword>
5050
<RootNamespace>WinMLRunnerStaticLib</RootNamespace>
51-
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
51+
<WindowsTargetPlatformVersion>10.0.18323.0</WindowsTargetPlatformVersion>
5252
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
5353
</PropertyGroup>
5454
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

Tools/WinMLRunner/src/CommandLineArgs.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <string>
33
#include <iostream>
44
#include "CommandLineArgs.h"
5+
#include <apiquery2.h>
56

67
using namespace Windows::AI::MachineLearning;
78

@@ -15,6 +16,7 @@ void CommandLineArgs::PrintUsage() {
1516
std::cout << " -GPU : run model on default GPU" << std::endl;
1617
std::cout << " -GPUHighPerformance : run model on GPU with highest performance" << std::endl;
1718
std::cout << " -GPUMinPower : run model on GPU with the least power" << std::endl;
19+
std::cout << " -GPUAdapterIndex : run model on GPU specified by its index in DXGI enumeration. NOTE: Please only use this flag on DXCore supported machines." << std::endl;
1820
std::cout << " -CreateDeviceOnClient : create the device on the client and pass it to WinML" << std::endl;
1921
std::cout << " -CreateDeviceInWinML : create the device inside WinML" << std::endl;
2022
std::cout << " -CPUBoundInput : bind the input to the CPU" << std::endl;
@@ -54,6 +56,17 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
5456
{
5557
m_useGPUMinPower = true;
5658
}
59+
else if ((_wcsicmp(args[i].c_str(), L"-GPUAdapterIndex") == 0) && i + 1 < args.size() && args[i + 1][0] != L'-')
60+
{
61+
HMODULE library{ nullptr };
62+
library = LoadLibrary(L"ext-ms-win-dxcore-l1-1-0");
63+
if (!library)
64+
{
65+
throw hresult_invalid_argument(L"ERROR: DXCORE isn't supported on this machine. GpuAdapterIndex flag should only be used with DXCore supported machines.");
66+
}
67+
m_useGPU = true;
68+
m_adapterIndex = static_cast<UINT>(_wtoi(args[++i].c_str()));
69+
}
5770
else if ((_wcsicmp(args[i].c_str(), L"-CreateDeviceOnClient") == 0))
5871
{
5972
m_createDeviceOnClient = true;

Tools/WinMLRunner/src/CommandLineArgs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CommandLineArgs
2828
const std::wstring& OutputPath() const { return m_perfOutputPath; }
2929
const std::wstring& FolderPath() const { return m_modelFolderPath; }
3030
const std::wstring& ModelPath() const { return m_modelPath; }
31+
UINT GetGPUAdapterIndex() const { return m_adapterIndex; }
3132

3233
bool UseRGB() const
3334
{
@@ -124,6 +125,7 @@ class CommandLineArgs
124125
bool m_autoScale = false;
125126
bool m_perfOutput = false;
126127
BitmapInterpolationMode m_autoScaleInterpMode = BitmapInterpolationMode::Cubic;
128+
UINT m_adapterIndex = -1;
127129
bool m_saveTensor = false;
128130
std::string m_saveTensorMode = "First";
129131

Tools/WinMLRunner/src/Common.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#ifndef _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
33
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
44
#endif
5+
#include <vcruntime.h>
6+
#include <windows.h>
57
// unknown.h needs to be inlcuded before any winrt headers
68
#include <unknwn.h>
79
#include <winrt/Windows.AI.MachineLearning.h>
@@ -20,7 +22,9 @@
2022
#include <numeric>
2123
#include <cassert>
2224
#include <fstream>
25+
#include <Windows.AI.MachineLearning.Native.h>
2326
#include <dxgi1_6.h>
27+
#include <d3d12.h>
2428
#include "TypeHelper.h"
2529
#include "TimerHelper.h"
2630

@@ -88,4 +92,16 @@ inline void ThrowIfFailed(HRESULT hr, const std::wstring &errorMsg = L"")
8892
inline void ThrowFailure(const std::wstring &errorMsg)
8993
{
9094
throw errorMsg;
91-
}
95+
}
96+
97+
//
98+
// Delay load exception information
99+
//
100+
#ifndef FACILITY_VISUALCPP
101+
#define FACILITY_VISUALCPP ((LONG)0x6d)
102+
#endif
103+
104+
#define VcppException(sev,err) ((sev) | (FACILITY_VISUALCPP<<16) | err)
105+
106+
HRESULT CreateDXGIFactory2SEH(void **pIDXGIFactory);
107+

Tools/WinMLRunner/src/OutputHelper.h

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,34 @@ class OutputHelper
114114
{
115115
std::cout << "WinML Runner" << std::endl;
116116

117-
com_ptr<IDXGIFactory6> factory;
118-
CreateDXGIFactory1(__uuidof(IDXGIFactory6), factory.put_void());
117+
com_ptr<IDXGIFactory4> factory;
118+
HRESULT hr;
119+
120+
try
121+
{
122+
hr = CreateDXGIFactory2SEH(factory.put_void());
123+
}
124+
catch (...)
125+
{
126+
hr = E_FAIL;
127+
}
128+
if (hr != S_OK)
129+
{
130+
return;
131+
}
132+
133+
//Print All Adapters
119134
com_ptr<IDXGIAdapter> adapter;
120-
factory->EnumAdapters(0, adapter.put());
121-
DXGI_ADAPTER_DESC description;
122-
if (SUCCEEDED(adapter->GetDesc(&description)))
135+
for (UINT i = 0; ; ++i)
123136
{
124-
std::wcout << L"GPU: " << description.Description << std::endl;
125-
std::cout << std::endl;
137+
com_ptr<IDXGIAdapter1> spAdapter;
138+
if (factory->EnumAdapters1(i, spAdapter.put()) != S_OK)
139+
{
140+
break;
141+
}
142+
DXGI_ADAPTER_DESC1 pDesc;
143+
spAdapter->GetDesc1(&pDesc);
144+
printf("Index: %d, Description: %ls\n", i, pDesc.Description);
126145
}
127146
}
128147

0 commit comments

Comments
 (0)