# CUDA.jl and svd getting automatic casting to Array{Float32,2}

**URL:** <https://discourse.julialang.org/t/cuda-jl-and-svd-getting-automatic-casting-to-array-float32-2/56190>\
**Category:** General Usage\
**Tags:** cuda\
**Created:** [February 28, 2021, 1:28pm UTC](https://discourse.julialang.org/t/cuda-jl-and-svd-getting-automatic-casting-to-array-float32-2/56190 "2021-02-28T13:28:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadir-gunel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kadir-gunel/32/35790_2.png) [@kadir-gunel](https://discourse.julialang.org/u/kadir-gunel)\
**Post date:** [February 28, 2021, 1:28pm UTC](https://discourse.julialang.org/t/cuda-jl-and-svd-getting-automatic-casting-to-array-float32-2/56190/1 "2021-02-28T13:28:21Z")

</div>

Hello, I am using CUDA.jl package for svd calculation. But I get automatic casting to Array{Float32,2}.  
Could anyone help please ? Below, I share m.w.e.

```julia
using CUDA

A = CUDA.rand(10, 20) ; # getting float32 on GPU
# then applying SVD on it
F = CUDA.svd(A) # Object F has U, S, V and Vt 
# everything is still on GPU
1 ./ F.S # returns CuArray
# then applying some operations
diagm(1 ./ F.S) # returns Array{Float32,2} not CuArray{Float32,2}

# trying another approach
CUDA.diagm(1 ./ F.S) # again returns Array{Float32,2} not CuArray{Float32,2}

```

---

<div class="post-metadata">

**Author:** ![Jesus\_Chavez\_Solano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jesus_chavez_solano/32/25194_2.png) [@Jesus\_Chavez\_Solano](https://discourse.julialang.org/u/Jesus_Chavez_Solano)\
**Post date:** [May 18, 2021, 3:35am UTC](https://discourse.julialang.org/t/cuda-jl-and-svd-getting-automatic-casting-to-array-float32-2/56190/2 "2021-05-18T03:35:36Z")

</div>

Hi Kadir, if you’re using PLUTO, you need to define CUDA: GPUArrays, such as:

```julia
begin
	using CUDA
	using CUDA: GPUArrays
	CUDA.allowscalar(false) # without this fallback functionality performing iteration
end

```

```julia
begin
	B = CUDA.rand(10, 20) ; # getting float32 on GPU
	# then applying SVD on it
	F = CUDA.svd(Array(B)) # Object F has U, S, V and Vt 
	# everything is still on GPU
	1 ./ F.S # returns CuArray
	# then applying some operations
	diagm(1 ./ F.S) # returns Array{Float32,2} not CuArray{Float32,2}
	
	# trying another approach
	CUDA.diagm(1 ./ F.S) # again returns Array{Float32,2} not CuArray{Float32,2}
end

```
