What is the best way to check for successful allocation of memory when using new in a kernel call with CUDA? Is there anything similar to (nothrow) if there isn’t is there a way to continue execution of the kernel, even in the event of memory allocation failure?
Thanks!
I don’t think that
newis officially supported on the device-side. Moreover – to my knowledge – there is no support for exceptions on the device-side, so annotations likenothrowhave no effect.What you can do in the kernel is to call
malloc. Upon the failure the function just returnsNULLand you can check that normally.Do note that
mallocis supported only on devices 2.0 (Fermi) and higher.cudaDeviceSetLimit.Further reading: CUDA C Programming Guide, v.5.0, chapter B.17 – Dynamic Global Memory Allocation
Update: Tests have shown that
newseems to be supported and seems to be working the same way, i.e. returningNULLupon failure.