Skip to content

Commit db1cd36

Browse files
Merge pull request #58 from bratpiorka/rrudnick_errors
Improve SYCL error handling
2 parents 9675bf2 + adaed09 commit db1cd36

5 files changed

Lines changed: 13 additions & 19 deletions

File tree

‎sycl/sycl-rs-sys/src/context-sys.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ pub mod ffi {
2020
#[namespace = "sycl_shims"]
2121
type Context = crate::types::ffi::Context;
2222

23-
fn new_context(devices: Vec<DevicePtr>) -> UniquePtr<Context>;
23+
fn new_context(devices: Vec<DevicePtr>) -> Result<UniquePtr<Context>>;
2424
}
2525
}

‎sycl/sycl-rs-sys/src/device-sys.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub mod ffi {
3131
fn get_device_type(device: &Device) -> DeviceType;
3232
fn get_version(device: &Device) -> String;
3333
fn get_name(device: &Device) -> String;
34-
fn get_pci_bdf_address(device: &Device) -> String;
34+
fn get_pci_bdf_address(device: &Device) -> Result<String>;
3535

3636
fn enable_peer_access(device: &mut UniquePtr<Device>, peer: &Device) -> Result<()>;
3737
fn disable_peer_access(device: &mut UniquePtr<Device>, peer: &Device) -> Result<()>;

‎sycl/sycl-rs/examples/sycl-ls.rs‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ fn main() {
1717
let device_version = device.get_info::<info::device::Version>();
1818
let platform_version = platform.get_info::<info::platform::Version>();
1919

20-
let pci_bdf_address = if device.has(Aspect::ExtIntelPciAddress) {
21-
device.get_info::<info::device::PciBdfAddress>()
22-
} else {
23-
String::from("N/A")
20+
let pci_bdf_address = match device.get_info::<info::device::PciBdfAddress>() {
21+
Ok(address) => address,
22+
Err(_) => String::from("N/A"),
2423
};
2524

2625
let integrated_status = if device.has(Aspect::ExtOneapiIsIntegratedGpu) {

‎sycl/sycl-rs/src/context.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ impl From<cxx::UniquePtr<ffi::Context>> for Context {
2121
}
2222

2323
impl Context {
24-
pub fn new(devices: &[&Device]) -> Self {
24+
/// Constructs a context for devices from the same platform.
25+
///
26+
/// Returns an error if the device list is empty or context construction fails.
27+
pub fn new(devices: &[&Device]) -> Result<Self> {
2528
let devices = devices
2629
.iter()
2730
.map(|d| DevicePtr {
2831
ptr: (*d).clone().0,
2932
})
3033
.collect::<Vec<_>>();
3134

32-
ffi::new_context(devices).into()
35+
ffi::new_context(devices).map(Into::into)
3336
}
3437

3538
pub fn create_kernel_bundle_from_source(&self, source: &str) -> Result<SourceKernelBundle> {

‎sycl/sycl-rs/src/info/device-info.rs‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88

99
use sycl_rs_sys::device::ffi;
1010

11-
use crate::{
12-
device::{Aspect, Device},
13-
info::Info,
14-
private::Sealed,
15-
};
11+
use crate::{Result, device::Device, info::Info, private::Sealed};
1612

1713
/// Returns the device type associated with the device. May not return `sycl_rs::info::DeviceType::All`
1814
pub struct DeviceType;
@@ -48,17 +44,13 @@ impl Info for Name {
4844
}
4945

5046
/// Returns the PCI BDF address reported by the Intel SYCL extension.
51-
/// Panics when the device does not support the extension.
47+
/// Returns an error when the device does not support the extension or the query fails.
5248
pub struct PciBdfAddress;
5349
impl Sealed for PciBdfAddress {}
5450
impl Info for PciBdfAddress {
55-
type Item = String;
51+
type Item = Result<String>;
5652
type Target = Device;
5753
fn get_item(target: &Self::Target) -> Self::Item {
58-
assert!(
59-
target.has(Aspect::ExtIntelPciAddress),
60-
"device does not support the Intel PCI address extension"
61-
);
6254
ffi::get_pci_bdf_address(&target.0)
6355
}
6456
}

0 commit comments

Comments
 (0)