From f6983486c3b4622527fa3ac3ce4925d8188b3e05 Mon Sep 17 00:00:00 2001 From: jungfrau Date: Mon, 24 Aug 2026 05:31:08 -0400 Subject: [PATCH] Put the test's mask in through LoadUserMask, not through a const_cast The fused GPU preprocessor uploads a byte-per-pixel form of the mask that PixelMask derives when the mask is loaded. Writing the bitfield behind its back left that form stale, so the device worked from a mask the CPU reference did not have. Co-Authored-By: Claude Opus 5 (1M context) --- tests/ImagePreprocessorGPUFusedTest.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/ImagePreprocessorGPUFusedTest.cpp b/tests/ImagePreprocessorGPUFusedTest.cpp index 0400591d..fcd122b8 100644 --- a/tests/ImagePreprocessorGPUFusedTest.cpp +++ b/tests/ImagePreprocessorGPUFusedTest.cpp @@ -69,10 +69,13 @@ void CheckFusedMatchesCPU(CompressedImageMode mode, T err_value, uint32_t seed) PixelMask mask(x); // Mask a deterministic scatter of pixels, so masked-vs-error-vs-saturated priority is exercised - // rather than assumed. - auto &m = const_cast &>(mask.GetMask()); - for (size_t i = 0; i < npixels; i += 997) m[i] = 1; - for (size_t i = 13; i < npixels; i += 4001) m[i] = 1; + // rather than assumed. It goes in through LoadUserMask because the mask derives the + // byte-per-pixel form the GPU preprocessor uploads: writing the bitfield behind its back leaves + // that form stale, and the device then works from a mask the CPU reference does not have. + std::vector user_mask(mask.GetMask().size(), 0); + for (size_t i = 0; i < npixels; i += 997) user_mask[i] = 1; + for (size_t i = 13; i < npixels; i += 4001) user_mask[i] = 1; + mask.LoadUserMask(x, user_mask); const auto img = MakeImage(npixels, err_value, seed); JFJochBitShuffleCompressor compressor(CompressionAlgorithm::BSHUF_LZ4); @@ -132,8 +135,9 @@ TEST_CASE("ImagePreprocessorGPU_FusedMatchesHostUpload", "[ImagePreprocessorGPU] DiffractionExperiment x = MakeExperiment(32000); const size_t npixels = x.GetPixelsNum(); PixelMask mask(x); - auto &m = const_cast &>(mask.GetMask()); - for (size_t i = 0; i < npixels; i += 1301) m[i] = 1; + std::vector user_mask(mask.GetMask().size(), 0); + for (size_t i = 0; i < npixels; i += 1301) user_mask[i] = 1; + mask.LoadUserMask(x, user_mask); const auto img = MakeImage(npixels, UINT32_MAX, 77); JFJochBitShuffleCompressor compressor(CompressionAlgorithm::BSHUF_LZ4);