Skip to content

Commit 79c63a4

Browse files
emberianBigLeprvagg
authored
feat: extend support for Apple Silicon (#92)
* upgrade deps * fix clippy * allow(unused) + cargo fmt * Handle Apple GPU PCI bus information properly Apple Silicon GPUs are integrated into the SoC and don't use PCI bus. This change ensures synthetic PCI-ID assignment for Apple devices. * Fix formatting - add missing comma * trigger CI rebuild * Fix CI: install clippy and rustfmt components * chore: add clippy and rustfmt components * chore: remove rustfmt and clippy installs from GHA * fix(src): toolchain formatting --------- Co-authored-by: Steve Loeppky <[email protected]> Co-authored-by: Rod Vagg <[email protected]>
1 parent ccb3c7e commit 79c63a4

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

rust-toolchain

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
1.81.0
1+
[toolchain]
2+
channel = "1.81.0"
3+
components = ["clippy", "rustfmt"]

src/device.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const AMD_DEVICE_ON_APPLE_VENDOR_STRING: &str = "AMD";
2828
const AMD_DEVICE_ON_APPLE_VENDOR_ID: u32 = 0x1021d00;
2929
const NVIDIA_DEVICE_VENDOR_STRING: &str = "NVIDIA Corporation";
3030
const NVIDIA_DEVICE_VENDOR_ID: u32 = 0x10de;
31+
const APPLE_DEVICE_VENDOR_ID: u32 = 0x1027F00;
32+
const APPLE_DEVICE_VENDOR_STRING: &str = "Apple";
3133

3234
// The owned CUDA contexts are stored globally. Each devives contains an unowned reference, so
3335
// that devices can be cloned.
@@ -180,6 +182,8 @@ pub enum Vendor {
180182
Intel,
181183
/// GPU by NVIDIA.
182184
Nvidia,
185+
/// GPU by Apple.
186+
Apple,
183187
}
184188

185189
impl TryFrom<&str> for Vendor {
@@ -191,6 +195,7 @@ impl TryFrom<&str> for Vendor {
191195
AMD_DEVICE_ON_APPLE_VENDOR_STRING => Ok(Self::Amd),
192196
INTEL_DEVICE_VENDOR_STRING => Ok(Self::Intel),
193197
NVIDIA_DEVICE_VENDOR_STRING => Ok(Self::Nvidia),
198+
APPLE_DEVICE_VENDOR_STRING => Ok(Self::Apple),
194199
_ => Err(GPUError::UnsupportedVendor(vendor.to_string())),
195200
}
196201
}
@@ -205,6 +210,7 @@ impl TryFrom<u32> for Vendor {
205210
AMD_DEVICE_ON_APPLE_VENDOR_ID => Ok(Self::Amd),
206211
INTEL_DEVICE_VENDOR_ID => Ok(Self::Intel),
207212
NVIDIA_DEVICE_VENDOR_ID => Ok(Self::Nvidia),
213+
APPLE_DEVICE_VENDOR_ID => Ok(Self::Apple),
208214
_ => Err(GPUError::UnsupportedVendor(format!("0x{:x}", vendor))),
209215
}
210216
}
@@ -216,6 +222,7 @@ impl fmt::Display for Vendor {
216222
Self::Amd => AMD_DEVICE_VENDOR_STRING,
217223
Self::Intel => INTEL_DEVICE_VENDOR_STRING,
218224
Self::Nvidia => NVIDIA_DEVICE_VENDOR_STRING,
225+
Self::Apple => APPLE_DEVICE_VENDOR_STRING,
219226
};
220227
write!(f, "{}", vendor)
221228
}

src/opencl/utils.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ fn get_pci_id(device: &opencl3::device::Device) -> GPUResult<PciId> {
3737
let device_id = device.pci_slot_id_nv()? as u16;
3838
(bus_id << 8) | device_id
3939
}
40+
Vendor::Apple => {
41+
// Apple Silicon GPUs are integrated into the SoC and don't use PCI bus
42+
// Return an error to trigger synthetic PCI-ID assignment
43+
return Err(GPUError::Generic(
44+
"Apple GPUs don't have PCI bus information".to_string(),
45+
));
46+
}
4047
};
4148
Ok(id.into())
4249
}

0 commit comments

Comments
 (0)