anirudh2290 commented on a change in pull request #13401: [MXNET-1227] Adding CornerPooling operator URL: https://github.com/apache/incubator-mxnet/pull/13401#discussion_r243474038
########## File path: src/operator/contrib/corner_pooling-inl.h ########## @@ -0,0 +1,315 @@ +/* + * 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) 2018 by Contributors + * \file corner_pooling-inl.h + * \brief corner pooling operator + * \author Jiajie Tang +*/ + +#ifndef MXNET_OPERATOR_CONTRIB_CORNER_POOLING_INL_H_ +#define MXNET_OPERATOR_CONTRIB_CORNER_POOLING_INL_H_ + +#include <vector> + +#include "dmlc/parameter.h" +#include "../operator_common.h" +#include "../mxnet_op.h" + +namespace mxnet { +namespace op { + +namespace corner_pool_enum { +enum PoolingOpInputs {kData}; +enum PoolingOpOutputs {kOut}; +enum PoolingOpType {kTopPooling, kBottomPooling, kLeftPooling, kRightPooling}; +enum PoolingOpPadConventionType {kValid, kFull, kSame}; +} + +struct CornerPoolingParam : public dmlc::Parameter<CornerPoolingParam> { + int corner_pooling_type; + DMLC_DECLARE_PARAMETER(CornerPoolingParam) { + DMLC_DECLARE_FIELD(corner_pooling_type) + .add_enum("left", corner_pool_enum::kLeftPooling) + .add_enum("right", corner_pool_enum::kRightPooling) + .add_enum("top", corner_pool_enum::kTopPooling) + .add_enum("bottom", corner_pool_enum::kBottomPooling) + .describe("CornerPooling type to be applied(left, right, top or bottom)."); + } +}; + +inline int GetNumOutputs(const CornerPoolingParam ¶m) { + return 1; +} + +inline int GetNumBackInputs(const CornerPoolingParam ¶m) { + return 3; +} + + +#if MXNET_USE_CUDA +template<typename DType> +inline void corner_pool(mshadow::Stream<gpu> *s, + const DType *in_data, const TShape &ishape, + const int corner_pooling_type, + OpReqType req_type, + DType *out_data); + +template<typename DType> +inline void corner_pool_grad(mshadow::Stream<gpu> *s, + const DType *out_grad, + const DType *in_data, + const DType *out_data, + const TShape &ishape, + const int corner_pooling_type, + OpReqType req_type, + DType *in_grad); +#endif // MXNET_USE_CUDA + +template<typename DType> +inline void corner_pool(mshadow::Stream<cpu> *s, + const DType *in_data, + const TShape &ishape, + const int corner_pooling_type, + OpReqType req_type, + DType *out_data) { + CHECK_EQ(req_type, kWriteTo) + << "Only support req=kWriteTo in corner pooling operations"; + using mshadow::red::limits::MinValue; +// const TShape &oshape = ishape; + int height = ishape[2], width = ishape[3]; + if (corner_pooling_type == 0 || corner_pooling_type == 1) { + // top or bottom + int h_end = 0, h_start = 0, h_step = 0; + if (corner_pooling_type == 0) { + h_step = -1; + h_start = height - 1; + h_end = -1; + } else { + h_step = +1; + h_start = 0; + h_end = height; + } + const index_t data_offset = width * height; + for (index_t b{0}; b < ishape[0]; ++b) + for (index_t c{0}; c < ishape[1]; ++c) { + for (index_t w{0}; w < width; ++w) { Review comment: can you add TODOs for optimization with ```Kernel::Launch``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
