Hi, I’m tying to make a fifo buffer in cuda where I automaticlly will end up in the “beginning of the buffer” right after I reached the end of the buffer. I would prefere solving this using modulus, but unfortunatly I can’t find the syntax for modulus in cuda. I’ve tried using normal c implementation, but that does not work. Any suggestions?
The syntax for modulus is just %, like in normal C. But believe me, you don’t want to use it in CUDA as it’s extremely slow (it uses floating point division in some strange way). Simply do this:
Thanks for the tip!
I dont think this trick works, at least the way I understand it. What is X ? is that just a counter?
X apparently is the variable that the modulus should be taken of. If you don’t increment X in steps of 1, you should probably replace
X = (X+step) % bufsize;
X += step; while (X>= bufsize) X -= bufsize;
If bufsize is a power of 2, then instead of X % bufsize do X & (bufsize-1)