lundi 24 juin 2019

How to fix: Initializing a cl::Kernel has error that kernel name returns empty string

I tried to initialize a OpenCL kernel with cl::Kernel. The constructor of cl::Kernel needs a cl::Program (in the following called program) and a const char[] (in the following called kernel name). As mentioned in the title, I have the problem that the kernel name is always an empty string.

I tried to copy the char array of the std::string like in the following code.

cout << "Generate Programm for: " << device.getName() << endl;
            device.generateProgramm(task);
            char * cstr = new char[task->getKernelName().length() + 1];
            strcpy(cstr, task->getKernelName().c_str());
            cout << "Kernel Name: " << cstr << endl;
            cl::Kernel kernel = cl::Kernel(task->getProgramm(), cstr,  &ErrorCode);
            cout << "Error Code for generating Kernel: "<<ErrorCode <<" Kernel Name: "<<task->getKernelName()<<"-"<<kernel.getInfo<CL_KERNEL_FUNCTION_NAME>()<<endl;

I've even tried to set the kernel name like this:

cl::Kernel kernel = cl::Kernel(task->getProgramm(), "xAxis",  &ErrorCode);

The current result is: Generate Programm for: pthread-Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz Success Kernel Name: xAxis Error Code for generating Kernel: -46 Kernel Name: xAxis-

The expected restult is: Generate Programm for: pthread-Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz Success Kernel Name: xAxis Error Code for generating Kernel: 0 Kernel Name: xAxis-xAxis

So the correct Kernel name is set.

Please help me.

Aucun commentaire:

Enregistrer un commentaire