Conditional load of OpenCL.jl
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
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 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 it seems to work in my case. Thank you for the workaround!
We are now using OpenCL_jll to install the dependency on the platform.