Safe exit checking for CUDA applications under windows. In application you

could use the following for safe exit checking. 

#ifdef _WIN32
//Jason: Safe exit check macro to play nicer with Cuda & MS-CRT
 #ifdef USE_CUDA 
  #define SAFE_EXIT_CHECK  do { \
   if (worker_thread_exit_request) { \
      fprintf(stderr,"-> Worker received exit request, syncing Cuda...");
cudaThreadSynchronize(); fprintf(stderr,"Done.\n"); \
      fprintf(stderr,"  Worker Freeing Cuda data..."); cudaAcc_free();
fprintf(stderr,"Done.\n"); \
      fprintf(stderr,"  Worker Acknowledging exit request, spinning->\n");
worker_thread_exit_ack = true; \
      while (1) Sleep(10); \
   } \
  } while (0);
 #else
  #define SAFE_EXIT_CHECK  do { \
   if (worker_thread_exit_request) { \
      fprintf(stderr,"  Worker Acknowledging exit request, spinning-> ");
worker_thread_exit_ack = true; \
      while (1) Sleep(10); \
   } \
  } while (0);
 #endif
#else  // Linux or other probably have their own safe exit handling, defined as
blank, do nothing
 #define SAFE_EXIT_CHECK
#endif
 
and install at the top of the cffft loop, and more locations if desired:
  SAFE_EXIT_CHECK;

I'd like to implement these as BOINC API functions, but have not yet done so.



svn path=/trunk/boinc/; revision=23646
This commit is contained in:
Eric J. Korpela 2011-06-07 01:46:14 +00:00
parent 4d74982131
commit e9ecb9c04a
2 changed files with 25 additions and 1 deletions

View File

@ -164,6 +164,9 @@ static HANDLE hSharedMem;
HANDLE worker_thread_handle;
// used to suspend worker thread, and to measure its CPU time
DWORD timer_thread_id;
//Jason: New windows exit handling to play more nicely with cuda & MS-CRT
volatile bool worker_thread_exit_request = false;
volatile bool worker_thread_exit_ack = false;
#else
static volatile bool worker_thread_exit_flag = false;
static volatile int worker_thread_exit_status;
@ -654,7 +657,22 @@ void boinc_exit(int status) {
BOINCINFO("Exit Status: %d", status);
fflush(NULL);
#if defined(_WIN32)
#if defined(_WIN32)
//Jason: Windows exit handling to play nicer with cuda & MS-CRT
worker_thread_exit_request = true;
fprintf(stderr,"boinc_exit(): requesting safe worker shutdown ->\n");
int exitcounter = 0;
while ( !worker_thread_exit_ack && exitcounter < 20 )
{
Sleep(100);
exitcounter++;
}
if (worker_thread_exit_ack)
fprintf(stderr,"boinc_exit(): received safe worker shutdown acknowledge ->\n");
else
fprintf(stderr,"boinc_exit(): worker didn't respond to exit request within 2 seconds, exiting anyway.\n");
fflush(NULL);
// ... Continue original nasty exit code here
// Halt all the threads and cleans up.
TerminateProcess(GetCurrentProcess(), status);
// note: the above CAN return!

View File

@ -119,6 +119,12 @@ extern int setMacPList(void);
extern int setMacIcon(char *filename, char *iconData, long iconSize);
#endif
#ifdef _WIN32
//Jason: New windows exit handling to play more nicely with cuda & MS-CRT
extern volatile bool worker_thread_exit_request;
extern volatile bool worker_thread_exit_ack;
#endif
#ifdef __cplusplus
} // extern "C" {
#endif