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>
22 
24 #include <rmm/resource_ref.hpp>
25 
26 #include <memory>
27 
28 namespace CUDF_EXPORT cudf {
29 
40 enum class binary_operator : int32_t {
41  ADD,
42  SUB,
43  MUL,
44  DIV,
45  TRUE_DIV,
46  FLOOR_DIV,
54  MOD,
55  PMOD,
58  PYMOD,
59  POW,
60  INT_POW,
62  LOG_BASE,
63  ATAN2,
64  SHIFT_LEFT,
65  SHIFT_RIGHT,
68  BITWISE_AND,
69  BITWISE_OR,
70  BITWISE_XOR,
71  LOGICAL_AND,
72  LOGICAL_OR,
73  EQUAL,
74  NOT_EQUAL,
75  LESS,
76  GREATER,
77  LESS_EQUAL,
78  GREATER_EQUAL,
79  NULL_EQUALS,
83  NULL_MAX,
85  NULL_MIN,
89  NULL_LOGICAL_AND,
91  NULL_LOGICAL_OR,
94 };
95 
97 template <typename L, typename R, typename = void>
99 
101 template <typename L, typename R>
102 struct binary_op_common_type<L, R, std::enable_if_t<has_common_type_v<L, R>>> {
104  using type = std::common_type_t<L, R>;
105 };
106 
108 template <typename L, typename R>
110  L,
111  R,
112  std::enable_if_t<is_fixed_point<L>() && cuda::std::is_floating_point_v<R>>> {
114  using type = L;
115 };
116 
118 template <typename L, typename R>
120  L,
121  R,
122  std::enable_if_t<is_fixed_point<R>() && cuda::std::is_floating_point_v<L>>> {
124  using type = R;
125 };
126 
128 template <typename L, typename R>
130 
131 namespace detail {
132 template <typename AlwaysVoid, typename L, typename R>
133 struct binary_op_has_common_type_impl : std::false_type {};
134 
135 template <typename L, typename R>
136 struct binary_op_has_common_type_impl<std::void_t<binary_op_common_type_t<L, R>>, L, R>
137  : std::true_type {};
138 } // namespace detail
139 
141 template <typename L, typename R>
142 constexpr inline bool binary_op_has_common_type_v =
143  detail::binary_op_has_common_type_impl<void, L, R>::value;
144 
168 std::unique_ptr<column> binary_operation(
169  scalar const& lhs,
170  column_view const& rhs,
171  binary_operator op,
172  data_type output_type,
175 
199 std::unique_ptr<column> binary_operation(
200  column_view const& lhs,
201  scalar const& rhs,
202  binary_operator op,
203  data_type output_type,
206 
229 std::unique_ptr<column> binary_operation(
230  column_view const& lhs,
231  column_view const& rhs,
232  binary_operator op,
233  data_type output_type,
236 
260 std::unique_ptr<column> binary_operation(
261  column_view const& lhs,
262  column_view const& rhs,
263  std::string const& ptx,
264  data_type output_type,
267 
277  int32_t left_scale,
278  int32_t right_scale);
279 
289  cudf::data_type const& lhs,
290  cudf::data_type const& rhs);
291 
292 namespace binops {
293 
304 
314 std::pair<rmm::device_buffer, size_type> scalar_col_valid_mask_and(
315  column_view const& col,
316  scalar const& s,
319 
320 } // namespace binops
321  // end of group
323 } // namespace CUDF_EXPORT cudf
324 
325 namespace CUDF_EXPORT cudf {
326 namespace binops::compiled::detail {
327 
340  column_view const& lhs,
341  column_view const& rhs,
342  bool is_lhs_scalar,
343  bool is_rhs_scalar,
344  binary_operator op,
345  rmm::cuda_stream_view stream);
346 } // namespace binops::compiled::detail
347 } // 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=rmm::mr::get_current_device_resource())
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.
cuda::mr::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
device_memory_resource * get_current_device_resource()
binary_operator
Types of binary operations that can be performed on data.
Definition: binaryop.hpp:40
typename binary_op_common_type< L, R >::type binary_op_common_type_t
Binary operation common type helper.
Definition: binaryop.hpp:129
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
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=rmm::mr::get_current_device_resource())
Performs a binary operation between two columns using a user-defined PTX function.
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
constexpr bool binary_op_has_common_type_v
Checks if binary operation types have a common type.
Definition: binaryop.hpp:142
@ 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:37
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:104
Binary operation common type default.
Definition: binaryop.hpp:98