Mousius commented on a change in pull request #9163:
URL: https://github.com/apache/tvm/pull/9163#discussion_r719577836
##########
File path: src/relay/backend/contrib/cmsisnn/relay_to_tir.cc
##########
@@ -32,17 +32,37 @@ namespace relay {
namespace contrib {
namespace cmsisnn {
-class RelayToTIR : public MixedModeVisitor {
+class RelayToTIRVisitor : public MixedModeVisitor {
public:
- explicit RelayToTIR(String func_name) : func_name_(func_name) {}
+ explicit RelayToTIRVisitor(String func_name) : func_name_(func_name) {}
+
+ tir::PrimFunc GetReplacementPrimFunc() { return primfunc_; }
private:
- void emit_softmax_tir(const Expr& expr) {
+ template <typename T>
+ const T ArgumentToConstantValue(const Expr& arg) {
+ const ConstantNode* constant_node = arg.as<ConstantNode>();
+ return static_cast<const T*>(constant_node->data->data)[0];
+ }
+
+ void CreatePrimFuncForExtern(Array<tir::Var> func_signature,
+ tvm::Array<PrimExpr> call_extern_args) {
+ Map<String, ObjectRef> dict_attrs;
+ dict_attrs.Set("global_symbol", func_name_);
+ dict_attrs.Set("tir.noalias", Bool(true));
+
+ tir::Stmt body = tir::Evaluate(
+ tvm::tir::Call(DataType::Int(8), tir::builtin::call_extern(),
call_extern_args));
+
+ primfunc_ = tir::PrimFunc(func_signature, body, VoidType(), Map<tir::Var,
tir::Buffer>(),
+ DictAttrs(dict_attrs));
+ }
+
+ void EmitSoftMax(const Expr& expr) {
auto* quantize_call = expr.as<CallNode>();
auto* softmax_call = quantize_call->args[0].as<CallNode>();
auto* dequant_call = softmax_call->args[0].as<CallNode>();
- auto* scale_const = dequant_call->args[1].as<ConstantNode>();
- const float quant_scale = static_cast<const
float*>(scale_const->data->data)[0];
+ const float quant_scale =
ArgumentToConstantValue<float>(dequant_call->args[1]);
Review comment:
Awesome! I wish I'd known about this.
I'll do this in a follow up if it's ok with you? I'm going to be back here
anyway :smile_cat:
--
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]