Closed
Description
typedef struct __attribute__ ((packed)) myPackedStruct {
int3 tPre;
int3 vec;
} testStruct;
__kernel void test_vec_align_packed_struct_arr(__global testStruct *source, __global uint *dest)
{
int tid = get_global_id(0);
dest[tid] = (uint)((__global uchar *)&(source[tid].vec) - (__global uchar *)&(source[0]));
}
- 分析
这是一个结构体对齐的测试;
对于一个int3变量,我们期望的大小是16,但得到17。把int3换成float3,uint3问题也存在。
如果换成char3,uchar3,short3,ushort3,double3就没有问题;第一个偏移分别是4,4,8,8,32.