• 第10节 libtorch与torchvision交叉编译(ARM与安卓 ios)


    libtorch cross compile on aarch64-linux-gnu-gcc include torchvision

    Refer to:

    https://github.com/pytorch/pytorch#get-the-pytorch-source

    https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst

    Compile libtorch c++ api from source - #2 by WMF1997 - C++ - PyTorch Forums

    libtorch を Android でビルドするメモ - Qiita

    https://github.com/ljk53/pytorch-android-cpp-demo

    https://github.com/dpilger26/NumCpp/tree/master

    #install gcc compiler

    sudo apt install build-essential

    #install python3 version >= 3.7 need, here is a lot works.

    https://fatalfeel.blogspot.com/2019/12/ai-with-cuda-install-step-and-yolov3-in.html

    #install cmake 3.20.5

    wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null

    sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'

    sudo apt update

    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DE19EB17684BA42D

    sudo apt install cmake cmake-qt-gui cmake-curses-gui

    sudo apt install ninja-build

    #download torch source

    git clone --recursive https://github.com/pytorch/pytorch.git

    cd pytorch

    git checkout v1.7.1

    git submodule sync

    git submodule update --init --recursive

    CPU_NUM=$(grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}')

    echo "CPU number = "$CPU_NUM

    =========Ubuntu16.04 x86_64=========

    (a)

    build opencv x64 version for libtorch, opencv can help convert image to tensor easier

    https://fatalfeel.blogspot.com/2013/12/opencv-and-dlib-training.html

    (b)

    cd pytorch

    mkdir build

    cd build

    #OpenCV_DIR can get OpenCVConfig.cmake

    cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/libtorch/x64 -DPYTHON_EXECUTABLE=$(which python3) -DBUILDING_WITH_TORCH_LIBS=ON -DATEN_THREADING=NATIVE -DUSE_OPENCV=ON -DOpenCV_DIR=/opt/opencv/share/OpenCV -DBUILD_EXAMPLES=ON -DUSE_CUDA=ON

    cmake --build . --target install -- -j$CPU_NUM VERBOSE=1

    =========Android=========

    https://developer.android.com/ndk/downloads/older_releases

    download and extract Android NDK 19c to /opt

    #python link to python3

    ln -sf /usr/bin/python3.7 /usr/bin/python

    pip3 install pyyaml

    cd pytorch

    #release version

    gedit ./scripts/build_android.sh

    -DCMAKE_BUILD_TYPE=Release

    #change to

    -DCMAKE_BUILD_TYPE=RelWithDebInfo

    #debug version

    gedit ./scripts/build_android.sh

    -DCMAKE_BUILD_TYPE=Release

    #change to

    -DCMAKE_BUILD_TYPE=Debug

    export ANDROID_NDK=/opt/android-ndk

    export ANDROID_ABI=arm64-v8a

    export ANDROID_NATIVE_API_LEVEL=28

    export ANDROID_DEBUG_SYMBOLS=1

    export VERBOSE=1

    ./scripts/build_android.sh

    =========Numpy C++=========

    add-apt-repository ppa:mhier/libboost-latest

    apt update

    apt install libboost1.68-dev

    git clone https://github.com/dpilger26/NumCpp.git

    cd $HOME/NumCpp/install

    mkdir build

    cd build

    cmake -DCMAKE_INSTALL_PREFIX=/opt/numcpp ..

    make && make install

    (when use it need CXXFLAGS += -std=c++14)

    Example libtorch and numpy in eclipse:

    http://www.mediafire.com/file/zr1txqkqzl064i9/openai.tar.gz

    =========================aarch64-linux-gnu-gcc=========================

    refer to:

    a. dependencies prebuilt

    https://github.com/t-kuha/mpsoc-library/wiki/How-to-build-libtorch-&-torchvision          

    b. dependencies manual

    https://github.com/t-kuha/mpsoc-library/wiki/How-to-build-Caffe-%26-libtorch-dependencies

    c. cmake 3.20.5

    https://fatalfeel.blogspot.com/2013/12/build-nrf9160dk-projects-with-zephyr-os.html      

    d. python 3.7.9

    https://fatalfeel.blogspot.com/2019/12/ai-with-cuda-install-step-and-yolov3-in.html         

    //libtorch dependency prebuilt in git//

    1.

    git clone --recursive https://github.com/pytorch/pytorch

    cd pytorch

    git checkout v1.7.1

    git submodule sync

    git submodule update --init --recursive

    export LIBTORCH_ROOT=$(pwd)

    2.

    ./scripts/build_host_protoc.sh

    3.

    cd third_party/sleef

    mkdir _host

    cd _host

    cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=_install -DBUILD_TESTS=OFF

    cmake --build . --target install -- -j$CPU_NUM VERBOSE=1

    4. (if use manual make libs, skip this)

    cd ../..

    git clone -b 2019.2 https://github.com/t-kuha/mpsoc-library.git

    export DEPEND_DIR=$(pwd)/mpsoc-library

    5.

    cd $LIBTORCH_ROOT

    gedit ./toolchain.make

    #add

    set( CMAKE_SYSTEM_NAME Linux )

    set( CMAKE_SYSTEM_PROCESSOR aarch64 )

    set( CMAKE_C_COMPILER /opt/ivot/aarch64-ca53-linux-gnueabihf-8.4/bin/aarch64-ca53-linux-gnu-gcc )

    set( CMAKE_CXX_COMPILER /opt/ivot/aarch64-ca53-linux-gnueabihf-8.4/bin/aarch64-ca53-linux-gnu-g++ )

    #save & exit

    6.

    export PATH=$PATH:/opt/ivot/aarch64-ca53-linux-gnueabihf-8.4/bin

    export LD_LIBRARY_PATH=/opt/ivot/aarch64-ca53-linux-gnueabihf-8.4/lib

    CPU_NUM=$(grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}')

    echo "CPU number = "$CPU_NUM

    7. (option can skip, if cmake error)

    when

    CMake Error at cmake/Codegen.cmake:163 (message):

    cd $LIBTORCH_ROOT

    gedit ./cmake/Codegen.cmake

    set(GEN_COMMAND

      "${PYTHON_EXECUTABLE}" ${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/gen.py

    #to

    find_package (Python COMPONENTS Interpreter)

    set(GEN_COMMAND

      "${Python_EXECUTABLE}" ${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/gen.py

    8.

    cd $LIBTORCH_ROOT

    gedit ./cmake/TorchConfig.cmake.in

    ~comment

    ###if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

    ###  set(TORCH_CXX_FLAGS "-

    _GLIBCXX_USE_CXX11_ABI=@GLIBCXX_USE_CXX11_ABI@")

    ###endif()

    mkdir _mpsoc

    cd _mpsoc

    cmake ${LIBTORCH_ROOT} -G"Unix Makefiles" \

    -DCMAKE_INSTALL_PREFIX=/opt/libtorch/arm64 \

    -DCMAKE_BUILD_TYPE=Release \

    -DCAFFE2_CUSTOM_PROTOC_EXECUTABLE=${LIBTORCH_ROOT}/build_host_protoc/bin/protoc \

    -DCMAKE_TOOLCHAIN_FILE=toolchain.make \

    -DCMAKE_PREFIX_PATH=${DEPEND_DIR}/dl-framework/caffe-dependency \

    -DPYTHON_EXECUTABLE=$(which python3) \

    -C${DEPEND_DIR}/dl-framework/libtorch/TryRunResults.cmake \

    -DBUILDING_WITH_TORCH_LIBS=ON \

    -DBUILD_BINARY=ON \

    -DBUILD_CAFFE2_MOBILE=ON \

    -DBUILD_CAFFE2_OPS=ON \

    -DBUILD_CUSTOM_PROTOBUF=ON \

    -DBUILD_DFT=OFF \

    -DBUILD_DOCS=OFF \

    -DBUILD_GMOCK=ON \

    -DBUILD_GNUABI_LIBS=OFF \

    -DBUILD_LIBM=ON \

    -DBUILD_ONNX_PYTHON=OFF \

    -DBUILD_PYTHON=OFF \

    -DBUILD_QUAD=OFF \

    -DBUILD_SHARED_LIBS=ON \

    -DBUILD_TEST=ON \

    -DBUILD_TESTS=ON \

    -DUSE_ASAN=OFF \

    -DUSE_CUDA=OFF \

    -DUSE_DISTRIBUTED=OFF \

    -DUSE_FBGEMM=ON \

    -DUSE_FFMPEG=ON \

    -DUSE_GFLAGS=ON \

    -DUSE_GLOG=ON \

    -DUSE_GLOO=OFF \

    -DUSE_LEVELDB=ON \

    -DUSE_LITE_PROTO=OFF \

    -DUSE_LMDB=ON \

    -DUSE_METAL=OFF \

    -DUSE_MKLDNN=OFF \

    -DUSE_MPI=OFF \

    -DUSE_NATIVE_ARCH=OFF \

    -DUSE_NNAPI=OFF \

    -DUSE_NNPACK=ON \

    -DUSE_NUMA=OFF \

    -DUSE_NUMPY=ON \

    -DUSE_OBSERVERS=OFF \

    -DUSE_OPENCL=OFF \

    -DUSE_OPENCV=ON \

    -DUSE_OPENMP=OFF \

    -DUSE_PROF=OFF \

    -DUSE_PYTORCH_QNNPACK=OFF \

    -DUSE_QNNPACK=ON \

    -DUSE_REDIS=OFF \

    -DUSE_ROCKSDB=ON \

    -DUSE_ROCM=OFF \

    -DUSE_SNPE=OFF \

    -DUSE_SYSTEM_EIGEN_INSTALL=OFF \

    -DUSE_TBB=OFF \

    -DUSE_TENSORRT=OFF \

    -DUSE_ZMQ=ON \

    -DUSE_ZSTD=OFF \

    -DHAVE_STD_REGEX=0 \

    -DHAVE_POSIX_REGEX=0 \

    -DHAVE_STEADY_CLOCK=0 \

    -DATEN_THREADING=NATIVE \

    -DBLAS=OpenBLAS \

    -DCMAKE_CROSSCOMPILING=ON \

    -DNATIVE_BUILD_DIR=${LIBTORCH_ROOT}/third_party/sleef/_host/ \

    -DCMAKE_CXX_FLAGS="-L${DEPEND_DIR}/dl-framework/caffe-dependency/lib -llmdb -lleveldb -lsnappy -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_video -lopencv_videoio -lzmq -lrocksdb"

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    /libtorch manual make libs///

    1.

    wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null

    sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'

    sudo apt update

    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DE19EB17684BA42D

    sudo apt install cmake cmake-qt-gui cmake-curses-gui

    2.

    gedit ./toolchain.make

    set( CMAKE_SYSTEM_NAME Linux )

    set( CMAKE_SYSTEM_PROCESSOR aarch64 )

    set( CMAKE_C_COMPILER /opt/ivot/aarch64-ca53-linux-gnueabihf-8.4/bin/aarch64-ca53-linux-gnu-gcc )

    set( CMAKE_CXX_COMPILER /opt/ivot/aarch64-ca53-linux-gnueabihf-8.4/bin/aarch64-ca53-linux-gnu-g++ )

    ~~~save and copy to each dependency source~~~

    3.

    wget https://raw.githubusercontent.com/t-kuha/mpsoc-library/2019.2/dl-framework/libtorch/TryRunResults.cmake

    mkdir -p /opt/torch_dependency/arm64

    cp ./TryRunResults.cmake /opt/torch_dependency/arm64

    4.

    export PATH=$PATH:/opt/ivot/aarch64-ca53-linux-gnueabihf-8.4/bin

    export LD_LIBRARY_PATH=/opt/ivot/aarch64-ca53-linux-gnueabihf-8.4/lib

    CPU_NUM=$(grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}')

    echo "CPU number = "$CPU_NUM

    5.

    Version 1.68.0

    download bboost_1_68_0.tar.gz

    tar -xvf ./boost_1_68_0.tar.gz

    cd boost_1_68_0

    ./bootstrap.sh

    gedit ./project-config.jam

    using gcc ;

    ~change to

    using gcc : arm64 : aarch64-ca53-linux-gnu-g++ ;

    using python : 2.7 : /usr ;

    ~change to

    using python : 3.7 : /usr ;

    ./bjam install toolset=gcc-arm64 variant=release link=shared threading=multi runtime-link=shared --prefix=/opt/torch_dependency/arm64 --with-thread --with-system --with-filesystem -j$CPU_NUM

    6.

    https://github.com/gflags/gflags/releases

    download gflags-2.2.2.tar.gz

    tar -xvf ./gflags-2.2.2.tar.gz

    cd gflags-2.2.2

    mkdir _mpsoc

    cd _mpsoc

    cmake .. -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.make -DCMAKE_INSTALL_PREFIX=/opt/torch_dependency/arm64 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    7.

    https://github.com/google/glog/releases

    download glog-0.4.0.tar.gz

    tar -xvf ./glog-0.4.0.tar.gz

    cd glog-0.4.0

    mkdir _mpsoc

    cd _mpsoc

    cmake .. -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.make -DCMAKE_INSTALL_PREFIX=/opt/torch_dependency/arm64 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    8.

    https://github.com/google/leveldb/releases

    download leveldb-1.22.tar.gz

    tar -xvf ./leveldb-1.22.tar.gz

    cd leveldb-1.22

    mkdir _mpsoc

    cd _mpsoc

    cmake .. -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.make -DCMAKE_INSTALL_PREFIX=/opt/torch_dependency/arm64 -DCMAKE_BUILD_TYPE=Release -DLEVELDB_BUILD_TESTS=OFF -DLEVELDB_BUILD_BENCHMARKS=OFF -DBUILD_SHARED_LIBS=ON

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    9.

    Tags · openldap / OpenLDAP · GitLab

    download openldap-LMDB_0.9.24.tar.gz

    tar -xvf ./openldap-LMDB_0.9.24.tar.gz

    cd openldap-LMDB_0.9.24/libraries/liblmdb

    gedit ./Makefile

    CC      = gcc

    AR      = ar

    OPT     = -O2 -g

    prefix  = /usr/local

    #change to

    CC      = aarch64-ca53-linux-gnu-gcc

    AR      = aarch64-ca53-linux-gnu-ar

    OPT     = -O3

    prefix  = /opt/torch_dependency/arm64

    #save

    make -j$CPU_NUM install

    10.

    https://github.com/xianyi/OpenBLAS/releases?page=2

    download OpenBLAS-0.3.7.tar.gz

    tar -xvf ./OpenBLAS-0.3.7.tar.gz

    cd OpenBLAS-0.3.7

    mkdir _mpsoc

    cd _mpsoc

    cmake .. -G"Unix Makefiles" \

    -DCMAKE_TOOLCHAIN_FILE=toolchain.make \

    -DCMAKE_INSTALL_PREFIX=/opt/torch_dependency/arm64 \

    -DCMAKE_BUILD_TYPE=Release \

    -DNOFORTRAN=1 \

    -DBUILD_SHARED_LIBS=1

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    11.

    Releases - OpenCV

    download opencv-3.4.8.zip

    unzip ./opencv-3.4.8.zip

    cd opencv-3.4.8

    mkdir _mpsoc

    cd _mpsoc

    cmake .. -G"Unix Makefiles" \

    -DCMAKE_TOOLCHAIN_FILE=toolchain.make \

    -DCMAKE_INSTALL_PREFIX=/opt/torch_dependency/arm64 \

    -DCMAKE_BUILD_TYPE=Release \

    -DBUILD_PERF_TESTS=OFF \

    -DBUILD_TESTS=OFF \

    -DBUILD_ZLIB=ON \

    -DWITH_CUDA=OFF \

    -DZLIB_INCLUDE_DIR=../3rdparty/zlib

    cmake-gui ./CMakeCache.txt

    #enable these modules, disable unuse BUILD_opencv_xxxx

    BUILD_opencv_core

    BUILD_opencv_video

    BUILD_opencv_videoio

    BUILD_opencv_highgui

    BUILD_opencv_imgproc

    BUILD_opencv_imgcodecs

    #press Configure then Generate

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    12.

    https://github.com/protocolbuffers/protobuf/releases?page=6

    download protobuf-3.10.1.tar.gz

    tar -xvf ./protobuf-3.10.1.tar.gz

    cd protobuf-3.10.1

    mkdir _host

    cd _host

    cmake ../cmake/ -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/opt/torch_dependency/x64/host -Dprotobuf_BUILD_TESTS=OFF

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    ~~~must copy toolchain.make to ./protobuf-3.10.1/cmake

    cd ..

    mkdir _mpsoc

    cd _mpsoc

    export PATH=${PATH}:/opt/torch_dependency/x64/host/bin

    cmake ../cmake/ -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.make -DCMAKE_INSTALL_PREFIX=/opt/torch_dependency/arm64 -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=ON

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    13.

    https://github.com/google/snappy/releases

    download snappy-1.1.7.tar.gz

    tar -xvf ./snappy-1.1.7.tar.gz

    cd snappy-1.1.7

    mkdir _mpsoc

    cd _mpsoc

    cmake .. -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.make -DCMAKE_INSTALL_PREFIX=/opt/torch_dependency/arm64 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    14.

    https://github.com/facebook/rocksdb/releases?page=4

    download rocksdb-6.4.6.tar.gz

    tar -xvf ./rocksdb-6.4.6.tar.gz

    cd rocksdb-6.4.6

    mkdir _mpsoc

    cd _mpsoc

    cmake .. -G"Ninja" -DCMAKE_TOOLCHAIN_FILE=toolchain.make -DCMAKE_INSTALL_PREFIX=/opt/torch_dependency/arm64 -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=OFF -DWITH_TOOLS=OFF -DWITH_GFLAGS=OFF -DPORTABLE=ON

    ~~~can not use VERBOSE=1~~~

    cmake --build . --config Release --target install -- -j$CPU_NUM

    15.

    https://github.com/zeromq/libzmq/releases

    download libzmq-4.3.4.tar.gz

    tar -xvf ./libzmq-4.3.4.tar.gz

    cd libzmq-4.3.4

    mkdir _mpsoc

    cd _mpsoc

    cmake .. -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/opt/torch_dependency/arm64 -DCMAKE_TOOLCHAIN_FILE=toolchain.make -DBUILD_STATIC=OFF -DBUILD_TESTS=OFF -DWITH_DOCS=OFF -DWITH_PERF_TOOL=OFF

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    16.

    first do step 1.2.3.5.6.7. of [libtorch dependency prebuilt in git]

    cd $LIBTORCH_ROOT

    gedit ./cmake/TorchConfig.cmake.in

    ~comment

    ###if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

    ###  set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=@GLIBCXX_USE_CXX11_ABI@")

    ###endif()

    mkdir _mpsoc

    cd _mpsoc

    cmake ${LIBTORCH_ROOT} -G"Unix Makefiles" \

    -DCMAKE_INSTALL_PREFIX=/opt/libtorch/arm64 \

    -DCMAKE_BUILD_TYPE=Release \

    -DCAFFE2_CUSTOM_PROTOC_EXECUTABLE=${LIBTORCH_ROOT}/build_host_protoc/bin/protoc \

    -DCMAKE_TOOLCHAIN_FILE=toolchain.make \

    -DCMAKE_PREFIX_PATH=/opt/torch_dependency/arm64 \

    -DPYTHON_EXECUTABLE=$(which python3) \

    -C/opt/torch_dependency/arm64/TryRunResults.cmake \

    -DBUILDING_WITH_TORCH_LIBS=ON \

    -DBUILD_BINARY=ON \

    -DBUILD_CAFFE2_MOBILE=ON \

    -DBUILD_CAFFE2_OPS=ON \

    -DBUILD_CUSTOM_PROTOBUF=ON \

    -DBUILD_DFT=OFF \

    -DBUILD_DOCS=OFF \

    -DBUILD_GMOCK=ON \

    -DBUILD_GNUABI_LIBS=OFF \

    -DBUILD_LIBM=ON \

    -DBUILD_ONNX_PYTHON=OFF \

    -DBUILD_PYTHON=OFF \

    -DBUILD_QUAD=OFF \

    -DBUILD_SHARED_LIBS=ON \

    -DBUILD_TEST=ON \

    -DBUILD_TESTS=ON \

    -DUSE_ASAN=OFF \

    -DUSE_CUDA=OFF \

    -DUSE_DISTRIBUTED=OFF \

    -DUSE_FBGEMM=ON \

    -DUSE_FFMPEG=ON \

    -DUSE_GFLAGS=ON \

    -DUSE_GLOG=ON \

    -DUSE_GLOO=OFF \

    -DUSE_LEVELDB=ON \

    -DUSE_LITE_PROTO=OFF \

    -DUSE_LMDB=ON \

    -DUSE_METAL=OFF \

    -DUSE_MKLDNN=OFF \

    -DUSE_MPI=OFF \

    -DUSE_NATIVE_ARCH=OFF \

    -DUSE_NNAPI=OFF \

    -DUSE_NNPACK=ON \

    -DUSE_NUMA=OFF \

    -DUSE_NUMPY=ON \

    -DUSE_OBSERVERS=OFF \

    -DUSE_OPENCL=OFF \

    -DUSE_OPENCV=ON \

    -DUSE_OPENMP=OFF \

    -DUSE_PROF=OFF \

    -DUSE_PYTORCH_QNNPACK=OFF \

    -DUSE_QNNPACK=ON \

    -DUSE_REDIS=OFF \

    -DUSE_ROCKSDB=ON \

    -DUSE_ROCM=OFF \

    -DUSE_SNPE=OFF \

    -DUSE_SYSTEM_EIGEN_INSTALL=OFF \

    -DUSE_TBB=OFF \

    -DUSE_TENSORRT=OFF \

    -DUSE_ZMQ=ON \

    -DUSE_ZSTD=OFF \

    -DHAVE_STD_REGEX=0 \

    -DHAVE_POSIX_REGEX=0 \

    -DHAVE_STEADY_CLOCK=0 \

    -DATEN_THREADING=NATIVE \

    -DBLAS=OpenBLAS \

    -DCMAKE_CROSSCOMPILING=ON \

    -DNATIVE_BUILD_DIR=${LIBTORCH_ROOT}/third_party/sleef/_host/ \

    -DCMAKE_CXX_FLAGS="-L/opt/torch_dependency/arm64/lib -llmdb -lleveldb -lsnappy -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_video -lopencv_videoio -lzmq -lrocksdb"

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    ~~~note: using python 3.7.9 = -DPYTHON_EXECUTABLE=$(which python3)

    17.

    https://github.com/pytorch/vision/releases

    download vision-0.8.2.tar.gz

    tar -xvf ./vision-0.8.2.tar.gz

    cd vision-0.8.2

    ~modify these files add definition USE_PYTHON for cmake, header, source

    ./CMakeLists.txt

    ./cmake/TorchVisionConfig.cmake.in

    ./torchvision/csrc/cpu/image/image.cpp

    ./torchvision/csrc/cpu/video/Video.h

    ./torchvision/csrc/cpu/video_reader/VideoReader.cpp

    ./torchvision/csrc/cpu/vision_cpu.h

    ./torchvision/csrc/empty_tensor_op.h

    ./torchvision/csrc/vision.cpp

    ~patch here

    vision-0.8.2_patch.tar

    mkdir _mpsoc

    cd _mpsoc

    cmake .. -G"Unix Makefiles" \

    -DCMAKE_TOOLCHAIN_FILE=toolchain.make \

    -DCMAKE_INSTALL_PREFIX=/opt/torch_vision/arm64 \

    -DCMAKE_BUILD_TYPE=Release \

    -DCMAKE_PREFIX_PATH=/opt/torch_dependency/arm64 \

    -DTorch_DIR=/opt/libtorch/arm64/share/cmake/Torch \

    -DUSE_PYTHON=OFF \

    -DWITH_CUDA=OFF \

    -DPNG_LIBRARY=/opt/torch_dependency/arm64/lib/libopencv_imgcodecs.so \

    -DJPEG_LIBRARY=/opt/torch_dependency/arm64/lib/libopencv_imgcodecs.so

    ~~~remove define _GLIBCXX_USE_CXX11_ABI

    ~~~TorchConfig.cmake.in modified already, so we can skip sed -i

    ###sed -i 's/-D_GLIBCXX_USE_CXX11_ABI=//g' ./CMakeFiles/torchvision.dir/flags.make

    cmake --build . --config Release --target install -- -j$CPU_NUM VERBOSE=1

    sample code:

    torch_test.tar

    demo: (both forward & backward support for aarch64-linux-gnu-gcc)

    File sharing and storage made simple

    File sharing and storage made simple

    https://www.mediafire.com/view/cmqha2rgexv7l3p/libtorch_nettransform.png

    File sharing and storage made simple

    ///

    Tesla told in New York Herald: I prefer to be remembered as the inventor who succeeded in abolishing war. That will be my highest pride.

    Tesla Collection (in middle section)

    Albert Einstein: The release of atom power has changed everything except our way of thinking... the solution to this problem lies in the heart of mankind. If only I had known, I should have become a watchmaker.

    Albert Einstein – AtomicTrauma

    AI produce carbon footprint

    https://arxiv.org/pdf/1906.02243.pdf

  • 相关阅读:
    测试左移?测试右移?测试人员往哪移?
    新电脑的正确打开方式——(近万字图文并茂详细分步骤讲解)【包括个性锁屏,磁盘分区……】等你来解锁哦
    Java版分布式微服务云开发架构 Spring Cloud+Spring Boot+Mybatis 电子招标采购系统功能清单
    QT绘制图像QImage-QPixmap-QBitmap-QPicture
    C++ //练习 10.34 使用reverse_iterator逆序打印一个vector。
    微信公众号授权登录后报redirect_uri参数错误的问题
    算法——滑动窗口
    大模型幻觉成应用落地难题 最新评测文心一言解决幻觉能力最好文心一言解决幻觉能力最好 或成产业应用首选
    java 版本企业招标投标管理系统源码+多个行业+tbms+及时准确+全程电子化
    万字长文详解静态图和动态图中的自动求导机制
  • 原文地址:https://blog.csdn.net/weixin_32393347/article/details/126242481