Skip to content

Commit 78c4b65

Browse files
author
Ryan Lai
authored
Add batching size 1 and session options (#264)
* check session options version * Create Session Considering Support for Session Options * Only set batchsize to 1 * Made batch size override always 1 * Merged * Update minimum SDK
1 parent d813cef commit 78c4b65

File tree

6 files changed

+64
-37
lines changed

6 files changed

+64
-37
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.18362.0</WindowsTargetPlatformVersion>
2727
<ProjectSubType>NativeUnitTestProject</ProjectSubType>
2828
</PropertyGroup>
2929
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

Tools/WinMLRunner/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can either download the x64 executable or build it yourself.
1616
#### Prerequisites
1717
- [Visual Studio 2017 Version 15.7.4 or Newer](https://developer.microsoft.com/en-us/windows/downloads)
1818
- [Windows 10 - Build 17763 or higher](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewiso)
19-
- [Windows SDK - Build 17763 or higher](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewSDK)
19+
- [Windows SDK - Build 18362 or higher](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewSDK)
2020

2121
The easiest way to use these samples without using Git is to download the zip file containing the current version (using the following link or by clicking the "Download ZIP" button on the repo page). You can then unzip the entire archive and use the samples in Visual Studio 2017. Notes: Before you unzip the archive, right-click it, select Properties, and then select Unblock.
2222
Be sure to unzip the entire archive, and not just individual samples. The samples all depend on the SharedContent folder in the archive. In Visual Studio 2017, the platform target defaults to ARM, so be sure to change that to x64 or x86 if you want to test on a non-ARM device. Reminder: If you unzip individual samples, they will not build due to references to other portions of the ZIP file that were not unzipped.

Tools/WinMLRunner/WinMLRunner.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<ProjectGuid>{31653A2F-02CC-4A95-9880-BF86965FB262}</ProjectGuid>
4949
<Keyword>Win32Proj</Keyword>
5050
<RootNamespace>WinMLRunner</RootNamespace>
51-
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
51+
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
5252
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
5353
</PropertyGroup>
5454
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

Tools/WinMLRunner/WinMLRunnerScenarios.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<ProjectGuid>{C174D45D-C189-475B-B1A7-494939EE7491}</ProjectGuid>
3232
<Keyword>Win32Proj</Keyword>
3333
<RootNamespace>WinMLRunnerScenarios</RootNamespace>
34-
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
34+
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
3535
</PropertyGroup>
3636
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
3737
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

Tools/WinMLRunner/WinMLRunnerStaticLib.vcxproj

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

Tools/WinMLRunner/src/Run.cpp

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include <Windows.Graphics.DirectX.Direct3D11.interop.h>
77
#include "Run.h"
88
#include "Scenarios.h"
9+
#include <winrt/Windows.Foundation.Metadata.h>
910
using namespace winrt::Windows::Graphics::DirectX::Direct3D11;
10-
11+
using namespace winrt::Windows::Foundation::Metadata;
1112
std::vector<ILearningModelFeatureValue> GenerateInputFeatures(const LearningModel& model, const CommandLineArgs& args,
1213
InputBindingType inputBindingType,
1314
InputDataType inputDataType,
@@ -137,6 +138,57 @@ HRESULT CreateDXGIFactory2SEH(void** dxgiFactory)
137138
}
138139
#endif
139140

141+
void PopulateSessionOptions(LearningModelSessionOptions& sessionOptions)
142+
{
143+
// Batch Size Override as 1
144+
try
145+
{
146+
sessionOptions.BatchSizeOverride(1);
147+
}
148+
catch (...)
149+
{
150+
printf("Batch size override couldn't be set.\n");
151+
throw;
152+
}
153+
}
154+
155+
void CreateSessionConsideringSupportForSessionOptions(LearningModelSession& session,
156+
LearningModel& model,
157+
Profiler<WINML_MODEL_TEST_PERF>& profiler,
158+
CommandLineArgs& args,
159+
LearningModelDevice& learningModelDevice)
160+
{
161+
auto statics = get_activation_factory<ApiInformation, IApiInformationStatics>();
162+
bool isSessionOptionsTypePresent = isSessionOptionsTypePresent =
163+
statics.IsTypePresent(L"Windows.AI.MachineLearning.LearningModelSessionOptions");
164+
if (isSessionOptionsTypePresent)
165+
{
166+
LearningModelSessionOptions sessionOptions;
167+
PopulateSessionOptions(sessionOptions);
168+
if (args.IsPerformanceCapture())
169+
{
170+
WINML_PROFILING_START(profiler, WINML_MODEL_TEST_PERF::CREATE_SESSION);
171+
}
172+
session = LearningModelSession(model, learningModelDevice, sessionOptions);
173+
if (args.IsPerformanceCapture())
174+
{
175+
WINML_PROFILING_STOP(profiler, WINML_MODEL_TEST_PERF::CREATE_SESSION);
176+
}
177+
}
178+
else
179+
{
180+
if (args.IsPerformanceCapture())
181+
{
182+
WINML_PROFILING_START(profiler, WINML_MODEL_TEST_PERF::CREATE_SESSION);
183+
}
184+
session = LearningModelSession(model, learningModelDevice);
185+
if (args.IsPerformanceCapture())
186+
{
187+
WINML_PROFILING_STOP(profiler, WINML_MODEL_TEST_PERF::CREATE_SESSION);
188+
}
189+
}
190+
}
191+
140192
HRESULT CreateSession(LearningModelSession& session, IDirect3DDevice& winrtDevice, LearningModel& model,
141193
CommandLineArgs& args, OutputHelper& output, DeviceType deviceType,
142194
DeviceCreationLocation deviceCreationLocation, Profiler<WINML_MODEL_TEST_PERF>& profiler)
@@ -150,6 +202,7 @@ HRESULT CreateSession(LearningModelSession& session, IDirect3DDevice& winrtDevic
150202
#endif
151203
try
152204
{
205+
LearningModelDevice learningModelDevice = NULL;
153206
if (deviceCreationLocation == DeviceCreationLocation::UserD3DDevice && deviceType != DeviceType::CPU)
154207
{
155208
// Enumerate Adapters to pick the requested one.
@@ -194,17 +247,7 @@ HRESULT CreateSession(LearningModelSession& session, IDirect3DDevice& winrtDevic
194247
THROW_IF_FAILED(hr);
195248

196249
winrtDevice = inspectableDevice.as<IDirect3DDevice>();
197-
LearningModelDevice learningModelDevice = LearningModelDevice::CreateFromDirect3D11Device(winrtDevice);
198-
output.PrintLearningModelDevice(deviceType, learningModelDevice);
199-
if (args.IsPerformanceCapture())
200-
{
201-
WINML_PROFILING_START(profiler, WINML_MODEL_TEST_PERF::CREATE_SESSION);
202-
}
203-
session = LearningModelSession(model, learningModelDevice);
204-
if (args.IsPerformanceCapture())
205-
{
206-
WINML_PROFILING_STOP(profiler, WINML_MODEL_TEST_PERF::CREATE_SESSION);
207-
}
250+
learningModelDevice = LearningModelDevice::CreateFromDirect3D11Device(winrtDevice);
208251
}
209252
#ifdef DXCORE_SUPPORTED_BUILD
210253
else if ((TypeHelper::GetWinmlDeviceKind(deviceType) != LearningModelDeviceKind::Cpu) && !adapterName.empty())
@@ -319,31 +362,15 @@ HRESULT CreateSession(LearningModelSession& session, IDirect3DDevice& winrtDevic
319362
com_ptr<::IUnknown> spUnkLearningModelDevice;
320363
THROW_IF_FAILED(
321364
factory->CreateFromD3D12CommandQueue(d3d12CommandQueue.get(), spUnkLearningModelDevice.put()));
322-
if (args.IsPerformanceCapture())
323-
{
324-
WINML_PROFILING_START(profiler, WINML_MODEL_TEST_PERF::CREATE_SESSION);
325-
}
326-
session = LearningModelSession(model, spUnkLearningModelDevice.as<LearningModelDevice>());
327-
if (args.IsPerformanceCapture())
328-
{
329-
WINML_PROFILING_STOP(profiler, WINML_MODEL_TEST_PERF::CREATE_SESSION);
330-
}
365+
learningModelDevice = spUnkLearningModelDevice.as<LearningModelDevice>();
331366
}
332367
#endif
333368
else
334369
{
335-
LearningModelDevice learningModelDevice(TypeHelper::GetWinmlDeviceKind(deviceType));
336-
output.PrintLearningModelDevice(deviceType, learningModelDevice);
337-
if (args.IsPerformanceCapture())
338-
{
339-
WINML_PROFILING_START(profiler, WINML_MODEL_TEST_PERF::CREATE_SESSION);
340-
}
341-
session = LearningModelSession(model, learningModelDevice);
342-
if (args.IsPerformanceCapture())
343-
{
344-
WINML_PROFILING_STOP(profiler, WINML_MODEL_TEST_PERF::CREATE_SESSION);
345-
}
370+
learningModelDevice = LearningModelDevice(TypeHelper::GetWinmlDeviceKind(deviceType));
346371
}
372+
output.PrintLearningModelDevice(deviceType, learningModelDevice);
373+
CreateSessionConsideringSupportForSessionOptions(session, model, profiler, args, learningModelDevice);
347374
}
348375
catch (hresult_error hr)
349376
{

0 commit comments

Comments
 (0)