types.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #ifdef __CUDACC__
12 #define CUDF_HOST_DEVICE __host__ __device__
16 #define CUDF_KERNEL __global__ static
17 #else
21 #define CUDF_HOST_DEVICE
25 #define CUDF_KERNEL static
26 #endif
27 
28 #include <cudf/utilities/export.hpp>
29 
30 #include <cuda/std/iterator>
31 
32 #include <cassert>
33 #include <cstddef>
34 #include <cstdint>
35 
41 namespace CUDF_EXPORT cudf {
42 // Forward declaration
43 class column;
44 class column_view;
45 class mutable_column_view;
46 class string_view;
47 class list_view;
48 class struct_view;
49 class scalar;
50 
51 // clang-format off
52 class list_scalar;
53 class struct_scalar;
54 class string_scalar;
55 template <typename T> class numeric_scalar;
56 template <typename T> class fixed_point_scalar;
57 template <typename T> class timestamp_scalar;
58 template <typename T> class duration_scalar;
59 
60 class string_scalar_device_view;
61 template <typename T> class numeric_scalar_device_view;
62 template <typename T> class fixed_point_scalar_device_view;
63 template <typename T> class timestamp_scalar_device_view;
64 template <typename T> class duration_scalar_device_view;
65 // clang-format on
66 
67 class table;
68 class table_view;
69 class mutable_table_view;
70 
76 using size_type = int32_t;
77 using bitmask_type = uint32_t;
78 using valid_type = uint8_t;
79 using thread_index_type = int64_t;
80 using char_utf8 = uint32_t;
81 
90 template <typename T>
92 {
93  return static_cast<size_type>(cuda::std::distance(f, l));
94 }
95 
99 enum class order : bool {
100  ASCENDING,
101  DESCENDING
102 };
103 
107 enum class null_policy : bool {
108  EXCLUDE,
109  INCLUDE
110 };
111 
115 enum class nan_policy : bool {
116  NAN_IS_NULL,
117  NAN_IS_VALID
118 };
119 
124 enum class nan_equality /*unspecified*/ {
125  ALL_EQUAL,
126  UNEQUAL
127 };
128 
132 enum class null_equality : bool {
133  EQUAL,
134  UNEQUAL
135 };
136 
140 enum class null_order : bool {
141  AFTER,
142  BEFORE
143 };
144 
148 enum class sorted : bool { NO, YES };
149 
153 struct order_info {
157 };
158 
162 enum class mask_state : int32_t {
163  UNALLOCATED,
164  UNINITIALIZED,
165  ALL_VALID,
166  ALL_NULL
167 };
168 
173 enum class interpolation : int32_t {
174  LINEAR,
175  LOWER,
176  HIGHER,
177  MIDPOINT,
178  NEAREST,
180 };
181 
185 enum class type_id : int32_t {
186  EMPTY,
187  INT8,
188  INT16,
189  INT32,
190  INT64,
191  UINT8,
192  UINT16,
193  UINT32,
194  UINT64,
195  FLOAT32,
196  FLOAT64,
197  BOOL8,
203  DURATION_DAYS,
208  DICTIONARY32,
209  STRING,
210  LIST,
211  DECIMAL32,
212  DECIMAL64,
213  DECIMAL128,
214  STRUCT,
215  // `NUM_TYPE_IDS` must be last!
216  NUM_TYPE_IDS
217 };
218 
224 enum class null_aware : bool {
225  NO = 0,
226  YES = 1
227 };
228 
250 enum class output_nullability : uint8_t {
251  PRESERVE = 0,
252  ALL_VALID = 1
254 };
255 
260 enum class error_policy : uint8_t {
261  PROPAGATE = 0,
262  NULLIFY = 1
263 };
264 
268 enum class udf_source_type : uint8_t {
269  CUDA = 0,
270  PTX = 1
271 };
272 
279 class data_type {
280  public:
281  data_type() = default;
282  ~data_type() = default;
283  data_type(data_type const&) = default;
284  data_type(data_type&&) = default;
285 
291  data_type& operator=(data_type const&) = default;
292 
299 
305  CUDF_HOST_DEVICE explicit constexpr data_type(type_id id) : _id{id} {}
306 
313  explicit data_type(type_id id, int32_t scale) : _id{id}, _fixed_point_scale{scale}
314  {
315  assert(id == type_id::DECIMAL32 || id == type_id::DECIMAL64 || id == type_id::DECIMAL128);
316  }
317 
323  [[nodiscard]] CUDF_HOST_DEVICE constexpr type_id id() const noexcept { return _id; }
324 
330  [[nodiscard]] CUDF_HOST_DEVICE constexpr int32_t scale() const noexcept
331  {
332  return _fixed_point_scale;
333  }
334 
335  private:
336  type_id _id{type_id::EMPTY};
337 
338  // Below is additional type specific metadata. Currently, only _fixed_point_scale is stored.
339 
340  int32_t _fixed_point_scale{}; // numeric::scale_type not available here, use int32_t
341 };
342 
355 constexpr bool operator==(data_type const& lhs, data_type const& rhs)
356 {
357  // use std::tie in the future, breaks NVRTC currently
358  return lhs.id() == rhs.id() && lhs.scale() == rhs.scale();
359 }
360 
373 inline bool operator!=(data_type const& lhs, data_type const& rhs) { return !(lhs == rhs); }
374 
385 std::size_t size_of(data_type t);
386 
388 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:279
data_type & operator=(data_type &&)=default
Move assignment operator for data_type.
data_type(data_type &&)=default
Move constructor.
constexpr CUDF_HOST_DEVICE type_id id() const noexcept
Returns the type identifier.
Definition: types.hpp:323
data_type(type_id id, int32_t scale)
Construct a new data_type object for numeric::fixed_point
Definition: types.hpp:313
data_type & operator=(data_type const &)=default
Copy assignment operator for data_type.
data_type(data_type const &)=default
Copy constructor.
constexpr CUDF_HOST_DEVICE data_type(type_id id)
Construct a new data_type object.
Definition: types.hpp:305
constexpr CUDF_HOST_DEVICE int32_t scale() const noexcept
Returns the scale (for fixed_point types)
Definition: types.hpp:330
@ NULLIFY
Output values corresponding to out-of-bounds indices are null.
@ LOWER
all lower case characters
null_order
Indicates how null values compare against all other values.
Definition: types.hpp:140
null_equality
Enum to consider two nulls as equal or unequal.
Definition: types.hpp:132
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:76
null_policy
Enum to specify whether to include nulls or exclude nulls.
Definition: types.hpp:107
uint32_t bitmask_type
Bitmask type stored as 32-bit unsigned integer.
Definition: types.hpp:77
output_nullability
Indicates the null output policy of a function.
Definition: types.hpp:250
size_type distance(T f, T l)
Similar to std::distance but returns cudf::size_type and performs static_cast
Definition: types.hpp:91
constexpr bool operator==(data_type const &lhs, data_type const &rhs)
Compares two data_type objects for equality.
Definition: types.hpp:355
null_aware
A function is null-aware if its output value uses the input validity.
Definition: types.hpp:224
mask_state
Controls the allocation/initialization of a null mask.
Definition: types.hpp:162
std::size_t size_of(data_type t)
Returns the size in bytes of elements of the specified data_type
error_policy
Indicates whether a function nullifies its output on error.
Definition: types.hpp:260
int64_t thread_index_type
Thread index type in kernels.
Definition: types.hpp:79
nan_policy
Enum to treat NaN floating point value as null or non-null element.
Definition: types.hpp:115
order
Indicates the order in which elements should be sorted.
Definition: types.hpp:99
bool operator!=(data_type const &lhs, data_type const &rhs)
Compares two data_type objects for inequality.
Definition: types.hpp:373
uint8_t valid_type
Valid type in host memory.
Definition: types.hpp:78
interpolation
Interpolation method to use when the desired quantile lies between two data points i and j.
Definition: types.hpp:173
sorted
Indicates whether a collection of values is known to be sorted.
Definition: types.hpp:148
udf_source_type
Indicates the source language of a user defined function (UDF) to be used in JIT APIs.
Definition: types.hpp:268
type_id
Identifies a column's logical element type.
Definition: types.hpp:185
nan_equality
Enum to consider different elements (of floating point types) holding NaN value as equal or unequal.
Definition: types.hpp:124
uint32_t char_utf8
UTF-8 characters are 1-4 bytes.
Definition: string_view.hpp:22
@ BEFORE
NULL values ordered before all other values.
@ AFTER
NULL values ordered after all other values.
@ INCLUDE
include null elements
@ EXCLUDE
exclude null elements
@ PRESERVE
A null-mask may be produced if needed.
@ ALL_VALID
Null mask allocated, initialized to all elements valid.
@ UNALLOCATED
Null mask not allocated, (all elements are valid)
@ ALL_NULL
Null mask allocated, initialized to all elements NULL.
@ UNINITIALIZED
Null mask allocated, but not initialized.
@ PROPAGATE
The function propagates errors.
@ NAN_IS_VALID
treat nans as valid elements (non-null)
@ NAN_IS_NULL
treat nans as null elements
@ HIGHER
Higher data point (j)
@ LINEAR
Linear interpolation between i and j.
@ NEAREST
i or j, whichever is nearest (half-to-even rounding)
@ NEAREST_HALF_UP
i or j, whichever is nearest (half-away-from-zero rounding)
@ CUDA
The UDF is a CUDA function.
@ PTX
The UDF is a PTX function.
@ BOOL8
Boolean using one byte per value, 0 == false, else true.
@ UINT32
4 byte unsigned integer
@ DURATION_MILLISECONDS
time interval of milliseconds in int64
@ NUM_TYPE_IDS
Total number of type ids.
@ UINT16
2 byte unsigned integer
@ DECIMAL128
Fixed-point type with __int128_t.
@ TIMESTAMP_MILLISECONDS
point in time in milliseconds since Unix Epoch in int64
@ DURATION_NANOSECONDS
time interval of nanoseconds in int64
@ DURATION_DAYS
time interval of days in int32
@ UINT64
8 byte unsigned integer
@ TIMESTAMP_MICROSECONDS
point in time in microseconds since Unix Epoch in int64
@ DURATION_SECONDS
time interval of seconds in int64
@ DURATION_MICROSECONDS
time interval of microseconds in int64
@ EMPTY
Always null with no underlying data.
@ TIMESTAMP_SECONDS
point in time in seconds since Unix Epoch in int64
@ TIMESTAMP_NANOSECONDS
point in time in nanoseconds since Unix Epoch in int64
@ TIMESTAMP_DAYS
point in time in days since Unix Epoch in int32
@ DECIMAL64
Fixed-point type with int64_t.
@ DECIMAL32
Fixed-point type with int32_t.
@ UINT8
1 byte unsigned integer
@ DICTIONARY32
Dictionary type using int32 indices.
@ UNEQUAL
All NaNs compare unequal (IEEE754 behavior)
@ ALL_EQUAL
All NaNs compare equal, regardless of sign.
cuDF interfaces
Definition: host_udf.hpp:27
Indicates how a collection of values has been ordered.
Definition: types.hpp:153
order ordering
Indicates the order in which the values are sorted.
Definition: types.hpp:155
null_order null_ordering
Indicates how null values compare against all other values.
Definition: types.hpp:156
sorted is_sorted
Indicates whether the collection is sorted.
Definition: types.hpp:154
#define CUDF_HOST_DEVICE
Indicates that the function or method is usable on host and device.
Definition: types.hpp:21