Skip to content

chenjunhao0315/Tensor

Repository files navigation

Tensor

About

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.

Feature

  • C++17
  • No dependencies
  • Multi-thread support with OpenMp
  • Symbolic operation
  • Arm optimization

Documentation

Build and run

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 = 0 to build with mobile optimize. Note that this will disable AVX capability
OTTER_OPENMP = 1 to enable multithread with openmp
OTTER_AVX = 1 to enable AVX capability

MacOS

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

Build for iOS with Xcode

Detail step

Linux

mkdir build && cd build
cmake ..
make -j 8

Windows

g++ -DOTTER_CONFIG=1 -Os -fopenmp -ffp-contract=fast -mavx -mavx2 -msse3 -msse4.1 -msse4.2 -msse4a -mfma -o otter *.cpp

Thanks for and reference

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages