【问题标题】:OpenCL: State space mismatch between instruction and addressOpenCL:指令和地址之间的状态空间不匹配
【发布时间】:2012-07-02 15:27:42
【问题描述】:

我正在编写一个 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;
}

.....
}

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

【问题讨论】:

    标签: c++ opencl ptxas


    【解决方案1】:

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

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

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

    【讨论】:

    • 为什么您认为该错误与demand 结构有关?汇编语言翻译似乎表明问题与inst_to_cust数组有关。
    • 你是对的。我错过了需求中的“s”。然后我不明白你为什么会收到错误。您是否尝试过从 inst_to_cust 声明中删除初始化数组,只是为了看看它是否有所不同?
    • 好建议 - 从声明中移动初始化确实解决了问题。唯一的问题是,现在初始化看起来像maxinst_per_rack[0] = 2; maxinst_per_rack[1] = 1; 等,看起来不太好(优雅),尤其是当我使用更长的数组时。另外,我不知道为什么移动初始化可以解决问题。
    • 对我来说它看起来像是一个编译器错误。就好像编译器将整个数组放在常量内存中只是因为它是用常量列表初始化的。
    • 看起来初始化值是特定于算法正在解决的问题的一个实例,而不是一般实例?如果是这样,当您的算法变得更加完整并且您将其设置为处理问题的一般实例时,这个特定问题可能会消失。
    猜你喜欢
    • 2016-07-20
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 2018-07-19
    • 1970-01-01
    相关资源
    最近更新 更多