Files
leonarski_f 7f2ebd8209
Build Packages / Build documentation (push) Successful in 46s
Build Packages / Create release (push) Successful in 8s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m25s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 9m46s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 13m25s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 16m41s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 23m46s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m37s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 24m31s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 28m9s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 20m47s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 26m21s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 27m36s
Build Packages / Generate python client (push) Successful in 31s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 29m27s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 31m46s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 25m22s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 30m36s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 31m49s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 23m57s
Build Packages / Unit tests (push) Successful in 1h47m52s
Build Packages / Validation Battery (push) Successful in 44m55s
v1.0.0-rc.184 (#95)
* Rugnux: Rotation processing recovers most of the speed lost since 1.0.0-rc.180; live processing in jfjoch_broker finishes sooner.
* Rugnux: More reliable rotation processing and indexing, including small molecules and supercells.
* Rugnux: More robust serial data and model refinement; molecular replacement handles multi-chain models.
* jfjoch_broker (experimental): Live serial processing keeps the detector geometry fixed for the whole run.
* jfjoch_broker: Pixel sum without an FPGA, a mask bit for inactive pixels, and several stability fixes.
* jfjoch_broker: Rotation indexing and quick integration moved to rugnux live mode; their API settings are deprecated and ignored.
* jfjoch_broker, Rugnux: Azimuthal integration can use logarithmic (log10) Q bins or a given number of bins, set from the API, the web interface and the Rugnux command line.
* jfjoch_viewer: Build and display fixes; the README is rewritten.

Reviewed-on: #95
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-11-10 22:06:51 +01:00

63 lines
3.4 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <cstdint>
#include <cstddef>
#include <vector>
#include "../common/CompressedImage.h"
#include "../common/DiffractionExperiment.h"
#include "../common/PixelMask.h"
#include "ImagePreprocessorBuffer.h"
struct alignas(8) ImageStatistics {
unsigned long long error_pixel_count = 0;
unsigned long long saturated_pixel_count = 0;
unsigned long long masked_pixel_count = 0;
long long max_value = INT64_MIN;
long long min_value = INT64_MAX;
// Of the pixels that are not error, saturated or under the device mask, as on the FPGA. A pixel masked
// only by what a run determined (PixelMask::RunMaskBits) counts, so the sum does not depend on it.
long long pixel_sum = 0;
};
class ImagePreprocessor {
protected:
const size_t npixels;
const DiffractionExperiment &experiment;
const int64_t saturation_limit;
public:
ImagePreprocessor(const DiffractionExperiment &experiment);
virtual ~ImagePreprocessor() = default;
virtual ImageStatistics Analyze(ImagePreprocessorBuffer &processed_image, const uint8_t *decompressed_image, CompressedImageMode image_mode) = 0;
// Analyze straight from the COMPRESSED image, decompressing wherever the implementation prefers.
// The GPU implementation uploads the compressed chunk and decodes it on the device, so only a few
// MB cross PCIe instead of the whole frame and the host never decompresses at all.
// Returns false when this implementation cannot handle the image - the CPU preprocessor always,
// and the GPU one for any algorithm without a device decoder - and the caller then decompresses
// on the host and calls Analyze() as before. Keeping the fallback explicit means a format we
// cannot decode on the device is a slower path, never a wrong answer.
virtual bool AnalyzeCompressed(ImagePreprocessorBuffer &processed_image, const CompressedImage &image,
ImageStatistics &stats) { return false; }
// Device time the last AnalyzeCompressed() spent getting the chunk across and decompressing it,
// so the caller can still report a decompression cost once the host no longer does the work.
// Meaningless unless the previous call returned true.
[[nodiscard]] virtual float GetLastDecompressionTime_s() const { return 0.0f; }
// Resize the buffer an image will be decompressed into and page-lock it, so that the host->device
// copy of Analyze() is a real DMA. Without page-locking the driver stages the copy through its own
// pinned pool, which is a host-side copy on the calling thread: it does not overlap and it degrades
// badly with the number of workers. Nothing to do on the CPU.
virtual void PinInputBuffer(std::vector<uint8_t> &buffer, size_t size) {}
// The same for a region the caller already owns. An uncompressed image is never decompressed
// into a buffer of ours - the upload reads the reader's own bytes - so that is what has to be
// page-locked. The region is remembered, so a worker handing over the same buffer on every frame
// registers it once. The registration is dropped when this object is destroyed, which is why an
// engine must not outlive the buffer it was given.
virtual void PinInputRegion(const void *ptr, size_t bytes) {}
};