-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[iOS] Add tracker support into ios-rpc application #7876
Conversation
apps/ios_rpc/tvmrpc/rpc_server.h
Outdated
* \param ping_period Timeout for select call waiting | ||
*/ | ||
void AcceptConnection(TrackerClient* tracker, support::TCPSocket* conn_sock, | ||
support::SockAddr* addr, std::string* opts, int ping_period = 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specify units: ping_period_sec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as previous comment. Copy-paste form cpp_rpc
. Already removed. You may move this comment into original cpp_rpc
application
tvm/apps/cpp_rpc/rpc_server.cc
Line 238 in 1c251f5
support::SockAddr* addr, std::string* opts, int ping_period = 2) { |
apps/ios_rpc/tvmrpc/rpc_server.h
Outdated
* \param opts The option string | ||
*/ | ||
int GetTimeOutFromOpts(const std::string& opts) const { | ||
const std::string option = "-timeout="; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if this should also have units? -timeout-sec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. And already removed.
@@ -71,88 +73,19 @@ void LogMessageImpl(const std::string& file, int lineno, const std::string& mess | |||
namespace tvm { | |||
namespace runtime { | |||
|
|||
class NSStreamChannel final : public RPCChannel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious why this is going away? not needed if we use standard sockets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved into "RPCServer.mm". And now it's wrapped into PackedFunction
to meet API requirements of rpc.CreateEventDrivenServer
.
fe5622e
to
c3765ea
Compare
3970ee7
to
e6f6f08
Compare
@areusch I've tried to answer your comments. Could you please continue a review? Some part of code you pointed previously to improve was redesigned with latest commits, specially the code which was borrowed from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apeskov thanks! a couple more questions--mainly it would be helpful for me to understand the use case around introducing the gRPC transport. it's not that i'm opposed to doing that, but I'd like to understand why we may need it since it does add some complexity.
apps/ios_rpc/tvmrpc/RPCArgs.mm
Outdated
|
||
bool immediate_connect = false; | ||
bool verbose = false; | ||
char server_mode = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should that be an enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it could be enum. I've changed it to use enum form RPCServer.h.
apps/ios_rpc/tvmrpc/RPCArgs.mm
Outdated
args.server_mode = 0; | ||
} else if (server_mode == "proxy") { | ||
args.server_mode = 1; | ||
} else if (server_mode == "pure_server") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the use case for gRPC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to answer in reply message.
apps/ios_rpc/tvmrpc/RPCArgs.h
Outdated
|
||
/// Immediate server launch. No UI interaction. | ||
/// 0 - UI interaction, 1 - automatically connect on launch | ||
char immediate_connect; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you represent bool quantities with char? (instead of bool or uint8_t)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, bool should be used here. Will change.
Originally it was a simplest way to share API between code written on Obj-C, Obj-C++, and C++ ("BOOL" and "bool" are not so compatible). But now there is no such need.
apps/ios_rpc/tvmrpc/RPCArgs.mm
Outdated
[defaults setObject:[NSString stringWithUTF8String:g_rpc_args.host_url.c_str()] | ||
forKey:@"tmvrpc_url"]; | ||
[defaults setInteger:g_rpc_args.host_port forKey:@"tmvrpc_port"]; | ||
[defaults setObject:[NSString stringWithUTF8String:g_rpc_args.key.c_str()] forKey:@"tmvrpc_key"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: tvm, here and above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
apps/ios_rpc/tvmrpc/RPCServer.mm
Outdated
/*! | ||
*/ | ||
- (NSData*)requestInputDataPacked { | ||
int size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to use the inttypes when taking sizeof() to compute payload lengths for wire data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Moved to int32_t everywhere.
apps/ios_rpc/tvmrpc/RPCServer.mm
Outdated
switch (state_) { | ||
case RPCServerProxyState_HandshakeToSend: { | ||
// Send together kRPCMagic and server descriptor because of Proxy | ||
int code = tvm::runtime::kRPCMagic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inttypes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Will assume that gRPC == PureRPC in terminology of this patch. At first, I would like to note that "PureRPC" is a part of "Tracker" mode. The implementation of "Tracker" server mode is using using "PureRPC" as internal server. I've just expose it outside for person who would like to use direct connection to iOS without tracker/proxy. Removing this piece of functionality will not simplify implementation. The main goal was to allow user and developers to work with iOS without requirements to keep tracker/proxy server. As example I have one laptop and one iOS device connected to it via USB (there are no local WiFi network at all, or it is very slow). With using PureRPC mode plus port tunnelling (via usbmux tool) I can work with such setup. In addition to this patch I have a plan to introduce iOSRPCRunner script which will allow me to automate iOS test with quite simple code like next: # Will use first connected iOS device with automatic TCP port tunnelling to host
ios_rpc_serv = RPCServerIOS.create_ios_rpc_server(key=key, mode="pure_server")
remote = rpc.connect(ios_rpc_serv.host, ios_rpc_serv.port, key=key)
do_some_test_with_ios(remote) Port tunnelling may significantly speed up work with iOS device. My local benchmarking shows 3x-4x speed depends on kind of workload (yes, wifi router matter). Definitely, the same speed up result can be also achieved with tracker. For this purpose I've introduced flag Totally, from my point of view, PureRPC is not so hard to support feature, but it can simplify/speedup my scripts in some cases :-) |
@areusch could you please continue review. I resolved all your comments excluding two. I've tried to explain in corresponding replies why I don't want to change it. Hope it will be enough. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apeskov sorry i think the thing i'm confused about is: what functionality does RPCServerPure add over the existing tracker (or: why was the existing tracker not able to be run over usbmux)? perhaps it would be helpful to see an e.g. README.md explaining how to use RPCServerPure. Does it e.g. allow you to start/stop the tracker or RPC server? sorry my obj-c/iOS is not super great so I keep trying to review this but going in circles.
apps/ios_rpc/tvmrpc/RPCServer.mm
Outdated
*/ | ||
FEventHandler CreateServerEventHandler(NSOutputStream* outputStream, std::string name, | ||
std::string remote_key) { | ||
const PackedFunc* event_handler_factor = Registry::Get("rpc.CreateEventDrivenServer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: event_handler_factory
d7049cf
to
84bd23c
Compare
@apeskov just reviving this--please address the comment |
Hello @areusch! @apeskov is busy with other activities. I'm working to finish this PR. What about your comment. I already fixed the typo, and now I'm working on adding a detailed instruction which will help to understand the new workflow and how it works. |
84bd23c
to
2b363ac
Compare
Signed-off-by: Alexander Peskov <peskovnn@gmail.com>
Signed-off-by: Alexander Peskov <peskovnn@gmail.com>
Signed-off-by: Alexander Peskov <peskovnn@gmail.com>
Also containes: * Links with tvm_runtime.dylib * Minor improvements from UX perspective * Add cli args support * Add caching for url/port/key attributes Signed-off-by: Alexander Peskov <peskovnn@gmail.com>
Signed-off-by: Alexander Peskov <peskovnn@gmail.com>
Also: - Disabled bit-code - Enabled ARC - Use custom DSO loader by default - Single button to connect/disconnect - Add verbose flag Signed-off-by: Alexander Peskov <peskovnn@gmail.com>
Signed-off-by: Alexander Peskov <peskovnn@gmail.com>
Signed-off-by: Alexander Peskov <peskovnn@gmail.com>
ca092c9
to
f6a2f8f
Compare
Renamed to standalone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks @apeskov !
and thanks @echuraev ! |
* [IOS-RPC] Missprint in flag value Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] custom_dyld up commit id. Fix mem leak Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] build without scheme Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] Add tracker support into ios-rpc app Also containes: * Links with tvm_runtime.dylib * Minor improvements from UX perspective * Add cli args support * Add caching for url/port/key attributes Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] lint fix Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] Uniform servers Also: - Disabled bit-code - Enabled ARC - Use custom DSO loader by default - Single button to connect/disconnect - Add verbose flag Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS_RPC] Min changes. Fix warnings Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] Fix review comments Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * Fix RPC connection to tracker * Fix typo * Fix build for local developer profile * Add tvmrpc xcode scheme * Revert unnecessary change * Remove old mechanism of reloading libs * Display ip and port for PureRPC mode * Update tests * Remove tvmLauncher from ios_rpc * Add updating tvm_build_dir in init_proj script * Update default bundle * Update README.md for ios_rpc * Fix lint * Apply comments * Rename PureRPC to Standalone Co-authored-by: Egor Churaev <egor.churaev@gmail.com>
* [IOS-RPC] Missprint in flag value Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] custom_dyld up commit id. Fix mem leak Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] build without scheme Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] Add tracker support into ios-rpc app Also containes: * Links with tvm_runtime.dylib * Minor improvements from UX perspective * Add cli args support * Add caching for url/port/key attributes Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] lint fix Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] Uniform servers Also: - Disabled bit-code - Enabled ARC - Use custom DSO loader by default - Single button to connect/disconnect - Add verbose flag Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS_RPC] Min changes. Fix warnings Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * [IOS-RPC] Fix review comments Signed-off-by: Alexander Peskov <peskovnn@gmail.com> * Fix RPC connection to tracker * Fix typo * Fix build for local developer profile * Add tvmrpc xcode scheme * Revert unnecessary change * Remove old mechanism of reloading libs * Display ip and port for PureRPC mode * Update tests * Remove tvmLauncher from ios_rpc * Add updating tvm_build_dir in init_proj script * Update default bundle * Update README.md for ios_rpc * Fix lint * Apply comments * Rename PureRPC to Standalone Co-authored-by: Egor Churaev <egor.churaev@gmail.com>
Some set of improvements for iOS RPC application. The main point of changes is in build procedure and introducing support of direct RPC connection and connection via Tracker.
Build process improvements
-undefined,error
linker flag which is not compatible with bitcode.UI changes
RPC functional changes
Registry::Get("rpc.CreateEventDrivenServer")
Note:
Arguments support and status printing are a prerequisites for implementation python based RPC Server launcher (on top of iOS-deploy and simctl tools). Will be introduced a little bit later.