cudaMalloc - Array of pointers.

Hi,
I have a class Object and a class Sphere that inherit Object. Here’s what I have in host memory:
vector<Sphere*> spheres;

I want to take this vector to device memory as an array of Object pointers. I tried everything, but I couldn’t get it work. At the moment I have this:

Object objectsDev;
Object objectDev;
numObjects = spheres.size();
cudaMalloc((void
)&objectsDev, numObjectssizeof(Object));
pos = 0;
for(int i = 0; i < spheres.size(); i++, pos++)
{
cudaMalloc((void
*)&objectDev, sizeof(spheres[i]));
cudaMemcpy(objectDev, &spheres[i], sizeof(spheres[i]), cudaMemcpyHostToDevice);
cudaMemcpy(&objectsDev[pos], &objectDev, sizeof(Sphere*), cudaMemcpyDeviceToDevice);
}

Any idea?

Hi,
I have a class Object and a class Sphere that inherit Object. Here’s what I have in host memory:
vector<Sphere*> spheres;

I want to take this vector to device memory as an array of Object pointers. I tried everything, but I couldn’t get it work. At the moment I have this:

Object objectsDev;
Object objectDev;
numObjects = spheres.size();
cudaMalloc((void
)&objectsDev, numObjectssizeof(Object));
pos = 0;
for(int i = 0; i < spheres.size(); i++, pos++)
{
cudaMalloc((void
*)&objectDev, sizeof(spheres[i]));
cudaMemcpy(objectDev, &spheres[i], sizeof(spheres[i]), cudaMemcpyHostToDevice);
cudaMemcpy(&objectsDev[pos], &objectDev, sizeof(Sphere*), cudaMemcpyDeviceToDevice);
}

Any idea?

Hi.

I have a very similar problem to solve:

I need to have a lookUpTable in the device memory… the problem is, that on the host STL types are used.

Here’s what I have to get onto the graphics card:

tableEntry:

std::vector<std::vector<std::list<tableEntry> > >;

with:

struct tableEntry 

{

	unsigned int index;

	float weight;

};

extendedVertex:

std::vector<extendedVertex>;

with:

struct extendedVertex{

	float x;

	std::vector<float> f1;

	std::vector<Point> p1;

	std::vector<Point> p2;

	double dA;

	double d1[3];

	float y;

	[... some more floats here]

	unsigned int index;

};

and:

struct Point

{

	Point(unsigned int uiX, unsigned int uiY) {x = uiX; y = uiY;};

	Point(unsigned int uiX, unsigned int uiY, unsigned char ucChannel) {x = uiX; y = uiY; c = ucChannel;};

	Point() {x = 0; y = 0; c = 0;};

	unsigned int x;

	unsigned int y;

	unsigned char c;

};

So… I don’t have a clue, how to get this rebuilt with CUDA datatypes…

Any help and any hint is very appreciated :).

Thanks a lot!

Hi.

I have a very similar problem to solve:

I need to have a lookUpTable in the device memory… the problem is, that on the host STL types are used.

Here’s what I have to get onto the graphics card:

tableEntry:

std::vector<std::vector<std::list<tableEntry> > >;

with:

struct tableEntry 

{

	unsigned int index;

	float weight;

};

extendedVertex:

std::vector<extendedVertex>;

with:

struct extendedVertex{

	float x;

	std::vector<float> f1;

	std::vector<Point> p1;

	std::vector<Point> p2;

	double dA;

	double d1[3];

	float y;

	[... some more floats here]

	unsigned int index;

};

and:

struct Point

{

	Point(unsigned int uiX, unsigned int uiY) {x = uiX; y = uiY;};

	Point(unsigned int uiX, unsigned int uiY, unsigned char ucChannel) {x = uiX; y = uiY; c = ucChannel;};

	Point() {x = 0; y = 0; c = 0;};

	unsigned int x;

	unsigned int y;

	unsigned char c;

};

So… I don’t have a clue, how to get this rebuilt with CUDA datatypes…

Any help and any hint is very appreciated :).

Thanks a lot!

I’ve implemented a RayTracer using CUDA before http://www.cs264.org/projects/web/Patel_Krunal/index.html
forget anything to do with STL and stuff (though I’ve been told using STL in device is bad)…
The main problem you have is sizeof(Object) < sizeof(Sphere)…I’m assuming that and am probably right…so when you declare a device pointer to Object and then say that you will be storing Spheres, I think you are messing things up. If you refer to my code above you’ll figure things out…sorry can’t be more helpful than that…it’s been a while since I’ve touched CUDA…only getting back on it now since I’m implementing Text Mining on GPU

good luck

I’ve implemented a RayTracer using CUDA before http://www.cs264.org/projects/web/Patel_Krunal/index.html
forget anything to do with STL and stuff (though I’ve been told using STL in device is bad)…
The main problem you have is sizeof(Object) < sizeof(Sphere)…I’m assuming that and am probably right…so when you declare a device pointer to Object and then say that you will be storing Spheres, I think you are messing things up. If you refer to my code above you’ll figure things out…sorry can’t be more helpful than that…it’s been a while since I’ve touched CUDA…only getting back on it now since I’m implementing Text Mining on GPU

good luck

Thank you for yous reply. I’m working in a raytracing algorithm as well.

I think I didn’t explain clearly what is my problem with the spheres. I’m not using vector inside my kernel. I read the input and save the spheres in a vector. Then I alocate a sphere array in device memory to use in my kernel. But I also have another objects (triangles, boxes, etc) just like you have. But I couldn’t alocate a “Object **objects”. How can I alocate an sphere in device and keep its address in my Object array?

Thank you for yous reply. I’m working in a raytracing algorithm as well.

I think I didn’t explain clearly what is my problem with the spheres. I’m not using vector inside my kernel. I read the input and save the spheres in a vector. Then I alocate a sphere array in device memory to use in my kernel. But I also have another objects (triangles, boxes, etc) just like you have. But I couldn’t alocate a “Object **objects”. How can I alocate an sphere in device and keep its address in my Object array?