Three resource fixes and two latent bugs, none of which changes a computed number. The preprocessed image has a host copy that only a CPU engine ever reads. On the GPU path every engine reads the device buffer instead, and rugnux always runs the fused adaptive finder, so that host copy is allocated, zeroed and PAGE-LOCKED for nothing - 72 MB per worker, 3.5 GB over 48 of them, and a cudaHostRegister each, which the driver serializes. It is now skipped by the same condition that already decides whether the device copies the image back. ImagePreprocessorBuffer keeps the pixel count separately so size() still answers when the mirror was not allocated. ROIIntegrationGPU asked device 0 for the SM count it sizes its grid from, while workers are pinned round-robin across the GPUs - so on a multi-GPU node it could size a grid from a card it never launches on. It asks the current device now, like every other engine. ~CudaRegisteredVector called a function that throws out of a destructor, and the move-assignment did the same from a noexcept function. Either would abort the process rather than report the failure, and teardown - after a device reset, or while another exception unwinds - is exactly where cudaHostUnregister fails. Both now use an unchecked unregister, as every other destructor in that header already does for its own teardown call. The throwing form stays for rebind()/unregister(), which are called from live code. Measured on a 16M-pixel rotation dataset: unchanged space group, merged reflection count and merging statistics. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
45 lines
1.8 KiB
Plaintext
45 lines
1.8 KiB
Plaintext
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "ImagePreprocessorBufferGPU.h"
|
|
|
|
__global__ void gather_kernel(const int32_t *__restrict__ image,
|
|
const uint32_t *__restrict__ npixel,
|
|
int32_t *__restrict__ values,
|
|
int count) {
|
|
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < count; i += blockDim.x * gridDim.x)
|
|
values[i] = image[npixel[i]];
|
|
}
|
|
|
|
ImagePreprocessorBufferGPU::ImagePreprocessorBufferGPU(size_t npixel, bool host_mirror)
|
|
: ImagePreprocessorBuffer(npixel, host_mirror),
|
|
gpu_image(npixel),
|
|
// A no-op when the mirror was not allocated: CudaRegisteredVector skips an empty vector.
|
|
buffer_reg(buffer),
|
|
gpu_gather_index(MAX_GATHER),
|
|
gpu_gather_value(MAX_GATHER) {
|
|
}
|
|
|
|
int32_t *ImagePreprocessorBufferGPU::getGPUBuffer() {
|
|
return gpu_image;
|
|
}
|
|
|
|
const int32_t *ImagePreprocessorBufferGPU::getGPUBuffer() const {
|
|
return gpu_image;
|
|
}
|
|
|
|
void ImagePreprocessorBufferGPU::Gather(const std::vector<uint32_t> &npixel, std::vector<int32_t> &values) const {
|
|
values.resize(npixel.size());
|
|
if (npixel.empty())
|
|
return;
|
|
|
|
const int count = static_cast<int>(npixel.size());
|
|
cudaMemcpyAsync(gpu_gather_index.get(), npixel.data(), count * sizeof(uint32_t),
|
|
cudaMemcpyHostToDevice, gather_stream);
|
|
gather_kernel<<<(count + 255) / 256, 256, 0, gather_stream>>>(
|
|
gpu_image.get(), gpu_gather_index.get(), gpu_gather_value.get(), count);
|
|
cudaMemcpyAsync(values.data(), gpu_gather_value.get(), count * sizeof(int32_t),
|
|
cudaMemcpyDeviceToHost, gather_stream);
|
|
cudaStreamSynchronize(gather_stream);
|
|
}
|