Reputation: 688
I am doing computations in Cuda using float
s. Because we do not have enough memory on the GPU, we store the raw data as uint16_t
and int16_t
on the GPU. Thus, before I use this data I have to convert it to float
s.
The number of int
s is not that large (approximately 12k of uint16_t
and the same number of int16_t
). Profiling showed that converting the numbers takes a considerable amount of time (approx. 5-10%). The rest of the calculation cannot be optimized more.
Thus my 3+1 questions are:
int
s to float
s.int16_t
or uint16_t
.int
types, e.g. int32
or int64
.float
s to int
s. Is this something one usually does not do?Upvotes: 3
Views: 2327
Reputation: 1
- What is the fastest way to convert ints to floats.
Simple assignment. There are hardware type conversion instructions which the CUDA compiler will emit automatically without you doing anything. Hardware conversion includes the correct IEEE rounding modes.
- Is there a substantial difference when converting
int16_t
oruint16_t
.
No.
- Is there a substantial difference when converting larger int types, e.g.
int32
orint64
.
No.Yes. The instruction throughput for type conversion instructions is documented. 32 bit and 16 bit integer to float conversion instructions have the same throughput. 64 bit conversion instructions are considerably slower than 16 and 32 bit conversion instructions on most architectures.
- Why are all questions on SO about converting floats to ints. Is this something one usually does not do?
Because many people don't get the difference between float
and int
types, and why they loose precision, when they convert their float
or double
type to an int
type.
That's nothing you have to worry about in your situation.
Upvotes: 6