offload in std::intrinsics - Rust
Description: Generates the LLVM body of a wrapper function to offload a kernel `f`.

## offload

# Function offload

Source

    pub const fn offload<F, T, R>(
        f: F,
        workgroup_dim: [u32; 3],
        thread_dim: [u32; 3],
        args: T,
    ) -> Rwhere
        T: Tuple,

🔬This is a nightly-only experimental API. (`core_intrinsics`)
Expand description

Generates the LLVM body of a wrapper function to offload a kernel `f`.

Type Parameters:

- `F`: The kernel to offload. Must be a function item.
- `T`: A tuple of arguments passed to `f`.
- `R`: The return type of the kernel.

Arguments:

- `f`: The kernel function to offload.
- `workgroup_dim`: A 3D size specifying the number of workgroups to launch.
- `thread_dim`: A 3D size specifying the number of threads per workgroup.
- `args`: A tuple of arguments forwarded to `f`.

Example usage (pseudocode):

ⓘ

    fn kernel(x: *mut [f64; 128]) {
        core::intrinsics::offload(kernel_1, [256, 1, 1], [32, 1, 1], (x,))
    }

    #[cfg(target_os = "linux")]
    extern "C" {
        pub fn kernel_1(array_b: *mut [f64; 128]);
    }

    #[cfg(not(target_os = "linux"))]
    #[rustc_offload_kernel]
    extern "gpu-kernel" fn kernel_1(x: *mut [f64; 128]) {
        unsafe { (*x)[0] = 21.0 };
    }

For reference, see the Clang documentation on offloading: https://clang.llvm.org/docs/OffloadingDesign.html.