From de1015854c5192145dd6e7ff7d090c180f9faae3 Mon Sep 17 00:00:00 2001 From: Ke Han Date: Mon, 16 Mar 2020 11:34:04 +0800 Subject: [PATCH] * Fix windows oversize by adding files --- benchmark/python/ffi/benchmark_ffi.py | 3 + python/mxnet/ndarray/numpy/_op.py | 2 + python/mxnet/symbol/numpy/_symbol.py | 12 +- ... np_elemwise_broadcast_op_extended_sec.cc} | 4 +- .../np_elemwise_broadcast_op_extended.cc | 93 ------------ .../np_elemwise_broadcast_op_extended.cu | 45 ------ .../np_elemwise_broadcast_op_extended_sec.cc | 142 ++++++++++++++++++ .../np_elemwise_broadcast_op_extended_sec.cu | 77 ++++++++++ 8 files changed, 232 insertions(+), 146 deletions(-) rename src/api/operator/numpy/{np_elemwise_broadcast_op_extended.cc => np_elemwise_broadcast_op_extended_sec.cc} (95%) create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_extended_sec.cc create mode 100644 src/operator/numpy/np_elemwise_broadcast_op_extended_sec.cu diff --git a/benchmark/python/ffi/benchmark_ffi.py b/benchmark/python/ffi/benchmark_ffi.py index 2b9d8dfa58fe..7740f6857ba4 100644 --- a/benchmark/python/ffi/benchmark_ffi.py +++ b/benchmark/python/ffi/benchmark_ffi.py @@ -77,6 +77,9 @@ def prepare_workloads(): OpArgMngr.add_workload("ones_like", pool['2x2']) OpArgMngr.add_workload("random.uniform", low=0, high=1, size=1) OpArgMngr.add_workload("where", pool['2x3'], pool['2x3'], pool['2x1']) + OpArgMngr.add_workload("fmax", pool['2x2'], pool['2x2']) + OpArgMngr.add_workload("fmin", pool['2x2'], pool['2x2']) + OpArgMngr.add_workload("fmod", pool['2x2'], pool['2x2']) OpArgMngr.add_workload("may_share_memory", pool['2x3'][:0], pool['2x3'][:1]) diff --git a/python/mxnet/ndarray/numpy/_op.py b/python/mxnet/ndarray/numpy/_op.py index addd12a9f286..76e936c1f7c4 100644 --- a/python/mxnet/ndarray/numpy/_op.py +++ b/python/mxnet/ndarray/numpy/_op.py @@ -1198,6 +1198,7 @@ def fmod(x1, x2, out=None, **kwargs): _np.fmod(x1, x2, out=out) return _api_internal.fmod(x1, x2, out) + @set_module('mxnet.ndarray.numpy') def delete(arr, obj, axis=None): """ @@ -4415,6 +4416,7 @@ def fmax(x1, x2, out=None, **kwargs): _np.fmax(x1, x2, out=out) return _api_internal.fmax(x1, x2, out) + @set_module('mxnet.ndarray.numpy') @wrap_np_binary_func def minimum(x1, x2, out=None, **kwargs): diff --git a/python/mxnet/symbol/numpy/_symbol.py b/python/mxnet/symbol/numpy/_symbol.py index f0266e1fe823..751c1355041a 100644 --- a/python/mxnet/symbol/numpy/_symbol.py +++ b/python/mxnet/symbol/numpy/_symbol.py @@ -4148,7 +4148,12 @@ def minimum(x1, x2, out=None, **kwargs): @set_module('mxnet.symbol.numpy') -<<<<<<< HEAD +@wrap_np_binary_func +def fmin(x1, x2, out=None, **kwargs): + return _ufunc_helper(x1, x2, _npi.fmin, _np.fmin, _npi.fmin_scalar, None, out) + + +@set_module('mxnet.symbol.numpy') def all(a, axis=None, out=None, keepdims=False): """ Test whether all array elements along a given axis evaluate to True. @@ -4207,11 +4212,6 @@ def any(a, axis=None, out=None, keepdims=False): in which case a reference to out is returned. """ return _npi.any(a, axis=axis, keepdims=keepdims, out=out) -======= -@wrap_np_binary_func -def fmin(x1, x2, out=None, **kwargs): - return _ufunc_helper(x1, x2, _npi.fmin, _np.fmin, _npi.fmin_scalar, None, out) ->>>>>>> [Numpy] Add op fmax, fmin @set_module('mxnet.symbol.numpy') diff --git a/src/api/operator/numpy/np_elemwise_broadcast_op_extended.cc b/src/api/operator/numpy/np_elemwise_broadcast_op_extended_sec.cc similarity index 95% rename from src/api/operator/numpy/np_elemwise_broadcast_op_extended.cc rename to src/api/operator/numpy/np_elemwise_broadcast_op_extended_sec.cc index f68a2deeaeca..248af4dd6e3e 100644 --- a/src/api/operator/numpy/np_elemwise_broadcast_op_extended.cc +++ b/src/api/operator/numpy/np_elemwise_broadcast_op_extended_sec.cc @@ -18,8 +18,8 @@ */ /*! - * \file np_elemwise_broadcast_op_extended.cc - * \brief Implementation of the API of functions in src/operator/numpy/np_elemwise_broadcast_op_extended.cc + * \file np_elemwise_broadcast_op_extended_sec.cc + * \brief Implementation of the API of functions in src/operator/numpy/np_elemwise_broadcast_op_extended_sec.cc */ #include #include diff --git a/src/operator/numpy/np_elemwise_broadcast_op_extended.cc b/src/operator/numpy/np_elemwise_broadcast_op_extended.cc index 3d79e3a4105a..70233a596dc7 100644 --- a/src/operator/numpy/np_elemwise_broadcast_op_extended.cc +++ b/src/operator/numpy/np_elemwise_broadcast_op_extended.cc @@ -371,98 +371,5 @@ MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_rldexp_scalar) .set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = std::stod(attrs->dict["scalar"]); }) .set_attr("FCompute", BinaryScalarOp::Backward); -MXNET_OPERATOR_REGISTER_BINARY_BROADCAST(_npi_fmax) -.set_attr("FCompute", BinaryBroadcastCompute) -.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmax"}); - -NNVM_REGISTER_OP(_backward_npi_fmax) -.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", BinaryBroadcastBackwardUseIn); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_fmax_scalar) -.set_attr("FCompute", BinaryScalarOp::Compute) -.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmax_scalar"}); - -MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_fmax_scalar) -.add_argument("scalar", "float", "scalar value") -.set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = std::stod(attrs->dict["scalar"]); }) -.set_attr("FCompute", BinaryScalarOp::Backward); - -MXNET_OPERATOR_REGISTER_BINARY_BROADCAST(_npi_fmin) -.set_attr("FCompute", BinaryBroadcastCompute) -.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmin"}); - -NNVM_REGISTER_OP(_backward_npi_fmin) -.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", BinaryBroadcastBackwardUseIn); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_fmin_scalar) -.set_attr("FCompute", BinaryScalarOp::Compute) -.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmin_scalar"}); - -MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_fmin_scalar) -.add_argument("scalar", "float", "scalar value") -.set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = std::stod(attrs->dict["scalar"]); }) -.set_attr("FCompute", BinaryScalarOp::Backward); - -MXNET_OPERATOR_REGISTER_BINARY_BROADCAST(_npi_fmod) -.set_attr("FCompute", BinaryBroadcastCompute) -.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmod"}); - -NNVM_REGISTER_OP(_backward_npi_fmod) -.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", BinaryBroadcastBackwardUseIn); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_fmod_scalar) -.set_attr("FCompute", BinaryScalarOp::Compute) -.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmod_scalar"}); - -MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_fmod_scalar) -.add_argument("scalar", "float", "scalar value") -.set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = std::stod(attrs->dict["scalar"]); }) -.set_attr("FCompute", BinaryScalarOp::Backward); - -MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_rfmod_scalar) -.set_attr("FCompute", BinaryScalarOp::Compute) -.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_rfmod_scalar"}); - -MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_rfmod_scalar) -.add_argument("scalar", "float", "scalar value") -.set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = std::stod(attrs->dict["scalar"]); }) -.set_attr("FCompute", BinaryScalarOp::Backward); - } // namespace op } // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_extended.cu b/src/operator/numpy/np_elemwise_broadcast_op_extended.cu index 8e3ec3db8784..8f135b3efd03 100644 --- a/src/operator/numpy/np_elemwise_broadcast_op_extended.cu +++ b/src/operator/numpy/np_elemwise_broadcast_op_extended.cu @@ -116,50 +116,5 @@ NNVM_REGISTER_OP(_backward_npi_ldexp_scalar) NNVM_REGISTER_OP(_backward_npi_rldexp_scalar) .set_attr("FCompute", BinaryScalarOp::Backward); -NNVM_REGISTER_OP(_npi_fmax) -.set_attr("FCompute", BinaryBroadcastCompute); - -NNVM_REGISTER_OP(_backward_npi_fmax) -.set_attr("FCompute", BinaryBroadcastBackwardUseIn); - -NNVM_REGISTER_OP(_npi_fmax_scalar) -.set_attr("FCompute", BinaryScalarOp::Compute); - -NNVM_REGISTER_OP(_backward_npi_fmax_scalar) -.set_attr("FCompute", BinaryScalarOp::Backward); - -NNVM_REGISTER_OP(_npi_fmin) -.set_attr("FCompute", BinaryBroadcastCompute); - -NNVM_REGISTER_OP(_backward_npi_fmin) -.set_attr("FCompute", BinaryBroadcastBackwardUseIn); - -NNVM_REGISTER_OP(_npi_fmin_scalar) -.set_attr("FCompute", BinaryScalarOp::Compute); - -NNVM_REGISTER_OP(_backward_npi_fmin_scalar) -.set_attr("FCompute", BinaryScalarOp::Backward); - -NNVM_REGISTER_OP(_npi_fmod) -.set_attr("FCompute", BinaryBroadcastCompute); - -NNVM_REGISTER_OP(_backward_npi_fmod) -.set_attr("FCompute", BinaryBroadcastBackwardUseIn); - -NNVM_REGISTER_OP(_npi_fmod_scalar) -.set_attr("FCompute", BinaryScalarOp::Compute); - -NNVM_REGISTER_OP(_backward_npi_fmod_scalar) -.set_attr("FCompute", BinaryScalarOp::Backward); - -NNVM_REGISTER_OP(_npi_rfmod_scalar) -.set_attr("FCompute", BinaryScalarOp::Compute); - -NNVM_REGISTER_OP(_backward_npi_rfmod_scalar) -.set_attr("FCompute", BinaryScalarOp::Backward); - } // namespace op } // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_extended_sec.cc b/src/operator/numpy/np_elemwise_broadcast_op_extended_sec.cc new file mode 100644 index 000000000000..7455da139a14 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_extended_sec.cc @@ -0,0 +1,142 @@ +/* + * 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_extended_sec.cc + * \brief CPU Implementation of extended functions for elementwise numpy binary broadcast operator. (Second extended file) + */ + +#include "../../common/utils.h" +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +#define MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(name) \ + NNVM_REGISTER_OP(name) \ + .set_num_inputs(1) \ + .set_num_outputs(1) \ + .set_attr_parser([](NodeAttrs* attrs) { \ + attrs->parsed = std::stod(attrs->dict["scalar"]); \ + }) \ + .set_attr("FInferShape", ElemwiseShape<1, 1>) \ + .set_attr("FInferType", NumpyBinaryScalarType) \ + .set_attr("FInplaceOption", \ + [](const NodeAttrs& attrs){ \ + return std::vector >{{0, 0}}; \ + }) \ + .add_argument("data", "NDArray-or-Symbol", "source input") \ + .add_argument("scalar", "float", "scalar input") + +MXNET_OPERATOR_REGISTER_BINARY_BROADCAST(_npi_fmax) +.set_attr("FCompute", BinaryBroadcastCompute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmax"}); + +NNVM_REGISTER_OP(_backward_npi_fmax) +.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", BinaryBroadcastBackwardUseIn); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_fmax_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmax_scalar"}); + +MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_fmax_scalar) +.add_argument("scalar", "float", "scalar value") +.set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = std::stod(attrs->dict["scalar"]); }) +.set_attr("FCompute", BinaryScalarOp::Backward); + +MXNET_OPERATOR_REGISTER_BINARY_BROADCAST(_npi_fmin) +.set_attr("FCompute", BinaryBroadcastCompute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmin"}); + +NNVM_REGISTER_OP(_backward_npi_fmin) +.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", BinaryBroadcastBackwardUseIn); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_fmin_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmin_scalar"}); + +MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_fmin_scalar) +.add_argument("scalar", "float", "scalar value") +.set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = std::stod(attrs->dict["scalar"]); }) +.set_attr("FCompute", BinaryScalarOp::Backward); + +MXNET_OPERATOR_REGISTER_BINARY_BROADCAST(_npi_fmod) +.set_attr("FCompute", BinaryBroadcastCompute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmod"}); + +NNVM_REGISTER_OP(_backward_npi_fmod) +.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", BinaryBroadcastBackwardUseIn); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_fmod_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_fmod_scalar"}); + +MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_fmod_scalar) +.add_argument("scalar", "float", "scalar value") +.set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = std::stod(attrs->dict["scalar"]); }) +.set_attr("FCompute", BinaryScalarOp::Backward); + +MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_rfmod_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute) +.set_attr("FGradient", ElemwiseGradUseIn{"_backward_npi_rfmod_scalar"}); + +MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_rfmod_scalar) +.add_argument("scalar", "float", "scalar value") +.set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = std::stod(attrs->dict["scalar"]); }) +.set_attr("FCompute", BinaryScalarOp::Backward); + +} // namespace op +} // namespace mxnet diff --git a/src/operator/numpy/np_elemwise_broadcast_op_extended_sec.cu b/src/operator/numpy/np_elemwise_broadcast_op_extended_sec.cu new file mode 100644 index 000000000000..fa2f3bf080c7 --- /dev/null +++ b/src/operator/numpy/np_elemwise_broadcast_op_extended_sec.cu @@ -0,0 +1,77 @@ +/* + * 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_extended_sec.cu + * \brief GPU Implementation of extended functions for elementwise binary broadcast operator. (Second extended file) + */ + +#include "./np_elemwise_broadcast_op.h" + +namespace mxnet { +namespace op { + +NNVM_REGISTER_OP(_npi_fmax) +.set_attr("FCompute", BinaryBroadcastCompute); + +NNVM_REGISTER_OP(_backward_npi_fmax) +.set_attr("FCompute", BinaryBroadcastBackwardUseIn); + +NNVM_REGISTER_OP(_npi_fmax_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute); + +NNVM_REGISTER_OP(_backward_npi_fmax_scalar) +.set_attr("FCompute", BinaryScalarOp::Backward); + +NNVM_REGISTER_OP(_npi_fmin) +.set_attr("FCompute", BinaryBroadcastCompute); + +NNVM_REGISTER_OP(_backward_npi_fmin) +.set_attr("FCompute", BinaryBroadcastBackwardUseIn); + +NNVM_REGISTER_OP(_npi_fmin_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute); + +NNVM_REGISTER_OP(_backward_npi_fmin_scalar) +.set_attr("FCompute", BinaryScalarOp::Backward); + +NNVM_REGISTER_OP(_npi_fmod) +.set_attr("FCompute", BinaryBroadcastCompute); + +NNVM_REGISTER_OP(_backward_npi_fmod) +.set_attr("FCompute", BinaryBroadcastBackwardUseIn); + +NNVM_REGISTER_OP(_npi_fmod_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute); + +NNVM_REGISTER_OP(_backward_npi_fmod_scalar) +.set_attr("FCompute", BinaryScalarOp::Backward); + +NNVM_REGISTER_OP(_npi_rfmod_scalar) +.set_attr("FCompute", BinaryScalarOp::Compute); + +NNVM_REGISTER_OP(_backward_npi_rfmod_scalar) +.set_attr("FCompute", BinaryScalarOp::Backward); + +} // namespace op +} // namespace mxnet