OpenCL:指令和地址之间的状态空间不匹配

时间:2012-07-02 08:10:02

标签: c++ opencl ptxas

我正在编写一个OpenCL程序,在构建时我遇到了这个错误:

Build Log:
ptxas application ptx input, line 268; error   : State space mismatch between instruction and address in instruction 'ld'
ptxas application ptx input, line 269; error   : State space mismatch between instruction and address in instruction 'ld'
ptxas application ptx input, line 270; error   : State space mismatch between instruction and address in instruction 'ld'
ptxas application ptx input, line 271; error   : State space mismatch between instruction and address in instruction 'ld'
....(same error on several more lines)

相应的ptx行(自动生成)为:

ld.local.u32    %r1913, [demands$inst_to_cust+16];
ld.local.u32    %rl10, [demands$inst_to_cust+12];
ld.local.u32    %rl12, [demands$inst_to_cust+8];
ld.local.u32    %rl14, [demands$inst_to_cust+4];
ld.local.u32    %rl16, [demands$inst_to_cust];

这是我写的函数:

int
demands(cl_ushort ball, cl_ushort bin,
    __global const struct problem *problem,
    __constant const struct demand *demand,
    const cl_ushort soln[BALL_MAXNUM],
    struct demand_op ops[DEMAND_MAXOPS],
    __global cl_ushort debug_data[DEBUG_LEN])
{
int i, k = demand->data[0]; 
int serv_to_rack[] = {0, 1, 1}; 
int inst_to_cust[] = {0, 0, 0, 1, 1}; 
int maxinst_per_rack[] = {2, 1}; 

int cust_num = inst_to_cust[ball];
int max = ball, min = ball, count = 1;
int max_in_rack = maxinst_per_rack[cust_num];
for (i = ball; i < NUM_BALLS; i++) {
    if (inst_to_cust[i] == ball) max = i;
    else break;
}

.....
}

错误的原因是什么?怎么解决?

1 个答案:

答案 0 :(得分:1)

编译器对demand结构的位置感到困惑。 “状态空间”是内存类型的ptx-talk。 ld.local期望源位于本地内存中,但在您的情况下,它看起来实际上是在常量内存中。

我不熟悉OpenCL,但在CUDA中,__constant__限定符将变量放在常量内存中,该内存具有特殊的缓存语义。它与C ++中的const无关。编译器可能会因为你一起使用它们而感到困惑。

尝试从__constant行中删除const__constant const struct demand *demand中的一个或两个。