Hi alltogether,

as I am writing to this board I am quite new to programming with OpenCL - I recently made some attempts to get some C++ sample Code from the tutorials compiled under MacOS X SnowLeopard but unfortunatetly none of them succeeded.

The main problem is that the normal way to include the openCL framework headers which is described in the tutorials (use #include OpenCL/opencl.h) does not work on my system.
The only place the header files are located is /System/Library/Frameworks/OpenCL.framework/Versions/A/Headers/ which is not in the search path assumed - I tried to fix that by switching
to the commandline interface , using the -I and -L switches in combination with the "-framework opencl" option - but this did not work either. The error message always follows the pattern:
firstCL.cpp: In function ‘int main()’:
firstCL.cpp:28: error: ‘cl’ has not been declared
firstCL.cpp:28: error: ‘cl’ has not been declared
firstCL.cpp:28: error: ‘platformList’ was not declared in this scope
firstCL.cpp:29: error: ‘Platform’ has not been declared
firstCL.cpp:39: error: ‘cl’ has not been declared
firstCL.cpp:39: error: expected `;' before ‘context’
firstCL.cpp:46: error: ‘cl’ has not been declared
firstCL.cpp:46: error: ‘cl’ has not been declared
firstCL.cpp:46: error: ‘devices’ was not declared in this scope
firstCL.cpp:47: error: ‘context’ was not declared in this scope

what in my interpretation means that the cl:: namespace qualifier is not found in that context

Did anybody run into the same problem and can give me some guidance how to proceed from here.
Do I ,for example, have to install a certain package - c++ bindings ?
the code I am using for testing follows below.

Best regards + many thanks in advance
Stefan


#include <stdlib.h>
#include <math.h>
#include <OpenCL/opencl.h>

int main (int argc, const char * argv[]) {

// some code

cl_device_id device_id; //declaring a device id gives no errors

int err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);

// insert code here...
printf("Hello, World!\n");
printf("Device ID is : %s", device_id);
printf(" err is %d", err);

return 0;
}
*/

#include <utility>

#define __NO_STD_VECTOR // Use cl::vector instead of STL version
#include <OpenCL/opencl.h>

#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;
vector< cl::Platform > platformList;
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, "Conext::Context()");
cl::vector<cl:evice> 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];
}