OpenCL.jl icon indicating copy to clipboard operation
OpenCL.jl copied to clipboard

map_mem / unmap! fails sporadically: array not mapped to buffer

Open skleinbo opened this issue 7 years ago • 0 comments

This minimal example demonstrates the issue:

using OpenCL

mutable struct MyBufferedType
    A::Array{Float32,1}
    A_buf::OpenCL.cl.Buffer
end
function MyBufferedType(cl_ctx::OpenCL.cl.Context)
    A = zeros(Float32,8)
    A_buf = OpenCL.cl.Buffer(Float32, cl_ctx, (:rw,:use), hostbuf=A)
    MyBufferedType(A,A_buf)
end

function main()
    cl_device = cl.devices(:gpu)[2]
    cl_ctx = cl.Context(cl_device)
    cl_queue = cl.CmdQueue(cl_ctx)
    D = MyBufferedType(cl_ctx)
    for j in 1:10^6
        try
            D.A, evt = cl.enqueue_map_mem(cl_queue, D.A_buf, :rw, 0, size(D.A), nothing, true)
            cl.wait(evt)
            cl.unmap!(cl_queue, D.A_buf,D.A)
        catch err
            println(j)
            warn(err)
            break
        end
    end
    return (cl_device,cl_ctx,cl_queue),D
end

dcq,D = main();

fails with e.g

103271
ERROR: ArgumentError: array @Ptr{Float32} @0x0000000019f5e190 is not mapped to buffer Buffer{Float32
}(@0x0000000021e61200)

The struct holds an array and a buffer. They are mapped onto each other repeatedly. The program fails reliably but randomly across different platforms and OSs (AMD GPU + Intel iGPU on Windows, NVIDIA on MacOS).

skleinbo avatar Jun 26 '18 06:06 skleinbo