Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Runtime] Enhance PackedFunc Metaprogramming with PackArgs #15595

Merged

Conversation

junrushao
Copy link
Member

This PR introduces a convenient method PackArgs that allows packing variadic C++ parameters into TVM's PackedFunc calling convention without recursion using C++ parameter pack tricks.

As an example,

template <typename... Args>
void MyVariadicMethod(Args&&... args) {
  constexpr int kNumArgs = sizeof...(Args);
  TVMValue values[kNumArgs];
  int type_codes[kNumArgs];
  tvm::runtime::PackArgs(values, type_codes, std::forward<Args>(args)...);
  ...
}

This PR introduces a convenient method `PackArgs` that allows packing
variadic C++ parameters into TVM's PackedFunc calling convention without
recursion using C++ parameter pack tricks.

As an example,

```C++
template <typename... Args>
void MyVariadicMethod(Args&&... args) {
  constexpr int kNumArgs = sizeof...(Args);
  TVMValue values[kNumArgs];
  int type_codes[kNumArgs];
  tvm::runtime::PackArgs(values, type_codes, std::forward<Args>(args)...);
  ...
}
```
@tvm-bot
Copy link
Collaborator

tvm-bot commented Aug 20, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@junrushao junrushao marked this pull request as ready for review August 20, 2023 03:37
@junrushao
Copy link
Member Author

CC: @cyx-6 @tqchen

Copy link
Contributor

@cyx-6 cyx-6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cyx-6 cyx-6 merged commit 63b0c8f into apache:main Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants