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

support adb-shell style cpp_rpc #8223

Merged
merged 5 commits into from
Jun 21, 2021

Conversation

fantasyRqg
Copy link
Contributor

@fantasyRqg fantasyRqg commented Jun 9, 2021

Fix problem mentioned at #7390

Support tvm_rpc directly use in adb shell terminal

@vinx13 @tqchen

@fantasyRqg
Copy link
Contributor Author

Android Application test log:

2021-06-09 22:21:48.114 12387-12428/com.rqg.tvm_rpc D/TVM_RUNTIME: /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_server.cc:129: bind to 0.0.0.0:9091
2021-06-09 22:21:48.114 12387-12429/com.rqg.tvm_rpc D/TVM_RUNTIME: /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_tracker_client.h:194: Tracker connecting to 192.168.100.4:9091
2021-06-09 22:21:58.230 12387-12429/com.rqg.tvm_rpc D/TVM_RUNTIME: /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_server.cc:295: Connection success 192.168.100.4:63009
2021-06-09 22:21:58.532 12437-12437/? D/TVM_RUNTIME: /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_env.cc:126: Load module from /data/data/com.rqg.tvm_rpc/cache/rpc/cpu_lib.so ...
2021-06-09 22:21:58.802 12437-12437/? D/TVM_RUNTIME: /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_server.cc:317: Finish serving 192.168.100.4:63009
2021-06-09 22:21:58.841 12387-12429/com.rqg.tvm_rpc D/TVM_RUNTIME: /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_server.cc:200: Child pid=12436 killed, Process status = 15
2021-06-09 22:21:58.841 12387-12429/com.rqg.tvm_rpc D/TVM_RUNTIME: /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_server.cc:224: Socket Connection Closed

adb shell test log:

/tvm_rpc server --port=9090 --tracker=192.168.100.4:9091 --key=android                                                                    <
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:260: ./tvm_rpc
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:260: server
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:260: --port=9090
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:260: --tracker=192.168.100.4:9091
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:260: --key=android
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:96: host        = 0.0.0.0
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:97: port        = 9090
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:98: port_end    = 9099
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:99: tracker     = ('192.168.100.4', 9091)
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:100: key         = android
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:101: custom_addr =
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:102: work_dir    =
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:103: silent      = False
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:266: Starting CPP Server, Press Ctrl+C to stop.
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/main.cc:285: RPCServerCreate: ('192.168.100.4', 9091)
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_server.cc:129: bind to 0.0.0.0:9090
[22:23:41] /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_tracker_client.h:194: Tracker connecting to 192.168.100.4:9091
[22:23:48] /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_server.cc:295: Connection success 192.168.100.4:63333
[22:23:48] /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_env.cc:126: Load module from ./rpc/cpu_lib.so ...
[22:23:48] /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_server.cc:317: Finish serving 192.168.100.4:63333
[22:23:48] /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_server.cc:200: Child pid=12526 killed, Process status = 15
[22:23:48] /Users/rqg/Playground/tvm/apps/cpp_rpc/rpc_server.cc:224: Socket Connection Closed

@FrozenGene
Copy link
Member

please fix the format problem using clang-format-10

.gitignore Outdated
Comment on lines 199 to 200
cmake-build-debug
cmake-build*
Copy link
Member

Choose a reason for hiding this comment

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

your pr should not be related with this .gitignore

Copy link
Contributor Author

@fantasyRqg fantasyRqg Jun 10, 2021

Choose a reason for hiding this comment

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

Should I modify .gitignore in another PR ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, if you think it is a must

std::string android_base_ = "/data/data/" + std::string(cwd) +"/cache";
struct stat statbuf;
if (stat(android_base_.data(), &statbuf) == -1 || !S_ISDIR(statbuf.st_mode)){
android_base_ = ".";
Copy link
Member

Choose a reason for hiding this comment

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

If failed, android_base_ becomes ., will ./rpc work well on android?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When current working directory is writable, Yes .

Another option is force base_ to /data/local/tmp/rpc. But I don't think this is a good choice. So I keep the original implementation .

Copy link
Member

Choose a reason for hiding this comment

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

how about add one simple code comment to indicate users if failed, should make sure the directory is writable and also consider to change base_ to /data/local/tmp/rpc. This could help users find one solution more quickly

@fantasyRqg
Copy link
Contributor Author

@FrozenGene All problems solved

base_ = "/data/data/" + std::string(cwd) + "/cache/rpc";
std::string android_base_ = "/data/data/" + std::string(cwd) + "/cache";
struct stat statbuf;
// Check if application data directory exist. If not exist usually mean tvm_rpc run from adb
Copy link
Member

Choose a reason for hiding this comment

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

Nitty comment. If not exist, usually means we run tvm_rpc from adb shell terminal

// Check if application data directory exist. If not exist usually mean tvm_rpc run from adb
// shell terminal.
if (stat(android_base_.data(), &statbuf) == -1 || !S_ISDIR(statbuf.st_mode)) {
// Tmp directory always writable for 'shell' user.
Copy link
Member

Choose a reason for hiding this comment

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

is always writable...

@FrozenGene FrozenGene self-assigned this Jun 15, 2021
@fantasyRqg
Copy link
Contributor Author

@FrozenGene Thanks for correcting my spelling mistake [Lol]

@FrozenGene FrozenGene merged commit c208a1f into apache:main Jun 21, 2021
@FrozenGene
Copy link
Member

Thanks @fantasyRqg

ylc pushed a commit to ylc/tvm that referenced this pull request Sep 29, 2021
* support adb-shell style cpp_rpc

* fix review problems,  apache#8223

* add comment & use /data/local/tmp dir in shell terminal case

* fix spelling errors

* fix spelling errors

Co-authored-by: rqg <ranqingguo90@qq.com>
Co-authored-by: rqg <ranqingguo318@gmail.com>
zxy844288792 pushed a commit to zxy844288792/tvm that referenced this pull request Mar 4, 2022
* support adb-shell style cpp_rpc

* fix review problems,  apache#8223

* add comment & use /data/local/tmp dir in shell terminal case

* fix spelling errors

* fix spelling errors

Co-authored-by: rqg <ranqingguo90@qq.com>
Co-authored-by: rqg <ranqingguo318@gmail.com>
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