# Float32 function return and Cuda

**URL:** https://discourse.julialang.org/t/float32-function-return-and-cuda/25489
**Category:** General Usage
**Tags:** question, data, cuda, type
**Created:** [June 20, 2019, 5:00pm UTC](https://discourse.julialang.org/t/float32-function-return-and-cuda/25489 "2019-06-20T17:00:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![wiktorkujawa](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wiktorkujawa](https://discourse.julialang.org/u/wiktorkujawa)
#### Post date: [June 20, 2019, 5:00pm UTC](https://discourse.julialang.org/t/float32-function-return-and-cuda/25489/1 "2019-06-20T17:00:59Z")

</div>

I have GPU(GTX 1050) that performance for Float32 compared to Float64 is about 32 times better, so I should use Float32 values. I have function that return values in format of Float64(or Tuple of Float64). Function looks like that.

```julia
function FunctionName(x,y,z,...) 
   firstValue=...
   secondValue=...
   ...
   return firstValue, secondValue
end

```

and it returns values in format of Float64. All input data of this function are Float32 datatypes.  
How to get Float32 return values?

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [June 20, 2019, 5:25pm UTC](https://discourse.julialang.org/t/float32-function-return-and-cuda/25489/2 "2019-06-20T17:25:49Z")

</div>

Do you have a literal vaue like 0.0 in your code? It sounds like that is causing a promotion. Try using `@code_warntype` or Traceur.jl or the debugger to find where the promotion to Float64 occurs.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [June 20, 2019, 6:54pm UTC](https://discourse.julialang.org/t/float32-function-return-and-cuda/25489/3 "2019-06-20T18:54:19Z")

</div>

you can always convert back to Float32 but as dpsanders said, it’s better to debug and see where the promotion happens – usually when you do operation with some literal Float64 value (either ± or \*/)

---

<div class="post-metadata">

### Author: ![wiktorkujawa](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wiktorkujawa](https://discourse.julialang.org/u/wiktorkujawa)
#### Post date: [June 20, 2019, 7:06pm UTC](https://discourse.julialang.org/t/float32-function-return-and-cuda/25489/4 "2019-06-20T19:06:11Z")

</div>

The problem was, that in this function I created some helpful variable: buffer=[sin(x), cos(x),0.0], which was later multiplied by some input data. I corrected with: buffer=Float32[sin(x), cos(x),0.0] and everything works.
