From DoubleTensor to cuda.FloatTensor

I’m using float64 values on the cpu but I want to use float32 values on the gpu. What’s the fastest way to convert a DoubleTensor to a cuda.FloatTensor?

torch.DoubleTensor(10).float().cuda() would be the way to go.
It would be faster, if you could load your data as floats, if that’s possible.

I’m doing RL so the data is generated as float64 for stability reasons. I don’t think this conversion will be a bottleneck but was wondering if there was a single instruction for this. It appears there isn’t.

Ah ok, I understand.
Well you could use

a = torch.DoubleTensor(10)
a = a.type(torch.cuda.FloatTensor)

, if you would like to have a single command.

I tried to time it with torch.cuda.synchronize() and got mixed results.
Currently my GPU is busy, so the timing is most likely useless in this state. :wink:


Nice, I’ll try that!