Since I suspect that the black box (GPU) does not close clean in some larger code ( others, perhaps, too ), I would include cudaDeviceReset() at the end of main() . But wait! This will be a Segmentation fault all instances of classes statically created in main() with non-trivial CUDA code in destructors, right? For instance.
class A { public: cudaEvent_t tt; cudaEvent_t uu; A() { cudaEventCreate(&tt); cudaEventCreate(&uu); } ~A(){ cudaEventDestroy(tt); cudaEventDestroy(uu); } };
is created statically:
int main() { A t; cudaDeviceReset(); return 0; }
segfaults on exit. Question: perhaps cudaDeviceReset() is called automatically when exiting main() ?
Otherwise, all the useful main() code should be offset by some run() , and cudaDeviceReset() should be the last command in main() , right?
source share