Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sycl/sycl-rs-sys/src/context-sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ pub mod ffi {
#[namespace = "sycl_shims"]
type Context = crate::types::ffi::Context;

fn new_context(devices: Vec<DevicePtr>) -> UniquePtr<Context>;
fn new_context(devices: Vec<DevicePtr>) -> Result<UniquePtr<Context>>;
}
}
2 changes: 1 addition & 1 deletion sycl/sycl-rs-sys/src/device-sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub mod ffi {
fn get_device_type(device: &Device) -> DeviceType;
fn get_version(device: &Device) -> String;
fn get_name(device: &Device) -> String;
fn get_pci_bdf_address(device: &Device) -> String;
fn get_pci_bdf_address(device: &Device) -> Result<String>;

fn enable_peer_access(device: &mut UniquePtr<Device>, peer: &Device) -> Result<()>;
fn disable_peer_access(device: &mut UniquePtr<Device>, peer: &Device) -> Result<()>;
Expand Down
7 changes: 3 additions & 4 deletions sycl/sycl-rs/examples/sycl-ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ fn main() {
let device_version = device.get_info::<info::device::Version>();
let platform_version = platform.get_info::<info::platform::Version>();

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

let integrated_status = if device.has(Aspect::ExtOneapiIsIntegratedGpu) {
Expand Down
7 changes: 5 additions & 2 deletions sycl/sycl-rs/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ impl From<cxx::UniquePtr<ffi::Context>> for Context {
}

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

ffi::new_context(devices).into()
ffi::new_context(devices).map(Into::into)
}

pub fn create_kernel_bundle_from_source(&self, source: &str) -> Result<SourceKernelBundle> {
Expand Down
14 changes: 3 additions & 11 deletions sycl/sycl-rs/src/info/device-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

use sycl_rs_sys::device::ffi;

use crate::{
device::{Aspect, Device},
info::Info,
private::Sealed,
};
use crate::{Result, device::Device, info::Info, private::Sealed};

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

/// Returns the PCI BDF address reported by the Intel SYCL extension.
/// Panics when the device does not support the extension.
/// Returns an error when the device does not support the extension or the query fails.
pub struct PciBdfAddress;
impl Sealed for PciBdfAddress {}
impl Info for PciBdfAddress {
type Item = String;
type Item = Result<String>;
type Target = Device;
fn get_item(target: &Self::Target) -> Self::Item {
assert!(
target.has(Aspect::ExtIntelPciAddress),
"device does not support the Intel PCI address extension"
);
ffi::get_pci_bdf_address(&target.0)
}
}
Loading