|
6 | 6 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
7 | 7 | // |
8 | 8 |
|
| 9 | +//! # oneAPI-rs |
| 10 | +//! oneAPI-rs is a set of (mostly) safe Rust bindings for SYCL. The bindings mirror the C++ API |
| 11 | +//! where appropriate, but they also introduce some changes. In particular - accessors and command |
| 12 | +//! group handlers have been replaced with USM allocations and free-function kernels. |
| 13 | +//! |
| 14 | +//! # Getting started |
| 15 | +//! 1. Create a [`Queue`](crate::queue::Queue). It's the main entry point to the SYCL API. |
| 16 | +//! ``` |
| 17 | +//! let mut queue = Queue::new(); |
| 18 | +//! ``` |
| 19 | +//! |
| 20 | +//! 2. Create an [USM buffer](crate::buffer::Buffer) for your data. |
| 21 | +//! ``` |
| 22 | +//! let mut device_buffer = queue.alloc_device::<f64>(1024).wait(); |
| 23 | +//! ``` |
| 24 | +//! |
| 25 | +//! 3. Build a SYCL kernel. |
| 26 | +//! ``` |
| 27 | +//! let kernel = queue |
| 28 | +//! .get_context() |
| 29 | +//! .create_kernel_bundle_from_source(IOTA_SRC) |
| 30 | +//! .build() |
| 31 | +//! .get_kernel("iota"); |
| 32 | +//! ``` |
| 33 | +//! |
| 34 | +//! 4. Launch your kernel. |
| 35 | +//! ``` |
| 36 | +//! unsafe { |
| 37 | +//! queue.launch( |
| 38 | +//! NdRange::new([1024], [16]), |
| 39 | +//! &kernel, |
| 40 | +//! (3.14, &mut device_buffer), |
| 41 | +//! ) |
| 42 | +//! } |
| 43 | +//! .wait(); |
| 44 | +//! ``` |
| 45 | +//! |
| 46 | +//! 5. Copy your data to the host. |
| 47 | +//! ``` |
| 48 | +//! let mut host_buffer = queue.alloc_host::<f64>(1024).wait(); |
| 49 | +//! queue.copy(&device_buffer, &mut host_buffer).wait(); |
| 50 | +//! ``` |
| 51 | +//! |
| 52 | +//! You can access your host data just like a normal Rust slice. |
| 53 | +//! ``` |
| 54 | +//! for e in host_buffer.iter() { |
| 55 | +//! print!("{e} "); |
| 56 | +//! } |
| 57 | +//! println!(); |
| 58 | +//! ``` |
| 59 | +//! |
| 60 | +//! # Safety model |
| 61 | +//! - USM allocations are represented by a zero-cost `Buffer` type managed through RAII. |
| 62 | +//! - Note: Unlike SYCL buffers, oneAPI-rs buffers do not rely on accessors. |
| 63 | +//! - Buffers are zero-initialized by default. |
| 64 | +//! - Buffers can only store types that implement [`bytemuck::Pod`]. |
| 65 | +//! - Kernel launch is inherently unsafe. |
| 66 | +//! |
| 67 | +//! # Asynchronous programming model |
| 68 | +//! Each queue operation returns an [`Event`](`crate::event::Event`). You can synchronously |
| 69 | +//! [`.wait()`](crate::event::Event::wait) for it, or asynchronously `.await` it. |
| 70 | +//! |
| 71 | +//! You can also synchronously call [`Queue::wait()`](crate::queue::Queue::wait) to wait for a |
| 72 | +//! [`Queue`](crate::queue::Queue) directly. To do the same asynchronously you have to `.await` an |
| 73 | +//! event returned by [`Queue::barrier()`](crate::queue::Queue::barrier). |
| 74 | +//! |
| 75 | +//! # System dependencies |
| 76 | +//! Make sure to download the [Intel oneAPI toolkit](https://www.intel.com/content/www/us/en/developer/tools/oneapi/oneapi-toolkit-download.html). |
| 77 | +//! Then go to your installation directory and source the `setvars.sh` file. |
| 78 | +
|
9 | 79 | pub mod buffer; |
10 | 80 | pub mod context; |
11 | 81 | pub mod device; |
|
0 commit comments