File tree Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Expand file tree Collapse file tree 3 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -4,4 +4,5 @@ CUDAdrv = "c5f51814-7f29-56b8-a69c-e4d8f6be1fde"
4
4
CUDAnative = " be33ccc6-a3ff-5ff2-a52e-74243cff1e17"
5
5
CuArrays = " 3a865a2d-5b23-5a0f-bc46-62713ec82fae"
6
6
KernelAbstractions = " 63c18a36-062a-441e-b654-da1e3ab1ce7c"
7
+ StaticArrays = " 90137ffa-7385-5640-81b9-e52037218182"
7
8
Test = " 8dfed614-e22c-5e08-85e1-65c5234f0b40"
Original file line number Diff line number Diff line change 1
1
module LoopInfo
2
2
3
- const HAS_LOOPINFO_EXPR = VERSION >= v " 1.2.0-DEV.462 "
3
+ using MacroTools
4
4
export @unroll
5
5
6
6
# #
@@ -20,13 +20,16 @@ module MD
20
20
end
21
21
22
22
function loopinfo (expr, nodes... )
23
- if expr. head != :for
23
+ if @capture (expr, for i_ in iter_ body__ end )
24
+ return quote
25
+ for $ i in $ iter
26
+ $ (body... )
27
+ $ (Expr (:loopinfo , nodes... ))
28
+ end
29
+ end
30
+ else
24
31
error (" Syntax error: loopinfo needs a for loop" )
25
32
end
26
- if HAS_LOOPINFO_EXPR
27
- push! (expr. args[2 ]. args, Expr (:loopinfo , nodes... ))
28
- end
29
- return expr
30
33
end
31
34
32
35
"""
@@ -48,6 +51,7 @@ if it is safe to do so.
48
51
"""
49
52
macro unroll (N, expr)
50
53
if ! (N isa Integer)
54
+ @debug " @unroll macro inputs" N expr
51
55
error (" Syntax error: `@unroll N expr` needs a constant integer N" )
52
56
end
53
57
expr = loopinfo (expr, MD. unroll_count (N))
Original file line number Diff line number Diff line change 1
1
using KernelAbstractions
2
2
using KernelAbstractions. Extras
3
+ using StaticArrays
3
4
4
5
@kernel function kernel_unroll! (a)
5
6
@unroll for i in 1 : 5
13
14
end
14
15
end
15
16
17
+ # Check that nested `@unroll` doesn't throw a syntax error
18
+ @kernel function kernel_unroll! (a, :: Val{N} ) where N
19
+ @uniform begin
20
+ a = MVector {3, Float64} (1 , 2 , 3 )
21
+ b = MVector {3, Float64} (3 , 2 , 1 )
22
+ c = MMatrix {3, 3, Float64} (undef)
23
+ end
24
+ I = @index (Global)
25
+ @inbounds for m in 1 : 3
26
+ @unroll for j = 1 : 3
27
+ @unroll for i = 1 : 3
28
+ c[1 , j] = m * a[1 ] * b[j]
29
+ end
30
+ end
31
+ a[I] = c[1 , 1 ]
32
+ m % 2 == 0 && @synchronize
33
+ end
34
+ end
35
+
16
36
let
17
37
a = zeros (5 )
18
38
kernel! = kernel_unroll! (CPU (), 1 , 1 )
You can’t perform that action at this time.
0 commit comments