GPU: kernels read host buffers in place on unified-memory systems

gpu_direct_host_read() (CUDAWrapper) is true where the device accesses pageable
memory through the host's page tables (cudaDevAttrPageableMemoryAccess and
...UsesHostPageTables: GB10, GH200, GB200), asked once per device;
JFJOCH_FORCE_DIRECT_HOST_READ forces it on for testing with page-locked inputs.
Where it holds:
- BSLZ4DecoderGPU: the LZ4/fused kernels and the tail copy read the reader's
  compressed chunk directly, no pinned staging memcpy and no H2D copy;
- ImagePreprocessorGPU: Analyze and the UINT16_WIDENED path hand the host
  buffer to preprocess_kernel (if aligned to the pixel type), and nothing is
  page-locked;
- RotationScaleMergeGPU::IngestUpload: IngestExtractKernel reads the pinned
  stage in place, without device staging buffers; the stage is reused only
  after the kernel has run.
Discrete cards take the unchanged path. Every caller synchronises its stream
before the host buffer goes away. DirectHostReadGPUTest checks the three
sites against the CPU on page-locked inputs, in either mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 21:49:37 +02:00
co-authored by Claude Opus 5.5
parent fe4db26716
commit e3b33591ca
10 changed files with 263 additions and 29 deletions
@@ -31,6 +31,9 @@ class ImagePreprocessorGPU : public ImagePreprocessor {
size_t pinned_input_bytes = 0;
// Staging for a marCCD frame's stored 16-bit pixels (UINT16_WIDENED), allocated on first use.
CudaHostPtr<uint8_t> host_stored;
// The card reads host memory directly (gpu_direct_host_read()): images are read where they lie,
// nothing is page-locked or staged; only the CBF device decoder still uploads its input.
bool direct_host_read = false;
std::vector<int32_t> cpu_image;
@@ -46,10 +49,11 @@ class ImagePreprocessorGPU : public ImagePreprocessor {
ImageStatistics AnalyzeStoredInt32(ImagePreprocessorBuffer &processed_image, const CompressedImage &image);
template <class T> ImageStatistics Analyze(ImagePreprocessorBuffer &processed_image, const uint8_t *input, T err_value, T sat_value);
// Preprocess an image already sitting in gpu_decompressed_image (the host-upload path).
// err_value and sat_value are compared with the pixel's value, not its bits, so a narrower T can
// carry the int32 semantics of the image it widens to.
template <class T> ImageStatistics AnalyzeOnDevice(ImagePreprocessorBuffer &processed_image,
// Preprocess the image at `input`: gpu_decompressed_image on the host-upload path, or the host
// buffer itself where the card reads host memory directly. err_value and sat_value are compared
// with the pixel's value, not its bits, so a narrower T can carry the int32 semantics of the image
// it widens to.
template <class T> ImageStatistics AnalyzeOnDevice(ImagePreprocessorBuffer &processed_image, const void *input,
int64_t err_value, int64_t sat_value);
// Preprocess straight out of the bitshuffled bytes (the device-decode path). Same per-pixel
// decision and same statistics as AnalyzeOnDevice, with the un-transpose folded in.