Skip to content

Commit 32cd7ac

Browse files
authored
add WORKER_VISIBLE_DEVICES env var to select worker devices (#589)
1 parent f5161f8 commit 32cd7ac

File tree

1 file changed

+23
-0
lines changed
  • crates/worker/src/checks/hardware

1 file changed

+23
-0
lines changed

crates/worker/src/checks/hardware/gpu.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ pub fn detect_gpu() -> Vec<GpuSpecs> {
4545
fn get_gpu_status() -> Vec<GpuDevice> {
4646
let mut nvml_guard = NVML.lock().unwrap();
4747

48+
// Read WORKER_VISIBLE_DEVICES environment variable
49+
let visible_devices: Option<Vec<u32>> =
50+
std::env::var("WORKER_VISIBLE_DEVICES").ok().and_then(|s| {
51+
if s.trim().is_empty() {
52+
None
53+
} else {
54+
Some(
55+
s.split(',')
56+
.filter_map(|idx| idx.trim().parse::<u32>().ok())
57+
.collect(),
58+
)
59+
}
60+
});
61+
4862
// Initialize NVML if not already initialized
4963
if nvml_guard.is_none() {
5064
// Try to load the NVIDIA management library dynamically
@@ -94,6 +108,15 @@ fn get_gpu_status() -> Vec<GpuDevice> {
94108
std::collections::HashMap::new();
95109

96110
for i in 0..device_count {
111+
let device_index = i as u32;
112+
113+
// Skip this device if it's not in the visible devices list
114+
if let Some(ref visible) = visible_devices {
115+
if !visible.contains(&device_index) {
116+
continue;
117+
}
118+
}
119+
97120
match nvml.device_by_index(i as u32) {
98121
Ok(device) => {
99122
let name = device.name().unwrap_or_else(|_| "Unknown".to_string());

0 commit comments

Comments
 (0)