Skip to main content

oneapi_rs/
platform.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::platform::ffi;
10
11use crate::{device::Device, info::platform::PlatformInfo};
12
13/// Abstraction for SYCL platform.
14///
15/// The `Platform` struct encapsulates a single SYCL platform on which SYCL kernel functions may be executed.
16/// A SYCL platform must be associated with a single SYCL backend.
17///
18/// A `Platform` is also associated with one or more SYCL devices associated with the same SYCL backend.
19pub struct Platform(pub(crate) cxx::UniquePtr<ffi::Platform>);
20
21impl Platform {
22    /// Returns a [`Vec`] containing all SYCL platforms from all SYCL backends available in the system.
23    pub fn get_platforms() -> Vec<Self> {
24        ffi::get_platforms()
25            .into_iter()
26            .map(|platform| Self(platform.ptr))
27            .collect()
28    }
29
30    /// Returns a [`Vec`] containing all the root devices associated with this `Platform`.
31    pub fn get_devices(&self) -> Vec<Device> {
32        ffi::get_devices(&self.0)
33            .into_iter()
34            .map(|device| Device(device.ptr))
35            .collect()
36    }
37
38    /// Queries this `Platform` for information requested by the generic parameter `Param`.
39    /// The associated type `Param::Item` must be defined in accordance with the info parameters
40    /// in [`oneapi_rs::info::platform`](`crate::info::platform`) to facilitate returning the type associated with the `Param` parameter.
41    pub fn get_info<T: PlatformInfo>(&self) -> T::Item {
42        T::get_item(self)
43    }
44}