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

标签 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;
}

.....
}

错误的原因是什么?如何解决?

最佳答案

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

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

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

关于c++ - OpenCL:指令和地址之间的状态空间不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11289893/

相关文章:

c++ - 在没有兼容硬件的情况下运行 OpenCL?

OpenCL:仅运行基于 CPU 的内核的单个实例

cuda - 如何实现涉及多个变量的自定义原子函数?

c++ - CUDA:--ptxas-options=-v 共享内存和 cudaFuncAttributes.sharedSizeBytes 不匹配

c++ - 尝试在单击按钮时从编辑框中捕获文本,然后显示到另一个编辑框

c++ - MFC 应用程序启动后立即崩溃

c++ - 当我将它添加到指针时,我可以安全地忽略溢出检查的最小偏移量是多少?

cuda - 不同硬件的编程模型

cuda - 避免内联 PTX 中不必要的 mov 操作

c++ - 无法让变量相互交互 (C++)