Using virtual functions in CUDA kernels
Asked Answered
T

1

3

So I want to allocate an object with virtual functions on the device, then call a kernel and execute some of those virtual functions. I have tried two ways to do this but neither work:

1) Allocate and copy the object from the host using cudaMalloc and cudaMemcpy. This copies over the virtual function table that contains host memory pointers which obviously crash the kernel when executing on the device.

2) Allocate the object from a second kernel, save the device memory pointer to the object and pass that pointer to the original kernel. However, since the kernels are different, the functions are not in the same places in device memory upon kernel execution and the virtual function table is incorrect and crashes the kernel when used.

Can I only use virtual functions with objects created in the kernel the functions are called from?

Can I somehow reference the original kernel when I allocate my objects to get the virtual function table right?

Do I even understand what the actual problem is here?

Transom answered 19/4, 2011 at 21:29 Comment(1)
There is a newer question that this duplicates, which I have answered. Voting to close this one since the OP has not visited SO since April 2011.Jamisonjammal
D
1

Do I even understand what the actual problem is here?

Part of it.

As you experimented C++ in cuda is not fully supported. Only Starting from 4.0 you can use the virtual function.

  1. Make sure you have the 4.0 driver / api.

  2. Post your Error log.

Day answered 19/4, 2011 at 23:6 Comment(1)
Sorry, I am using 4.0, and I have a compute capability 2.1 card. A virtual function call works exactly as it should if I allocate the object and then call the function within the same kernel. It's only going across kernels that I have a problem. I don't get an error log, the kernel just dumps out without printing the things it's supposed to print. I haven't looked too much into the error codes or anything it may be producing.Transom

© 2022 - 2024 — McMap. All rights reserved.