# Cannot take the CPU address of a CUDA.CuArray{Float32, 1, CUDA.Mem.DeviceBuffer} in LinearAlgebra matmul

**URL:** <https://discourse.julialang.org/t/cannot-take-the-cpu-address-of-a-cuda-cuarray-float32-1-cuda-mem-devicebuffer-in-linearalgebra-matmul/80666>\
**Category:** GPU\
**Tags:** question, error\
**Created:** [May 7, 2022, 12:53pm UTC](https://discourse.julialang.org/t/cannot-take-the-cpu-address-of-a-cuda-cuarray-float32-1-cuda-mem-devicebuffer-in-linearalgebra-matmul/80666 "2022-05-07T12:53:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![LarsWl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larswl/32/36048_2.png) [@LarsWl](https://discourse.julialang.org/u/LarsWl)\
**Post date:** [May 7, 2022, 12:53pm UTC](https://discourse.julialang.org/t/cannot-take-the-cpu-address-of-a-cuda-cuarray-float32-1-cuda-mem-devicebuffer-in-linearalgebra-matmul/80666/1 "2022-05-07T12:53:17Z")

</div>

Have such function, that usually calculated correct.

```julia
function predict_train(model::Model, batch)
  (calculate_hidden(model, batch, dropout_active=true) .^ 3) |> 
    model.upper_layer |>
    (upper) -> model.output_layer(upper') |>
    calculate_softmax
end

```

Also have this loss function

```julia
loss = (sample) -> begin
  sum(sample) do (batch, gold)
    predict_train(model, batch) |> scores -> transition_loss(scores, gold)
  end + L2_norm(ps, training_context.settings)
end

```

In usual this works fine, i can call them separtly fine, but when I try call Zygote.gradient I get a CPU address error, that failed in ouput\_layer calculation. I checked types before error, and both output weight and upper result is CuArray, but error still happens every time in LinearAlgebra.BLAS
