Nothrow with new CUDA

What's the best way to test for a successful memory allocation when used new

in a kernel call using CUDA? Is there something similar (nothrow)

if there is no way to continue kernel execution even if memory allocation fails?

Thank!

+3


source to share


1 answer


I don't think it is new

officially supported on the device side. Moreover, as far as I know, there is no device support, so annotations like this nothrow

have no effect.

What you can do in the kernel is call it malloc

. After failure, the function just returns NULL

and you can test it normally.

Note that

  • device side malloc

    is only supported on devices 2.0 (Fermi) and above.
  • By default, you only have 8MB of heap memory. If you want to have more, you need to set a higher limit through cudaDeviceSetLimit

    .


Further reading: CUDA C Programming Guide, v.5.0, Chapter B.17 - Dynamic Global Memory Allocation


Update: Tests have shown that it new

appears to be supported and appears to work the same, i.e. returns NULL

on failure.

+3


source







All Articles