# pow(Complex, Int) supported on CUDA?

**URL:** https://discourse.julialang.org/t/pow-complex-int-supported-on-cuda/36280
**Category:** GPU
**Created:** [March 20, 2020, 9:25pm UTC](https://discourse.julialang.org/t/pow-complex-int-supported-on-cuda/36280 "2020-03-20T21:25:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![a5vzener](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a5vzener/32/16257_2.png) [@a5vzener](https://discourse.julialang.org/u/a5vzener)
#### Post date: [March 20, 2020, 9:25pm UTC](https://discourse.julialang.org/t/pow-complex-int-supported-on-cuda/36280/1 "2020-03-20T21:25:59Z")

</div>

I’m trying to run some Julia code on my new nVidia Jetson Nano and I ran into this error:

```julia
> **[ Info:** Building the CUDAnative run-time library for your sm_53 device, this might take a while...
> **ERROR:** LoadError: MethodError: no method matching pow(::Complex{Float32}, ::Int64)
> Closest candidates are:
> pow(::Union{Float32, Float64}, ::Int64) at /home/doug/.julia/packages/CUDAnative/hfulr/src/device/cuda/math.jl:209

Indeed, when I checked math.jl, not all functions also support complex numbers.

The function I am broadcasting against a CuArray of Complex{Float32} values is:

```

function f(z, A, N, M)  
z̅ = conj(z)  
sum(A .\* (z .^ N .\* z̅ .^ M + z .^ M .\* z̅ .^ N))  
end

```julia
where N and M contain integers (Int64).

Am I missing something or is this capability actually missing and (hopefully) on a development roadmap?

Thanks all!
-doug
```

---

<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: [March 21, 2020, 9:18pm UTC](https://discourse.julialang.org/t/pow-complex-int-supported-on-cuda/36280/2 "2020-03-21T21:18:06Z")

</div>

Many Base math functions are GPU incompatible because they use the CPU math library, that’s why we prefer to use NVIDIA’s math library. Functions from that library however do not support that many types, as you can see here. For now, you can just add (or create a PR with) the necessary methods that reuse available functionality, as in [Add some more complex operations - Take 2 by PhilipVinc · Pull Request #466 · JuliaGPU/CUDAnative.jl · GitHub](https://github.com/JuliaGPU/CUDAnative.jl/pull/466), often copying similar functionality from the Julia standard library. In the future, we hope to reuse those Base implementations by means of contextual dispatch.

---

<div class="post-metadata">

### Author: ![a5vzener](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a5vzener/32/16257_2.png) [@a5vzener](https://discourse.julialang.org/u/a5vzener)
#### Post date: [March 26, 2020, 12:57am UTC](https://discourse.julialang.org/t/pow-complex-int-supported-on-cuda/36280/3 "2020-03-26T00:57:14Z")

</div>

Thank you for the info. This is very new to me, this multiple-layer CUDA cake. In looking at my problem of pow(z, n), the Base method that performs this is a brute force algorithm of powers\_by\_squaring, essentially looping z \*= z enough times to produce the result. I copied over the code from Base and slightly tweaked. It’s probably not in-linable, but it works! I’m sorta amazed, actually. I’ll submit a PL so you can have a look.

But now I have another problem, with GPU compilation failing because of non-isbit types. I’ll post a new question about that.

Thanks again!
