- FFTIndexerGPU makes and transforms the projection histograms FFT_BATCH_DIRECTIONS (4096) directions at a time, into one set of batch buffers, and keeps only the transposed magnitudes of all directions for the peak search, which still runs once over all of them. cuFFT's R2C gives the same bits at any batch count (checked at histogram lengths 1024-12568 and batches 1-16384), and every other step is per direction, so the result does not change. Measured: the two indexers of a first pass hold 0.83 instead of 2.48 GB, plus a quarter of the plan work area (0.2 instead of 0.8 GB each at a doubled cell bound). - Rugnux::GPUWorkersPerCard: the per-image loop's existing rule (24 bytes a detector pixel, half of the card's total memory) as one function, now also capping the first pass's spot-finding workers and the pre-scan's workers (both at most 8 a card as before). No change on a 16 GB or an 8.55 GB card with a 16-18 Mpx detector; a 4-6 GB card gets 4-6 of them. Output unchanged: p.hkl byte-identical on cytc_x10sa, myob_x10sa, 4nwv and 8qaw, on the RTX 5080 and with its total read as 8.55 GB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.5 KiB
C++
65 lines
2.5 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
// This include should be only included in sections of the code, where it is certain that CUDA is present
|
|
// so with JFJOCH_USE_CUDA preprocessor definition, given this file is included in the source only in this case
|
|
|
|
#include <vector>
|
|
#include <mutex>
|
|
#include <optional>
|
|
#include "CUDAMemHelpers.h"
|
|
#include "../../common/Coord.h"
|
|
#include "../../common/CrystalLattice.h"
|
|
#include "FFTIndexer.h"
|
|
#include "../common/IndexingSettings.h"
|
|
#include "FFTResult.h"
|
|
|
|
// The histograms are made and transformed FFT_BATCH_DIRECTIONS directions at a time. All at once, the
|
|
// histograms, their transforms and cuFFT's work area held 0.8 GB at the default 16384 directions and 2 GB
|
|
// at a doubled cell bound, for the length of the indexer's life; a batch holds a quarter of that. A
|
|
// direction's histogram and transform do not depend on which batch it is in - cuFFT's R2C gives the same
|
|
// bits at any batch count (checked at the histogram sizes the indexer uses) - so neither does the result.
|
|
// Kept large enough that a batch still fills the card.
|
|
constexpr int FFT_BATCH_DIRECTIONS = 4096;
|
|
|
|
class FFTIndexerGPU : public FFTIndexer {
|
|
CudaDevicePtr<float> d_dir_x;
|
|
CudaDevicePtr<float> d_dir_y;
|
|
CudaDevicePtr<float> d_dir_z;
|
|
|
|
CudaDevicePtr<float> d_spot_x;
|
|
CudaDevicePtr<float> d_spot_y;
|
|
CudaDevicePtr<float> d_spot_z;
|
|
|
|
CudaHostPtr<float> spot_x;
|
|
CudaHostPtr<float> spot_y;
|
|
CudaHostPtr<float> spot_z;
|
|
|
|
// The histograms and their transforms of one batch of directions, and the magnitudes of all of them.
|
|
CudaDevicePtr<float> d_input_fft;
|
|
CudaDevicePtr<cufftComplex> d_output_fft;
|
|
CudaDevicePtr<float> d_mag_t;
|
|
CudaDevicePtr<FFTResult> d_result_fft;
|
|
|
|
CudaRegisteredVector<FFTResult> result_fft_reg;
|
|
|
|
CudaStream stream;
|
|
|
|
// After the stream: it waits for the stream before the plan goes back, and goes before the stream.
|
|
CudaFFTPlan plan;
|
|
CudaFFTPlan plan_last; // the last batch, where FFT_BATCH_DIRECTIONS does not divide the directions
|
|
|
|
void ExecuteFFT(const std::vector<Coord> &coord, size_t nspots) override;
|
|
void DirectionsChanged() override;
|
|
public:
|
|
explicit FFTIndexerGPU(const IndexingSettings& settings);
|
|
FFTIndexerGPU(const FFTIndexerGPU &i) = delete;
|
|
const FFTIndexerGPU &operator=(const FFTIndexerGPU &i) = delete;
|
|
~FFTIndexerGPU() override = default;
|
|
};
|
|
|
|
|
|
|