@@ -25,34 +25,42 @@ const (
2525
2626// ProbeGPUSupport determines whether or not the Docker engine has GPU support.
2727func ProbeGPUSupport (ctx context.Context , dockerClient client.SystemAPIClient ) (GPUSupport , error ) {
28- // Check for ROCm runtime first
29- if hasROCm , err := HasROCmRuntime (ctx , dockerClient ); err == nil && hasROCm {
30- return GPUSupportROCm , nil
28+ // Query Docker Engine for its effective configuration.
29+ // Docker Info is the source of truth for which runtimes are actually usable.
30+ info , err := dockerClient .Info (ctx )
31+ if err != nil {
32+ // Preserve best-effort behavior: if Docker Info is unavailable (e.g. in
33+ // restricted or degraded environments), do not treat this as a hard failure.
34+ // Instead, assume no GPU support and allow callers to continue.
35+ return GPUSupportNone , nil
3136 }
3237
33- // Then check for MTHREADS runtime
34- if hasMTHREADS , err := HasMTHREADSRuntime (ctx , dockerClient ); err == nil && hasMTHREADS {
35- return GPUSupportMUSA , nil
36- }
37- // Check for CANN runtime first
38- if hasCANN , err := HasCANNRuntime (ctx , dockerClient ); err == nil && hasCANN {
39- return GPUSupportCANN , nil
40- }
41- // Then search for nvidia-container-runtime on PATH
42- if _ , err := exec .LookPath ("nvidia-container-runtime" ); err == nil {
43- return GPUSupportCUDA , nil
38+ // Runtimes are checked in priority order, from highest to lowest.
39+ // The first matching runtime determines the selected GPU support.
40+ supportedRuntimes := []struct {
41+ name string
42+ support GPUSupport
43+ }{
44+ {"nvidia" , GPUSupportCUDA }, // 1. CUDA (NVIDIA)
45+ {"rocm" , GPUSupportROCm }, // 2. ROCm (AMD)
46+ {"mthreads" , GPUSupportMUSA }, // 3. MUSA (MThreads)
47+ {"cann" , GPUSupportCANN }, // 4. Ascend CANN (Huawei)
4448 }
4549
46- // Next look for explicitly configured nvidia runtime. This is not required in Docker 19.03+ but
47- // may be configured on some systems
48- hasNvidia , err := HasNVIDIARuntime (ctx , dockerClient )
49- if err != nil {
50- return GPUSupportNone , err
50+ for _ , r := range supportedRuntimes {
51+ if _ , ok := info .Runtimes [r .name ]; ok {
52+ return r .support , nil
53+ }
5154 }
52- if hasNvidia {
55+
56+ // Legacy fallback
57+ // Older Docker setups may not register the NVIDIA runtime explicitly,
58+ // but still have the legacy nvidia-container-runtime available on PATH.
59+ if _ , err := exec .LookPath ("nvidia-container-runtime" ); err == nil {
5360 return GPUSupportCUDA , nil
5461 }
5562
63+ // No known GPU runtime detected.
5664 return GPUSupportNone , nil
5765}
5866
0 commit comments