Skip to content

Enable fastops vectorized math on AArch64 and on FreeBSD/Darwin - #98230

Merged
Algunenano merged 17 commits into
masterfrom
fastops_more
Mar 27, 2026
Merged

Algunenano merged 17 commits into
masterfrom
fastops_more

Conversation

@Algunenano

@Algunenano Algunenano commented Feb 27, 2026 •

Copy link
Copy Markdown
Member

Enable the fastops vectorized math library on AArch64 builds (NEON + SVE
runtime dispatch) and remove the FreeBSD/Darwin exclusion on x86_64. Previously
fastops was limited to x86_64 Linux; now it works on all supported platforms.

Changes:

  • Update fastops submodule to include AArch64 NEON/SVE backends and new Exp2/Exp10 functions
  • Extend CMake gating from ARCH_AMD64 AND NOT OS_FREEBSD AND NOT OS_DARWIN to ARCH_AMD64 OR (ARCH_AARCH64 AND NOT NO_ARMV81_OR_HIGHER) — this enables fastops on x86 FreeBSD/Darwin (previously excluded) and on ARM (ARMv8.1+ required)
  • Add ops_neon.cpp and ops_sve.cpp (with -march=armv8-a+sve) to ARM builds; SVE is Linux-only since arm_sve.h is not available on Darwin/FreeBSD toolchains
  • Move ops_plain.cpp and avx_id.cpp into the x86 block since they are x86-specific

Related: ClickHouse/fastops#6

Changelog category (leave one):

  • Performance Improvement

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

Vectorized math functions (exp, log, sigmoid, tanh) are now accelerated on AArch64 (using NEON/SVE) and on FreeBSD/Darwin, where they previously used a slower scalar fallback

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.322

The upstream `fastops` library now supports ARM via NEON intrinsics.
Enable it in our CMake for `ARCH_AARCH64` builds (when
`NO_ARMV81_OR_HIGHER` is not set, since NEON requires ARMv8.1+).

On ARM, only `ops_neon.cpp` and `fastops.cpp` are compiled — the
x86-only `ops_plain.cpp` and `avx_id.cpp` are skipped.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@Algunenano Algunenano self-assigned this Feb 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0521bb6]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan_ubsan, distributed plan, parallel, 1/2) failure
02967_parallel_replicas_joins_and_analyzer FAIL cidb, issue ISSUE EXISTS
Upgrade check (amd_release) failure
Changed MergeTree settings are not reflected in the settings changes history (see changed_merge_tree_settings.txt) FAIL cidb IGNORED
New MergeTree settings are not reflected in settings changes history (see new_merge_tree_settings.txt) FAIL cidb IGNORED

AI Review

Summary

This PR enables fastops vectorized math acceleration on AArch64 (NEON, plus Linux-only SVE dispatch) and broadens platform availability by removing prior non-Linux exclusions where supported by toolchains. Based on the final diff and discussion context, I did not find new correctness, safety, concurrency, performance, or compatibility issues requiring changes.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements submodule changed At least one submodule changed in this PR. labels Feb 27, 2026
@Algunenano Algunenano changed the title Enable fastops on AArch64 with NEON, use it for exp2/exp10 Enable fastops on AArch64 with NEON Mar 2, 2026
@Algunenano

Copy link
Copy Markdown
Member Author

After passing all tests in x86, NEON and SVE I decide to break this PR into a) enabling fastops in ARM and other OSs if possible and b) considering support for exp2 and exp10. The reason is result differences in these new functions as well as type changes. It's easier to verify and consider each change individually

@Algunenano Algunenano changed the title Enable fastops on AArch64 with NEON Enable fastops on AArch64 with NEON/SVE Mar 2, 2026
Move the `plain/ops_plain.cpp` and `core/avx_id.cpp` sources into the
main `ARCH_AMD64` block, keeping each architecture's files together.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@Algunenano

Copy link
Copy Markdown
Member Author
image

@Algunenano
Algunenano marked this pull request as ready for review March 3, 2026 16:41
@Algunenano

Copy link
Copy Markdown
Member Author

Multiple infra issues. I'll restart the CI

@Algunenano

Copy link
Copy Markdown
Member Author
image

@Algunenano Algunenano removed their assignment Mar 12, 2026
Comment thread contrib/fastops-cmake/CMakeLists.txt Resolved
Comment thread contrib/fastops-cmake/CMakeLists.txt Resolved
Algunenano added a commit to Algunenano/ClickHouse that referenced this pull request Mar 15, 2026
The `docker compose up -d` calls for ZooKeeper and Keeper containers
had no retry logic, unlike image pulls which already use `retry()`.
When Docker-in-Docker's network subsystem isn't fully initialized,
the transient "network ... not found" error immediately fails all
tests in the shard.

Wrap both ZooKeeper compose-up calls (regular and secure) with the
same `retry()` decorator, using 3 retries with 3s base delay.

Seen in ClickHouse#98230:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98230&sha=3a1a2a77d4ecaffb47629f3d75243946e1c36100&name_0=PR&name_1=Integration%20tests%20%28amd_binary%2C%201%2F5%29

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@Algunenano Algunenano changed the title Enable fastops on AArch64 with NEON/SVE Enable fastops vectorized math on AArch64 and on FreeBSD/Darwin Mar 25, 2026
@Algunenano

Copy link
Copy Markdown
Member Author

Performance tests look fine, but I'm going to have a look at log since it was worse in some cases and I have the feeling fastops might not be helping in that case, so better to confirm:

image

@Algunenano

Copy link
Copy Markdown
Member Author

As I remember seeing, log doesn't seem to be faster. At least the one time it was run, and the rest are fine:

  Here are all ARM results for exp, log, sigmoid, tanh across all commits in PR #98230:                                                    
                                                                                                                                           
  ┌──────────┬────────────────────────────────────────────────┬─────────┬─────────┬───────────────┬──────────────┐                         
  │  Commit  │                    Function                    │ Old (s) │ New (s) │    Change     │ Significant? │                         
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ d603ce78 │ tanh(toFloat32)                                │ 0.397   │ 0.153   │ -2.59x faster │ YES          │                         
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ d603ce78 │ sigmoid(toFloat64)                             │ 0.396   │ 0.217   │ -1.83x faster │ YES          │                         
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ d603ce78 │ exp(number)                                    │ 0.373   │ 0.337   │ -9.6%         │ no           │                         
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ d2900a17 │ exp(toFloat32)                                 │ 0.324   │ 0.191   │ -1.70x faster │ YES          │                         
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ d2900a17 │ sigmoid(number)                                │ 0.301   │ 0.211   │ -1.43x faster │ YES          │
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ 0459e117 │ tanh(toFloat32)                                │ 0.328   │ 0.142   │ -2.31x faster │ YES          │
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ 0459e117 │ exp(number)                                    │ 0.303   │ 0.326   │ +7.5%         │ no           │
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ c5b06b3a │ tanh(toFloat32)                                │ 0.324   │ 0.155   │ -2.10x faster │ YES          │
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ c5b06b3a │ tanh(number)                                   │ 0.300   │ 0.231   │ -1.30x faster │ YES          │
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ c5b06b3a │ log(number+1)                                  │ 0.523   │ 0.643   │ +1.23x slower │ YES          │
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ 79cdc4bb │ tanh(number)                                   │ 0.304   │ 0.224   │ -1.36x faster │ YES          │
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ 3a1a2a77 │ (no exp/log/sigmoid/tanh landed in ARM shards) │         │         │               │              │
  ├──────────┼────────────────────────────────────────────────┼─────────┼─────────┼───────────────┼──────────────┤                         
  │ 3d57462d │ (no exp/log/sigmoid/tanh landed in ARM shards) │         │         │               │              │
  └──────────┴────────────────────────────────────────────────┴─────────┴─────────┴───────────────┴──────────────┘  

I'm having a look

@Algunenano

Copy link
Copy Markdown
Member Author

Addressed the regression in log. The problem was that in Graviton 3 SVE code was always faster than NEON as it uses 256-bit SVE, but on Graviton-4 they use 128-bit SVE and this is either slower or has the same performance of NEON. So it's solved by dispatching to SVE only in the case it's faster, while keeping NEON for anything else.

@Algunenano

Algunenano commented Mar 27, 2026 •

Copy link
Copy Markdown
Member Author

Literally none of the affected functions run in this performance test batch after the fix.

@Algunenano

Copy link
Copy Markdown
Member Author

Nice:
image

@antonio2368 antonio2368 self-assigned this Mar 27, 2026
@Algunenano
Algunenano enabled auto-merge March 27, 2026 14:10
@Algunenano
Algunenano added this pull request to the merge queue Mar 27, 2026
@alexey-milovidov
alexey-milovidov removed this pull request from the merge queue due to a manual request Mar 27, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Let's fix the Upgrade check first.

@Algunenano
Algunenano added this pull request to the merge queue Mar 27, 2026
Merged via the queue into master with commit 627bb97 Mar 27, 2026
147 of 149 checks passed
@Algunenano
Algunenano deleted the fastops_more branch March 27, 2026 14:31
@Algunenano

Copy link
Copy Markdown
Member Author

Let's fix the Upgrade check first.

It's already reported and @Avogar is working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants