diff --git a/CLAUDE.md b/CLAUDE.md index 218801403..3f430a2e5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -367,9 +367,12 @@ generated API model and internal types. (`beam_stop/ShadowFinder` is built and runs by default in `rugnux` — it is no longer the unbuilt prototype an older version of this file described). Least-squares refinement uses **Ceres** (fetched in `image_analysis/CMakeLists.txt`, built with miniglog, no MKL, no Ceres-CUDA, CXX_THREADS). -The indexer is chosen with `-X` (`FFBIDX|FFT|FFTW|Auto|None`, default `Auto`, which resolves to a +The indexer is chosen with `-X` (`Auto|FFT|cuFFT|FFTW|FFBIDX|None`, default `Auto`, which resolves to a GPU indexer when one is present and `fftw` otherwise): `ffbidx` wants a known cell (`-C`) and suits -sparse serial stills; `fft`/`fftw` index de novo and suit strong rotation data. +sparse serial stills; `fft` indexes de novo and suits strong rotation data - it is the algorithm, run +with cuFFT on a GPU and with FFTW without one (or under `--no-gpu`), while `cufft`/`fftw` name one +implementation each. Only rugnux's CLI spells it this way: internally (and in the broker's OpenAPI) +`FFT` is the GPU implementation, which the CLI's `cufft` maps onto. **FPGA** (`fpga/`): `hls/` is the Vitis HLS source (image-analysis kernels), `hls_simulation/` runs that same HLS on CPU for hardware-free testing, `hdl/` is the Verilog RTL, `host_library/` is diff --git a/docs/RUGNUX_ADVANCED.md b/docs/RUGNUX_ADVANCED.md index 5510b61c8..4b8e13ef8 100644 --- a/docs/RUGNUX_ADVANCED.md +++ b/docs/RUGNUX_ADVANCED.md @@ -330,7 +330,7 @@ General: | `-e, --end-image ` | Last image to process (default: all) | | `-t, --stride ` | Process every *n*-th image (default: 1) | | `-v, --verbose` | Show the whole log on the terminal in place of the steps; `_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) | +| `--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` and `-X FFT` index with FFTW; `-X cuFFT` and `-X FFBIDX` are refused) | Mode — `--mode ` (default `mx`): @@ -408,7 +408,7 @@ For very long axes the direction grid's angular resolution binds well below 500 | Option | Description | | --- | --- | | `--force-still` | Treat a rotation (goniometer) dataset as independent stills instead of rotation | -| `-X, --indexing-algorithm ` | `FFBIDX` \| `FFT` \| `FFTW` \| `Auto` \| `None` | +| `-X, --indexing-algorithm ` | `Auto` (default) \| `FFT` \| `cuFFT` \| `FFTW` \| `FFBIDX` \| `None`, case-insensitive. `FFT` is the de-novo FFT search, on the GPU (cuFFT) where there is one and `--no-gpu` is not given, otherwise on the CPU (FFTW); `cuFFT` and `FFTW` name one implementation each. `cuFFT` and `FFBIDX` (known cell, `-C`) need a GPU and are refused without one. `Auto` takes `FFBIDX` on stills with a known cell and a GPU, and `FFT` otherwise; rotation data always use the FFT search | | `-C, --unit-cell ` | Reference unit cell `"a,b,c,alpha,beta,gamma"` (required by `ffbidx`). On rotation data it also widens the FFT search to cover the cell given, at both ends: the longest axis looked for is raised to reach it, and `--fft-min-unit-cell` is lowered to admit it | | `--fft-min-unit-cell ` | Shortest cell axis the FFT search accepts, Å (default: 10). A candidate with a shorter axis is discarded — but a de-novo rotation run also runs a **second first-pass hypothesis with the floor lowered to 5 Å by default**, adopted when the standing cell turns out to be an integer supercell of what it finds, so a small-molecule cell is indexed without this flag. `-C` lowers the floor on its own to cover the cell given (and the second hypothesis then stays out of the way). On stills, where neither applies, a crystal below the floor cannot be indexed unless this is lowered | | `--min-indexed-spots ` | Spots a frame must have on the lattice before it counts as indexed (default: 6, minimum 4). It sets the reported indexing rate and the count the rotation first pass ranks candidate lattices by; whether the run has a lattice at all is decided on the pooled spots instead ([§4.1](CPU_DATA_ANALYSIS_INDEXING.md#41-indexed-spot-decision-inlier-test)), and integration is not gated by it | diff --git a/docs/RUGNUX_INSTALL.md b/docs/RUGNUX_INSTALL.md index eb5b0a61b..5f9b42422 100644 --- a/docs/RUGNUX_INSTALL.md +++ b/docs/RUGNUX_INSTALL.md @@ -113,8 +113,8 @@ build has no CUDA there and needs nothing installed beyond Xcode and CMake. ## Hardware As with the rest of Jungfraujoch, **serious performance requires an NVIDIA GPU**. The CUDA build -provides the GPU fast-feedback indexer (`ffbidx`) and the GPU FFT indexer (`fft`); without CUDA -only the CPU `fftw` indexer is available. With a GPU present most of the per-image pipeline runs on +provides the GPU fast-feedback indexer (`ffbidx`) and the GPU FFT indexer (`cufft`); without CUDA +only the CPU `fftw` indexer is available, and `-X fft` runs on it. With a GPU present most of the per-image pipeline runs on the device — bitshuffle+LZ4 decompression, miniCBF byte-offset decoding and marCCD widening, image preprocessing, azimuthal integration, spot finding, prediction and Bragg integration — as do the pre-scan (beam-stop mask, background beam-centre fit, spot widths, defective pixels; one accumulator diff --git a/rugnux/RugnuxCommandLine.cpp b/rugnux/RugnuxCommandLine.cpp index 83d61b1bf..eb7c08495 100644 --- a/rugnux/RugnuxCommandLine.cpp +++ b/rugnux/RugnuxCommandLine.cpp @@ -25,7 +25,7 @@ namespace { const char *indexing_alg_flag(IndexingAlgorithmEnum a) { switch (a) { case IndexingAlgorithmEnum::FFBIDX: return "ffbidx"; - case IndexingAlgorithmEnum::FFT: return "fft"; + case IndexingAlgorithmEnum::FFT: return "cufft"; // the GPU implementation; rugnux's -X fft is the algorithm case IndexingAlgorithmEnum::FFTW: return "fftw"; case IndexingAlgorithmEnum::None: return "none"; case IndexingAlgorithmEnum::Auto: diff --git a/rugnux/rugnux_cli.cpp b/rugnux/rugnux_cli.cpp index 4853c5119..da20f59e6 100644 --- a/rugnux/rugnux_cli.cpp +++ b/rugnux/rugnux_cli.cpp @@ -119,7 +119,7 @@ void print_usage() { std::cout << " -N, --threads 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; + "touched and every GPU step takes its CPU path (-X Auto and FFT index with FFTW)" << std::endl; std::cout << " -s, --start-image Start image number (default: 0)" << std::endl; std::cout << " -e, --end-image End image number (default: all)" << std::endl; std::cout << " -t, --stride Image stride (default: 1)" << std::endl; @@ -169,7 +169,9 @@ void print_usage() { std::cout << " --rotation-scale Goniometer rotation scale: the stage turned k times the angle stored in the file (the commanded one). Applied to both passes; overrides the fitted correction" << std::endl; std::cout << " --rotation-no-postrefine Disable the (default-on) two-pass rotation post-refine (post-refine detector distance/beam + cell/axis, then re-integrate; only the refined pass is written, as the canonical _* output)" << std::endl; std::cout << " --prepass-fraction Integrate the first fraction f of the sweep, but at least 120 deg of it, in the two-pass rotation geometry pre-pass (0.05-1, default 0.5; 1 = the whole sweep); pass 2 reads every frame. The pre-scan and the first-pass indexing sample the same part of the sweep" << std::endl; - std::cout << " -X, --indexing-algorithm Indexing algorithm (FFBIDX|FFT|FFTW|Auto|None)" << std::endl; + std::cout << " -X, --indexing-algorithm Indexing algorithm (Auto|FFT|cuFFT|FFTW|FFBIDX|None, default Auto). FFT is " + "the de-novo FFT search, on the GPU (cuFFT) where there is one and --no-gpu is not given, otherwise on the " + "CPU (FFTW); cuFFT and FFTW name one implementation each. cuFFT and FFBIDX (known cell) need a GPU" << std::endl; std::cout << " -S, --space-group Space group number (96) or symbol (P43212) - for indexing and scaling" << std::endl; std::cout << " -C, --unit-cell Fix reference unit cell: \"a,b,c,alpha,beta,gamma\"" << std::endl; std::cout << " --fft-min-unit-cell Shortest cell axis the FFT search accepts, in A (default: 10). A candidate with a shorter axis is discarded, but a de-novo rotation run also tries a second first-pass hypothesis with the floor at 5 A, so a small-molecule cell is indexed without this flag; -C lowers it on its own to cover the cell given" << std::endl; @@ -1133,7 +1135,9 @@ static int RunRugnux(int argc, char **argv, bool no_gpu) { if (alg == "ffbidx") indexing_algorithm = IndexingAlgorithmEnum::FFBIDX; - else if (alg == "fft") + else if (alg == "fft") // the algorithm: on the GPU where there is one, else with FFTW + indexing_algorithm = get_gpu_count() > 0 ? IndexingAlgorithmEnum::FFT : IndexingAlgorithmEnum::FFTW; + else if (alg == "cufft") indexing_algorithm = IndexingAlgorithmEnum::FFT; else if (alg == "fftw") indexing_algorithm = IndexingAlgorithmEnum::FFTW; @@ -1207,7 +1211,7 @@ static int RunRugnux(int argc, char **argv, bool no_gpu) { dump_observations = optarg; break; case 'F': - indexing_algorithm = IndexingAlgorithmEnum::FFT; + indexing_algorithm = get_gpu_count() > 0 ? IndexingAlgorithmEnum::FFT : IndexingAlgorithmEnum::FFTW; break; case 'A': anomalous_mode = true; @@ -1594,6 +1598,14 @@ static int RunRugnux(int argc, char **argv, bool no_gpu) { exit(EXIT_FAILURE); } + if ((indexing_algorithm == IndexingAlgorithmEnum::FFT || indexing_algorithm == IndexingAlgorithmEnum::FFBIDX) + && get_gpu_count() == 0) { + logger.Error("-X {} runs on the GPU only, and {}; -X FFT or Auto index on the CPU", + indexing_algorithm == IndexingAlgorithmEnum::FFT ? "cuFFT" : "FFBIDX", + no_gpu ? "--no-gpu is given" : "no GPU is visible"); + exit(EXIT_FAILURE); + } + input_file = argv[optind]; const std::string broker_url = (optind == argc - 2) ? argv[optind + 1] : ""; diff --git a/tests/RugnuxTest.cpp b/tests/RugnuxTest.cpp index bb8367cb7..70c8621f7 100644 --- a/tests/RugnuxTest.cpp +++ b/tests/RugnuxTest.cpp @@ -263,7 +263,7 @@ TEST_CASE("RugnuxCommandLine_Full", "[process]") { CHECK(cmd.find("-N 8") != std::string::npos); CHECK(cmd.find("-e 500") != std::string::npos); CHECK(cmd.find("-o run1") != std::string::npos); - CHECK(cmd.find("-X fft") != std::string::npos); + CHECK(cmd.find("-X cufft") != std::string::npos); CHECK(cmd.find("-S 96") != std::string::npos); // -R takes an optional argument, so its value must be attached (-R30); a separate "-R 30" token // would not re-parse (getopt would leave 30 as a positional and drop the count).