CUDA C++
Multi-file projects built with nvcc. The Hello, GPU and Vector addition templates start here.
__global__ void add(const float* a,
const float* b,
float* c, int n) {
int i = blockIdx.x * blockDim.x
+ threadIdx.x;
if (i < n) c[i] = a[i] + b[i];
}
Profiling target RTX 3090
Python with Numba
Launch and profile a CUDA kernel from Python, then verify the result on the host.
@cuda.jit
def add(a, b, c, n):
i = cuda.grid(1)
if i < n:
c[i] = a[i] + b[i]
add[blocks, 256](a, b, c, n)
Profiling target RTX 3090
Rust Beta
The kernel and the host program in Rust with cuda-oxide, NVIDIA's Rust CUDA toolchain. Profiled like any other run.
#[kernel]
pub fn add(a: &[f32], b: &[f32],
mut c: DisjointSlice<f32>,
n: u32) {
let idx = thread::index_1d();
if let Some(out) = c.get_mut(idx) {
*out = a[idx.get()] + b[idx.get()];
}
}
Profiling target NVIDIA L4