zhanchangbao-sanechips commented on PR #51340:
URL: https://github.com/apache/arrow/pull/51340#issuecomment-6906081325
Add RVV128/RVV256 SIMD kernels for bit-packing unpack.
### What changes are included
- **CMake**: define `ARROW_RVV128/256/512_FLAGS`(`-march=rv64gcv_zvlXXb
-mrvv-vector-bits=zvl`), set
`ARROW_HAVE_RUNTIME_RVV*` on riscv64, add `append_runtime_rvv*_src`
macros, and apply the matching RVV compile flags to `bpacking_simd_128.cc` /
`bpacking_simd_256.cc`.
- **`bpacking_simd_internal.h`**: map `UNPACK_ARCH128`/`UNPACK_ARCH256` to
`unpack_rvv128`/`unpack_rvv256`.
- **`bpacking.cc`**: add `RVV128`/`RVV256` dynamic dispatch targets and
pre-dispatch scalar fallbacks keyed on `CpuInfo::RVV256`.
- **`bpacking_simd_128.cc` / `bpacking_simd_256.cc`**: define the RVV
kernels and per-VLEN scalar fallback heuristics.
### Testing / verification
- Build for riscv64 on VLEN=128(SG2044) and VLEN=256(SpacemiT) hardware.
- Existing `bpacking` unit tests (`bpacking_test.cc`) pass on supported
platforms.
### Benchmarks
Measured with `arrow-bpacking-benchmark` on riscv64, separately on a
VLEN=128 and a VLEN=256 machine. Each dataset covers 18 type/bit-width
combinations × 5 batch sizes (32, 64, 128, 256, 512) = 90 cases. Speedup is the
scalar (`NONE`) time divided by the RVV kernel time.
**Overall**
| Metric | VLEN=128 | VLEN=256 |
|---|---|---|
| Cases | 90 | 90 |
| Speedup ≥ 1.1× | 80 (89%) | 61 (68%) |
| Flat (0.97–1.1×) | 9 (10%) | 29 (32%) |
| Regression (< 0.97×) | 1 (1%) | 0 |
| Geometric-mean speedup | **1.90×** | **1.71×** |
| Best case | 7.84× (Uint16/8-bit/batch=512) | 6.98×
(Uint16/8-bit/batch=512) |
**Per type / bit width** (geometric mean across batch sizes, min–max in
parentheses)
| Type | Bits | VLEN=128 | VLEN=256 |
|---|---|---|---|
| Bool | 0 | 1.04× (0.95–1.22) | 1.05× (1.03–1.05) |
| Bool | 1 | 2.25× (1.46–3.03) | 2.24× (1.74–2.66) |
| Uint8 | 1 | 1.97× (1.52–2.25) | 2.89× (2.00–3.80) |
| Uint8 | 2 | 2.05× (1.52–2.39) | 2.85× (1.91–3.87) |
| Uint8 | 8 | 1.23× (1.18–1.30) | 1.43× (1.24–1.62) |
| Uint16 | 1 | 2.56× (1.76–3.24) | 2.37× (1.74–2.95) |
| Uint16 | 2 | 2.51× (1.81–3.09) | 2.33× (1.70–2.97) |
| Uint16 | 8 | 4.81× (2.62–7.84) | 4.46× (2.50–6.98) |
| Uint16 | 13 | 2.19× (1.10–4.08) | 1.62× (0.99–2.98) |
| Uint32 | 1 | 1.14× (1.08–1.19) | 1.02× (0.98–1.06) |
| Uint32 | 2 | 1.26× (1.16–1.36) | 1.09× (1.07–1.11) |
| Uint32 | 8 | 3.11× (1.96–4.57) | 2.11× (1.49–2.76) |
| Uint32 | 20 | 2.48× (1.70–3.47) | 1.59× (0.98–2.48) |
| Uint64 | 1 | 1.03× (1.00–1.14) | 1.00× (0.99–1.00) |
| Uint64 | 2 | 1.13× (1.12–1.14) | 0.99× (0.98–1.00) |
| Uint64 | 8 | 1.90× (1.47–2.38) | 1.48× (1.26–1.68) |
| Uint64 | 20 | 1.70× (1.29–2.20) | 1.16× (0.98–1.44) |
| Uint64 | 47 | 3.11× (1.91–4.35) | 2.20× (1.43–2.96) |
**Observations**
- The largest gains are for small bit widths (1/2-bit) and `Uint16`/8-bit,
where the medium kernel maps well onto RVV: up to 7.84× on VLEN=128 and 6.98×
on VLEN=256 at batch=512.
- `Uint64` with 1–2-bit packing is at parity or slightly slower than scalar
on VLEN=256. The generic medium kernel relies on byte swizzles plus per-lane
variable shifts, which do not map efficiently to RVV, while the compiler
auto-vectorizes the scalar loop well. This is why those cases use the scalar
fallback.
- The data confirms the exact fallback thresholds. On VLEN=256,
`Uint16`/13-bit/batch≤32 (0.99×), `Uint32`/20-bit/batch≤32 (0.98×) and
`Uint64`/20-bit/batch≤64 (0.98–0.99×) are at or below parity, whereas the same
cases are faster on VLEN=128 (1.10×, 1.70×, 1.29×) and at larger batches on
VLEN=256 (1.13× and above); hence the fallback is limited to VLEN=256 and small
batches.
- After the fallbacks, no case is below 0.98× on either platform, except the
Bool/0-bit/batch=128 edge case on VLEN=128 (0.95×, ~48 ns absolute, negligible).
- Absolute times are not comparable between the two datasets because they
were collected on different machines; only the per-platform speedups are
meaningful.
### AI disclosure:
Parts of this work were drafted with the assistance of an AI coding
assistant, reviewed and tested by me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]