Limitation in CuArrays


What is the reason for this limitation in CuArrays?

When broadcasting, watch out for errors like:

julia> sin.(cos.(xs))
ERROR: CUDA error: invalid program counter (code #718, ERROR_INVALID_PC)

A current limitation of CUDAnative means that you'll need to restart Julia and use CUDAnative.sin, CUDAnative.cos etc in this case.

And how one should deal with them? I have this question because was trying to calculate entropy and get this error. So now I am using dispatch, but it looks not very convenient, may be better solution exists.

entropy(p::AbstractArray) = sum(-p .* log.(p))
entropy(p::CuArray) = sum(-p .* CUDAnative.log.(p))


Reason: – if you call sin, that is resolved to Base.sin which ccalls into openlibm. There’s currently no easy way to override Base.sin to CUDAnative.sin automatically for GPU code.
As you’ve discovered, the current solution is to manually call the correct intrinsics (ie. CUDAnative.log). This will be fixed in the future, probably using Cassette.jl.