Skip to content

Commit f387f23

Browse files
committed
add docs for @kernel and @const
1 parent ac2f258 commit f387f23

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/KernelAbstractions.jl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,48 @@ using Requires
1010

1111
"""
1212
@kernel function f(args) end
13+
14+
Takes a function definition and generates a Kernel constructor from it.
15+
The enclosed function is allowed to contain kernel language constructs.
16+
In order to call it the kernel has first to be specialized on the backend
17+
and then invoked on the arguments.
18+
19+
# Kernel language
20+
21+
- [`@Const`](@ref)
22+
- [`@index`](@ref)
23+
- [`@localmem`](@ref)
24+
- [`@private`](@ref)
25+
- [`@synchronize`](@ref)
26+
27+
# Example:
28+
29+
@kernel function vecadd(A, @Const(B))
30+
I = @index(Global)
31+
@inbounds A[I] += B[I]
32+
end
33+
34+
A = ones(1024)
35+
B = rand(1024)
36+
event = vecadd(CPU(), 64)(A, B, ndrange=size(A))
37+
wait(event)
1338
"""
14-
macro kernel end
39+
macro kernel(expr)
40+
__kernel(expr)
41+
end
1542

1643
"""
1744
@Const(A)
45+
46+
`@Const` is an argument annotiation that asserts that the memory reference
47+
by `A` is both not written to as part of the kernel and that it does not alias
48+
any other memory in the kernel.
49+
50+
!!! danger
51+
Violating those constraints will lead to arbitrary behaviour.
52+
53+
as an example given a kernel signature `kernel(A, @Const(B))`, you are not
54+
allowed to call the kernel with `kernel(A, A)` or `kernel(A, view(A, :))`.
1855
"""
1956
macro Const end
2057

src/macros.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import Base.Meta: isexpr
22

3-
macro kernel(expr)
4-
__kernel(expr)
5-
end
6-
73
# XXX: Proper errors
84
function __kernel(expr)
95
@assert isexpr(expr, :function)

0 commit comments

Comments
 (0)