Learn GPU kernel programming
Write CUDA kernels right in your browser, and run them on a real GPU.
Private alpha · invite only
#include <cuda_runtime.h>
__global__ void vector_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];
}
// a, b, c are device pointers
extern "C" void solve(const float* a, const float* b, float* c, int N) {
int threads = 256;
int blocks = (N + threads - 1) / threads;
vector_add<<<blocks, threads>>>(a, b, c, N);
}