Macro rust_gpu_tools::program_closures[][src]

macro_rules! program_closures {
    (| $program : ident, $arg : ident | -> $ret : ty $body : block) => { ... };
    (| $program : ident, $arg : ident : $arg_type : ty | -> $ret : ty $body :
 block) => { ... };
}
Expand description

Creates two closures, one for CUDA, one for OpenCL for the given one.

This macro is used to be able to interact with rust-gpu-tools with unified code for both, CUDA and OpenCL, without the need to repeat the code. The input parameter is a program and it will be mapped to [&cuda::Program] and [&opencl::Program].

The second parameter is a single arbitrary argument, which will be passed on into the closure. This is useful when you e.g. need to pass in a mutable reference. Such a reference cannot be shared between closures, hence we pass it on, so that the compiler knows that it is used at most once.

Depending on whether the cuda and/or opencl feature is enabled, it will do the correct thing and not specify one of them if it is appropriate.

Example

use rust_gpu_tools::{cuda, opencl, program_closures};

let closures = program_closures!(|program, arg: u8| -> bool {
    true
});

// Generates
let closures = (
    |program: &cuda::Program, arg: u8| { true },
    |program: &opencl::Program, arg: u8| { true },
);

// If e.g. the `cuda` feature is disabled, it would generate
let closures_without_cuda = (
    (),
    |program: &opencl::Program, arg: u8| { true },
);