Files
leonarski_f 77bc0cfe52
Build Packages / build:viewer-tgz:cpu (push) Successful in 11m35s
Build Packages / build:windows:nocuda (push) Successful in 16m52s
Build Packages / build:windows:cuda (push) Successful in 20m24s
Build Packages / build:rugnux-tgz (x86_64) (push) Successful in 18m38s
Build Packages / build:rugnux:windows (push) Successful in 10m38s
Build Packages / build:rugnux:aarch64 (cross) (push) Successful in 9m4s
Build Packages / build:viewer-tgz:cuda (push) Successful in 14m44s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 20m46s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 21m24s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 24m13s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 26m2s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 18m34s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 23m55s
Build Packages / build:rpm (rocky9) (push) Successful in 21m9s
Build Packages / XDS test (durin plugin) (push) Successful in 12m8s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 20m6s
Build Packages / build:rpm (rocky8) (push) Successful in 25m46s
Build Packages / Generate python client (push) Successful in 38s
Build Packages / Create release (push) Skipped
Build Packages / Build documentation (push) Successful in 58s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 24m36s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 8m44s
Build Packages / XDS test (neggia plugin) (push) Successful in 7m17s
Build Packages / DIALS test (push) Successful in 19m45s
Build Packages / Unit tests (push) Successful in 1h26m13s
v1.0.0-rc.168 (#78)
* rugnux is substantially faster - a corpus of 145 rotation datasets processes in about two thirds of the time - with identical results.
* A crystal whose lattice looks more symmetric than it is because the beam centre is off is no longer processed on the wrong cell.
* rugnux prints at startup, and writes at the foot of every results report, a short acknowledgement of the X-ray research community whose methods it implements and of the open-source projects it builds on; `ACKNOWLEDGEMENT.md` now ships in every package beside `LICENSE` and `THIRD_PARTY_NOTICES.md`.

Reviewed-on: #78
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-09-10 13:51:16 +02:00

60 lines
3.1 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;
};
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) {}
};