1

I'm new to CUDA programming. In serial code I often have a function that I use for gracefully exiting code after an error occurs. E.g.

void exit_with_error(char * message){
  fprintf(stderr, "%s", message);
  fflush(stderr);
  exit(1);
}

QUESTION : Is there a clean way to do that in the device code using CUDA 8.0?

I'm looking for something similar to what you can do in MPI. So if one thread on the GPU device encounters an 'error' (e.g. a conditional that should never be true), it

  1. prints the error

  2. sends a signal to all other threads to exit (possibly flushing their stdout/stderr buffers).

  3. program terminates.

talonmies
  • 70,661
  • 34
  • 192
  • 269
irritable_phd_syndrome
  • 4,631
  • 3
  • 32
  • 60
  • you want this?https://stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api – Ander Biguri Aug 31 '18 at 13:47
  • No. That is used in the host code. I want a way to force program termination if a single thread encounters a condition that I think should never happen. E.g. `if(A>B){exit_program_now()}` – irritable_phd_syndrome Aug 31 '18 at 13:50
  • Not sure if in newer versions is possible, it was not in 2011: https://stackoverflow.com/questions/5114449/cuda-how-to-assert-in-kernel-code – Ander Biguri Aug 31 '18 at 13:52
  • 2
    its not possible. Termination of a host thread must be accomplished by host code. – Robert Crovella Aug 31 '18 at 13:54

1 Answers1

3

This is not possible. CUDA device code cannot cause termination of a host thread or process.

Termination of a host thread must be accomplished by host code.

Robert Crovella
  • 143,785
  • 11
  • 213
  • 257