From c9b7ae7bd53fbd66682bfbbf86064561beec007a Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 7 Oct 2026 07:40:06 +0200 Subject: [PATCH] Avoid trailing_zeros in the strided reduction's offset decode trailing_zeros becomes SPIR-V's ctz, which spirv2clc can't translate, so reductions over several non-contiguous dims failed to compile on OpenCL.jl's OpenCL C path (e.g. pocl with program_backend!(:opencl)). For a power of two, count_ones(sz - 1) is the same shift. --- src/reduce/mapreduce_nd.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/reduce/mapreduce_nd.jl b/src/reduce/mapreduce_nd.jl index bd49707b..f5f9076a 100644 --- a/src/reduce/mapreduce_nd.jl +++ b/src/reduce/mapreduce_nd.jl @@ -622,7 +622,8 @@ end @inbounds for i in 1:length(reduce_sizes) - 1 sz = reduce_sizes[i] if ispow2(sz) - shift = trailing_zeros(sz) + # (`trailing_zeros` would be `ctz`, which spirv2clc can't translate to OpenCL C) + shift = count_ones(sz - 1) r = tmp & (sz - 1) tmp = tmp >> shift else