column.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
8 #include <cudf/null_mask.hpp>
9 #include <cudf/types.hpp>
12 
13 #include <rmm/device_buffer.hpp>
14 #include <rmm/device_uvector.hpp>
15 
16 #include <cuda/stream>
17 
18 #include <memory>
19 #include <type_traits>
20 #include <utility>
21 #include <vector>
22 
28 namespace CUDF_EXPORT cudf {
29 
37 class column {
38  public:
39  column() = default;
40  ~column() = default;
41  column& operator=(column const& other) = delete;
42  column& operator=(column&& other) = delete;
43 
55  column(column const& other,
56  cuda::stream_ref stream = cudf::get_default_stream(),
58 
66  column(column&& other) noexcept;
67 
75  template <typename T, CUDF_ENABLE_IF(cudf::is_numeric<T>() or cudf::is_chrono<T>())>
76  column(rmm::device_uvector<T>&& other, rmm::device_buffer&& null_mask, size_type null_count)
77  : _type{cudf::data_type{cudf::type_to_id<T>()}},
78  _size{[&]() {
80  other.size() <= static_cast<std::size_t>(std::numeric_limits<size_type>::max()),
81  "The device_uvector size exceeds the column size limit",
82  std::overflow_error);
83  return static_cast<size_type>(other.size());
84  }()},
85  _data{other.release()},
86  _null_mask{std::move(null_mask)},
87  _null_count{null_count}
88  {
89  }
90 
106  template <typename B1, typename B2 = rmm::device_buffer>
108  size_type size,
109  B1&& data,
110  B2&& null_mask,
112  std::vector<std::unique_ptr<column>>&& children = {})
113  : _type{dtype},
114  _size{size},
115  _data{std::forward<B1>(data)},
116  _null_mask{std::forward<B2>(null_mask)},
117  _null_count{null_count},
118  _children{std::move(children)}
119  {
120  CUDF_EXPECTS(size >= 0, "Column size cannot be negative.");
121  }
122 
133  explicit column(column_view view,
134  cuda::stream_ref stream = cudf::get_default_stream(),
136 
142  [[nodiscard]] data_type type() const noexcept { return _type; }
143 
149  [[nodiscard]] size_type size() const noexcept { return _size; }
150 
156  [[nodiscard]] size_type null_count() const { return _null_count; }
157 
169  void set_null_mask(rmm::device_buffer&& new_null_mask, size_type new_null_count);
170 
183  void set_null_mask(rmm::device_buffer const& new_null_mask,
184  size_type new_null_count,
185  cuda::stream_ref stream = cudf::get_default_stream());
186 
194  void set_null_count(size_type new_null_count);
195 
208  [[nodiscard]] bool nullable() const noexcept { return (_null_mask.size() > 0); }
209 
216  [[nodiscard]] bool has_nulls() const noexcept { return (null_count() > 0); }
217 
223  [[nodiscard]] size_type num_children() const noexcept { return _children.size(); }
224 
231  column& child(size_type child_index) noexcept { return *_children[child_index]; };
232 
239  [[nodiscard]] column const& child(size_type child_index) const noexcept
240  {
241  return *_children[child_index];
242  };
243 
249  struct contents {
250  std::unique_ptr<rmm::device_buffer> data;
251  std::unique_ptr<rmm::device_buffer> null_mask;
252  std::vector<std::unique_ptr<column>> children;
253  };
254 
270  contents release() noexcept;
271 
281  [[nodiscard]] std::size_t alloc_size() const;
282 
289  [[nodiscard]] column_view view() const;
290 
299  operator column_view() const { return this->view(); };
300 
308 
320  operator mutable_column_view() { return this->mutable_view(); };
321 
322  private:
323  cudf::data_type _type{type_id::EMPTY};
324  cudf::size_type _size{};
325  rmm::device_buffer _data{};
327  rmm::device_buffer _null_mask{};
329  mutable cudf::size_type _null_count{};
330  std::vector<std::unique_ptr<column>> _children{};
332 };
333  // end of group
335 } // namespace CUDF_EXPORT cudf
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
A container of nullable device data as a column of elements.
Definition: column.hpp:37
column(column_view view, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct a new column by deep copying the contents of a column_view.
data_type type() const noexcept
Returns the column's logical element type.
Definition: column.hpp:142
bool has_nulls() const noexcept
Indicates whether the column contains null elements.
Definition: column.hpp:216
size_type null_count() const
Returns the count of null elements.
Definition: column.hpp:156
size_type num_children() const noexcept
Returns the number of child columns.
Definition: column.hpp:223
mutable_column_view mutable_view()
Creates a mutable, non-owning view of the column's data, null mask, and children.
column(column &&other) noexcept
Move the contents from other to create a new column.
column const & child(size_type child_index) const noexcept
Returns a const reference to the specified child.
Definition: column.hpp:239
column & child(size_type child_index) noexcept
Returns a reference to the specified child.
Definition: column.hpp:231
column(data_type dtype, size_type size, B1 &&data, B2 &&null_mask, size_type null_count, std::vector< std::unique_ptr< column >> &&children={})
Construct a new column from existing device memory.
Definition: column.hpp:107
void set_null_mask(rmm::device_buffer &&new_null_mask, size_type new_null_count)
Sets the column's null value indicator bitmask to new_null_mask.
column(column const &other, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct a new column object by deep copying the contents of other.
bool nullable() const noexcept
Indicates whether it is possible for the column to contain null values, i.e., it has an allocated nul...
Definition: column.hpp:208
contents release() noexcept
Releases ownership of the column's contents.
size_type size() const noexcept
Returns the number of elements.
Definition: column.hpp:149
void set_null_count(size_type new_null_count)
Updates the count of null elements.
void set_null_mask(rmm::device_buffer const &new_null_mask, size_type new_null_count, cuda::stream_ref stream=cudf::get_default_stream())
Sets the column's null value indicator bitmask to new_null_mask.
Indicator for the logical data type of an element in a column.
Definition: types.hpp:279
A non-owning, mutable view of device data as a column of elements, some of which may be null as indic...
column view class definitions
APIs for querying the default CUDA stream and per-thread default stream status.
size_type null_count(bitmask_type const *bitmask, size_type start, size_type stop, cuda::stream_ref stream=cudf::get_default_stream())
Given a validity bitmask, counts the number of null elements (unset bits) in the range [start,...
cuda::stream_ref 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
#define CUDF_EXPECTS(...)
Macro for checking (pre-)conditions that throws an exception when a condition is violated.
Definition: error.hpp:182
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:76
constexpr CUDF_HOST_DEVICE bool is_chrono()
Indicates whether the type T is a chrono type.
Definition: traits.hpp:494
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:27
APIs for managing validity bitmasks.
Wrapper for the contents of a column.
Definition: column.hpp:249
std::unique_ptr< rmm::device_buffer > data
data device memory buffer
Definition: column.hpp:250
std::unique_ptr< rmm::device_buffer > null_mask
null mask device memory buffer
Definition: column.hpp:251
std::vector< std::unique_ptr< column > > children
child columns
Definition: column.hpp:252
Type declarations for libcudf.