Skip to main content

offload

Macro offload 

Source
macro_rules! offload {
    ($($field:ident = $val:expr),* $(,)?) => { ... };
    (
        @ munch[kernel = $val:expr $(, $rest_f:ident = $rest_v:expr)*]; kernel
        = NONE; workgroup_dim = $w:tt; thread_dim = $t:tt; dyn_cache = $d:tt;
        device = $device:tt; args = $a:tt
    ) => { ... };
    (
        @ munch[kernel = $val:expr $(, $rest_f:ident = $rest_v:expr)*]; kernel
        = (SOME $old:expr); workgroup_dim = $w:tt; thread_dim = $t:tt;
        dyn_cache = $d:tt; device = $device:tt; args = $a:tt
    ) => { ... };
    (
        @ munch[workgroup_dim = $val:expr $(, $rest_f:ident = $rest_v:expr)*];
        kernel = $k:tt; workgroup_dim = ([1, 1, 1]); thread_dim = $t:tt;
        dyn_cache = $d:tt; device = $device:tt; args = $a:tt
    ) => { ... };
    (
        @ munch[workgroup_dim = $val:expr $(, $rest_f:ident = $rest_v:expr)*];
        kernel = $k:tt; workgroup_dim = (SOME $old:expr); thread_dim = $t:tt;
        dyn_cache = $d:tt; device = $device:tt; args = $a:tt
    ) => { ... };
    (
        @ munch[thread_dim = $val:expr $(, $rest_f:ident = $rest_v:expr)*];
        kernel = $k:tt; workgroup_dim = $w:tt; thread_dim = ([1, 1, 1]);
        dyn_cache = $d:tt; device = $device:tt; args = $a:tt
    ) => { ... };
    (
        @ munch[thread_dim = $val:expr $(, $rest_f:ident = $rest_v:expr)*];
        kernel = $k:tt; workgroup_dim = $w:tt; thread_dim = (SOME $old:expr);
        dyn_cache = $d:tt; device = $device:tt; args = $a:tt
    ) => { ... };
    (
        @ munch[dyn_cache = $val:expr $(, $rest_f:ident = $rest_v:expr)*];
        kernel = $k:tt; workgroup_dim = $w:tt; thread_dim = $t:tt; dyn_cache =
        (0); device = $device:tt; args = $a:tt
    ) => { ... };
    (
        @ munch[dyn_cache = $val:expr $(, $rest_f:ident = $rest_v:expr)*];
        kernel = $k:tt; workgroup_dim = $w:tt; thread_dim = $t:tt; dyn_cache =
        (SOME $old:expr); device = $device:tt; args = $a:tt
    ) => { ... };
    (
        @ munch[device = $val:expr $(, $rest_f:ident = $rest_v:expr)*]; kernel
        = $k:tt; workgroup_dim = $w:tt; thread_dim = $t:tt; dyn_cache = $d:tt;
        device = NONE; args = $a:tt
    ) => { ... };
    (
        @ munch[device = $val:expr $(, $rest_f:ident = $rest_v:expr)*]; kernel
        = $k:tt; workgroup_dim = $w:tt; thread_dim = $t:tt; dyn_cache = $d:tt;
        device = (SOME $old:expr); args = $a:tt
    ) => { ... };
    (
        @ munch[args = $val:expr $(, $rest_f:ident = $rest_v:expr)*]; kernel =
        $k:tt; workgroup_dim = $w:tt; thread_dim = $t:tt; dyn_cache = $d:tt;
        device = $device:tt; args = NONE
    ) => { ... };
    (
        @ munch[args = $val:expr $(, $rest_f:ident = $rest_v:expr)*]; kernel =
        $k:tt; workgroup_dim = $w:tt; thread_dim = $t:tt; dyn_cache = $d:tt;
        device = $device:tt; args = (SOME $old:expr)
    ) => { ... };
    (
        @ munch[$invalid:ident = $val:expr $(, $rest_f:ident =
        $rest_v:expr)*]; kernel = $k:tt; workgroup_dim = $w:tt; thread_dim =
        $t:tt; dyn_cache = $d:tt; device = $device:tt; args = $a:tt
    ) => { ... };
    (
        @ munch[]; kernel = NONE; workgroup_dim = $w:tt; thread_dim = $t:tt;
        dyn_cache = $d:tt; device = $device:tt; args = $a:tt
    ) => { ... };
    (
        @ munch[]; kernel = $k:tt; workgroup_dim = $w:tt; thread_dim = $t:tt;
        dyn_cache = $d:tt; device = $device:tt; args = NONE
    ) => { ... };
    (
        @ munch[]; kernel = (SOME $kernel:expr); workgroup_dim = $w:tt;
        thread_dim = $t:tt; dyn_cache = $d:tt; device = $device:tt; args =
        (SOME $args:expr)
    ) => { ... };
    (@ value(SOME $val:expr)) => { ... };
    (@ value($val:expr)) => { ... };
    (@ device NONE) => { ... };
    (@ device(SOME $val:expr)) => { ... };
}
🔬This is a nightly-only experimental API. (gpu_offload #131513)
Expand description

Launches a kernel on an offload device (e.g., a GPU).

This macro is an interface over the offload intrinsic. The kernel itself must be defined using the offload_kernel macro.

The following named arguments are accepted:

  • kernel: The kernel function to offload. Must be a function item. (required)
  • args: A tuple of arguments forwarded to kernel. (required)
  • workgroup_dim: A 3D size specifying the number of workgroups to launch. Defaults to [1, 1, 1].
  • thread_dim: A 3D size specifying the number of threads per workgroup. Defaults to [1, 1, 1].
  • dyn_cache: The amount of dynamic shared memory, in bytes, to allocate for the kernel. Defaults to 0.
  • device: The index of the device to offload to. Must be >= 0. If omitted, the default device is used. Use crate::intrinsics::offload_get_num_devices to discover which device ids are valid.

Each argument may only be specified once.

§Examples

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