Repository navigation
Conversation
The ALP SIMD kernels are written with SIMDe's AVX2 API, but TsFile builds
for the portable x86-64 baseline, so SIMDe compiles them into its portable
fallback. Mirror the RLE packer's dispatch: add native AVX2 copies of
EncodeValues, DecodeValues and the bit-unpack kernels in alp_avx2.h,
compiled with __attribute__((target("avx2"))), and select them at runtime
through common::cpu_has_avx2(). The binary's ISA floor is unchanged;
non-x86 targets, MSVC and CPUs without AVX2 keep the SIMDe path, and both
paths encode identical bytes and decode bit-identical values.
Measured on an i7-11700 with the default build (no -mavx2), ALP block size
(1024 values) per call: float encode 3.3-6.2x, float decode 1.4-1.6x,
double encode 1.2-1.6x, double decode 1.03-1.10x, uint32 unpack 2.9-3.5x,
uint64 unpack 2.7-3.4x.
Add differential AVX2-vs-SIMDe tests over all factor/exponent pairs,
special values, counts around the vector-width boundaries and every safe
bit width, plus malformed-exception status checks. Update the ALP design
doc and add cpp/bench_mark/alp_avx2_benchmark.cc.
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
3 open issues
_mm256_i32gather_epi64loads 8 bytes per lane frombody + byte_offset. For bit-packed buffers… · New This test only checks that AVX2 output matches SIMDe output, but it doesn’t validate correctness vs… · New New C++ code should prefernullptroverNULLfor pointer arguments, especially in templated… · New
What changed in this PR
Adds runtime AVX2 dispatch for ALP SIMD kernels (keeping a portable SIMDe fallback), plus differential tests and a micro-benchmark to validate/measure the native AVX2 path.
Changes:
- Introduces native AVX2 implementations (
alp_avx2.h) and runtime dispatch wrappers inalp_simde.h. - Adds AVX2-vs-SIMDe differential tests (encode/decode + unpack) gated on AVX2 dispatch support.
- Adds an ALP SIMD micro-benchmark target and documents how to run it.
| File | Description |
|---|---|
| cpp/test/encoding/alp_simde_test.cc | Adds differential tests comparing AVX2 kernels vs SIMDe fallback. |
| cpp/src/encoding/alp/alp_simde.h | Adds runtime dispatch wrappers and separates “SIMDe fallback” kernel naming. |
| cpp/src/encoding/alp/alp_avx2.h | New native AVX2 kernels compiled with target attributes and used via dispatch. |
| cpp/docs/alp-codec-design.md | Updates design doc to describe AVX2 copies, runtime dispatch, and new tests/bench. |
| cpp/bench_mark/alp_avx2_benchmark.cc | New benchmark executable to compare SIMDe vs AVX2 performance per entry point. |
| cpp/bench_mark/README.md | Documents how to build/run the new AVX2 benchmark. |
| cpp/CMakeLists.txt | Adds alp_avx2_benchmark target under BUILD_BENCHMARK when ENABLE_SIMD is on. |
Review effort: Lite
Document the padded-body contract the gather-based unpack kernels rely on, compare the AVX2 unpack output against the packed input instead of only against SIMDe, and use nullptr in the new code.
…time-dispatch-2added # Conflicts: # cpp/CMakeLists.txt
…time-dispatch-2added # Conflicts: # cpp/bench_mark/README.md
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
5 open issues
On 32-bit x86, convertingdoubletoint64_tviastatic_cast<int64_t>is undefined behavior… · New These differential decode checks passbitmap_ptr=nullptrwhensimde_count==0. That can mask… · New This is C++ code; prefernullptroverNULLfor pointer literals to avoid overload ambiguity and… · New This is C++ code; prefernullptroverNULLfor pointer literals to avoid overload ambiguity and… · Newvallis used as an all-ones mask inxoroperations alongside 64-bit lane values (e.g.,… · New
3 resolved since last review
Review effort: Lite
Restrict ALP AVX2 dispatch to x86-64 so 32-bit x86 cannot reach an undefined double-to-int64 cast, always pass the exception bitmap to the differential decode test so a wrongly set bit with exception_count == 0 is caught, use nullptr in the benchmark, and use an epi64 all-ones mask in the double kernel.
The second review round restricted the ALP AVX2 kernels to x86-64; update the remaining comments, benchmark output and docs that still referred to x86 generally.
The AVX2 kernel converts int64 to double with the scalar cvtsi2sd instruction while SIMDe uses split arithmetic; add a regression test that decodes INT64_MIN/MAX and powers of two through both kernels and the scalar reference. Also finish the x86-64 wording in the benchmark build comment and design doc.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
This computesavx2_mps / simde_mpswithout guarding againstsimde_mps == 0.0. On platforms with… · New This stores a__m256iinto anint64_t[4]viareinterpret_cast<__m256i*>, which relies on… · New The helper continues execution after anEncodeValuesfailure because it usesEXPECT_EQ. If this… · New
5 resolved since last review
On 32-bit x86, convertingdoubletoint64_tviastatic_cast<int64_t>is undefined behavior… These differential decode checks passbitmap_ptr=nullptrwhensimde_count==0. That can mask…vallis used as an all-ones mask inxoroperations alongside 64-bit lane values (e.g.,… This is C++ code; prefernullptroverNULLfor pointer literals to avoid overload ambiguity and… This is C++ code; prefernullptroverNULLfor pointer literals to avoid overload ambiguity and…
Review effort: Lite
Guard the benchmark speedup column against a zero SIMDe rate, copy the converted int64 lanes with std::memcpy instead of aliasing a __m256i store, and make the test encode helpers return a status so the caller can assert fatally instead of continuing after a failed encode.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
3 resolved since last review
Review effort: Lite
The scalar tails of the SIMDe and AVX2 encode kernels left encoded[i] untouched on the exception path while the vector body and the scalar reference write 0. Zero them for deterministic output, and assert it in the differential test by pre-filling the output buffers with a sentinel.



Summary
The ALP SIMD kernels are written with SIMDe's AVX2 API, but TsFile builds for the portable x86-64 baseline, so SIMDe compiles them into its portable fallback. This mirrors the RLE packer's existing runtime dispatch (
cpp/src/encoding/int64_packer.h):cpp/src/encoding/alp/alp_avx2.hadds native AVX2 copies ofEncodeValuesandDecodeValues(float,double) plus theUnpackkernels (uint32_t,uint64_t), compiled withTSFILE_TARGET_AVX2(__attribute__((target("avx2")))).AlpSimdKernel/AlpSimdUnpackKernelpick the AVX2 copy once per batch call throughcommon::cpu_has_avx2().ALP_AVX2_DISPATCHgates the ALP kernels to x86-64.-mavx2/-march=nativeis added; the binary's ISA floor is unchanged. Non-x86-64 targets (including 32-bit x86), MSVC and CPUs without AVX2 keep the SIMDe kernels. Both paths encode identical bytes and decode bit-identical values.AlpSimdeKernel/AlpSimdeUnpackKerneland stay untouched as the fallback.Double kernels process four lanes. AVX2 has no packed int64 <-> double conversion (AVX-512DQ), so the per-lane conversion uses the same scalar instruction as the reference, preserving bit patterns.
Benchmarks
cpp/bench_mark/alp_avx2_benchmark.cc, default build (no-mavx2), i7-11700, GCC 9.4,ALP_BLOCK_SIZE(1024) values per call, one warmup plus a calibrated batch per row. Every row verifies that the AVX2 output matches SIMDe.Double decode stays on the same order of magnitude because it is conversion-bound: it cannot use a packed int64 -> double instruction on AVX2 (a second run measured 0.97x/1.05x/1.04x, i.e. within run-to-run noise). An all-vector 32-bit split conversion was tried and reverted: it did not help decode and dropped double encode from ~1.5x to ~1.26x.
Tests
AlpAvx2Testdifferential tests call the AVX2 and SIMDe kernels directly on the same inputs and compare encoded arrays, bitmaps, exception bit patterns and decoded values: all factor/exponent pairs, decimal/high-entropy streams, NaN/±Inf/-0.0/subnormals/max, counts 0..1024 around the 8-lane (float) and 4-lane (double) boundaries, every safe bit width for both unpack widths, and malformed exception statuses. A dedicated case pins the int64 -> double conversion at INT64_MIN/MAX and powers of two against both SIMDe and the scalar reference. Decode tests always pass the exception bitmap when one exists, so a wrongly set bit withexception_count == 0fails. They skip on CPUs without AVX2; the existingAlpSimdeTestcases also run through the dispatcher../mvnw clean verify -P with-java,with-python -Denable.lzma2=ONon the merged tree: BUILD SUCCESS (Java 1119 tests, C++ CTest 1624/1624, Python 610 passed/16 skipped, checkstyle/spotless/RAT clean).-DENABLE_ASAN=ON, RelWithDebInfo) full C++ suite on the merged tree: 1619/1619, no sanitizer reports.objdumpconfirms the AVX2 kernels are separate target-attributed symbols usingvpgatherdq/vpsrlvq/vpermps; they are not inlined into baseline callers.Docs
cpp/docs/alp-codec-design.mdpreviously said there was no runtime dispatch; the SIMD Plan section now describes the AVX2 copies, the dispatcher, the x86-64 restriction and the fallback.cpp/bench_mark/README.mddocuments the new benchmark.