atomicAdd function for an unsigned short value

Hallo cuda fans,

I need a function to add two unsigned short values atomically. The atomicAdd function is only for a 32Bit integer but I use an unsigned short value.

Is there a particular reason you cannot simply substitute a 32-bit integer? Rule of thumb based on experience: Every integer wants to be an int unless there is a compelling reason for it to be some other integer type.

1 Like

You can do atomic operations on one byte and two byte quantities, using a 4-byte atomic operation plus some extra processing. this thread may be of interest.

1 Like

with unsigned short support available in atomicCAS you can directly combine that with the custom atomic example given in the programming guide to create a 16-bit atomic op. Any of these methods that I have mentioned will be less performant than doing a native 32-bit atomic op, so as hinted by njuffa that realization may be preferred for performance.

1 Like