LaurentMazare / tch-rs

Rust bindings for the C++ api of PyTorch.
Apache License 2.0
4.33k stars 344 forks source link

Android/iOS supported? #315

Open songww opened 3 years ago

songww commented 3 years ago

Failed to build for iOS:

warning: clang: warning: -Wl,-rpath=/Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/lib: 'linker' input unused [-Wunused-command-line-argument]
warning: In file included from libtch/torch_api.cpp:1:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/autograd/engine.h:6:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/ATen/Tensor.h:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/ATen/core/TensorBody.h:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/c10/core/Device.h:5:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/c10/util/Exception.h:5:
warning: /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/c10/util/StringUtil.h:77:5: error: thread-local storage is not supported for the current target
warning:     thread_local const std::string empty_string_literal;
warning:     ^
warning: /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/c10/util/StringUtil.h:78:12: warning: reference to stack memory associated with local variable 'empty_string_literal' returned [-Wreturn-stack-address]
warning:     return empty_string_literal;
warning:            ^~~~~~~~~~~~~~~~~~~~
warning: In file included from libtch/torch_api.cpp:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/torch.h:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/all.h:8:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/data.h:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/data/dataloader.h:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/data/dataloader/base.h:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/data/dataloader_options.h:4:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/types.h:7:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/autograd/generated/variable_factories.h:12:
warning: /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/jit/frontend/tracer.h:140:10: error: thread-local storage is not supported for the current target
warning:   static thread_local ArgumentStash stash;
warning:          ^
warning: In file included from libtch/torch_api.cpp:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/torch.h:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/all.h:12:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/nn.h:3:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/nn/cloneable.h:5:
warning: In file included from /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/torch/csrc/api/include/torch/utils.h:3:
warning: /Users/songmowei/Workspace/src/gitlab.weilaicheng.com/pytorch/build_ios/install/include/ATen/Parallel.h:41:3: error: thread-local storage is not supported for the current target
warning:   thread_local bool init = false;
warning:   ^
warning: In file included from libtch/torch_api.cpp:8:
warning: libtch/torch_api.h:6:1: error: thread-local storage is not supported for the current target
warning: thread_local char *torch_last_err = nullptr;
warning: ^
warning: 1 warning and 4 errors generated.

error: failed to run custom build command for `torch-sys v0.3.1`
songww commented 3 years ago

For iOS, should add flag -miphoneos-version-min=9.0 to cc.

songww commented 3 years ago

Many srcs not compiled for mobile default. Perhaps we should add some feature gates to works for mobile?

simlay commented 1 year ago

To fix this thread_local issue, specify a IPHONEOS_DEPLOYMENT_TARGET of something 9.0 or later. It defaults to 7.0.

flutter-painter commented 1 year ago

Any news so far ?