From b0c5f2dd18812412ea97ff02b5eda252fc5ac103 Mon Sep 17 00:00:00 2001 From: Szymon Zadworny Date: Wed, 29 Jul 2026 09:48:22 +0000 Subject: [PATCH 1/9] Add generic Info traits --- oneapi-rs/src/info.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/oneapi-rs/src/info.rs b/oneapi-rs/src/info.rs index 9811994..6e78ad5 100644 --- a/oneapi-rs/src/info.rs +++ b/oneapi-rs/src/info.rs @@ -20,3 +20,16 @@ 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; + +pub trait Info { + type Item; + type Target; + + fn get_item(target: &Self::Target) -> Self::Item; +} + +pub trait InfoTarget { + fn get_info>(&self) -> T::Item { + T::get_item(self) + } +} From badc43235378fd8fd61998151162a2c9f599610f Mon Sep 17 00:00:00 2001 From: Szymon Zadworny Date: Wed, 29 Jul 2026 09:49:10 +0000 Subject: [PATCH 2/9] Refactor Event to use new Info trait --- oneapi-rs/src/event.rs | 8 +++----- oneapi-rs/src/info/event-info.rs | 13 +++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/oneapi-rs/src/event.rs b/oneapi-rs/src/event.rs index 0b120c1..e4be3db 100644 --- a/oneapi-rs/src/event.rs +++ b/oneapi-rs/src/event.rs @@ -16,7 +16,7 @@ use oneapi_rs_sys::{event::ffi, types::SharedWaker}; use pin_project::pin_project; -use crate::{info::event::EventInfo, queue::Queue}; +use crate::{info::InfoTarget, queue::Queue}; pub struct Event(pub(crate) cxx::UniquePtr); @@ -24,12 +24,10 @@ impl Event { pub fn wait(&mut self) { ffi::wait(&mut self.0); } - - pub fn get_info(&self) -> T::Item { - T::get_item(self) - } } +impl InfoTarget for Event {} + impl From> for Event { fn from(value: cxx::UniquePtr) -> Self { Self(value) diff --git a/oneapi-rs/src/info/event-info.rs b/oneapi-rs/src/info/event-info.rs index 1a8e6bf..55df74e 100644 --- a/oneapi-rs/src/info/event-info.rs +++ b/oneapi-rs/src/info/event-info.rs @@ -7,18 +7,15 @@ // use crate::event::Event; +use crate::info::Info; 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 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) } } From e3596e7a259f8e70b93715ec40f1076a89ce352e Mon Sep 17 00:00:00 2001 From: Szymon Zadworny Date: Wed, 29 Jul 2026 10:06:05 +0000 Subject: [PATCH 3/9] Refactor Platform to use new Info trait --- oneapi-rs/src/info/platform-info.rs | 27 +++++++++++++-------------- oneapi-rs/src/platform.rs | 11 +++-------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/oneapi-rs/src/info/platform-info.rs b/oneapi-rs/src/info/platform-info.rs index 168381d..49f70e2 100644 --- a/oneapi-rs/src/info/platform-info.rs +++ b/oneapi-rs/src/info/platform-info.rs @@ -6,37 +6,36 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // +use crate::info::Info; use crate::platform::Platform; 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 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 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 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) } } diff --git a/oneapi-rs/src/platform.rs b/oneapi-rs/src/platform.rs index 7af6fe3..fd88332 100644 --- a/oneapi-rs/src/platform.rs +++ b/oneapi-rs/src/platform.rs @@ -8,7 +8,7 @@ use oneapi_rs_sys::platform::ffi; -use crate::{device::Device, info::platform::PlatformInfo}; +use crate::{device::Device, info::InfoTarget}; /// Abstraction for SYCL platform. /// @@ -18,6 +18,8 @@ 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); +impl InfoTarget for Platform {} + impl Platform { /// Returns a [`Vec`] containing all SYCL platforms from all SYCL backends available in the system. pub fn get_platforms() -> Vec { @@ -34,11 +36,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(&self) -> T::Item { - T::get_item(self) - } } From 53af259c559bd39804c98cc9709b5e8a9edf09d1 Mon Sep 17 00:00:00 2001 From: Szymon Zadworny Date: Wed, 29 Jul 2026 10:12:53 +0000 Subject: [PATCH 4/9] Refactor Device to use new Info trait --- oneapi-rs/src/device.rs | 12 +++--------- oneapi-rs/src/info/device-info.rs | 27 +++++++++++++-------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/oneapi-rs/src/device.rs b/oneapi-rs/src/device.rs index 8560062..18e0e14 100644 --- a/oneapi-rs/src/device.rs +++ b/oneapi-rs/src/device.rs @@ -8,13 +8,15 @@ use oneapi_rs_sys::device::ffi; -use crate::{info::device::DeviceInfo, platform::Platform}; +use crate::{info::InfoTarget, platform::Platform}; /// 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); +impl InfoTarget for Device {} + impl From> for Device { fn from(value: cxx::UniquePtr) -> Self { Self(value) @@ -31,14 +33,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(&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); diff --git a/oneapi-rs/src/info/device-info.rs b/oneapi-rs/src/info/device-info.rs index f630b72..6d3b6b4 100644 --- a/oneapi-rs/src/info/device-info.rs +++ b/oneapi-rs/src/info/device-info.rs @@ -6,37 +6,36 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // +use crate::info::Info; use crate::device::Device; 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 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 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 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) } } From 06f55e09cc77f975904653391a0f45897297cadd Mon Sep 17 00:00:00 2001 From: Szymon Zadworny Date: Wed, 29 Jul 2026 10:20:46 +0000 Subject: [PATCH 5/9] Add prelude module --- oneapi-rs/examples/sycl-ls.rs | 2 +- oneapi-rs/src/lib.rs | 1 + oneapi-rs/src/prelude.rs | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 oneapi-rs/src/prelude.rs diff --git a/oneapi-rs/examples/sycl-ls.rs b/oneapi-rs/examples/sycl-ls.rs index 7473408..25dfa48 100644 --- a/oneapi-rs/examples/sycl-ls.rs +++ b/oneapi-rs/examples/sycl-ls.rs @@ -6,7 +6,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // -use oneapi_rs::info; +use oneapi_rs::info::{self, InfoTarget}; use oneapi_rs::platform::Platform; fn main() { diff --git a/oneapi-rs/src/lib.rs b/oneapi-rs/src/lib.rs index f179f20..6840b8b 100644 --- a/oneapi-rs/src/lib.rs +++ b/oneapi-rs/src/lib.rs @@ -6,6 +6,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // +pub mod prelude; pub mod buffer; pub mod context; pub mod device; diff --git a/oneapi-rs/src/prelude.rs b/oneapi-rs/src/prelude.rs new file mode 100644 index 0000000..0a66a27 --- /dev/null +++ b/oneapi-rs/src/prelude.rs @@ -0,0 +1,4 @@ +pub use crate::{ + info::InfoTarget, + kernel::{KernelArgument, KernelArgumentList} +}; From 8e6ca87efd28b8cab5b8eb1eb1afd9fc2b1c450b Mon Sep 17 00:00:00 2001 From: Szymon Zadworny Date: Wed, 29 Jul 2026 10:33:04 +0000 Subject: [PATCH 6/9] Update examples --- oneapi-rs/examples/kernel_launch_derive.rs | 2 +- oneapi-rs/examples/sycl-ls.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/oneapi-rs/examples/kernel_launch_derive.rs b/oneapi-rs/examples/kernel_launch_derive.rs index 8be1e8a..61d4125 100644 --- a/oneapi-rs/examples/kernel_launch_derive.rs +++ b/oneapi-rs/examples/kernel_launch_derive.rs @@ -7,8 +7,8 @@ // use oneapi_rs::{ + prelude::*, buffer::Buffer, - kernel::{KernelArgument, KernelArgumentList}, queue::Queue, range::NdRange, usm::{SharedAllocator, UsmAllocator}, diff --git a/oneapi-rs/examples/sycl-ls.rs b/oneapi-rs/examples/sycl-ls.rs index 25dfa48..a604c2b 100644 --- a/oneapi-rs/examples/sycl-ls.rs +++ b/oneapi-rs/examples/sycl-ls.rs @@ -6,8 +6,11 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // -use oneapi_rs::info::{self, InfoTarget}; -use oneapi_rs::platform::Platform; +use oneapi_rs::{ + prelude::*, + info, + platform::Platform +}; fn main() { for platform in Platform::get_platforms() { From 7f5b1cefb9196fe81658541d859ec23b8a2a8e8a Mon Sep 17 00:00:00 2001 From: Szymon Zadworny Date: Wed, 29 Jul 2026 10:33:16 +0000 Subject: [PATCH 7/9] cargo fmt --- oneapi-rs/examples/kernel_launch_derive.rs | 3 ++- oneapi-rs/examples/sycl-ls.rs | 7 ++----- oneapi-rs/src/info/device-info.rs | 2 +- oneapi-rs/src/lib.rs | 2 +- oneapi-rs/src/prelude.rs | 2 +- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/oneapi-rs/examples/kernel_launch_derive.rs b/oneapi-rs/examples/kernel_launch_derive.rs index 61d4125..d70d7ec 100644 --- a/oneapi-rs/examples/kernel_launch_derive.rs +++ b/oneapi-rs/examples/kernel_launch_derive.rs @@ -6,8 +6,9 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // +use oneapi_rs::prelude::*; + use oneapi_rs::{ - prelude::*, buffer::Buffer, queue::Queue, range::NdRange, diff --git a/oneapi-rs/examples/sycl-ls.rs b/oneapi-rs/examples/sycl-ls.rs index a604c2b..e6e1419 100644 --- a/oneapi-rs/examples/sycl-ls.rs +++ b/oneapi-rs/examples/sycl-ls.rs @@ -6,11 +6,8 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // -use oneapi_rs::{ - prelude::*, - info, - platform::Platform -}; +use oneapi_rs::prelude::*; +use oneapi_rs::{info, platform::Platform}; fn main() { for platform in Platform::get_platforms() { diff --git a/oneapi-rs/src/info/device-info.rs b/oneapi-rs/src/info/device-info.rs index 6d3b6b4..fc28835 100644 --- a/oneapi-rs/src/info/device-info.rs +++ b/oneapi-rs/src/info/device-info.rs @@ -6,8 +6,8 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // -use crate::info::Info; use crate::device::Device; +use crate::info::Info; use oneapi_rs_sys::device::ffi; /// Returns the device type associated with the device. May not return `oneapi_rs::info::DeviceType::All` diff --git a/oneapi-rs/src/lib.rs b/oneapi-rs/src/lib.rs index 6840b8b..42156bf 100644 --- a/oneapi-rs/src/lib.rs +++ b/oneapi-rs/src/lib.rs @@ -6,7 +6,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // -pub mod prelude; pub mod buffer; pub mod context; pub mod device; @@ -14,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; diff --git a/oneapi-rs/src/prelude.rs b/oneapi-rs/src/prelude.rs index 0a66a27..5cb0e43 100644 --- a/oneapi-rs/src/prelude.rs +++ b/oneapi-rs/src/prelude.rs @@ -1,4 +1,4 @@ pub use crate::{ info::InfoTarget, - kernel::{KernelArgument, KernelArgumentList} + kernel::{KernelArgument, KernelArgumentList}, }; From a3e9a2939b6d62a8d23432a7a73d321597c08215 Mon Sep 17 00:00:00 2001 From: Szymon Zadworny Date: Wed, 29 Jul 2026 10:41:35 +0000 Subject: [PATCH 8/9] Add documentation --- oneapi-rs/src/info.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/oneapi-rs/src/info.rs b/oneapi-rs/src/info.rs index 6e78ad5..72ca688 100644 --- a/oneapi-rs/src/info.rs +++ b/oneapi-rs/src/info.rs @@ -21,14 +21,18 @@ 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; +/// Types which can return an Item of information for a given Target. pub trait Info { 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 { + /// Queries this object for information requested by given generic parameter. fn get_info>(&self) -> T::Item { T::get_item(self) } From 25225ddfd9d4824e96ca291aac5527dc0aad7ddb Mon Sep 17 00:00:00 2001 From: Szymon Zadworny Date: Wed, 29 Jul 2026 11:34:59 +0000 Subject: [PATCH 9/9] Make info traits sealed --- oneapi-rs/src/device.rs | 3 ++- oneapi-rs/src/event.rs | 3 ++- oneapi-rs/src/info.rs | 6 ++++-- oneapi-rs/src/info/device-info.rs | 4 ++++ oneapi-rs/src/info/event-info.rs | 2 ++ oneapi-rs/src/info/platform-info.rs | 4 ++++ oneapi-rs/src/platform.rs | 3 ++- 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/oneapi-rs/src/device.rs b/oneapi-rs/src/device.rs index 18e0e14..d2d4d5c 100644 --- a/oneapi-rs/src/device.rs +++ b/oneapi-rs/src/device.rs @@ -8,13 +8,14 @@ use oneapi_rs_sys::device::ffi; -use crate::{info::InfoTarget, 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); +impl Sealed for Device {} impl InfoTarget for Device {} impl From> for Device { diff --git a/oneapi-rs/src/event.rs b/oneapi-rs/src/event.rs index e4be3db..9e8e1c3 100644 --- a/oneapi-rs/src/event.rs +++ b/oneapi-rs/src/event.rs @@ -16,7 +16,7 @@ use oneapi_rs_sys::{event::ffi, types::SharedWaker}; use pin_project::pin_project; -use crate::{info::InfoTarget, queue::Queue}; +use crate::{info::InfoTarget, private::Sealed, queue::Queue}; pub struct Event(pub(crate) cxx::UniquePtr); @@ -26,6 +26,7 @@ impl Event { } } +impl Sealed for Event {} impl InfoTarget for Event {} impl From> for Event { diff --git a/oneapi-rs/src/info.rs b/oneapi-rs/src/info.rs index 72ca688..821c399 100644 --- a/oneapi-rs/src/info.rs +++ b/oneapi-rs/src/info.rs @@ -21,8 +21,10 @@ 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 { +pub trait Info: Sealed { type Item; type Target; @@ -31,7 +33,7 @@ pub trait Info { } /// Types which can be queried for information. -pub trait InfoTarget { +pub trait InfoTarget: Sealed { /// Queries this object for information requested by given generic parameter. fn get_info>(&self) -> T::Item { T::get_item(self) diff --git a/oneapi-rs/src/info/device-info.rs b/oneapi-rs/src/info/device-info.rs index fc28835..3696850 100644 --- a/oneapi-rs/src/info/device-info.rs +++ b/oneapi-rs/src/info/device-info.rs @@ -8,10 +8,12 @@ use crate::device::Device; use crate::info::Info; +use crate::private::Sealed; use oneapi_rs_sys::device::ffi; /// Returns the device type associated with the device. May not return `oneapi_rs::info::DeviceType::All` pub struct DeviceType; +impl Sealed for DeviceType {} impl Info for DeviceType { type Item = crate::info::DeviceType; type Target = Device; @@ -22,6 +24,7 @@ impl Info for DeviceType { /// Returns a backend-defined device version. pub struct Version; +impl Sealed for Version {} impl Info for Version { type Item = String; type Target = Device; @@ -32,6 +35,7 @@ impl Info for Version { /// Returns the device name of this SYCL device. pub struct Name; +impl Sealed for Name {} impl Info for Name { type Item = String; type Target = Device; diff --git a/oneapi-rs/src/info/event-info.rs b/oneapi-rs/src/info/event-info.rs index 55df74e..9517429 100644 --- a/oneapi-rs/src/info/event-info.rs +++ b/oneapi-rs/src/info/event-info.rs @@ -8,10 +8,12 @@ use crate::event::Event; use crate::info::Info; +use crate::private::Sealed; use oneapi_rs_sys::event::ffi; /// Returns the event status of the action associated with this event. pub struct CommandExecutionStatus; +impl Sealed for CommandExecutionStatus {} impl Info for CommandExecutionStatus { type Item = crate::info::EventCommandStatus; type Target = Event; diff --git a/oneapi-rs/src/info/platform-info.rs b/oneapi-rs/src/info/platform-info.rs index 49f70e2..179e4a8 100644 --- a/oneapi-rs/src/info/platform-info.rs +++ b/oneapi-rs/src/info/platform-info.rs @@ -8,10 +8,12 @@ use crate::info::Info; use crate::platform::Platform; +use crate::private::Sealed; use oneapi_rs_sys::platform::ffi; /// Returns a backend-defined platform version. pub struct Version; +impl Sealed for Version {} impl Info for Version { type Item = String; type Target = Platform; @@ -22,6 +24,7 @@ impl Info for Version { /// Returns the name of the platform. pub struct Name; +impl Sealed for Name {} impl Info for Name { type Item = String; type Target = Platform; @@ -32,6 +35,7 @@ impl Info for Name { /// Returns the name of the vendor providing the platform. pub struct Vendor; +impl Sealed for Vendor {} impl Info for Vendor { type Item = String; type Target = Platform; diff --git a/oneapi-rs/src/platform.rs b/oneapi-rs/src/platform.rs index fd88332..c398771 100644 --- a/oneapi-rs/src/platform.rs +++ b/oneapi-rs/src/platform.rs @@ -8,7 +8,7 @@ use oneapi_rs_sys::platform::ffi; -use crate::{device::Device, info::InfoTarget}; +use crate::{device::Device, info::InfoTarget, private::Sealed}; /// Abstraction for SYCL platform. /// @@ -18,6 +18,7 @@ use crate::{device::Device, info::InfoTarget}; /// A `Platform` is also associated with one or more SYCL devices associated with the same SYCL backend. pub struct Platform(pub(crate) cxx::UniquePtr); +impl Sealed for Platform {} impl InfoTarget for Platform {} impl Platform {