rocm_kernel_macros
Crate for generating subprojects with kernel source written in rust
Requirements
- rust nightly
- rust target: amdgcn-amd-amdhsa
- rust-src
- ROCM 6.0 or newer
Examples
- Writing gpu kernels in rust
// initialize new kernel subproject
amdgpu_kernel_init!;
// mark function that will be copied to kernel src
// compile and get path to kernel binary
const AMDGPU_KERNEL_BINARY_PATH: &str = amdgpu_kernel_finalize!;
- Running kernel on gpu side using
rocm-rs(assuming above kernel)
// aquire device
let device = new?;
device.set_current?;
// load kernel binary
let kernel_path = from;
assert!;
let module = load?;
// search for function in module
let function = unsafe ;
// prepare input and output memory
let mut in_host: = vec!;
let mut out_host: = vec!;
// prepare data
for i in 0..LEN
let mut input = new?;
let output = new?;
input.copy_from_host?;
// prepare kernel arguments
let kernel_args = ;
// setup launch arguments
let grid_dim = Dim3 ;
let block_dim = Dim3 ;
// launch kernel (grid_dim, block_dim, shared_mem_bytes, stream, args)
function.launch?;
- Running kernel on host side (assuming above kernel, highly not recomended)