Illegal Memory Access on cudaDeviceSynchronize

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 12:59:34
Robert Crovella

I think it's likely that in-kernel new is failing, because you are allocating too much memory.

In-kernel new has similar behavior and limitations as in-kernel malloc. These allocations are limited to the device heap, which starts out by default at 8MB. If the 250x250 array size corresponds to something in that range (8MB), then going significantly above that would cause some of the new operations to "silently" fail (i.e. return null pointers). If you then try to use those null pointers, you'll get an illegal memory access.

A few recommendations:

  1. Figure out how much space you need, and pre-reserve it ahead of time on the device heap using cudaDeviceSetLimit(cudaLimitMallocHeapSize, size_t size)
  2. When you're having trouble with kernels that use new or malloc, it may be useful for debug purposes to perhaps use a debug macro to check the returned pointers for NULL. This is a good practice in general.
  3. You can learn how to debug an illegal memory access with more clarity (localizing it to a specific line in a specific kernel) using the method described here.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!