apeforest commented on a change in pull request #13297: [MKLDNN]Add quantized concat URL: https://github.com/apache/incubator-mxnet/pull/13297#discussion_r236365225
########## File path: src/operator/quantization/mkldnn/mkldnn_quantized_concat.cc ########## @@ -0,0 +1,119 @@ +/* + * 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 quantized_concat.cc + * \brief + */ + +#if MXNET_USE_MKLDNN == 1 +#include "../../nn/mkldnn/mkldnn_concat-inl.h" +#include "../quantization_utils.h" + +namespace mxnet { +namespace op { + +namespace quantized_concat_enum { +enum QuantizedConcatOutputs { kOut, kMin, kMax }; +} + +static float GetScale(const NDArray& data, float min, float max) { + auto data_range = (data.dtype() == mshadow::kInt8) ? kInt8Range : kUint8Range; + return data_range / MaxAbs(min, max); +} + +static void MKLDNNQuantizedConcatForward(const nnvm::NodeAttrs& attrs, const OpContext& ctx, + const std::vector<NDArray>& in_data, + const std::vector<OpReqType>& req, + const std::vector<NDArray>& out_data) { + const ConcatParam& param_ = nnvm::get<ConcatParam>(attrs.parsed); + CHECK_EQ(in_data.size(), static_cast<size_t>(param_.num_args * 3)); + CHECK_EQ(out_data.size(), 3U); + // Collect data and output min/max + std::vector<float> data_min(param_.num_args); + std::vector<float> data_max(param_.num_args); + float output_min = 0.f; Review comment: Thanks for your explanation. It may not be a bug in this case but having a piece of confusing code is bug-prone. e.g. someone else copy paste these piece of logic in a similar operator but having a different assumption as yours. A code with good readability should be self-explanatory. Otherwise, a detailed comment should be added. In this case, I would suggest that you either initiate output_min to FLT_MAX so you get the minimal values from data_min correctly and then compare it with 0.0 to get the non-positive one. Or, rename the variable and add comment about your logic. Personally, I prefer the former as it is more easily understood. Regarding performance loss, coding design should follow the 80/20 rule where 80% performance is determined by 20% of the critical code. I think in this case we should not sacrifice readability for one of the 80% non-critical code. ---------------------------------------------------------------- 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
