Weak dependence on CUDA packages, 2019 version

What’s state of the art for writing code with weak dependence on CUDA, e.g. when you want to provide automatic speedup if GPU is available, but provide fallback for systems with only CPUs? I remember a lot of discussion about it, but things seems to have been improved since the last time I checked it. In particular:

  1. Is it safe to add CuArrays and CUDAnative as dependencies to a general-purpose project if they are not loaded by default (e.g. when all calls to them are wrapped into Requires.@required)?
  2. How to safely detect if CUDA is available in the system? Something like @cuda_available macro.
1 Like

FYI Pkg.jl may implement more direct solution soon:


Awaiting that, you can use CUDAapi to know if you can load CUDAnative/CuArrays: CuArrays/CUDAnative PSA: Simplified package loading


Thanks! This is pretty much like what I was looking for.