Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,4 @@ We plan to add many GPU-accelerated, concurrent data structures to `cuCollection
`cuco::experimental::roaring_bitmap` implements a Roaring bitmap following the [Roaring bitmap format specification](https://github.com/RoaringBitmap/RoaringFormatSpec).

#### Examples:
- [Host-bulk APIs](https://github.com/NVIDIA/cuCollections/blob/dev/examples/roaring_bitmap/host_bulk_example.cu) (see [live example in godbolt](https://godbolt.org/clientstate/eJy9WAtPGzkQ_itzi1RtIMmGlEcbHteUlCq6HlSUe0hQrZxdJ7GyWW9tL5BD_Pcb2_uEpdDHXZDIrj3-5uFvxuPcOpJKyXgsncHFrcNCZ7DZdiISz1Iyo87ACdKQOG1H8lQE-t1bv4xhHT59HP3dOWYRPeLJSrDZXJ3TGzWA4hXcoAX9Xn-7g_922nDy53g0HsLR6dnH07Ph-fj0BF7A8Ph4_GE8PH_3qQvDKAKzUoKgkoorGnZLVR9YQGNJO-OQxopNGRUDGCYkmNNOv9vTct5lfBmvsTiI0pDCfpAG3BOcCBbP_AlTS5J0g3R--EAmVSxiauUpQZiS3XmSHN5HCoknVegF-C-k08NHJ1msmifVKqG-VVATUHORSuWF9Ard869ooLjozptEIj5jAYmaJ9OYXVEhSVSFqMpNcaPkSiq6rC2fSiUoqY8x3jCIQxjG2pDVZPR465YTb7QamCOAP0mjhU9vyDKJKIbdTk8Eo1MY0SWyDYOhqIRUIsuAT0HNKdR3Cy4djXLpQMT5Ik0MMAw_jqWhhYEcx7iQScg0wTVFYRKCuubwst9BILBgEkgcAo8p7GxVhsFNuFBkgkunXCyJasFU8KW2xuBfnFmT3hrpYyPyKaHBZ3euVCIHnjdjap5OugFfejXZ_K1c00JaJ1wyjNpKW2MUIH-DBTDrv3Y3dxb9RHmVi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dR3DHUKK1hRn0EHEJXUrlmSlN7tPFI5nnX0RAUtfrPZUsCXyl0RoQe0OUvYr9XHX7vBzzd6rbLztlqrHgkswoSV2y1GoUwSPIEUY7gGGsbJvrYImWaNVa7wavCdg91AzV-I3tXcse3-oEqBeJnQreFgaYSuE4Z2OvuZyRdVbvLF0shtLxSMyw7XZncRar-XvX8atCvloDWqXVuTTVS_zm5OOnlZkNYtHA6jXmT4XF_ilzEERBz3Op-4DpVU7MsOwPlS6A_OThFrd3llOZnlfU4MTJvt1K7QkGtX00GtsGuKV2LT0eSevu3h_ND4rKly1GQdNKT9kAu1uXLVXuCnTIKBSQv1zYNv85j6pAN_AMtd8kcuLdY7-4rsAvxXNHlZ1tOZLnJNTxFZxtNxW8UzDIKvftqJhmEiUzIkZyUy4V8grG5pL_Ao9GMAmTq7pw7FUVhwZzXe5xv3KLmvIAsNGrBwMy4COUf3ed-mUbUH2uXSecRls3V_44KDKvLP-xCGbGqo6bQc7zgQrpSh_GXTiqyDY7G-nmzhtDcNJp4OAB8HGxuYudIgI5gdy6e_2oNPB0qrwn9LtQdiJyHJifkuM2KSCGQRBhIP6DEI8HNBcWzh37Xweq3RtHuuVc_fZ_P0LZpjzEQ==))
- [Host-bulk APIs](https://github.com/NVIDIA/cuCollections/blob/dev/examples/roaring_bitmap/host_bulk_example.cu) (see [live example in godbolt](https://godbolt.org/clientstate/eJy9WAtP20gQ_itzRqocSOJAebQpcE1JqaLrQUW5h1Qqa2NvklUcr7u7BnIo__1md_0MptDHXZCIvTs7z29mZ3LnSCol47F0-p_uHBY6_e22E5F4mpIpdfpOkIbEaTuSpyLQ797mVQyb8PHD8O_OKYvoCU-Wgk1n6pLeqj4Ur-AGLdjp7ex18N9-G87-HA1HAzg5v_hwfjG4HJ2fwTMYnJ6O3o8Gl28_dmEQRWBOShBUUnFNw24p6j0LaCxpZxTSWLEJo6IPg4QEM9rZ6fY0nXcVX8UbLA6iNKRwGKQB9wQngsVTf8zUgiTdIJ0d36NJFYu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chmarks/roaring_bitmap/contains_bench.cu
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <cuda/std/cstddef>
#include <cuda/std/cstdint>
#include <cuda/std/span>
#include <thrust/device_vector.h>
#include <thrust/universal_vector.h>

Expand Down Expand Up @@ -40,7 +41,8 @@ void roaring_bitmap_contains(nvbench::state& state, nvbench::type_list<T>)
file.read(reinterpret_cast<char*>(thrust::raw_pointer_cast(buffer.data())), file_size);
file.close();

cuco::experimental::roaring_bitmap<T> roaring_bitmap(thrust::raw_pointer_cast(buffer.data()));
cuco::experimental::roaring_bitmap<T> roaring_bitmap(
cuda::std::span<cuda::std::byte const>{thrust::raw_pointer_cast(buffer.data()), buffer.size()});

thrust::device_vector<T> items(num_items);

Expand Down
3 changes: 2 additions & 1 deletion examples/roaring_bitmap/host_bulk_example.cu
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cuda/std/cstddef>
#include <cuda/std/cstdint>
#include <cuda/std/span>
#include <cuda/std/type_traits>
#include <thrust/device_vector.h>
#include <thrust/logical.h>
Expand Down Expand Up @@ -95,7 +96,7 @@ bool check(std::string const& bitmap_file_path)

// Create roaring bitmap from the file
cuco::experimental::roaring_bitmap<KeyType> roaring_bitmap(
thrust::raw_pointer_cast(buffer.data()));
cuda::std::span<cuda::std::byte const>{thrust::raw_pointer_cast(buffer.data()), buffer.size()});

// Generate query keys (all should be contained in the bitmap)
auto keys = generate_keys();
Expand Down
9 changes: 9 additions & 0 deletions include/cuco/detail/roaring_bitmap/roaring_bitmap.inl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@
#pragma once

#include <cuda/std/cstddef>
#include <cuda/std/span>
#include <cuda/stream_ref>

namespace cuco::experimental {

template <class T, class Allocator>
roaring_bitmap<T, Allocator>::roaring_bitmap(cuda::std::span<cuda::std::byte const> bitmap,
Allocator const& alloc,
cuda::stream_ref stream)
: storage_{bitmap, alloc, stream}
{
}

template <class T, class Allocator>
roaring_bitmap<T, Allocator>::roaring_bitmap(cuda::std::byte const* bitmap,
Allocator const& alloc,
Expand Down
77 changes: 71 additions & 6 deletions include/cuco/detail/roaring_bitmap/roaring_bitmap_storage.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#include <cuco/detail/error.hpp>
#include <cuco/detail/roaring_bitmap/util.cuh>
#include <cuco/detail/storage/storage_base.cuh>
#include <cuco/detail/utility/memcpy_async.hpp>
#include <cuco/utility/traits.hpp>

#include <cuda/std/cstddef>
#include <cuda/std/cstdint>
#include <cuda/std/span>
#include <cuda/stream_ref>

#include <memory>
Expand Down Expand Up @@ -245,6 +247,27 @@ class roaring_bitmap_storage<cuda::std::uint32_t, Allocator> {

~roaring_bitmap_storage() = default;

/**
* @brief Constructs storage by validating and copying bitmap data to device memory
*
* @param bitmap Serialized bitmap bytes in host memory
* @param alloc Allocator for device memory allocation
* @param stream CUDA stream for memory operations
*/
roaring_bitmap_storage(cuda::std::span<cuda::std::byte const> bitmap,
Allocator const& alloc,
cuda::stream_ref stream)
: allocator_{alloc},
metadata_{bitmap},
data_{allocator_.allocate(metadata_.size_bytes, stream),
cuco::detail::custom_deleter<cuda::std::size_t, allocator_type>{
metadata_.size_bytes, allocator_, stream}},
ref_{data_.get(), metadata_}
{
CUCO_CUDA_TRY(cuco::detail::memcpy_async(
data_.get(), bitmap.data(), metadata_.size_bytes, cudaMemcpyHostToDevice, stream));
}

/**
* @brief Constructs storage by copying bitmap data to device memory
*
Expand All @@ -262,8 +285,8 @@ class roaring_bitmap_storage<cuda::std::uint32_t, Allocator> {
metadata_.size_bytes, allocator_, stream}},
ref_{data_.get(), metadata_}
{
CUCO_CUDA_TRY(cudaMemcpyAsync(
data_.get(), bitmap, metadata_.size_bytes, cudaMemcpyHostToDevice, stream.get()));
CUCO_CUDA_TRY(cuco::detail::memcpy_async(
data_.get(), bitmap, metadata_.size_bytes, cudaMemcpyHostToDevice, stream));
}

/**
Expand Down Expand Up @@ -335,6 +358,48 @@ class roaring_bitmap_storage<cuda::std::uint64_t, Allocator> {

~roaring_bitmap_storage() = default;

/**
* @brief Constructs storage by validating and copying bitmap data to device memory
*
* @param bitmap Serialized bitmap bytes in host memory
* @param alloc Allocator for device memory allocation
* @param stream CUDA stream for memory operations
*/
roaring_bitmap_storage(cuda::std::span<cuda::std::byte const> bitmap,
Allocator const& alloc,
cuda::stream_ref stream)
: allocator_{alloc},
bucket_allocator_{alloc},
bucket_metadata_{},
buckets_h_{},
metadata_{
[bitmap](std::vector<typename ref_type::metadata_type::bucket_metadata>& bucket_metadata) {
return typename ref_type::metadata_type{bitmap, bucket_metadata};
}(bucket_metadata_)},
data_{allocator_.allocate(metadata_.size_bytes, stream),
cuco::detail::custom_deleter<cuda::std::size_t, allocator_type>{
metadata_.size_bytes, allocator_, stream}},
buckets_{bucket_allocator_.allocate(metadata_.num_buckets, stream),
cuco::detail::custom_deleter<cuda::std::size_t, bucket_allocator_type>{
metadata_.num_buckets, bucket_allocator_, stream}},
ref_{data_.get(), metadata_, buckets_.get()}
{
assert(metadata_.valid);
buckets_h_.reserve(bucket_metadata_.size());
for (auto const& meta : bucket_metadata_) {
buckets_h_.emplace_back(meta.key,
bucket_ref_type{data_.get() + meta.byte_offset, meta.metadata});
}
CUCO_CUDA_TRY(cuco::detail::memcpy_async(
data_.get(), bitmap.data(), metadata_.size_bytes, cudaMemcpyHostToDevice, stream));
CUCO_CUDA_TRY(cuco::detail::memcpy_async(
buckets_.get(),
buckets_h_.data(),
metadata_.num_buckets * sizeof(cuda::std::pair<cuda::std::uint32_t, bucket_ref_type>),
cudaMemcpyHostToDevice,
stream));
}

/**
* @brief Constructs storage by copying bitmap data to device memory
*
Expand Down Expand Up @@ -367,14 +432,14 @@ class roaring_bitmap_storage<cuda::std::uint64_t, Allocator> {
buckets_h_.emplace_back(meta.key,
bucket_ref_type{data_.get() + meta.byte_offset, meta.metadata});
}
CUCO_CUDA_TRY(cudaMemcpyAsync(
data_.get(), bitmap, metadata_.size_bytes, cudaMemcpyHostToDevice, stream.get()));
CUCO_CUDA_TRY(cudaMemcpyAsync(
CUCO_CUDA_TRY(cuco::detail::memcpy_async(
data_.get(), bitmap, metadata_.size_bytes, cudaMemcpyHostToDevice, stream));
CUCO_CUDA_TRY(cuco::detail::memcpy_async(
buckets_.get(),
buckets_h_.data(),
metadata_.num_buckets * sizeof(cuda::std::pair<cuda::std::uint32_t, bucket_ref_type>),
cudaMemcpyHostToDevice,
stream.get()));
stream));
}

/**
Expand Down
Loading
Loading