column_device_view.cuh
前往此文件的文档。
1 /*
2  * 版权所有 (c) 2019-2025, NVIDIA CORPORATION.
3  *
4  * 根据 Apache License, Version 2.0 ("许可") 获得许可;
5  * 您除非遵守许可条款,否则不得使用此文件。
6  * 您可获取许可协议的副本,地址为:
7  *
8  * https://apache.ac.cn/licenses/LICENSE-2.0
9  *
10  * 除非适用法律要求或书面同意,否则根据许可分发的软件
11  * 按"现状"提供,不附带任何明示或暗示的保证或条件。
12  * 请参阅许可协议以了解管理权限和
13  * 限制的特定语言。
14  */
15 
16 #pragma once
17 
19 #include <cudf/detail/offsets_iterator.cuh>
20 #include <cudf/detail/utilities/alignment.hpp>
22 #include <cudf/lists/list_view.hpp>
23 #include <cudf/strings/string_view.cuh>
26 #include <cudf/types.hpp>
27 #include <cudf/utilities/bit.hpp>
29 #include <cudf/utilities/span.hpp>
32 
33 #include <rmm/cuda_stream_view.hpp>
34 
35 #include <cuda/std/optional>
36 #include <cuda/std/type_traits>
37 #include <thrust/iterator/counting_iterator.h>
38 #include <thrust/iterator/transform_iterator.h>
39 #include <thrust/pair.h>
40 
41 #include <algorithm>
42 #include <functional>
43 #include <type_traits>
44 
50 namespace CUDF_EXPORT cudf {
51 
61 struct nullate {
62  struct YES : cuda::std::true_type {};
63  struct NO : cuda::std::false_type {};
69  struct DYNAMIC {
70  DYNAMIC() = delete;
79  constexpr explicit DYNAMIC(bool b) noexcept : value{b} {}
86  CUDF_HOST_DEVICE constexpr operator bool() const noexcept { return value; }
87  bool value;
88  };
89 };
90 
91 namespace detail {
103 /**
104  * @brief 设备端列视图的基类。
105  *
106  * 此类提供了在设备上访问列元数据和数据的通用功能。
107  * 它旨在用作 `column_device_view` 和`
108  * `mutable_column_device_view` 的基类。
114  */
120 class alignas(16) column_device_view_base {
121  public
138  column_device_view_base() = delete;
139  ~column_device_view_base() = default;
140  /** @brief 拷贝构造函数 */
142  /** @brief 移动构造函数 */
144  /** @brief 拷贝赋值运算符 */
161  /** @brief 移动赋值运算符 */
162  operator=(column_device_view_base&&) = default;
163 
171  /**
178  * @brief 返回指向列原始数据缓冲区的指针。
179  *
189  * 此指针在设备上有效。
190  *
200  * @tparam T 元素类型。应与列的数据类型布局兼容。
201  * @return 指向原始数据缓冲区的指针。
202  */
203  template <typename T = void,
211  CUDF_ENABLE_IF(std::is_same_v<T, void> or is_rep_layout_compatible<T>())>
227  [[nodiscard]] CUDF_HOST_DEVICE T const* head() const noexcept
228  {
229  return static_cast<T const*>(_data);
230  }
231 
244  /**
245  * @brief 返回指向列数据缓冲区第一个元素的指针。
246  *
247  * 此指针在设备上有效。
248  *
262  * @tparam T 元素类型。应与列的数据类型布局兼容。
263  * @return 指向第一个元素的指针。
264  */
265  template <typename T, CUDF_ENABLE_IF(is_rep_layout_compatible<T>())>
266  [[nodiscard]] CUDF_HOST_DEVICE T const* data() const noexcept
278  {
279  return head<T>() + _offset;
280  }
281 
282  /**
292  * @brief 返回列中的元素数量。
293  */
294  [[nodiscard]] CUDF_HOST_DEVICE size_type size() const noexcept { return _size; }
295 
296  /**
297  * @brief 返回列的数据类型。
298  */
299  [[nodiscard]] CUDF_HOST_DEVICE data_type type() const noexcept { return _type; }
301  /**
303  * @brief 如果列有关联的 null mask,则返回 true。
305  *
315  * 此函数被标记为 `CUDF_HOST_DEVICE`,因为它需要从内核和`
316  * 设备函数中调用。
317  */
318  [[nodiscard]] CUDF_HOST_DEVICE bool nullable() const noexcept { return nullptr != _null_mask; }
319 
320  /**
321  * @brief 返回指向 null mask 缓冲区的指针,如果不可空则返回 `nullptr`。
322  *
323  * 此指针在设备上有效。
324  */
325  [[nodiscard]] CUDF_HOST_DEVICE bitmask_type const* null_mask() const noexcept
326  {
327  return _null_mask;
328  }
329 
331  /**
332  * @brief 返回列数据相对于缓冲区起点的偏移量。
333  */
334  [[nodiscard]] CUDF_HOST_DEVICE size_type offset() const noexcept { return _offset; }
335 
336  /**
337  * @brief 检查给定索引处的元素是否有效(非 null)。
338  *
339  * 此函数被标记为 `__device__`,因为它仅适用于从设备`
340  * 内核调用。
341  *
342  * @param element_index 要检查的元素的索引。
343  * @return 如果元素有效则返回 true,否则返回 false。
344  */
345  [[nodiscard]] __device__ bool is_valid(size_type element_index) const noexcept
346  {
347  return not nullable() or is_valid_nocheck(element_index);
348  }
349 
350  /**
351  * @brief 检查给定索引处的元素是否有效(非 null),假设列可空。
352  *
353  * 此函数被标记为 `__device__`,因为它仅适用于从设备`
354  * 内核调用。
355  *
356  * @param element_index 要检查的元素的索引。
357  * @return 如果元素有效则返回 true,否则返回 false。
358  */
359  [[nodiscard]] __device__ bool is_valid_nocheck(size_type element_index) const noexcept
360  {
361  return bit_is_set(_null_mask, offset() + element_index);
362  }
363 
364  /**
365  * @brief 检查给定索引处的元素是否为 null。
366  *
367  * 此函数被标记为 `__device__`,因为它仅适用于从设备`
368  * 内核调用。
369  *
370  * @param element_index 要检查的元素的索引。
371  * @return 如果元素为 null 则返回 true,否则返回 false。
372  */
373  [[nodiscard]] __device__ bool is_null(size_type element_index) const noexcept
374  {
375  return not is_valid(element_index);
376  }
377 
378  /**
379  * @brief 检查给定索引处的元素是否为 null,假设列可空。
380  *
381  * 此函数被标记为 `__device__`,因为它仅适用于从设备`
382  * 内核调用。
383  *
384  * @param element_index 要检查的元素的索引。
385  * @return 如果元素为 null 则返回 true,否则返回 false。
386  */
387  [[nodiscard]] __device__ bool is_null_nocheck(size_type element_index) const noexcept
388  {
389  return not is_valid_nocheck(element_index);
390  }
391 
392  /**
393  * @brief 获取第 `word_index` 个位掩码字。
394  *
395  * @param word_index 要检索的位掩码字的索引。
396  * @return 位掩码字。
397  */
398  [[nodiscard]] __device__ bitmask_type get_mask_word(size_type word_index) const noexcept
399  {
400  return null_mask()[word_index];
401  }
402 
403  protected
404  data_type _type{type_id::EMPTY};
405  cudf::size_type _size{};
406  void const* _data{};
407  bitmask_type const* _null_mask{};
409  size_type _offset{};
411 
415  /**
416  * @brief 构造一个新的设备端列视图基类对象,使用原始指针和元数据。
417  */
419  size_type size,
420  void const* data,
421  bitmask_type const* null_mask,
422  size_type offset)
423  : _type{type}, _size{size}, _data{data}, _null_mask{null_mask}, _offset{offset}
424  {
425  }
426 
427  template <typename C, typename T, typename = void>
428  struct has_element_accessor_impl : cuda::std::false_type {};
429 
430  template <typename C, typename T>
431  struct has_element_accessor_impl<
432  C,
433  T,
434  void_t<decltype(cuda::std::declval<C>().template element<T>(cuda::std::declval<size_type>()))>>
435  : cuda::std::true_type {};
436 };
437 // @cond
438 // 前向声明
439 template <typename T>
440 struct value_accessor;
441 template <typename T, typename Nullate>
442 struct optional_accessor;
443 template <typename T, bool has_nulls>
444 struct pair_accessor;
445 template <typename T, bool has_nulls>
446 struct pair_rep_accessor;
447 template <typename T>
448 struct mutable_value_accessor;
449 // @endcond
450 } // namespace detail
451 
455 /**
456  * @brief 设备上不可变列数据和元数据的视图。
457  *
458  * `column_device_view` 是用于设备内核的列数据的不可变视图。
459  * 它包含指向列数据、null mask 和子列的设备指针。
460  */
461 class alignas(16) column_device_view : public detail::column_device_view_base {
462  public
463  column_device_view() = delete;
464  ~column_device_view() = default;
465  /** @brief 拷贝构造函数 */
466  column_device_view(column_device_view const&) = default;
467  /** @brief 移动构造函数 */
472  /** @brief 拷贝赋值运算符 */
474  /** @brief 移动赋值运算符 */
476 
477  /**
478  * @brief 从主机端列视图和指向子列视图的设备指针构造一个新的设备端列视图对象。
479  *
480  * 此构造函数仅打算由工厂函数 `create` 调用。
481  *
482  * @param column 用于构造的主机端列视图。
383  * @param h_ptr 指向支持此视图的设备内存的主机端指针。用于计算到数据缓冲区的偏移量,该偏移量是根据 `column_view` 及其 `data()` 成员的相对地址计算的。
484  * @param d_ptr 指向支持此视图的设备内存的设备端指针。
485  */
486  column_device_view(column_view column, void* h_ptr, void* d_ptr);
487 
493  /**
494  * @brief 返回元素子范围的新视图。
495  *
496  * 返回的视图与原始视图具有相同的类型、null mask 和子项。
497  * 新视图的数据指针和 null mask 指针根据请求的子范围进行偏移。
498  *
499  * @param offset 子范围的起始索引。
500  * @param size 子范围中的元素数量。
501  * @return 指定子范围的新设备端列视图。
506  */
508  size_type size) const noexcept
509  {
510  return column_device_view{this->type(),
511  size,
512  this->head(),
513  this->null_mask(),
514  this->offset() + offset,
515  d_children,
516  this->num_child_columns()};
517  }
518 
523  /**
524  * @brief 返回给定索引处的元素。
525  *
526  * 索引相对于此视图的起始位置。
527  *
528  * @tparam T 元素类型。必须与列的数据类型布局兼容。
529  * @param element_index 要检索的元素的索引。
530  * @return 给定索引处的元素。
531  */
532  template <typename T, CUDF_ENABLE_IF(is_rep_layout_compatible<T>())>
533  [[nodiscard]] __device__ T element(size_type element_index) const noexcept
534  {
535  return data<T>()[element_index];
536  }
537 
538  /**
539  * @brief 对于字符串列,返回给定索引处的元素。
540  *
541  * 索引相对于此视图的起始位置。
542  *
543  * @tparam T 必须为 `string_view`。
544  * @param element_index 要检索的元素的索引。
545  * @return 给定索引处的字符串元素。
546  */
547  template <typename T, CUDF_ENABLE_IF(std::is_same_v<T, string_view>)>
548  [[nodiscard]] __device__ T element(size_type element_index) const noexcept
549  {
550  size_type index = element_index + offset(); // account for this view's _offset
551  char const* d_strings = static_cast<char const*>(_data);
552  auto const offsets = d_children[strings_column_view::offsets_column_index];
553  auto const itr = cudf::detail::input_offsetalator(offsets.head(), offsets.type());
554  auto const offset = itr[index];
555  return string_view{d_strings + offset, static_cast<cudf::size_type>(itr[index + 1] - offset)};
556  }
557 
558  private
564  /**
565  * @brief 从索引类型列的 device_view 中提取元素的函数对象。
566  */
567  struct index_element_fn {
568  template <typename IndexType,
569  CUDF_ENABLE_IF(is_index_type<IndexType>() and std::is_signed_v<IndexType>)>
570  __device__ size_type operator()(column_device_view const& indices, size_type index)
571  {
572  return static_cast<size_type>(indices.element<IndexType>(index));
573  }
574 
575  template <typename IndexType,
576  typename... Args,
577  CUDF_ENABLE_IF(not(is_index_type<IndexType>() and std::is_signed_v<IndexType>))>
578  __device__ size_type operator()(Args&&... args)
579  {
580  CUDF_UNREACHABLE("dictionary indices must be a signed integral type");
581  }
582  };
583 
584  public
597  /**
598  * @brief 对于字典列,返回给定索引处的元素。
599  *
600  * 索引相对于此视图的起始位置。
601  *
602  * @tparam T 必须为 `dictionary32`。
603  * @param element_index 要检索的元素的索引。
604  * @return 给定索引处的字典元素。
605  */
606  template <typename T, CUDF_ENABLE_IF(std::is_same_v<T, dictionary32>)>
607  [[nodiscard]] __device__ T element(size_type element_index) const noexcept
608  {
609  size_type index = element_index + offset(); // account for this view's _offset
610  auto const indices = d_children[0];
611  return dictionary32{type_dispatcher(indices.type(), index_element_fn{}, indices, index)};
612  }
613 
618  /**
619  * @brief 对于 fixed_point 类型,返回给定索引处的元素。
620  *
621  * @tparam T 必须是 fixed_point 类型。
622  * @param element_index 要检索的元素的索引。
623  * @return 给定索引处的 fixed_point 元素。
624  */
625  template <typename T, CUDF_ENABLE_IF(cudf::is_fixed_point<T>())>
626  [[nodiscard]] __device__ T element(size_type element_index) const noexcept
627  {
628  using namespace numeric;
629  using rep = typename T::rep;
630  auto const scale = scale_type{_type.scale()};
631  return T{scaled_integer<rep>{data<rep>()[element_index], scale}};
632  }
633 
639  /**
640  * @brief 如果此类型受 `element()` 支持,则返回 true。
641  *
642  * @tparam T 要检查的类型。
643  */
644  template <typename T>
645  CUDF_HOST_DEVICE static constexpr bool has_element_accessor()
646  {
647  return has_element_accessor_impl<column_device_view, T>::value;
648  }
649 
651  /** @brief 列索引计数迭代器的类型别名 */
546  using count_it = thrust::counting_iterator<size_type>;
653  /**
654  * @brief 列元素常量迭代器的类型别名。
655  *
656  * 解引用迭代器返回元素的副本。
657  */
658  template <typename T>
659  using const_iterator = thrust::transform_iterator<detail::value_accessor<T>, count_it>;
660 
661  /**
662  * @brief 返回指向第一个元素的迭代器。
663  *
664  * 列类型必须受 `element()` 支持。
665  *
666  * @tparam T 元素类型。
667  * @return 指向第一个元素的迭代器。
668  */
669  template <typename T, CUDF_ENABLE_IF(column_device_view::has_element_accessor<T>())>
670  [[nodiscard]] const_iterator<T> begin() const
671  {
673  }
674 
675  /**
676  * @brief 返回指向列末尾的迭代器。
677  *
678  * 列类型必须受 `element()` 支持。
679  *
680  * @tparam T 元素类型。
681  * @return 指向列末尾的迭代器。
682  */
683  template <typename T, CUDF_ENABLE_IF(column_device_view::has_element_accessor<T>())>
684  [[nodiscard]] const_iterator<T> end() const
685  {
1152  __device__ void set_null(size_type element_index) const noexcept
1153  {
1154  return clear_bit(null_mask(), element_index);
1155  }
1156 
1157 #endif
1158 
1169  __device__ void set_mask_word(size_type word_index, bitmask_type new_word) const noexcept
1170  {
1171  null_mask()[word_index] = new_word;
1172  }
1173 
1182  static std::size_t extent(mutable_column_view source_view);
1183 
1190  void destroy();
1191 
1192  private
1193  mutable_column_device_view* d_children{};
1197  size_type _num_children{};
1198 
1207  mutable_column_device_view(mutable_column_view source);
1208 };
1209 
1210 namespace detail {
1211 
1212 #ifdef __CUDACC__ // because set_bit in bit.hpp is wrapped with __CUDACC__
1213 
1220 __device__ inline bitmask_type get_mask_offset_word(bitmask_type const* __restrict__ source,
1221  size_type destination_word_index,
1222  size_type source_begin_bit,
1223  size_type source_end_bit)
1224 {
1225  size_type source_word_index = destination_word_index + word_index(source_begin_bit);
1226  bitmask_type curr_word = source[source_word_index];
1227  bitmask_type next_word = 0;
1228  if (word_index(source_end_bit - 1) >
1229  word_index(source_begin_bit +
1230  destination_word_index * detail::size_in_bits<bitmask_type>())) {
1231  next_word = source[source_word_index + 1];
1232  }
1233  return __funnelshift_r(curr_word, next_word, source_begin_bit);
1234 }
1235 
1236 #endif
1237 
1252 template <typename T>
1255 
1261  value_accessor(column_device_view const& _col) : col{_col}
1262  {
1263  CUDF_EXPECTS(type_id_matches_device_storage_type<T>(col.type().id()), "the data type mismatch");
1264  }
1265 
1271  __device__ T operator()(cudf::size_type i) const { return col.element<T>(i); }
1272 };
1273 
1300 template <typename T, typename Nullate>
1303 
1310  optional_accessor(column_device_view const& _col, Nullate with_nulls)
1311  : col{_col}, has_nulls{with_nulls}
1312  {
1313  CUDF_EXPECTS(type_id_matches_device_storage_type<T>(col.type().id()), "the data type mismatch");
1314  if (with_nulls) { CUDF_EXPECTS(_col.nullable(), "Unexpected non-nullable column."); }
1315  }
1316 
1324  __device__ inline cuda::std::optional<T> operator()(cudf::size_type i) const
1325  {
1326  if (has_nulls) {
1327  return (col.is_valid_nocheck(i)) ? cuda::std::optional<T>{col.element<T>(i)}
1328  : cuda::std::optional<T>{cuda::std::nullopt};
1329  }
1330  return cuda::std::optional<T>{col.element<T>(i)};
1331  }
1332 
1333  Nullate has_nulls{};
1334 };
1335 
1355 template <typename T, bool has_nulls = false>
1358 
1364  pair_accessor(column_device_view const& _col) : col{_col}
1365  {
1366  CUDF_EXPECTS(type_id_matches_device_storage_type<T>(col.type().id()), "the data type mismatch");
1367  if (has_nulls) { CUDF_EXPECTS(_col.nullable(), "Unexpected non-nullable column."); }
1368  }
1369 
1376  __device__ inline thrust::pair<T, bool> operator()(cudf::size_type i) const
1377  {
1378  return {col.element<T>(i), (has_nulls ? col.is_valid_nocheck(i) : true)};
1379  }
1380 };
1381 
1401 template <typename T, bool has_nulls = false>
1404 
1406 
1412  pair_rep_accessor(column_device_view const& _col) : col{_col}
1413  {
1414  CUDF_EXPECTS(type_id_matches_device_storage_type<T>(col.type().id()), "the data type mismatch");
1415  if (has_nulls) { CUDF_EXPECTS(_col.nullable(), "Unexpected non-nullable column."); }
1416  }
1417 
1424  __device__ inline thrust::pair<rep_type, bool> operator()(cudf::size_type i) const
1425  {
1426  return {get_rep<T>(i), (has_nulls ? col.is_valid_nocheck(i) : true)};
1427  }
1428 
1429  private
1430  template <typename R, std::enable_if_t<std::is_same_v<R, rep_type>, void>* = nullptr>
1431  [[nodiscard]] __device__ inline auto get_rep(cudf::size_type i) const
1432  {
1433  return col.element<R>(i);
1434  }
1435 
1436  template <typename R, std::enable_if_t<not std::is_same_v<R, rep_type>, void>* = nullptr>
1437  [[nodiscard]] __device__ inline auto get_rep(cudf::size_type i) const
1438  {
1439  return col.element<R>(i).value();
1440  }
1441 };
1442 
1454 template <typename T>
1457 
1464  {
1465  CUDF_EXPECTS(type_id_matches_device_storage_type<T>(col.type().id()), "the data type mismatch");
1466  }
1467 
1474  __device__ T& operator()(cudf::size_type i) { return col.element<T>(i); }
1475 };
1476 
1502 template <typename ColumnDeviceView, typename ColumnViewIterator>
1503 ColumnDeviceView* child_columns_to_device_array(ColumnViewIterator child_begin,
1504  ColumnViewIterator child_end,
1505  void* h_ptr,
1506  void* d_ptr)
1507 {
1508  ColumnDeviceView* d_children = detail::align_ptr_for_type<ColumnDeviceView>(d_ptr);
1509  auto num_children = std::distance(child_begin, child_end);
1510  if (num_children > 0) {
1511  // The beginning of the memory must be the fixed-sized ColumnDeviceView
1512  // struct objects in order for d_children to be used as an array.
1513  auto h_column = detail::align_ptr_for_type<ColumnDeviceView>(h_ptr);
1514  auto d_column = d_children;
1515 
1516  // Any child data is assigned past the end of this array: h_end and d_end.
1517  auto h_end = reinterpret_cast<int8_t*>(h_column + num_children);
1518  auto d_end = reinterpret_cast<int8_t*>(d_column + num_children);
1519  std::for_each(child_begin, child_end, [&](auto const& col) {
1520  // inplace-new each child into host memory
1521  new (h_column) ColumnDeviceView(col, h_end, d_end);
1522  h_column++; // advance to next child
1523  // update the pointers for holding this child column's child data
1524  auto col_child_data_size = ColumnDeviceView::extent(col) - sizeof(ColumnDeviceView);
1525  h_end += col_child_data_size;
1526  d_end += col_child_data_size;
1527  });
1528  }
1529  return d_children;
1530 }
1531 
1532 } // namespace detail
1533 } // namespace CUDF_EXPORT cudf
Utilities for bit and bitmask operations.
An immutable, non-owning view of device data as a column of elements that is trivially copyable and u...
static std::unique_ptr< column_device_view, std::function< void(column_device_view *)> > create(column_view source_view, rmm::cuda_stream_view stream=cudf::get_default_stream())
Factory to construct a column view that is usable in device memory.
column_device_view(column_view source)
Construct's a column_device_view from a column_view populating all but the children.
column_device_view child(size_type child_index) const noexcept
Returns the specified child.
void destroy()
Destroy the column_device_view object.
column_device_view & operator=(column_device_view &&)=default
Move assignment operator.
thrust::counting_iterator< size_type > count_it
Counting iterator.
static constexpr CUDF_HOST_DEVICE bool has_element_accessor()
For a given T, indicates if column_device_view::element<T>() has a valid overload.
const_pair_iterator< T, has_nulls > pair_end() const
Return a pair iterator to the element following the last element of the column.
const_pair_rep_iterator< T, has_nulls > pair_rep_end() const
Return a pair iterator to the element following the last element of the column.
const_pair_iterator< T, has_nulls > pair_begin() const
Return a pair iterator to the first element of the column.
T element(size_type element_index) const noexcept
Returns reference to element at the specified index.
column_device_view & operator=(column_device_view const &)=default
Copy assignment operator.
CUDF_HOST_DEVICE column_device_view slice(size_type offset, size_type size) const noexcept
Get a new column_device_view which is a slice of this column.
thrust::transform_iterator< detail::value_accessor< T >, count_it > const_iterator
Iterator for navigating this column.
auto optional_end(Nullate has_nulls) const
Return an optional iterator to the element following the last element of the column.
thrust::transform_iterator< detail::pair_accessor< T, has_nulls >, count_it > const_pair_iterator
Pair iterator for navigating this column.
const_pair_rep_iterator< T, has_nulls > pair_rep_begin() const
Return a pair iterator to the first element of the column.
thrust::transform_iterator< detail::optional_accessor< T, Nullate >, count_it > const_optional_iterator
Optional iterator for navigating this column.
CUDF_HOST_DEVICE size_type num_child_columns() const noexcept
Returns the number of child columns.
auto optional_begin(Nullate has_nulls) const
Return an optional iterator to the first element of the column.
column_device_view(column_device_view const &)=default
Copy constructor.
column_device_view(column_device_view &&)=default
Move constructor.
const_iterator< T > begin() const
Return an iterator to the first element of the column.
thrust::transform_iterator< detail::pair_rep_accessor< T, has_nulls >, count_it > const_pair_rep_iterator
Pair rep iterator for navigating this column.
static std::size_t extent(column_view const &source_view)
Return the size in bytes of the amount of memory needed to hold a device view of the specified column...
column_device_view(column_view column, void *h_ptr, void *d_ptr)
Creates an instance of this class using the specified host memory pointer (h_ptr) to store child obje...
const_iterator< T > end() const
Returns an iterator to the element following the last element of the column.
device_span< column_device_view const > children() const noexcept
Returns a span containing the children of this column.
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:47
Indicator for the logical data type of an element in a column.
Definition: types.hpp:243
constexpr CUDF_HOST_DEVICE type_id id() const noexcept
Returns the type identifier.
Definition: types.hpp:287
An immutable, non-owning view of device data as a column of elements that is trivially copyable and u...
CUDF_HOST_DEVICE T const * head() const noexcept
Returns pointer to the base device memory allocation casted to the specified type.
CUDF_HOST_DEVICE data_type type() const noexcept
Returns the element type.
CUDF_HOST_DEVICE column_device_view_base(data_type type, size_type size, void const *data, bitmask_type const *null_mask, size_type offset)
Constructs a column with the specified type, size, data, nullmask and offset.
column_device_view_base & operator=(column_device_view_base &&)=default
Move assignment operator.
CUDF_HOST_DEVICE size_type size() const noexcept
Returns the number of elements in the column.
bitmask_type get_mask_word(size_type word_index) const noexcept
Returns the specified bitmask word from the null_mask().
column_device_view_base(column_device_view_base &&)=default
Move constructor.
column_device_view_base(column_device_view_base const &)=default
Copy constructor.
CUDF_HOST_DEVICE bitmask_type const * null_mask() const noexcept
Returns raw pointer to the underlying bitmask allocation.
bool is_valid_nocheck(size_type element_index) const noexcept
Returns whether the specified element holds a valid value (i.e., not null)
CUDF_HOST_DEVICE T const * data() const noexcept
Returns the underlying data casted to the specified type, plus the offset.
column_device_view_base & operator=(column_device_view_base const &)=default
Copy assignment operator.
bool is_null(size_type element_index) const noexcept
Returns whether the specified element is null.
CUDF_HOST_DEVICE size_type offset() const noexcept
Returns the index of the first element relative to the base memory allocation, i.e....
bool is_null_nocheck(size_type element_index) const noexcept
Returns whether the specified element is null.
CUDF_HOST_DEVICE bool nullable() const noexcept
Indicates whether the column can contain null elements, i.e., if it has an allocated bitmask.
bool is_valid(size_type element_index) const noexcept
Returns whether the specified element holds a valid value (i.e., not null).
A mutable, non-owning view of device data as a column of elements that is trivially copyable and usab...
static constexpr CUDF_HOST_DEVICE bool has_element_accessor()
For a given T, indicates if mutable_column_device_view::element<T>() has a valid overload.
void destroy()
Destroy the mutable_column_device_view object.
void set_mask_word(size_type word_index, bitmask_type new_word) const noexcept
Updates the specified bitmask word in the null_mask() with a new word.
mutable_column_device_view(mutable_column_view column, void *h_ptr, void *d_ptr)
Creates an instance of this class using the specified host memory pointer (h_ptr) to store child obje...
static std::size_t extent(mutable_column_view source_view)
Return the size in bytes of the amount of memory needed to hold a device view of the specified column...
thrust::counting_iterator< size_type > count_it
Counting iterator.
mutable_column_device_view child(size_type child_index) const noexcept
Returns the specified child.
CUDF_HOST_DEVICE bitmask_type * null_mask() const noexcept
Returns raw pointer to the underlying bitmask allocation.
CUDF_HOST_DEVICE T * head() const noexcept
Returns pointer to the base device memory allocation casted to the specified type.
CUDF_HOST_DEVICE T * data() const noexcept
Returns the underlying data casted to the specified type, plus the offset.
mutable_column_device_view(mutable_column_device_view const &)=default
Copy constructor.
T & element(size_type element_index) const noexcept
Returns reference to element at the specified index.
iterator< T > end()
Return one past the last element after underlying data is casted to the specified type.
mutable_column_device_view & operator=(mutable_column_device_view &&)=default
Move assignment operator.
mutable_column_device_view(mutable_column_device_view &&)=default
Move constructor.
mutable_column_device_view & operator=(mutable_column_device_view const &)=default
Copy assignment operator.
static std::unique_ptr< mutable_column_device_view, std::function< void(mutable_column_device_view *)> > create(mutable_column_view source_view, rmm::cuda_stream_view stream=cudf::get_default_stream())
Factory to construct a column view that is usable in device memory.
thrust::transform_iterator< detail::mutable_value_accessor< T >, count_it > iterator
Iterator for navigating this column.
iterator< T > begin()
Return first element (accounting for offset) after underlying data is casted to the specified type.
A non-owning, mutable view of device data as a column of elements, some of which may be null as indic...
A non-owning, immutable view of device data that is a variable length char array representing a UTF-8...
ColumnDeviceView * child_columns_to_device_array(ColumnViewIterator child_begin, ColumnViewIterator child_end, void *h_ptr, void *d_ptr)
Helper function for use by column_device_view and mutable_column_device_view constructors to build de...
column view class definitions
Class definition for fixed point data type.
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
scale_type
The scale type for fixed_point.
std::unique_ptr< cudf::column > is_valid(cudf::column_view const &input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a column of type_id::BOOL8 elements where for every element in input true indicates the value...
constexpr CUDF_HOST_DEVICE size_type word_index(size_type bit_index)
Returns the index of the word containing the specified bit.
Definition: bit.hpp:74
CUDF_HOST_DEVICE bool bit_is_set(bitmask_type const *bitmask, size_type bit_index)
Indicates whether the specified bit is set to 1
Definition: bit.hpp:128
CUDF_HOST_DEVICE constexpr decltype(auto) __forceinline__ type_dispatcher(cudf::data_type dtype, Functor f, Ts &&... args)
Invokes an operator() template with the type instantiation based on the specified cudf::data_type's i...
std::conditional_t< std::is_same_v< numeric::decimal32, T >, int32_t, std::conditional_t< std::is_same_v< numeric::decimal64, T >, int64_t, std::conditional_t< std::is_same_v< numeric::decimal128, T >, __int128_t, T > >> device_storage_type_t
"Returns" the corresponding type that is stored on the device when using cudf::column
#define CUDF_EXPECTS(...)
Macro for checking (pre-)conditions that throws an exception when a condition is violated.
Definition: error.hpp:178
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:95
uint32_t bitmask_type
Bitmask type stored as 32-bit unsigned integer.
Definition: types.hpp:96
size_type distance(T f, T l)
Similar to std::distance but returns cudf::size_type and performs static_cast
Definition: types.hpp:110
void void_t
Utility metafunction that maps a sequence of any types to the type void.
Definition: traits.hpp:37
#define CUDF_ENABLE_IF(...)
Convenience macro for SFINAE as an unnamed template parameter.
Definition: traits.hpp:50
Class definition for cudf::list_view.
cuDF interfaces
Definition: host__udf.hpp:37
bool nullable(table_view const &view)
Returns True if any of the columns in the table is nullable. (not entire hierarchy)
bool has_nulls(table_view const &view)
Returns True if the table has nulls in any of its columns.
fixed_point and supporting types
APIs for spans.
Class definition for cudf::strings_column_view.
Class definition for cudf::struct_view.
Mutable value accessor of column without null bitmask.
T & operator()(cudf::size_type i)
Accessor.
mutable_value_accessor(mutable_column_device_view &_col)
Constructor.
mutable_column_device_view col
mutable column view of column in device
optional accessor of a column
cuda::std::optional< T > operator()(cudf::size_type i) const
Returns a cuda::std::optional of column[i].
column_device_view const col
column view of column in device
optional_accessor(column_device_view const &_col, Nullate with_nulls)
Constructor.
pair accessor of column with/without null bitmask
column_device_view const col
column view of column in device
thrust::pair< T, bool > operator()(cudf::size_type i) const
Pair accessor.
pair_accessor(column_device_view const &_col)
constructor
pair accessor of column with/without null bitmask
thrust::pair< rep_type, bool > operator()(cudf::size_type i) const
Pair accessor.
column_device_view const col
column view of column in device
device_storage_type_t< T > rep_type
representation type
pair_rep_accessor(column_device_view const &_col)
constructor
value accessor of column without null bitmask
column_device_view const col
column view of column in device
value_accessor(column_device_view const &_col)
constructor
T operator()(cudf::size_type i) const
Returns the value of element at index i
Device version of C++20 std::span with reduced feature set.
Definition: span.hpp:355
A strongly typed wrapper for indices in a DICTIONARY type column.
Definition: dictionary.hpp:49
nullate::DYNAMIC defers the determination of nullability to run time rather than compile time....
bool value
True if nulls are expected.
constexpr DYNAMIC(bool b) noexcept
Create a runtime nullate object.
Indicates the presence of nulls at compile-time or runtime.
Helper struct for constructing fixed_point when value is already shifted.
Defines the mapping between cudf::type_id runtime type information and concrete C++ types.
Type declarations for libcudf.
#define CUDF_HOST_DEVICE
Indicates that the function or method is usable on host and device.
Definition: types.hpp:32