title: Proper use of cudaDeviceReset()
body: <p>Since I'm having suspicions the "black box" (GPU) is not shutting down cleanly in some larger code (<a href="https://stackoverflow.com/questions/10294595/handling-ctrlc-exception-with-gpu">others perhaps too</a>), I would include a <code>cudaDeviceReset()</code> at the end of <code>main()</code>. But wait! This would <code>Segmentation fault</code> all instances of classes statically created in <code>main()</code> with non-trivial CUDA code in destructors, right? E.g.</p>
  
  <pre><code>class A {
  public:
    cudaEvent_t tt;
    cudaEvent_t uu;
    A() { 
      cudaEventCreate(&amp;tt);
      cudaEventCreate(&amp;uu);
    }
    ~A(){  
      cudaEventDestroy(tt);
      cudaEventDestroy(uu);
    }
  };
  </code></pre>
  
  <p>instantiated statically:</p>
  
  <pre><code>int main() {
    A t;
    cudaDeviceReset();
    return 0;
  } 
  </code></pre>
  
  <p>segfaults on exit. Question: is perhaps <code>cudaDeviceReset()</code> invoked automatically on exit from <code>main()</code>?</p>
  
  <p>Otherwise whole useful code of <code>main()</code> should be shifted to some <code>run()</code>, and <code>cudaDeviceReset()</code> should be the as last command in <code>main()</code>, right?</p>