This program uses LibTorch (the C++ version of PyTorch) to train a simple neural network on the MNIST dataset. It performs the following steps:
- Downloads the MNIST dataset.
- Loads the entire dataset into GPU memory.
- Trains a model for 10 epochs.
- Collects and saves performance stats (time, accuracy, GPU usage, memory) to the
stats/directory in the project root.
- An NVIDIA GPU with CUDA.
- A C++ compiler,
cmake, andlibcurl. - A downloaded copy of LibTorch. You must set the
LIBTORCHenvironment variable to point to the extracted LibTorch directory.
From the cpp/ directory, run:
# Set this to your LibTorch path
export LIBTORCH=/path/to/your/libtorch
# Build the project
cd cpp_benchmark
mkdir -p build
cd build
cmake ..
make
# Run the benchmark
./mnist_benchmark_cpp