File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -1263,7 +1263,23 @@ fn num_cuda_devices() -> Option<usize> {
1263
1263
let devices = match env:: var ( "CUDA_VISIBLE_DEVICES" ) {
1264
1264
Ok ( devices) => devices,
1265
1265
Err ( _) => match env:: var ( "NVIDIA_VISIBLE_DEVICES" ) {
1266
- Ok ( devices) => devices,
1266
+ Ok ( devices) => {
1267
+ if devices. trim ( ) == "all" {
1268
+ // Count the number of all GPUs via nvidia-smi
1269
+ let output = Command :: new ( "nvidia-smi" )
1270
+ . args ( [ "--query-gpu=uuid" , "--format=csv,noheader" ] )
1271
+ . output ( )
1272
+ . ok ( ) ?;
1273
+
1274
+ String :: from_utf8_lossy ( & output. stdout )
1275
+ . lines ( )
1276
+ . filter ( |line| !line. trim ( ) . is_empty ( ) )
1277
+ . count ( )
1278
+ . to_string ( )
1279
+ } else {
1280
+ devices
1281
+ }
1282
+ }
1267
1283
Err ( _) => env:: var ( "ZE_AFFINITY_MASK" ) . ok ( ) ?,
1268
1284
} ,
1269
1285
} ;
You can’t perform that action at this time.
0 commit comments