Skip to content

Commit 9dcc97e

Browse files
Update the quickstart documentation. (#410)
1 parent bc803d1 commit 9dcc97e

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ backend and depend on
2525

2626
### CUDA
2727
```julia
28-
using CUDA
28+
import CUDA
2929
using KernelAbstractions
3030
```
3131
[`CUDA.jl`](https://github.com/JuliaGPU/CUDA.jl) is currently the most mature way to program for GPUs.

docs/src/quickstart.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,32 @@ The [`synchronize`](@ref) blocks the *host* until the kernel has completed on th
4646
## Launching kernel on the backend
4747

4848
To launch the kernel on a backend-supported backend `isa(backend, KA.GPU)` (e.g., `CUDABackend()`, `ROCBackend()`, `oneBackend()`), we generate the kernel
49-
for this backend provided by `CUDAKernels`, `ROCKernels`, or `oneAPIKernels`.
49+
for this backend.
5050

5151
First, we initialize the array using the Array constructor of the chosen backend with
5252

5353
```julia
54-
using CUDAKernels # Required to access CUDABackend
54+
using CUDA: CuArray
5555
A = CuArray(ones(1024, 1024))
5656
```
5757

5858
```julia
59-
using ROCKernels # Required to access ROCBackend
59+
using ROCArrays: ROCArray
6060
A = ROCArray(ones(1024, 1024))
6161
```
6262

6363
```julia
64-
using oneAPIKernels # Required to access oneBackend
64+
using oneAPI: oneArray
6565
A = oneArray(ones(1024, 1024))
6666
```
6767
The kernel generation and execution are then
6868
```julia
69+
backend = get_backend(A)
6970
mul2_kernel(backend, 64)(A, ndrange=size(A))
7071
synchronize(backend)
7172
all(A .== 2.0)
7273
```
7374

74-
For simplicity, we stick with the case of `backend=CUDABackend()`.
75-
7675
## Synchronization
7776
!!! danger
7877
All kernel launches are asynchronous, use [`synchronize(backend)`](@ref)
@@ -82,23 +81,24 @@ The code around KA may heavily rely on
8281
[`GPUArrays`](https://github.com/JuliaGPU/GPUArrays.jl), for example, to
8382
intialize variables.
8483
```julia
85-
using CUDAKernels # Required to access CUDABackend
86-
function mymul(A::CuArray)
84+
function mymul(A)
8785
A .= 1.0
88-
ev = mul2_kernel(CUDABackend(), 64)(A, ndrange=size(A))
86+
backend = get_backend(A)
87+
ev = mul2_kernel(backend, 64)(A, ndrange=size(A))
8988
synchronize(backend)
9089
all(A .== 2.0)
9190
end
9291
```
9392

9493
```julia
95-
using CUDAKernels # Required to access CUDABackend
96-
function mymul(A::CuArray, B::CuArray)
94+
function mymul(A, B)
9795
A .= 1.0
9896
B .= 3.0
99-
mul2_kernel(CUDABackend(), 64)(A, ndrange=size(A))
100-
mul2_kernel(CUDABackend(), 64)(A, ndrange=size(A))
101-
synchronize(CUDABackend())
97+
backend = get_backend(A)
98+
@assert get_backend(B) == backend
99+
mul2_kernel(backend, 64)(A, ndrange=size(A))
100+
mul2_kernel(backend, 64)(B, ndrange=size(B))
101+
synchronize(backend)
102102
all(A .+ B .== 8.0)
103103
end
104104
```

0 commit comments

Comments
 (0)