Skip to content

[MISC] Add miss Type2Str and remove compile warnings#10430

Merged
junrushao merged 2 commits into
apache:mainfrom
comaniac:fix_type2str
Mar 2, 2022
Merged

[MISC] Add miss Type2Str and remove compile warnings#10430
junrushao merged 2 commits into
apache:mainfrom
comaniac:fix_type2str

Conversation

@comaniac

@comaniac comaniac commented Mar 1, 2022

Copy link
Copy Markdown
Contributor

After #10326, we now require the argument type of PackFunc to have a corresponding template of Type2Str. Otherwise we will get the following error during compilation (note that my argument type is DLDataType).

include/tvm/runtime/packed_func.h:1400:22: note: candidate: template<class> static std::__cxx11::string tvm::runtime::detail::type2str::Type2Str<T>::v() [with <template-parameter-2-1> = <template-parameter-1-1>; T = DLDataType]
   static std::string v() {
                      ^
/include/tvm/runtime/packed_func.h:1400:22: note:   template argument deduction/substitution failed

This PR adds a Type2Str template for DLDataType to remove my blocker. However, this doesn't solve the root problem. Ideally, we should not error out only if the Type2Str template is missing but the argument type of a PackFunc is actually supported. A straightforward solution to this issue is adding all templates for the types supported by TVMArgValue (e.g., intX_t, uintX_t for X in 8, 16, 32, 64; basically everything covered in https://github.com/apache/tvm/blob/main/include/tvm/runtime/packed_func.h#L1225). While it is tedious, I'm wondering if we could have a default template that simply prints "unknown_type" for non-ObjectRef types. It might be possible to leverage std::enable_if_t<!std::is_base_of<ObjectRef, T>::value>, but I'm not sure how to achieve it in the case of Type2Str struct.

(nit) In addition, this PR also removes some compiler warnings reported by Clang:

  1. size_t is always larger or equal than zero, so no need to check idx >= 0.
  2. The derived mutator and visitor don't implement all virtual functions.

cc @cyx-6 @junrushao1994

@junrushao junrushao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@junrushao junrushao merged commit 1df1580 into apache:main Mar 2, 2022
pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
* [MISC] Add miss Type2Str and remove compile warnings

* fix lint
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.

2 participants