# Bring your CUDA code

Ben Koska, Nov 18, 2026

You don't have to rewrite a codebase to start with Emma. Bring the CUDA kernels you already have, call them from your Emma program like native Emma kernels, and port them one at a time when it suits you.

## Start with the kernel you have

Here is a plain CUDA kernel that adds two vectors. It keeps running as it is while the rest of your program moves to Emma.

```cuda
__global__ void vectorAdd(const float *a, const float *b,
                          float *c, int n) {
    int i = blockDim.x * blockIdx.x + threadIdx.x;
    if (i < n) {
        c[i] = a[i] + b[i];
    }
}
```

Bind it into your Emma program and call it the same way you call any Emma kernel. Nothing about the CUDA side has to change.

## Port it when you are ready

When a kernel is worth porting, the Emma version reads like the math it does.

```emma
kernel func vectorAdd(a: Float[], b: Float[], c: Float[]) {
    c[id.x] = a[id.x] + b[id.x]
}
```

Targets: CUDA, ROCm, Vulkan

Once it is ported, the same source compiles to every backend Emma supports, so the kernel is no longer tied to one vendor.

## Move at your own pace

Port the hot paths first, leave the rest, and keep shipping. You decide when a kernel moves, one at a time.
