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

allow specifying an adapter name also when using DXGI #261

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 3 additions & 6 deletions Tools/WinMLRunner/src/CommandLineArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ void CommandLineArgs::PrintUsage()
std::cout << " -GPU : run model on default GPU" << std::endl;
std::cout << " -GPUHighPerformance : run model on GPU with highest performance" << std::endl;
std::cout << " -GPUMinPower : run model on GPU with the least power" << std::endl;
#ifdef DXCORE_SUPPORTED_BUILD
std::cout << " -GPUAdapterName <adapter name substring>: run model on GPU specified by its name. NOTE: Please only use this flag on DXCore supported machines."
<< std::endl;
#endif
std::cout << " -GPUAdapterName <adapter name substring>: run model on GPU specified by its name." << std::endl;
std::cout << " -CreateDeviceOnClient : create the D3D device on the client and pass it to WinML to create session" << std::endl;
std::cout << " -CreateDeviceInWinML : create the device inside WinML" << std::endl;
std::cout << " -CPUBoundInput : bind the input to the CPU" << std::endl;
Expand Down Expand Up @@ -101,10 +98,10 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
{
m_useGPUMinPower = true;
}
#ifdef DXCORE_SUPPORTED_BUILD
else if (_wcsicmp(args[i].c_str(), L"-GPUAdapterName") == 0)
{
CheckNextArgument(args, i);
#ifdef DXCORE_SUPPORTED_BUILD
HMODULE library = nullptr;
library = LoadLibrary(L"dxcore.dll");
if (!library)
Expand All @@ -113,10 +110,10 @@ CommandLineArgs::CommandLineArgs(const std::vector<std::wstring>& args)
L"ERROR: DXCORE isn't supported on this machine. "
L"GpuAdapterName flag should only be used with DXCore supported machines.");
}
#endif
m_adapterName = args[++i];
m_useGPU = true;
}
#endif
else if ((_wcsicmp(args[i].c_str(), L"-CreateDeviceOnClient") == 0))
{
m_createDeviceOnClient = true;
Expand Down
5 changes: 1 addition & 4 deletions Tools/WinMLRunner/src/CommandLineArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ class CommandLineArgs
const std::wstring& ModelPath() const { return m_modelPath; }
const std::wstring& PerIterationDataPath() const { return m_perIterationDataPath; }
std::vector<std::pair<std::string, std::string>>& GetPerformanceFileMetadata() { return m_perfFileMetadata; }
#ifdef DXCORE_SUPPORTED_BUILD
const std::wstring& GetGPUAdapterName() const { return m_adapterName; }
#endif


bool UseRGB() const
{
Expand Down Expand Up @@ -159,9 +158,7 @@ class CommandLineArgs
std::wstring m_inputImageFolderPath;
std::wstring m_csvData;
std::wstring m_inputData;
#ifdef DXCORE_SUPPORTED_BUILD
std::wstring m_adapterName;
#endif
std::wstring m_perfOutputPath;
std::wstring m_perIterationDataPath;
uint32_t m_numIterations = 1;
Expand Down
29 changes: 25 additions & 4 deletions Tools/WinMLRunner/src/Run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ HRESULT CreateSession(LearningModelSession& session, IDirect3DDevice& winrtDevic
{
return hresult_invalid_argument().code();
}
#ifdef DXCORE_SUPPORTED_BUILD

const std::wstring& adapterName = args.GetGPUAdapterName();
#endif

try
{
if (deviceCreationLocation == DeviceCreationLocation::UserD3DDevice && deviceType != DeviceType::CPU)
Expand All @@ -160,8 +160,29 @@ HRESULT CreateSession(LearningModelSession& session, IDirect3DDevice& winrtDevic
switch (deviceType)
{
case DeviceType::DefaultGPU:
hr = factory->EnumAdapterByGpuPreference(0, DXGI_GPU_PREFERENCE_UNSPECIFIED, __uuidof(IDXGIAdapter),
adapter.put_void());
if (adapterName.empty())
{
hr = factory->EnumAdapterByGpuPreference(0, DXGI_GPU_PREFERENCE_UNSPECIFIED,
__uuidof(IDXGIAdapter), adapter.put_void());
}
else
{
DXGI_ADAPTER_DESC desc;

int adapterIndex = 0;
do
{
hr = factory->EnumAdapters(adapterIndex, adapter.put());

if (adapter)
{
adapter->GetDesc(&desc);
}

adapterIndex++;
} while ((hr != DXGI_ERROR_NOT_FOUND) &&
(wcsstr(desc.Description, adapterName.c_str()) == NULL));
}
break;
case DeviceType::MinPowerGPU:
hr = factory->EnumAdapterByGpuPreference(0, DXGI_GPU_PREFERENCE_MINIMUM_POWER,
Expand Down