# CPU address error with qr function

**URL:** <https://discourse.julialang.org/t/cpu-address-error-with-qr-function/93234>\
**Category:** General Usage\
**Tags:** cuda\
**Created:** [January 19, 2023, 8:47pm UTC](https://discourse.julialang.org/t/cpu-address-error-with-qr-function/93234 "2023-01-19T20:47:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eveee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eveee/32/45034_2.png) [@Eveee](https://discourse.julialang.org/u/Eveee)\
**Post date:** [January 19, 2023, 8:47pm UTC](https://discourse.julialang.org/t/cpu-address-error-with-qr-function/93234/1 "2023-01-19T20:47:14Z")

</div>

Hi all,

I am puzzled by an error I am getting when using the qr function on CUDA.

The following code works fine:

```julia
a=CUDA.randn(3,3)
q=qr(a).Q
q * a

```

However, the following line does not:

```julia
a * q

```

It results in this error:

```julia
ERROR: ArgumentError: cannot take the CPU address of a CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}
Stacktrace:
 [1] unsafe_convert(#unused#::Type{Ptr{Float32}}, x::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer})
 [2] ormqr!(side::Char, trans::Char, A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, tau::CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, C::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer})
 [3] rmul!(A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, B::LinearAlgebra.QRPackedQ{Float32, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}})
 [4] *(A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, Q::LinearAlgebra.QRPackedQ{Float32, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}})

```

I would expect either both a \* q and q \* a to work or to result in an error. What is the cause of this and how can I execute this calculation on the GPU nevertheless?

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [January 20, 2023, 3:06am UTC](https://discourse.julialang.org/t/cpu-address-error-with-qr-function/93234/2 "2023-01-20T03:06:30Z")

</div>

There seems to be a missing set of methods for right multiplication, so it falls through to ordinary LinearAlgebra wrappers. You can do this until they are added:

```julia
CUDA.CUSOLVER.ormqr!('R', 'N', q.factors, q.τ, a)

```

Please file an issue at CUDA.jl

---

<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:** [January 20, 2023, 3:11pm UTC](https://discourse.julialang.org/t/cpu-address-error-with-qr-function/93234/3 "2023-01-20T15:11:02Z")

</div>

> <https://github.com/JuliaGPU/CUDA.jl/pull/1739>
>
> Fixes https://github.com/JuliaGPU/CUDA.jl/issues/1738
> Depends on https://github….com/JuliaGPU/GPUArrays.jl/pull/447
> 
> cc @evelyne-ringoot
