rugnux --no-gpu: run on the CPU only, without touching CUDA, on a machine with a GPU
hide_gpus() in CUDAWrapper makes get_gpu_count() answer 0 without calling cudaGetDeviceCount, so every GPU decision in the process (indexer Auto -> FFTW, preprocessing/spot finding/decode, pre-scan, scaling engine, model validation, MR) takes the path it takes on a machine without a GPU, and no CUDA context is created. rugnux reads --no-gpu in main, ahead of the parser, because set_gpu_blocking_sync() already asks CUDA for the devices. The banner says 'CPU only (--no-gpu)'. The 'run it on the CPU' advice in the out-of-GPU-memory messages and in the install docs now names --no-gpu instead of CUDA_VISIBLE_DEVICES=. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
70276a69fe
commit
bfd715b64d
8 files changed
+53
-15
No files matched your search
@@ -80,6 +80,8 @@ int32_t get_gpu_count() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hide_gpus() {}
|
||||
|
||||
std::vector<std::string> get_gpu_names() {
|
||||
return {};
|
||||
}
|
||||
|
||||
+19
-4
@@ -18,7 +18,17 @@ inline void cuda_err(cudaError_t val) {
|
||||
throw JFJochException(JFJochExceptionCategory::GPUCUDAError, cudaGetErrorString(val));
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::atomic<bool> gpus_hidden{false};
|
||||
}
|
||||
|
||||
void hide_gpus() {
|
||||
gpus_hidden = true;
|
||||
}
|
||||
|
||||
int32_t get_gpu_count() {
|
||||
if (gpus_hidden)
|
||||
return 0;
|
||||
int device_count;
|
||||
cudaError_t val = cudaGetDeviceCount(&device_count);
|
||||
switch (val) {
|
||||
@@ -137,11 +147,13 @@ void set_gpu_blocking_sync() {
|
||||
// cudaSetDevice creates the device's context, serially, and on four cards that was most of a
|
||||
// second before the run had started. The function is taken from the driver at run time, so the
|
||||
// program does not link against it and still starts on a machine without one.
|
||||
// Without a device nothing is called at all: even cudaGetLastError() would load the driver.
|
||||
if (get_gpu_count() == 0)
|
||||
return;
|
||||
void *fn = nullptr;
|
||||
cudaDriverEntryPointQueryResult found{};
|
||||
if (get_gpu_count() == 0
|
||||
|| cudaGetDriverEntryPointByVersion("cuDevicePrimaryCtxSetFlags", &fn, 12000, cudaEnableDefault,
|
||||
&found) != cudaSuccess
|
||||
if (cudaGetDriverEntryPointByVersion("cuDevicePrimaryCtxSetFlags", &fn, 12000, cudaEnableDefault, &found)
|
||||
!= cudaSuccess
|
||||
|| found != cudaDriverEntryPointSuccess) {
|
||||
cudaGetLastError();
|
||||
return;
|
||||
@@ -175,10 +187,13 @@ void release_gpu_contexts() {
|
||||
}
|
||||
|
||||
void cuda_clear_error() {
|
||||
cudaGetLastError();
|
||||
if (!gpus_hidden) // hidden, nothing has used CUDA, and this call would still load the driver
|
||||
cudaGetLastError();
|
||||
}
|
||||
|
||||
void cuda_throw_if_context_lost() {
|
||||
if (gpus_hidden)
|
||||
return;
|
||||
// cudaFree(nullptr) frees nothing, but a lost context fails it. The last error cannot say the same:
|
||||
// once cudaGetLastError() has returned a sticky error, it and cudaPeekAtLastError() report success.
|
||||
const cudaError_t err = cudaFree(nullptr);
|
||||
|
||||
@@ -11,6 +11,12 @@
|
||||
|
||||
int32_t get_gpu_count();
|
||||
|
||||
// From here on get_gpu_count() is 0 without asking CUDA, so nothing in the process creates a context or
|
||||
// touches a device and every GPU path takes its CPU path, as on a machine without a GPU: what
|
||||
// CUDA_VISIBLE_DEVICES= does, asked for by the program (rugnux --no-gpu). Call it before anything uses
|
||||
// CUDA; there is no way back.
|
||||
void hide_gpus();
|
||||
|
||||
// Names of the visible GPUs, in device order and one entry per device, so repeated cards repeat.
|
||||
// Empty without CUDA and on a machine with no device, which is also what get_gpu_count() == 0 says.
|
||||
std::vector<std::string> get_gpu_names();
|
||||
|
||||
@@ -330,6 +330,7 @@ General:
|
||||
| `-e, --end-image <num>` | Last image to process (default: all) |
|
||||
| `-t, --stride <num>` | Process every *n*-th image (default: 1) |
|
||||
| `-v, --verbose` | Show the whole log on the terminal in place of the steps; `<prefix>_log.txt` is written either way |
|
||||
| `--no-gpu` | Run on the CPU only, as on a machine without a GPU, even where one is present: CUDA is not touched and every GPU step takes its CPU path (`-X Auto` indexes with FFTW; `-X FFT` and `-X FFBIDX` are refused) |
|
||||
|
||||
Mode — `--mode <name>` (default `mx`):
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ fits and rigid-body placement of the validation and the rotation and translation
|
||||
molecular replacement. The CPU implementations are the path where there is no GPU, and the two agree
|
||||
to rounding rather than bit for bit (parts of the scaling and the model fits round differently
|
||||
on the card), so a GPU and a CPU run can differ in the last digits of the merged data. The choice is automatic;
|
||||
a CUDA build runs on the CPU when the GPU is hidden from it (`CUDA_VISIBLE_DEVICES= rugnux ...`).
|
||||
a CUDA build runs on the CPU when told to (`rugnux --no-gpu ...`).
|
||||
The thread count (`-N`) governs the CPU side of all of it.
|
||||
|
||||
The released CUDA builds need only an NVIDIA **driver** on the host, no CUDA toolkit: 525.60.13 or
|
||||
@@ -189,7 +189,7 @@ a big cell. One sweep of a crystal with an axis of about 640 Å predicted 236 mi
|
||||
peaked at **17.5 GB of host memory on a GPU build and 72.5 GB on a CPU-only build**. A CPU-only build
|
||||
keeps in host RAM what a GPU build keeps on the card, so it is the one that needs the large machine.
|
||||
When such a set is too large for GPU scaling on the card, the run stops and says to run it on the
|
||||
CPU (`CUDA_VISIBLE_DEVICES= rugnux ...`, or a CPU-only build) — which then wants that much host memory.
|
||||
CPU (`rugnux --no-gpu ...`, or a CPU-only build) — which then wants that much host memory.
|
||||
|
||||
### When host memory runs out
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ inline std::string GPUMemoryFailure(const char *what, size_t bytes, bool out_of_
|
||||
msg += buf;
|
||||
}
|
||||
return msg + ". Either another program is using this GPU, or this data set needs more GPU memory than "
|
||||
"the card has - free the GPU and run again, or run on the CPU (CUDA_VISIBLE_DEVICES= rugnux "
|
||||
"the card has - free the GPU and run again, or run on the CPU (rugnux --no-gpu "
|
||||
"..., or a CPU-only build)";
|
||||
}
|
||||
|
||||
|
||||
@@ -1127,7 +1127,7 @@ namespace {
|
||||
"Scaling %lld partial observations needs more GPU memory than this card has: %.1f GB for "
|
||||
"their per-observation arrays alone (%zu bytes each), before the merge's other buffers, "
|
||||
"on a %.1f GB card. This data set is too large for GPU scaling on this card - run it on "
|
||||
"the CPU (CUDA_VISIBLE_DEVICES= rugnux ..., or a CPU-only build) on a machine with plenty of "
|
||||
"the CPU (rugnux --no-gpu ..., or a CPU-only build) on a machine with plenty of "
|
||||
"host memory: the CPU path keeps all of it in RAM, which for a set this large can be "
|
||||
"tens of GB",
|
||||
static_cast<long long>(n_obs), double(n_obs) * OBS_BYTES / 1e9, OBS_BYTES,
|
||||
@@ -1146,7 +1146,7 @@ namespace {
|
||||
"Scaling %lld partial observations ran out of GPU memory: a buffer of %.1f MB did not fit, "
|
||||
"with %.1f GB of the %.1f GB card free (the per-observation arrays take %.1f GB). Either "
|
||||
"another program is using this GPU, or this data set is too large for GPU scaling on this "
|
||||
"card - run it on the CPU (CUDA_VISIBLE_DEVICES= rugnux ..., or a CPU-only build) on a "
|
||||
"card - run it on the CPU (rugnux --no-gpu ..., or a CPU-only build) on a "
|
||||
"machine with plenty of host memory",
|
||||
static_cast<long long>(n_obs), double(bytes) / 1e6, double(free_bytes) / 1e9,
|
||||
double(total_bytes) / 1e9, double(n_obs) * OBS_BYTES / 1e9);
|
||||
@@ -1162,7 +1162,7 @@ namespace {
|
||||
snprintf(msg, sizeof(msg),
|
||||
"GPU busy: scaling %lld partial observations waited %lld minutes for GPU work running "
|
||||
"beside it in this process to give back its memory, and it did not. The data set fits "
|
||||
"this card; run it again, or on the CPU (CUDA_VISIBLE_DEVICES= rugnux ...)",
|
||||
"this card; run it again, or on the CPU (rugnux --no-gpu ...)",
|
||||
static_cast<long long>(n_obs),
|
||||
static_cast<long long>(std::chrono::duration_cast<std::chrono::minutes>(GPU_BUSY_TIMEOUT).count()));
|
||||
throw JFJochException(JFJochExceptionCategory::GPUCUDAError, msg);
|
||||
|
||||
+19
-5
@@ -118,6 +118,8 @@ void print_usage() {
|
||||
"(debug level); an empty prefix writes nothing at all" << std::endl;
|
||||
std::cout << " -N, --threads <num> Number of threads (default: every CPU the run may use - its affinity and cgroup quota - of which the "
|
||||
"per-image loop uses at most 16 per GPU; an explicit value is used as given)" << std::endl;
|
||||
std::cout << " --no-gpu Run on the CPU only, as on a machine without a GPU: CUDA is not "
|
||||
"touched and every GPU step takes its CPU path (-X Auto indexes with FFTW)" << std::endl;
|
||||
std::cout << " -s, --start-image <num> Start image number (default: 0)" << std::endl;
|
||||
std::cout << " -e, --end-image <num> End image number (default: all)" << std::endl;
|
||||
std::cout << " -t, --stride <num> Image stride (default: 1)" << std::endl;
|
||||
@@ -318,6 +320,7 @@ enum {
|
||||
OPT_FINALIST_LEDGER,
|
||||
OPT_SIMULATE_LIVE,
|
||||
OPT_DEVELOPER,
|
||||
OPT_NO_GPU,
|
||||
OPT_FORCE_STILL,
|
||||
OPT_AZIM_MIN_Q,
|
||||
OPT_AZIM_MAX_Q,
|
||||
@@ -375,6 +378,7 @@ static option long_options[] = {
|
||||
{"finalist-ledger", no_argument, nullptr, OPT_FINALIST_LEDGER},
|
||||
{"simulate-live", required_argument, nullptr, OPT_SIMULATE_LIVE},
|
||||
{"developer", no_argument, nullptr, OPT_DEVELOPER},
|
||||
{"no-gpu", no_argument, nullptr, OPT_NO_GPU},
|
||||
{"smooth-g", optional_argument, nullptr, OPT_SMOOTH_G},
|
||||
{"relative-b", optional_argument, nullptr, OPT_RELATIVE_B},
|
||||
{"no-scaling-corrections", no_argument, nullptr, OPT_NO_SCALING_CORRECTIONS},
|
||||
@@ -852,7 +856,7 @@ extern "C" void fftwf_assertion_failed(const char *s, int line, const char *file
|
||||
// cannot reject on its own (a resolution limit of zero, a distance of zero, a polarisation above one,
|
||||
// an unreadable file), so main wraps this and reports rather than letting the exception terminate the
|
||||
// process with no diagnostic and exit code 134.
|
||||
static int RunRugnux(int argc, char **argv) {
|
||||
static int RunRugnux(int argc, char **argv, bool no_gpu) {
|
||||
// The whole invocation, reported at the end and written into the results report. Started before
|
||||
// anything else so it covers reading the file and setting up as well as the processing.
|
||||
const auto invocation_start = std::chrono::steady_clock::now();
|
||||
@@ -898,8 +902,8 @@ static int RunRugnux(int argc, char **argv) {
|
||||
: fmt::format(" (git {} {})", jfjoch_git_sha1().substr(0, 6), jfjoch_git_date()), build);
|
||||
logger.Info("Build flags: {}", jfjoch_build_cxx_flags().empty() ? "none" : jfjoch_build_cxx_flags());
|
||||
logger.Info("Command line: {}", provenance.command_line);
|
||||
logger.Info("GPU: {}", provenance.gpu_count > 0
|
||||
? fmt::format("{} ({} visible)", provenance.gpu_description, provenance.gpu_count)
|
||||
logger.Info("GPU: {}", no_gpu ? std::string("not used (--no-gpu) - running on the CPU")
|
||||
: provenance.gpu_count > 0 ? fmt::format("{} ({} visible)", provenance.gpu_description, provenance.gpu_count)
|
||||
: std::string("none visible - running on the CPU"));
|
||||
RegisterHDF5Filter();
|
||||
|
||||
@@ -1361,6 +1365,8 @@ static int RunRugnux(int argc, char **argv) {
|
||||
case OPT_DEVELOPER:
|
||||
provenance.developer = true;
|
||||
break;
|
||||
case OPT_NO_GPU: // acted on in main, before anything asks CUDA for the devices
|
||||
break;
|
||||
case OPT_SMOOTH_G:
|
||||
smooth_g_deg_arg = optarg ? parse_double_arg(optarg, "--smooth-g", logger) : SMOOTH_G_DEFAULT_DEG;
|
||||
break;
|
||||
@@ -1639,7 +1645,8 @@ static int RunRugnux(int argc, char **argv) {
|
||||
// Said before the run rather than after it: the GPUs are what makes rugnux fast, and a machine
|
||||
// that turns out to have none - a driver mismatch, a CUDA_VISIBLE_DEVICES left over from another
|
||||
// job - is worth knowing about while there is still time to stop and fix it.
|
||||
console->Field("Compute", provenance.gpu_count > 0
|
||||
console->Field("Compute", no_gpu ? fmt::format("CPU only (--no-gpu), {} threads", nthreads)
|
||||
: provenance.gpu_count > 0
|
||||
? fmt::format("{}{}, {} threads", provenance.gpu_count > 1 ? fmt::format("{} x ", provenance.gpu_count) : "",
|
||||
provenance.gpu_description, nthreads)
|
||||
: fmt::format("no GPU visible - {} CPU threads, which is much slower", nthreads));
|
||||
@@ -3297,9 +3304,16 @@ int main(int argc, char **argv) {
|
||||
// Before anything creates a CUDA context, which fixes the flags for the device. A thread
|
||||
// waiting on the GPU then sleeps instead of spinning on a core - measured on a 16M rotation
|
||||
// run, a fifth of all CPU time went to that spinning, with no change in wall time either way.
|
||||
// --no-gpu is looked for here, ahead of the parser, because that already asks CUDA for the devices.
|
||||
bool no_gpu = false;
|
||||
for (int i = 1; i < argc; i++)
|
||||
if (std::strcmp(argv[i], "--no-gpu") == 0)
|
||||
no_gpu = true;
|
||||
if (no_gpu)
|
||||
hide_gpus();
|
||||
set_gpu_blocking_sync();
|
||||
enable_gpu_numa_binding();
|
||||
const int ret = RunRugnux(argc, argv);
|
||||
const int ret = RunRugnux(argc, argv, no_gpu);
|
||||
// Everything that used a card has been destroyed with the run.
|
||||
release_gpu_contexts();
|
||||
return ret;
|
||||
|
||||
Reference in new issue
Block a user