我看到 CUDA 不允许将具有虚函数的类传递到内核函数中。此限制是否有任何解决方法?
我真的很希望能够在内核函数中使用多态。
谢谢!
我想编写一些兼容主机和设备的函数,并根据代码是在设备上执行还是在主机上执行来更改执行.我正在尝试编写一个将在设备和主机上使用的类,并隐藏与用户的区别.
如果没有办法做到这一点,是否有人就如何实现这一目标提出建议?
即
__host__ __device__ void foo(){
bool executingOnHost = // how do I figure this out?
if( executingOnHost)
// do stuff using host pointers
else
// do stuff with device pointers
}
Run Code Online (Sandbox Code Playgroud) 我遇到一个非常奇怪的错误,因为我在运行特定大小的Heat 2D模拟时遇到"非法内存访问"错误,但如果运行完全相同的模拟,模拟运行良好,只需少量元素.
是否有理由增加数组的大小会导致此异常?我正在使用Titan Black GPU(6 GB内存),但我正在运行的模拟远不是那么大.我计算出我可以运行4000 x 4000模拟,但是如果我超过250 x 250就会出错.
我在设备上实例化模拟对象数组后立即发生错误.实例化代码如下:
template<typename PlaceType, typename StateType>
__global__ void instantiatePlacesKernel(Place** places, StateType *state,
void *arg, int *dims, int nDims, int qty) {
unsigned idx = blockDim.x * blockIdx.x + threadIdx.x;
if (idx < qty) {
// set pointer to corresponding state object
places[idx] = new PlaceType(&(state[idx]), arg);
places[idx]->setIndex(idx);
places[idx]->setSize(dims, nDims);
}
}
template<typename PlaceType, typename StateType>
Place** DeviceConfig::instantiatePlaces(int handle, void *argument, int argSize,
int dimensions, int size[], int qty) {
// add …Run Code Online (Sandbox Code Playgroud)