types.hpp
转到此文件的文档。
1 /*
2  * Copyright (c) 2018-2024, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://apache.ac.cn/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #ifdef __CUDACC__
23 #define CUDF_HOST_DEVICE __host__ __device__
27 #define CUDF_KERNEL __global__ static
28 #else
32 #define CUDF_HOST_DEVICE
36 #define CUDF_KERNEL static
37 #endif
38 
39 #include <cudf/utilities/export.hpp>
40 
41 #include <cassert>
42 #include <cstddef>
43 #include <cstdint>
44 #include <iterator>
45 
51 // Forward declarations
53 namespace rmm {
54 class device_buffer;
56 
57 } // namespace rmm
58 
59 namespace CUDF_EXPORT cudf {
60 // Forward declaration
61 class column;
62 class column_view;
63 class mutable_column_view;
64 class string_view;
65 class list_view;
66 class struct_view;
67 class scalar;
68 
69 // clang-format off
70 class list_scalar;
71 class struct_scalar;
72 class string_scalar;
73 template <typename T> class numeric_scalar;
74 template <typename T> class fixed_point_scalar;
75 template <typename T> class timestamp_scalar;
76 template <typename T> class duration_scalar;
77 
78 class string_scalar_device_view;
79 template <typename T> class numeric_scalar_device_view;
80 template <typename T> class fixed_point_scalar_device_view;
81 template <typename T> class timestamp_scalar_device_view;
82 template <typename T> class duration_scalar_device_view;
83 // clang-format on
84 
85 class table;
86 class table_view;
87 class mutable_table_view;
88 
95 using size_type = int32_t;
96 using bitmask_type = uint32_t;
97 using valid_type = uint8_t;
98 using thread_index_type = int64_t;
99 using char_utf8 = uint32_t;
100 
109 template <typename T>
111 {
112  return static_cast<size_type>(std::distance(f, l));
113 }
114 
118 enum class order : bool {
119  ASCENDING,
120  DESCENDING
121 };
122 
126 enum class null_policy : bool {
127  EXCLUDE,
128  INCLUDE
129 };
130 
134 enum class nan_policy : bool {
135  NAN_IS_NULL,
137 };
138 
143 enum class nan_equality /*unspecified*/ {
144  ALL_EQUAL,
145  UNEQUAL
146 };
147 
151 enum class null_equality : bool {
152  EQUAL,
153  UNEQUAL
154 };
155 
159 enum class null_order : bool {
160  AFTER,
161  BEFORE
162 };
163 
167 enum class sorted : bool { NO, YES };
168 
172 struct order_info {
176 };
177 
181 enum class mask_state : int32_t {
182  UNALLOCATED,
184  ALL_VALID,
185  ALL_NULL
186 };
187 
192 enum class interpolation : int32_t {
193  LINEAR,
194  LOWER,
195  HIGHER,
196  MIDPOINT,
197  NEAREST
198 };
199 
203 enum class type_id : int32_t {
204  EMPTY,
205  INT8,
206  INT16,
207  INT32,
208  INT64,
209  UINT8,
210  UINT16,
211  UINT32,
212  UINT64,
213  FLOAT32,
214  FLOAT64,
215  BOOL8,
226  DICTIONARY32,
227  STRING,
228  LIST,
229  DECIMAL32,
230  DECIMAL64,
231  DECIMAL128,
232  STRUCT,
233  // `NUM_TYPE_IDS` must be last!
235 };
236 
243 class data_type {
244  public
245  data_type() = default;
246  ~data_type() = default;
247  data_type(data_type const&) = default;
248  data_type(data_type&&) = default;
249 
255  data_type& operator=(data_type const&) = default;
256 
263 
269  CUDF_HOST_DEVICE explicit constexpr data_type(type_id id) : _id{id} {}
270 
277  explicit data_type(type_id id, int32_t scale) : _id{id}, _fixed_point_scale{scale}
278  {
279  assert(id == type_id::DECIMAL32 || id == type_id::DECIMAL64 || id == type_id::DECIMAL128);
280  }
281 
287  [[nodiscard]] CUDF_HOST_DEVICE constexpr type_id id() const noexcept { return _id; }
288 
294  [[nodiscard]] CUDF_HOST_DEVICE constexpr int32_t scale() const noexcept
295  {
296  return _fixed_point_scale;
297  }
298 
299  private
300  type_id _id{type_id::EMPTY};
301 
302  // Below is additional type specific metadata. Currently, only _fixed_point_scale is stored.
303 
304  int32_t _fixed_point_scale{}; // numeric::scale_type not available here, use int32_t
305 };
306 
319 constexpr bool operator==(data_type const& lhs, data_type const& rhs)
320 {
321  // use std::tie in the future, breaks JITIFY currently
322  return lhs.id() == rhs.id() && lhs.scale() == rhs.scale();
323 }
324 
337 inline bool operator!=(data_type const& lhs, data_type const& rhs) { return !(lhs == rhs); }
338 
349 std::size_t size_of(data_type t);
350 
352 } // namespace CUDF_EXPORT cudf
列中元素的逻辑数据类型的指示符。
定义: types.hpp:243
data_type & operator=(data_type &&)=default
data_type 的移动赋值运算符。
data_type(data_type &&)=default
移动构造函数。
constexpr CUDF_HOST_DEVICE type_id id() const noexcept
返回类型标识符。
定义: types.hpp:287
data_type(type_id id, int32_t scale)
构造一个新的用于 numeric::fixed_point 的 data_type 对象。
定义: types.hpp:277
data_type & operator=(data_type const &)=default
data_type 的拷贝赋值运算符。
data_type(data_type const &)=default
拷贝构造函数。
constexpr CUDF_HOST_DEVICE data_type(type_id id)
构造一个新的 data_type 对象。
定义: types.hpp:269
constexpr CUDF_HOST_DEVICE int32_t scale() const noexcept
返回小数位数(用于 fixed_point 类型)。
定义: types.hpp:294
@ LOWER
所有小写字符
null_order
指示 null 值与所有其他值的比较方式。
定义: types.hpp:159
null_equality
用于将两个 null 值视为相等或不相等的枚举。
定义: types.hpp:151
int32_t size_type
列和表的行索引类型。
定义: types.hpp:95
null_policy
用于指定是否包含 null 或排除 null 的枚举。
定义: types.hpp:126
uint32_t bitmask_type
存储为 32 位无符号整数的位掩码类型。
定义: types.hpp:96
size_type distance(T f, T l)
类似于 std::distance,但返回 cudf::size_type 并执行 static_cast。
定义: types.hpp:110
constexpr bool operator==(data_type const &lhs, data_type const &rhs)
比较两个 data_type 对象的相等性。
定义: types.hpp:319
mask_state
控制 null 掩码的分配/初始化。
定义: types.hpp:181
std::size_t size_of(data_type t)
返回指定 data_type 元素的字节大小。
int64_t thread_index_type
核函数中的线程索引类型。
定义: types.hpp:98
nan_policy
用于将 NaN 浮点值视为 null 或非 null 元素的枚举。
定义: types.hpp:134
order
指示元素应如何排序。
定义: types.hpp:118
bool operator!=(data_type const &lhs, data_type const &rhs)
比较两个 data_type 对象的不相等性。
定义: types.hpp:337
uint8_t valid_type
主机内存中的有效类型。
定义: types.hpp:97
interpolation
当所需的 quantile 位于两个数据点 i 和 j 之间时使用的插值方法。
定义: types.hpp:192
sorted
指示已知一组值是否已排序。
定义: types.hpp:167
type_id
标识列的逻辑元素类型。
定义: types.hpp:203
nan_equality
用于将持有 NaN 值的不同元素(浮点类型)视为相等或不相等的枚举。
定义: types.hpp:143
uint32_t char_utf8
UTF-8 字符为 1-4 字节。
@ BEFORE
NULL 值排在所有其他值之前。
@ AFTER
NULL 值排在所有其他值之后。
@ INCLUDE
包含 null 元素
@ EXCLUDE
排除 null 元素
@ ALL_VALID
已分配 null 掩码,初始化为所有元素都有效。
@ UNALLOCATED
未分配 null 掩码(所有元素都有效)。
@ ALL_NULL
已分配 null 掩码,初始化为所有元素都为 NULL。
@ UNINITIALIZED
已分配 null 掩码,但未初始化。
@ NAN_IS_VALID
将 NaN 视为有效元素(非 null)。
@ NAN_IS_NULL
将 NaN 视为 null 元素。
@ ASCENDING
元素从小到大排序。
@ DESCENDING
元素从大到小排序。
@ HIGHER
较高的数据点 (j)。
@ LINEAR
i 和 j 之间的线性插值。
@ NEAREST
i 或 j,取最接近的那个。
@ BOOL8
布尔类型,每个值使用一个字节,0 表示 false,否则为 true。
@ FLOAT64
8 字节浮点数。
@ UINT32
4 字节无符号整数。
@ DURATION_MILLISECONDS
int64 表示的毫秒时间间隔。
@ NUM_TYPE_IDS
类型 ID 的总数。
@ UINT16
2 字节无符号整数。
@ DECIMAL128
使用 __int128_t 的定点类型。
@ INT16
2 字节有符号整数。
@ TIMESTAMP_MILLISECONDS
自 Unix Epoch 起以 int64 表示的毫秒时间点。
@ DURATION_NANOSECONDS
int64 表示的纳秒时间间隔。
@ DURATION_DAYS
int32 表示的天时间间隔。
@ UINT64
8 字节无符号整数。
@ TIMESTAMP_MICROSECONDS
自 Unix Epoch 起以 int64 表示的微秒时间点。
@ DURATION_SECONDS
int64 表示的秒时间间隔。
@ DURATION_MICROSECONDS
int64 表示的微秒时间间隔。
@ FLOAT32
4 字节浮点数。
@ EMPTY
始终为 null,无底层数据。
@ TIMESTAMP_SECONDS
自 Unix Epoch 起以 int64 表示的秒时间点。
@ TIMESTAMP_NANOSECONDS
自 Unix Epoch 起以 int64 表示的纳秒时间点。
@ TIMESTAMP_DAYS
自 Unix Epoch 起以 int32 表示的天时间点。
@ DECIMAL64
使用 int64_t 的定点类型。
@ DECIMAL32
使用 int32_t 的定点类型。
@ UINT8
1 字节无符号整数。
@ INT8
1 字节有符号整数。
@ DICTIONARY32
使用 int32 索引的字典类型。
@ UNEQUAL
所有 NaN 比较结果均不相等 (IEEE754 行为)。
@ ALL_EQUAL
所有 NaN 比较结果均相等,无论符号如何。
cuDF 接口
定义: host_udf.hpp:37
指示一组值的排序方式。
定义: types.hpp:172
order ordering
指示值排序的顺序。
定义: types.hpp:174
null_order null_ordering
指示 null 值与所有其他值的比较方式。
定义: types.hpp:175
sorted is_sorted
指示集合是否已排序。
定义: types.hpp:173
#define CUDF_HOST_DEVICE
表示函数或方法可在 host 和 device 上使用。
定义: types.hpp:32