PDA

View Full Version : Copying c++ classes for use in open CL



jazpearson
12-20-2012, 08:07 AM
I'm just starting out with open CL, so there's a number of issues / questions that i have.

My first question revolves around a list of 2-D points, for example in the following c++ class:



class Point2d
{
public:

double x, y;

Point2d(double ax=0, double ay=0);

};



So let's say i have an array of Point2D. How do i pass this information to the GPU? Can i pass my Point2d array directly (which i'm assuming not), or do i have to manipulate my array another way? If so, how?

I know you have to set up the platform, context, queues etc (not that i'm an expert on that, either).

Say for example i wanted to take an array of Point2d, and have the GPU translate or rotate each of the points, in what form do i pass the information? (i know that getting the gpu to do this sort of task is overkill, but it's to help me get my head round it).

Bilog
12-22-2012, 03:11 AM
The OpenCL C programming language is based on C99, and therefore has no support for C++ features and types. In particular, this means you cannot pass C++ objects to OpenCL.

For your specific example, you can just use the OpenCL built-in vector types, and they should do fine.

clint3112
01-08-2013, 07:35 AM
You could also define a struct for your point. but i think it would be the same as using float2 datatype. If you really need double precision you have to keep in mind that you have to check for double precision compability and load the extension for it.