Repository navigation
Add ARM SVE infrastructure and SVE-optimized paths for unary arithmetic and findExtreme - #97473
chiranmoyf wants to merge 5 commits into
Conversation
|
Workflow [PR], commit [f730450] Summary: ❌
AI ReviewSummaryThis PR adds AArch64 SVE detection and runtime-dispatched SVE-specialized variants for unary arithmetic and Findings❌ Blockers
Missing context / blind spots
Final Verdict❌ Changes required before merge. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 22/29 (75.86%) · Uncovered code |
|
@chiranmoyf could you please take a look why the build in CI fails? |
|
@rienath, the error is from clang-tidy. The error is related to MULTITARGET_FUNCTION_X86_V4_V3_SVE. clang-tidy is flagging that FUNCTION_BODY is expanded multiple times in MULTITARGET_FUNCTION_X86_V4_V3_SVE. There are two solutions possible to this.
What do you think of these solutions? Do you have any other solution? |
|
@ajeyabsf thanks for taking a look. We expanded multiple times with x86 too, but looks like it didn't fire because our CI runner is on ARM. Let's add |
5c855c8 to
dc6b2aa
Compare
|
@rienath |
rienath
left a comment
There was a problem hiding this comment.
I've partially reviewed the PR and will continue once these comments are addressed. Some of them are questions / calls for discussion, so feel free to answer and ping me
dba3fb9 to
bd2e757
Compare
There was a problem hiding this comment.
The PR looks great! I've left a few nits, but we are almost done.
Regarding the pastila links with performance tests that you left in PR description: could you please add them as .xml performance tests in tests/performance folder? Especially the ones benchmarking ColumnVector. As far as I can tell, we have no existing test that isolates this path. It'd be great to include multiple element widths (not only 4 bytes). This PR doesn't target them all, but it would give us broader coverage for future work
| /// We see no benefit from using AVX512BW or AVX512F (over AVX2), so we only declare SSE and AVX2 | ||
| if (isArchSupported(TargetArch::x86_64_v3)) | ||
| return findExtremeImpl_x86_64_v3<T, ComparatorClass, add_all_elements, add_if_cond_zero>(ptr, condition_map, start, end); | ||
| #elif USE_ARM_MULTITARGET_CODE |
| using ArrayA = typename ColVecA::Container; | ||
| using ArrayC = typename ColVecC::Container; | ||
|
|
||
| MULTITARGET_FUNCTION_X86_V4_V3( |
bd2e757 to
cdb82ba
Compare
Added the queries in
We cannot use |
|
Hi @rienath, just following up, could you please take another look when you get a chance? |
|
@chiranmoyf @abhijain1204fujitsu thanks for working on this! Before we merge, I'd like to resolve conflicts and make a few minor changes. Moreover, we cannot merge with red CI, so we'd need to wait for relevant fixes and merge master, perhaps multiple times. To avoid friction, could you please give me rights to commit to this branch ( |
|
@rienath, we're working on getting you commit rights. In the meantime, please let us know if there are any specific changes you'd like us to make. |
| */ | ||
| #define DECLARE_ARM_SVE_SPECIFIC_CODE(...) | ||
|
|
||
| #elif ENABLE_MULTITARGET_CODE && defined(__GNUC__) && defined(__aarch64__) |
There was a problem hiding this comment.
USE_ARM_MULTITARGET_CODE becomes 1 on every __aarch64__ build here, but haveSVE only reports TargetArch::ARM_SVE on Linux (src/Common/CPUID.h returns false on Darwin/FreeBSD). As a result, supported non-Linux AArch64 builds such as arm_darwin still compile all of the new *_ARM_SVE clones from FunctionUnaryArithmetic.h and findExtreme.cpp, but runtime dispatch can never select them.
In FunctionUnaryArithmetic.h alone that duplicates every unary-op instantiation across a long list of translation units for code that is unreachable on those platforms. Please either gate this AArch64 multitarget branch to OSes where haveSVE can return true, or add non-Linux SVE detection so codegen and runtime selection stay aligned.
There was a problem hiding this comment.
Added SVE runtime detection for FreeBSD. Darwin doesn't support SVE yet, so SVE is enabled only on Linux and FreeBSD.
There was a problem hiding this comment.
src/Common/TargetSpecific.h:404 is still #elif ENABLE_MULTITARGET_CODE && defined(__GNUC__) && defined(__aarch64__) without the Linux/FreeBSD guard you added above, and src/Common/TargetSpecific.h:418-447 still expands every MULTITARGET_FUNCTION_*_ARM_SVE call site into an _ARM_SVE clone.
So FunctionUnaryArithmetic.h and findExtreme.cpp still emit SVE-specific declarations on arm_darwin even though the earlier block leaves USE_ARM_MULTITARGET_CODE=0 there. Because SVE_FUNCTION_SPECIFIC_ATTRIBUTE is only defined in the Linux/FreeBSD branch, this is now a compile-time failure on Darwin rather than just unreachable code.
…ic and findExtreme
…and TargetSpecific::SVE to TargetSpecific::ARM_SVE Renamed ENABLE_SVE to ENABLE_SVE_GLOBALLY in cpu_features.cmake. Renamed TargetSpecific::SVE to TargetSpecific::ARM_SVE and TargetArch::SVE to TargetArch::ARM_SVE to mirror the x86_64_* arch-family prefix convention and match the _ARM_SVE function-name suffix. Updated comments in TargetSpecific.h.
…ver FreeBSD via elf_aux_info
f35cdb8 to
5c58f4a
Compare
`DB::iota` and `DB::iotaWithStep` are loop-carried fills that clang auto-vectorises on every target, but on AArch64 it interleaves them 2x where the shipped `-march=x86-64-v3` uses 4x. Reported by @ egor-click in ClickHouse#116581 with the AArch64 measurements and this patch: 1.21x on `SELECT count() FROM numbers(3000000000)` and 1.13x on `sum(number)` on Graviton3. Those timings are his, so the Performance Comparison job arbitrates. The cause is not the absence of `-mcpu=` on AArch64 that the issue identifies. Measured on the pinned clang-22, `-mcpu=neoverse-v1`, `-mtune=neoverse-v1` and `-mcpu=neoverse-n1` all leave the interleave factor at 2. The deciding property is the LLVM subtarget feature `FeatureMaxInterleaveFactor4` (`contrib/llvm-project/llvm/lib/Target/AArch64/AArch64Features.td:926`), which raises `MaxInterleaveFactor` from its AArch64 default of 2 and which processors opt into individually: Neoverse-V2, Apple M1 and Cortex-A57 carry it, Neoverse-N1, Neoverse-V1 and Neoverse-N2 do not. No flag available to this repository reaches it, so the general fix belongs upstream in `AArch64Processors.td` and a per-loop hint is the only lever here. The hint is arch-guarded, which the patch in the issue is not. On this translation unit it is byte-identical at `x86-64-v3` and `-v4`, but unguarded it changes 367 instruction lines at `x86-64-v2` and 380 at level 1, and level 1 is what `BuildTypes.AMD_COMPAT` ships. With the same `-march`, `arm64-apple-macos11` already interleaves 4x, so the hint is inert on Darwin. The guard therefore matches the two existing positive-hint sites in `FunctionsConversion.h` exactly. No `-Wpass-failed` suppression is needed: a bare `interleave_count` compiles clean under this build's `-Weverything -Werror`, unlike the `vectorize_width` those sites use. Verified on the AArch64 object by execution rather than by argument. It has no undefined symbols, so it links freestanding and runs under `qemu-aarch64-static`: 13356900 element comparisons against an independent scalar reference over counts 0 to 2100 for `UInt8`, `UInt32` and `UInt64`, with wrapping first values and steps including 0 and the maximum, and a sentinel region past `count`. Zero mismatches and zero overruns, hash identical to the unmodified object, while the same harness reddens for a `value += 2` mutant and for an `i <= count` mutant. All six vectorised loops move from `interleaved count: 2` to `4` with no change in vectorisation width or loop count, and each instantiation goes from one `stp` to two, that is from two accumulators to four. `NO_INLINE` is kept, and every hot loop still opens on a `.p2align 5` boundary, matching the global `-falign-loops=32`. The two `UInt32` instantiations gain one extra aligned block, which is the shape the `UInt8` ones already had. `src/Common/findExtreme.cpp` is deliberately not touched. The reporter scoped that half as review input on ClickHouse#97473, which restructures that file behind `MULTITARGET_FUNCTION` and does not touch `src/Common/iota.cpp`. A preprocessor guard could not keep this hint out of its SVE clone in any case, because `__ARM_FEATURE_SVE` is undefined inside a `target("+sve")` clone even when that clone is SVE-vectorised. Residuals not resolved here: small-`count` callers are unmeasured, and of those `translate` and `arrayRandomSample` have no performance test at all; `iotaWithStep` has no performance coverage of its own and is changed for symmetry with the loop beside it; AArch64 cores other than Graviton3 are untested, so the direction should hold but not the magnitude. Related: ClickHouse#116581 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes82 object files changed (+308.57 KiB total), 0 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units333 translation units recompiled, 1316 s compile time in total, 333 of them have a recent master baseline. |
|
Dear @rienath, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |


Add ARM SVE detection and SVE dispatch infrastructure on AArch64.
Add
MULTITARGET_FUNCTION_ARM_SVEand extendMULTITARGET_FUNCTION_X86_V4_V3toMULTITARGET_FUNCTION_X86_V4_V3_ARM_SVE, andMULTITARGET_FUNCTION_X86_V4toMULTITARGET_FUNCTION_X86_V4_ARM_SVE.Add dispatchers for unary arithmetic and findExtreme functions. Performance improvements for several example functions on m7g.8xlarge - pastila.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improve performance of unary arithmetic functions and
min/maxaggregation on AArch64 CPUs with SVE support (e.g. AWS Graviton 3) via runtime-dispatched SVE implementations.Workflow [PR]
Sync PR [sync-upstream/pr/97473]