Skip to content

Commit

Permalink
User/orilevari/winmlrunner dxcore latest (#256)
Browse files Browse the repository at this point in the history
* retarget to latest dxcore api surface. modify code accordingly

* Remove D3D12EnableExperimentalFeatures usage
  • Loading branch information
Ori Levari authored Jul 12, 2019
1 parent 7cd642e commit f1e8dde
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Tools/WinMLRunner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Required command-Line arguments:
-GPU : run model on default GPU
-GPUHighPerformance : run model on GPU with highest performance
-GPUMinPower : run model on GPU with the least power
-GPUAdapterName <adapter name substring>: run model on GPU specified by its name. NOTE: Please only use this flag on DXCore supported machines.
-GPUAdapterName <adapter name substring>: run model on GPU specified by its name. NOTE: Please only use this flag on DXCore supported machines. You will need to retarget the solution to at least windows insider build 18936
-CreateDeviceOnClient : create the D3D device on the client and pass it to WinML to create session
-CreateDeviceInWinML : create the device inside WinML
-CPUBoundInput : bind the input to the CPU
Expand Down
26 changes: 10 additions & 16 deletions Tools/WinMLRunner/src/Run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ HRESULT CreateSession(LearningModelSession& session, IDirect3DDevice& winrtDevic
com_ptr<IDXCoreAdapterList> spAdapterList;
const GUID dxGUIDs[] = { DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE };

THROW_IF_FAILED(spFactory->GetAdapterList(dxGUIDs, ARRAYSIZE(dxGUIDs), spAdapterList.put()));
THROW_IF_FAILED(spFactory->CreateAdapterList(ARRAYSIZE(dxGUIDs), dxGUIDs, IID_PPV_ARGS(spAdapterList.put())));

std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::string adapterNameStr = converter.to_bytes(adapterName);
Expand All @@ -221,16 +221,16 @@ HRESULT CreateSession(LearningModelSession& session, IDirect3DDevice& winrtDevic
printf("Printing available adapters..\n");
for (UINT i = 0; i < spAdapterList->GetAdapterCount(); i++)
{
THROW_IF_FAILED(spAdapterList->GetItem(i, currAdapter.put()));
THROW_IF_FAILED(spAdapterList->GetAdapter(i, currAdapter.put()));

// If the adapter is a software adapter then don't consider it for index selection
bool isHardware;
size_t driverDescriptionSize;
THROW_IF_FAILED(
currAdapter->QueryPropertySize(DXCoreProperty::DriverDescription, &driverDescriptionSize));
currAdapter->GetPropertySize(DXCoreAdapterProperty::DriverDescription, &driverDescriptionSize));
CHAR* driverDescription = new CHAR[driverDescriptionSize];
THROW_IF_FAILED(currAdapter->QueryProperty(DXCoreProperty::IsHardware, sizeof(isHardware), &isHardware));
THROW_IF_FAILED(currAdapter->QueryProperty(DXCoreProperty::DriverDescription, driverDescriptionSize,
THROW_IF_FAILED(currAdapter->GetProperty(DXCoreAdapterProperty::IsHardware, &isHardware));
THROW_IF_FAILED(currAdapter->GetProperty(DXCoreAdapterProperty::DriverDescription, driverDescriptionSize,
driverDescription));
if (isHardware)
{
Expand Down Expand Up @@ -258,21 +258,21 @@ HRESULT CreateSession(LearningModelSession& session, IDirect3DDevice& winrtDevic
adapterName);
}
size_t driverDescriptionSize;
THROW_IF_FAILED(spAdapter->QueryPropertySize(DXCoreProperty::DriverDescription, &driverDescriptionSize));
THROW_IF_FAILED(spAdapter->GetPropertySize(DXCoreAdapterProperty::DriverDescription, &driverDescriptionSize));
CHAR* driverDescription = new CHAR[driverDescriptionSize];
spAdapter->QueryProperty(DXCoreProperty::DriverDescription, driverDescriptionSize, driverDescription);
spAdapter->GetProperty(DXCoreAdapterProperty::DriverDescription, driverDescriptionSize, driverDescription);
printf("Using adapter : %s\n", driverDescription);
free(driverDescription);
IUnknown* pAdapter = spAdapter.get();
com_ptr<IDXGIAdapter> spDxgiAdapter;
D3D_FEATURE_LEVEL d3dFeatureLevel = D3D_FEATURE_LEVEL_1_0_CORE;
D3D12_COMMAND_LIST_TYPE commandQueueType = D3D12_COMMAND_LIST_TYPE_COMPUTE;

// Check if adapter selected has DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRFX attribute selected. If so,
// Check if adapter selected has DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS attribute selected. If so,
// then GPU was selected that has D3D12 and D3D11 capabilities. It would be the most stable to
// use DXGI to enumerate GPU and use D3D_FEATURE_LEVEL_11_0 so that image tensorization for
// video frames would be able to happen on the GPU.
if (spAdapter->IsDXAttributeSupported(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRFX))
if (spAdapter->IsAttributeSupported(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS))
{
d3dFeatureLevel = D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0;
com_ptr<IDXGIFactory4> dxgiFactory4;
Expand All @@ -291,18 +291,12 @@ HRESULT CreateSession(LearningModelSession& session, IDirect3DDevice& winrtDevic
// the selectedAdapter
std::cout << "Using DXGI for adapter creation.." << std::endl;
LUID adapterLuid;
THROW_IF_FAILED(spAdapter->GetLUID(&adapterLuid));
THROW_IF_FAILED(spAdapter->GetProperty(DXCoreAdapterProperty::InstanceLuid, &adapterLuid));
THROW_IF_FAILED(dxgiFactory4->EnumAdapterByLuid(adapterLuid, __uuidof(IDXGIAdapter),
spDxgiAdapter.put_void()));
pAdapter = spDxgiAdapter.get();
}
}
else
{
// Need to enable experimental features to create D3D12 Device with adapter that has compute only
// capabilities.
THROW_IF_FAILED(D3D12EnableExperimentalFeatures(1, &D3D12ComputeOnlyDevices, nullptr, 0));
}

// create D3D12Device
com_ptr<ID3D12Device> d3d12Device;
Expand Down

0 comments on commit f1e8dde

Please sign in to comment.