2013年3月5日 星期二

OpenCL(1) vector add



//vector add 副程式  類似glsl中 fragment shader 和vertex shader呼叫方式


const char* programSource =
"__kernel                 \n"
"void vecadd(__global int *A,\n"
"            __global int *B,\n"
"            __global int *C) \n"
"{\n"

"   // Get the work-item unique ID                \n"
"   int idx = get_global_id(0);                   \n"
"\n"
"   // Add the corresponding locations of        \n"
"   // 'A' and 'B', and store the result in 'C'. \n"
"   C[idx] = A[idx] + B[idx];\n"
"}\n"
;



main主程式
...
kernel = clCreateKernel(program, "vecadd", &status);    //inline 方式call vecadd
...


Compile方法

g++ vectoradd.c -I/usr/local/cuda-5.0/include -L/usr/local/cuda-5.0/lib64 -lOpenCL

沒有留言:

張貼留言