binaryop.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2024, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cudf/column/column.hpp>
20 #include <cudf/scalar/scalar.hpp>
21 #include <cudf/utilities/export.hpp>
23 
24 #include <memory>
25 
26 namespace CUDF_EXPORT cudf {
27 
38 enum class binary_operator : int32_t {
39  ADD,
40  SUB,
41  MUL,
42  DIV,
43  TRUE_DIV,
44  FLOOR_DIV,
52  MOD,
53  PMOD,
56  PYMOD,
57  POW,
58  INT_POW,
60  LOG_BASE,
61  ATAN2,
62  SHIFT_LEFT,
63  SHIFT_RIGHT,
66  BITWISE_AND,
67  BITWISE_OR,
68  BITWISE_XOR,
69  LOGICAL_AND,
70  LOGICAL_OR,
71  EQUAL,
72  NOT_EQUAL,
73  LESS,
74  GREATER,
75  LESS_EQUAL,
76  GREATER_EQUAL,
77  NULL_EQUALS,
81  NULL_MAX,
83  NULL_MIN,
87  NULL_LOGICAL_AND,
89  NULL_LOGICAL_OR,
92 };
93 
95 template <typename L, typename R, typename = void>
97 
99 template <typename L, typename R>
100 struct binary_op_common_type<L, R, std::enable_if_t<has_common_type_v<L, R>>> {
102  using type = std::common_type_t<L, R>;
103 };
104 
106 template <typename L, typename R>
108  L,
109  R,
110  std::enable_if_t<is_fixed_point<L>() && cuda::std::is_floating_point_v<R>>> {
112  using type = L;
113 };
114 
116 template <typename L, typename R>
118  L,
119  R,
120  std::enable_if_t<is_fixed_point<R>() && cuda::std::is_floating_point_v<L>>> {
122  using type = R;
123 };
124 
126 template <typename L, typename R>
128 
129 namespace detail {
130 template <typename AlwaysVoid, typename L, typename R>
131 struct binary_op_has_common_type_impl : std::false_type {};
132 
133 template <typename L, typename R>
134 struct binary_op_has_common_type_impl<std::void_t<binary_op_common_type_t<L, R>>, L, R>
135  : std::true_type {};
136 } // namespace detail
137 
139 template <typename L, typename R>
140 constexpr inline bool binary_op_has_common_type_v =
141  detail::binary_op_has_common_type_impl<void, L, R>::value;
142 
166 std::unique_ptr<column> binary_operation(
167  scalar const& lhs,
168  column_view const& rhs,
169  binary_operator op,
170  data_type output_type,
173 
197 std::unique_ptr<column> binary_operation(
198  column_view const& lhs,
199  scalar const& rhs,
200  binary_operator op,
201  data_type output_type,
204 
227 std::unique_ptr<column> binary_operation(
228  column_view const& lhs,
229  column_view const& rhs,
230  binary_operator op,
231  data_type output_type,
234 
258 std::unique_ptr<column> binary_operation(
259  column_view const& lhs,
260  column_view const& rhs,
261  std::string const& ptx,
262  data_type output_type,
265 
275  int32_t left_scale,
276  int32_t right_scale);
277 
287  cudf::data_type const& lhs,
288  cudf::data_type const& rhs);
289 
290 namespace binops {
291 
302 
312 std::pair<rmm::device_buffer, size_type> scalar_col_valid_mask_and(
313  column_view const& col,
314  scalar const& s,
317 
318 } // namespace binops
319  // end of group
321 } // namespace CUDF_EXPORT cudf
322 
323 namespace CUDF_EXPORT cudf {
324 namespace binops::compiled::detail {
325 
338  column_view const& lhs,
339  column_view const& rhs,
340  bool is_lhs_scalar,
341  bool is_rhs_scalar,
342  binary_operator op,
343  rmm::cuda_stream_view stream);
344 } // namespace binops::compiled::detail
345 } // namespace CUDF_EXPORT cudf
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.
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:243
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:49
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::async_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:38
typename binary_op_common_type< L, R >::type binary_op_common_type_t
Binary operation common type helper.
Definition: binaryop.hpp:127
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
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:140
@ 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:35
cuDF interfaces
Definition: aggregation.hpp:35
Class definitions for cudf::scalar.
std::common_type_t< L, R > type
The common type of the template parameters.
Definition: binaryop.hpp:102
Binary operation common type default.
Definition: binaryop.hpp:96