I am new to OpenCL so I have been working on some simple Opencl c++ programming. I have written a code on Gray scaling using OpenCL and OpenCV. It has been compiled properly, but on run it gives me the following error: -
Platform Found : ARM Platform
terminate called after throeing an instance of ‘cl::Error’
what() : clCreateKernel
Aborted
I have been writing the code on Ubuntu, using vim editor.
My host code is : -
int main( int argc, char** argv )
{
cl_int error = 0 ;
//Load image using OpenCV
IplImage *src = cvLoadImage("/home/akash/Desktop/Bird.jpg",CV_LOAD_IMAGE_COLOR );
IplImage *result_image = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1);
const int width = src->width;
const int height =src->height;
unsigned char *vec_h;
// long count = width*height;
// std::vector<float> size(width*height,1);
vec_h = (unsigned char )malloc((widthheight)*sizeof(unsigned char));
std::vector<cl::Platform> plat;
std::vector<cl::Device>dev;
try
{
//Find OCL platform
cl::Platform::get(&plat);
string value;
if(plat[0].getInfo(CL_PLATFORM_NAME,&value)!=CL_SUCCESS)
{
std::cout<<"No platform found"<<std::endl;
}
else
cout<<"Platform found : "<<value<<endl;
//Find device
if(plat[0].getDevices(CL_DEVICE_TYPE_GPU,&dev)!=CL_SUCCESS)
{
std::cout<<"No device found"<<std::endl;
}
// Context Properties
cl_context_properties props[3] = {CL_CONTEXT_PLATFORM,(cl_context_properties)(plat[0]), 0};
//Create Context
cl::Context ctxt(dev,props,0,0,&error);
//Create CommandQueue
cl::CommandQueue cque(ctxt,dev[0],0,&error);
//Create Program
std::ifstream sourceFileName("/Grayscale/Test1.cl");
std::string sourceFile(std::istreambuf_iterator<char>(sourceFileName),(std::istreambuf_iterator<char>()));
cl::Program::Sources graysrce(1,std::make_pair(sourceFile.c_str(),sourceFile.length()+1));
cl::Program prog(ctxt,graysrce);
//BuildProgram
prog.build(dev);
//Create Kernels
cl::Kernel kernel(prog,"Grayscale",&error);
//Memory Objects
cl::Buffer input, output;
input = cl::Buffer(ctxt,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,width*height,NULL,&error);
output =cl::Buffer(ctxt,CL_MEM_WRITE_ONLY,width*height,0,&error);
The error is at clCreateKernel so I have added code till that only.
Any ideas?? Thanks for the help!!