You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/04/18 22:24:21 UTC

[GitHub] [tvm] apeskov opened a new pull request #7875: Custom dyld linker for iOS mach-o executable files

apeskov opened a new pull request #7875:
URL: https://github.com/apache/tvm/pull/7875


   This PR is a part of iOS enabling efforts. Particularly it allows to use regular TVM RPC mechanics in the way like for Android platform.
   
   Essential part of auto tuning on real iOS device is an ability to run kernel from module received over network. This patch allows to load shared libraries received by RPC server from host side and stored in temporal directory on device. No requirements of signing this binary.
   
   As in a short this patch introduce custom version of dlopen, dlclose, dlsym functions with next features:
   * Based on original dyld sources provided by Apple
   * The check of binary signing is switched off
   * Works only under debugger (lldb). The JIT itself is not allowed for iOS, but it has some mitigation for debuggers.
   * Provides very limited linker implementation but enough for successful RPC processing
   
   The sources copied from original dyld repository are stored in folder `3rdparty/macho-dyld/src/dyld`. The TVM specific changes are marked with FOR_TVM macros.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-844263545


   Thanks @apeskov !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] apeskov closed pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
apeskov closed pull request #7875:
URL: https://github.com/apache/tvm/pull/7875


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen edited a comment on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-833584917


   Thanks @apeskov I agree moving the changes into the iOS rpc app.  The files we include in the 3rdparty would beed to be apache compatible, because we bundle and release the source code, which requires more careful handling. 
   
   Only putting macho loader that is ALv2, and provide instructions/script for the user of iOS RPC to download and link the macho loader is cleaner. Given that particular header's API is generic(can use dlopen on linux), we can release that particular header under Apache v2, and implement the API using the mach-o library. As the end result, from the source release point of view we are not bundling the source code with Apple license. 
   
   Of course the user who wish to use iOS RPC app would need to build the app, and at that time the app itself need to comply with the Apple license. 
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-833584917


   Thanks @apeskov I agree moving the changes into the iOS rpc app.  The files we include in the 3rdparty would beed to be apache compatible, because we bundle and release the source code, which requires more careful handling.
   
   Only putting macho loader that is ALv2, and provide instructions/script for the user of iOS RPC to download and link the macho loader is cleaner. Since from the source release point of view we are not bundling the source code 
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen edited a comment on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-822532298


   After looking at the source code, I think it would be better to isolate the piece of macho-dyld linker as a separate thirdparty repo (e.g. like https://github.com/tlc-pack/libbacktrace). While exposing a set of common C APIs that we can depend on, in particular the following C APIs.
   
   - macho_dlopen
   - macho_dlsym
   - macho_dlclose
   
   We can then depend on these API headers cleanly(as they are common public API that can be reimplemented in other platforms). This would alleviate the possible license mixing concerns that might arise.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen edited a comment on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-833584917


   Thanks @apeskov I agree moving the changes into the iOS rpc app.  The files we include in the 3rdparty would beed to be apache compatible, because we bundle and release the source code, which requires more careful handling. 
   
   Only putting macho loader that is ALv2, and provide instructions/script for the user of iOS RPC to download and link the macho loader is cleaner. Given that particular header's API is generic(can use dlopen on linux), we can also make the name generic(e.g. custom_dlopen),  we can release that particular header under Apache v2, and implement the API using the mach-o library. As the end result, from the source release point of view we are not bundling the source code with Apple license. 
   
   Of course the user who wish to use iOS RPC app would need to build the app, and at that time the app itself need to comply with the Apple license. 
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen edited a comment on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-822520669


   Thanks @apeskov , it would be great to know if we can rely on the apple DYLD via submodule or linked library. Additionally, we want to check if the license(Apple license) is compatible with ALv2. 
   
   If not, we cannot checkin the code that directly relies on this  and would need to create a separate repo for the iOS RPC to make sure the TVM source is clean


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-822532298


   After looking at the source code, I think it would be better to isolate the piece of macho-dyld linker as a separate repo while exposing a set of common C APIs that we can depend on, in particular the following C APIs.
   
   - macho_dlopen
   - macho_dlsym
   - macho_dlclose
   
   We can then depend on these API headers cleanly(as they are common public API that can be reimplemented in other platforms). This would alleviate the possible license mixing concerns that might arise.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] apeskov commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
apeskov commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-843031087


   @tqchen @jcf94 Could you please continue review or assign someone to take a look.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen edited a comment on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-822520669


   Thanks @apeskov . This enablement looks quite interesting. We might need to be careful here wrt to the compatiblity of Apple license with ALv2.  We cannot checkin the code that directly relies on this  and would need to create a separate repo for the iOS RPC to make sure the TVM source is clean


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen edited a comment on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-833584917


   Thanks @apeskov I agree moving the changes into the iOS rpc app.  The files we include in the 3rdparty would beed to be apache compatible, because we bundle and release the source code, which requires more careful handling. Given that particular header's API is generic(can use dlopen on linux), we can release that particular header under a Apache v2, and implement the API using the mach-o library
   
   Only putting macho loader that is ALv2, and provide instructions/script for the user of iOS RPC to download and link the macho loader is cleaner. Since from the source release point of view we are not bundling the source code 
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] apeskov commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
apeskov commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-832645618


   Reopen. Was closed by mistake.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-832848378


   Thanks @apeskov . This is an important step. Would be great if we can think about de-couple further to reverse the dependency. (e.g. make the macho depend on libtvm as a plugin).
   
   The main rationale is that depending on the license we may not want to directly make this as a submodule(which means we will package and distribute the source by default and there might be some license complications).
   
   Here is an idea:
   - We create another plugin module that depends on libtvm which registers an overrided version of so loader.
   - see https://github.com/apache/tvm/blob/main/src/runtime/dso_library.cc#L93
   - We can then run a plugin that registers the new loader back to TVM. see an example here https://github.com/apache/tvm/tree/main/apps/extension
   
   This way we do not need to hijack the dso library 
   
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen edited a comment on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-822532298


   After looking at the source code, I think it would be better to isolate the piece of macho-dyld linker as a separate thirdparty repo (e.g. https://github.com/tlc-pack/macho-dyld). While exposing a set of common C APIs that we can depend on, in particular the following C APIs.
   
   - macho_dlopen
   - macho_dlsym
   - macho_dlclose
   
   We can then depend on these API headers cleanly(as they are common public API that can be reimplemented in other platforms). This would alleviate the possible license mixing concerns that might arise.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] apeskov commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
apeskov commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-833513287


   Thank you @tqchen for comment! Your concerns about license mixing is relevant. And I absolutely agree that keep license clean is a priority.
   
   I've got your point about reverse linker->tvm dependency. And moreover It will be more elegant solution I guess. I will do it on iOS RPC server side via "tvm.rpc.server.load_module" rewriting. It will have the same effect. 
   
   But anyway, I didn't fully catch your position regarding keep this module in 3rdparty folder. Is it acceptable or not? My wishes is very simple, I would like to have TVM tuning with iOS devices out of box. Doesn't matter how it will be distributed: integrated submodule, checked out by cmake or installed from brew.  
   
   If we would like to keep 3rdparty folder only for Apache/MIT/BSD licensed code, I can suggest next plan of integration:
   
   1. Move all changes into iOS RPC server app. New DSO loader injection via "tvm.rpc.server.load_module" modification.
   2. Implement minimal loader version from scratch and put it under ALv2 license near iOS_rpc app. Just a minimal quasi loader  suitable for tuning purposes. It will depend only on system header files from public SDK (like `mach-o/loader.h` and may be some others). I hope it's applicable to include files with Apple License header from apache code.
   
   @tqchen What do you think regarding this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen edited a comment on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-833584917


   Thanks @apeskov I agree moving the changes into the iOS rpc app.  The files we include in the 3rdparty would beed to be apache compatible, because we bundle and release the source code, which requires more careful handling. 
   
   Only putting macho loader that is ALv2, and provide instructions/script for the user of iOS RPC to download and link the macho loader is cleaner. Given that particular header's API is generic(can use dlopen on linux), we can release that particular header under a Apache v2, and implement the API using the mach-o library. As the end result, from the source release point of view we are not bundling the source code 
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-822520669


   Thanks @apeskov , it would be great to know if we can rely on the apple DYLD via submodule or linked library. Additionally, we want to check if the license(Apple license) is compatible with ALv2. 
   
   If not, we cannot checkin the code that directly relies on this  and would need to create a separate repo for the iOS RPC .


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] apeskov commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
apeskov commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-841812080


   @tqchen I've tried to address your comments. Could you please take a look on updated version of this PR and provide a feedback is it OK or not.
   
   As in short:
   * I've moved macho-dyld repository into cmake level as ExternalProject. It will be automatically downloaded and built with `ios_rpc` cmake target. This targets are enabled under special flag "USE_IOS_RPC" (is switched off by default).
   * Xcode project is modified to support conditional compilation of custom_dso_loader plugin triggered by user defined setting "USE_CUSTOM_DSO_LOADER=1". Otherwise it will work as before.
   * Corresponding section in readme and test scripts are also added.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] tqchen merged pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
tqchen merged pull request #7875:
URL: https://github.com/apache/tvm/pull/7875


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] apeskov commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
apeskov commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-841812080


   @tqchen I've tried to address your comments. Could you please take a look on updated version of this PR and provide a feedback is it OK or not.
   
   As in short:
   * I've moved macho-dyld repository into cmake level as ExternalProject. It will be automatically downloaded and built with `ios_rpc` cmake target. This targets are enabled under special flag "USE_IOS_RPC" (is switched off by default).
   * Xcode project is modified to support conditional compilation of custom_dso_loader plugin triggered by user defined setting "USE_CUSTOM_DSO_LOADER=1". Otherwise it will work as before.
   * Corresponding section in readme and test scripts are also added.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] apeskov commented on pull request #7875: Custom dyld linker for iOS mach-o executable files

Posted by GitBox <gi...@apache.org>.
apeskov commented on pull request #7875:
URL: https://github.com/apache/tvm/pull/7875#issuecomment-832657486


   @tqchen Your recommendation was fulfilled.
   * The conflict sources was extracted into separate repo https://github.com/octoml/macho-dyld
   * TVM is linked with macho_dyld dynamically
   * TVM depends only on one header file `macho_dlfcn.h`
   
   Some details about macho-dyld. All sources inside this repo including written by myself have an Apple license header (I treat it as deep modification of original implementations). There is only one header `macho_dlfcn.h` without any license it has an declaration of API functions. I hope that is a correct handling of Apple sources in context of integration to TVM.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org