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

feat: improve GPU support when multiple GPUs #2238

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

mhdawson
Copy link
Contributor

@mhdawson mhdawson commented Dec 9, 2024

What does this PR do?

If there are multiple GPUs use the first one that is of known type instead of first GPU. If no GPUs of are known type fall back to the first GPU as before.

Add another string for vendor that is accepted as an NVIDIA GPU when doing GPU detection based on what was seen on linux with an NVIDIA 4070 Ti Super

The VM in which I did testing for potential GPU support on linux (#2180) had 2 CPUs, one of which is NVIDIA but it was not gpu[0]. This should have no effect in people only have 1 gpu. With this change I could use the second GPU.

Screenshot / video of UI

N/A

What issues does this PR fix or reference?

#2214

How to test this PR?

Run unit tests as updated

Copy link
Collaborator

@benoitf benoitf left a comment

Choose a reason for hiding this comment

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

cannot test locally as I only have one GPU on my computer

Comment on lines 204 to 209
for (let i = 0; i < gpus.length; i++) {
if (gpus[i].vendor !== GPUVendor.UNKNOWN) {
selectedGPU = i;
break;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: use the Array.find method ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we would need to use findIndex versus find. With that we'd have to check for -1 as that is what's returned if there is no match. Not sure it would be much less code or clearer.

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is a single GPU we will take it but won't check if the vendor is known. Should we check it as well ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeffmaury I left it not checking since that was the way it was before and I was not sure if that would break anything. I can add the check if that is the right thing to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good because I understood your configuration have 2 GPUs returned one which is not to be selected so I wonder we could have a configuration where we could have this single GPU returned

Comment on lines 200 to 214
let selectedGPU = 0;
if (gpus.length > 1) {
// Look for a GPU that is of a known type, use the first one found.
// Fall back to the first one if no GPUs are of known type.
for (let i = 0; i < gpus.length; i++) {
if (gpus[i].vendor !== GPUVendor.UNKNOWN) {
selectedGPU = i;
break;
}
}
console.warn(
`found ${gpus.length} gpus: using multiple GPUs is not supported. Using ${gpus[selectedGPU].model}.`,
);
}
gpu = gpus[selectedGPU];
Copy link
Contributor

@axel7083 axel7083 Dec 10, 2024

Choose a reason for hiding this comment

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

Suggested change
let selectedGPU = 0;
if (gpus.length > 1) {
// Look for a GPU that is of a known type, use the first one found.
// Fall back to the first one if no GPUs are of known type.
for (let i = 0; i < gpus.length; i++) {
if (gpus[i].vendor !== GPUVendor.UNKNOWN) {
selectedGPU = i;
break;
}
}
console.warn(
`found ${gpus.length} gpus: using multiple GPUs is not supported. Using ${gpus[selectedGPU].model}.`,
);
}
gpu = gpus[selectedGPU];
if (gpus.length > 1) {
// Look for a GPU that is of a known type, use the first one found.
// Fall back to the first one if no GPUs are of known type.
gpu = gpus.find(({vendor}) => vendor !== GPUVendor.UNKNOWN) ?? gpus[0];
}

We can simplify

Copy link
Contributor Author

@mhdawson mhdawson Dec 10, 2024

Choose a reason for hiding this comment

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

The change missed the case with 0, cpus. pulled it in minus the check for number of cpus and it seems to do the right thing. Also rebased.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a lot more compact which is great.

If there are multiple GPUs use the first one that is of
known type instead of first GPU. If no GPUs of are known
type fall back to the first GPU as before.

Add another string for vendor that is accepted as an NVIDIA
GPU when doing GPU detection based on what was seen on linux
with an NVIDIA 4070 Ti Super

Signed-off-by: Michael Dawson <[email protected]>
@mhdawson mhdawson force-pushed the improve-gpu-detection branch from 022cb15 to 9d09bf3 Compare December 10, 2024 14:27

// Look for a GPU that is of a known type, use the first one found.
// Fall back to the first one if no GPUs are of known type.
gpu = gpus.find(({ vendor }) => vendor !== GPUVendor.UNKNOWN) ?? gpus[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If as @benoitf suggested we should only use recognized GPUs it should be as simple as removing the ?? gpus[0]

Copy link
Contributor

@axel7083 axel7083 left a comment

Choose a reason for hiding this comment

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

LGTM

@axel7083
Copy link
Contributor

Merging as got two approval and tests are passing

@axel7083 axel7083 merged commit ce6844b into containers:main Dec 11, 2024
7 checks passed
@axel7083
Copy link
Contributor

Thanks @mhdawson this is great !

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