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

Added functionality to choose dml adapter by luid #1041

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

DavitGrigoryan132
Copy link

@DavitGrigoryan132 DavitGrigoryan132 commented Nov 6, 2024

Description: This PR adds functionality to allow users to specify a "DML" (DirectML) execution provider device adapter by providing the adapter's LUID (Locally Unique Identifier). Previously, the system would automatically select the most performant adapter by default. With this enhancement, users can now select a specific adapter by passing the luid_high_part and luid_low_part options, giving them greater control over device selection.

Key Changes:

Added support for selecting a DML execution provider device adapter using luid_high_part and luid_low_part.
Default behavior remains the same, choosing the most performant adapter unless these options are specified.

Motivation: This update provides more flexibility for users needing to target specific adapters, enhancing customizability in environments with multiple available adapters.

#1029

@natke
Copy link
Contributor

natke commented Nov 7, 2024

Thank you for this contribution. Can you please add a test/tests for the new functionality?

@pranavsharma
Copy link
Contributor

This should be reviewed by the DML team.

Comment on lines 57 to 67
ComPtr<IDXGIAdapter1> adapter;
for (uint32_t adapter_index = 0; dxgi_factory->EnumAdapters1(adapter_index, &adapter) != DXGI_ERROR_NOT_FOUND; adapter_index++) {
// We can't assume the ordering of hardware and software adapters, so keep looping. This path should only execute on Windows 10
// version 1709 or earlier; IDD (e.g. remote desktop) adapters do not exist when taking this code path.
if (IsSoftwareAdapter(adapter.Get())) {
continue;
}

// Make sure that we are able to create the device
ComPtr<ID3D12Device> d3d12_device;
THROW_IF_FAILED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&d3d12_device)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enumeration code is the same as the code below. I think It's better to have a single else block, and to only have an if (device_luid) when it's time to actually push it to the adapter_infos vector.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I updated it

Comment on lines 444 to 450
if (name == "luid_high_part") {
device_luid.HighPart = std::stol(value);
contains_device_luid = true;
} else if (name == "luid_low_part") {
device_luid.LowPart = std::stol(value);
contains_device_luid = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the user only specifies the low or high part of the luid? Alternatively, can't we simply parse the entire LUID from a single string?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user only specifies the low or high part of the luid, the program will crush. Yes, I can change it and specify luid by a single string, where high part and low part will be separated by ":" symbol

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -497,8 +514,8 @@ void Model::CreateSessionOptionsFromConfig(const Config::SessionOptions& config_

// If no device gets set, default to CPU
if (!p_device_) {
assert(device_type_ == DeviceType::CPU);
p_device_ = GetDeviceInterface(device_type_);
assert(device_type_ == DeviceType::CPU || device_type_ == DeviceType::DML || device_type_ == DeviceType::WEBGPU);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line throws an error when device_type_ is set to DML. I believe both DML and WEBGPU should use the CPU DeviceInterface to avoid this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants