-
Notifications
You must be signed in to change notification settings - Fork 4.1k
GH-50026: [C++][Parquet] SIMD-accelerate SBBF probe via branchless autovec #50030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dmatth1
wants to merge
3
commits into
apache:main
Choose a base branch
from
dmatth1:simd-sbbf-autovec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include <xsimd/xsimd.hpp> | ||
|
|
||
| #include "parquet/bloom_filter_avx2_internal.h" | ||
|
|
||
| namespace parquet::internal { | ||
|
|
||
| // Parquet SBBF probe (256-bit block, 8 SALT-derived bits per probe). Unrelated | ||
| // to cpp/src/arrow/acero/bloom_filter_avx2.cc -- Acero's blocked bloom filter | ||
| // is a different algorithm (64-bit block, ~4 bits per probe, in-memory only) | ||
| // and the two kernels are not interchangeable. See the Parquet spec for the | ||
| // SBBF on-disk layout this kernel must match. | ||
| // | ||
| // Spelled in xsimd rather than reusing the autovectorized body in | ||
| // bloom_filter_block_inc.h: only clang lowers that body to a single vptest; | ||
| // gcc and MSVC emit a longer horizontal vpor reduction. | ||
| bool FindHashBlockAvx2(const uint32_t* block, const uint32_t* salt, uint32_t key) { | ||
| using batch = xsimd::batch<uint32_t>; | ||
| const batch mask = | ||
| batch(uint32_t{1}) | ||
| << xsimd::bitwise_rshift<27>(batch(key) * batch::load_unaligned(salt)); | ||
| const batch miss = xsimd::bitwise_andnot(mask, batch::load_unaligned(block)); | ||
| // `miss != 0` (one extra vpcmpeqd) is deliberate: reinterpreting `miss` | ||
| // directly as a batch_bool would skip the compare but feed non-canonical | ||
| // lane values into batch_bool, which relies on xsimd's AVX2 backend | ||
| // lowering none() to a whole-register vptest. That lowering is not part | ||
| // of xsimd's documented contract. | ||
| return xsimd::none(miss != batch(uint32_t{0})); | ||
| } | ||
|
|
||
| } // namespace parquet::internal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| #include "parquet/platform.h" | ||
|
|
||
| namespace parquet::internal { | ||
|
|
||
| PARQUET_EXPORT bool FindHashBlockAvx2(const uint32_t* block, const uint32_t* salt, | ||
| uint32_t key); | ||
|
|
||
| } // namespace parquet::internal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| // Used to make sure ODR rule isn't violated. | ||
| #ifndef PARQUET_IMPL_NAMESPACE | ||
| # error "PARQUET_IMPL_NAMESPACE must be defined" | ||
| #endif | ||
|
|
||
| namespace parquet::internal::PARQUET_IMPL_NAMESPACE { | ||
|
|
||
| inline bool FindHashBlockImpl(const uint32_t* block, const uint32_t* salt, uint32_t key) { | ||
| constexpr int kBitsSetPerBlock = 8; | ||
| uint32_t miss = 0; | ||
| for (int i = 0; i < kBitsSetPerBlock; ++i) { | ||
| const uint32_t mask = static_cast<uint32_t>(1) << ((key * salt[i]) >> 27); | ||
| miss |= (~block[i] & mask); | ||
| } | ||
| return miss == 0; | ||
| } | ||
|
|
||
| } // namespace parquet::internal::PARQUET_IMPL_NAMESPACE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? I don't see other similar places have
#if defined(ARROW_HAVE_RUNTIME_AVX2)protection. cc @AntoinePrvThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This yes.
This too.
I thought in practice CMake will force
ARROW_HAVE_RUNTIME_AVX2withARROW_HAVE_AVX2, but I cannot find any code to support this claim. If so, then this is a problem general to Arrow.Regardless of the build tool, a defensive pattern
defined(ARROW_HAVE_AVX2) || defined(ARROW_HAVE_RUNTIME_AVX2)would be welcome.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not needed,
ARROW_DISPATCH_TARGET_AVX2handles that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @AntoinePrv for confirming it. So it looks like we have issues in other similar parts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I removed it from DISPATCH and added the more defensive pattern for the include