Skip to content

Commit 1c0c421

Browse files
authored
Add noop nvmlDeviceGetComputeRunningProcesses, fix nvmlDeviceGetHandleByPciBusId_v2 (#531)
1 parent f68ea06 commit 1c0c421

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

zluda_common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ from_cuda_nop!(
164164
CUlaunchConfig,
165165
cublasMath_t,
166166
nvmlDevice_t,
167+
nvmlProcessInfo_v1_t,
167168
nvmlFieldValue_t,
168169
nvmlGpuFabricInfo_t,
169170
cublasLtHandle_t,

zluda_ml/src/impl_unix.rs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,46 +80,40 @@ impl PciBusId {
8080

8181
fn parse_pci_bus_id(id: &std::ffi::CStr) -> Option<PciBusId> {
8282
let s = id.to_str().ok()?.trim();
83-
let mut domain: u16 = 0;
84-
let mut rest = s;
85-
if let Some(colon1) = s.find(':') {
86-
if colon1 == 4 {
87-
domain = hex_u16(&s[..4])?;
88-
rest = &s[5..];
89-
}
90-
}
91-
let mut parts = rest.split(':');
92-
let bus_part = parts.next()?;
93-
let tail = parts.next()?;
94-
if parts.next().is_some() {
83+
let mut segments = s.split(':').rev();
84+
let func_dev = segments.next()?;
85+
let mut function_dev = func_dev.split('.');
86+
let device = function_dev.next()?;
87+
let function = function_dev.next();
88+
let function = match function {
89+
Some(f) => hex_u8(f)?,
90+
None => 0,
91+
};
92+
if function_dev.next().is_some() {
9593
return None;
9694
}
97-
let mut dev_func = tail.split('.');
98-
let dev_part = dev_func.next()?;
99-
let func_part = dev_func.next();
100-
let function = match func_part {
101-
Some(f) => hex_u8(f)?,
95+
let bus = segments.next()?;
96+
let domain = segments.next();
97+
let domain = match domain {
98+
Some(d) => hex_u16(d)?,
10299
None => 0,
103100
};
101+
if segments.next().is_some() {
102+
return None;
103+
}
104104
Some(PciBusId {
105105
domain,
106-
bus: hex_u8(bus_part)?,
107-
device: hex_u8(dev_part)?,
106+
bus: hex_u8(bus)?,
107+
device: hex_u8(device)?,
108108
function,
109109
})
110110
}
111111

112112
fn hex_u16(s: &str) -> Option<u16> {
113-
if s.len() > 4 {
114-
return None;
115-
}
116113
u16::from_str_radix(s, 16).ok()
117114
}
118115

119116
fn hex_u8(s: &str) -> Option<u8> {
120-
if s.len() > 2 {
121-
return None;
122-
}
123117
u8::from_str_radix(s, 16).ok()
124118
}
125119

@@ -156,6 +150,15 @@ pub(crate) fn device_get_handle_by_index_v2(
156150
nvmlReturn_t::SUCCESS
157151
}
158152

153+
pub(crate) fn device_get_compute_running_processes(
154+
_device: cuda_types::nvml::nvmlDevice_t,
155+
info_count: &mut ::core::ffi::c_uint,
156+
_infos: Option<&mut cuda_types::nvml::nvmlProcessInfo_v1_t>,
157+
) -> nvmlReturn_t {
158+
*info_count = 0;
159+
Ok(())
160+
}
161+
159162
#[cfg(test)]
160163
mod tests {
161164
#[test]
@@ -187,4 +190,14 @@ mod tests {
187190
assert_eq!(parsed.device, 0xa0);
188191
assert_eq!(parsed.function, 0xf);
189192
}
193+
194+
#[test]
195+
fn parse_long_pci_bus_id() {
196+
let id = std::ffi::CString::new("00000002:00:00.0").unwrap();
197+
let parsed = super::parse_pci_bus_id(&id).unwrap();
198+
assert_eq!(parsed.domain, 0x0002);
199+
assert_eq!(parsed.bus, 0x00);
200+
assert_eq!(parsed.device, 0x00);
201+
assert_eq!(parsed.function, 0x00);
202+
}
190203
}

zluda_ml/src/impl_win.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,12 @@ pub(crate) fn device_get_handle_by_index_v2(
5151
) -> nvmlReturn_t {
5252
crate::impl_common::unimplemented()
5353
}
54+
55+
pub(crate) fn device_get_compute_running_processes(
56+
_device: cuda_types::nvml::nvmlDevice_t,
57+
info_count: &mut ::core::ffi::c_uint,
58+
_infos: Option<&mut cuda_types::nvml::nvmlProcessInfo_v1_t>,
59+
) -> nvmlReturn_t {
60+
*info_count = 0;
61+
Ok(())
62+
}

zluda_ml/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ cuda_macros::nvml_function_declarations!(
5454
nvmlInit_v2,
5555
nvmlShutdown,
5656
nvmlSystemGetDriverVersion,
57+
nvmlDeviceGetComputeRunningProcesses
5758
],
5859
implemented_unnormalized <= [nvmlErrorString,]
5960
);

0 commit comments

Comments
 (0)