Cloo
Cloo copied to clipboard
Bool type maybe wrong calculated
I used a code for number theory returning results on a bool array. The code crashed in unpredictable way.
Now I found that SizeOf returns a 4 byte for bool. Should it be 1 byte? I am not sure. I changed the type on c# to byte[] and in kernel to uchar[], and the code works now.
Could there by a bug? I am not sure, so sorry if it is a false alarm.
internal static int SizeOf<T>() { return typeof (T).IsGenericType ? Marshal.SizeOf(default(T)) : Marshal.SizeOf(typeof(T)); }
https://stackoverflow.com/questions/4441280/does-opencl-support-boolean-variables
Arguments to __kernel functions in a program cannot be declared with the built-in scalar types bool, half, size_t, ptrdiff_t, intptr_t, and uintptr_t. The size in bytes of these types except half are implementation-defined and in addition can also be different for the OpenCL device and the host processor making it difficult to allocate buffer objects to be passed as arguments to a kernel declared as pointer to these type
TL;DR Don't use bools for kernel arguments.