tch-rs icon indicating copy to clipboard operation
tch-rs copied to clipboard

Initial changes for iOS support

Open simlay opened this issue 2 years ago • 2 comments

I figured I'd give iOS building a shot. To even get started, one must build the iOS library for PyTorch. Make sure the TORCH_VERSION from torch-sys matches the PyTorch checkout.

For aarch64-apple-ios-sim you want to run BUILD_PYTORCH_MOBILE=1 IOS_PLATFORM=SIMULATOR IOS_ARCH=arm64 ./scripts/build_ios.sh. For aarch64-apple-ios you want BUILD_PYTORCH_MOBILE=1 IOS_ARCH=arm64 ./scripts/build_ios.sh It's unclear how to get x86_64-apple-ios (the x86-64 iOS simulator).

Once you've got that built, IPHONEOS_DEPLOYMENT_TARGET=16.1 LIBTORCH=$PWD/pytorch-checkout/build_ios/install cargo build --target aarch64-apple-ios-sim --example basics

TODO:

ld: in /Users/simlay/projects/tch-rs/target/debug/deps/libring-9ce1a2518f1231ce.rlib(aesv8-armx-ios64.o), building for macOS, but linking in object file built for iOS, file '/Users/simlay/projects/tch-rs/target/debug/deps/libring-9ce1a2518f1231ce.rlib' for architecture arm64

Work around is to build for host and then build for cross compiler target.

Here's the runtime error I'm seeing when I run the basics example in the iOS simulator:

"Could not find schema for aten::zeros.
Exception raised from findSchemaOrThrow at /Users/simlay/projects/torch-sys-source/pytorch/aten/src/ATen/core/dispatch/Dispatcher.cpp:131 (most recent call first):
frame #0: _ZN3c106detail14torchCheckFailEPKcS2_jRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE + 92 (0x100a7aa1c in basics)
frame #1: _ZN3c1010Dispatcher17findSchemaOrThrowEPKcS2_ + 516 (0x100a37234 in basics)
frame #2: _ZN2at4_opsL25create_zeros_typed_handleEv + 48 (0x100a138f0 in basics)
frame #3: _ZN2at4_ops5zeros4callEN3c108ArrayRefINS2_6SymIntEEENS2_8optionalINS2_10ScalarTypeEEENS6_INS2_6LayoutEEENS6_INS2_6DeviceEEENS6_IbEE + 176 (0x100a1387c in basics)
frame #4: _ZN2at5zerosEN3c108ArrayRefIxEENS0_13TensorOptionsE + 248 (0x1009ce27c in basics)
frame #5: _ZN5torch5zerosEN3c108ArrayRefIxEENS0_13TensorOptionsE + 136 (0x1009c592c in basics)
frame #6: at_tensor_of_data + 124 (0x1009c56c8 in basics)
frame #7: _ZN3tch8wrappers6tensor6Tensor10f_of_slice17h8c301062d1683d0dE + 136 (0x1009bdae4 in basics)
frame #8: _ZN3tch8wrappers6tensor6Tensor8of_slice17h3ef2e65ed55dda2cE + 36 (0x1009bdbd0 in basics)
frame #9: _ZN6basics4main17h4585665960def4e9E + 44 (0x1009be1ac in basics)
frame #10: _ZN4core3ops8function6FnOnce9call_once17h166a604c999bde6cE + 20 (0x1009bdd94 in basics)
frame #11: _ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h133407b50aa38c1eE + 24 (0x1009bdd38 in basics)
frame #12: _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h8df4dd181cd92464E + 28 (0x1009bde84 in basics)
frame #13: _ZN3std2rt19lang_start_internal17h75a83dce357f8b7cE + 380 (0x1009f350c in basics)
frame #14: _ZN3std2rt10lang_start17h53972f716e62a038E + 84 (0x1009bde50 in basics)
frame #15: main + 36 (0x1009be614 in basics)
frame #16: start_sim + 20 (0x100c59fa0 in dyld)
frame #17: 0x0 + 4308835920 (0x100d39e50 in ???)
frame #18: 0x0 + 5216716480866942976 (0x4865800000000000 in ???)
")', /Users/simlay/projects/tch-rs/src/wrappers/tensor.rs:447:32

simlay avatar Mar 26 '23 20:03 simlay

@simlay Does it mean it's possible to build and link the torch lib statically? I filed this ticket originally to find out: https://github.com/LaurentMazare/tch-rs/issues/647

antimora avatar Apr 03 '23 18:04 antimora

@simlay Does it mean it's possible to build and link the torch lib statically? I filed this ticket originally to find out: #647

I believe that would be one result of iOS support. Given that my local iOS pytorchlib directory doesn't have any dylibs (only .a's) I believe so.

simlay avatar Apr 04 '23 15:04 simlay