delldu commented on a change in pull request #8443:
URL: https://github.com/apache/tvm/pull/8443#discussion_r670267862
##########
File path: src/relay/op/nn/pad.cc
##########
@@ -272,5 +272,86 @@ RELAY_REGISTER_OP("nn.mirror_pad")
.add_type_rel("MirrorPad", MirrorPadRel)
.set_attr<TOpPattern>("TOpPattern", kInjective);
+Array<te::Tensor> Im2colCompute(const Attrs& attrs, const Array<te::Tensor>&
inputs,
+ const Type& out_type) {
+ const auto* param = attrs.as<Im2colAttrs>();
+ ICHECK(param != nullptr);
+
+ return Array<te::Tensor>{
+ topi::im2col(inputs[0], param->kernel_size, param->dilation,
param->padding, param->stride)};
+}
+
+bool Im2colRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
+ const TypeReporter& reporter) {
+ // types: [input, output]
+ ICHECK_EQ(types.size(), 2) << "Expects two types, one for the input and
another for the output";
+
+ const auto* input = types[0].as<TensorTypeNode>();
+ if (input == nullptr) return false;
+
+ if (input->shape.size() != 4) {
+ reporter->GetDiagCtx().EmitFatal(Diagnostic::Error(reporter->GetSpan())
+ << "Im2lossRel: input data should be 4
dimensions, NxCxHxW.");
+ return false;
+ }
+
+ const Im2colAttrs* param = attrs.as<Im2colAttrs>();
+ if (param == nullptr) return false;
+
+ // Calculate output shape
+ auto kernel_h = tvm::cast(tvm::DataType::Int(32), param->kernel_size[0]);
+ auto kernel_w = tvm::cast(tvm::DataType::Int(32), param->kernel_size[1]);
+ auto dilation_h = tvm::cast(tvm::DataType::Int(32), param->dilation[0]);
+ auto dilation_w = tvm::cast(tvm::DataType::Int(32), param->dilation[1]);
+ auto padding_h = tvm::cast(tvm::DataType::Int(32), param->padding[0]);
+ auto padding_w = tvm::cast(tvm::DataType::Int(32), param->padding[1]);
+ auto stride_h = tvm::cast(tvm::DataType::Int(32), param->stride[0]);
+ auto stride_w = tvm::cast(tvm::DataType::Int(32), param->stride[1]);
Review comment:
Just copy from PadCompute.
--
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]