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
179 };
180 
184 enum class type_id : int32_t {
185  EMPTY,
186  INT8,
187  INT16,
188  INT32,
189  INT64,
190  UINT8,
191  UINT16,
192  UINT32,
193  UINT64,
194  FLOAT32,
195  FLOAT64,
196  BOOL8,
202  DURATION_DAYS,
207  DICTIONARY32,
208  STRING,
209  LIST,
210  DECIMAL32,
211  DECIMAL64,
212  DECIMAL128,
213  STRUCT,
214  // `NUM_TYPE_IDS` must be last!
215  NUM_TYPE_IDS
216 };
217 
223 enum class null_aware : bool {
224  NO = 0,
225  YES = 1
226 };
227 
249 enum class output_nullability : uint8_t {
250  PRESERVE = 0,
251  ALL_VALID = 1
253 };
254 
259 enum class error_policy : uint8_t {
260  PROPAGATE = 0,
261  NULLIFY = 1
262 };
263 
267 enum class udf_source_type : uint8_t {
268  CUDA = 0,
269  PTX = 1
270 };
271 
278 class data_type {
279  public:
280  data_type() = default;
281  ~data_type() = default;
282  data_type(data_type const&) = default;
283  data_type(data_type&&) = default;
284 
290  data_type& operator=(data_type const&) = default;
291 
298 
304  CUDF_HOST_DEVICE explicit constexpr data_type(type_id id) : _id{id} {}
305 
312  explicit data_type(type_id id, int32_t scale) : _id{id}, _fixed_point_scale{scale}
313  {
314  assert(id == type_id::DECIMAL32 || id == type_id::DECIMAL64 || id == type_id::DECIMAL128);
315  }
316 
322  [[nodiscard]] CUDF_HOST_DEVICE constexpr type_id id() const noexcept { return _id; }
323 
329  [[nodiscard]] CUDF_HOST_DEVICE constexpr int32_t scale() const noexcept
330  {
331  return _fixed_point_scale;
332  }
333 
334  private:
335  type_id _id{type_id::EMPTY};
336 
337  // Below is additional type specific metadata. Currently, only _fixed_point_scale is stored.
338 
339  int32_t _fixed_point_scale{}; // numeric::scale_type not available here, use int32_t
340 };
341 
354 constexpr bool operator==(data_type const& lhs, data_type const& rhs)
355 {
356  // use std::tie in the future, breaks NVRTC currently
357  return lhs.id() == rhs.id() && lhs.scale() == rhs.scale();
358 }
359 
372 inline bool operator!=(data_type const& lhs, data_type const& rhs) { return !(lhs == rhs); }
373 
384 std::size_t size_of(data_type t);
385 
387 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:278
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:322
data_type(type_id id, int32_t scale)
Construct a new data_type object for numeric::fixed_point
Definition: types.hpp:312
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:304
constexpr CUDF_HOST_DEVICE int32_t scale() const noexcept
Returns the scale (for fixed_point types)
Definition: types.hpp:329
@ 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:249
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:354
null_aware
A function is null-aware if its output value uses the input validity.
Definition: types.hpp:223
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:259
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:372
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:267
type_id
Identifies a column's logical element type.
Definition: types.hpp:184
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
@ 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:26
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