binaryop.hpp
前往此文件的文档。
1 /*
2  * Copyright (c) 2019-2024, NVIDIA CORPORATION.
3  *
4  * 根据 Apache 许可证 2.0 版(“许可证”)获得许可;
5  * 除非遵守许可证的规定,否则您不得使用本文件。
6  * 您可从以下网址获得许可证的副本
7  *
8  * https://apache.ac.cn/licenses/LICENSE-2.0
9  *
10  * 除非适用法律要求或书面同意,软件
11  * 根据许可证分发,按“现状”分发,
12  * 不附带任何明示或暗示的保证或条件。
13  * 请参阅许可证了解管辖权限和
14  * 许可证下的限制的特定语言。
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 /// 可对数据执行的二元运算类型。
39 enum class binary_operator : int32_t {
40  ADD,
41  SUB,
42  MUL,
43  DIV,
44  TRUE_DIV,
52  FLOOR_DIV,
53  MOD,
56  /// PMOD
57  PMOD,
58  PYMOD,
60  POW,
61  /// 对数
62  INT_POW,
63  /// 双参数反正切
64  LOG_BASE,
66  /// 运算符 <<
67  ATAN2,
68  /// 运算符 >>
69  SHIFT_LEFT,
72  BITWISE_AND,
73  BITWISE_OR,
74  BITWISE_XOR,
75  LOGICAL_AND,
76  LOGICAL_OR,
77  EQUAL,
78  NOT_EQUAL,
79  LESS,
80  GREATER,
81  LESS_EQUAL,
82  GREATER_EQUAL,
87  NULL_MAX,
89  NULL_MIN,
93  NULL_LOGICAL_AND,
95  NULL_LOGICAL_OR,
96  /// 无效操作
98 };
99 
101 /// 二元运算通用类型默认值。
102 template <typename L, typename R, typename = void>
104 
106 /// \private
107 template <typename L, typename R>
108 struct binary_op_common_type<L, R, std::enable_if_t<has_common_type_v<L, R>>> {
110  /// 模板参数的通用类型。
111 using type = std::common_type_t<L, R>;
112 };
113 
115 /// \private
116 template <typename L, typename R>
118  L,
119  R,
120  std::enable_if_t<is_fixed_point<L>() && cuda::std::is_floating_point_v<R>>> {
122  using type = L;
123 };
124 
126 /// \private
128  L,
129  R,
130  std::enable_if_t<is_fixed_point<R>() && cuda::std::is_floating_point_v<L>>> {
132  using type = R;
133 };
134 
136 /// Binary operation common type helper.
137 template <typename L, typename R>
139 
140 namespace detail {
141 template <typename AlwaysVoid, typename L, typename R>
142 struct binary_op_has_common_type_impl : std::false_type {};
143 
144 template <typename L, typename R>
145 struct binary_op_has_common_type_impl<std::void_t<binary_op_common_type_t<L, R>>, L, R>
146  : std::true_type {};
147 } // namespace detail
148 
150 /// Checks if binary operation types have a common type.
151 template <typename L, typename R>
152 constexpr inline bool binary_op_has_common_type_v =
153  detail::binary_op_has_common_type_impl<void, L, R>::value;
154 
166 /// Performs a binary operation between a scalar and a column.
167 std::unique_ptr<column> binary_operation(
168  scalar const& lhs,
169  column_view const& rhs,
170  binary_operator op,
171  data_type output_type,
174 
197 /// Performs a binary operation between a column and a scalar.
198 std::unique_ptr<column> binary_operation(
199  column_view const& lhs,
200  scalar const& rhs,
201  binary_operator op,
202  data_type output_type,
205 
227 /// Performs a binary operation between two columns.
228 std::unique_ptr<column> binary_operation(
229  column_view const& lhs,
230  column_view const& rhs,
231  binary_operator op,
232  data_type output_type,
235 
258 /// Performs a binary operation between two columns using a user-defined PTX function.
259 std::unique_ptr<column> binary_operation(
260  column_view const& lhs,
261  column_view const& rhs,
262  std::string const& ptx,
263  data_type output_type,
266 
274 /// 根据给定的二元运算符 op 计算定点数的比例。
276  int32_t left_scale,
277  int32_t right_scale);
278 
286 /// 根据给定的二元运算符 op 计算定点数的数据类型。
288  cudf::data_type const& lhs,
289  cudf::data_type const& rhs);
290 
291 namespace binops {
292 
301 /// @brief 检查给定的输入类型是否支持二元运算符。
303 
312 /// @brief 计算列与标量之间操作的输出有效掩码。
313 std::pair<rmm::device_buffer, size_type> scalar_col_valid_mask_and(
314  column_view const& col,
315  scalar const& s,
318 
319 } // namespace binops
320  /// end of group
321 } // namespace CUDF_EXPORT cudf
322 
323 namespace CUDF_EXPORT cudf {
324 namespace binops::compiled::detail {
325 
337 /// @brief 使用 NaN 感知的排序物理元素比较器进行结构二元运算
339  column_view const& lhs,
340  column_view const& rhs,
341  bool is_lhs_scalar,
342  bool is_rhs_scalar,
343  binary_operator op,
344  rmm::cuda_stream_view stream);
345 } // namespace binops::compiled::detail
346 } // namespace CUDF_EXPORT cudf
bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op)
cudf::binops::scalar_col_valid_mask_and
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())
cudf::binops::compiled::detail::apply_sorting_struct_binary_op
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)
使用 NaN 感知的排序物理元素比较器进行结构二元运算
表示设备数据作为元素列的非拥有、不可变视图,其中一些元素可能为空,如指示...
cudf::data_type
列中元素的逻辑数据类型指示器。
表示设备数据作为元素列的非拥有、可变视图,其中一些元素可能为空,如指示...
cudf::scalar
rmm::cuda_stream_view
cudf::column 的类定义。
cudf::get_default_stream
获取当前默认流。
cudf::get_current_device_resource_ref
获取当前设备内存资源引用。
device_async_resource_ref
cudf::binary_operation_fixed_point_output_type
int32_t binary_operation_fixed_point_scale(binary_operator op, int32_t left_scale, int32_t right_scale)
cudf::binary_operation
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())
检查二元运算类型是否具有通用类型。
cudf::binary_operator::INVALID_BINARY
无效操作
cudf::binary_operator::LOG_BASE
对数
cudf::binary_operator::NULL_NOT_EQUALS
cudf::binary_operator::GENERIC_BINARY
cudf::binary_operator::SHIFT_RIGHT_UNSIGNED
@ SHIFT_RIGHT_UNSIGNED
cudf::binary_operator::PMOD
cudf::binary_operator::SHIFT_LEFT
@ SHIFT_LEFT
cudf::binary_operator::NULL_EQUALS
cudf::binary_operator::INT_POW
@ INT_POW
cudf::binary_operator::NULL_MIN
cudf::binary_operator::SHIFT_RIGHT
@ INT_POW
@ SHIFT_RIGHT
cudf::binary_operator::ATAN2
@ INT_POW
@ ATAN2
cudf::binary_operator::NULL_MAX
@ NULL_MAX