macro_rules! gen_cuda_functions {
    (@as_bench_ident Seq) => { ... };
    (@as_bench_ident Lcg) => { ... };
    (@as_bench_str Seq) => { ... };
    (@as_bench_str Lcg) => { ... };
    (@as_op_str Read) => { ... };
    (@as_op_str Write) => { ... };
    (@as_op_str CompareAndSwap) => { ... };
    (@as_bytes_str Bytes4) => { ... };
    (@as_bytes_str Bytes8) => { ... };
    (@as_bytes_str Bytes16) => { ... };
    (@as_threads_str Threads1) => { ... };
    (@as_threads_str Threads2) => { ... };
    (@as_threads_str Threads4) => { ... };
    (@as_threads_str Threads8) => { ... };
    (@as_threads_str Threads16) => { ... };
    (@as_threads_str Threads32) => { ... };
    (@gen_pattern ($benchmark:ident, $operation:ident, $bytes:ident, $threads:ident)) => { ... };
    (@gen_function_str ($benchmark:ident, $operation:ident, $bytes:ident, $threads:ident)) => { ... };
    ($obj:expr, $(case($benchmark:ident, $operation:ident, $bytes:ident, $threads:ident)),*) => { ... };
}
Expand description

Generate CUDA function bindings that are callable from Rust

The CUDA memory benchmark functions are named using the scheme:

  • gpu_{operator}_bandwidth_{benchmark}_{bytes}B
  • gpu_{operator}_bandwidth_{benchmark}_{bytes}B_{tile size}T

CUDA provides cuModuleGetFunction, that returns a handle to a function within a module by searching for the function name. Thus, gen_cuda_fucntions constructs the function name as a string.

Usage

The macro takes a tuple (Benchmark, MemoryOperation, ItemBytes, TileSize) and a list of cases and returns a &'static str string. Each case is encoded as case(bench, op, bytes, tile_size).

Benchmarks:

  • Seq
  • Lcg

MemoryOperations:

  • Read
  • Write
  • CompareAndSwap

Bytes:

  • Bytes4
  • Bytes8
  • Bytes16

TileSize:

  • Threads1
  • Threads2
  • Threads4
  • Threads8
  • Threads16
  • Threads32

Example

let cuda_function = gen_cuda_functions!(
  (bench, op, item_bytes, tile_size),
  case(Seq, Read, Bytes4, Threads1),
  case(Lcg, Write, Bytes16, Threads16)
);