This is a project to implement the tensor calculation library and (inference) neural network in c++, can see it as a revision of PyTorch and ncnn, the difference is that I remove all codes that not relate to CPU, maybe will support GPU after but not now.
The network structure is same as Neural Network with some enhancement and is inspired by ConvNetJS, Darknet, Caffe and ncnn.
It aims to enhance the performance on mobile phone platform.
The main purpose of this project is used for NTHU電機系實作專題.
Add some function for image loading and saving, which is powered by stb_image.
Add some drawing for image, which is powered by OpenCV.
- C++17
- No dependencies
- Multi-thread support with OpenMp
- Symbolic operation
- Arm optimization
Since some consideration, the project configuration is dominant by CMake. Hence, if you has the requirement of not depend on CMake, you need to add a flag -DOTTER_CONFIG when compiling, with that, you can manually control the option by Config.hpp
OTTER_MOBILE = 0to build with mobile optimize. Note that this will disableAVXcapability
OTTER_OPENMP = 1to enable multithread withopenmp
OTTER_AVX = 1to enableAVXcapability
Build for intel
mkdir build && cd build
cmake ..
make -j8
Build for intel and M1. Note that need to revise Config.hpp -> OTTER_MOBILE = 1
mkdir build && cd build
cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" ..
make -j8
If you encounter libomp problem. Try to install openmp with below steps.
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/openmp-11.0.0.src.tar.xz
tar -xf openmp-11.0.0.src.tar.xz
cd openmp-11.0.0.src
sed -i'' -e '/.size __kmp_unnamed_critical_addr/d' runtime/src/z_Linux_asm.S
sed -i'' -e 's/__kmp_unnamed_critical_addr/___kmp_unnamed_critical_addr/g' runtime/src/z_Linux_asm.S
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
-DLIBOMP_ENABLE_SHARED=OFF -DLIBOMP_OMPT_SUPPORT=OFF -DLIBOMP_USE_HWLOC=OFF ..
cmake --build . -j 2
cmake --build . --target install
mkdir openmp-install
cp -r install/* ./openmp-install
sudo cp ./openmp-install/include/* /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
sudo cp ./openmp-install/lib/libomp.a /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
mkdir build && cd build
cmake ..
make -j 8
g++ -DOTTER_CONFIG=1 -Os -fopenmp -ffp-contract=fast -mavx -mavx2 -msse3 -msse4.1 -msse4.2 -msse4a -mfma -o otter *.cpp