@@ -2,6 +2,7 @@ package gpu
22
33import (
44 "context"
5+ "os/exec"
56
67 "github.com/docker/docker/client"
78)
@@ -18,12 +19,30 @@ const (
1819
1920// ProbeGPUSupport determines whether or not the Docker engine has GPU support.
2021func ProbeGPUSupport (ctx context.Context , dockerClient client.SystemAPIClient ) (GPUSupport , error ) {
21- info , err := dockerClient .Info (ctx )
22+ // First search for nvidia-container-runtime on PATH
23+ if _ , err := exec .LookPath ("nvidia-container-runtime" ); err == nil {
24+ return GPUSupportCUDA , nil
25+ }
26+
27+ // Next look for explicitly configured nvidia runtime. This is not required in Docker 19.03+ but
28+ // may be configured on some systems
29+ hasNvidia , err := HasNVIDIARuntime (ctx , dockerClient )
2230 if err != nil {
2331 return GPUSupportNone , err
2432 }
25- if _ , hasNvidia := info . Runtimes [ "nvidia" ]; hasNvidia {
33+ if hasNvidia {
2634 return GPUSupportCUDA , nil
2735 }
36+
2837 return GPUSupportNone , nil
2938}
39+
40+ // HasNVIDIARuntime determines whether there is an nvidia runtime available
41+ func HasNVIDIARuntime (ctx context.Context , dockerClient client.SystemAPIClient ) (bool , error ) {
42+ info , err := dockerClient .Info (ctx )
43+ if err != nil {
44+ return false , err
45+ }
46+ _ , hasNvidia := info .Runtimes ["nvidia" ]
47+ return hasNvidia , nil
48+ }
0 commit comments