bartekkuncer commented on a change in pull request #20817:
URL: https://github.com/apache/incubator-mxnet/pull/20817#discussion_r787700675



##########
File path: src/operator/quantization/dnnl/dnnl_quantized_transpose.cc
##########
@@ -0,0 +1,70 @@
+
+/*
+ * 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.
+ */
+
+/*!
+ * \file dnnl_quantized_transpose.cc
+ */
+#if MXNET_USE_ONEDNN == 1
+#include "../../nn/dnnl/dnnl_transpose-inl.h"
+#include "../../tensor/matrix_op-inl.h"
+
+namespace mxnet {
+namespace op {
+
+inline static bool QuantizedTransposeStorageType(const nnvm::NodeAttrs& attrs,
+                                                 const int dev_mask,
+                                                 DispatchMode* dispatch_mode,
+                                                 std::vector<int>* in_attrs,
+                                                 std::vector<int>* out_attrs) {
+  CHECK_EQ(in_attrs->size(), 3U);
+  CHECK_EQ(out_attrs->size(), 3U);
+  return DNNLStorageType(attrs, dev_mask, true, dispatch_mode, in_attrs, 
out_attrs);
+}
+
+static void DNNLQuantizedTransposeForward(const nnvm::NodeAttrs& attrs,
+                                          const OpContext& ctx,
+                                          const std::vector<NDArray>& inputs,
+                                          const std::vector<OpReqType>& req,
+                                          const std::vector<NDArray>& outputs) 
{
+  CHECK(inputs[0].dtype() == mshadow::kUint8 || inputs[0].dtype() == 
mshadow::kInt8)
+      << "dnnl_quantized_pooling op only supports uint8 and int8 as input 
type";
+  if (req[0] == kNullOp) {
+    return;
+  }
+  CHECK_EQ(inputs.size(), 3U);
+  CHECK_EQ(outputs.size(), 3U);
+  DNNLRun(DNNLTransposeForward<TransposeParam>, attrs, ctx, inputs[0], req[0], 
outputs[0]);

Review comment:
       I believe RafaƂ wrote the checks here as they are different than the 
ones in SupportDNNLTranspose function. I agree that they could be moved to a 
function.

##########
File path: src/operator/quantization/quantized_transpose.cc
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file quantized_transpose.cc
+ */
+#include <mxnet/op_attr_types.h>
+#include "../tensor/matrix_op-inl.h"
+
+namespace mxnet {
+namespace op {
+
+inline bool QuantizedTransposeType(const nnvm::NodeAttrs& attrs,
+                                   std::vector<int>* in_attrs,
+                                   std::vector<int>* out_attrs) {
+  CHECK_EQ(in_attrs->size(), 3U);
+  CHECK_EQ(out_attrs->size(), 3U);
+  TYPE_ASSIGN_CHECK(*in_attrs, 1, mshadow::kFloat32);
+  TYPE_ASSIGN_CHECK(*in_attrs, 2, mshadow::kFloat32);
+  TYPE_ASSIGN_CHECK(*out_attrs, 0, (*in_attrs)[0]);
+  TYPE_ASSIGN_CHECK(*out_attrs, 1, mshadow::kFloat32);
+  TYPE_ASSIGN_CHECK(*out_attrs, 2, mshadow::kFloat32);
+  return (*in_attrs)[0] != -1;
+}
+
+inline bool QuantizedTransposeShape(const nnvm::NodeAttrs& attrs,
+                                    mxnet::ShapeVector* in_attrs,
+                                    mxnet::ShapeVector* out_attrs) {
+  CHECK_EQ(in_attrs->size(), 3U);
+  CHECK_EQ(out_attrs->size(), 3U);
+  mxnet::ShapeVector qin_attrs(1);
+  mxnet::ShapeVector qout_attrs(1);
+  SHAPE_ASSIGN_CHECK(qin_attrs, 0, (*in_attrs)[0]);
+  SHAPE_ASSIGN_CHECK(qout_attrs, 0, (*out_attrs)[0]);
+  TransposeShape(attrs, &qin_attrs, &qout_attrs);
+  SHAPE_ASSIGN_CHECK(*in_attrs, 0, qin_attrs[0]);
+  SHAPE_ASSIGN_CHECK(*out_attrs, 0, qout_attrs[0]);
+  SHAPE_ASSIGN_CHECK(*in_attrs, 1, mxnet::TShape{1});
+  SHAPE_ASSIGN_CHECK(*in_attrs, 2, mxnet::TShape{1});
+  SHAPE_ASSIGN_CHECK(*out_attrs, 1, mxnet::TShape{1});
+  SHAPE_ASSIGN_CHECK(*out_attrs, 2, mxnet::TShape{1});
+  return shape_is_known(qout_attrs[0]);
+}
+
+NNVM_REGISTER_OP(_contrib_quantized_transpose)
+    .add_alias("_npx_quantized_transpose")
+    .set_num_inputs(3)
+    .set_num_outputs(3)
+    .set_attr_parser(ParamParser<TransposeParam>)
+    .set_attr<mxnet::FInferShape>("FInferShape", QuantizedTransposeShape)
+    .set_attr<nnvm::FInferType>("FInferType", QuantizedTransposeType)
+    // TODO(Xinyu): a temp solution to enable GluonCV INT8 flow,

Review comment:
       I believe this comment is taken from another operator and as its scope 
is bigger than just transpose op, checking whether it is still valid could be 
done in a separate task.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to