OpenCL.jl
OpenCL.jl copied to clipboard
OpenCL.wait and type stability
Is it possible to enforce type stability when wrapping kernel calls with OpenCL.wait? The inferred return type of OpenCL.wait is Union{Array{OpenCL.CLEvent,1},OpenCL.CLEvent}.
I can try to illustrate using a part of my code. The PLINK.PlinkGPUVariables type is a container object with the GPU buffer y_buff as one field. copy_y! simply copies a CPU SharedVector y to y_buff. Float is a typealias for Union{Float32, Float64}.
Function
function copy_y!{T <: Float}(v::PlinkGPUVariables{T}, y::SharedVector{T})
cl.wait(cl.copy!(v.queue, v.y_buff, sdata(y)))
end
Check type stability
@time 1+1 # compile @time
@code_warntype copy_y!(v, y)
copy_y!(v, y) # compile copy_y!
@time copy_y!(v, y)
Output
Variables:
v::PLINK.PlinkGPUVariables{Float64,OpenCL.Buffer{Float64}}
y::SharedArray{Float64,1}
Body:
begin # /Users/kkeys/.julia/v0.4/PLINK/src/gpu.jl, line 231:
return (OpenCL.wait)((OpenCL.copy!)((top(getfield))(v::PLINK.PlinkGPUVariables{Float64,OpenCL.Buffer{Float64}},:queue)::OpenCL.CmdQueue,(top(getfield))(v::PLINK.PlinkGPUVariables{Float64,OpenCL.Buffer{Float64}},:y_buff)::OpenCL.Buffer{Float64},(top(getfield))(y::SharedArray{Float64,1},:s)::Array{Float64,1})::ANY)::UNION{ARRAY{OPENCL.CLEVENT,1},OPENCL.CLEVENT}
end::UNION{ARRAY{OPENCL.CLEVENT,1},OPENCL.CLEVENT}
0.000478 seconds (9 allocations: 288 bytes)