NicolaLancellotti commented on code in PR #12384:
URL: https://github.com/apache/tvm/pull/12384#discussion_r945836877


##########
src/relay/backend/contrib/ethosn/codegen.cc:
##########
@@ -918,6 +943,19 @@ TVM_REGISTER_GLOBAL("relay.ethos-n.support.relu")
       err += EthosnError(reason);
     });
 
+TVM_REGISTER_GLOBAL("relay.ethos-n.support.requantize")
+    .set_body([](tvm::TVMArgs args, tvm::TVMRetValue* rv) {
+      Call call = args[0];
+      RequantizeParams params;
+      auto err = EthosnAPI::Requantize(call, &params);
+      err += EthosnCompiler::SupportedSetup();
+      char reason[kReasonMaxLength];
+      reason[0] = '\0';
+      *rv = !err && EthosnCompiler::GetSupported()->IsRequantizeSupported(
+                        params.requantize_info, params.input_info, nullptr, 
reason, sizeof(reason));

Review Comment:
   Done.



##########
src/relay/backend/contrib/ethosn/ethosn_api.cc:
##########
@@ -676,6 +677,35 @@ EthosnError EthosnAPI::Relu(const Expr& expr, ReluParams* 
params) {
   return err;
 }
 
+EthosnError EthosnAPI::Requantize(const Expr& expr, RequantizeParams* params) {
+  Call call = Downcast<Call>(expr);
+  const auto* input_dtype = call->args[0]->checked_type().as<TensorTypeNode>();
+  sl::TensorShape input_tensor_shape = {1, 1, 1, 1};
+  sl::DataType input_data_type;
+  EthosnError err = Tvm2Npu(input_dtype->shape, &input_tensor_shape);
+  err += Tvm2Npu(input_dtype->dtype, &input_data_type);
+
+  float input_sc, output_sc;
+  int input_zp, output_zp;
+  err += AsConstant(call->args[1], &input_sc);
+  err += AsConstant(call->args[2], &input_zp);
+  err += AsConstant(call->args[3], &output_sc);
+  err += AsConstant(call->args[4], &output_zp);
+
+  params->requantize_info = sl::RequantizeInfo(sl::QuantizationInfo(output_zp, 
output_sc));

Review Comment:
   Done.



-- 
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: commits-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to