__kernel void MyCLAdd(__global int *dst, __global int *src1, __global int *src2)
{
int index = get_global_id(0);
dst[index] = src1[index] + src2[index];
}
我们将上述代码保存为cl_kernel.cl,放在这个工程放资源文件和源代码的文件夹下。在VC++工程中,我们可以将这个文件添加到Resource筛选器下。
接下来,我们可以写main函数,或其它什么函数来创建并运行这段OpenCL内核代码。
#include
#include
#include
using namespace std;
int main(void)
{
cl_uint numPlatforms = 0; //the NO. of platforms
cl_platform_id platform = nullptr; //the chosen platform
cl_context context = nullptr; // OpenCL context
cl_command_queue commandQueue = nullptr;
cl_program program = nullptr; // OpenCL kernel program object that'll be running on the compute device
cl_mem input1MemObj = nullptr; // input1 memory object for input argument 1
cl_mem input2MemObj = nullptr; // input2 memory object for input argument 2
cl_mem outputMemObj = nullptr; // output memory object for output
cl_kernel kernel = nullptr; // kernel object
cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms);
if (status != CL_SUCCESS)
{
cout