cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

fabtagon
Journeyman III

Tutorial "Hello World": includes unclean code/commands, gives error

two unclean issues in the tutorial, additionally I get an error with or without them

I started with the tutorial "Hello World" from http://developer.amd.com/GPU/ATISTREAMSDK/pages/TutorialOpenCL.aspx .

 

First, there are two unclean issues in the tutorial:

i) using gcc for C++

Eventhough we are about to compile C++ code the tutorial tells us to compile using

gcc –o hello_world –Ipath-OpenCL-include –Lpath-OpenCL-libdir lesson1.cpp –lOpenCL


gcc compiles only C code. g++ is responsible for C++. (gcc sometimes works with C++ code under weird circumstances, but generally will result in weird errors)

 

ii) type missmatch in parameter of getInfo()

(At least in the current version) cl::Platform::getInfo expects its' second argument to be of type cl::string. In the tutorial it is std::string (resulting in compile error).

 

iii) no compute devices found

While these are just not very suitable for a tutorial intented for beginner, the next one looks like a real problem:

When running I get

ERROR: cl::Platform::get (-1)


This means the very first OpenCL call in the code cl::Platform::get() fails to find any suitable compute device.

Does anybody have an idea what could cause the problem or how to further investigate it?

 

System:

  • Ubuntu 9.10 AMD64
  • ATI Catalyst 10.2 (glx and compiz enabled and working)
  • ATI Stream SDK 2.01-lnx64
  • AMD Phenom II 905e
  • ATI Radeon HD 4350

edits: markup fixes

 

#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; cl::string platformVendor; platformList[0].getInfo(CL_PLATFORM_VENDOR, &platformVendor); std::cerr << "Platform is by: " << platformVendor.c_str() << "\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, "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]; }

0 Likes
4 Replies
nou
Exemplar

did other samples from SDK work? did you registry ICD?

0 Likes

The CAL samples do work. The OpenCL samples do not.

After your hint I've registered the ICD accordingly to http://www.khronos.org/registry/cl/extensions/khr/cl_khr_icd.txt . However the ATI Stream OpenCL applications do not try to use this extension (checked via strace that there is not even a try to open any file under /etc/OpenCL/...) and the problem persists.

edit: ICD

0 Likes

fabtagon, 

Release notes explain how to register ICD.

Here are the steps to follow

1. Create /usr/lib/OpenCL/vendors folder, if does not already exist.

2.symlink [INSTALLDIR]/lib/x86/libatiocl32.so into the vendors folder:

sudo ln -sf [INSTALLDIR]/lib/x86/libatiocl32.so /usr/lib/OpenCL/vendors/libatiocl32.so

For 64-bit installations, you must also symlink [INSTALLDIR]/lib/x86_64/libatiocl64.so

to the vendors folder:

sudo ln -sf [INSTALLDIR]/lib/x86_64/libatiocl64.so /usr/lib/OpenCL/vendors/libatiocl64.so



0 Likes

Thank you very much for your reply! It's now working as expected.

(I am wondering why this is hidden in the release notes instead of being included in the installation guide)

0 Likes