transform.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
9 #include <cudf/column/scalar_column_view.hpp>
10 #include <cudf/types.hpp>
11 #include <cudf/utilities/export.hpp>
13 
14 #include <functional>
15 #include <memory>
16 #include <optional>
17 #include <span>
18 #include <variant>
19 #include <vector>
20 
26 namespace CUDF_EXPORT cudf {
27 
37 using transform_input = std::variant<column_view, scalar_column_view>;
38 
45  data_type type = data_type{type_id::EMPTY};
46 
47  output_nullability nullability =
48  output_nullability::PRESERVE;
50 };
51 
70 [[deprecated("Use transform instead")]] std::unique_ptr<column> transform_extended(
71  std::span<transform_input const> inputs,
72  std::string const& udf,
73  data_type output_type,
74  udf_source_type source_type,
75  std::optional<void*> user_data = std::nullopt,
76  null_aware is_null_aware = null_aware::NO,
77  std::optional<size_type> row_size = std::nullopt,
78  output_nullability null_policy = output_nullability::PRESERVE,
79  cuda::stream_ref stream = cudf::get_default_stream(),
81 
91  type_id type = type_id::EMPTY;
92 
93  bool is_scalar = false;
94 
95  std::vector<transform_input_spec> children =
96  {};
97 };
98 
107  type_id type = type_id::EMPTY;
108 
109  output_nullability nullability =
110  output_nullability::PRESERVE;
111 
112  bool has_string_offsets = false;
113  std::vector<transform_output_spec> children =
114  {};
115 };
116 
126  private:
127  struct impl;
128 
129  std::unique_ptr<impl> impl_;
130 
131  public:
149  transform_program(std::string const& udf,
150  udf_source_type source_type,
151  null_aware is_null_aware,
152  std::optional<void*> user_data,
153  std::span<transform_input const> inputs,
154  std::span<transform_output const> outputs,
155  std::span<std::unique_ptr<column> const> string_offsets);
156 
172  transform_program(std::string const& udf,
173  udf_source_type source_type,
174  null_aware is_null_aware,
175  std::optional<void*> user_data,
176  std::span<transform_input_spec const> inputs,
177  std::span<transform_output_spec const> outputs);
178 
191  std::span<std::reference_wrapper<ast::expression const> const> expressions,
192  cuda::stream_ref stream = cudf::get_default_stream(),
194 
200 
207 
211 
229  std::unique_ptr<table> run(
230  std::span<transform_input const> inputs,
231  std::span<transform_output const> outputs,
232  std::vector<std::unique_ptr<column>>&& string_offsets,
233  std::optional<size_type> row_size,
234  cuda::stream_ref stream = cudf::get_default_stream(),
236 
248  std::unique_ptr<table> run(
249  table_view const& table,
250  cuda::stream_ref stream = cudf::get_default_stream(),
252 };
253 
295 std::unique_ptr<table> transform(
296  std::string const& udf,
297  udf_source_type source_type,
298  null_aware is_null_aware,
299  std::optional<void*> user_data,
300  std::span<transform_input const> inputs,
301  std::span<transform_output const> outputs,
302  std::vector<std::unique_ptr<column>>&& string_offsets,
303  std::optional<size_type> row_size,
304  cuda::stream_ref stream = cudf::get_default_stream(),
306 
325 [[deprecated("Use transform instead")]] std::unique_ptr<table> multi_transform(
326  std::string const& udf,
327  udf_source_type source_type,
328  null_aware is_null_aware,
329  std::optional<void*> user_data,
330  std::span<transform_input const> inputs,
331  std::span<transform_output const> outputs,
332  std::vector<std::unique_ptr<column>>&& string_offsets,
333  std::optional<size_type> row_size,
334  cuda::stream_ref stream = cudf::get_default_stream(),
336 
340 enum class lto_binary_type : uint8_t {
341  LTO_IR, //< LTO-IR binary
342  FATBIN //< FATBIN binary
343 };
344 
383 std::unique_ptr<table> transform_lto(
384  std::span<uint8_t const> udf,
385  lto_binary_type binary_type,
386  null_aware is_null_aware,
387  std::optional<void*> user_data,
388  std::span<transform_input const> inputs,
389  std::span<transform_output const> outputs,
390  std::vector<std::unique_ptr<column>>&& string_offsets,
391  std::optional<size_type> row_size,
392  cuda::stream_ref stream = cudf::get_default_stream(),
394 
409 [[deprecated]] std::pair<std::unique_ptr<rmm::device_buffer>, size_type> nans_to_nulls(
410  column_view const& input,
411  cuda::stream_ref stream = cudf::get_default_stream(),
413 
425 std::unique_ptr<column> column_nans_to_nulls(
426  column_view const& input,
427  cuda::stream_ref stream = cudf::get_default_stream(),
429 
448 std::unique_ptr<column> compute_column(
449  table_view const& table,
450  ast::expression const& expr,
451  cuda::stream_ref stream = cudf::get_default_stream(),
453 
471 std::unique_ptr<column> compute_column_jit(
472  table_view const& table,
473  ast::expression const& expr,
474  cuda::stream_ref stream = cudf::get_default_stream(),
476 
499 std::unique_ptr<table> compute_table_jit(
500  table_view const& table,
501  std::span<std::reference_wrapper<ast::expression const> const> expressions,
502  cuda::stream_ref stream = cudf::get_default_stream(),
504 
521 std::pair<std::unique_ptr<rmm::device_buffer>, cudf::size_type> bools_to_mask(
522  column_view const& input,
523  cuda::stream_ref stream = cudf::get_default_stream(),
525 
551 std::pair<std::unique_ptr<cudf::table>, std::unique_ptr<cudf::column>> encode(
552  cudf::table_view const& input,
553  cuda::stream_ref stream = cudf::get_default_stream(),
555 
584 std::pair<std::unique_ptr<column>, table_view> one_hot_encode(
585  column_view const& input,
586  column_view const& categories,
587  cuda::stream_ref stream = cudf::get_default_stream(),
589 
612 std::unique_ptr<column> mask_to_bools(
613  bitmask_type const* bitmask,
614  size_type begin_bit,
615  size_type end_bit,
616  cuda::stream_ref stream = cudf::get_default_stream(),
618 
645 std::unique_ptr<column> row_bit_count(
646  table_view const& t,
647  cuda::stream_ref stream = cudf::get_default_stream(),
649 
669 std::unique_ptr<column> segmented_row_bit_count(
670  table_view const& t,
671  size_type segment_length,
672  cuda::stream_ref stream = cudf::get_default_stream(),
674  // end of group
676 } // namespace CUDF_EXPORT cudf
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
Indicator for the logical data type of an element in a column.
Definition: types.hpp:279
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
A set of cudf::column's of the same size.
Definition: table.hpp:31
Class definitions for building and evaluating abstract syntax tree expressions.
cuda::stream_ref const get_default_stream()
Get the current default stream.
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
std::unique_ptr< table > multi_transform(std::string const &udf, udf_source_type source_type, null_aware is_null_aware, std::optional< void * > user_data, std::span< transform_input const > inputs, std::span< transform_output const > outputs, std::vector< std::unique_ptr< column >> &&string_offsets, std::optional< size_type > row_size, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new table by applying a transform function against every element of the input columns.
std::unique_ptr< column > row_bit_count(table_view const &t, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns an approximate cumulative size in bits of all columns in the table_view for each row.
std::unique_ptr< column > transform_extended(std::span< transform_input const > inputs, std::string const &udf, data_type output_type, udf_source_type source_type, std::optional< void * > user_data=std::nullopt, null_aware is_null_aware=null_aware::NO, std::optional< size_type > row_size=std::nullopt, output_nullability null_policy=output_nullability::PRESERVE, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new column by applying a transform function against every element of the input columns.
std::pair< std::unique_ptr< rmm::device_buffer >, size_type > nans_to_nulls(column_view const &input, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a null_mask from input by converting NaN to null and preserving existing null values and also...
std::unique_ptr< table > transform_lto(std::span< uint8_t const > udf, lto_binary_type binary_type, null_aware is_null_aware, std::optional< void * > user_data, std::span< transform_input const > inputs, std::span< transform_output const > outputs, std::vector< std::unique_ptr< column >> &&string_offsets, std::optional< size_type > row_size, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new table by applying a transform function against every element of the input columns.
std::unique_ptr< table > transform(std::string const &udf, udf_source_type source_type, null_aware is_null_aware, std::optional< void * > user_data, std::span< transform_input const > inputs, std::span< transform_output const > outputs, std::vector< std::unique_ptr< column >> &&string_offsets, std::optional< size_type > row_size, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new table by applying a transform function against every element of the input columns.
std::unique_ptr< column > column_nans_to_nulls(column_view const &input, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a null_mask from input by converting NaN elements to null rows and preserving existing null v...
std::unique_ptr< column > segmented_row_bit_count(table_view const &t, size_type segment_length, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns an approximate cumulative size in bits of all columns in the table_view for each segment of r...
std::unique_ptr< column > compute_column_jit(table_view const &table, ast::expression const &expr, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Compute a new column by evaluating an expression tree on a table using a JIT-compiled kernel.
std::variant< column_view, scalar_column_view > transform_input
Typedef for inputs to the transform function. Each input can be either a column or a scalar column.
Definition: transform.hpp:37
std::pair< std::unique_ptr< column >, table_view > one_hot_encode(column_view const &input, column_view const &categories, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Encodes input by generating a new column for each value in categories indicating the presence of that...
std::unique_ptr< table > compute_table_jit(table_view const &table, std::span< std::reference_wrapper< ast::expression const > const > expressions, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Compute a new table by evaluating expression trees on a table using a JIT-compiled kernel.
std::unique_ptr< column > mask_to_bools(bitmask_type const *bitmask, size_type begin_bit, size_type end_bit, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a boolean column from given bitmask.
std::pair< std::unique_ptr< cudf::table >, std::unique_ptr< cudf::column > > encode(cudf::table_view const &input, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Encode the rows of the given table as integers.
lto_binary_type
The type of LTO Binary.
Definition: transform.hpp:340
std::pair< std::unique_ptr< rmm::device_buffer >, cudf::size_type > bools_to_mask(column_view const &input, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a bitmask from a column of boolean elements.
std::unique_ptr< column > compute_column(table_view const &table, ast::expression const &expr, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Compute a new column by evaluating an expression tree on a table.
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
null_aware
A function is null-aware if its output value uses the input validity.
Definition: types.hpp:224
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
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:27
A generic expression that can be evaluated to return a value.
Definition: expressions.hpp:72
Describes a transform input independently of a particular column.
Definition: transform.hpp:90
Describes a transform output independently of a particular output column.
Definition: transform.hpp:106
Specification for the outputs of the transform function. This includes the output type and nullabilit...
Definition: transform.hpp:44
A reusable transform program that retains a JIT-compiled kernel.
Definition: transform.hpp:125
transform_program & operator=(transform_program const &)=delete
Deleted copy assignment.
std::unique_ptr< table > run(table_view const &table, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Evaluates the AST expressions used to construct this program on a table.
transform_program(table_view const &table, std::span< std::reference_wrapper< ast::expression const > const > expressions, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Constructs a reusable program for an AST expression.
transform_program(transform_program &&other)
Move constructor for transform_program.
transform_program(std::string const &udf, udf_source_type source_type, null_aware is_null_aware, std::optional< void * > user_data, std::span< transform_input const > inputs, std::span< transform_output const > outputs, std::span< std::unique_ptr< column > const > string_offsets)
Constructs a reusable program by deriving specifications from transform arguments.
transform_program(transform_program const &)=delete
Deleted copy constructor.
std::unique_ptr< table > run(std::span< transform_input const > inputs, std::span< transform_output const > outputs, std::vector< std::unique_ptr< column >> &&string_offsets, std::optional< size_type > row_size, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Runs the transform program on the given inputs and outputs.
transform_program & operator=(transform_program &&other)
Move assignment operator for transform_program.
~transform_program()
Destructor.
transform_program(std::string const &udf, udf_source_type source_type, null_aware is_null_aware, std::optional< void * > user_data, std::span< transform_input_spec const > inputs, std::span< transform_output_spec const > outputs)
Constructs a reusable program from explicit input and output specifications.
Type declarations for libcudf.