-
Notifications
You must be signed in to change notification settings - Fork 353
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
Device::cuda_if_available() is false #907
Comments
same on Ubuntu enviroment, is there any way to solve it? |
exactly the same issue on Windows 11 |
Ensure that you have a |
Thanks! I tried your suggestion, but unfortunately, the problem still persists.
|
Well, I'm not sure if this can be the final solution, even I am still can't sure what the problem is, but it seems to have solved my problem for now. The answer in this link worked for me. use std::ffi::CString;
use libc::dlopen;
fn main() {
let path = CString::new("/root/libtorch/lib/libtorch_cuda.so").unwrap();
unsafe {
dlopen(path.into_raw(), 1);
}
println!("cuda: {}", tch::Cuda::is_available());
println!("cudnn: {}", tch::Cuda::cudnn_is_available());
} |
I had this same issue on Ubuntu 22.04.5, tch 0.18.0, and libtorch 2.5.0 cxx11-abi for CUDA 12.4 with rustc 1.84.0-nightly (81eef2d36 2024-11-11), i.e. all the following lines printed "false": println!("{:?}", tch::Cuda::is_available());
println!("{:?}", tch::utils::has_cuda());
println!("{:?}", tch::utils::has_cudart()); And when I added the following build.rs to mycrate root... 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");
}
_ => {}
}
} ...the build failed with the following error:
But simply removing the following line from build.rs fixed that error and now CUDA is detected by tch just fine: println!("cargo:rustc-link-arg=-Wl,--copy-dt-needed-entries"); By the way, according to ld manual (which I believe lld is trying to adhere to), it seems that "--copy-dt-needed-entries" is the default option anyway, so perhaps it's not actually needed. |
Had the same issue with the same settings as @pubfnbar and his solution worked. I remember that it worked at some point without this hack with an earlier rustc version. |
I tried to run the examples with
My environment:
Output:
|
Copying some of the fn main() {
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=-ltorch");
} Notably, this didn't work without removing the |
@Anivie's solution worked for me on Windows 11: use std::ffi::CString;
use std::os::raw::c_char;
use winapi::um::libloaderapi::LoadLibraryA;
fn main() {
let path = CString::new("X:\\path\\to\\torch_cuda.dll").unwrap();
unsafe {
LoadLibraryA(path.as_ptr() as *const c_char);
}
println!("cuda: {}", tch::Cuda::is_available());
println!("cudnn: {}", tch::Cuda::cudnn_is_available());
} |
After spending a while trying to get libtorch-cxx11 + rocm 6.2 + my 6700xt working in a docker container, this made it finally work and it I can enable cuda. Note: this is related strictly to pytorch itself, but I also had to export LIBTORCH=/root/libtorch/
export LIBTORCH_INCLUDE=/root/libtorch/
export LIBTORCH_LIB=/root/libtorch/
export LD_LIBRARY_PATH=/root/libtorch/lib/:$LD_LIBRARY_PATH
export HSA_OVERRIDE_GFX_VERSION=10.3.0 |
I use tch = "0.18.0" on windows 11
Downloaded libtorch-win-shared-with-deps-2.5.0+cu118
My env vars are:
LIBTORCH=D:\softwares\Libtorch\libtorch-win-shared-with-deps-2.5.0+cu118\libtorch
TORCH_CUDA_VERSION=11.8
TORCH_VERSION=cu118
Could anybody help me,
what I need to do to have cuda?
The text was updated successfully, but these errors were encountered: