Hello World program

Discussion created by sine on Jun 20, 2010
Latest reply on Jun 23, 2010 by sine
Hello World with the SDK 2.1 on Linux


The HelloCL from sample files works correctly, and I tested successfully a few other with --device cpu.

Following the tutorial for the latest SDK ( ). I tried to compile the Hello World program. I get the following error:

$ g++ -o hello_world -I/usr/local/ati-stream-sdk-v2.1-lnx32/include/ -L/usr/local/ati-stream-sdk-v2.1-lnx32/lib/ test.cpp -lOpenCL
test.cpp: In function ‘int main()’:
test.cpp:35: error: no matching function for call to ‘cl:latform::getInfo(int, std::string*)’
/usr/local/ati-stream-sdk-v2.1-lnx32/include/CL/cl.hpp:1388: note: candidates are: cl_int cl:latform::getInfo(cl_platform_info, cl::STRING_CLASS*) const
test.cpp: At global scope:
test.cpp:112: error: expected constructor, destructor, or type conversion before ‘char’
test.cpp:113: error: expected constructor, destructor, or type conversion before ‘void’


The details of the platform are as follows:

$ uname -a
Linux office #1 SMP Tue Apr 27 20:38:56 EDT 2010 i686 Intel(R) Core(TM)2 CPU          4400  @ 2.00GHz GNU/Linux
$  gcc --version
gcc (GCC) 4.4.1


SDK is installed in /usr/local/ati-stream-sdk-v2.1-lnx32

LD_LIBRARY_PATH includes /usr/local/ati-stream-sdk-v2.1-lnx32/lib/x86

Could anyone please correct the code or any other mistake please?





#include <utility> #define __NO_STD_VECTOR // Use cl::vector and cl::string and #define __NO_STD_STRING // not STL versions, more on this later #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) { if (err != CL_SUCCESS) { std::cerr << "ERROR: " << name << " (" << err << ")" << std::endl; exit(EXIT_FAILURE); } } int main(void) { 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_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, "Conext::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(""); checkErr(file.is_open() ? CL_SUCCESS:-1, ""); 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 =,""); 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, "ComamndQueue::enqueueNDRangeKernel()"); event.wait(); err = queue.enqueueReadBuffer( outCL, CL_TRUE, 0, hw.length()+1, outH); checkErr(err, "ComamndQueue::enqueueReadBuffer()"); std::cout << outH; return EXIT_SUCCESS; } #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]; }