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

Initial changes for iOS support #660

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ fn grad_example() {
}

fn main() {
println!("Cuda available: {}", tch::Cuda::is_available());
println!("Cudnn available: {}", tch::Cuda::cudnn_is_available());
let device = tch::Device::cuda_if_available();
//println!("Cuda available: {}", tch::Cuda::is_available());
//println!("Cudnn available: {}", tch::Cuda::cudnn_is_available());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If these two lines are uncommented, I get the following compile error:

error: linking with `cc` failed: exit status: 1
  = note: Undefined symbols for architecture arm64:
            "torch::cuda::is_available()", referenced from:
                _atc_cuda_is_available in libtorch_sys-0d280fb35559980b.rlib(torch_api.o)
            "torch::cuda::cudnn_is_available()", referenced from:
                _atc_cudnn_is_available in libtorch_sys-0d280fb35559980b.rlib(torch_api.o)
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm not sure why. It doesn't happen on the macOS build.

//TODO: Fix this for ios and non-ios.
let device = tch::Device::Mps;
let t = Tensor::of_slice(&[3, 1, 4, 1, 5]).to(device);
t.print();
let t = Tensor::randn(&[5, 4], kind::FLOAT_CPU);
Expand Down
9 changes: 8 additions & 1 deletion torch-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn make<P: AsRef<Path>>(libtorch: P, use_cuda: bool, use_hip: bool) {
println!("cargo:rerun-if-changed=libtch/stb_image_resize.h");
println!("cargo:rerun-if-changed=libtch/stb_image.h");
match os.as_str() {
"linux" | "macos" => {
"linux" | "macos" | "ios" => {
let libtorch_cxx11_abi =
env_var_rerun("LIBTORCH_CXX11_ABI").unwrap_or_else(|_| "1".to_owned());
cc::Build::new()
Expand Down Expand Up @@ -257,12 +257,19 @@ fn main() {
println!("cargo:rustc-link-lib=torch_cpu");
println!("cargo:rustc-link-lib=torch");
println!("cargo:rustc-link-lib=c10");

if use_hip {
println!("cargo:rustc-link-lib=c10_hip");
}

let target = env::var("TARGET").unwrap();

if target.contains("ios") {
println!("cargo:rustc-link-lib=cpuinfo");
println!("cargo:rustc-link-lib=clog");
println!("cargo:rustc-link-lib=pthreadpool");
}

if !target.contains("msvc") && !target.contains("apple") {
println!("cargo:rustc-link-lib=gomp");
}
Expand Down