compute-runtime
compute-runtime copied to clipboard
[OpenCL] struct value argument issue when compiling via SPIR-V
With the following OpenCL C code the computation and sizeof is strange for the iGPU OpenCL driver when building via SPIR-V:
struct Foo {
int A;
long B;
};
kernel void struct_argsize(struct Foo F, global long* out) {
out[0] = F.A + F.B;
out[1] = sizeof(struct Foo);
out[2] = F.A;
out[3] = F.B;
}
### 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
Using OpenCL C.
Host sizeof(Foo): 16
Output: 110
Device sizeof(Foo): 16
Components: 10 100
Output OK.
### 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
Using SPIRV.
Host sizeof(Foo): 16
Output: 110
Device sizeof(Foo): 16
Components: 10 100
Output OK.
### Intel(R) Iris(R) Xe Graphics [0x9a49]
Using OpenCL C.
Host sizeof(Foo): 16
Output: 110
Device sizeof(Foo): 16
Components: 10 100
Output OK.
### Intel(R) Iris(R) Xe Graphics [0x9a49]
Using SPIRV.
Host sizeof(Foo): 16
Output: 94591419739465
Device sizeof(Foo): 139848430125057
Components: 10 100
Output wrong.
This was found when trying to figure out what are the struct alignment rules in SPIR-V, which are not entirely clearly stated (see https://github.com/CHIP-SPV/chip-spv/issues/279).