I'm writing a OpenCL program and on build I get this error:
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)
The corresponding ptx lines (auto-generated) are:
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];
Here's the function I've written :
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;
}
.....
}
What is the reason for the error? How can it be resolved?
The compiler is confused as to the location of the demand
struct. "state space" is ptx-talk for memory type. ld.local
expects the source to be in local memory, but in your case, it looks like it is actually in constant memory.
I'm not familiar with OpenCL, but in CUDA the __constant__
qualifier places variables in constant memory, which has special caching semantics. It's not related to const
in C++. It may be that the compiler is confused because you're using them together.
Try removing one or both of __constant
and const
from the __constant const struct demand *demand
line.