# Bug in CUDA, CuArray, or something I just don't know?

**URL:** https://discourse.julialang.org/t/bug-in-cuda-cuarray-or-something-i-just-dont-know/92059
**Category:** GPU
**Created:** [December 23, 2022, 7:27pm UTC](https://discourse.julialang.org/t/bug-in-cuda-cuarray-or-something-i-just-dont-know/92059 "2022-12-23T19:27:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [December 23, 2022, 7:27pm UTC](https://discourse.julialang.org/t/bug-in-cuda-cuarray-or-something-i-just-dont-know/92059/1 "2022-12-23T19:27:55Z")

</div>

Hello!

When I run this code to convert a vector of ints into a CuArray, I see something extremely weird…

```julia
julia> ListOfInts = collect(1:1*10^6)
1000000-element Vector{Int64}:
       1
       2
       3
       4
       5
       ⋮
  999997
  999998
  999999
 1000000

julia> CuArray(ListOfInts)
1000000-element CuArray{Int64, 1, CUDA.Mem.DeviceBuffer}:
       1
       2
       3
       4
       5
       ⋮
  999997
  999998
  999999
 1000000

julia> CuArray(ListOfInts)
1000000-element CuArray{Int64, 1, CUDA.Mem.DeviceBuffer}:
                    1
                    2
                    3
                    4
                    5
                    ⋮
  4533517044312782213
  4529285733552316672
 -9223372036854775808
 -4708928475910122632

```

It works the first time, but completely errors out the second time. Makes me a bit nervous for using it, could anyone tell me where I am going wrong?

I am new to GPU programming.

Kind regards

---

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [December 23, 2022, 7:31pm UTC](https://discourse.julialang.org/t/bug-in-cuda-cuarray-or-something-i-just-dont-know/92059/2 "2022-12-23T19:31:39Z")

</div>

I think it perhaps might be a printing error since I do get the correct sum:

```julia
julia> j = CuArray(ListOfInts)
1000000-element CuArray{Int64, 1, CUDA.Mem.DeviceBuffer}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
  ⋮
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0

julia> sum(j)
500000500000

```

---

<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: [December 25, 2022, 9:55am UTC](https://discourse.julialang.org/t/bug-in-cuda-cuarray-or-something-i-just-dont-know/92059/3 "2022-12-25T09:55:41Z")

</div>

I take it you’re running this in the VSCode terminal: [CuArrays don't seem to display correctly in VS code · Issue #875 · JuliaGPU/CUDA.jl · GitHub](https://github.com/JuliaGPU/CUDA.jl/issues/875)

---

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [December 25, 2022, 12:03pm UTC](https://discourse.julialang.org/t/bug-in-cuda-cuarray-or-something-i-just-dont-know/92059/4 "2022-12-25T12:03:33Z")

</div>

Indeed!

Thank you for making me aware of that issue 🙂

I will mark your answer as solution, hope it gets fixed one day, VS Code is a bit too good to let go off, even for GPU programming… 😉

Kind regards
