Skip to content

Commit

Permalink
format code and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
marigoold committed Aug 7, 2023
1 parent a34ed87 commit 70b528c
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 117 deletions.
98 changes: 42 additions & 56 deletions oneflow/core/ep/cpu/primitive/broadcast_elementwise_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,63 +563,49 @@ class BroadcastElementwiseBinaryFactoryImpl : public BroadcastElementwiseBinaryF
std::tuple<BinaryOp, DataType, DataType>,
std::function<std::unique_ptr<BroadcastElementwiseBinary>(Scalar, Scalar)>>
new_broadcast_elementwise_binary_handle{
OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_OP_SEQ, NDARRAY_BINARY_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_COMPLEX_MATH_OP_SEQ,
CPU_PRIMITIVE_COMPLEX_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
// MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
// BINARY_BITWISE_SHIFT_OP_SEQ, CPU_PRIMITIVE_INT_TYPE_SEQ)

// OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
// MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY,
// BINARY_LOGICAL_OP_SEQ BINARY_COMPARISION_OP_SEQ,
// NDARRAY_BINARY_TYPE_SEQ, CPU_PRIMITIVE_BOOL_TYPE_SEQ)

// OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
// MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_ACTIVATION_GRAD_ENTRY,
// BINARY_ACTIVATION_BACKWARD_OP_SEQ,
// CPU_PRIMITIVE_FLOATING_TYPE_SEQ)

// OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
// MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
// BINARY_MATH_BACKWARD_OP_SEQ,
// CPU_PRIMITIVE_FLOATING_TYPE_SEQ)};
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY, BINARY_BITWISE_OP_SEQ,
CPU_PRIMITIVE_INT_TYPE_SEQ CPU_PRIMITIVE_BOOL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_FLOATING_OP_SEQ, CPU_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY,
BINARY_LOGICAL_OP_SEQ BINARY_COMPARISION_OP_SEQ,
NDARRAY_BINARY_TYPE_SEQ, CPU_PRIMITIVE_BOOL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY,
BINARY_COMPLEX_COMPARISION_OP_SEQ,
CPU_PRIMITIVE_COMPLEX_TYPE_SEQ, CPU_PRIMITIVE_BOOL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_ACTIVATION_GRAD_ENTRY,
BINARY_ACTIVATION_BACKWARD_OP_SEQ,
CPU_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_BACKWARD_OP_SEQ,
CPU_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_BACKWARD_OP_SEQ_COMPLEX,
CPU_PRIMITIVE_COMPLEX_TYPE_SEQ)};
// clang-format off
OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_OP_SEQ, NDARRAY_BINARY_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_COMPLEX_MATH_OP_SEQ, CPU_PRIMITIVE_COMPLEX_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_BITWISE_SHIFT_OP_SEQ, CPU_PRIMITIVE_INT_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY, BINARY_BITWISE_OP_SEQ,
CPU_PRIMITIVE_INT_TYPE_SEQ CPU_PRIMITIVE_BOOL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_FLOATING_OP_SEQ, CPU_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY,
BINARY_LOGICAL_OP_SEQ BINARY_COMPARISION_OP_SEQ,
NDARRAY_BINARY_TYPE_SEQ, CPU_PRIMITIVE_BOOL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY,
BINARY_COMPLEX_COMPARISION_OP_SEQ,
CPU_PRIMITIVE_COMPLEX_TYPE_SEQ, CPU_PRIMITIVE_BOOL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_ACTIVATION_GRAD_ENTRY,
BINARY_ACTIVATION_BACKWARD_OP_SEQ, CPU_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_BACKWARD_OP_SEQ, CPU_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_BACKWARD_OP_SEQ_COMPLEX, CPU_PRIMITIVE_COMPLEX_TYPE_SEQ)};
// clang-format on
#undef MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY
#undef MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY

Expand Down
92 changes: 44 additions & 48 deletions oneflow/core/ep/cuda/primitive/broadcast_elementwise_binary.cu
Original file line number Diff line number Diff line change
Expand Up @@ -74,55 +74,51 @@ class BroadcastElementwiseBinaryFactoryImpl : public BroadcastElementwiseBinaryF
static const std::map<
std::tuple<BinaryOp, DataType, DataType>,
std::function<std::unique_ptr<BroadcastElementwiseBinary>(Scalar, Scalar)>>
// clang-format off
new_broadcast_elementwise_binary_handle{
OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_OP_SEQ, CUDA_PRIMITIVE_REAL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_COMPLEX_MATH_OP_SEQ,
CUDA_PRIMITIVE_COMPLEX_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY,
BINARY_COMPARISION_OP_SEQ BINARY_LOGICAL_OP_SEQ,
CUDA_PRIMITIVE_REAL_TYPE_SEQ, CUDA_PRIMITIVE_BOOL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_FLOATING_OP_SEQ, CUDA_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
// MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
// BINARY_BITWISE_OP_SEQ,
// CUDA_PRIMITIVE_INT_TYPE_SEQ CUDA_PRIMITIVE_BOOL_TYPE_SEQ)

// OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
// MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
// BINARY_BITWISE_SHIFT_OP_SEQ, CUDA_PRIMITIVE_INT_TYPE_SEQ)};
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY,
BINARY_COMPLEX_COMPARISION_OP_SEQ, CUDA_PRIMITIVE_COMPLEX_TYPE_SEQ,
CUDA_PRIMITIVE_BOOL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_ACTIVATION_GRAD_ENTRY,
BINARY_ACTIVATION_BACKWARD_OP_SEQ,
CUDA_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_ACTIVATION_GRAD_ENTRY,
BINARY_MATH_BACKWARD_OP_SEQ,
CUDA_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_BACKWARD_OP_SEQ_COMPLEX,
CUDA_PRIMITIVE_COMPLEX_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_BITWISE_OP_SEQ,
CUDA_PRIMITIVE_INT_TYPE_SEQ
CUDA_PRIMITIVE_BOOL_TYPE_SEQ)};
OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_OP_SEQ, CUDA_PRIMITIVE_REAL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_COMPLEX_MATH_OP_SEQ, CUDA_PRIMITIVE_COMPLEX_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY,
BINARY_COMPARISION_OP_SEQ BINARY_LOGICAL_OP_SEQ,
CUDA_PRIMITIVE_REAL_TYPE_SEQ, CUDA_PRIMITIVE_BOOL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_FLOATING_OP_SEQ, CUDA_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_BITWISE_SHIFT_OP_SEQ, CUDA_PRIMITIVE_INT_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY,
BINARY_COMPLEX_COMPARISION_OP_SEQ,
CUDA_PRIMITIVE_COMPLEX_TYPE_SEQ, CUDA_PRIMITIVE_BOOL_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_ACTIVATION_GRAD_ENTRY,
BINARY_ACTIVATION_BACKWARD_OP_SEQ, CUDA_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_ACTIVATION_GRAD_ENTRY,
BINARY_MATH_BACKWARD_OP_SEQ, CUDA_PRIMITIVE_FLOATING_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_MATH_BACKWARD_OP_SEQ_COMPLEX, CUDA_PRIMITIVE_COMPLEX_TYPE_SEQ)

OF_PP_SEQ_PRODUCT_FOR_EACH_TUPLE(
MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY,
BINARY_BITWISE_OP_SEQ,
CUDA_PRIMITIVE_INT_TYPE_SEQ CUDA_PRIMITIVE_BOOL_TYPE_SEQ)};
// clang-format on

#undef MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_COMPARASION_AND_LOGICAL_ENTRY
#undef MAKE_NEW_BROADCAST_ELEMENTWISE_BINARY_MATH_ENTRY
Expand Down
28 changes: 15 additions & 13 deletions oneflow/user/ops/math_binary_broadcast_seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@ namespace oneflow {
OF_PP_MAKE_TUPLE_SEQ("broadcast_isclose_eq_nan", IEN) \
OF_PP_MAKE_TUPLE_SEQ("broadcast_isclose_neq_nan", INN)

#define MATH_BINARY_BROADCAST_FUNC_SEQ_ODS \
OF_PP_MAKE_TUPLE_SEQ(BroadcastAddOp, Add) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastSubOp, Sub) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastMulOp, Mul) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastDivOp, Div) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastMinimumOp, Min) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastMaximumOp, Max) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastBitwiseAndOp, BitwiseAnd) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastBitwiseOrOp, BitwiseOr) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastBitwiseXorOp, BitwiseXor) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastFloorModOp, FloorMod) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastFmodOp, FMod) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastPowOp, Pow) \
#define MATH_BINARY_BROADCAST_FUNC_SEQ_ODS \
OF_PP_MAKE_TUPLE_SEQ(BroadcastAddOp, Add) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastSubOp, Sub) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastMulOp, Mul) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastDivOp, Div) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastMinimumOp, Min) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastMaximumOp, Max) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastBitwiseAndOp, BitwiseAnd) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastBitwiseOrOp, BitwiseOr) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastBitwiseXorOp, BitwiseXor) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastBitwiseLeftShiftOp, BitwiseLeftShift) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastBitwiseRightShiftOp, BitwiseRightShift) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastFloorModOp, FloorMod) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastFmodOp, FMod) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastPowOp, Pow) \
OF_PP_MAKE_TUPLE_SEQ(BroadcastZetaOp, Zeta)

#define MATH_BINARY_BROADCAST_LOGICAL_FUNC_SEQ_ODS \
Expand Down

0 comments on commit 70b528c

Please sign in to comment.