Skip to content

Commit 36e8442

Browse files
authored
Add Concurrency scenario (#167)
Initial implementation to create static lib for loading multiple models concurrently. With -ConcurrentLoad option, WinMLRunner will now load models in different threads concurrently with -NumThreads of threads
1 parent 30c46b1 commit 36e8442

File tree

10 files changed

+337
-19
lines changed

10 files changed

+337
-19
lines changed

Tools/WinMLRunner/WinMLRunner.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinMLRunner", "WinMLRunner.
1313
EndProject
1414
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinMLRunnerStaticLib", "WinMLRunnerStaticLib.vcxproj", "{C3BCBEA1-90E6-426F-88AC-64C274BCEF45}"
1515
EndProject
16+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinMLRunnerScenarios", "WinMLRunnerScenarios.vcxproj", "{C174D45D-C189-475B-B1A7-494939EE7491}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|ARM64 = Debug|ARM64
@@ -57,6 +59,18 @@ Global
5759
{C3BCBEA1-90E6-426F-88AC-64C274BCEF45}.Release|x64.Build.0 = Release|x64
5860
{C3BCBEA1-90E6-426F-88AC-64C274BCEF45}.Release|x86.ActiveCfg = Release|Win32
5961
{C3BCBEA1-90E6-426F-88AC-64C274BCEF45}.Release|x86.Build.0 = Release|Win32
62+
{C174D45D-C189-475B-B1A7-494939EE7491}.Debug|ARM64.ActiveCfg = Debug|ARM64
63+
{C174D45D-C189-475B-B1A7-494939EE7491}.Debug|ARM64.Build.0 = Debug|ARM64
64+
{C174D45D-C189-475B-B1A7-494939EE7491}.Debug|x64.ActiveCfg = Debug|x64
65+
{C174D45D-C189-475B-B1A7-494939EE7491}.Debug|x64.Build.0 = Debug|x64
66+
{C174D45D-C189-475B-B1A7-494939EE7491}.Debug|x86.ActiveCfg = Debug|Win32
67+
{C174D45D-C189-475B-B1A7-494939EE7491}.Debug|x86.Build.0 = Debug|Win32
68+
{C174D45D-C189-475B-B1A7-494939EE7491}.Release|ARM64.ActiveCfg = Release|ARM64
69+
{C174D45D-C189-475B-B1A7-494939EE7491}.Release|ARM64.Build.0 = Release|ARM64
70+
{C174D45D-C189-475B-B1A7-494939EE7491}.Release|x64.ActiveCfg = Release|x64
71+
{C174D45D-C189-475B-B1A7-494939EE7491}.Release|x64.Build.0 = Release|x64
72+
{C174D45D-C189-475B-B1A7-494939EE7491}.Release|x86.ActiveCfg = Release|Win32
73+
{C174D45D-C189-475B-B1A7-494939EE7491}.Release|x86.Build.0 = Release|Win32
6074
EndGlobalSection
6175
GlobalSection(SolutionProperties) = preSolution
6276
HideSolutionNode = FALSE

Tools/WinMLRunner/WinMLRunner.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<ClCompile Include="src/main.cpp" />
3131
</ItemGroup>
3232
<ItemGroup>
33+
<ProjectReference Include="WinMLRunnerScenarios.vcxproj">
34+
<Project>{c174d45d-c189-475b-b1a7-494939ee7491}</Project>
35+
</ProjectReference>
3336
<ProjectReference Include="WinMLRunnerStaticLib.vcxproj">
3437
<Project>{c3bcbea1-90e6-426f-88ac-64c274bcef45}</Project>
3538
</ProjectReference>
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<ClInclude Include="src/Scenarios.h" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<ClCompile Include="src/Concurrency.cpp" />
26+
</ItemGroup>
27+
<PropertyGroup Label="Globals">
28+
<VCProjectVersion>15.0</VCProjectVersion>
29+
<ProjectGuid>{C174D45D-C189-475B-B1A7-494939EE7491}</ProjectGuid>
30+
<Keyword>Win32Proj</Keyword>
31+
<RootNamespace>WinMLRunnerScenarios</RootNamespace>
32+
<WindowsTargetPlatformVersion>10.0.18323.0</WindowsTargetPlatformVersion>
33+
</PropertyGroup>
34+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
36+
<ConfigurationType>StaticLibrary</ConfigurationType>
37+
<UseDebugLibraries>true</UseDebugLibraries>
38+
<PlatformToolset>v141</PlatformToolset>
39+
<CharacterSet>Unicode</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
42+
<ConfigurationType>StaticLibrary</ConfigurationType>
43+
<UseDebugLibraries>false</UseDebugLibraries>
44+
<PlatformToolset>v141</PlatformToolset>
45+
<WholeProgramOptimization>true</WholeProgramOptimization>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
49+
<ConfigurationType>StaticLibrary</ConfigurationType>
50+
<UseDebugLibraries>true</UseDebugLibraries>
51+
<PlatformToolset>v141</PlatformToolset>
52+
<CharacterSet>Unicode</CharacterSet>
53+
</PropertyGroup>
54+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
55+
<ConfigurationType>StaticLibrary</ConfigurationType>
56+
<UseDebugLibraries>false</UseDebugLibraries>
57+
<PlatformToolset>v141</PlatformToolset>
58+
<WholeProgramOptimization>true</WholeProgramOptimization>
59+
<CharacterSet>Unicode</CharacterSet>
60+
</PropertyGroup>
61+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
62+
<ImportGroup Label="ExtensionSettings">
63+
</ImportGroup>
64+
<ImportGroup Label="Shared">
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
73+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
74+
</ImportGroup>
75+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
76+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
77+
</ImportGroup>
78+
<PropertyGroup Label="UserMacros" />
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
80+
<LinkIncremental>true</LinkIncremental>
81+
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
82+
</PropertyGroup>
83+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
84+
<LinkIncremental>true</LinkIncremental>
85+
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
86+
</PropertyGroup>
87+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
88+
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
89+
<LinkIncremental>false</LinkIncremental>
90+
</PropertyGroup>
91+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
92+
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
93+
<LinkIncremental>false</LinkIncremental>
94+
</PropertyGroup>
95+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
96+
<ClCompile>
97+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
98+
<WarningLevel>Level3</WarningLevel>
99+
<Optimization>Disabled</Optimization>
100+
<SDLCheck>true</SDLCheck>
101+
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
102+
<ConformanceMode>true</ConformanceMode>
103+
<LanguageStandard>stdcpp17</LanguageStandard>
104+
</ClCompile>
105+
<Link>
106+
<SubSystem>Windows</SubSystem>
107+
<GenerateDebugInformation>true</GenerateDebugInformation>
108+
</Link>
109+
</ItemDefinitionGroup>
110+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
111+
<ClCompile>
112+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
113+
<WarningLevel>Level3</WarningLevel>
114+
<Optimization>Disabled</Optimization>
115+
<SDLCheck>true</SDLCheck>
116+
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
117+
<ConformanceMode>true</ConformanceMode>
118+
<AdditionalIncludeDirectories>E:\winml\Windows-Machine-Learning\Tools\WinMLRunner\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
119+
<LanguageStandard>stdcpp17</LanguageStandard>
120+
<PrecompiledHeaderFile />
121+
<PrecompiledHeaderOutputFile />
122+
</ClCompile>
123+
<Link>
124+
<SubSystem>Windows</SubSystem>
125+
<GenerateDebugInformation>true</GenerateDebugInformation>
126+
</Link>
127+
</ItemDefinitionGroup>
128+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
129+
<ClCompile>
130+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
131+
<WarningLevel>Level3</WarningLevel>
132+
<Optimization>MaxSpeed</Optimization>
133+
<FunctionLevelLinking>true</FunctionLevelLinking>
134+
<IntrinsicFunctions>true</IntrinsicFunctions>
135+
<SDLCheck>true</SDLCheck>
136+
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
137+
<ConformanceMode>true</ConformanceMode>
138+
<AdditionalIncludeDirectories>E:\winml\Windows-Machine-Learning\Tools\WinMLRunner\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
139+
<LanguageStandard>stdcpp17</LanguageStandard>
140+
<PrecompiledHeaderFile />
141+
<PrecompiledHeaderOutputFile />
142+
</ClCompile>
143+
<Link>
144+
<SubSystem>Windows</SubSystem>
145+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
146+
<OptimizeReferences>true</OptimizeReferences>
147+
<GenerateDebugInformation>true</GenerateDebugInformation>
148+
</Link>
149+
</ItemDefinitionGroup>
150+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
151+
<ClCompile>
152+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
153+
<WarningLevel>Level3</WarningLevel>
154+
<Optimization>MaxSpeed</Optimization>
155+
<FunctionLevelLinking>true</FunctionLevelLinking>
156+
<IntrinsicFunctions>true</IntrinsicFunctions>
157+
<SDLCheck>true</SDLCheck>
158+
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
159+
<ConformanceMode>true</ConformanceMode>
160+
<LanguageStandard>stdcpp17</LanguageStandard>
161+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
162+
</ClCompile>
163+
<Link>
164+
<SubSystem>Windows</SubSystem>
165+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
166+
<OptimizeReferences>true</OptimizeReferences>
167+
<GenerateDebugInformation>true</GenerateDebugInformation>
168+
</Link>
169+
</ItemDefinitionGroup>
170+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
171+
<ImportGroup Label="ExtensionTargets">
172+
</ImportGroup>
173+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="src/Scenarios.h">
19+
<Filter>Header Files</Filter>
20+
</ClInclude>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClCompile Include="src/Concurrency.cpp">
24+
<Filter>Source Files</Filter>
25+
</ClCompile>
26+
</ItemGroup>
27+
</Project>

Tools/WinMLRunner/src/CommandLineArgs.cpp

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ void CommandLineArgs::PrintUsage() {
3434
std::cout << " -Debug: print trace logs" << std::endl;
3535
std::cout << " -Terse: Terse Mode (suppresses repetitive console output)" << std::endl;
3636
std::cout << " -AutoScale <interpolationMode>: Enable image autoscaling and set the interpolation mode [Nearest, Linear, Cubic, Fant]" << std::endl;
37+
std::cout << std::endl;
38+
std::cout << "Concurrency Options:" << std::endl;
39+
std::cout << " -ConcurrentLoad: load models concurrently" << std::endl;
40+
std::cout << " -NumThreads <number>: number of threads to load a model. By default this will be the number of model files to be executed." << std::endl;
41+
std::cout << " -ThreadInterval <milliseconds>: interval time between two thread creations in milliseconds" << std::endl;
3742
}
3843

39-
CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
44+
CommandLineArgs::CommandLineArgs(const std::vector<std::wstring> &args)
4045
{
4146
for (UINT i = 0; i < args.size(); i++)
4247
{
@@ -58,6 +63,7 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
5863
}
5964
else if ((_wcsicmp(args[i].c_str(), L"-GPUAdapterIndex") == 0) && i + 1 < args.size() && args[i + 1][0] != L'-')
6065
{
66+
CheckNextArgument(args, i);
6167
HMODULE library{ nullptr };
6268
library = LoadLibrary(L"ext-ms-win-dxcore-l1-1-0");
6369
if (!library)
@@ -79,12 +85,14 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
7985
{
8086
m_numIterations = static_cast<UINT>(_wtoi(args[++i].c_str()));
8187
}
82-
else if ((_wcsicmp(args[i].c_str(), L"-Model") == 0) && (i + 1 < args.size()))
88+
else if ((_wcsicmp(args[i].c_str(), L"-Model") == 0))
8389
{
90+
CheckNextArgument(args, i);
8491
m_modelPath = args[++i];
8592
}
86-
else if ((_wcsicmp(args[i].c_str(), L"-Folder") == 0) && (i + 1 < args.size()))
93+
else if ((_wcsicmp(args[i].c_str(), L"-Folder") == 0))
8794
{
95+
CheckNextArgument(args, i);
8896
m_modelFolderPath = args[++i];
8997
}
9098
else if ((_wcsicmp(args[i].c_str(), L"-Input") == 0))
@@ -93,7 +101,7 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
93101
}
94102
else if ((_wcsicmp(args[i].c_str(), L"-PerfOutput") == 0))
95103
{
96-
if (i + 1 < args.size() && args[i+1][0] != L'-')
104+
if (i + 1 < args.size() && args[i + 1][0] != L'-')
97105
{
98106
m_perfOutputPath = args[++i];
99107
}
@@ -121,7 +129,7 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
121129
}
122130
else if ((_wcsicmp(args[i].c_str(), L"-Perf") == 0))
123131
{
124-
if (i + 1 < args.size() && args[i + 1][0] != L'-' && (_wcsicmp(args[i+1].c_str(), L"all") == 0))
132+
if (i + 1 < args.size() && args[i + 1][0] != L'-' && (_wcsicmp(args[i + 1].c_str(), L"all") == 0))
125133
{
126134
m_perfConsoleOutputAll = true;
127135
i++;
@@ -140,8 +148,9 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
140148
{
141149
m_terseOutput = true;
142150
}
143-
else if ((_wcsicmp(args[i].c_str(), L"-AutoScale") == 0) && (i + 1 < args.size()))
151+
else if ((_wcsicmp(args[i].c_str(), L"-AutoScale") == 0))
144152
{
153+
CheckNextArgument(args, i);
145154
m_autoScale = true;
146155
if (_wcsicmp(args[++i].c_str(), L"Nearest") == 0)
147156
{
@@ -161,13 +170,13 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
161170
}
162171
else
163172
{
164-
std::cout << "Unknown AutoScale Interpolation Mode!" << std::endl;
165173
PrintUsage();
166-
return;
174+
throw hresult_invalid_argument(L"Unknown AutoScale Interpolation Mode!");
167175
}
168176
}
169177
else if ((_wcsicmp(args[i].c_str(), L"-SaveTensorData") == 0) && (i + 1 < args.size()))
170178
{
179+
CheckNextArgument(args, i);
171180
m_saveTensor = true;
172181
if (_wcsicmp(args[++i].c_str(), L"First") == 0)
173182
{
@@ -179,9 +188,8 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
179188
}
180189
else
181190
{
182-
std::cout << "Unknown Mode!" << std::endl;
183191
PrintUsage();
184-
return;
192+
throw hresult_invalid_argument(L"Unknown Mode!");
185193
}
186194
}
187195
else if (_wcsicmp(args[i].c_str(), L"-version") == 0)
@@ -213,6 +221,29 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
213221
PrintUsage();
214222
return;
215223
}
224+
// concurrency options
225+
else if ((_wcsicmp(args[i].c_str(), L"-ConcurrentLoad") == 0))
226+
{
227+
ToggleConcurrentLoad(true);
228+
}
229+
else if ((_wcsicmp(args[i].c_str(), L"-NumThreads") == 0))
230+
{
231+
CheckNextArgument(args, i);
232+
unsigned num_threads = std::stoi(args[++i].c_str());
233+
SetNumThreads(num_threads);
234+
}
235+
else if ((_wcsicmp(args[i].c_str(), L"-ThreadInterval") == 0))
236+
{
237+
CheckNextArgument(args, i);
238+
unsigned thread_interval = std::stoi(args[++i].c_str());
239+
SetThreadInterval(thread_interval);
240+
}
241+
else
242+
{
243+
std::wstring msg = L"Unknown option ";
244+
msg += args[i].c_str();
245+
throw hresult_invalid_argument(msg.c_str());
246+
}
216247
}
217248

218249
if (m_modelPath.empty() && m_modelFolderPath.empty())
@@ -235,3 +266,10 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
235266
}
236267
}
237268

269+
void CommandLineArgs::CheckNextArgument(const std::vector<std::wstring> &args, UINT i) {
270+
if (i + 1 >= args.size() || args[i + 1][0] == L'-') {
271+
std::wstring msg = L"Invalid parameter for ";
272+
msg += args[i].c_str();
273+
throw hresult_invalid_argument(msg.c_str());
274+
}
275+
}

0 commit comments

Comments
 (0)