@@ -52,26 +52,7 @@ function ka_code_llvm(kernel, argtypes; ndrange=nothing, workgroupsize=nothing,
52
52
end
53
53
54
54
55
- """
56
- Get the typed IR for a kernel
57
-
58
- # Examples
59
- ```
60
- @ka_code_typed kernel(args. ndrange=...)
61
- @ka_code_typed kernel(args. ndrange=... workgroupsize=...)
62
- @ka_code_typed optimize=false kernel(args. ndrange=...)
63
- ```
64
- To use interactive mode (with Cthulhu), call
65
- ```
66
- @ka_code_typed interactive=true kernel(args. ndrange=...)
67
- ```
68
- If ndrange is statically defined, then you could call
69
- ```
70
- @ka_code_typed kernel(args.)
71
- ```
72
- Works for CPU or CUDA kernels, with static or dynamic declarations
73
- """
74
- macro ka_code_typed (ex0... )
55
+ function format_ex (ex0)
75
56
ex = ()
76
57
args = gensym (:args )
77
58
old_args = nothing
@@ -83,7 +64,10 @@ macro ka_code_typed(ex0...)
83
64
if isa (ex0[i]. args[end ], Expr)
84
65
# at expr (like ndrange=10)
85
66
kw = ex0[i]. args[end ]
86
- @assert kw. head == :kw
67
+ if kw. head != :kw
68
+ # if an expr in place of a variable, skip
69
+ break
70
+ end
87
71
kw. args[2 ] = esc (kw. args[2 ])
88
72
kw. head = Symbol (" =" )
89
73
resize! (ex0[i]. args, length (ex0[i]. args) - 1 )
@@ -103,6 +87,31 @@ macro ka_code_typed(ex0...)
103
87
end
104
88
@assert (old_args != nothing )
105
89
@assert (kern != nothing )
90
+ return ex, args, old_args, kern
91
+ end
92
+
93
+
94
+ """
95
+ Get the typed IR for a kernel
96
+
97
+ # Examples
98
+ ```
99
+ @ka_code_typed kernel(args. ndrange=...)
100
+ @ka_code_typed kernel(args. ndrange=... workgroupsize=...)
101
+ @ka_code_typed optimize=false kernel(args. ndrange=...)
102
+ ```
103
+ To use interactive mode (with Cthulhu), call
104
+ ```
105
+ @ka_code_typed interactive=true kernel(args. ndrange=...)
106
+ ```
107
+ If ndrange is statically defined, then you could call
108
+ ```
109
+ @ka_code_typed kernel(args.)
110
+ ```
111
+ Works for CPU or CUDA kernels, with static or dynamic declarations
112
+ """
113
+ macro ka_code_typed (ex0... )
114
+ ex, args, old_args, kern = format_ex (ex0)
106
115
107
116
thecall = InteractiveUtils. gen_call_with_extracted_types_and_kwargs (__module__, :ka_code_typed , ex)
108
117
@@ -137,43 +146,18 @@ If ndrange is statically defined, then you could call
137
146
Works for CPU kernels ONLY, with static or dynamic declarations
138
147
"""
139
148
macro ka_code_llvm (ex0... )
140
- ex = ()
141
- args = gensym (:args )
142
- old_args = nothing
143
- kern = nothing
144
- for i = 1 : length (ex0)
145
- if ex0[i]. head == :call
146
- # inside kernel() expr
147
- while length (ex0[i]. args) > 2
148
- if isa (ex0[i]. args[end ], Expr)
149
- # at expr (like ndrange=10)
150
- kw = ex0[i]. args[end ]
151
- @assert kw. head == :kw
152
- kw. args[2 ] = esc (kw. args[2 ])
153
- kw. head = Symbol (" =" )
154
- resize! (ex0[i]. args, length (ex0[i]. args) - 1 )
155
- ex = (kw,). .. , ex...
156
- else
157
- # only symbols left
158
- break
159
- end
160
- end
161
- # save kernel args
162
- old_args = Expr (:tuple , map (esc, ex0[i]. args[2 : end ])... )
163
- resize! (ex0[i]. args, 2 )
164
- ex0[i]. args[2 ] = Expr (:... , args)
165
- kern = esc (ex0[i]. args[1 ])
166
- end
167
- ex = ex... , ex0[i]
168
- end
169
- @assert (old_args != nothing )
170
- @assert (kern != nothing )
149
+ ex, args, old_args, kern = format_ex (ex0)
171
150
172
151
thecall = InteractiveUtils. gen_call_with_extracted_types_and_kwargs (__module__, :ka_code_llvm , ex)
173
152
174
153
quote
175
154
local $ (esc (args)) = $ (old_args)
176
155
156
+ if isa ($ kern, Kernel{CUDADevice})
157
+ # does not support CUDA kernels
158
+ error (" @ka_code_llvm does not support CUDA kernels" )
159
+ end
160
+
177
161
local results = $ thecall
178
162
end
179
163
end
0 commit comments