We should only add GPU data is there's a current CUDA context, i.e.
if !isnothing(CUDA.CuCurrentContext())
gpu_name = CUDA.CuCurrentContext() |> CUDA.device |> CUDA.name
s = s * " GPU: $gpu_name\n"
end
A related issue but really outside our scope is that someone that has CUDA but doesn't have things configured correctly can have difficulty running Oceananigans --- even if they only ever planned on running CPU models. This issue was avoided when has_cuda() was based on whether using CuArrays failed or not.
Yeah... Might be worth opening an issue on CUDA.jl or @maleadt might have some tips.
I guess has_cuda() as it functions now is more accurate than what we did. We want something more like has_working_cuda()... ?
I don't understand the issue; when does has_cuda return true while CUDA doesn't work? Also, you generally shouldn't use the low-level CuCurrentContext, because that'll return nothing if you just haven't done anything CUDA-related yet. Calling context() should always return a context (i.e., it'll create one if the system hasn't been initialized yet). There's also has_cuda_gpu that checks if CUDA works and there's at least one GPU; added by @simonbyrne IIRC.
Ah thanks @maleadt, sounds like we should be using context() instead.
@maleadt perhaps I am misremembering. @raphaelouillon may be able to provide more information --- I seem to remember that he was unable to use Oceananigans.jl due to some CUDA issue, despite having no interest in running code on his laptop's GPU.
Most helpful comment
I don't understand the issue; when does
has_cudareturntruewhile CUDA doesn't work? Also, you generally shouldn't use the low-levelCuCurrentContext, because that'll returnnothingif you just haven't done anything CUDA-related yet. Callingcontext()should always return a context (i.e., it'll create one if the system hasn't been initialized yet). There's alsohas_cuda_gputhat checks if CUDA works and there's at least one GPU; added by @simonbyrne IIRC.