-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inconsistent alignment of cl_* types on i386 #149
Comments
FWIW, we used to have alignment attributes on these types, but removed them a couple of years ago: The POCL issue linked above seems to be about passing structs from host code to kernel code. Is that correct? Just trying to understand the bounds of the problem. Thanks! |
The test in question is https://github.com/pocl/pocl/blob/master/tests/regression/test_structs_as_args.cpp The error output is
I think dropping the Should there be tests for alignment expectations and struct paddings? |
Thank you for your patience and sorry for the slow reply. I'm not sure that there is a "right answer" to this problem. On the one hand, including the alignment attribute is convenient, assuming it it works, and when using the "cl"-prefixed types. On the other hand, including the alignment attribute may not be supported everywhere, has its own set of problems (the GCC STL warning mentioned in #40 was especially ugly), and doesn't "just work" when using standard C or C++ types vs. the "cl"-prefixed types. Could / should alignment attributes be placed on the struct members in the test host code itself (and perhaps in the device code also?) to ensure a consistent layout between the host and the device? |
What about a patch like https://gist.github.com/anbe42/3e3c6fadf25b0619abaa8206b46efc87 ? That does solve the alignment inconsistency for the I do not know whether this issue affects the 32-bit windows world and if it needs/can/should be fixed there, too. Of course it can be fixed in the struct used in the pocl testcase, but if writing portable OpenCL code using structs requires manual struct alignment that would really be a pity:
|
Enhanced version of my test program, supporting both C and C++:
|
141/143 Test pocl#85: regression/struct_kernel_arguments ..................................................***Failed Error regular expression found in output. Regex=[FAIL] 4.58 sec CMake Error at /build/pocl-1.4/cmake/run_test.cmake:34 (message): FAIL: Test exited with nonzero code (1): /build/pocl-1.4/obj-i686-linux-gnu/tests/regression/test_structs_as_args STDOUT: F(4: 0 != 5) F(5: -2147483648 != 6) F(6: 0 != 7) F(7: 0 != 8) STDERR: -- OK on i386, the default alignment is 4 for 64-bit types, too the OpenCL standard is only explicit about alignment requirements for OpenCL types, but not for the corresponding cl_* types in C KhronosGroup/OpenCL-Headers#149 fixes: pocl#801
While looking further into pocl/pocl#801 on Debian i386 I found some inconsistencies in the alignment of
cl_*
types resulting in astruct {cl_int; cl_long;};
to have size12
on i386 but16
elsewhere (includingstruct {int; long;};
in OpenCL).This causes mismatches when passing such a struct as a kernel argument.
We all know that i386 is 'special' with its alignment requirements, but does this need to carry on into
cl_*
?I found it especially curious to see differences between results in a i386 chroot and a 32-bit program built on the x86-64 host system with
-m32
.(All this was observed on Debian sid/testing with
gcc-10
, I haven't tested this on other distributions.)I can't conclude from the standard that
cl_long
inC
should have an alignment of8
(only for the OpenCLlong
type this is required), but maybe I've just missed something?But doesn't a
cl_long
without well defined alignment somehow break its purpose?A small program to show the alignments of some types:
The text was updated successfully, but these errors were encountered: