How to compile binary with libtorch without CUDA

Is that possible somehow? I looked at the Caffe2 and Torch cmake files and there did not seem to be a straightforward way to do it (but I’m a newbie with C++ compilation and cmake).

I am not sure what you want. But the NO_CUDA=1 flag will disable all cuda stuff.

1 Like

I want to have no dependencies on CUDA when using libtorch to compile binaries, as I’m not going to be using a GPU.

I’m now thinking the way to do this is to compile pytorch without CUDA, is that possible? There’s a year old issue where the answer is no it isn’t.

As I said above, running the compilation with NO_CUDA=1 env variable set will do a compilation and install without any cuda dependency.

1 Like

Sorry, and thanks.

How could one compile it without installing it? I don’t want it to overwrite my existing installation, which I assume will happen when doing python3 install.

You can do python3 build to only build cpp dependencies.

1 Like

How do we set the No_CUDA = 1 flag? In the Cmake file or something else?

I set the environment variable NO_CUDA as 1 in my windows OS. It is not working. CMake still asked me cuda stuff.
The error message is following

– Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18363.
CUDA_TOOLKIT_ROOT_DIR not found or specified
CMake Warning at C:/libtorch/share/cmake/Caffe2/public/cuda.cmake:31 (message):
Caffe2: CUDA cannot be found. Depending on whether you are building Caffe2
or a Caffe2 dependent library, the next warning / error will give you more
Call Stack (most recent call first):
C:/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
C:/libtorch/share/cmake/Torch/TorchConfig.cmake:40 (find_package)
CMakeLists.txt:4 (find_package)

reply to myself,
just use the libtorch that does not need cuda.


Updated answer:

# Bash
USE_CUDA=0 python install
# CMD (Windows)
set USE_CUDA=0
python install
# Powershell
python install