# Limitation in CuArrays

**URL:** <https://discourse.julialang.org/t/limitation-in-cuarrays/7011>\
**Category:** GPU\
**Created:** [November 11, 2017, 7:36pm UTC](https://discourse.julialang.org/t/limitation-in-cuarrays/7011 "2017-11-11T19:36:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [November 11, 2017, 7:36pm UTC](https://discourse.julialang.org/t/limitation-in-cuarrays/7011/1 "2017-11-11T19:36:13Z")

</div>

What is the reason for this limitation in [CuArrays](https://github.com/JuliaGPU/CuArrays.jl/blob/master/README.md#current-limitations)?

```julia
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.

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

```

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [November 11, 2017, 8:06pm UTC](https://discourse.julialang.org/t/limitation-in-cuarrays/7011/2 "2017-11-11T20:06:34Z")

</div>

Reason: [https://github.com/JuliaGPU/CUDAnative.jl/issues/27](https://github.com/JuliaGPU/CUDAnative.jl/issues/27) – if you call `sin`, that is resolved to `Base.sin` which `ccall`s 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.
