HuaHuaY commented on code in PR #50030: URL: https://github.com/apache/arrow/pull/50030#discussion_r3381827791
########## cpp/src/parquet/bloom_filter.cc: ########## @@ -34,7 +35,35 @@ #include "parquet/thrift_internal.h" #include "parquet/xxhasher.h" +#if defined(ARROW_HAVE_AVX2) || defined(ARROW_HAVE_RUNTIME_AVX2) +# include "parquet/bloom_filter_avx2_internal.h" +#endif + +#include "parquet/bloom_filter_block_impl_internal.h" + +#include "arrow/util/dispatch_internal.h" Review Comment: I suggest adjusting the include order. Can we move line 44 to line 26? ########## cpp/src/parquet/bloom_filter_block_impl_internal.h: ########## @@ -0,0 +1,33 @@ +// 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> + +namespace parquet::internal { + +inline bool FindHashBlockImpl(const uint32_t* block, const uint32_t* salt, uint32_t key) { Review Comment: Can we use `std::span<const uint32_t, kBitsSetPerBlock> block` as the first parameter? ########## cpp/src/parquet/bloom_filter_block_impl_internal.h: ########## @@ -0,0 +1,33 @@ +// 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. Review Comment: I recommend adding a newline. ########## cpp/src/parquet/bloom_filter_block_impl_internal.h: ########## @@ -0,0 +1,33 @@ +// 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> + +namespace parquet::internal { + +inline bool FindHashBlockImpl(const uint32_t* block, const uint32_t* salt, uint32_t key) { + constexpr int kBitsSetPerBlock = 8; Review Comment: Why define a new `kBitsSetPerBlock` here? ########## cpp/src/parquet/bloom_filter.cc: ########## @@ -346,20 +375,18 @@ void BlockSplitBloomFilter::WriteTo(ArrowOutputStream* sink) const { } bool BlockSplitBloomFilter::FindHash(uint64_t hash) const { + // Probe kernels in bloom_filter_block_impl_internal.h and bloom_filter_avx2.cc both + // hard-code an 8-lane (256-bit) block. + static_assert(kBitsSetPerBlock == 8, Review Comment: I suggest to move this `static_assert` to `block_filter_avx2.cc`. ########## cpp/src/parquet/bloom_filter_avx2.cc: ########## @@ -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_impl_internal.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>; Review Comment: May xsimd generate avx512 here? I think we may need to use `xsimd::batch<uint32_t, xsimd::avx2>`. ########## cpp/src/parquet/bloom_filter_test.cc: ########## @@ -434,5 +443,85 @@ TYPED_TEST(TestBatchBloomFilter, Basic) { AssertBufferEqual(*buffer, *batch_insert_buffer); } +// Guards against silent drift between the baseline and AVX2 probe bodies -- +// DynamicDispatch only runs one of them per host. +#if defined(ARROW_HAVE_RUNTIME_AVX2) +namespace { + +// Mirror of BlockSplitBloomFilter::kBitsSetPerBlock (private to the class). +constexpr int kBitsSetPerBlock = 8; Review Comment: We already have a definition in `cpp/src/parquet/bloom_filter.h`. We can use it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
