Skip to main content

Module offload

Module offload 

Source
🔬This is a nightly-only experimental API. (gpu_offload #131513)
Expand description

This module provides support for gpu offloading. For technical details regarding the offload_kernel and offload! macros, see their respective documentation.

§General usage

The offload_kernel macro can be applied to a function to generate the necessary code to launch a kernel on the target device.

ⓘ
#[offload_kernel]
fn kernel(x: *mut [f64; 256]) {
    // SAFETY:
    // calling our `arch` functions and dereferencing a raw pointer is unsafe
    unsafe {
        let n = (*x).len();
        let i = (thread_idx_x() + block_idx_x() * block_dim_x()) as usize;
        if i < n {
            (*x)[i] = i as f64;
        }
    }
}

To launch an offloaded kernel, use the offload! macro. It lets you specify the kernel, the workgroup and thread dimensions, the device to offload to, and the arguments to forward to the device.

ⓘ
let mut x = [0.0f64; 256];
core::offload::offload! {
    kernel = kernel,
    workgroup_dim = [256, 1, 1],
    args = (&mut x as *mut [f64; 256],),
}

For precise information on the underlying offload intrinsic, see its respective documentation.

§Current limitations:

  • Usage is restricted to types supported by the current device-mapping implementation.
  • Functions accepting dyn Trait are not supported.

Re-exports§

use core::ptr::NonNull; 🔒
pub use crate::macros::builtin::offload_kernel;Experimental
pub use crate::offload;Experimental
pub use crate::offload;Experimental

Structs§

LaunchErrorExperimental
Error returned by PartitioningStrategy::check_launch when a launch configuration is not compatible with a partitioning strategy.
RawRegionExperimental
Raw representation used to build a Region from common aggregate types.
RegionExperimental
A memory region bound to a partitioning strategy.

Traits§

DefaultLaunchCheck 👻 Experimental
no-op launch check for kernel arguments that are not Regions.
PartitioningStrategyExperimental
Defines how execution units access memory regions.
RegionLaunchCheck 👻 Experimental
Implementation detail of offload!: validates a Region argument against the launch configuration of an offload call.