types.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
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 // Forward declarations
43 namespace rmm {
44 class device_buffer;
46 
47 } // namespace rmm
48 
49 namespace CUDF_EXPORT cudf {
50 // Forward declaration
51 class column;
52 class column_view;
53 class mutable_column_view;
54 class string_view;
55 class list_view;
56 class struct_view;
57 class scalar;
58 
59 // clang-format off
60 class list_scalar;
61 class struct_scalar;
62 class string_scalar;
63 template <typename T> class numeric_scalar;
64 template <typename T> class fixed_point_scalar;
65 template <typename T> class timestamp_scalar;
66 template <typename T> class duration_scalar;
67 
68 class string_scalar_device_view;
69 template <typename T> class numeric_scalar_device_view;
70 template <typename T> class fixed_point_scalar_device_view;
71 template <typename T> class timestamp_scalar_device_view;
72 template <typename T> class duration_scalar_device_view;
73 // clang-format on
74 
75 class table;
76 class table_view;
77 class mutable_table_view;
78 
85 using size_type = int32_t;
86 using bitmask_type = uint32_t;
87 using valid_type = uint8_t;
88 using thread_index_type = int64_t;
89 using char_utf8 = uint32_t;
90 
99 template <typename T>
101 {
102  return static_cast<size_type>(cuda::std::distance(f, l));
103 }
104 
108 enum class order : bool {
109  ASCENDING,
110  DESCENDING
111 };
112 
116 enum class null_policy : bool {
117  EXCLUDE,
118  INCLUDE
119 };
120 
124 enum class nan_policy : bool {
125  NAN_IS_NULL,
126  NAN_IS_VALID
127 };
128 
133 enum class nan_equality /*unspecified*/ {
134  ALL_EQUAL,
135  UNEQUAL
136 };
137 
141 enum class null_equality : bool {
142  EQUAL,
143  UNEQUAL
144 };
145 
149 enum class null_order : bool {
150  AFTER,
151  BEFORE
152 };
153 
157 enum class sorted : bool { NO, YES };
158 
162 struct order_info {
166 };
167 
171 enum class mask_state : int32_t {
172  UNALLOCATED,
173  UNINITIALIZED,
174  ALL_VALID,
175  ALL_NULL
176 };
177 
182 enum class interpolation : int32_t {
183  LINEAR,
184  LOWER,
185  HIGHER,
186  MIDPOINT,
187  NEAREST
188 };
189 
193 enum class type_id : int32_t {
194  EMPTY,
195  INT8,
196  INT16,
197  INT32,
198  INT64,
199  UINT8,
200  UINT16,
201  UINT32,
202  UINT64,
203  FLOAT32,
204  FLOAT64,
205  BOOL8,
211  DURATION_DAYS,
216  DICTIONARY32,
217  STRING,
218  LIST,
219  DECIMAL32,
220  DECIMAL64,
221  DECIMAL128,
222  STRUCT,
223  // `NUM_TYPE_IDS` must be last!
224  NUM_TYPE_IDS
225 };
226 
232 enum class null_aware : bool {
233  NO = 0,
234  YES = 1
235 };
236 
258 enum class output_nullability : uint8_t {
259  PRESERVE = 0,
260  ALL_VALID = 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
@ LOWER
all lower case characters
null_order
Indicates how null values compare against all other values.
Definition: types.hpp:149
null_equality
Enum to consider two nulls as equal or unequal.
Definition: types.hpp:141
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:85
null_policy
Enum to specify whether to include nulls or exclude nulls.
Definition: types.hpp:116
uint32_t bitmask_type
Bitmask type stored as 32-bit unsigned integer.
Definition: types.hpp:86
output_nullability
Indicates the null output policy of a function.
Definition: types.hpp:258
size_type distance(T f, T l)
Similar to std::distance but returns cudf::size_type and performs static_cast
Definition: types.hpp:100
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:232
mask_state
Controls the allocation/initialization of a null mask.
Definition: types.hpp:171
std::size_t size_of(data_type t)
Returns the size in bytes of elements of the specified data_type
int64_t thread_index_type
Thread index type in kernels.
Definition: types.hpp:88
nan_policy
Enum to treat NaN floating point value as null or non-null element.
Definition: types.hpp:124
order
Indicates the order in which elements should be sorted.
Definition: types.hpp:108
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:87
interpolation
Interpolation method to use when the desired quantile lies between two data points i and j.
Definition: types.hpp:182
sorted
Indicates whether a collection of values is known to be sorted.
Definition: types.hpp:157
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:193
nan_equality
Enum to consider different elements (of floating point types) holding NaN value as equal or unequal.
Definition: types.hpp:133
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.
@ 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.
@ FLOAT64
8 byte floating point
@ 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.
@ INT16
2 byte signed integer
@ 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
@ FLOAT32
4 byte floating point
@ 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
@ INT8
1 byte signed 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:162
order ordering
Indicates the order in which the values are sorted.
Definition: types.hpp:164
null_order null_ordering
Indicates how null values compare against all other values.
Definition: types.hpp:165
sorted is_sorted
Indicates whether the collection is sorted.
Definition: types.hpp:163
#define CUDF_HOST_DEVICE
Indicates that the function or method is usable on host and device.
Definition: types.hpp:21