Hi,
This issue can be fixed by updating Makefile with “-Wl,–no-as-needed”.
The root cause of cuda::is_available() returns false is that CUDA context cannot be created correctly.
You can find more message when calling at::detail::getCUDAHooks().showConfig().
Cannot query detailed CUDA version without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason. The CUDA library MUST be loaded, EVEN IF you don’t directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,–no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don’t depend on any of their symbols. You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.
As indicates, CUDA library doesn’t load since the dependencies is removed by dynamic linkers.
After adding the *-Wl,–no-as-needed" config, we can get cuda::is_available() return True on XavierNX.
diff --git a/Makefile b/Makefile
index 0f69c2c..6939e75 100644
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@ LIBS+= -Wl,-no-undefined \
-lnppc -lnppig -lnpps -lnppicc -lnppidei
-LIBS+= -Wl,-no-undefined \
+LIBS+= -Wl,-no-undefined -Wl,--no-as-needed\
-L$(PYTORCH_LIBRARIES) -ltorch -lc10 -lgomp -lnvToolsExt -lc10_cuda -ltorch_cuda -ltorch_cpu\
-Wl,-rpath,$(PYTORCH_LIBRARIES)
diff --git a/main.cpp b/main.cpp
Thanks.