contiguous_split.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <cudf/packed_types.hpp>
9 #include <cudf/types.hpp>
10 #include <cudf/utilities/export.hpp>
12 
13 #include <cstdint>
14 #include <memory>
15 #include <span>
16 #include <vector>
17 
23 namespace CUDF_EXPORT cudf {
24 
70 std::vector<packed_table> contiguous_split(
71  cudf::table_view const& input,
72  std::vector<size_type> const& splits,
73  cuda::stream_ref stream = cudf::get_default_stream(),
75 
76 namespace detail {
77 
83 struct contiguous_split_state;
84 } // namespace detail
85 
145  public:
156  explicit chunked_pack(
157  cudf::table_view const& input,
158  std::size_t user_buffer_size,
159  cuda::stream_ref stream = cudf::get_default_stream(),
161 
167 
173  [[nodiscard]] std::size_t get_total_contiguous_size() const;
174 
180  [[nodiscard]] bool has_next() const;
181 
195  [[nodiscard]] std::size_t next(cudf::device_span<uint8_t> const& user_buffer);
196 
202  [[nodiscard]] std::unique_ptr<std::vector<uint8_t>> build_metadata() const;
203 
223  [[nodiscard]] static std::unique_ptr<chunked_pack> create(
224  cudf::table_view const& input,
225  std::size_t user_buffer_size,
226  cuda::stream_ref stream = cudf::get_default_stream(),
228 
229  private:
230  // internal state of contiguous split
231  std::unique_ptr<detail::contiguous_split_state> state;
232 };
233 
248  cuda::stream_ref stream = cudf::get_default_stream(),
250 
263 std::size_t packed_size(
264  cudf::table_view const& input,
265  cuda::stream_ref stream = cudf::get_default_stream(),
267 
281 std::vector<uint8_t> pack_metadata(table_view const& table,
282  uint8_t const* contiguous_buffer,
283  size_t buffer_size);
284 
300 
318 table_view unpack(uint8_t const* metadata, uint8_t const* gpu_data);
319 
343  public:
355  class column_view {
356  public:
360  [[nodiscard]] data_type type() const;
361 
365  [[nodiscard]] size_type num_rows() const;
366 
370  [[nodiscard]] size_type null_count() const;
371 
375  [[nodiscard]] size_type num_children() const;
376 
384  [[nodiscard]] column_view child(size_type i) const;
385 
386  private:
387  friend class packed_metadata_view;
388  data_type _type{type_id::EMPTY};
389  size_type _size{};
390  size_type _null_count{};
391  size_type _num_children{};
392  // Span from this entry to the end of the metadata buffer (needed for child traversal).
393  std::span<std::uint8_t const> _buffer;
394  explicit column_view(std::span<std::uint8_t const> buffer);
395  };
396 
404  explicit packed_metadata_view(std::span<std::uint8_t const> buffer);
405 
409  [[nodiscard]] size_type num_columns() const;
410 
416  [[nodiscard]] size_type num_rows() const;
417 
425  [[nodiscard]] column_view column(size_type i) const;
426 
427  private:
428  // Span from the first top-level column entry to the end of the metadata buffer.
429  std::span<std::uint8_t const> _entries;
430  size_type _num_columns{};
431  // Table row count, read directly from the serialized table header.
432  size_type _num_rows{};
433 };
434 
436 } // namespace CUDF_EXPORT cudf
Perform a chunked "pack" operation of the input table_view using a user provided buffer of size user_...
std::size_t get_total_contiguous_size() const
Obtain the total size of the contiguously packed table_view.
chunked_pack(cudf::table_view const &input, std::size_t user_buffer_size, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref temp_mr=cudf::get_current_device_resource_ref())
Construct a chunked_pack class.
std::size_t next(cudf::device_span< uint8_t > const &user_buffer)
Packs the next chunk into user_buffer. This should be called as long as has_next returns true....
~chunked_pack()
Destructor that will be implemented as default. Declared with definition here because contiguous_spli...
std::unique_ptr< std::vector< uint8_t > > build_metadata() const
Build the opaque metadata for all added columns.
bool has_next() const
Function to check if there are chunks left to be copied.
static std::unique_ptr< chunked_pack > create(cudf::table_view const &input, std::size_t user_buffer_size, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref temp_mr=cudf::get_current_device_resource_ref())
Creates a chunked_pack instance to perform a "pack" of the table_view "input", where a buffer of user...
Indicator for the logical data type of an element in a column.
Definition: types.hpp:279
A non-owning view of a single column's metadata within packed column data.
column_view child(size_type i) const
A view of the i-th child column's metadata.
A non-owning view over the host metadata produced by cudf::pack.
size_type num_rows() const
The number of rows in the table.
column_view column(size_type i) const
A view of the i-th top-level column's metadata.
size_type num_columns() const
packed_metadata_view(std::span< std::uint8_t const > buffer)
Construct a view from a metadata byte buffer.
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
A set of cudf::column's of the same size.
Definition: table.hpp:31
std::vector< packed_table > contiguous_split(cudf::table_view const &input, std::vector< size_type > const &splits, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Performs a deep-copy split of a table_view into a vector of packed_table where each packed_table is u...
packed_columns pack(cudf::table_view const &input, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Deep-copy a table_view into a serialized contiguous memory format.
std::size_t packed_size(cudf::table_view const &input, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref temp_mr=cudf::get_current_device_resource_ref())
Compute the size in bytes of the contiguous memory buffer needed to pack the input table.
table_view unpack(uint8_t const *metadata, uint8_t const *gpu_data)
Deserialize the result of cudf::pack.
std::vector< uint8_t > pack_metadata(table_view const &table, uint8_t const *contiguous_buffer, size_t buffer_size)
Produce the metadata used for packing a table stored in a contiguous buffer.
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
cuda::std::span< T, Extent > device_span
Device span is an alias of cuda::std::span.
Definition: span.hpp:300
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:76
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:27
Packed table and column types for serialization.
Column data in a serialized format.
Type declarations for libcudf.