Cuda Newbie: what does CUDA_SAFE_CALL do?


i am new in this language an i’m trying to program a numerical method for physics. I would like to understand what is the difference between using CUDA_SAFE_CALL and not using it. Can anybody help? please! best regards, carlos.

It is an error checking macro from the SDK. Don’t use it.

Well, even if you don’t use it, you should check the return codes somehow…

Yep, like avidday said, it’s just for use with the SDK to help them write the demos a bit more easily. Don’t start using it in your own code though, because then you’ll get stuck with some crazy dependency issues down the road. If you’re just trying to understand the examples though, it basically calls whatever function it’s wrapping, checks the result code that’s returned, and “breaks” if that result is an error.

If you copy it into your own header file, the dependency problem can be avoided…

I actually think it’s a very useful macro - if you don’t want to come up with a proper error handling system (perhaps it’s early development, or a very short program), then wrapping up all the CUDA calls in CUDA_SAFE_CALL at least guarantees that GPU errors will get found. It’s not a solution for programs which have to fail gracefully, but CUDA_SAFE_CALL is much, much better than nothing.

Thank you everyone!
i will keep on investigating.

Yes, I also have copied it into headers in some of my apps, where the desired behavior really is “fail immediately if something bad happens and tell me why.” That is unacceptable for apps where your users are not also developers of the application, but it works for lots of data analysis kinds of situations.