74 lines
2.1 KiB
C++
74 lines
2.1 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#ifndef JFJOCH_FFTINDEXER_H
|
|
#define JFJOCH_FFTINDEXER_H
|
|
|
|
// 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 "CUDAMemHelpers.h"
|
|
#include "../../common/Coord.h"
|
|
#include "../../common/CrystalLattice.h"
|
|
#include "Indexer.h"
|
|
#include "../common/IndexingSettings.h"
|
|
|
|
#define FFT_MAX_SPOTS (64*1024)
|
|
|
|
struct FFTResult {
|
|
float magnitude;
|
|
int32_t direction;
|
|
float length;
|
|
};
|
|
|
|
class FFTIndexer : public Indexer {
|
|
float min_length_A;
|
|
float max_length_A;
|
|
float histogram_spacing;
|
|
int64_t histogram_size;
|
|
std::vector<Coord> direction_vectors;
|
|
|
|
size_t input_size;
|
|
size_t output_size;
|
|
|
|
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;
|
|
|
|
CudaDevicePtr<float> d_input_fft;
|
|
CudaDevicePtr<cufftComplex> d_output_fft;
|
|
CudaDevicePtr<FFTResult> d_result_fft;
|
|
CudaHostPtr<FFTResult> result_fft;
|
|
|
|
CudaFFTPlan plan;
|
|
|
|
CudaStream stream;
|
|
|
|
void SetupUnitCell(const std::optional<UnitCell> &cell) override;
|
|
void SetupDirectionVectors(int64_t nPoints);
|
|
void ExecuteFFT(const std::vector<Coord> &coord, size_t nspots);
|
|
std::vector<Coord> FilterFFTResults() const;
|
|
std::vector<CrystalLattice> ReduceResults(const std::vector<Coord> &result) const;
|
|
public:
|
|
explicit FFTIndexer(const IndexingSettings& settings);
|
|
FFTIndexer(const FFTIndexer &i) = delete;
|
|
const FFTIndexer &operator=(const FFTIndexer &i) = delete;
|
|
~FFTIndexer() override = default;
|
|
|
|
std::vector<CrystalLattice> Run(const std::vector<Coord> &coord, size_t nspots) override;
|
|
};
|
|
|
|
|
|
#endif //JFJOCH_FFTINDEXER_H
|