Raise an exception in a C CUDA extension

Hi there, I am programming a C CUDA extension to pytorch.

I want to check for some conditions within that code, and raise exceptions if these conditions are not satisfied.

I don’t see how to do that, could you please give me some pointers ?

thanks

Well, you cannot raise in CUDA device code and expect that to propagate to host C/Python before synchronization takes place.
That said, in cuda kernels you can use assert(condition);. On the host AT_CHECK(cond, "error message with ", mytensor.dims(), " dynamic content"); works.
rgrep in aten/src/ will find examples of either.

Best regards

Thomas

thanks a lot for the reply. I want to go for the AT_CHECK solution,

sorry for the stupid question, but could you please tell me which header I should include for this one ?

It’s defined in ATen/Error.h, but that should be automatically included from ATen/ATen.h .

Best regards

Thomas