Add ARM SVE detection and SVE dispatch infrastructure and SVE-optimized paths for ColumnVector filter, unary arithmetic, and findExtreme by chiranmoyf · Pull Request #97473 · ClickHouse/ClickHouse · GitHub
Skip to content

Add ARM SVE detection and SVE dispatch infrastructure and SVE-optimized paths for ColumnVector filter, unary arithmetic, and findExtreme#97473

Open
chiranmoyf wants to merge 1 commit into
ClickHouse:masterfrom
MonakaResearch:sve-enablement-and-optimization
Open

Add ARM SVE detection and SVE dispatch infrastructure and SVE-optimized paths for ColumnVector filter, unary arithmetic, and findExtreme#97473
chiranmoyf wants to merge 1 commit into
ClickHouse:masterfrom
MonakaResearch:sve-enablement-and-optimization

Conversation

@chiranmoyf

@chiranmoyf chiranmoyf commented Feb 20, 2026

Copy link
Copy Markdown

Changelog category (leave one):

  • Performance Improvement

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

  1. Add ARM SVE detection and SVE dispatch infrastructure on AArch64.

  2. Rename USE_MULTITARGET_CODE to USE_X86_MULTITARGET_CODE and introduce USE_ARM_MULTITARGET_CODE for AArch64.

  3. Add MULTITARGET_FUNCTION_ARM_SVE and extend MULTITARGET_FUNCTION_X86_V4_V3 to MULTITARGET_FUNCTION_X86_V4_V3_ARM_SVE, and MULTITARGET_FUNCTION_X86_V4 to MULTITARGET_FUNCTION_X86_V4_ARM_SVE.

  4. Add dispatchers for unary arithmetic and findExtreme functions. Performance improvements for several example functions on m7g.8xlarge - pastila.

  5. Optimize ColumnVector filter operation using svcompact.
    svcompact only supports 4/8-byte datatypes. Testing shows performance improvement for 4-byte datatypes such as UInt32, Float32, and IPv4. Performance improvements on m7g.8xlarge - pastila.

@clickhouse-gh

clickhouse-gh Bot commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Feb 20, 2026
@rienath rienath self-assigned this Feb 20, 2026
@Algunenano

Algunenano commented Feb 23, 2026

Copy link
Copy Markdown
Member

As I'm working on #90043 I'm wondering if it doesn't make more sense to make sve a requirement for the default build instead. We'd drop support for graviton 2, which is old and noticebly worse than 3 and 4. And we would not need dispatch, and have better code all around.

Testing it here: #97781

@rienath

rienath commented Mar 2, 2026

Copy link
Copy Markdown
Member

@chiranmoyf could you please take a look why the build in CI fails?

@ajeyabsf

Copy link
Copy Markdown

@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.

  1. Add '-bugprone-macro-repeated-side-effects' to clang-tidy.
  2. Add a NOLINT comment to each of the function call sites. There are 14 of them, and the comment would have to be added to each place. It might have to be added if there are new invocations in future.

What do you think of these solutions? Do you have any other solution?

@rienath

rienath commented Mar 12, 2026

Copy link
Copy Markdown
Member

@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 // NOLINT(bugprone-macro-repeated-side-effects) at each call site to be as surgical as possible. The only downside is that future contributors would need to include it too. But in practice, people copy-paste existing invocations of the macro anyway, so the NOLINT will come along for the ride

@rienath rienath changed the title Adds SVE support for ColumnVector, aggregate sum, function unary arithmetic and functions comparison. Add SVE support for ColumnVector, aggregate sum, function unary arithmetic and functions comparison Mar 12, 2026
@rageshh-fj rageshh-fj force-pushed the sve-enablement-and-optimization branch from 5c855c8 to dc6b2aa Compare March 19, 2026 16:57
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Mar 19, 2026
@chiranmoyf

Copy link
Copy Markdown
Author

@rienath /// NOLINT is used to suppress MULTITARGET_FUNCTION_BODY macro warnings in AggregateFunctionSum.h. Therefore, we have added the same instead of /// NOLINT(bugprone-macro-repeated-side-effects) in ColumnVector.cpp and other places.

Comment thread cmake/cpu_features.cmake Outdated

@rienath rienath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread cmake/cpu_features.cmake Outdated
Comment thread cmake/cpu_features.cmake Outdated
Comment thread src/Common/TargetSpecific.h Outdated
Comment thread src/Common/TargetSpecific.h
Comment thread src/Common/TargetSpecific.h
Comment thread src/AggregateFunctions/AggregateFunctionSum.h Outdated
Comment thread src/Common/TargetSpecific.h
Comment thread src/Common/TargetSpecific.h Outdated
Comment thread src/Common/CPUID.h
@rageshh-fj rageshh-fj force-pushed the sve-enablement-and-optimization branch from dba3fb9 to bd2e757 Compare April 4, 2026 14:22
@chiranmoyf chiranmoyf requested review from rienath and rschu1ze April 6, 2026 06:08

@rienath rienath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread cmake/cpu_features.cmake Outdated
Comment thread src/Common/TargetSpecific.cpp
Comment thread src/Common/findExtreme.cpp Outdated
/// 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
image

Comment thread src/Functions/FunctionUnaryArithmetic.h Outdated
using ArrayA = typename ColVecA::Container;
using ArrayC = typename ColVecC::Container;

MULTITARGET_FUNCTION_X86_V4_V3(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

image

Comment thread src/Columns/ColumnVector.cpp
@rageshh-fj rageshh-fj force-pushed the sve-enablement-and-optimization branch from bd2e757 to cdb82ba Compare April 23, 2026 05:04
@chiranmoyf

chiranmoyf commented Apr 23, 2026

Copy link
Copy Markdown
Author

As far as I can tell, we have no existing test that isolates this path ...

Added the queries in filter_on_column_vector.xml file. Datatypes starting 1 byte to 8 bytes are covered.
Other queries involving aggregation and unary arithmetic functions were taken from existing xml files.

It'd be great to include multiple element widths (not only 4 bytes)

We cannot use svcompact directly. Maybe a combination of other intrinsics might work. We can look into it once the macros infrastructure is in place.

Comment thread src/AggregateFunctions/AggregateFunctionSum.h
Comment thread src/Functions/FunctionsComparison.h
@chiranmoyf chiranmoyf requested a review from rienath April 23, 2026 08:56
@chiranmoyf chiranmoyf changed the title Add SVE support for ColumnVector, aggregate sum, function unary arithmetic and functions comparison Add SVE support for ColumnVector, aggregate and function unary arithmetic Apr 23, 2026
@chiranmoyf chiranmoyf changed the title Add SVE support for ColumnVector, aggregate and function unary arithmetic Add ARM SVE detection and SVE dispatch infrastructure and SVE-optimized paths for ColumnVector filter, unary arithmetic, and findExtreme Apr 25, 2026
@chiranmoyf

Copy link
Copy Markdown
Author

Hi @rienath, just following up, could you please take another look when you get a chance?

@rienath rienath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments. Could you also please merge the master? It'd be also great if you gave me rights to commit to this branch, but it's ok if you don't. When CI is red because of some other problems, I'd wait for the fix and merge the master without pinging you. Thanks!

Comment thread src/AggregateFunctions/AggregateFunctionSum.h
Comment thread src/Functions/FunctionsComparison.h
Comment thread tests/performance/filter_on_column_vector.xml Outdated
Comment thread cmake/cpu_features.cmake Outdated
…hs for ColumnVector filtering, unary arithmetic, and findExtreme
@abhijain1204fujitsu abhijain1204fujitsu force-pushed the sve-enablement-and-optimization branch from cdb82ba to 4e71de5 Compare June 19, 2026 03:52
{
svbool_t filt_mask = svcmpne(FILT_LOAD_PRED,
svld1ub_u32(FILT_LOAD_PRED, reinterpret_cast<const uint8_t *>(filt_pos + i)), 0);
svuint32_t vec = svld1(ALL_TRUE, reinterpret_cast<const uint32_t *>(data_pos + i));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ColumnVector<T>::filter now routes every sizeof(T) == 4 column through this SVE path, including Float32 and IPv4 from the new performance test, but the compact loop accesses the column storage through uint32_t *. That is not type-compatible for Float32 or the IPv4 strong typedef, so optimized builds can treat this as a strict-aliasing violation and miscompile the filter result.

Please keep the SVE load/store type-compatible, for example by selecting svfloat32_t / svint32_t / svuint32_t with if constexpr and handling strong typedefs through their actual underlying storage, or by restricting this fast path to the 4-byte types that can be legally accessed this way.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SVE load/store and svcompact just perform data movement. No arithmetic operations are being performed. Still, if this causes miscompilation, we can use if constexpr, but this will tie the implementation to specific data types.

@rienath Apologies for the delayed rebase. Due to a recent commit, there were many changes to the AVX infrastructure, causing many merge conflicts, especially due to the renaming of USE_MULTITARGET_CODE to USE_X86_MULTITARGET_CODE. Can we decouple the ColumnVector filter portion from the rest of the PR (i.e., SVE infrastructure, optimized paths for unary arithmetic, findExtreme, etc.)? They already have proven benefit from the perf scripts, and this will make the PR more manageable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chiranmoyf yes, go for it. Would it be possible to leave at least one path s.t. we can verify that it indeed works after the changes?

@clickhouse-gh

clickhouse-gh Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.20% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 151/168 (89.88%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 10 line(s) · Uncovered code

Full report · Diff report

@clickhouse-gh

This comment has been minimized.

@rienath rienath self-assigned this Jun 23, 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 manual approve Manual approve required to run CI pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants