Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmake/rapids_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ endif()
if(NOT rapids-cmake-branch)
set(rapids-cmake-branch "${RAPIDS_BRANCH}")
endif()

# Test rapids-cmake PR #1044 (bump cuco for the new bloom filter)
set(rapids-cmake-repo "PointKernel/rapids-cmake")
set(rapids-cmake-branch "cuco-new-filter")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
include("${CMAKE_CURRENT_LIST_DIR}/RAPIDS.cmake")

# Don't use sccache-dist for CMake's compiler tests
Expand Down
118 changes: 23 additions & 95 deletions cpp/src/io/parquet/arrow_filter_policy.cuh
Original file line number Diff line number Diff line change
@@ -1,118 +1,46 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <cudf/hashing/detail/xxhash_64.cuh>
#include <cudf/types.hpp>

#include <cuda/std/algorithm>
#include <cuda/std/limits>
#include <cuco/bloom_filter_policies.cuh>

#include <cstdint>

namespace cudf::io::parquet::detail {

/**
* @brief A policy that defines how Arrow Block-Split Bloom Filter generates and stores a key's
* fingerprint.
* @brief Hasher adapter that exposes the `argument_type` member required by cuco's
* `parametric_filter_policy`.
*
* @tparam Key The type of the values to generate a fingerprint for.
*/
template <class Key>
struct arrow_hasher : cudf::hashing::detail::XXHash_64<Key> {
using argument_type = Key;
Comment thread
PointKernel marked this conversation as resolved.
Resolved
using cudf::hashing::detail::XXHash_64<Key>::XXHash_64;
};

/**
* @brief A policy that defines how the Apache Arrow Block-Split Bloom Filter generates and stores a
* key's fingerprint.
*
* Implemented in terms of cuco's `parametric_filter_policy` with the Apache Arrow layout: 256-bit
* blocks (8 x `uint32_t`), 8 fingerprint bits per key, fully horizontal add (Theta=8) and fully
* vertical contains (Phi=8). This is bit-compatible with Apache Arrow, as verified by cuCollections
* `tests/bloom_filter/arrow_compat_test.cu`.
*
* Reference:
* https://github.com/apache/arrow/blob/be1dcdb96b030639c0b56955c4c62f9d6b03f473/cpp/src/parquet/bloom_filter.cc#L219-L230
*
* @tparam Key The type of the values to generate a fingerprint for.
*/
template <class Key>
class arrow_filter_policy {
public:
using hasher =
cudf::hashing::detail::XXHash_64<Key>; ///< 64-bit XXHash hasher for Arrow bloom filter policy
using word_type = std::uint32_t; ///< uint32_t for Arrow bloom filter policy
using key_type = Key; ///< Hash function input type
using hash_result_type = std::uint64_t; ///< hash function output type

static constexpr std::uint32_t bits_set_per_block = 8; ///< bits set per Arrow filter block
static constexpr std::uint32_t words_per_block = 8; ///< words per Arrow filter block

static constexpr std::uint32_t bytes_per_filter_block =
32; ///< Number of bytes in one Arrow filter block
static constexpr std::uint32_t max_arrow_filter_bytes =
128 * 1024 * 1024; ///< Max bytes in Arrow bloom filter
static constexpr std::uint32_t max_filter_blocks =
(max_arrow_filter_bytes /
bytes_per_filter_block); ///< Max sub-filter blocks allowed in Arrow bloom filter

/**
* @brief Constructs the `arrow_filter_policy` object.
*
* @note The number of filter blocks with Arrow policy must be in the
* range of [1, 4194304]. If the bloom filter is constructed with a larger
* number of blocks, only the first 4194304 (128MB) blocks will be used.
*
* @param hash Hash function used to generate a key's fingerprint
*/
CUDF_HOST_DEVICE constexpr arrow_filter_policy(hasher hash = {}) : hash_{hash} {}

/**
* @brief Generates the hash value for a given key.
*
* @param key The key to hash
*
* @return The hash value of the key
*/
__device__ constexpr hash_result_type hash(key_type const& key) const { return hash_(key); }

/**
* @brief Determines the filter block a key is added into.
*
* @note The number of filter blocks with Arrow policy must be in the
* range of [1, 4194304]. Passing a larger `num_blocks` will still
* upperbound the number of blocks used to the mentioned range.
*
* @tparam Extent Size type that is used to determine the number of blocks in the filter
*
* @param hash Hash value of the key
* @param num_blocks Number of block in the filter
*
* @return The block index for the given key's hash value
*/
template <class Extent>
__device__ constexpr auto block_index(hash_result_type hash, Extent num_blocks) const
{
constexpr auto hash_bits = cuda::std::numeric_limits<word_type>::digits;
auto const max_blocks = cuda::std::min<Extent>(num_blocks, max_filter_blocks);
// Make sure we are only contained within the `max_filter_blocks` blocks
return static_cast<word_type>(((hash >> hash_bits) * max_blocks) >> hash_bits) % max_blocks;
}

/**
* @brief Determines the fingerprint pattern for a word/segment within the filter block for a
* given key's hash value.
*
* @param hash Hash value of the key
* @param word_index Target word/segment within the filter block
*
* @return The bit pattern for the word/segment in the filter block
*/
__device__ constexpr word_type word_pattern(hash_result_type hash, std::uint32_t word_index) const
{
constexpr std::uint32_t salts[words_per_block] = {0x47b6137bU,
0x44974d91U,
0x8824ad5bU,
0xa2b7289dU,
0x705495c7U,
0x2df1424bU,
0x9efc4947U,
0x5c6bfb31U};
word_type const key = static_cast<word_type>(hash);
auto const salt = salts[word_index];
return word_type{1} << ((key * salt) >> 27);
}

private:
hasher hash_;
};
using arrow_filter_policy =
cuco::parametric_filter_policy<arrow_hasher<Key>, std::uint32_t, 8, 8, 8, 1, 1, 8, false, false>;

} // namespace cudf::io::parquet::detail
5 changes: 2 additions & 3 deletions cpp/src/join/mark_join.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
Expand Down Expand Up @@ -165,8 +165,7 @@ using storage_ref_type =
cuco::bucket_storage_ref<mark_key_type, mark_join_bucket_size, cuco::extent<std::size_t>>;
using right_key_type = cuco::pair<hash_value_type, rhs_index_type>;

using bloom_filter_policy_type =
cuco::default_filter_policy<cuco::detail::identity_hash<hash_value_type>, hash_value_type, 2U>;
using bloom_filter_policy_type = cuco::default_filter_policy<hash_value_type>;
using bloom_filter_allocator_type = rmm::mr::polymorphic_allocator<cuda::std::byte>;
using bloom_filter_type = cuco::bloom_filter<hash_value_type,
cuco::extent<std::size_t>,
Expand Down
Loading