I am using atomic_add(char *ptr, (char)(-1)), and dump the result of ptr, it shows the first position is FEFF, seems like the ptr is 32bit buf , but indeed ptr is 8bit’s buf. Why the result is FEFF not FE00?
The legacy atomic builtins operate on int
or unsigned int
values (see OpenCL C 1.x Legacy Atomics).
The C11 atomic style builtins operate on atomic types (atomic_int
, atomic_float
etc.), but those are also 4 or 8 bytes in size.
Given how strongly GPUs prefer to operate on 4 byte sized (and aligned!) types, I think that’s not really surprising. I’m almost more surprised you are not getting a warning about the conversion from char*
to the argument type of atomic_add
, but perhaps there is some quirky rule about char*
conversions that prevents it?