Skip to content

[Object] Add String container - #4628

Merged
tqchen merged 3 commits into
apache:masterfrom
wweic:string-obj
Mar 11, 2020
Merged

[Object] Add String container#4628
tqchen merged 3 commits into
apache:masterfrom
wweic:string-obj

Conversation

@wweic

@wweicwweic commented Jan 6, 2020

Copy link
Copy Markdown

Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h
@tqchentqchen self-assigned this Jan 6, 2020
@tqchentqchen added status: need update need update based on feedbacks status: need review labels Jan 6, 2020
@wweic

Copy link
Copy Markdown
Author

@tqchen@FrozenGene Thanks for the comments. Please take a look again.

Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h
Comment threadinclude/tvm/runtime/container.h
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
@tqchen

Copy link
Copy Markdown
Member

we can do it in a followup PR but as a reminder, we need python side wrapper for String and perhaps we need to make some special treatment to make sure python could treat it as customized string types (e.g. by subclass string or related).

Comment threadinclude/tvm/runtime/container.h
@tqchen

Copy link
Copy Markdown
Member

gentle ping

@wweic

wweic commented Feb 1, 2020

Copy link
Copy Markdown
Author

@tqchen I'll send new revision soon.

@wweic
wweicforce-pushed the string-obj branch 3 times, most recently from 880f432 to 28beaadCompareFebruary 2, 2020 12:30
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadtests/cpp/container_test.cc
Comment threadtests/cpp/container_test.cc
Comment threadinclude/tvm/runtime/container.h
@tqchen

tqchen commented Feb 8, 2020

Copy link
Copy Markdown
Member

@wweic here is a code snippet that we can reuse for hash. We should consider migrate to require c++14, which will give us string view support

#defineTVM_USE_CXX14_STRING_VIEW \
defined(__cpp_lib_experimental_string_view) && __cpp_lib_experimental_string_view >= 201411
#defineTVM_USE_CXX17_STRING_VIEW \
defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606
#include<string>
#include<dmlc/logging.h>
#if TVM_USE_CXX17_STRING_VIEW
#include<string_view>
#elif TVM_USE_CXX14_STRING_VIEW
#include<experimental/string_view>
#endifintmain(int argc, char* argv[]) {
std::string xyz = "xyz";
#if TVM_USE_CXX17_STRING_VIEW
LOG(INFO) << "C++17=" << std::hash<std::string_view>()(xyz);
#elif TVM_USE_CXX14_STRING_VIEW
LOG(INFO) << "C++14=" << std::hash<std::experimental::string_view>()(xyz);
#elseLOG(INFO) << "C++11=" << std::hash<std::string>()(xyz);
#endifreturn0;
}

@wweic

wweic commented Feb 9, 2020

Copy link
Copy Markdown
Author

Thanks @tqchen! I have incorporated the snippet, please let me if I should put the macro in other places.

Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
@FrozenGene

Copy link
Copy Markdown
Member

IMO, it is bad idea to introduce std::experimental to this core part. As C++ standard says: The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std unless otherwise specified. That is to say std::experimental’s behavior is not guaranteed. Different version of compilers / compared with C++17 std, std::experimental maybe have different result too. I strongly suggest we remove std::experimental from this pr. Or we could consider implementing our string::view if we think it is very important.

@tqchen

tqchen commented Feb 9, 2020

Copy link
Copy Markdown
Member

@FrozenGene In general I agree that we should avoid std::experimental.

In this particular case, i think the usage is fair, because it is guarded by marco tests and is only under a very limited case we a std::hash function that can hash a string without copying it(instead of using the string_view data structure).

  • T0: We could have implemented a hash function by ourselves, but the hash itself may be inconsistent with the std version.
  • T1: While the std::experimental::string_view's hash could have been inconsistent with the std::string version as per compiler version(because of experimental), in practice it is consistent with std::string as per string_view proposal(and can be confirmed using different compilers). More importantly, it is also fine if the hash is inconsistent with the std ver(then we will be the case of T1.

Given the above consideration, I think it is fine to permit the limited usecase. However, I agree that we should have a more careful documentation about the std::experimental use case here and only limit it to the specific usecase.

Comment threadinclude/tvm/runtime/container.h
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadtests/cpp/container_test.cc
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h Outdated
@tqchen

Copy link
Copy Markdown
Member

@FrozenGene @icemelon9 please help to take another look. The standard lib is the core part of the system so we need extra caution in terms of reviewing. Thanks @wweic for pushing it through.

@zhiics@Hzfengsy@jroesch@ZihengJiang@yzhliu please also help to take a look if you have time.

Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadpython/tvm/relay/prelude.py Outdated
Comment threadinclude/tvm/runtime/container.h
Comment threadinclude/tvm/runtime/container.h Outdated
@yzhliu

Copy link
Copy Markdown
Member

good to me.

@zhiicszhiics 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, please rebase.

Comment threadinclude/tvm/runtime/container.h Outdated

@FrozenGeneFrozenGene 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

@wweic

wweic commented Mar 4, 2020

Copy link
Copy Markdown
Author

CI has passed after retry 2 times.

@tqchentqchen 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.

Spot another potential problem, added comments about more test coverage

Comment threadtests/cpp/container_test.cc Outdated
Comment threadtests/cpp/container_test.cc
Comment threadinclude/tvm/runtime/container.h Outdated
Comment threadinclude/tvm/runtime/container.h
@tqchen

Copy link
Copy Markdown
Member

ping @wweic :)

@wweic

Copy link
Copy Markdown
Author

@tqchen sorry for the delay. Was adjusting working from china schedules. I have addressed your comments.

@tqchen
tqchen merged commit d2a79a5 into apache:masterMar 11, 2020
@tqchen

Copy link
Copy Markdown
Member

Thanks @wweic for all the patience to polish this core data structure.
Thanks @FrozenGene@zhiics @icemelon9 for reviews.

This PR is now merged. Perhaps we can move on to add python side wrappers to the String container. And followup with the final container -- Array.

@tqchentqchen added status: accepted and removed status: need review status: need update need update based on feedbacks labels Mar 11, 2020
@wweic

Copy link
Copy Markdown
Author

@tqchen Yes. I'll explore Python interface for String.

@wweic
wweic deleted the string-obj branch March 11, 2020 23:45
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Apr 16, 2020
zhiics pushed a commit to neo-ai/tvm that referenced this pull request Apr 17, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@wweic@tqchen@FrozenGene@yzhliu@icemelon@zhiics