---
title: "Smoke: Enzyme"
engine: julia
julia:
  exeflags: ["+1.12", "--project=../julia"]
---

```{julia}
#| label: grad
using CUDA, KernelAbstractions, Enzyme
@kernel function square!(y, @Const(x))
    i = @index(Global)
    @inbounds y[i] = x[i]^2
end
f!(y, x) = (square!(get_backend(x))(y, x; ndrange=length(x)); nothing)
x = CuArray(Float32[1, 2, 3, 4]); dx = CUDA.zeros(Float32, 4)
y = CUDA.zeros(Float32, 4);       dy = CUDA.ones(Float32, 4)
Enzyme.autodiff(Reverse, f!, Const, Duplicated(y, dy), Duplicated(x, dx))
Array(dx)
```
