2

Is there a way to execute a statement inside the device code without raising CUDA error? Something looks like the following:

__global__ void myKernel(float* X1, float* X2, float* Y){
try{
    Y[0] = X1[0] / X2[0];
   }catch(){
    Y[0] = 0.0f;
    }
}

I know that we can check the value of X2[0] before division, but what If I want to execute the statement without checking for valid inputs, and execute it safely?

1 Answer 1

3

currently, CUDA device code does not support exception handling.

try/catch cannot be used in CUDA device code.

If a statement would cause a device side error (e.g. out-of-bounds access, for example), there is no way to execute that statement in device code without triggering the device side error.

To avoid the error, you would need to modify the statement, or conditionally not execute it, to avoid triggering the device side error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.