Skip to main content

oneapi_rs/
device.rs

1//
2// Copyright (C) 2026 Intel Corporation
3//
4// Under the MIT License or the Apache License v2.0.
5// See LICENSE-MIT and LICENSE-APACHE for license information.
6// SPDX-License-Identifier: MIT OR Apache-2.0
7//
8
9use oneapi_rs_sys::device::ffi;
10
11use crate::{info::device::DeviceInfo, platform::Platform};
12
13/// The `Device` struct encapsulates a single SYCL device on which kernels can be executed.
14///
15/// The `Device` struct provides the common reference semantics.
16pub struct Device(pub(crate) cxx::UniquePtr<ffi::Device>);
17
18impl Device {
19    /// Returns a [`Vec`] containing all the root devices from all SYCL backends
20    /// available in the system which have the device type encapsulated by [`DeviceType`](crate::info::DeviceType).
21    pub fn get_devices() -> Vec<Self> {
22        ffi::get_devices()
23            .into_iter()
24            .map(|device| Self(device.ptr))
25            .collect()
26    }
27
28    /// Queries this `Device` for information requested by the generic parameter `Param`.
29    /// The associated type `Param::Item` must be defined in accordance with the info parameters
30    /// in [`oneapi_rs::info::device`](`crate::info::device`) to facilitate returning the type
31    /// associated with the `Param` parameter.
32    pub fn get_info<T: DeviceInfo>(&self) -> T::Item {
33        T::get_item(self)
34    }
35
36    /// Returns the associated SYCL platform.
37    pub fn get_platform(&self) -> Platform {
38        let raw_platform = ffi::get_platform(&self.0);
39        Platform(raw_platform)
40    }
41}