3 Replies Latest reply on Oct 17, 2009 8:32 PM by lightnix

    OpenCL tutorial help - CL_INVALID_KERNEL_NAME

    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)

        • OpenCL tutorial help - CL_INVALID_KERNEL_NAME
          laykun

          Hi Lightnix,

          This may be a little too late but I had the exact same problem as you. I however have found a workaround for fixing this.

          In your kernel method instead of passing it a char pointer make it so that it takes a uint pointer, this is effectively the same as a char. so your method signature should look like this "void hello(__global uint* out)", the char array holding hello world can remain of type char though.

          This means you have to change outH to type u_int *, and when it comes to printing the message just make a for loop that prints out each individual character, casting them to type char.

          Hope this helps, Leigh.

           

          • OpenCL tutorial help - CL_INVALID_KERNEL_NAME
            genaganna

             

            Originally posted 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. 

             

             

             

             

            Add following pragma to .cl file.

            #pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable

            Note : write to < 32 bits via pointer not allowed without enabling cl_khr_byte_addressable_store extension

            beta4 not supporting any extensions to GPU.

             

            Still not clear why program.build is not giving any error.