This project implements a simple feedforward neural network for the MNIST dataset, with the following variants:
- Naive C++ implementation - strightforward implementation using standard library and some sort of OOP (
app/naive) - Eigen-optimized implementation - linear-algebra-friendly implementation using Eigen library (
app/eigen)
All variants load the MNIST dataset from embedded resources (embedded with cmakerc library) and train/test a neural network with specified number of hidden layer.
- Minimum CMake: 3.25
- Compilers tested:
gcc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
- Internet connection (required for CMake
FetchContent)
If you use a different version or compiler and encounter a compilation error, please let me know and I'll fix it as soon as possible.
cd vulkan_neural_network
mkdir build
cmake -S . -B build
cmake --build buildThere may be compilation warnings from some third-party libraries. You can ignore them.
VKNN_BUILD_EIGEN- build Eigen-based implementation -eigen_nn,ONby defaultVKNN_USE_AVX2- useavx2instructions set for the Eigen-based implementation,OFFby default, requires a CPU with avx2 support
VKNN_BUILD_NAIVE- build naive implementation -naive_nn,ONby defaultVKNN_USE_DOUBLE- use double precision (double) data type instead of single precision (float),OFFby default
To use an option, provide it during the configuration step, for example:
cmake -S . -B build -DVKNN_USE_DOUBLE=ON -DVKNN_BUILD_EIGEN=OFFapp/naive/— Naive neural network implementationapp/eigen/— Eigen-based neural network implementationlibs/common/— Common utilities (e.g., data loading, timers)libs/warnings/— Compiler warning settingsresources/— MNIST dataset filesthird_party/— External dependencies (fmt, cmakerc, eigen)
# naive implementation
./build/app/naive/naive_nn
# eigen implementation
./build/app/eigen/eigen_nnAll implementations will train and test a neural network on the embedded MNIST dataset.
The following MNIST files are embedded as resources:
train-images.idx3-ubytetrain-labels.idx1-ubytet10k-images.idx3-ubytet10k-labels.idx1-ubyte
See LICENSE.