`DFPatternRewriteComposer.AddRewrite` with additional args raises compile error

Hi folks,

I’m trying to use DFPatternRewriteComposer defined in src/relay/transforms/simplify_expr.h to compose rewrite patterns.
Suppose some of my rewrite patterns get arguments in constructor like this,

class SimplifyXXX : public DFPatternRewrite {
  public:
    SimplifyXXX(size_t batch_size_): batch_size(batch_size_) {
      ...
    }
  ...
  private:
    size_t batch_size;
    ...
}

and I tried to add this pattern in composer like this,

size_t batch_size = 1;
DFPatternRewriteComposer composer;
composer.AddRewrite<SimplifyXXX, size_t>(batch_size);

then it results in compile error as follows.

[build] /root/tvm/src/relay/transforms/simplify_expr.h:72:55: error: invalid conversion from 'long unsigned int*' to 'long unsigned int' [-fpermissive]
[build]    72 |     rewrites_.push_back(std::make_shared<T, Args...>(&args...));
[build]       |                                                       ^~~~
[build]       |                                                       |
[build]       |                                                       long unsigned int*

So I tried to change the code in src/relay/transforms/simplify_expr.h:72 like below and there was no error. (Note that & was moved from args to Args)

rewrites_.push_back(std::make_shared<T, Args&...>(args...));

I’m quite new to tvm and modern C++, so I’m not sure whether my change is correct. Could you give any opinions about this?

Thanks!

I think your change it correct, but I’d like to defer to @altanh , he’s the one that implemented this variadic template.

1 Like

Looks good to me, could you send a PR? Thanks!

1 Like

Thanks! I just sent a PR in https://github.com/apache/tvm/pull/10669.
If there are any guidelines that I missed, please let me know.