From 7159d8354304d192e5b7287a1dc7aa3e15dd0c99 Mon Sep 17 00:00:00 2001 From: barry-jin Date: Tue, 14 Sep 2021 15:10:10 -0700 Subject: [PATCH 1/5] split np_elemwise_broadcast_logic_op.cc --- .../numpy/np_elemwise_broadcast_logic_op.cu | 65 -------------- ...op.cc => np_elemwise_broadcast_logic_op.h} | 85 +++++-------------- .../np_elemwise_broadcast_logic_op_and.cc | 38 +++++++++ .../np_elemwise_broadcast_logic_op_and.cu | 35 ++++++++ .../np_elemwise_broadcast_logic_op_equal.cc | 38 +++++++++ .../np_elemwise_broadcast_logic_op_equal.cu | 35 ++++++++ .../np_elemwise_broadcast_logic_op_greater.cc | 38 +++++++++ .../np_elemwise_broadcast_logic_op_greater.cu | 35 ++++++++ ...emwise_broadcast_logic_op_greater_equal.cc | 38 +++++++++ ...emwise_broadcast_logic_op_greater_equal.cu | 35 ++++++++ .../np_elemwise_broadcast_logic_op_less.cc | 38 +++++++++ .../np_elemwise_broadcast_logic_op_less.cu | 35 ++++++++ ..._elemwise_broadcast_logic_op_less_equal.cc | 38 +++++++++ ..._elemwise_broadcast_logic_op_less_equal.cu | 35 ++++++++ ...p_elemwise_broadcast_logic_op_not_equal.cc | 38 +++++++++ ...p_elemwise_broadcast_logic_op_not_equal.cu | 35 ++++++++ .../np_elemwise_broadcast_logic_op_or.cc | 38 +++++++++ .../np_elemwise_broadcast_logic_op_or.cu | 35 ++++++++ .../np_elemwise_broadcast_logic_op_xor.cc | 38 +++++++++ .../np_elemwise_broadcast_logic_op_xor.cu | 35 ++++++++ 20 files changed, 678 insertions(+), 129 deletions(-) delete mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op.cu rename src/operator/numpy/{np_elemwise_broadcast_logic_op.cc => np_elemwise_broadcast_logic_op.h} (83%) create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_and.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_and.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_equal.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_equal.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_greater.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_greater.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_greater_equal.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_greater_equal.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_less.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_less.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_less_equal.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_less_equal.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_not_equal.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_not_equal.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_or.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_or.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_xor.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_logic_op_xor.cu diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op.cu b/src/operator/numpy/np_elemwise_broadcast_logic_op.cu deleted file mode 100644 index 540d2aaddca8..000000000000 --- a/src/operator/numpy/np_elemwise_broadcast_logic_op.cu +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * Copyright (c) 2019 by Contributors - * \file np_elemwise_broadcast_logic_op.cu - * \brief GPU Implementation of basic functions for elementwise binary - * broadcast logic operator. - */ -#include "../tensor/elemwise_binary_broadcast_op.h" -#include "../tensor/elemwise_binary_scalar_op.h" - -namespace mxnet { -namespace op { - -#if MXNET_USE_TVM_OP == 0 - -#define MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(name) \ - NNVM_REGISTER_OP(_npi_##name) \ - .set_attr("FCompute", BinaryBroadcastRTCCompute{"np_" #name}) - -#define MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(name) \ - NNVM_REGISTER_OP(_npi_##name##_scalar) \ - .set_attr("FCompute", BinaryScalarRTCCompute{"np_" #name}) - -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(not_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(greater); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(less); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(greater_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(less_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(logical_and); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(logical_or); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(logical_xor); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(not_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(greater); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(less); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(greater_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(less_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(logical_and); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(logical_or); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(logical_xor); - -#endif // MXNET_USE_TVM_OP - -} // namespace op -} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op.cc b/src/operator/numpy/np_elemwise_broadcast_logic_op.h similarity index 83% rename from src/operator/numpy/np_elemwise_broadcast_logic_op.cc rename to src/operator/numpy/np_elemwise_broadcast_logic_op.h index 001cbdc1ecf7..98cd7ce35be2 100644 --- a/src/operator/numpy/np_elemwise_broadcast_logic_op.cc +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op.h @@ -19,8 +19,8 @@ /*! * Copyright (c) 2019 by Contributors - * \file np_elemwise_binary_logic_op.cc - * \brief CPU Implementation of basic logic functions for elementwise numpy binary + * \file np_elemwise_binary_logic_op.h + * \brief Function definition of basic logic functions for elementwise numpy binary * broadcast operator. */ @@ -58,7 +58,7 @@ static constexpr char func_logical_xor_cpu[] = "logical_xor_cpu"; static constexpr char func_logical_xor_gpu[] = "logical_xor_gpu"; #pragma clang diagnostic pop -bool NumpyBinaryLogicOpType(const nnvm::NodeAttrs& attrs, +inline bool NumpyBinaryLogicOpType(const nnvm::NodeAttrs& attrs, std::vector* in_attrs, std::vector* out_attrs) { CHECK_EQ(in_attrs->size(), 2U); @@ -69,7 +69,7 @@ bool NumpyBinaryLogicOpType(const nnvm::NodeAttrs& attrs, return true; } -TBlob PrependAxes(const TBlob& src, const int dst_ndim) { +inline TBlob PrependAxes(const TBlob& src, const int dst_ndim) { CHECK_LE(src.shape_.ndim(), dst_ndim); const int src_ndim = src.shape_.ndim(); if (src_ndim == dst_ndim) @@ -228,16 +228,6 @@ struct GetBinaryBroadcastCompute { .add_argument("lhs", "NDArray-or-Symbol", "First input to the function") \ .add_argument("rhs", "NDArray-or-Symbol", "Second input to the function") -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(not_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(greater); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(less); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(greater_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(less_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(logical_and); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(logical_or); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(logical_xor); - #if MXNET_USE_TVM_OP #define MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(name) \ @@ -253,16 +243,6 @@ MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(logical_xor); .set_attr("FCompute", \ TVMBinaryBroadcastCompute{func_##name##_gpu, "np_" #name}) -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(not_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(greater); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(less); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(greater_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(less_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(logical_and); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(logical_or); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(logical_xor); - #endif // MXNET_USE_CUDA #else @@ -272,19 +252,17 @@ MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(logical_xor); .set_attr("FCompute", \ BinaryBroadcastComputeLogic) +#if MXNET_USE_CUDA + +#define MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(name) \ + NNVM_REGISTER_OP(_npi_##name) \ + .set_attr("FCompute", BinaryBroadcastRTCCompute{"np_" #name}) + +#endif // MXNET_USE_CUDA + #endif // MXNET_USE_TVM_OP -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(not_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(greater); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(less); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(greater_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(less_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(logical_and); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(logical_or); -MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(logical_xor); - -bool NumpyBinaryScalarLogicOpType(const nnvm::NodeAttrs& attrs, +inline bool NumpyBinaryScalarLogicOpType(const nnvm::NodeAttrs& attrs, std::vector* in_attrs, std::vector* out_attrs) { CHECK_EQ(in_attrs->size(), 1U); @@ -358,15 +336,6 @@ struct TVMBinaryBroadcastScalarCompute { .add_argument("data", "NDArray-or-Symbol", "First input to the function") \ .add_arguments(NumpyBinaryScalarParam::__FIELDS__()) -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(not_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(greater); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(less); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(greater_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(less_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(logical_and); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(logical_or); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(logical_xor); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-const-variable" @@ -404,16 +373,6 @@ static constexpr char func_logical_xor_scalar_gpu[] = "logical_xor_scalar_gpu" .set_attr("FCompute", \ TVMBinaryBroadcastScalarCompute{func_##name##_scalar_gpu}) -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(not_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(greater); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(less); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(greater_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(less_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(logical_and); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(logical_or); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(logical_xor); - #endif // MXNET_USE_CUDA #else @@ -426,17 +385,15 @@ MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(logical_xor); return std::vector{ResourceRequest::kTempSpace}; \ }) -#endif // MXNET_USE_TVM_OP +#if MXNET_USE_CUDA + +#define MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(name) \ + NNVM_REGISTER_OP(_npi_##name##_scalar) \ + .set_attr("FCompute", BinaryScalarRTCCompute{"np_" #name}) -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(not_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(greater); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(less); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(greater_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(less_equal); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(logical_and); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(logical_or); -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(logical_xor); +#endif // MXNET_USE_CUDA + +#endif // MXNET_USE_TVM_OP } // namespace op } // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_and.cc b/src/operator/numpy/np_elemwise_broadcast_logic_op_and.cc new file mode 100644 index 000000000000..e9d4bb35839a --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_and.cc @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_logic_op_and.cc + * \brief CPU Implementation of basic logic functions for logical_and operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(logical_and); +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(logical_and); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(logical_and); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(logical_and); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_and.cu b/src/operator/numpy/np_elemwise_broadcast_logic_op_and.cu new file mode 100644 index 000000000000..9eaa8851d100 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_and.cu @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_logic_op_and.cu + * \brief GPU Implementation of basic functions for logical_and operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(logical_and); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(logical_and); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_equal.cc b/src/operator/numpy/np_elemwise_broadcast_logic_op_equal.cc new file mode 100644 index 000000000000..fb60541d3e58 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_equal.cc @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_logic_op_equal.cc + * \brief CPU Implementation of basic logic functions for equal operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(equal); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(equal); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_equal.cu b/src/operator/numpy/np_elemwise_broadcast_logic_op_equal.cu new file mode 100644 index 000000000000..008e46eed431 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_equal.cu @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_logic_op_equal.cu + * \brief GPU Implementation of basic functions for equal operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(equal); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_greater.cc b/src/operator/numpy/np_elemwise_broadcast_logic_op_greater.cc new file mode 100644 index 000000000000..c5a535b79d30 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_greater.cc @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_logic_op_greater.cc + * \brief CPU Implementation of basic logic functions for greater operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(greater); +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(greater); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(greater); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(greater); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_greater.cu b/src/operator/numpy/np_elemwise_broadcast_logic_op_greater.cu new file mode 100644 index 000000000000..736d0b5b398b --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_greater.cu @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_logic_op_greater.cu + * \brief GPU Implementation of basic functions for greater operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(greater); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(greater); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_greater_equal.cc b/src/operator/numpy/np_elemwise_broadcast_logic_op_greater_equal.cc new file mode 100644 index 000000000000..5535891a725e --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_greater_equal.cc @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_logic_op_greater_equal.cc + * \brief CPU Implementation of basic logic functions for greater_equal operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(greater_equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(greater_equal); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(greater_equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(greater_equal); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_greater_equal.cu b/src/operator/numpy/np_elemwise_broadcast_logic_op_greater_equal.cu new file mode 100644 index 000000000000..9c86546075bd --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_greater_equal.cu @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_logic_op_greater_equal.cu + * \brief GPU Implementation of basic functions for greater_equal operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(greater_equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(greater_equal); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_less.cc b/src/operator/numpy/np_elemwise_broadcast_logic_op_less.cc new file mode 100644 index 000000000000..f2a6bfb7e86e --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_less.cc @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_logic_op_less.cc + * \brief CPU Implementation of basic logic functions for less operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(less); +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(less); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(less); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(less); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_less.cu b/src/operator/numpy/np_elemwise_broadcast_logic_op_less.cu new file mode 100644 index 000000000000..a7a34bf278ef --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_less.cu @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_logic_op_less.cu + * \brief GPU Implementation of basic functions for less operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(less); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(less); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_less_equal.cc b/src/operator/numpy/np_elemwise_broadcast_logic_op_less_equal.cc new file mode 100644 index 000000000000..cbd091064aa2 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_less_equal.cc @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_logic_op_less_equal.cc + * \brief CPU Implementation of basic logic functions for less_equal operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(less_equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(less_equal); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(less_equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(less_equal); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_less_equal.cu b/src/operator/numpy/np_elemwise_broadcast_logic_op_less_equal.cu new file mode 100644 index 000000000000..48502b78454c --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_less_equal.cu @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_logic_op_less_equal.cu + * \brief GPU Implementation of basic functions for less_equal operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(less_equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(less_equal); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_not_equal.cc b/src/operator/numpy/np_elemwise_broadcast_logic_op_not_equal.cc new file mode 100644 index 000000000000..939de1fb15b9 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_not_equal.cc @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_logic_op_not_equal.cc + * \brief CPU Implementation of basic logic functions for not equal operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(not_equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(not_equal); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(not_equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(not_equal); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_not_equal.cu b/src/operator/numpy/np_elemwise_broadcast_logic_op_not_equal.cu new file mode 100644 index 000000000000..e37aa89ce569 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_not_equal.cu @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_logic_op_not_equal.cu + * \brief GPU Implementation of basic functions for not equal operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(not_equal); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(not_equal); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_or.cc b/src/operator/numpy/np_elemwise_broadcast_logic_op_or.cc new file mode 100644 index 000000000000..ccf62975fa6e --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_or.cc @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_logic_op_or.cc + * \brief CPU Implementation of basic logic functions for logical_or operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(logical_or); +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(logical_or); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(logical_or); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(logical_or); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_or.cu b/src/operator/numpy/np_elemwise_broadcast_logic_op_or.cu new file mode 100644 index 000000000000..15f429a0f16b --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_or.cu @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_logic_op_or.cu + * \brief GPU Implementation of basic functions for logical_or operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(logical_or); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(logical_or); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_xor.cc b/src/operator/numpy/np_elemwise_broadcast_logic_op_xor.cc new file mode 100644 index 000000000000..a9886efb7150 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_xor.cc @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_logic_op_xor.cc + * \brief CPU Implementation of basic logic functions for logical_xor operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC(logical_xor); +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_CPU(logical_xor); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC(logical_xor); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_CPU(logical_xor); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op_xor.cu b/src/operator/numpy/np_elemwise_broadcast_logic_op_xor.cu new file mode 100644 index 000000000000..9ef32105aa14 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op_xor.cu @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_logic_op_xor.cu + * \brief GPU Implementation of basic functions for logical_xor operation. + */ + +#include "./np_elemwise_broadcast_logic_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_LOGIC_GPU(logical_xor); +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR_LOGIC_GPU(logical_xor); + +} // namespace op +} // namespace mxnet From b61c13e0cad2d95979dfd651753a1ff1348e295b Mon Sep 17 00:00:00 2001 From: barry-jin Date: Tue, 14 Sep 2021 15:33:36 -0700 Subject: [PATCH 2/5] fix lint --- src/operator/numpy/np_elemwise_broadcast_logic_op.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/operator/numpy/np_elemwise_broadcast_logic_op.h b/src/operator/numpy/np_elemwise_broadcast_logic_op.h index 98cd7ce35be2..1d7e13fe6918 100644 --- a/src/operator/numpy/np_elemwise_broadcast_logic_op.h +++ b/src/operator/numpy/np_elemwise_broadcast_logic_op.h @@ -19,17 +19,23 @@ /*! * Copyright (c) 2019 by Contributors - * \file np_elemwise_binary_logic_op.h + * \file np_elemwise_broadcast_logic_op.h * \brief Function definition of basic logic functions for elementwise numpy binary * broadcast operator. */ +#ifndef MXNET_OPERATOR_NUMPY_NP_ELEMWISE_BROADCAST_LOGIC_OP_H_ +#define MXNET_OPERATOR_NUMPY_NP_ELEMWISE_BROADCAST_LOGIC_OP_H_ + #if MXNET_USE_TVM_OP #include #include #include "../tvmop/op_module.h" #endif // MXNET_USE_TVM_OP +#include +#include +#include #include "../tensor/elemwise_binary_broadcast_op.h" #include "../tensor/elemwise_binary_scalar_op.h" @@ -397,3 +403,5 @@ static constexpr char func_logical_xor_scalar_gpu[] = "logical_xor_scalar_gpu" } // namespace op } // namespace mxnet + +#endif // MXNET_OPERATOR_NUMPY_NP_ELEMWISE_BROADCAST_LOGIC_OP_H_ From 8eed16ffe5af134336c66c797402b79faf7283ac Mon Sep 17 00:00:00 2001 From: barry-jin Date: Tue, 14 Sep 2021 17:23:09 -0700 Subject: [PATCH 3/5] split np_elemwise_broadcast_op.cc --- .../numpy/np_elemwise_broadcast_op.cc | 235 ------------------ .../numpy/np_elemwise_broadcast_op.cu | 85 ------- src/operator/numpy/np_elemwise_broadcast_op.h | 53 ++++ .../numpy/np_elemwise_broadcast_op_add.cc | 54 ++++ .../numpy/np_elemwise_broadcast_op_add.cu | 38 +++ .../numpy/np_elemwise_broadcast_op_mod.cc | 54 ++++ .../numpy/np_elemwise_broadcast_op_mod.cu | 38 +++ .../numpy/np_elemwise_broadcast_op_mul.cc | 54 ++++ .../numpy/np_elemwise_broadcast_op_mul.cu | 38 +++ .../numpy/np_elemwise_broadcast_op_pow.cc | 54 ++++ .../numpy/np_elemwise_broadcast_op_pow.cu | 38 +++ .../numpy/np_elemwise_broadcast_op_scalar.cc | 66 +++++ .../numpy/np_elemwise_broadcast_op_scalar.cu | 56 +++++ 13 files changed, 543 insertions(+), 320 deletions(-) delete mode 100644 src/operator/numpy/np_elemwise_broadcast_op.cc delete mode 100644 src/operator/numpy/np_elemwise_broadcast_op.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_add.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_add.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_mod.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_mod.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_mul.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_mul.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_pow.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_pow.cu create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_scalar.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_scalar.cu diff --git a/src/operator/numpy/np_elemwise_broadcast_op.cc b/src/operator/numpy/np_elemwise_broadcast_op.cc deleted file mode 100644 index 124b67df1665..000000000000 --- a/src/operator/numpy/np_elemwise_broadcast_op.cc +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * Copyright (c) 2019 by Contributors - * \file np_elemwise_binary_op.cc - * \brief CPU Implementation of basic functions for elementwise numpy binary broadcast operator. - */ - -#include "./np_elemwise_broadcast_op.h" - -namespace mxnet { -namespace op { - -DMLC_REGISTER_PARAMETER(NumpyBinaryScalarParam); - -#define MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(name) \ - NNVM_REGISTER_OP(name) \ - .set_num_inputs(1) \ - .set_num_outputs(1) \ - .set_attr_parser(ParamParser) \ - .set_attr("FInferShape", ElemwiseShape<1, 1>) \ - .set_attr("FInferType", NumpyBinaryScalarType) \ - .set_attr( \ - "FResourceRequest", \ - [](const NodeAttrs& attrs) { \ - return std::vector{ResourceRequest::kTempSpace}; \ - }) \ - .add_argument("data", "NDArray-or-Symbol", "source input") \ - .add_arguments(NumpyBinaryScalarParam::__FIELDS__()) - -bool NumpyBinaryMixedPrecisionType(const nnvm::NodeAttrs& attrs, - std::vector* in_attrs, - std::vector* out_attrs) { - CHECK_EQ(in_attrs->size(), 2U); - CHECK_EQ(out_attrs->size(), 1U); - const int ltype = in_attrs->at(0); - const int rtype = in_attrs->at(1); - if (ltype != -1 && rtype != -1 && (ltype != rtype)) { - // Only when both input types are known and not the same, we enter the mixed-precision mode - TYPE_ASSIGN_CHECK(*out_attrs, 0, common::np_binary_out_infer_type(ltype, rtype)); - } else { - return ElemwiseType<2, 1>(attrs, in_attrs, out_attrs); - } - return true; -} - -#define MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(name) \ - NNVM_REGISTER_OP(name) \ - .set_num_inputs(2) \ - .set_num_outputs(1) \ - .set_attr("FListInputNames", \ - [](const NodeAttrs& attrs) { \ - return std::vector{"lhs", "rhs"}; \ - }) \ - .set_attr("FInferShape", BinaryBroadcastShape) \ - .set_attr("FInferType", NumpyBinaryMixedPrecisionType) \ - .set_attr("FInplaceOption", \ - [](const NodeAttrs& attrs) { \ - return std::vector >{{0, 0}, {1, 0}}; \ - }) \ - .set_attr( \ - "FResourceRequest", \ - [](const NodeAttrs& attrs) { \ - return std::vector{ResourceRequest::kTempSpace}; \ - }) \ - .add_argument("lhs", "NDArray-or-Symbol", "First input to the function") \ - .add_argument("rhs", "NDArray-or-Symbol", "Second input to the function") - -MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_add) - .set_attr("FCompute", - NumpyBinaryBroadcastComputeWithBool) - .set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_broadcast_add"}); - -NNVM_REGISTER_OP(_backward_npi_broadcast_add) - .set_num_inputs(3) - .set_num_outputs(2) - .set_attr("TIsBackward", true) - .set_attr("FInplaceOption", - [](const NodeAttrs& attrs) { - return std::vector >{{0, 0}, {0, 1}}; - }) - .set_attr("FResourceRequest", - [](const NodeAttrs& attrs) { - return std::vector{ResourceRequest::kTempSpace}; - }) - .set_attr("FCompute", - NumpyBinaryBackwardUseIn); - -MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_subtract) - .set_attr("FCompute", - NumpyBinaryBroadcastCompute) - .set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_broadcast_sub"}); - -NNVM_REGISTER_OP(_backward_npi_broadcast_sub) - .set_num_inputs(3) - .set_num_outputs(2) - .set_attr("TIsBackward", true) - .set_attr("FInplaceOption", - [](const NodeAttrs& attrs) { - return std::vector >{{0, 0}, {0, 1}}; - }) - .set_attr("FResourceRequest", - [](const NodeAttrs& attrs) { - return std::vector{ResourceRequest::kTempSpace}; - }) - .set_attr("FCompute", - NumpyBinaryBackwardUseIn); - -MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_multiply) - .set_attr("FCompute", - NumpyBinaryBroadcastComputeWithBool) - .set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_broadcast_mul"}); - -NNVM_REGISTER_OP(_backward_npi_broadcast_mul) - .set_num_inputs(3) - .set_num_outputs(2) - .set_attr("TIsBackward", true) - .set_attr("FInplaceOption", - [](const NodeAttrs& attrs) { - return std::vector >{{0, 1}}; - }) - .set_attr("FResourceRequest", - [](const NodeAttrs& attrs) { - return std::vector{ResourceRequest::kTempSpace}; - }) - .set_attr("FCompute", - NumpyBinaryBackwardUseIn); - -MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_mod) - .set_attr("FCompute", - NumpyBinaryBroadcastCompute) - .set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_broadcast_mod"}); - -NNVM_REGISTER_OP(_backward_npi_broadcast_mod) - .set_num_inputs(3) - .set_num_outputs(2) - .set_attr("TIsBackward", true) - .set_attr("FInplaceOption", - [](const NodeAttrs& attrs) { - return std::vector >{{0, 1}}; - }) - .set_attr("FResourceRequest", - [](const NodeAttrs& attrs) { - return std::vector{ResourceRequest::kTempSpace}; - }) - .set_attr("FCompute", - NumpyBinaryBackwardUseIn); - -MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_power) - .set_attr("FCompute", - NumpyBinaryBroadcastComputeWithBool) - .set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_broadcast_power"}); - -NNVM_REGISTER_OP(_backward_npi_broadcast_power) - .set_num_inputs(3) - .set_num_outputs(2) - .set_attr("TIsBackward", true) - .set_attr("FInplaceOption", - [](const NodeAttrs& attrs) { - return std::vector >{{0, 1}}; - }) - .set_attr("FResourceRequest", - [](const NodeAttrs& attrs) { - return std::vector{ResourceRequest::kTempSpace}; - }) - .set_attr( - "FCompute", - NumpyBinaryBackwardUseIn); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_add_scalar) - .set_attr("FCompute", BinaryScalarOp::Compute) - .set_attr("FGradient", ElemwiseGradUseNone{"_copy"}); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_subtract_scalar) - .set_attr("FCompute", BinaryScalarOp::Compute) - .set_attr("FGradient", ElemwiseGradUseNone{"_copy"}); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_rsubtract_scalar) - .set_attr("FCompute", BinaryScalarOp::Compute) - .set_attr("FGradient", ElemwiseGradUseNone{"negative"}); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_multiply_scalar) - .set_attr("FCompute", BinaryScalarOp::Compute) - .set_attr("FGradient", ElemwiseGradUseNone{"_backward_mul_scalar"}); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_mod_scalar) - .set_attr("FCompute", BinaryScalarOp::Compute) - .set_attr("FGradient", ElemwiseGradUseIn{"_backward_mod_scalar"}); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_rmod_scalar) - .set_attr("FCompute", BinaryScalarOp::Compute) - .set_attr("FGradient", ElemwiseGradUseIn{"_backward_rmod_scalar"}); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_power_scalar) - .set_attr("FCompute", BinaryScalarOp::Compute) - .set_attr("FGradient", ElemwiseGradUseIn{"_backward_power_scalar"}); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_rpower_scalar) - .set_attr("FCompute", BinaryScalarOp::Compute) - .set_attr("FGradient", ElemwiseGradUseOut{"_backward_rpower_scalar"}); - -} // namespace op -} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op.cu b/src/operator/numpy/np_elemwise_broadcast_op.cu deleted file mode 100644 index 635bc4dee20c..000000000000 --- a/src/operator/numpy/np_elemwise_broadcast_op.cu +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * Copyright (c) 2019 by Contributors - * \file np_elemwise_broadcast_op.cu - * \brief GPU Implementation of basic functions for elementwise binary broadcast operator. - */ - -#include "./np_elemwise_broadcast_op.h" - -namespace mxnet { -namespace op { - -NNVM_REGISTER_OP(_npi_add).set_attr("FCompute", BinaryBroadcastRTCCompute{"add"}); - -NNVM_REGISTER_OP(_backward_npi_broadcast_add) - .set_attr("FCompute", BinaryBroadcastRTCBackwardUseIn{"one", "one"}); - -NNVM_REGISTER_OP(_npi_subtract) - .set_attr("FCompute", BinaryBroadcastRTCCompute{"sub"}); - -NNVM_REGISTER_OP(_backward_npi_broadcast_sub) - .set_attr("FCompute", BinaryBroadcastRTCBackwardUseIn{"one", "negone"}); - -NNVM_REGISTER_OP(_npi_multiply) - .set_attr("FCompute", BinaryBroadcastRTCCompute{"mul"}); - -NNVM_REGISTER_OP(_backward_npi_broadcast_mul) - .set_attr("FCompute", BinaryBroadcastRTCBackwardUseIn{"right", "left"}); - -NNVM_REGISTER_OP(_npi_mod).set_attr("FCompute", BinaryBroadcastRTCCompute{"mod"}); - -NNVM_REGISTER_OP(_backward_npi_broadcast_mod) - .set_attr("FCompute", BinaryBroadcastRTCBackwardUseIn{"mod_grad", "mod_rgrad"}); - -NNVM_REGISTER_OP(_npi_power) - .set_attr("FCompute", BinaryBroadcastRTCCompute{"power"}); - -NNVM_REGISTER_OP(_backward_npi_broadcast_power) - .set_attr("FCompute", - BinaryBroadcastRTCBackwardUseIn{"power_grad", "power_rgrad"}); - -NNVM_REGISTER_OP(_npi_add_scalar) - .set_attr("FCompute", BinaryScalarRTCCompute{"add"}); - -NNVM_REGISTER_OP(_npi_subtract_scalar) - .set_attr("FCompute", BinaryScalarRTCCompute{"sub"}); - -NNVM_REGISTER_OP(_npi_rsubtract_scalar) - .set_attr("FCompute", BinaryScalarRTCCompute{"rsub"}); - -NNVM_REGISTER_OP(_npi_multiply_scalar) - .set_attr("FCompute", BinaryScalarRTCCompute{"mul"}); - -NNVM_REGISTER_OP(_npi_mod_scalar) - .set_attr("FCompute", BinaryScalarRTCCompute{"mod"}); - -NNVM_REGISTER_OP(_npi_rmod_scalar) - .set_attr("FCompute", BinaryScalarRTCCompute{"rmod"}); - -NNVM_REGISTER_OP(_npi_power_scalar) - .set_attr("FCompute", BinaryScalarRTCCompute{"power"}); - -NNVM_REGISTER_OP(_npi_rpower_scalar) - .set_attr("FCompute", BinaryScalarRTCCompute{"rpow"}); - -} // namespace op -} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op.h b/src/operator/numpy/np_elemwise_broadcast_op.h index 1f01bc62f06a..22c9d712dd68 100644 --- a/src/operator/numpy/np_elemwise_broadcast_op.h +++ b/src/operator/numpy/np_elemwise_broadcast_op.h @@ -533,6 +533,59 @@ void NumpyBinaryBackwardUseIn(const nnvm::NodeAttrs& attrs, } } +#define MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(name) \ + NNVM_REGISTER_OP(name) \ + .set_num_inputs(1) \ + .set_num_outputs(1) \ + .set_attr_parser(ParamParser) \ + .set_attr("FInferShape", ElemwiseShape<1, 1>) \ + .set_attr("FInferType", NumpyBinaryScalarType) \ + .set_attr( \ + "FResourceRequest", \ + [](const NodeAttrs& attrs) { \ + return std::vector{ResourceRequest::kTempSpace}; \ + }) \ + .add_argument("data", "NDArray-or-Symbol", "source input") \ + .add_arguments(NumpyBinaryScalarParam::__FIELDS__()) + +inline bool NumpyBinaryMixedPrecisionType(const nnvm::NodeAttrs& attrs, + std::vector* in_attrs, + std::vector* out_attrs) { + CHECK_EQ(in_attrs->size(), 2U); + CHECK_EQ(out_attrs->size(), 1U); + const int ltype = in_attrs->at(0); + const int rtype = in_attrs->at(1); + if (ltype != -1 && rtype != -1 && (ltype != rtype)) { + // Only when both input types are known and not the same, we enter the mixed-precision mode + TYPE_ASSIGN_CHECK(*out_attrs, 0, common::np_binary_out_infer_type(ltype, rtype)); + } else { + return ElemwiseType<2, 1>(attrs, in_attrs, out_attrs); + } + return true; +} + +#define MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(name) \ + NNVM_REGISTER_OP(name) \ + .set_num_inputs(2) \ + .set_num_outputs(1) \ + .set_attr("FListInputNames", \ + [](const NodeAttrs& attrs) { \ + return std::vector{"lhs", "rhs"}; \ + }) \ + .set_attr("FInferShape", BinaryBroadcastShape) \ + .set_attr("FInferType", NumpyBinaryMixedPrecisionType) \ + .set_attr("FInplaceOption", \ + [](const NodeAttrs& attrs) { \ + return std::vector >{{0, 0}, {1, 0}}; \ + }) \ + .set_attr( \ + "FResourceRequest", \ + [](const NodeAttrs& attrs) { \ + return std::vector{ResourceRequest::kTempSpace}; \ + }) \ + .add_argument("lhs", "NDArray-or-Symbol", "First input to the function") \ + .add_argument("rhs", "NDArray-or-Symbol", "Second input to the function") + } // namespace op } // namespace mxnet #endif // MXNET_OPERATOR_NUMPY_NP_ELEMWISE_BROADCAST_OP_H_ diff --git a/src/operator/numpy/np_elemwise_broadcast_op_add.cc b/src/operator/numpy/np_elemwise_broadcast_op_add.cc new file mode 100644 index 000000000000..c39d6cd0a96e --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_add.cc @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_op_add.cc + * \brief CPU Implementation of basic functions for elementwise numpy binary add. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_add) +.set_attr( + "FCompute", + NumpyBinaryBroadcastComputeWithBool) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_broadcast_add"}); + +NNVM_REGISTER_OP(_backward_npi_broadcast_add) +.set_num_inputs(3) +.set_num_outputs(2) +.set_attr("TIsBackward", true) +.set_attr("FInplaceOption", + [](const NodeAttrs& attrs){ + return std::vector >{{0, 0}, {0, 1}}; + }) +.set_attr("FResourceRequest", + [](const NodeAttrs& attrs) { + return std::vector{ResourceRequest::kTempSpace}; + }) +.set_attr("FCompute", NumpyBinaryBackwardUseIn); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_add.cu b/src/operator/numpy/np_elemwise_broadcast_op_add.cu new file mode 100644 index 000000000000..14482303a95b --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_add.cu @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_op_add.cu + * \brief GPU Implementation of basic functions for elementwise binary broadcast add operator. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +NNVM_REGISTER_OP(_npi_add) +.set_attr("FCompute", BinaryBroadcastRTCCompute{"add"}); + +NNVM_REGISTER_OP(_backward_npi_broadcast_add) +.set_attr("FCompute", BinaryBroadcastRTCBackwardUseIn{"one", "one"}); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_mod.cc b/src/operator/numpy/np_elemwise_broadcast_op_mod.cc new file mode 100644 index 000000000000..76176b382add --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_mod.cc @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_op_mod.cc + * \brief CPU Implementation of basic functions for elementwise numpy binary mod. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_mod) +.set_attr( + "FCompute", + NumpyBinaryBroadcastCompute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_broadcast_mod"}); + +NNVM_REGISTER_OP(_backward_npi_broadcast_mod) +.set_num_inputs(3) +.set_num_outputs(2) +.set_attr("TIsBackward", true) +.set_attr("FInplaceOption", + [](const NodeAttrs& attrs){ + return std::vector >{{0, 1}}; + }) +.set_attr("FResourceRequest", + [](const NodeAttrs& attrs) { + return std::vector{ResourceRequest::kTempSpace}; + }) +.set_attr("FCompute", NumpyBinaryBackwardUseIn); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_mod.cu b/src/operator/numpy/np_elemwise_broadcast_op_mod.cu new file mode 100644 index 000000000000..6cb2ffa50620 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_mod.cu @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_op_mod.cu + * \brief GPU Implementation of basic functions for elementwise binary broadcast mod operator. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +NNVM_REGISTER_OP(_npi_mod) +.set_attr("FCompute", BinaryBroadcastRTCCompute{"mod"}); + +NNVM_REGISTER_OP(_backward_npi_broadcast_mod) +.set_attr("FCompute", BinaryBroadcastRTCBackwardUseIn{"mod_grad", "mod_rgrad"}); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_mul.cc b/src/operator/numpy/np_elemwise_broadcast_op_mul.cc new file mode 100644 index 000000000000..d8207a856fd7 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_mul.cc @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_op_mul.cc + * \brief CPU Implementation of basic functions for elementwise numpy binary multiply. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_multiply) +.set_attr( + "FCompute", + NumpyBinaryBroadcastComputeWithBool) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_broadcast_mul"}); + +NNVM_REGISTER_OP(_backward_npi_broadcast_mul) +.set_num_inputs(3) +.set_num_outputs(2) +.set_attr("TIsBackward", true) +.set_attr("FInplaceOption", + [](const NodeAttrs& attrs){ + return std::vector >{{0, 1}}; + }) +.set_attr("FResourceRequest", + [](const NodeAttrs& attrs) { + return std::vector{ResourceRequest::kTempSpace}; + }) +.set_attr("FCompute", NumpyBinaryBackwardUseIn); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_mul.cu b/src/operator/numpy/np_elemwise_broadcast_op_mul.cu new file mode 100644 index 000000000000..c8235e7506f9 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_mul.cu @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_op_mul.cu + * \brief GPU Implementation of basic functions for elementwise binary broadcast multiply operator. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +NNVM_REGISTER_OP(_npi_multiply) +.set_attr("FCompute", BinaryBroadcastRTCCompute{"mul"}); + +NNVM_REGISTER_OP(_backward_npi_broadcast_mul) +.set_attr("FCompute", BinaryBroadcastRTCBackwardUseIn{"right", "left"}); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_pow.cc b/src/operator/numpy/np_elemwise_broadcast_op_pow.cc new file mode 100644 index 000000000000..e7a4f23047e2 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_pow.cc @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_op_pow.cc + * \brief CPU Implementation of basic functions for elementwise numpy binary power. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_power) +.set_attr( + "FCompute", + NumpyBinaryBroadcastComputeWithBool) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_broadcast_power"}); + +NNVM_REGISTER_OP(_backward_npi_broadcast_power) +.set_num_inputs(3) +.set_num_outputs(2) +.set_attr("TIsBackward", true) +.set_attr("FInplaceOption", + [](const NodeAttrs& attrs){ + return std::vector >{{0, 1}}; + }) +.set_attr("FResourceRequest", + [](const NodeAttrs& attrs) { + return std::vector{ResourceRequest::kTempSpace}; + }) +.set_attr("FCompute", NumpyBinaryBackwardUseIn); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_pow.cu b/src/operator/numpy/np_elemwise_broadcast_op_pow.cu new file mode 100644 index 000000000000..234b5c8f78e7 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_pow.cu @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_op_pow.cu + * \brief GPU Implementation of basic functions for elementwise binary broadcast power operator. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +NNVM_REGISTER_OP(_npi_power) +.set_attr("FCompute", BinaryBroadcastRTCCompute{"power"}); + +NNVM_REGISTER_OP(_backward_npi_broadcast_power) +.set_attr("FCompute", BinaryBroadcastRTCBackwardUseIn{"power_grad", "power_rgrad"}); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_scalar.cc b/src/operator/numpy/np_elemwise_broadcast_op_scalar.cc new file mode 100644 index 000000000000..c3a4f118fc49 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_scalar.cc @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_op.cc + * \brief CPU Implementation of basic functions for elementwise numpy binary broadcast operator. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +DMLC_REGISTER_PARAMETER(NumpyBinaryScalarParam); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_add_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseNone{"_copy"}); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_subtract_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseNone{"_copy"}); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_rsubtract_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseNone{"negative"}); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_multiply_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseNone{"_backward_mul_scalar"}); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_mod_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_mod_scalar"}); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_rmod_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_rmod_scalar"}); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_power_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_power_scalar"}); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_rpower_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseOut{"_backward_rpower_scalar"}); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_scalar.cu b/src/operator/numpy/np_elemwise_broadcast_op_scalar.cu new file mode 100644 index 000000000000..613b0260cde3 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_scalar.cu @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_op_add.cu + * \brief GPU Implementation of basic functions for elementwise binary add. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +NNVM_REGISTER_OP(_npi_add_scalar) +.set_attr("FCompute", BinaryScalarRTCCompute{"add"}); + +NNVM_REGISTER_OP(_npi_subtract_scalar) +.set_attr("FCompute", BinaryScalarRTCCompute{"sub"}); + +NNVM_REGISTER_OP(_npi_rsubtract_scalar) +.set_attr("FCompute", BinaryScalarRTCCompute{"rsub"}); + +NNVM_REGISTER_OP(_npi_multiply_scalar) +.set_attr("FCompute", BinaryScalarRTCCompute{"mul"}); + +NNVM_REGISTER_OP(_npi_mod_scalar) +.set_attr("FCompute", BinaryScalarRTCCompute{"mod"}); + +NNVM_REGISTER_OP(_npi_rmod_scalar) +.set_attr("FCompute", BinaryScalarRTCCompute{"rmod"}); + +NNVM_REGISTER_OP(_npi_power_scalar) +.set_attr("FCompute", BinaryScalarRTCCompute{"power"}); + +NNVM_REGISTER_OP(_npi_rpower_scalar) +.set_attr("FCompute", BinaryScalarRTCCompute{"rpow"}); + +} // namespace op +} // namespace mxnet From 2ad4400cf172ad92915bf654374eae302d0e48b3 Mon Sep 17 00:00:00 2001 From: barry-jin Date: Tue, 14 Sep 2021 17:28:57 -0700 Subject: [PATCH 4/5] fix lint --- src/operator/numpy/np_elemwise_broadcast_op.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operator/numpy/np_elemwise_broadcast_op.h b/src/operator/numpy/np_elemwise_broadcast_op.h index 22c9d712dd68..0a4bf8df9d3f 100644 --- a/src/operator/numpy/np_elemwise_broadcast_op.h +++ b/src/operator/numpy/np_elemwise_broadcast_op.h @@ -26,6 +26,7 @@ #define MXNET_OPERATOR_NUMPY_NP_ELEMWISE_BROADCAST_OP_H_ #include +#include #include #include From 1a11f5f99ebbe058afeb5e42233ac4d4c256e94f Mon Sep 17 00:00:00 2001 From: barry-jin Date: Wed, 15 Sep 2021 09:22:41 -0700 Subject: [PATCH 5/5] add _npi_subtract --- .../numpy/np_elemwise_broadcast_op_sub.cc | 54 +++++++++++++++++++ .../numpy/np_elemwise_broadcast_op_sub.cu | 38 +++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_sub.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_sub.cu diff --git a/src/operator/numpy/np_elemwise_broadcast_op_sub.cc b/src/operator/numpy/np_elemwise_broadcast_op_sub.cc new file mode 100644 index 000000000000..f48cd098ceee --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_sub.cc @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_binary_op_sub.cc + * \brief CPU Implementation of basic functions for elementwise numpy binary subtract. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +MXNET_OPERATOR_REGISTER_NP_BINARY_MIXED_PRECISION(_npi_subtract) +.set_attr( + "FCompute", + NumpyBinaryBroadcastCompute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_broadcast_sub"}); + +NNVM_REGISTER_OP(_backward_npi_broadcast_sub) +.set_num_inputs(3) +.set_num_outputs(2) +.set_attr("TIsBackward", true) +.set_attr("FInplaceOption", + [](const NodeAttrs& attrs){ + return std::vector >{{0, 0}, {0, 1}}; + }) +.set_attr("FResourceRequest", + [](const NodeAttrs& attrs) { + return std::vector{ResourceRequest::kTempSpace}; + }) +.set_attr("FCompute", NumpyBinaryBackwardUseIn); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_sub.cu b/src/operator/numpy/np_elemwise_broadcast_op_sub.cu new file mode 100644 index 000000000000..59d4adf220a8 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_sub.cu @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file np_elemwise_broadcast_op_sub.cu + * \brief GPU Implementation of basic functions for elementwise binary broadcast subtract operator. + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +NNVM_REGISTER_OP(_npi_subtract) +.set_attr("FCompute", BinaryBroadcastRTCCompute{"sub"}); + +NNVM_REGISTER_OP(_backward_npi_broadcast_sub) +.set_attr("FCompute", BinaryBroadcastRTCBackwardUseIn{"one", "negone"}); + +} // namespace op +} // namespace mxnet