Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/cuda/src/lib/include/diderot/gpu-select.cuh
ViewVC logotype

Diff of /branches/cuda/src/lib/include/diderot/gpu-select.cuh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5634, Wed Sep 15 21:02:20 2021 UTC revision 5635, Wed Sep 15 21:12:51 2021 UTC
# Line 35  Line 35 
35              std::cerr << "Error: No CUDA GPUs found." << std::endl;              std::cerr << "Error: No CUDA GPUs found." << std::endl;
36              exit(1);              exit(1);
37          }          }
38            int defaultGpuIdx;
39            cudaGetDevice(&defaultGpuIdx);
40          if (!validGpuId && interactive) {          if (!validGpuId && interactive) {
41              std::cout << "Available GPUs:" << std::endl;              std::cout << "Available GPUs:" << std::endl;
42              std::cout << "| id | name | memory | max grid | max threads per block |\n";              std::cout << "| id | name | memory | max grid | max threads per block |\n";
# Line 61  Line 63 
63              } while (gpuIdx <= 0 || gpuIdx >= devicesCount);              } while (gpuIdx <= 0 || gpuIdx >= devicesCount);
64          }          }
65          validGpuId = gpuIdx >= 0 && gpuIdx <= devicesCount;          validGpuId = gpuIdx >= 0 && gpuIdx <= devicesCount;
66            cudaError_t gpuSelectionErr = cudaSuccess;
67          if (validGpuId) {          if (validGpuId) {
68              cudaDeviceProp deviceProperties{};              cudaDeviceProp deviceProperties{};
69              cudaGetDeviceProperties(&deviceProperties, gpuIdx);              cudaGetDeviceProperties(&deviceProperties, gpuIdx);
# Line 70  Line 73 
73                  return;                  return;
74              }              }
75              std::cout << "Set GPU to: " << deviceProperties.name << " (id:" << gpuIdx << ")" << std::endl;              std::cout << "Set GPU to: " << deviceProperties.name << " (id:" << gpuIdx << ")" << std::endl;
76              cudaSetDevice(gpuIdx);              gpuSelectionErr = cudaSetDevice(gpuIdx);
77          } else if (devicesCount > 1) { // No need to display selection when signle GPU              if (gpuSelectionErr == cudaErrorDeviceAlreadyInUse) {
78                    std::cerr << "Warning: GPU already in use - falling back to default" << std::endl;
79                } else if (gpuSelectionErr == cudaErrorInvalidDevice) { // Should technically not happen
80                    std::cerr << "Warning: GPU invalid - falling back to default" << std::endl;
81                }
82            }
83            if ((!validGpuId || gpuSelectionErr != cudaSuccess) &&
84                devicesCount > 1) { // No need to display selection when single GPU
85              cudaDeviceProp deviceProperties{};              cudaDeviceProp deviceProperties{};
86              cudaGetDeviceProperties(&deviceProperties, 0);              cudaGetDeviceProperties(&deviceProperties, defaultGpuIdx);
87              std::cout << "Using default GPU: " << deviceProperties.name << std::endl;              std::cout << "Using default GPU: " << deviceProperties.name << " (id:" << defaultGpuIdx << ")" << std::endl;
88              cudaSetDevice(0);              gpuSelectionErr = cudaSetDevice(defaultGpuIdx);
89                if (gpuSelectionErr == cudaErrorDeviceAlreadyInUse) {
90                    std::cerr << "Error: Default/Fallback GPU already in use" << std::endl;
91                    exit(1);
92                } else if (gpuSelectionErr == cudaErrorInvalidDevice) { // Should technically not happen
93                    std::cerr << "Warning: Default/Fallback GPU invalid" << std::endl;
94                    exit(1);
95                }
96          }          }
97      }      }
98  };  };

Legend:
Removed from v.5634  
changed lines
  Added in v.5635

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0