cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

JanS
Journeyman III

Internal error: Compilation failed since SDK 2.1

Hi,

i just downloaded and installed the new SDK 2.1. I've read about the OpenCL ICD changes, but i think that is not causing the problem. Nearly all SDK samples work without Problems, CLInfo etc. Just my code crashes and i dont know why.

Im running Ubuntu 32bit with current 10.4. drivers and updated all my includes and linker paths to the new SDK dir.

output and comments are in german. i tried to use as much c++ comfort as possible, ok. im a little ashamed because i used global variables but this code will be kept small and shouldnt be critical.

if you got other comments or improvements, please dont be afraid to tell it.

#define __CL_ENABLE_EXCEPTIONS #define __NO_STD_VECTOR #define __NO_STD_STRING #include <cstdio> #include <cstdlib> #include <iostream> #include <fstream> #include <ctime> #if defined(__APPLE__) || defined(__MACOSX) #include <OpenCL/cl.hpp> #else #include <CL/cl.hpp> #endif #include "ComputationTest.hpp" const char* filename = "aida_kernel.cl"; cl::vector<cl::Platform> platforms; cl::vector<cl::Device> devices; cl::Context context; cl::Program program_; int main(void) { const int count = 1048576; size_t memSize = sizeof(int)*count; int* data = new int[count]; for(int i=0; i < count; ++i ) data = 0; std::ifstream file(filename, std::ifstream::in); if(!file.is_open()) { std::cerr << "ERROR: Could not open kernel file " << filename << std::endl; return EXIT_FAILURE; } std::string prog(std::istreambuf_iterator<char>(file), (std::istreambuf_iterator<char>())); try { cl::vector<cl::Platform>::iterator curPlatform = initPlatform(); context = initContext(CL_DEVICE_TYPE_GPU, curPlatform); cl::vector<cl::Device>::iterator curDevice = initDevice(); cl::Program::Sources source(1, std::make_pair(prog.c_str(),prog.size())); program_ = cl::Program(context, source); program_.build(devices); cl::Kernel kernel(program_, "aida"); size_t localsize = kernel.getWorkGroupInfo<CL_KERNEL_WORK_GROUP_SIZE>(*devices); cl::CommandQueue queue(context, *curDevice); cl::Buffer membuff( context, CL_MEM_READ_WRITE, memSize ); // Daten vom Hauptspeicher in den GPU Speicher schreiben queue.enqueueWriteBuffer( membuff, CL_TRUE, 0, memSize, data ); cl::KernelFunctor func = kernel.bind( queue, cl::NDRange(count), cl::NDRange(localsize) ); time_t secondelapsed = time(NULL); std::cout << "\nStarting kernel..." << std::endl; func(membuff).wait(); time_t secondsfinished = time(NULL); // Daten vom GPU Speicher in den Hauptspeicher zurückschreiben queue.enqueueReadBuffer( membuff, CL_TRUE, 0, memSize, data ); /* unsigned int correct = 0; for( unsigned int i = 0; i < count; ++i ) { // std::cout << data << std::endl; // if( data == i ) ++correct; } std::cout << "Computed " << correct << "/" << count; std::cout << " correct values." << std::endl;*/ std::cout << "Finished after " << (secondsfinished - secondelapsed) << " seconds." << std::endl; } catch (cl::Error err) { std::cerr << "ERROR: " << err.what() << "(" << err.err() << ")" << std::endl; if(err.err() == -11) { std::cout << "Build log:\n" << program_.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[0]).c_str() << std::endl; } return EXIT_FAILURE; } return EXIT_SUCCESS; } cl::vector<cl::Platform>::iterator initPlatform() { std::cout << "Getting platform information...\n"; cl::Platform::get(&platforms); cl::vector<cl::Platform>::iterator i; if (platforms.size() > 0) { int platformCount = 0; for (i = platforms.begin(); i != platforms.end(); ++i, ++platformCount) { std::cout << "Found platform[" << platformCount << "]\n" << "\tName: " << (*i).getInfo<CL_PLATFORM_NAME>().c_str() << "\n" << "\tVendor: " << (*i).getInfo< CL_PLATFORM_VENDOR>().c_str() << "\n" << "\tPlatform Version: " << (*i).getInfo< CL_PLATFORM_VERSION>().c_str() << std::endl; } --i; // get last known(workaround) std::cout << "Using default platform[0]\n"; } return i; } cl::Context initContext(cl_device_type type, cl::vector<cl::Platform>::iterator& platforms) { cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)(*platforms)(), 0 }; return cl::Context(type, cps, NULL, NULL, NULL); } cl::vector<cl::Device>::iterator initDevice() { devices = context.getInfo<CL_CONTEXT_DEVICES> (); cl::vector<cl::Device>::iterator i; std::cout << "\nGetting device information...\n"; if (devices.size() > 0) { int deviceCount = 0; for (i = devices.begin(); i != devices.end(); ++i, ++deviceCount) { std::cout << "Found device[" << deviceCount << "]\n" << "\tName: " << (*i).getInfo<CL_DEVICE_NAME>().c_str() << "\n" << "\tGlobal memory size: " << (*i).getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>() / 1000 << "kb\n" << "\tVendor: " << (*i).getInfo< CL_DEVICE_VENDOR>().c_str() << "\n" << "\tDevice Version: " << (*i).getInfo< CL_DEVICE_VERSION>().c_str() << std::endl; } --i; // get last known(workaround) std::cout << "Using default device[0]\n"; } return i; } --------------------------------------------------------------KERNEL-------------------------------------------------------- __kernel void aida( __global int* membuff ) { const size_t id = get_global_id(0); for(int i=0; i < 10000;++i) { membuff[id] = membuff[id] ^ i; } }

0 Likes
2 Replies
dravisher
Journeyman III

I tried to compile the program, but I had to remove #include "ComputationTest.hpp", since I don't have that file, and I had to move the initPlatform, initContext and initDevice functions above main, since they were not declared. After this the code runs on my HD5870, output:


Getting platform information...
Found platform[0]
Name: ATI Stream
Vendor: Advanced Micro Devices, Inc.
Platform Version: OpenCL 1.0 ATI-Stream-v2.1 (145)
Using default platform[0]

Getting device information...
Found device[0]
Name: Cypress
Global memory size: 268435kb
Vendor: Advanced Micro Devices, Inc.
Device Version: OpenCL 1.0 ATI-Stream-v2.1 (145)
Using default device[0]

Starting kernel...
Finished after 0 seconds.

0 Likes

okay, this is strange. all SDK samples are working. should check my linker and include settings.

thanks!

0 Likes