How to I pass the class to kernel?

5 views
Skip to first unread message

will

unread,
Jul 13, 2009, 2:06:57 AM7/13/09
to CuPP
If I have a class , how to I pass it to kernel?

Can give a example ?

Jens

unread,
Jul 14, 2009, 8:22:43 AM7/14/09
to CuPP
Here is a quick and dirty example:

struct test_device {
int *arr;
};

class test {
int *arr;
int *arr_device;

public:
typedef test_device device_type;
typedef test host_type;

test() {
arr = new int[100];
arr_device = 0;
}

~test() {
delete[] arr;
cupp::free (arr_device);
}


device_type transform(const cupp::device &d) {
arr_device = cupp::malloc<int>(100);
cupp::copy_host_to_device(arr_device, arr, 100);

test_device a;
a.arr = arr_device;
return a;
}
};

Write your kernel to expect the device type:

__global__ void global_function (test_device a)

and than just pass test object to the cupp::kernel call.

-Jens
Reply all
Reply to author
Forward
0 new messages