I need to do GPU computations on an boolean array bool[] (note, not a std::vector<bool>) which was created in CPU memory (with C++11 code) and then copied to the GPU via cuMemCpy or similar.
First question:
sizeof(bool) reports 1 byte. Is this guaranteed by the C++11 standard?
Second question:
Is true (false) always represented as 1 (0) (in the unsigned char representation) or does the compiler have freedom here ? (It could use any non-zero integer less than 256 if it wanted)
Third question (PTX specific):
In PTX logical operations or, xor, etc. only operate on types larger than 8 bit. That is I can do logical operations on an unsigned int with or.u32 <out>,<in1>,<in2>. However since C++11 bool type seems to be 8 bits does this mean I can not operate on an array of bools that was copied directly from CPU to GPU memory and thus do I need to convert the array of bools first into some type PTX logical operations can operate on, i.e. u32, u16, etc.?
First answer:
No, this is not guaranteed. See
[expr.sizeof]/1, and the associated footnote:Second Answer:
I'm pretty sure that the value representation for
boolobjects is implementation defined, but I can't find anything explicitly stating that. The closest that I can get is[basic.types]/4:Third Answer:
I don't know, but from your description, it certainly looks like you would have to change the types.