binaryop.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 
8 #include <cudf/column/column.hpp>
9 #include <cudf/scalar/scalar.hpp>
10 #include <cudf/utilities/export.hpp>
12 
13 #include <memory>
14 
20 namespace CUDF_EXPORT cudf {
21 
30 enum class binary_operator : int32_t {
31  ADD,
32  SUB,
33  MUL,
34  DIV,
35  TRUE_DIV,
36  FLOOR_DIV,
44  MOD,
45  PMOD,
48  PYMOD,
49  POW,
50  INT_POW,
52  LOG_BASE,
53  ATAN2,
54  SHIFT_LEFT,
55  SHIFT_RIGHT,
58  BITWISE_AND,
59  BITWISE_OR,
60  BITWISE_XOR,
61  LOGICAL_AND,
62  LOGICAL_OR,
63  EQUAL,
64  NOT_EQUAL,
65  LESS,
66  GREATER,
67  LESS_EQUAL,
68  GREATER_EQUAL,
69  NULL_EQUALS,
73  NULL_MAX,
75  NULL_MIN,
79  NULL_LOGICAL_AND,
81  NULL_LOGICAL_OR,
84 };
85 
87 template <typename L, typename R, typename = void>
89 
91 template <typename L, typename R>
92 struct binary_op_common_type<L, R, std::enable_if_t<has_common_type_v<L, R>>> {
94  using type = std::common_type_t<L, R>;
95 };
96 
98 template <typename L, typename R>
100  L,
101  R,
102  std::enable_if_t<is_fixed_point<L>() && cuda::std::is_floating_point_v<R>>> {
104  using type = L;
105 };
106 
108 template <typename L, typename R>
110  L,
111  R,
112  std::enable_if_t<is_fixed_point<R>() && cuda::std::is_floating_point_v<L>>> {
114  using type = R;
115 };
116 
118 template <typename L, typename R>
120 
121 namespace detail {
122 template <typename AlwaysVoid, typename L, typename R>
123 struct binary_op_has_common_type_impl : std::false_type {};
124 
125 template <typename L, typename R>
126 struct binary_op_has_common_type_impl<std::void_t<binary_op_common_type_t<L, R>>, L, R>
127  : std::true_type {};
128 } // namespace detail
129 
131 template <typename L, typename R>
132 constexpr inline bool binary_op_has_common_type_v =
133  detail::binary_op_has_common_type_impl<void, L, R>::value;
134 
158 std::unique_ptr<column> binary_operation(
159  scalar const& lhs,
160  column_view const& rhs,
161  binary_operator op,
162  data_type output_type,
165 
189 std::unique_ptr<column> binary_operation(
190  column_view const& lhs,
191  scalar const& rhs,
192  binary_operator op,
193  data_type output_type,
196 
219 std::unique_ptr<column> binary_operation(
220  column_view const& lhs,
221  column_view const& rhs,
222  binary_operator op,
223  data_type output_type,
226 
250 std::unique_ptr<column> binary_operation(
251  column_view const& lhs,
252  column_view const& rhs,
253  std::string const& ptx,
254  data_type output_type,
257 
267  int32_t left_scale,
268  int32_t right_scale);
269 
279  cudf::data_type const& lhs,
280  cudf::data_type const& rhs);
281 
282 namespace binops {
283 
295 
305 std::pair<rmm::device_buffer, size_type> scalar_col_valid_mask_and(
306  column_view const& col,
307  scalar const& s,
310 
311 } // namespace binops
312  // end of group
314 } // namespace CUDF_EXPORT cudf
315 
316 namespace CUDF_EXPORT cudf {
317 namespace binops::compiled::detail {
318 
331  column_view const& lhs,
332  column_view const& rhs,
333  bool is_lhs_scalar,
334  bool is_rhs_scalar,
335  binary_operator op,
336  rmm::cuda_stream_view stream);
337 } // namespace binops::compiled::detail
338 } // namespace CUDF_EXPORT cudf
std::pair< rmm::device_buffer, size_type > scalar_col_valid_mask_and(column_view const &col, scalar const &s, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Computes output valid mask for op between a column and a scalar.
void apply_sorting_struct_binary_op(mutable_column_view &out, column_view const &lhs, column_view const &rhs, bool is_lhs_scalar, bool is_rhs_scalar, binary_operator op, rmm::cuda_stream_view stream)
struct binary operation using NaN aware sorting physical element comparators
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:278
A non-owning, mutable view of device data as a column of elements, some of which may be null as indic...
An owning class to represent a singular value.
Definition: scalar.hpp:41
Class definition for cudf::column.
rmm::cuda_stream_view 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
binary_operator
Types of binary operations that can be performed on data.
Definition: binaryop.hpp:30
typename binary_op_common_type< L, R >::type binary_op_common_type_t
Binary operation common type helper.
Definition: binaryop.hpp:119
cudf::data_type binary_operation_fixed_point_output_type(binary_operator op, cudf::data_type const &lhs, cudf::data_type const &rhs)
Computes the data_type for a fixed_point number based on given binary operator op
bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op)
Returns true if the binary operator is supported for the given input types.
int32_t binary_operation_fixed_point_scale(binary_operator op, int32_t left_scale, int32_t right_scale)
Computes the scale for a fixed_point number based on given binary operator op
std::unique_ptr< column > binary_operation(column_view const &lhs, column_view const &rhs, std::string const &ptx, data_type output_type, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Performs a binary operation between two columns using a user-defined PTX function.
constexpr bool binary_op_has_common_type_v
Checks if binary operation types have a common type.
Definition: binaryop.hpp:132
@ INVALID_BINARY
invalid operation
@ LOG_BASE
logarithm to the base
@ SHIFT_LEFT
operator <<
@ SHIFT_RIGHT
operator >>
@ ATAN2
2-argument arctangent
void void_t
Utility metafunction that maps a sequence of any types to the type void.
Definition: traits.hpp:30
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:26
Class definitions for cudf::scalar.
std::common_type_t< L, R > type
The common type of the template parameters.
Definition: binaryop.hpp:94
Binary operation common type default.
Definition: binaryop.hpp:88