我遵循了这个问题和这个链接提供的指导,这些指导涉及将指针数组传递到设备并返回的概念,但当指针指向一个对象时,我似乎正在努力解决我的特定情况。请参阅下面的示例代码,为简洁起见,我删除了错误检查。
// Kernel
__global__ void myKernel(Obj** d_array_of_objs)
{
// Change the scalar of each object to 5
// by dereferencing device array to get
// appropriate object pointer.
*d_array_of_objs->changeToFive(); <--------- SEE QUESTION 4
}
// Entry point
int main()
{
/********************************/
/* INITIALISE OBJ ARRAY ON HOST */
/********************************/
// Array of 3 pointers to Objs
Obj* h_obj[3];
for (int i = 0; i < 3; i++) {
h_obj[i] = new Obj(); // Create
h_obj[i]->scalar = i …Run Code Online (Sandbox Code Playgroud)