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

Rework the torch-sys build script. #703

Merged
merged 3 commits into from
May 13, 2023
Merged
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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ members = ["torch-sys"]

[features]
default = ["torch-sys/download-libtorch"]
python = ["cpython"]
python-libtorch = ["torch-sys/python-libtorch"]
rl_python = ["cpython"]
doc-only = ["torch-sys/doc-only"]
cuda-tests = []

Expand All @@ -48,7 +49,7 @@ features = [ "doc-only" ]

[[example]]
name = "reinforcement-learning"
required-features = ["python"]
required-features = ["rl_python"]

[[example]]
name = "stable-diffusion"
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ your system. You can either:

- Use the system-wide libtorch installation (default).
- Install libtorch manually and let the build script know about it via the `LIBTORCH` environment variable.
- When a system-wide libtorch can't be found and `LIBTORCH` is not set, the build script will download a pre-built binary version
of libtorch. By default a CPU version is used. The `TORCH_CUDA_VERSION` environment variable
can be set to `cu117` in order to get a pre-built binary using CUDA 11.7.
- Use a Python PyTorch install, to do this set `LIBTORCH_USE_PYTORCH=1`.
- When a system-wide libtorch can't be found and `LIBTORCH` is not set, the
build script will download a pre-built binary version of libtorch. By default
a CPU version is used. The `TORCH_CUDA_VERSION` environment variable can be
set to `cu117` in order to get a pre-built binary using CUDA 11.7.

### System-wide Libtorch

The build script will look for a system-wide libtorch library in the following locations:
- In Linux: `/usr/lib/libtorch.so`
On linux platforms, the build script will look for a system-wide libtorch
library in `/usr/lib/libtorch.so`.

### Python PyTorch Install

If the `LIBTORCH_USE_PYTORCH` environment variable is set, the active python
interpreter is called to retrieve information about the torch python package.
This version is then linked against.

### Libtorch Manual Install

Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ fn main() {
let os = std::env::var("CARGO_CFG_TARGET_OS").expect("Unable to get TARGET_OS");
match os.as_str() {
"linux" | "windows" => {
if let Some(lib_path) = std::env::var_os("DEP_TCH_LIBTORCH_LIB") {
println!("cargo:rustc-link-arg=-Wl,-rpath={}", lib_path.to_string_lossy());
}
println!("cargo:rustc-link-arg=-Wl,--no-as-needed");
println!("cargo:rustc-link-arg=-Wl,--copy-dt-needed-entries");
println!("cargo:rustc-link-arg=-ltorch");
Expand Down
1 change: 1 addition & 0 deletions torch-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ zip = "0.6"
[features]
download-libtorch = ["ureq", "serde", "serde_json"]
doc-only = []
python-libtorch = []

[package.metadata.docs.rs]
features = [ "doc-only" ]
Loading