@@ -143,6 +143,10 @@ abstract type AbstractKernel{F, TT} end
143143 call_t = Type[x[1 ] for x in zip (sig. parameters, to_pass) if x[2 ]]
144144 call_args = Union{Expr,Symbol}[x[1 ] for x in zip (args, to_pass) if x[2 ]]
145145
146+ # add the kernel state as the first argument
147+ pushfirst! (call_t, KernelState)
148+ pushfirst! (call_args, :(kernel. state))
149+
146150 # replace non-isbits arguments (they should be unused, or compilation would have failed)
147151 for (i,dt) in enumerate (call_t)
148152 if ! isbitstype (dt)
@@ -156,7 +160,20 @@ abstract type AbstractKernel{F, TT} end
156160
157161 quote
158162 indirect_memory = cl. AbstractMemory[]
163+
164+ # add exception info buffer to indirect memory
165+ # XXX : this is too expensive
166+ if kernel. state. exception_info != C_NULL
167+ ctx = cl. context ()
168+ if haskey (exception_infos, ctx)
169+ push! (indirect_memory, exception_infos[ctx])
170+ end
171+ end
172+
159173 clcall (kernel. fun, $ call_tt, $ (call_args... ); indirect_memory, call_kwargs... )
174+
175+ # check for exceptions after kernel execution
176+ check_exceptions ()
160177 end
161178end
162179
167184struct HostKernel{F,TT} <: AbstractKernel{F,TT}
168185 f:: F
169186 fun:: cl.Kernel
187+ state:: KernelState
170188end
171189
172190
@@ -191,7 +209,9 @@ function clfunction(f::F, tt::TT=Tuple{}; kwargs...) where {F,TT}
191209 kernel = get (_kernel_instances, h, nothing )
192210 if kernel === nothing
193211 # create the kernel state object
194- kernel = HostKernel {F,tt} (f, fun)
212+ exception_info = create_exceptions! (ctx, dev)
213+ state = KernelState (exception_info)
214+ kernel = HostKernel {F,tt} (f, fun, state)
195215 _kernel_instances[h] = kernel
196216 end
197217 return kernel:: HostKernel{F,tt}
0 commit comments