Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 16m43s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 28m46s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 32m5s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 39m44s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m7s
Build Packages / Create release (push) Successful in 8s
Build Packages / Build documentation (push) Successful in 49s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 22m30s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 31m54s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 11m29s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 23m51s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 26m7s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 29m38s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 28m6s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 29m44s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 33m22s
Build Packages / Generate python client (push) Successful in 47s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 34m6s
Build Packages / Unit tests (push) Successful in 1h2m47s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 35m59s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 34m8s
Build Packages / Validation Battery (push) Successful in 38m31s
* Rugnux: Refinement several times faster, one protocol on the CPU and the GPU, parts of it on the Apple GPU; its random draws are the same on every platform. * Rugnux: Refinement follows common practice: the free set decides only the restraint weights and the displacement model (isotropic, TLS or anisotropic, by Hamilton's test), everything else is decided on the working set; lower R-free for placed and predicted models. * Rugnux: Restraint dictionaries via `--restraints` (or among the inputs) and more built-in ligands; a model whose space group is a subgroup of the data's is refined in its own group; reflections plus a model select `--mode refine` on their own. * Rugnux: `-C` fixes the crystal system on the axes as typed; `-S` alone fixes the space group only, the cell is still found and reduced; a space group or cell stored in the input file is ignored, with a line in the log. * Rugnux: More reliable multi-sweep merging; `--mode scale` merges several stills runs as one; `_plot.txt` and the report name each input; a second crystal form is reported for stills given a cell. * jfjoch_broker (experimental): Live Rugnux on FPGA detectors (JUNGFRAU) takes the same path as a DECTRIS stream, rotation and serial alike, model step included, with analysis threads per GPU; frames waiting for the analysis can be viewed; no host stage drops a frame - a source faster than the analysis is held at the card. * jfjoch_broker: Summation of more than 256 frames per image is split between the card and the host (`summation_mode` is then `hybrid`), and live Rugnux runs on such collections; pedestal runs take a receiver of their own. * jfjoch_broker (experimental): `stills_downsample` analyses 1 of every N serial images (chosen by a hash; the first 2000 all; the others written without analysis; reset to 1 by `/initialize`); `max_spot_count` left out means 250 for per-image indexing and up to 1000 for live stills; the live status gives the merge before the model work, the fitted resolution and the anomalous peak height of each unexplained blob. * jfjoch_broker: Without a `pcie` entry the broker runs on a mock of the card instead of the HLS simulation; its spot, ROI and azimuthal results are zero then. * Web frontend: Redesigned Rugnux live page; Vite 8, TypeScript 6, Mol* 5.13 and dependency security updates. * Tools: `jfjoch_fpga_stills_test` measures live stills on the cards with a stored dataset; `jfjoch_fpga_test` loses the HLS-simulation option. * Other: FFTW no longer fetched or linked (the CPU FFT indexer keeps the name `FFTW`); PCIe driver now GPL-2.0-or-later and third-party notices complete; several crash fixes. Reviewed-on: #98 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
182 lines
8.0 KiB
C++
182 lines
8.0 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
// Summation split between the card and the host, on the mock of the card: the card sums the largest divisor of the
|
|
// summation up to 256, the host the card's images of one image. The pixels of both receivers are checked against
|
|
// a sum done here.
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include <map>
|
|
#include <mutex>
|
|
|
|
#include "../frame_serialize/CBORStream2Deserializer.h"
|
|
#include "../image_pusher/ImagePusher.h"
|
|
#include "../receiver/FPGAImagePuller.h"
|
|
#include "../receiver/FrameTransformation.h"
|
|
#include "../receiver/JFJochReceiverService.h"
|
|
#include "MockCardOutput.h"
|
|
|
|
namespace {
|
|
struct SumReceived {
|
|
DataMessage message;
|
|
std::vector<uint8_t> pixels;
|
|
};
|
|
|
|
class SumPusher : public ImagePusher {
|
|
public:
|
|
std::mutex m;
|
|
std::map<int64_t, SumReceived> images;
|
|
|
|
void StartDataCollection(StartMessage &) override {}
|
|
bool EndDataCollection(const EndMessage &) override { return true; }
|
|
bool SendCalibration(const CompressedImage &) override { return true; }
|
|
bool SendImage(const uint8_t *image_data, size_t image_size, int64_t image_number) override {
|
|
auto d = CBORStream2Deserialize(image_data, image_size);
|
|
SumReceived r;
|
|
r.message = d->data_message.value();
|
|
r.message.image.GetUncompressed(r.pixels);
|
|
r.message.image = CompressedImage();
|
|
std::unique_lock ul(m);
|
|
images.emplace(image_number, std::move(r));
|
|
return true;
|
|
}
|
|
std::string PrintSetup() const override { return "summation"; }
|
|
ImagePusherType GetType() const override { return ImagePusherType::Test; }
|
|
};
|
|
|
|
DiffractionExperiment SumExperiment(int64_t summation, int64_t images) {
|
|
DiffractionExperiment x(DetJF(2));
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true).InternalPacketGeneratorImages(1)
|
|
.ImagesPerTrigger(images).ImagesPerFile(10).IncidentEnergy_keV(12.4)
|
|
.DetectorDistance_mm(75).BeamX_pxl(500).BeamY_pxl(600);
|
|
x.Conversion();
|
|
x.Summation(summation).Compression(CompressionAlgorithm::BSHUF_LZ4);
|
|
return x;
|
|
}
|
|
|
|
constexpr size_t ErrPixel = 100, SatPixel = 200, LargePixel = 300;
|
|
constexpr int64_t CardImageCount = 5;
|
|
|
|
// What the card writes for its images, in its pixel format: a pattern, one pixel in error in the second image, one
|
|
// saturated in the third, and one large enough that three of them saturate in 32 bits
|
|
std::vector<CardImage> CardSums(const DiffractionExperiment &x) {
|
|
const bool wide = x.GetByteDepthFPGA() == 4;
|
|
std::vector<CardImage> ret;
|
|
std::vector<int64_t> values(RAW_MODULE_SIZE);
|
|
for (int64_t f = 0; f < CardImageCount; f++) {
|
|
CardImage image;
|
|
for (int m = 0; m < x.GetModulesNum(); m++) {
|
|
for (size_t i = 0; i < RAW_MODULE_SIZE; i++)
|
|
values[i] = (f * 7 + m * 3 + static_cast<int64_t>(i)) % 1000;
|
|
values[ErrPixel] = (f == 1) ? (wide ? INT32_MIN : INT16_MIN) : 5;
|
|
values[SatPixel] = (f == 2) ? (wide ? INT32_MAX : INT16_MAX) : 5;
|
|
values[LargePixel] = wide ? INT32_MAX / 3 + 1 : 30000;
|
|
auto output = std::make_unique<DeviceOutput>();
|
|
StorePixels(*output, x, values);
|
|
output->module_statistics.pixel_sum = 1000 * f + m;
|
|
image.push_back(std::move(output));
|
|
}
|
|
ret.push_back(std::move(image));
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
template<class Tsrc>
|
|
int32_t Pixel(const DeviceOutput &output, size_t i) {
|
|
return reinterpret_cast<const Tsrc *>(output.pixels)[i];
|
|
}
|
|
|
|
// The image summed here from the card's images, by ModuleSummation's rule: an error in any is an error, then a
|
|
// saturated one or a sum reaching INT32_MAX is saturated. Assembled by FrameTransformation, as the receivers do.
|
|
std::vector<uint8_t> Reference(const DiffractionExperiment &x, const std::vector<CardImage> &cards, int64_t image) {
|
|
const bool wide = x.GetByteDepthFPGA() == 4;
|
|
const int64_t err_src = wide ? INT32_MIN : INT16_MIN;
|
|
const int64_t sat_src = wide ? INT32_MAX : INT16_MAX;
|
|
const int64_t h = x.GetHostSummation();
|
|
|
|
FrameTransformation transformation(x);
|
|
for (int m = 0; m < x.GetModulesNum(); m++) {
|
|
auto output = std::make_unique<DeviceOutput>();
|
|
memset(output.get(), 0, sizeof(DeviceOutput));
|
|
output->module_statistics.module_number = m;
|
|
auto sum = reinterpret_cast<int32_t *>(output->pixels);
|
|
for (size_t i = 0; i < RAW_MODULE_SIZE; i++) {
|
|
int64_t acc = 0;
|
|
for (int64_t k = 0; k < h; k++) {
|
|
const auto &card = *cards[(image * h + k) % CardImageCount][m];
|
|
const int64_t v = wide ? Pixel<int32_t>(card, i) : Pixel<int16_t>(card, i);
|
|
if (v == err_src || acc == INT32_MIN)
|
|
acc = INT32_MIN;
|
|
else if (v == sat_src || acc == INT32_MAX || acc + v >= INT32_MAX)
|
|
acc = INT32_MAX;
|
|
else
|
|
acc += v;
|
|
}
|
|
sum[i] = static_cast<int32_t>(acc);
|
|
}
|
|
transformation.ProcessModule(output.get(), 0);
|
|
}
|
|
auto p = static_cast<const uint8_t *>(transformation.GetImage());
|
|
return {p, p + x.GetPixelsNum() * x.GetByteDepthImage()};
|
|
}
|
|
|
|
std::map<int64_t, SumReceived> Run(const DiffractionExperiment &x, bool puller) {
|
|
auto devices = MockDevices(x, CardSums(x));
|
|
Logger logger("FPGAImagePullerSummation");
|
|
SumPusher pusher;
|
|
JFJochReceiverService service(devices, logger, pusher, 256);
|
|
SpotFindingSettings spots = DiffractionExperiment::DefaultDataProcessingSettings();
|
|
spots.indexing = false;
|
|
service.NumThreads(4).SetSpotFindingSettings(spots);
|
|
service.FPGAImagePullerSettings(puller);
|
|
PixelMask mask(x);
|
|
const JFCalibration calib = GeneratePedestalCalibration(x);
|
|
service.Start(x, mask, &calib);
|
|
const auto out = service.Stop();
|
|
CHECK(out.efficiency == 1.0f);
|
|
CHECK(out.received_packets.empty() == puller); // only the FPGA receiver fills these
|
|
return std::move(pusher.images);
|
|
}
|
|
|
|
void CheckSummation(int64_t summation, int64_t card, int64_t host) {
|
|
const auto x = SumExperiment(summation, 2);
|
|
REQUIRE(x.GetFPGASummation() == card);
|
|
REQUIRE(x.GetHostSummation() == host);
|
|
REQUIRE(x.GetByteDepthImage() == 4);
|
|
const auto cards = CardSums(x);
|
|
|
|
for (const bool puller: {false, true}) {
|
|
INFO("puller " << puller);
|
|
const auto images = Run(x, puller);
|
|
REQUIRE(images.size() == 2);
|
|
for (const auto &[n, r]: images) {
|
|
INFO("image " << n);
|
|
CHECK(r.message.packets_received == r.message.packets_expected);
|
|
CHECK(r.message.packets_expected == 512 * summation * x.GetModulesNum());
|
|
CHECK(r.pixels == Reference(x, cards, n));
|
|
// From the card's module statistics: only the FPGA receiver keeps them
|
|
if (!puller) {
|
|
int64_t pixel_sum = 0;
|
|
for (int64_t k = 0; k < host; k++)
|
|
for (int m = 0; m < x.GetModulesNum(); m++)
|
|
pixel_sum += 1000 * ((n * host + k) % CardImageCount) + m;
|
|
CHECK(r.message.pixel_sum == pixel_sum);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_CASE("FPGAImagePuller_Summation256_CardOnly", "[FPGAImagePuller]") {
|
|
CheckSummation(256, 256, 1);
|
|
}
|
|
|
|
TEST_CASE("FPGAImagePuller_Summation1000_Hybrid", "[FPGAImagePuller]") {
|
|
CheckSummation(1000, 250, 4);
|
|
}
|
|
|
|
TEST_CASE("FPGAImagePuller_Summation257_HostOnly", "[FPGAImagePuller]") {
|
|
CheckSummation(257, 1, 257);
|
|
}
|