Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

float vs int in cuda

Tags:

cuda

Is it better to use a float instead of an int in CUDA?

Does a float decrease bank conflicts and insure coalescence? (or has it nothing to do with this?)

like image 918
neo Avatar asked Feb 27 '23 10:02

neo


2 Answers

Bank conflicts when reading shared memory are all about the amount of data read. So, since int and float are the same size (at least I think they are on all CUDA platforms), there's no difference.

Coalescence usually refers to global memory accesses - and again, this is to do with the number of bytes read, not the datatype.

like image 101
Edric Avatar answered May 06 '23 19:05

Edric


Both int and float are four bytes, so it doesn't make any difference (if you're accessing them both the same way) which you use in terms of coalescing your global memory accesses or bank conflicts on shared memory accesses.

Having said that, you may have better performance with floats since the devices are designed to crunch them as fast as possible, ints are often used for control and indexes etc. and hence have lower performance. Of course it's really more complicated than that - if you had nothing but floats then the integer hardware would sit idle which would be a waste.

like image 28
Tom Avatar answered May 06 '23 19:05

Tom