Float32 function return and Cuda

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.

function FunctionName(x,y,z,...) 
   return firstValue, secondValue

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

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.


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 */)

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.

1 Like