ATI/AMD OpenCL的局部变量对齐

ATI/AMD OpenCL的局部变量对齐,opencl,gpu,memory-alignment,ati,amd-processor,Opencl,Gpu,Memory Alignment,Ati,Amd Processor,我遇到了结构失调的问题。以下是涉及的结构: struct Ray { float4 origin; float4 dir; float len; float dummy [3]; }; struct RayStack { struct Ray r [STACK_DEPTH]; int depth [STACK_DEPTH]; float refr [STACK_DEPTH]; int top; float dummy [3

我遇到了结构失调的问题。以下是涉及的结构:

struct Ray
{
    float4 origin;
    float4 dir;
    float len;
    float dummy [3];
};

struct RayStack
{
    struct Ray r [STACK_DEPTH];
    int depth [STACK_DEPTH];
    float refr [STACK_DEPTH];
    int top;
    float dummy [3];
};
顺便说一下,堆栈深度是4的倍数。我一直小心地确保所有结构的大小都是16的倍数,并且float4位于对齐的边界上

问题是,当我将其用作局部变量时,结构光线堆栈未对齐:

struct RayStack stack;
printf("stack: %p\n", &stack);
堆栈地址以8结尾,而不是像我希望的16字节对齐结构那样以0结尾。这会导致ATI卡崩溃(尽管Intel和nVidia对此不感兴趣)。我试着将_属性_((对齐(16)))放在结构中(前后)和局部变量定义中,这不会改变任何东西。实际上,添加printf语句解决了这个问题,尽管我不知道如何解决

确保本地变量堆栈在16字节边界上对齐,并停止ATI卡上的崩溃

谢谢

您知道结构中的数组必须与16字节边界对齐吗?
“虚拟”数组的作用是什么?衬垫?如果是这样,请不要使用数组填充。
根据我对Nvidia、ATI和Intel的经验,以下是最安全的方法:

struct Ray
{
    float4 origin;
    float4 dir;
    float len;
    float padding1;
    float padding2;
    float padding3;
};

struct RayStack
{
    struct Ray r[STACK_DEPTH];
    int depth[STACK_DEPTH];
    float refr[STACK_DEPTH];
    int top;
    float padding1;
    float padding2;
    float padding3;
};

更新:我刚刚发现12.8版的驱动程序出现了问题。我认为12.10驱动程序破坏了编译器中的某些东西。