Skip to content

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