Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Object] Add String container #4628

Merged
merged 3 commits into from
Mar 11, 2020
Merged

[Object] Add String container #4628

merged 3 commits into from
Mar 11, 2020

Conversation

wweic
Copy link
Contributor

@wweic wweic commented Jan 6, 2020

include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Show resolved Hide resolved
@tqchen tqchen self-assigned this Jan 6, 2020
@tqchen tqchen added status: need update need update based on feedbacks status: need review labels Jan 6, 2020
@wweic
Copy link
Contributor Author

wweic commented Jan 12, 2020

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

include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Show resolved Hide resolved
include/tvm/runtime/container.h Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
@tqchen
Copy link
Member

tqchen commented Jan 12, 2020

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).

@tqchen
Copy link
Member

tqchen commented Jan 31, 2020

gentle ping

@wweic
Copy link
Contributor Author

wweic commented Feb 1, 2020

@tqchen I'll send new revision soon.

@wweic wweic force-pushed the string-obj branch 3 times, most recently from 880f432 to 28beaad Compare February 2, 2020 12:30
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
tests/cpp/container_test.cc Show resolved Hide resolved
tests/cpp/container_test.cc Show resolved Hide resolved
include/tvm/runtime/container.h Show resolved Hide resolved
@tqchen
Copy link
Member

tqchen commented Feb 8, 2020

@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

#define TVM_USE_CXX14_STRING_VIEW                                       \
  defined(__cpp_lib_experimental_string_view) && __cpp_lib_experimental_string_view >= 201411

#define TVM_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>
#endif

int main(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);
#else
  LOG(INFO) << "C++11=" << std::hash<std::string>()(xyz);
#endif
  return 0;
}

@wweic
Copy link
Contributor Author

wweic commented Feb 9, 2020

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

include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
@FrozenGene
Copy link
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
Copy link
Member

tqchen commented Feb 9, 2020

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

include/tvm/runtime/container.h Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
tests/cpp/container_test.cc Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
@tqchen
Copy link
Member

tqchen commented Mar 2, 2020

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

include/tvm/runtime/container.h Outdated Show resolved Hide resolved
python/tvm/relay/prelude.py Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
@yzhliu
Copy link
Member

yzhliu commented Mar 3, 2020

good to me.

Copy link
Member

@zhiics zhiics left a comment

Choose a reason for hiding this comment

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

LGTM, please rebase.

Copy link
Member

@FrozenGene FrozenGene left a comment

Choose a reason for hiding this comment

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

LGTM

@wweic
Copy link
Contributor Author

wweic commented Mar 4, 2020

CI has passed after retry 2 times.

Copy link
Member

@tqchen tqchen left a comment

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

tests/cpp/container_test.cc Outdated Show resolved Hide resolved
tests/cpp/container_test.cc Show resolved Hide resolved
include/tvm/runtime/container.h Outdated Show resolved Hide resolved
include/tvm/runtime/container.h Show resolved Hide resolved
@tqchen
Copy link
Member

tqchen commented Mar 10, 2020

ping @wweic :)

@wweic
Copy link
Contributor Author

wweic commented Mar 11, 2020

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

@tqchen tqchen merged commit d2a79a5 into apache:master Mar 11, 2020
@tqchen
Copy link
Member

tqchen commented Mar 11, 2020

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.

@tqchen tqchen added status: accepted and removed status: need review status: need update need update based on feedbacks labels Mar 11, 2020
@wweic
Copy link
Contributor Author

wweic commented Mar 11, 2020

@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 free to 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