lightnix

OpenCL tutorial help - CL_INVALID_KERNEL_NAME

Discussion created by lightnix on Oct 14, 2009
Latest reply on Oct 17, 2009 by lightnix

Hello there, I've been attempting to learn OpenCL and as such have been going through the Hello World openCL tutorial here:

http://developer.amd.com/gpu/ATIStreamSDK/pages/TutorialOpenCL.aspx

 

And whilst it is nicely written and easy to follow, I can't seem to get the thing to work properly! At the Kernel constructor call, I get an error -46, which as far as I can tell is 'CL_INVALID_KERNEL_NAME'. In cl.hpp that's described as "if \a name is not found in \a program." I've attempted to troubleshoot it to the best of my abilities (namely by getting the program to print out from the CL:rogram::source object, which appears to show the name of the kernel matches the one I'm trying to run - namely they're both 'hello' - not sure how helpful that is really!), but I think my knowledge of OpenCL is a bit lacking.

The samples (which are not using the C++ bindings, by the looks of it) build and run correctly for me, I'm using Visual Studio 2008, and am extremely stuck! Any help would be appreciated. I imagine I'll have just done something silly, though. 

 

EDIT: Okay, so I've found that replacing:

out[tid] = hw[tid];

with

out = hw[tid];

or any single character seems to work, but it outputs a load of garbage. Highly confusing! Is there any way to get any useful/relevant error messages? Either way it doesn't particularly seem to like writing to an element of 'out', only a single character to the whole pointer. 

 

MAIN.CPP #include <utility> #define __NO_STD_VECTOR #define __NO_STD_STRING #include <malloc.h> #include <CL/cl.hpp> #include <cstdio> #include <cstdlib> #include <fstream> #include <iostream> #include <string> #include <iterator> const std::string hw("Hello World!\n"); inline void checkErr(cl_int err, const char* name); int main() { cl_int err; cl::Context context( CL_DEVICE_TYPE_CPU, NULL, NULL, NULL, &err); checkErr(err, "Context::Context()"); char* outH = new char[hw.length()+1]; cl::Buffer outCL( context, CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, hw.length() + 1, outH, &err); checkErr(err, "Buffer::Buffer()"); cl::vector<cl::Device> devices; devices = context.getInfo<CL_CONTEXT_DEVICES>(); checkErr( devices.size() > 0 ? CL_SUCCESS : -1, "devices.size() > 0"); std::ifstream file("lesson1_kernels.cl"); checkErr(file.is_open() ? CL_SUCCESS: -1, "lesson1_kernels.cl"); std::string prog( std::istreambuf_iterator<char>(file), (std::istreambuf_iterator<char>())); cl::Program::Sources source( 1, std::make_pair(prog.c_str(), prog.length()+1)); cl::Program program(context, source); err = program.build(devices,""); checkErr(file.is_open() ? CL_SUCCESS : -1, "Program::build()"); std::cout<<source[0].first<<"\n"; std::string name("hello"); cl::Kernel kernel(program, name.c_str(), &err); if(err != CL_SUCCESS) { std::cout<<name<<" is an invalid method name."; } checkErr(err, "Kernel::Kernel()"); err = kernel.setArg(0,outCL); checkErr(err, "Kernel::setArg()"); cl::CommandQueue queue(context, devices[0], 0, &err); checkErr(err, "CommandQueue::CommandQueue()"); cl::Event event; err = queue.enqueueNDRangeKernel(kernel, cl::NullRange, cl::NDRange(hw.length()+1), cl::NDRange(1,1), NULL, &event); checkErr(err, "CommandQueue::enqueueNDRangeKernel()"); event.wait(); err = queue.enqueueReadBuffer(outCL, CL_TRUE, 0, hw.length() + 1, outH); checkErr(err,"CommandQueue::enqueueReadBuffer()"); std::cout<<outH; return EXIT_SUCCESS; return 0; } inline void checkErr(cl_int err, const char* name) { if(err != CL_SUCCESS) { std::cerr<<"Error! "<< name << " (" << err << ")\n"; std::cin.get(); exit (EXIT_FAILURE); } } LESSON1_KERNELS.CL __constant char hw[] = "Hello World\n"; __kernel void hello(__global char * out) { size_t tid = get_global_id(0); out[tid] = hw[tid]; } CONSOLE OUTPUT: For test only: Expires on Sun Feb 28 00:00:00 2010 __constant char hw[] = "Hello World\n"; __kernel void hello(__global char * out) { size_t tid = get_global_id(0); out[tid] = hw[tid]; } hello is an invalid method name.Error! Kernel::Kernel() (-46)

Outcomes