A port of the fast-feedback indexer's CUDA kernels to plain C++/Eigen: the same half-sphere and rotation samples, the same scores and the same 32 output cells for Refine(). The loops are reorganised so the inner one runs over samples and vectorises (GCC/Clang, no intrinsics), and the cell search separates the rotation about the candidate vector out of the per-spot terms. The vector refinement reproduces the library's warp sums - partial sums its shuffle reduction leaves in the other lanes carry into the next round - and its float arithmetic (FMA contraction, the Fibonacci points in float), because the candidates searched depend on it: on the library's 27 test spot lists and 4 synthetic stills the CPU and GPU best cells agree to ~1e-6 relative, the top-32 sets in 30 of 31 cases completely. FFBIDX now resolves to the GPU library where a GPU is visible and to the CPU port otherwise (no GPU, --no-gpu, or a build without CUDA); Auto takes FFBIDX for stills whenever a cell is known, also without a GPU, instead of FFTW. With a GPU nothing changes (a stills set and a rotation set reproduce the baseline exactly). Without a GPU the stills indexer pool gets one indexer per worker instead of eight, since the CPU indexer holds no card memory. Single core, synthetic still, loaded 5950X: ~8 ms per call at 30 spots, ~15 ms at 80, ~35 ms at 250; 16 threads ~1300/700/330 calls/s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu (cherry picked from commit 9a8eb8669d1be6c3ec16db6786280affd6830ee5)
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "IndexerFactory.h"
|
|
#include "FFBIDXIndexerCPU.h"
|
|
#include "../../common/CUDAWrapper.h"
|
|
|
|
#ifdef JFJOCH_USE_CUDA
|
|
#include "FFBIDXIndexer.h"
|
|
#include "FFTIndexerGPU.h"
|
|
#endif
|
|
|
|
#ifdef JFJOCH_USE_FFTW
|
|
#include "FFTIndexerCPU.h"
|
|
#endif
|
|
|
|
std::unique_ptr<Indexer> CreateIndexer(const DiffractionExperiment& experiment) {
|
|
std::unique_ptr<Indexer> indexer;
|
|
switch (experiment.GetIndexingAlgorithm()) {
|
|
case IndexingAlgorithmEnum::FFBIDX:
|
|
#ifdef JFJOCH_USE_CUDA
|
|
if (get_gpu_count() > 0)
|
|
indexer = std::make_unique<FFBIDXIndexer>();
|
|
#endif
|
|
if (!indexer)
|
|
indexer = std::make_unique<FFBIDXIndexerCPU>();
|
|
indexer->Setup(experiment);
|
|
break;
|
|
case IndexingAlgorithmEnum::FFTW:
|
|
#ifdef JFJOCH_USE_FFTW
|
|
indexer = std::make_unique<FFTIndexerCPU>(experiment.GetIndexingSettings());
|
|
indexer->Setup(experiment);
|
|
#endif
|
|
break;
|
|
case IndexingAlgorithmEnum::FFT:
|
|
#ifdef JFJOCH_USE_CUDA
|
|
indexer = std::make_unique<FFTIndexerGPU>(experiment.GetIndexingSettings());
|
|
indexer->Setup(experiment);
|
|
#endif
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return indexer;
|
|
} |