table_device_view.cuh
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 
9 #include <cudf/types.hpp>
12 
13 #include <rmm/device_buffer.hpp>
14 #include <rmm/resource_ref.hpp>
15 
16 #include <cuda/stream>
17 
18 #include <cassert>
19 #include <memory>
20 
26 namespace CUDF_EXPORT cudf {
27 namespace detail {
28 
45 template <typename ColumnDeviceView, typename HostTableView>
47  public:
48  table_device_view_base() = delete;
49  ~table_device_view_base() = default;
64 
70  __device__ ColumnDeviceView* begin() const noexcept { return _columns; }
71 
80  __device__ ColumnDeviceView* end() const noexcept { return _columns + _num_columns; }
81 
88  __device__ ColumnDeviceView const& column(size_type column_index) const noexcept
89  {
90  assert(column_index >= 0);
91  assert(column_index < _num_columns);
92  return _columns[column_index];
93  }
94 
101  __device__ ColumnDeviceView& column(size_type column_index) noexcept
102  {
103  assert(column_index >= 0);
104  assert(column_index < _num_columns);
105  return _columns[column_index];
106  }
107 
113  [[nodiscard]] __host__ __device__ size_type num_columns() const noexcept { return _num_columns; }
114 
120  [[nodiscard]] __host__ __device__ size_type num_rows() const noexcept { return _num_rows; }
121 
128  void destroy();
129 
130  private:
131  ColumnDeviceView* _columns{};
132  size_type _num_rows{};
133  size_type _num_columns{};
134 
135  protected:
143  table_device_view_base(HostTableView source_view, ColumnDeviceView* columns);
144 };
145 } // namespace detail
146 
150 class table_device_view : public detail::table_device_view_base<column_device_view, table_view> {
151  public:
167  static std::unique_ptr<table_device_view, std::function<void(table_device_view*)>> create(
168  table_view source_view,
169  cuda::stream_ref stream = cudf::get_default_stream(),
171 
172  private:
173  table_device_view(table_view source_view, column_device_view* columns);
174 };
175 
182  : public detail::table_device_view_base<mutable_column_device_view, mutable_table_view> {
183  public:
199  static std::unique_ptr<mutable_table_device_view, std::function<void(mutable_table_device_view*)>>
201  cuda::stream_ref stream = cudf::get_default_stream(),
203 
204  private:
206 };
207 
218 template <typename ColumnDeviceView, typename HostTableView>
219 std::pair<std::unique_ptr<rmm::device_buffer>, ColumnDeviceView*> create_column_device_views(
220  HostTableView source_view,
221  cuda::stream_ref stream,
223 
224 } // namespace CUDF_EXPORT cudf
An immutable, non-owning view of device data as a column of elements that is trivially copyable and u...
Base class for a device table of ColumnDeviceViews.
size_type num_rows() const noexcept
Returns the number of rows.
ColumnDeviceView const & column(size_type column_index) const noexcept
Returns a reference to the view of the specified column.
table_device_view_base(table_device_view_base &&)=default
Move constructor.
ColumnDeviceView * begin() const noexcept
Returns an iterator to the first view in the table.
void destroy()
Destroy the table_device_view object.
table_device_view_base(table_device_view_base const &)=default
Copy constructor.
table_device_view_base(HostTableView source_view, ColumnDeviceView *columns)
Constructor for subclasses to create a table device view from a host table view.
size_type num_columns() const noexcept
Returns the number of columns.
table_device_view_base & operator=(table_device_view_base const &)=default
Copy assignment operator.
ColumnDeviceView * end() const noexcept
Returns an iterator one past the last column view in the table.
table_device_view_base & operator=(table_device_view_base &&)=default
Move assignment operator.
ColumnDeviceView & column(size_type column_index) noexcept
Returns a reference to the view of the specified column.
A mutable, non-owning view of device data as a column of elements that is trivially copyable and usab...
Mutable table device view that is usable in device memory.
static std::unique_ptr< mutable_table_device_view, std::function< void(mutable_table_device_view *)> > create(mutable_table_view source_view, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Factory to construct a mutable table device view that is usable in device memory.
A set of mutable_column_views of the same size.
Definition: table_view.hpp:274
Table device view that is usable in device memory.
static std::unique_ptr< table_device_view, std::function< void(table_device_view *)> > create(table_view source_view, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Factory to construct a table device view that is usable in device memory.
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
Column device view class definitions.
APIs for querying the default CUDA stream and per-thread default stream status.
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
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
std::pair< std::unique_ptr< rmm::device_buffer >, ColumnDeviceView * > create_column_device_views(HostTableView source_view, cuda::stream_ref stream, rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Copies the contents of a table_view to a column device view in contiguous device memory.
Class definitions for (mutable)_table_view
Type declarations for libcudf.