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
3 changes: 2 additions & 1 deletion oneapi-rs/examples/kernel_launch_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//

use oneapi_rs::prelude::*;

use oneapi_rs::{
buffer::Buffer,
kernel::{KernelArgument, KernelArgumentList},
queue::Queue,
range::NdRange,
usm::{SharedAllocator, UsmAllocator},
Expand Down
4 changes: 2 additions & 2 deletions oneapi-rs/examples/sycl-ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//

use oneapi_rs::info;
use oneapi_rs::platform::Platform;
use oneapi_rs::prelude::*;
use oneapi_rs::{info, platform::Platform};

fn main() {
for platform in Platform::get_platforms() {
Expand Down
13 changes: 4 additions & 9 deletions oneapi-rs/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

use oneapi_rs_sys::device::ffi;

use crate::{info::device::DeviceInfo, platform::Platform};
use crate::{info::InfoTarget, platform::Platform, private::Sealed};

/// The `Device` struct encapsulates a single SYCL device on which kernels can be executed.
///
/// The `Device` struct provides the common reference semantics.
pub struct Device(pub(crate) cxx::UniquePtr<ffi::Device>);

impl Sealed for Device {}
impl InfoTarget for Device {}

impl From<cxx::UniquePtr<ffi::Device>> for Device {
fn from(value: cxx::UniquePtr<ffi::Device>) -> Self {
Self(value)
Expand All @@ -31,14 +34,6 @@ impl Device {
.collect()
}

/// Queries this `Device` for information requested by the generic parameter `Param`.
/// The associated type `Param::Item` must be defined in accordance with the info parameters
/// in [`oneapi_rs::info::device`](`crate::info::device`) to facilitate returning the type
/// associated with the `Param` parameter.
pub fn get_info<T: DeviceInfo>(&self) -> T::Item {
T::get_item(self)
}

/// Returns the associated SYCL platform.
pub fn get_platform(&self) -> Platform {
let raw_platform = ffi::get_platform(&self.0);
Comment on lines 37 to 39
Expand Down
9 changes: 4 additions & 5 deletions oneapi-rs/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@ use oneapi_rs_sys::{event::ffi, types::SharedWaker};

use pin_project::pin_project;

use crate::{info::event::EventInfo, queue::Queue};
use crate::{info::InfoTarget, private::Sealed, queue::Queue};

pub struct Event(pub(crate) cxx::UniquePtr<ffi::Event>);

impl Event {
pub fn wait(&mut self) {
ffi::wait(&mut self.0);
}

pub fn get_info<T: EventInfo>(&self) -> T::Item {
T::get_item(self)
}
}

impl Sealed for Event {}
impl InfoTarget for Event {}

Comment on lines +29 to +31
impl From<cxx::UniquePtr<ffi::Event>> for Event {
fn from(value: cxx::UniquePtr<ffi::Event>) -> Self {
Self(value)
Expand Down
19 changes: 19 additions & 0 deletions oneapi-rs/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,22 @@ pub use oneapi_rs_sys::device::ffi::DeviceType;

/// Event status of the contained action associated with this event.
pub use oneapi_rs_sys::event::ffi::EventCommandStatus;

use crate::private::Sealed;

/// Types which can return an Item of information for a given Target.
pub trait Info: Sealed {
type Item;
type Target;

/// Returns information for a given Target.
fn get_item(target: &Self::Target) -> Self::Item;
}

/// Types which can be queried for information.
pub trait InfoTarget: Sealed {
/// Queries this object for information requested by given generic parameter.
fn get_info<T: Info<Target = Self>>(&self) -> T::Item {
T::get_item(self)
}
}
31 changes: 17 additions & 14 deletions oneapi-rs/src/info/device-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,39 @@
//

use crate::device::Device;
use crate::info::Info;
use crate::private::Sealed;
use oneapi_rs_sys::device::ffi;

pub trait DeviceInfo {
type Item;
fn get_item(device: &Device) -> Self::Item;
}

/// Returns the device type associated with the device. May not return `oneapi_rs::info::DeviceType::All`
pub struct DeviceType;
impl DeviceInfo for DeviceType {
impl Sealed for DeviceType {}
impl Info for DeviceType {
type Item = crate::info::DeviceType;
fn get_item(device: &Device) -> Self::Item {
ffi::get_device_type(&device.0)
type Target = Device;
fn get_item(target: &Self::Target) -> Self::Item {
ffi::get_device_type(&target.0)
}
}

/// Returns a backend-defined device version.
pub struct Version;
impl DeviceInfo for Version {
impl Sealed for Version {}
impl Info for Version {
type Item = String;
fn get_item(device: &Device) -> Self::Item {
ffi::get_version(&device.0)
type Target = Device;
fn get_item(target: &Self::Target) -> Self::Item {
ffi::get_version(&target.0)
}
}

/// Returns the device name of this SYCL device.
pub struct Name;
impl DeviceInfo for Name {
impl Sealed for Name {}
impl Info for Name {
type Item = String;
fn get_item(device: &Device) -> Self::Item {
ffi::get_name(&device.0)
type Target = Device;
fn get_item(target: &Self::Target) -> Self::Item {
ffi::get_name(&target.0)
}
}
15 changes: 7 additions & 8 deletions oneapi-rs/src/info/event-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
//

use crate::event::Event;
use crate::info::Info;
use crate::private::Sealed;
use oneapi_rs_sys::event::ffi;

pub trait EventInfo {
type Item;
fn get_item(event: &Event) -> Self::Item;
}

/// Returns the event status of the action associated with this event.
pub struct CommandExecutionStatus;
impl EventInfo for CommandExecutionStatus {
impl Sealed for CommandExecutionStatus {}
impl Info for CommandExecutionStatus {
type Item = crate::info::EventCommandStatus;
fn get_item(event: &Event) -> Self::Item {
ffi::get_command_execution_status(&event.0)
type Target = Event;
fn get_item(target: &Self::Target) -> Self::Item {
ffi::get_command_execution_status(&target.0)
}
}
31 changes: 17 additions & 14 deletions oneapi-rs/src/info/platform-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,40 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//

use crate::info::Info;
use crate::platform::Platform;
use crate::private::Sealed;
use oneapi_rs_sys::platform::ffi;

pub trait PlatformInfo {
type Item;
fn get_item(platform: &Platform) -> Self::Item;
}

/// Returns a backend-defined platform version.
pub struct Version;
impl PlatformInfo for Version {
impl Sealed for Version {}
impl Info for Version {
type Item = String;
fn get_item(platform: &Platform) -> Self::Item {
ffi::get_version(&platform.0)
type Target = Platform;
fn get_item(target: &Self::Target) -> Self::Item {
ffi::get_version(&target.0)
}
}

/// Returns the name of the platform.
pub struct Name;
impl PlatformInfo for Name {
impl Sealed for Name {}
impl Info for Name {
type Item = String;
fn get_item(platform: &Platform) -> Self::Item {
ffi::get_name(&platform.0)
type Target = Platform;
fn get_item(target: &Self::Target) -> Self::Item {
ffi::get_name(&target.0)
}
}

/// Returns the name of the vendor providing the platform.
pub struct Vendor;
impl PlatformInfo for Vendor {
impl Sealed for Vendor {}
impl Info for Vendor {
type Item = String;
fn get_item(platform: &Platform) -> Self::Item {
ffi::get_vendor(&platform.0)
type Target = Platform;
fn get_item(target: &Self::Target) -> Self::Item {
ffi::get_vendor(&target.0)
}
}
1 change: 1 addition & 0 deletions oneapi-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod event;
pub mod info;
pub mod kernel;
pub mod platform;
pub mod prelude;
pub mod queue;
pub mod range;
pub mod usm;
Expand Down
12 changes: 4 additions & 8 deletions oneapi-rs/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use oneapi_rs_sys::platform::ffi;

use crate::{device::Device, info::platform::PlatformInfo};
use crate::{device::Device, info::InfoTarget, private::Sealed};

/// Abstraction for SYCL platform.
///
Expand All @@ -18,6 +18,9 @@ use crate::{device::Device, info::platform::PlatformInfo};
/// A `Platform` is also associated with one or more SYCL devices associated with the same SYCL backend.
pub struct Platform(pub(crate) cxx::UniquePtr<ffi::Platform>);

impl Sealed for Platform {}
impl InfoTarget for Platform {}

Comment on lines +21 to +23
impl Platform {
/// Returns a [`Vec`] containing all SYCL platforms from all SYCL backends available in the system.
pub fn get_platforms() -> Vec<Self> {
Expand All @@ -34,11 +37,4 @@ impl Platform {
.map(|device| Device(device.ptr))
.collect()
}

/// Queries this `Platform` for information requested by the generic parameter `Param`.
/// The associated type `Param::Item` must be defined in accordance with the info parameters
/// in [`oneapi_rs::info::platform`](`crate::info::platform`) to facilitate returning the type associated with the `Param` parameter.
pub fn get_info<T: PlatformInfo>(&self) -> T::Item {
T::get_item(self)
}
}
4 changes: 4 additions & 0 deletions oneapi-rs/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub use crate::{
info::InfoTarget,
kernel::{KernelArgument, KernelArgumentList},
};