![](/img/trans.png)
[英]When I try to install cython I get an error message unable to execute gcc-4.0
[英]subscripted value is not an array, pointer, or vector, i get this error message when i try to execute this kernel code
xx_np = np.random.rand(16500).astype(np.float32)
u_np = np.random.rand(16500).astype(np.float32)
vector_np = np.random.rand(16500).astype(np.float32)
temp_np = np.random.rand(16500).astype(np.float32)
ctx= cl.Context([device]) #context
queue = cl.CommandQueue(ctx) #commandqueue
mf = cl.mem_flags #memoryflags
xx_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=xx_np)
u_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=u_np)
vector_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=vector_np)
temp_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=temp_np)
q00=q0
prg = cl.Program(ctx, """
__kernel void dota( __global float *xx, __global float *u, __global float *vector, __global float *temp, __global float *res, float q00, float s,float i)
{
int index = get_global_id(0);
int qindex= get_global_id(0);
res[index] = xx[index]*u[index-1];
res[index] = res[index]*u[index-1];
xx[index]= xx[index]-res[index];
float a= pow(pow(xx[index],2)+pow(xx[index+1],2),0.5);
float b= pow(pow(vector[index],2)+pow(vector[index+1],2),0.5);
if(b==0)
{ i=vector[qindex]+q00;
b=pow(pow(i,2)+pow(i,2),0.5);
}
s=100*(a/b);
s[index]=s;
temp[index]=s[index];
}
""").build()
res_g = cl.Buffer(ctx, mf.WRITE_ONLY, temp_np.nbytes)
prg.dota(queue, temp_np.shape, None, temp_g, xx_g,res_g)
res_np = np.empty_like(temp_np)
cl.enqueue_copy(queue, res_np, res_g)
print res_np
下標的值不是數組,指針或向量,因此當我嘗試執行此內核代碼時會收到此錯誤消息。
我是opencl和內核代碼的新手,所以無法弄清楚為什么我收到此錯誤消息。 因為我采用了global_id(0)
,然后將其大小用作索引。 它應該工作正常。
s
是一個浮點變量,所以s[index]=s;
會引發錯誤
在代碼中,您已經定義了
s
作為..., float s, ...
index
為int index
其中既不是數組也不是指針。 但是后來,你寫
s[index]=s;
根據C11
第§6.5.2.1章,數組下標為Constraints,
其中一個表達式應具有“完成對象類型的指針”類型 ,另一個表達式應具有整數類型。
違反,因此您會看到錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.