You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/02/21 02:44:09 UTC

[GitHub] [tvm] cyx-6 commented on a change in pull request #10326: [runtime] Improved log information with function signature

cyx-6 commented on a change in pull request #10326:
URL: https://github.com/apache/tvm/pull/10326#discussion_r810741862



##########
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:
       Yes. Here is an example for `TVMArgValue`:
   https://github.com/apache/tvm/blob/73cf51b8246f1f0b5c0bff6fa206d154e053199b/src/ir/op.cc#L97-L101
   And here is an example for `TVMRetValue`:
   https://github.com/apache/tvm/blob/73cf51b8246f1f0b5c0bff6fa206d154e053199b/src/runtime/file_utils.cc#L219-L225




-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org