cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

Skysnake
Adept II

Cernel Error with the C++ binding sampel

Hi,

I have a very big problem with the OpenCL c++ sampel. I have solved several problems, but now i stuck and can´t find any solution for the Problem.

First my System:

Core2Duo E8400, HIS 5870, Cat 10.8 (8.14.10.0775), SDK2.2, VS2010 Prof, win 7 64

I start the project as a Visual C++ Win32 console appllication. After that I add to the linker $ATISTREAMSDKROOT)/lib/x86

Also i include the C:\...\ATI Sream\unclude\CL and C:\...\ATI Stream\include as Includedirectorys

As bilbiothekdirectorys i include C:\...\ATI Stream\lib

The Code is this:

 

So i can get it so far, that i can compile the programm without an arrow, the win32 console open, and i get the following results:

Platform number is: 1

Platform is by Advanced Micro Devices, Inc.

ERROR: Kernel() (-46)

Press any button...

 

I try very much, and use the search function for hours, but can´t find a solution for my problem

 

I hope somebody can help me.

 

PS: Excuse my english, i am no nativ speaker and schooltime is far away So when you don´t understand something, say it please.

 

EDIT: here the VS2010 project

http://s7.directupload.net/images/100914/9cvmyc3v.jpg

#################### lesson.cpp #################### // OpenCLAMD.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung. // #include "stdafx.h" #include <utility> #define __NO_STD_VECTOR //Use cl::vektor instead of STL version //#define __NO_STD_STRING #include <malloc.h> #define alloca _alloca #include <CL\cl.hpp> const std::string hw("Hello World\n"); inline void checkErr(cl_int err, const char* name)//Fehlerbehandlung da eine Anwendung geöffnet wird { if (err != CL_SUCCESS){ std::cerr<<"ERROR: "<<name<<" ("<<err<<")"<<std::endl; exit(EXIT_FAILURE); //Wenn OpenCL nicht richtig initialisiert wird, wird ein Fehler ausgegeben und das Programm beendet //Wenn kein Fehler auftaucht passiert nichts } } //int _tmain(int argc, _TCHAR* argv[]) int main() { cl_int err; cl::vector< cl::Platform > platformList; cl::Platform::get(&platformList); checkErr(platformList.size()!=0 ? CL_SUCCESS : -1, "cl::Platform::get"); std::cerr<<"Platform number is: "<< platformList.size()<<std::endl; std::string platformVendor; platformList[0].getInfo((cl_platform_info)CL_PLATFORM_VENDOR, &platformVendor); std::cerr<<"Platform is by: "<<platformVendor<<"\n"; cl_context_properties cprops[3]={CL_CONTEXT_PLATFORM, (cl_context_properties)(platformList[0])(),0}; cl::Context context( CL_DEVICE_TYPE_CPU, cprops, 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_kernel.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()"); cl::Kernel kernel(program, "hello", &err); 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::endqueueNDRangeKernel()"); event.wait(); err = queue.enqueueReadBuffer( outCL, CL_TRUE, 0, hw.length()+1, outH); checkErr(err, "CommandQueue::endqueueReadBuffer()"); std::cout<<outH; return EXIT_SUCCESS; } /* //ab hier kein OpenCL mehr printf("Hallo Welt"); std::cin.get(); return 0; } */ ############ lesson1_kernels.cl ############ #pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable __constant char hw[] = "Hello World\n"; __kernel void hello (__global char * out) { size_t tid = get_global_id(0); out [tid]= hw[tid]; }

0 Likes
Reply
11 Replies
nou
Exemplar

Cernel Error with the C++ binding sampel

-46 is CL_INVALID_KERNEL_NAME so double chceck if you load kernel source properly
0 Likes
Reply
Skysnake
Adept II

Cernel Error with the C++ binding sampel

Ok, now i know whot the Problem is, i also thought that it is a Problem with the Cernel, the debugger stops in the line, where the cernel load.

But my problem now is, that i don´t understand how this helps me to fix the bug.

 

EDIT: I have only two lines, with the cernel:

 

cl::vector devices;
    devices=context.getInfo();
    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(file),
        (std::istreambuf_iterator()));

 

The underlined s wasn´t there, but it doesnt matter if it is there or not. Allways the same failure

 

EDIT: perhaps it helps, that i can´t do this step:

On Windows, with a Visual Studio command window, an example is:
cl /Fehello_world.exe /Ipath-OpenCL-include lesson.cpp path-OpenCL-libdir/OpenCL.lib

I just compile it with "F7" or "STRG+ALT+F7" and than start it without debugger

0 Likes
Reply
Skysnake
Adept II

Cernel Error with the C++ binding sampel

Nobody out there who knows whot the mistake is?

 

With another OpenCL program that didn´t use a .cl kernel file i have no problems.

0 Likes
Reply
ryta1203
Journeyman III

Cernel Error with the C++ binding sampel

So nou's suggestion was incorrect? Why do you send clBuildProgram an empty string?

0 Likes
Reply
Skysnake
Adept II

Cernel Error with the C++ binding sampel

I just follow the instructions under http://developer.amd.com/gpu/ATIStreamSDK/pages/TutorialOpenCL.aspx

 

And there also just stand:

cl::Program program(context, source);
err = program.build(devices,"");
checkErr(file.is_open() ? CL_SUCCESS : -1, "Program::build()");

I learn atm OpenCL and i think this exampel ist very confusing. I understand some basics, but not everything. So i can´t say you why there is a emty sting.

It realy looks strange.
0 Likes
Reply
ryta1203
Journeyman III

Cernel Error with the C++ binding sampel

That looks like a horribly put together tutorial, I wouldn't follow that if I were you.

0 Likes
Reply
Skysnake
Adept II

Cernel Error with the C++ binding sampel

Yeah, but the Problem is, that i want to bring a matlab programm from CPU to GPU with OpenCL. Atm it takse 6 hour for a picture. The goal ist to solve the problem with a consumer card in a few minutes or less. So performance is very important. And so i think there is now way without c++ bindings, and i know no ohter exampel, than this.

And also it must work -.-

0 Likes
Reply
himanshu_gautam
Grandmaster

Cernel Error with the C++ binding sampel

hi skysnake,

Have you tried running hellocl sample that came with the SDK.

0 Likes
Reply
Skysnake
Adept II

Cernel Error with the C++ binding sampel

Yes i try some sampels from the SDK, and i also have no problems with my own OpenCL programs.

Only when the source is in a etxra file i have problems.

0 Likes
Reply