Build Packages / Create release (push) Successful in 24s
Build Packages / build:viewer:macos-arm64:nocuda (push) Successful in 3m29s
Build Packages / build:rugnux:macos-arm64:nocuda (push) Successful in 2m43s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 8m27s
Build Packages / build:rugnux:linux-x86_64:cuda (push) Successful in 9m53s
Build Packages / build:viewer:linux-x86_64:nocuda (push) Successful in 9m58s
Build Packages / build:viewer:linux-x86_64:cuda (push) Successful in 11m22s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 13m39s
Build Packages / build:viewer:windows-x86_64:nocuda (push) Successful in 18m37s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 16m32s
Build Packages / build:viewer:windows-x86_64:cuda (push) Successful in 24m11s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m30s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 19m3s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 20m23s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 19m41s
Build Packages / Generate python client (push) Successful in 50s
Build Packages / Build documentation (push) Successful in 1m16s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 21m0s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 18m38s
Build Packages / build:rugnux:windows-x86_64:cuda (push) Successful in 14m33s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 17m55s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 20m50s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 18m38s
Build Packages / Unit tests (push) Successful in 1h46m14s
* jfjoch_broker: Optional per-dataset authentication - statistics, images and plots can require a bearer token, which jfjoch_viewer supports. * jfjoch_viewer: Dark mode and a theme-matched colour scheme, a magnifier panel, and simpler contrast and background controls. * Rugnux: Multiple performance improvements on GPU and CPU (CPU-only processing up to 40% faster, faster image decoding on ARM), with unchanged results. * Rugnux: `--model` rigid-body refinement runs on the GPU, and the model-validation check is faster and more reliable. * Rugnux: Improved scaling and merging - error model, outlier rejection, absorption correction and French-Wilson amplitudes now agree more closely with XDS and ctruncate. * Rugnux: Improved integration - radial background on powder and ice rings, crowded rotation data keep their reflections, and CPU-only builds integrate large unit cells as GPU builds do. * Rugnux: More robust detector geometry - measured beam centre, X-ray bandwidth and goniometer rate, and geometry refinement accepted only on significant evidence. * Rugnux: Merged files are written in the standard setting, or in the setting of a reference MTZ, structure-factor mmCIF or model, with its free-R flags. * Rugnux: Richer report - ice and powder rings, further lattices, superstructure candidates and mosaicity, with warnings worded as prompts to check. * Rugnux: Clear error messages when a data set needs more GPU or host memory than is available. Reviewed-on: #83 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
124 lines
4.3 KiB
C++
124 lines
4.3 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
#include "../common/CUDAWrapper.h"
|
|
|
|
#include <optional>
|
|
#include <thread>
|
|
|
|
#ifdef JFJOCH_USE_CUDA
|
|
|
|
#include <future>
|
|
#include <latch>
|
|
#include <set>
|
|
#include <thread>
|
|
|
|
#include "../image_analysis/indexing/CUDAMemHelpers.h"
|
|
|
|
// The broker starts fresh worker threads for every data collection. A stream per thread ever started
|
|
// is a device-memory leak that ends a long-running broker, so threads that follow one another have to
|
|
// end up on the same stream.
|
|
TEST_CASE("CudaAllocationStream_ReusedByLaterThreads", "[CUDAMemHelpers]") {
|
|
if (get_gpu_count() == 0)
|
|
SKIP("No CUDA GPU present");
|
|
|
|
std::set<cudaStream_t> seen;
|
|
for (int i = 0; i < 100; i++)
|
|
std::thread([&seen] {
|
|
CudaDevicePtr<uint8_t> buffer(1 << 16);
|
|
seen.insert(cuda_allocation_stream());
|
|
}).join();
|
|
|
|
CHECK(seen.size() == 1);
|
|
CHECK(*seen.begin() != nullptr);
|
|
}
|
|
|
|
TEST_CASE("CudaAllocationStream_DistinctForConcurrentThreads", "[CUDAMemHelpers]") {
|
|
if (get_gpu_count() == 0)
|
|
SKIP("No CUDA GPU present");
|
|
|
|
// Neither thread may exit - and hand its stream back - before the other has taken its own.
|
|
std::latch both_have_one(2);
|
|
auto take = [&both_have_one] {
|
|
const cudaStream_t stream = cuda_allocation_stream();
|
|
both_have_one.count_down();
|
|
both_have_one.wait();
|
|
return stream;
|
|
};
|
|
auto a = std::async(std::launch::async, take);
|
|
auto b = std::async(std::launch::async, take);
|
|
const cudaStream_t stream_a = a.get();
|
|
const cudaStream_t stream_b = b.get();
|
|
|
|
CHECK(stream_a != nullptr);
|
|
CHECK(stream_b != nullptr);
|
|
CHECK(stream_a != stream_b);
|
|
}
|
|
|
|
// The shadow finder builds its GPU accumulator on a throw-away thread and frees it from another one
|
|
// long after. The free is ordered on the allocating thread's stream, so that stream has to outlive
|
|
// the thread - including while a later thread has borrowed it.
|
|
TEST_CASE("CudaDevicePtr_FreedAfterAllocatingThreadExited", "[CUDAMemHelpers]") {
|
|
if (get_gpu_count() == 0)
|
|
SKIP("No CUDA GPU present");
|
|
|
|
auto buffer = std::async(std::launch::async, [] {
|
|
return std::make_unique<CudaDevicePtr<uint8_t>>(1 << 20);
|
|
}).get();
|
|
std::thread([] { CudaDevicePtr<uint8_t> other(1 << 16); }).join();
|
|
|
|
REQUIRE(cudaMemset(buffer->get(), 0, 1 << 20) == cudaSuccess);
|
|
buffer.reset();
|
|
CHECK(cudaDeviceSynchronize() == cudaSuccess);
|
|
CHECK(cudaGetLastError() == cudaSuccess);
|
|
}
|
|
|
|
// A pool that cannot serve the request is not an error: the buffer comes from cudaMalloc instead. It
|
|
// must then not stay behind as the thread's last error, or the cudaGetLastError() after the next
|
|
// kernel launch throws "out of memory" over work that went fine.
|
|
TEST_CASE("CudaDevicePtr_HandledPoolFailureLeavesNoError", "[CUDAMemHelpers]") {
|
|
if (get_gpu_count() == 0)
|
|
SKIP("No CUDA GPU present");
|
|
|
|
int device = 0;
|
|
REQUIRE(cudaGetDevice(&device) == cudaSuccess);
|
|
|
|
cudaMemPoolProps props{};
|
|
props.allocType = cudaMemAllocationTypePinned;
|
|
props.location.type = cudaMemLocationTypeDevice;
|
|
props.location.id = device;
|
|
props.maxSize = 4 << 20;
|
|
|
|
cudaMemPool_t previous = nullptr, capped = nullptr;
|
|
REQUIRE(cudaDeviceGetMemPool(&previous, device) == cudaSuccess);
|
|
REQUIRE(cudaMemPoolCreate(&capped, &props) == cudaSuccess);
|
|
REQUIRE(cudaDeviceSetMemPool(device, capped) == cudaSuccess);
|
|
{
|
|
CudaDevicePtr<uint8_t> buffer(64 << 20);
|
|
CHECK(buffer.get() != nullptr);
|
|
CHECK(cudaGetLastError() == cudaSuccess);
|
|
}
|
|
REQUIRE(cudaDeviceSetMemPool(device, previous) == cudaSuccess);
|
|
cudaMemPoolDestroy(capped);
|
|
}
|
|
|
|
#endif
|
|
|
|
// A merge that finds the card full waits for the GPU work running beside it: until the last one
|
|
// ends, and not forever.
|
|
TEST_CASE("GPUWorkBeside_WaitEndsWithTheWork", "[CUDAMemHelpers]") {
|
|
CHECK(wait_for_gpu_work_beside(std::chrono::seconds(0)));
|
|
|
|
std::optional<GPUWorkBeside> work;
|
|
work.emplace();
|
|
CHECK_FALSE(wait_for_gpu_work_beside(std::chrono::seconds(0)));
|
|
|
|
std::thread ends([&work] {
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
work.reset();
|
|
});
|
|
CHECK(wait_for_gpu_work_beside(std::chrono::seconds(60)));
|
|
ends.join();
|
|
}
|