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::InfoTarget, private::Sealed};
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 Sealed for Platform {}
22impl InfoTarget for Platform {}
23
24impl Platform {
25    /// Returns a [`Vec`] containing all SYCL platforms from all SYCL backends available in the system.
26    pub fn get_platforms() -> Vec<Self> {
27        ffi::get_platforms()
28            .into_iter()
29            .map(|platform| Self(platform.ptr))
30            .collect()
31    }
32
33    /// Returns a [`Vec`] containing all the root devices associated with this `Platform`.
34    pub fn get_devices(&self) -> Vec<Device> {
35        ffi::get_devices(&self.0)
36            .into_iter()
37            .map(|device| Device(device.ptr))
38            .collect()
39    }
40}