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::InfoTarget, platform::Platform, private::Sealed};
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 Sealed for Device {}
19impl InfoTarget for Device {}
20
21impl From<cxx::UniquePtr<ffi::Device>> for Device {
22 fn from(value: cxx::UniquePtr<ffi::Device>) -> Self {
23 Self(value)
24 }
25}
26
27impl Device {
28 /// Returns a [`Vec`] containing all the root devices from all SYCL backends
29 /// available in the system which have the device type encapsulated by [`DeviceType`](crate::info::DeviceType).
30 pub fn get_devices() -> Vec<Self> {
31 ffi::get_devices()
32 .into_iter()
33 .map(|device| Self(device.ptr))
34 .collect()
35 }
36
37 /// Returns the associated SYCL platform.
38 pub fn get_platform(&self) -> Platform {
39 let raw_platform = ffi::get_platform(&self.0);
40 Platform(raw_platform)
41 }
42}
43
44impl Clone for Device {
45 fn clone(&self) -> Self {
46 ffi::clone(&self.0).into()
47 }
48}