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>
214 lines
9.4 KiB
C++
214 lines
9.4 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <cstddef>
|
|
#include "Definitions.h"
|
|
|
|
// Take half of the number, but only if not bad pixel/overload
|
|
template<typename T>
|
|
T half(T in, T min, T max) {
|
|
T tmp = in;
|
|
if ((in > min) && (in < max)) tmp /= 2;
|
|
return tmp;
|
|
}
|
|
|
|
template<typename T>
|
|
T quarter(T in, T min, T max) {
|
|
T tmp = in;
|
|
if ((in > min) && (in < max)) tmp /= 4;
|
|
return tmp;
|
|
}
|
|
|
|
// Copy line, divide everything by 2 and extend multipixels + divide them by additional factor of 2
|
|
template<typename Td, typename Ts>
|
|
void LineCopyAndAdjustMultipixelMidRow(Td *destination, const Ts *source, Ts min, Ts max,
|
|
int64_t fast_dir_step = 1, int64_t offset_0 = 0) {
|
|
for (int chip = 0; chip < 4; chip++) {
|
|
for (int i = 0; i < 256; i++) {
|
|
destination[offset_0 + (i + chip * 258) * fast_dir_step] = half(source[i + chip * 256], min, max);
|
|
}
|
|
}
|
|
for (int i = 0; i < 3; i++) {
|
|
destination[offset_0 + (255 + i * 258) * fast_dir_step] = quarter(source[255 + i * 256], min, max);
|
|
destination[offset_0 + (256 + i * 258) * fast_dir_step] = quarter(source[255 + i * 256], min, max);
|
|
destination[offset_0 + (257 + i * 258) * fast_dir_step] = quarter(source[256 + i * 256], min, max);
|
|
destination[offset_0 + (258 + i * 258) * fast_dir_step] = quarter(source[256 + i * 256], min, max);
|
|
}
|
|
}
|
|
|
|
// Copy line and extend multipixels + divide them by 2
|
|
template<typename Td, typename Ts>
|
|
void LineCopyAndAdjustMultipixel(Td *destination, const Ts *source, Ts min, Ts max,
|
|
int64_t fast_dir_step = 1, int64_t offset_0 = 0) {
|
|
for (int chip = 0; chip < 4; chip++) {
|
|
for (int i = 0; i < 256; i++) {
|
|
destination[offset_0 + (i + chip * 258) * fast_dir_step] = source[i + chip * 256];
|
|
}
|
|
}
|
|
for (int chip = 0; chip < 3; chip++) {
|
|
destination[offset_0 + (255 + chip * 258) * fast_dir_step] = half(source[255 + chip * 256], min, max);
|
|
destination[offset_0 + (256 + chip * 258) * fast_dir_step] = half(source[255 + chip * 256], min, max);
|
|
destination[offset_0 + (257 + chip * 258) * fast_dir_step] = half(source[256 + chip * 256], min, max);
|
|
destination[offset_0 + (258 + chip * 258) * fast_dir_step] = half(source[256 + chip * 256], min, max);
|
|
}
|
|
}
|
|
|
|
// Copy line and copy multipixels (e.g. for mask)
|
|
template<typename Td, typename Ts>
|
|
void LineCopyAndAddMultipixel(Td *destination, const Ts *source,
|
|
int64_t fast_dir_step = 1, int64_t offset_0 = 0) {
|
|
for (int chip = 0; chip < 4; chip++) {
|
|
for (int i = 0; i < 256; i++)
|
|
destination[offset_0 + (i + chip * 258) * fast_dir_step] = source[i + chip * 256];
|
|
}
|
|
for (int i = 0; i < 3; i++) {
|
|
destination[offset_0 + (256 + i * 258) * fast_dir_step] = source[255 + i * 256];
|
|
destination[offset_0 + (257 + i * 258) * fast_dir_step] = source[256 + i * 256];
|
|
}
|
|
}
|
|
|
|
template<class T, class Tint = int32_t>
|
|
T Bin2x2_sum(T a, T b, T c, T d, T underload, T overload) {
|
|
T ret;
|
|
if ((a <= underload) || (b <= underload) || (c <= underload) || (d <= underload))
|
|
ret = underload;
|
|
else if ((a >= overload) || (b >= overload) || (c >= overload) || (d >= overload))
|
|
ret = overload;
|
|
else {
|
|
Tint sum = a + b + c + d;
|
|
if (sum > overload)
|
|
ret = overload;
|
|
else
|
|
ret = static_cast<T>(sum);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
template<class T, class Tint = int32_t>
|
|
void Bin2x2_sum(T *destination, const T *source, size_t width, size_t height, T underload, T overload) {
|
|
for (int y = 0; y < height / 2; y++) {
|
|
for (int x = 0; x < width / 2; x++)
|
|
destination[y * (width / 2) + x] = Bin2x2_sum<T, Tint>(source[(y * 2) * width + (x * 2)],
|
|
source[(y * 2 + 1) * width + (x * 2)],
|
|
source[(y * 2) * width + (x * 2 + 1)],
|
|
source[(y * 2 + 1) * width + (x * 2 + 1)],
|
|
underload, overload);
|
|
}
|
|
}
|
|
|
|
template<class Td, class Ts>
|
|
void TransferModule(Td *destination, const Ts *source,
|
|
int64_t slow_dir_step,
|
|
int64_t fast_dir_step = 1,
|
|
int64_t offset_0 = 0) {
|
|
for (size_t line = 0; line < RAW_MODULE_LINES; line++) {
|
|
if ((line == 255) || (line == 256)) {
|
|
LineCopyAndAddMultipixel<Td, Ts>(destination + slow_dir_step * (line + 1),
|
|
source + RAW_MODULE_COLS * line,
|
|
fast_dir_step, offset_0);
|
|
LineCopyAndAddMultipixel<Td, Ts>(destination + slow_dir_step * (line + ((line > 255) ? 2 : 0)),
|
|
source + RAW_MODULE_COLS * line,
|
|
fast_dir_step, offset_0);
|
|
} else {
|
|
LineCopyAndAddMultipixel<Td, Ts>(destination + slow_dir_step * (line + ((line > 255) ? 2 : 0)),
|
|
source + RAW_MODULE_COLS * line,
|
|
fast_dir_step);
|
|
}
|
|
}
|
|
}
|
|
|
|
template<class Td, class Ts>
|
|
void TransferModuleAdjustMultipixels(Td *destination, const Ts *source, int64_t slow_dir_step, Ts min, Ts max,
|
|
int64_t fast_dir_step = 1, int64_t offset_0 = 0) {
|
|
for (size_t line = 0; line < RAW_MODULE_LINES; line++) {
|
|
if ((line != 255) && (line != 256))
|
|
LineCopyAndAdjustMultipixel<Td, Ts>(destination + slow_dir_step * (line + ((line > 255) ? 2 : 0)),
|
|
source + RAW_MODULE_COLS * line, min, max, fast_dir_step,
|
|
offset_0);
|
|
else {
|
|
LineCopyAndAdjustMultipixelMidRow<Td, Ts>(destination + slow_dir_step * (line + ((line > 255) ? 2 : 0)),
|
|
source + RAW_MODULE_COLS * line, min, max,
|
|
fast_dir_step, offset_0);
|
|
LineCopyAndAdjustMultipixelMidRow<Td, Ts>(destination + slow_dir_step * (line + 1),
|
|
source + RAW_MODULE_COLS * line, min, max,
|
|
fast_dir_step, offset_0);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Inverse of TransferModuleAdjustMultipixels: each raw pixel of the module is the sum of the pixels its value was
|
|
// split over (2 for a multipixel, 4 at a chip corner), as the split conserves the count. A raw pixel is an error
|
|
// pixel where any of them is at or below min, saturated where any is at or above max or the sum reaches dest_max.
|
|
template<class Td, class Ts>
|
|
void SqueezeMultipixelsToModule(Td *destination, const Ts *source, int64_t slow_dir_step, Ts min, Ts max,
|
|
Td dest_min, Td dest_max, int64_t fast_dir_step = 1, int64_t offset_0 = 0) {
|
|
for (int64_t line = 0; line < RAW_MODULE_LINES; line++) {
|
|
int64_t y[2] = {line + ((line > 255) ? 2 : 0), -1};
|
|
if (line == 255)
|
|
y[1] = 256;
|
|
else if (line == 256)
|
|
y[1] = 257;
|
|
|
|
for (int64_t col = 0; col < RAW_MODULE_COLS; col++) {
|
|
const int64_t chip = col / 256, i = col % 256;
|
|
int64_t x[2] = {i + chip * 258, -1};
|
|
if ((i == 255) && (chip < 3))
|
|
x[1] = x[0] + 1;
|
|
else if ((i == 0) && (chip > 0))
|
|
x[1] = x[0] - 1;
|
|
|
|
int64_t sum = 0;
|
|
bool error = false, saturated = false;
|
|
for (int64_t yy: y) {
|
|
for (int64_t xx: x) {
|
|
if ((yy < 0) || (xx < 0))
|
|
continue;
|
|
const Ts v = source[offset_0 + yy * slow_dir_step + xx * fast_dir_step];
|
|
if (v <= min)
|
|
error = true;
|
|
else if (v >= max)
|
|
saturated = true;
|
|
else
|
|
sum += v;
|
|
}
|
|
}
|
|
|
|
Td &out = destination[line * RAW_MODULE_COLS + col];
|
|
if (error)
|
|
out = dest_min;
|
|
else if (saturated || (sum >= dest_max))
|
|
out = dest_max;
|
|
else if (sum <= dest_min)
|
|
out = dest_min + 1;
|
|
else
|
|
out = static_cast<Td>(sum);
|
|
}
|
|
}
|
|
}
|
|
|
|
template<class T>
|
|
void LineConvtToRaw(T *destination, const T *source, size_t fast_direction_step) {
|
|
for (int chip = 0; chip < 4; chip++) {
|
|
for (int i = 0; i < 256; i++)
|
|
destination[i + chip * 256] = source[(i + chip * 258) * fast_direction_step];
|
|
}
|
|
}
|
|
|
|
|
|
template<class T>
|
|
void Bin2x2_or(T *destination, const T *source, size_t width, size_t height) {
|
|
for (int y = 0; y < height / 2; y++) {
|
|
for (int x = 0; x < width / 2; x++) {
|
|
T tmp[4];
|
|
tmp[0] = source[(y * 2) * width + (x * 2)];
|
|
tmp[1] = source[(y * 2 + 1) * width + (x * 2)];
|
|
tmp[2] = source[(y * 2) * width + (x * 2 + 1)];
|
|
tmp[3] = source[(y * 2 + 1) * width + (x * 2 + 1)];
|
|
destination[y * (width / 2) + x] = tmp[0] | tmp[1] | tmp[2] | tmp[3];
|
|
}
|
|
}
|
|
}
|