Skip to content

结构体对齐的问题 #161

Closed
Closed
@Jules-Kong

Description

@Jules-Kong
  • 复现
    测试套:cts/vectors
    ./test_vectors vec_align_packed_struct_arr
  • 现象
    Screenshot from 2025-01-07 14-40-41
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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions