examples/cpp/README.md
This is a minimal example of getting PyG to work in C++ with CMake.
In order to successfully compile this example, make sure you have both the C++ APIs of TorchScatter and TorchSparse installed.
For this, we need to add TorchLib to the -DCMAKE_PREFIX_PATH (run import torch; print(torch.utils.cmake_prefix_path) to obtain it).
Then, e.g., to install TorchScatter, run:
git clone https://github.com/rusty1s/pytorch_scatter.git
cd pytorch_scatter
mkdir build && cd build
cmake -DWITH_CUDA=on -DCMAKE_PREFIX_PATH="..." ..
make
(sudo) make install
Once both dependencies are sorted, we can start the CMake fun:
save_model.py to create and save a PyG GNN model.build directory inside the current one.build directory, run the following commands:
cmake -DCMAKE_PREFIX_PATH="<PATH_TO_LIBTORCH>;<PATH_TO_TORCHSCATTER>;<PATH_TO_TORCH_SPARSE>" ..cmake --build .That's it!
You should now have a hello-world executable in your build folder.
Run it via:
./hello-world ../model.pt