emu

Emu is a language for programming GPUs from Rust. Emu provides the emu! macro for writing code. Emu will then translate your code to OpenCL source code at compile time and store it in the EMU global constant. You can then run your code using a binding to OpenCL such as ocl or rust-opencl

extern crate em;
use em::emu;

emu! {
	// more particles
	more_particles(num_particles u32, num_moles u32) u32 {
		return num_particles + num_moles * L;
	}

	// moves particles
	move_particles(global_particles_x [f32], global_particles_y f32, global_particles_z f32) {
		global_particles_z[get_global_id(0)] += 7.3e1 as nm;
		global_particles_x[get_global_id(0)] += 2 as cm;
		global_particles_y[get_global_id(0)] += 6 as cm;
	}
	
	// moves particles in circle
	rotate_particles(global_particles_r [f32]) {
		global_particles_r[get_global_id(0)] += 7.5 * TAU;
	}

	// multiplies 2 matrices
	// n is the dimension of the matrices
	// a and b are the matrices to be multiplied, c is the result
	multiply_matrices(n i32, global_a [f32], global_b [f32], global_c [f32]) {
		// indices of cells to multiply
		let i: i32 = get_global_id(0);
		let j: i32 = get_global_id(1);

		// execute step of multiplication
		for k in 0..n {
			global_c[i * n + j] += global_a[i * n + k] * global_b[k * n + j];
		}
	}
}

To start writing Emu kernels embedded in your Rust code, simply add the following to your Cargo.toml file and import the macro as shown above.

[dependencies]
em = "0.1.2"