pytorch / cppdocs

PyTorch C++ API Documentation
https://pytorch.org/cppdocs
206 stars 33 forks source link

How to set up pytorch for c++ (with g++) via commandline not cmake #16

Closed usr577 closed 1 year ago

usr577 commented 1 year ago

I have a Lapop with a nvidia graphicscard and I'm trying to use pytorch for cuda with g++. But i couldn't find any good information about dependecies e.g and my compiler always trohws errors, I'm currently using this command I found on the internet: "g++ -std=c++14 main.cpp -I ${TORCH_DIR}/include/torch/csrc/api/include/ -I ${TORCH_DIR}/include/ -L ${TORCH_DIR}/lib/ -L /usr/local/cuda/lib64 -L /usr/local/cuda/nvvm/lib64 -ltorch -lc10 -lc10_cuda -lnvrtc -lcudart_static -ldl -lrt -pthread -o out", but it just says: "torch/torch.h: file not found"

albanD commented 1 year ago

Hi, Do you actually have PyTorch installed in that c++ folder? If you are not very familiar with build system and c++, I would recommend you use the python API for simplicity. Or at least use CMake if you want to stick with c++

usr577 commented 1 year ago

What do you mean by "installed"? If you mean having the "libtorch" folder there, then yes I have installed it, how would I make it with cmake?

albanD commented 1 year ago

You can find the minimal cmake in the intro here: https://pytorch.org/cppdocs/installing.html

usr577 commented 1 year ago

The sample programm doesn't find torch so I added set(Torch_DIR "/path/to/libtorch/share/cmake/Torch"), but now it returns

CMake Error at libtorch/share/cmake/Caffe2/Caffe2Config.cmake:100 (message): Your installed Caffe2 version uses cuDNN but I cannot find the cuDNN libraries. Please set the proper cuDNN prefixes and / or install cuDNN. Call Stack (most recent call first): libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package) CMakeLists.txt:5 (find_package)

albanD commented 1 year ago

Did you install cuDNN? Usually putting it inside your cuda install is the simplest way to do it.

usr577 commented 1 year ago

Yes I did using the guide on the Nvidia website, it described how to do it with apt and I followed it exactly.

albanD commented 1 year ago

Make sure that you install cuda in a compatible way. Don't you need to provide CUDNN_LIBRARY and include env variable?

usr577 commented 1 year ago

Followed the "tar Installation guide" on the Nvidia website and everything works smoothly now, thanks(Hope I didn't bother you too much :) )!