我试图在Xcode中编译这段代码,但是我得到了上面的错误
const char *KernelSource = "\n"\
"__kernel void pi( \n"\
"__global float* out, \n"\
"uint cntSteps \n"\
") \n"\
"{ \n"\
" const uint idThread = get_local_id(0); \n"\
" uint numprocs = get_global_size(0); \n"\
" const float local_num = (float)cntSteps / numprocs; \n"\
"float step = 1.0 / cntSteps; \n"\
"float sum = 0.0; \n"\
"float x; \n"\
"int localmax = (idThread + 1) * local_num; \n"\
"for(uint i = idThread * local_num; i < localmax; i++) \n"\
"{ \n"\
"x = step * (i + 0.5); \n"\
"sum = sum + 4.0 / (1.0 + x * x); \n"\
"} \n"\
"out[idThread] = sum * step; \n"\
"} \n";
知道这个内核有什么问题!,
答案 0 :(得分:0)
以下是我解决它的方法:
// calc_pi.cl
kernel void pi(global float* out, uint cntSteps) {
const uint idThread = get_local_id(0);
uint numprocs = get_global_size(0);
const float local_num = (float)cntSteps / numprocs;
float step = 1.0 / cntSteps;
float sum = 0.0;
float x;
int localmax = (idThread + 1) * local_num;
for(uint i = idThread * local_num; i < localmax; i++) {
x = step * (i + 0.5);
sum = sum + 4.0 / (1.0 + x * x);
}
out[idThread] = sum * step;
}
2. in main.cpp
// include all necessary headers and the above kernel e.g
#include "calc_pi.cl.h"
//.. more includes
我希望这有助于某些人开始在Xcode中使用OpenCL。