Bug? 1.5 c++ front end: torch::cuda::is_available() =false

I just installed torch 1.5 c++ front end (Windows, Visual Studio 2019). Cuda 10.1, latest
Nvidia drivers. This is in DEBUG version of the library.

Following code:

main() {
CudaPresent = torch::cuda::is_available();
}

CudaPresent is FALSE.

When I use torch 1.4 C++ front end, everything else is the same on the same PC, code is working fine
and returns CudaPresent = TRUE

Any help super appreciated.
thanks!

1 Like

Just found in some other post, adding a Linker option -INCLUDE:?warp_size@cuda@at@@YAHXZ
worked for me too.
Why is so complicated?

1 Like

Well, it is because torch_cuda and torch_cpu are separated to make the linker happy. (target executable/library has a size limit) However, calling torch::cuda::is_available(); doesn’t rely on any symbol in torch_cuda so the linker will optimize it away for your executable. As the result, you see FALSE there. Adding -INCLUDE:?warp_size@cuda@at@@YAHXZ forces the linker to include torch_cuda. If you use CMake, then you don’t need to set it manually. I just don’t expect so many users that create the VS project on their own. So we are working on to move this flag into the header to avoid confusing the user.

1 Like

Many thanks for prompt response. I was waiting for this VS integration capability for several years and it looks great right now. Thank you for your excellent work!

@artemmikheev at what linker option did you add “-INCLUDE:?warp_size@cuda@at@@YAHXZ” ?

It is under Linker>All Options>Additional Options

Thank you,I already tried that, but torch::cuda::is_available() is still 0.Any advices?

Does this issue resolved ? The torch::cuda::is_available() api return false on my linux system, while torch.cuda.is_available() return True.
How to fix it ?

oot@b92d948aa67e:/workspace/code/example# ldd build/main
linux-vdso.so.1 (0x00007ffd61df4000)
libc10.so => /workspace/code/mytorch/pytorch/build/lib/libc10.so (0x00007f964377c000)
libtorch_cpu.so => /workspace/code/mytorch/pytorch/build/lib/libtorch_cpu.so (0x00007f962dc51000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f962da69000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f962da4e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f962d85c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f962d70b000)
libgomp.so.1 => /lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f962d6c9000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f962d6a6000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9643953000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f962d69c000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f962d696000)
libmkl_intel_lp64.so.1 => /root/anaconda3/lib/libmkl_intel_lp64.so.1 (0x00007f962caf5000)
libmkl_gnu_thread.so.1 => /root/anaconda3/lib/libmkl_gnu_thread.so.1 (0x00007f962af6a000)
libmkl_core.so.1 => /root/anaconda3/lib/libmkl_core.so.1 (0x00007f9626afc000)
libcupti.so.11.6 => /usr/local/cuda/lib64/libcupti.so.11.6 (0x00007f9626250000)
libcudart.so.11.0 => /usr/local/cuda/lib64/libcudart.so.11.0 (0x00007f9625fac000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f9625fa5000)