Don't initialize CUDA before fork in Charm++ startup 44/4244/1
authorJim Phillips <jim@ks.uiuc.edu>
Wed, 6 Jun 2018 03:47:21 +0000 (22:47 -0500)
committerJim Phillips <jim@ks.uiuc.edu>
Wed, 6 Jun 2018 03:47:21 +0000 (22:47 -0500)
Change-Id: I0c5377628b1bac2a1bca4f5db9b83167b1c04d8f

src/CudaUtils.C
src/DeviceCUDA.C

index 837ecab..ea63c41 100644 (file)
@@ -36,6 +36,11 @@ void cudaNAMD_bug(const char *msg) {NAMD_bug(msg);}
 
 void cuda_affinity_initialize() {
   // called before Converse/Charm++ initialization so can't use Cmi/Ck utilities
+  char *forkstr;
+  forkstr=getenv("CmiMyForks");
+  int forks = 0;
+  if (forkstr) sscanf(forkstr,"%d",&forks);
+  if ( forks ) return;  // CUDA will fail on child if initialized before fork
   int devcnt = 0;
   cudaError_t err = cudaGetDeviceCount(&devcnt);
   if ( devcnt == 1 ) {  // only one device so it must be ours
index 60f36a2..da91152 100644 (file)
@@ -337,7 +337,12 @@ void DeviceCUDA::initialize() {
 
   {
     // if only one device then already initialized in cuda_affinity_initialize()
-    if ( deviceCount > 1 ) cudaCheck(cudaSetDeviceFlags(cudaDeviceMapHost));
+    cudaError_t cudaSetDeviceFlags_cudaDeviceMapHost = cudaSetDeviceFlags(cudaDeviceMapHost);
+    if ( cudaSetDeviceFlags_cudaDeviceMapHost == cudaErrorSetOnActiveProcess ) {
+      cudaGetLastError();
+    } else {
+      cudaCheck(cudaSetDeviceFlags_cudaDeviceMapHost);
+    }
 
     int dev;
     cudaCheck(cudaGetDevice(&dev));