junrushao1994 commented on a change in pull request #10326:
URL: https://github.com/apache/tvm/pull/10326#discussion_r811334446
##########
File path: include/tvm/runtime/packed_func.h
##########
@@ -1276,37 +1344,166 @@ struct func_signature_helper {
template <typename T, typename R, typename... Args>
struct func_signature_helper<R (T::*)(Args...)> {
using FType = R(Args...);
+ using ParamType = parameter_pack::ParamPack<Args...>;
+ using RetType = R;
static_assert(!std::is_reference<R>::value, "TypedPackedFunc return
reference");
};
template <typename T, typename R, typename... Args>
struct func_signature_helper<R (T::*)(Args...) const> {
using FType = R(Args...);
+ using ParamType = parameter_pack::ParamPack<Args...>;
+ using RetType = R;
static_assert(!std::is_reference<R>::value, "TypedPackedFunc return
reference");
};
/*!
- * \brief template class to get function signature of a function or functor.
+ * \brief Template class to get function signature of a function or functor.
* \tparam T The function/functor type.
*/
template <typename T>
struct function_signature {
using FType = typename
func_signature_helper<decltype(&T::operator())>::FType;
+ using ParamType = typename
func_signature_helper<decltype(&T::operator())>::ParamType;
+ using RetType = typename
func_signature_helper<decltype(&T::operator())>::RetType;
};
// handle case of function.
template <typename R, typename... Args>
struct function_signature<R(Args...)> {
using FType = R(Args...);
+ using ParamType = parameter_pack::ParamPack<Args...>;
+ using RetType = R;
static_assert(!std::is_reference<R>::value, "TypedPackedFunc return
reference");
};
// handle case of function ptr.
template <typename R, typename... Args>
struct function_signature<R (*)(Args...)> {
using FType = R(Args...);
+ using ParamType = detail::parameter_pack::ParamPack<Args...>;
+ using RetType = R;
static_assert(!std::is_reference<R>::value, "TypedPackedFunc return
reference");
};
+
+template <typename TSignature>
+struct SignaturePrinter;
+
+namespace type2str {
+
+template <typename T>
+struct TypeSimplifier;
+
+template <typename T>
+struct Type2Str {
+ template <typename = std::enable_if_t<std::is_base_of<ObjectRef, T>::value>>
+ static std::string v() {
+ return T::ContainerType::_type_key;
+ }
+};
+template <>
+struct Type2Str<int> {
+ static std::string v() { return "int"; }
+};
+template <>
+struct Type2Str<double> {
+ static std::string v() { return "double"; }
+};
+template <>
+struct Type2Str<int64_t> {
+ static std::string v() { return "int64_t"; }
+};
+template <>
+struct Type2Str<uint64_t> {
+ static std::string v() { return "uint64_t"; }
+};
+template <>
+struct Type2Str<bool> {
+ static std::string v() { return "bool"; }
+};
+template <>
+struct Type2Str<void> {
+ static std::string v() { return "void"; }
+};
+template <>
+struct Type2Str<std::basic_string<char>> {
+ static std::string v() { return "basic_string<char>"; }
+};
+template <typename K, typename V>
+struct Type2Str<Map<K, V>> {
+ static std::string v() {
+ return "Map<" + TypeSimplifier<K>::v() + ", " + TypeSimplifier<V>::v() +
">";
+ }
+};
+template <>
+struct Type2Str<DLDevice> {
+ static std::string v() { return "DLDevice"; }
+};
+template <>
+struct Type2Str<DLTensor> {
+ static std::string v() { return "DLTensor"; }
+};
+template <>
+struct Type2Str<DataType> {
+ static std::string v() { return "DataType"; }
+};
+template <>
+struct Type2Str<TVMRetValue> {
+ static std::string v() { return "TVMRetValue"; }
+};
+template <>
+struct Type2Str<TVMArgValue> {
+ static std::string v() { return "TVMArgValue"; }
+};
Review comment:
Thanks for your explanation! That makes total sense to me
--
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]