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

Conditional load of OpenCL.jl

Open klkeys opened this issue 9 years ago • 3 comments

Is it possible to conditionally load OpenCL depending on whether or not Julia can find an OpenCL library? For Unix systems, I thought that I could imitate what appears in api.jl:

module MyMulticoreModule

using LotsOfCPUPackages

### only load OpenCL.jl if the library is found
const libopencl = Libdl.find_library(["libOpenCL", "OpenCL"])
if libopencl == ""
    warn("cannot find OpenCL library!")
else
     using OpenCL
end

include("my_cpu_code.jl")

### same deal
if libopencl != ""
    include("my_gpu_code.jl")
end

end

klkeys avatar Oct 11 '16 19:10 klkeys

Perhaps not? This idea is covered in issues #6195 and #15705 in Julia Base. It appears that some problems include recompilation of the module and a revamp of type stability inference.

klkeys avatar Oct 11 '16 20:10 klkeys

@klkeys I am doing a simple trick to optionally load OpenCL in my package: https://github.com/juliohm/ImageQuilting.jl/blob/master/src/ImageQuilting.jl#L28-L32

In that case, before every use of the GPU, I check if cl is nothing or not. It has worked for me, but it may not be worth for you, I don't know.

juliohm avatar Oct 14 '16 23:10 juliohm

@juliohm it seems to work in my case. Thank you for the workaround!

klkeys avatar Oct 17 '16 17:10 klkeys

We are now using OpenCL_jll to install the dependency on the platform.

juliohm avatar Oct 05 '22 22:10 juliohm