Skip to content

perf: Add AVX2 SIMD acceleration for Kronecker operator - #120874

Merged
alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
philip-jingxin:perf/kronecker-x86-simd
Sep 22, 2026
Merged

alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
philip-jingxin:perf/kronecker-x86-simd

Conversation

@philip-jingxin

@philip-jingxin philip-jingxin commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Speed up Kronecker kernels using AVX2 SIMD instructions (1.9x to 2.5x higher throughput and 50% to 60% lower median latency).

Follows up on #119064

Detailed Description

This PR adds AVX2 SIMD optimizations for Kronecker kernels to support non-power-of-two dimensions (m=12 and 20):

  • AVX2 Vectorization: Replaced the scalar loop with 256-bit AVX2 intrinsics to process multiple array elements in parallel.
  • Codebase Consistency: Mirrored ClickHouse's existing Neon kernel implementation pattern to keep the architectural structure clean, maintainable, and fully backward-compatible with non-AVX2 hardware.

Testing

  • Passed all relevant unit and stateless tests across both scalar and AVX2 execution paths.

Benchmark Environment

  • CPU: 13th Gen Intel(R) Core(TM) i9-13900K (32 vCPUs, 36 MiB L3 cache)
  • Memory: 64 GB
  • OS / Kernel: Ubuntu 26.04 LTS / Linux 7.0.0-31-generic
  • Compiler: Clang 21.1.8
  • Benchmark Tool: clickhouse-benchmark

Benchmark Results

Ran 10,000 queries using clickhouse-benchmark on localhost:9000 with release build to compare the scalar baseline against the AVX2 SIMD implementation:

Benchmark Results

Test Case 1: Dimension 2560 (m = 20)

1. Throughput Comparison

Metric Baseline (Scalar) AVX2 Optimized Improvement
QPS (Queries/sec) 26.560 66.372 +149.89%
RPS (Rows/sec) 265,600.982 663,721.985 +149.89%
Throughput (MiB/s) 2,595.786 6,486.724 +149.89%

2. Latency Percentiles Comparison

Percentile Baseline (sec) AVX2 Optimized (sec) Latency Reduction
Min (0%) 0.139 0.048 -65.47%
P50 (Median) 0.149 0.060 -59.73%
P90 0.161 0.065 -59.63%
P95 0.165 0.072 -56.36%
P99 0.171 0.080 -53.22%
P99.99% (Max) 0.198 0.101 -48.99%

Test Case 2: Dimension 1536 (m = 12)

1. Throughput Comparison

Metric Baseline (Scalar) AVX2 Optimized Improvement
QPS (Queries/sec) 59.908 116.982 +95.27%
RPS (Rows/sec) 599,078.409 1,169,823.148 +95.27%
Throughput (MiB/s) 3,514.796 6,863.358 +95.27%

2. Latency Percentiles Comparison

Percentile Baseline (sec) AVX2 Optimized (sec) Latency Reduction
Min (0%) 0.062 0.028 -54.84%
P50 (Median) 0.066 0.033 -50.00%
P90 0.069 0.036 -47.83%
P95 0.073 0.040 -45.21%
P99 0.080 0.047 -41.25%
P99.99% (Max) 0.094 0.058 -38.30%

Workflow [PR]
Sync PR [sync-upstream/pr/120874]

Version info

  • Merged into: 26.10.1.437-master (included in 26.10 and later)

@clickhouse-gh clickhouse-gh Bot added comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... external Author is not a member of the ClickHouse organization labels Sep 18, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Sep 19, 2026
Comment thread src/Common/HadamardTransform.h Resolved
@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [41cec9d]

Summary: ✅


AI Review

Summary

This PR adds AVX2 implementations for the exact Kronecker Hadamard path used by randomHadamardTransform and the shared vector-quantization projection for dimensions of the form 2^k * 12 and 2^k * 20. I reviewed the current diff together with the prior discussion and do not see a remaining correctness, compatibility, or safety issue in the patch as it stands.

Missing context / blind spots
  • ⚠️ Most of the full PR CI matrix was still pending at review time; only Style check, Fast test, arm_tidy, and the build-profile diff had completed. A green x86 stateless run would close the remaining validation gap for the new default AVX2 path.
Final Verdict

✅ No new inline findings to post on the current patch.

LLVM Coverage Report

Measured on commit 41cec9d.

Metric Baseline Current Δ
Lines 88.00% 88.00% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 40/43 (93.02%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 41cec9d9f with master c22d746de (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 36 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 326a8522-4408-4e9c-bd4a-292a2a3c6bbe
  • MIRAI run: c50105eb-3fb6-489f-b4e8-519ed2b3c62d
  • PR check IDs:
    • clickbench_1295783_1790060774
    • clickbench_1295796_1790060774
    • clickbench_1295802_1790060774
    • tpch_adapted_1_official_1295808_1790060774
    • tpch_adapted_1_official_1295839_1790060775
    • tpch_adapted_1_official_1295853_1790060775

Comment thread src/Common/HadamardTransform.h Resolved
@philip-jingxin
philip-jingxin force-pushed the perf/kronecker-x86-simd branch 3 times, most recently from a95a16d to 8b968c4 Compare September 20, 2026 13:13
Comment thread src/Common/HadamardTransform.h Resolved
@alexey-milovidov alexey-milovidov mentioned this pull request Sep 21, 2026
1 task done
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 22, 2026
Merged via the queue into ClickHouse:master with commit c26d4c7 Sep 22, 2026
349 of 350 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... external Author is not a member of the ClickHouse organization pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants