Skip to content

📷 Share PyTorch binaries built for Raspberry Pi and Jetson.

Notifications You must be signed in to change notification settings

mheriyanto/pytorch-binaries

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pre-built LibTorch for ARM32/64 Systems

The pre-built package is https://github.com/wangkuiyi/pytorch-rpi and https://github.com/ljk53/pytorch-rpi.

NVIDIA Jetson Nano

Alternative 1

The steps to build it include:

  1. Log in to an NVIDIA Jetson Nano.
  2. Operating System: Ubuntu 18.04 for a recent Python.
  3. Install Clang with sudo apt install -y clang.
  4. Set environment variables:
    export USE_CUDA=1
    export USE_CUDNN=1
    export MAX_JOBS=4
    export USE_NNPACK=0
    export USE_QNNPACK=0
    export USE_PYTORCH_QNNPACK=0
    export BUILD_CAFFE2_OPS=0
    export USE_MKLDNN=0
    export USE_OPENCV=0
  5. Run ./build_libtorch.sh to build and pack the zip file.

Alternative 2

The steps to get libtorch.so with GNU C++ compiler:

  1. Visit Nvidia forum here. Download PyTorch what do you want, for example PyTorch v1.7.0 (Python 3.6 - torch-1.7.0-cp36-cp36m-linux_aarch64.whl)
  2. Follow command below:
    $ sudo apt install python3-pip 
    $ sudo pip3 install torch-1.7.0-cp36-cp36m-linux_aarch64.whl
    $ pip3 show torch    # to check path of the installed torch 
  3. After installation, check libtorch.so in path:
    $ cd /usr/local/lib/python3.6/dist-packages/torch/lib/      # that's consistent with output of command above
    $ ls
  4. Sett CMakeLists.txt like below
    set(CMAKE_PREFIX_PATH "/usr/local/lib/python3.6/dist-packages/torch")
    find_package(Torch REQUIRED)
    if (Torch_FOUND)
        message(STATUS "Torch library found!")
        message(STATUS "    include path: ${TORCH_INCLUDE_DIRS}" \n)
    else ()
        message(FATAL_ERROR "Could not locate Torch" \n)
    endif()

Alternative 3

The steps to get libtorch.so with Clang C++ compiler:

  1. Visit Qengineering repo here. Download PyTorch what do you want, for example PyTorch v1.7.0 (Python 3.6 - torch-1.7.0a0-cp36-cp36m-linux_aarch64.whl and torchvision-0.8.1a0+45f960c-cp36-cp36m-linux_aarch64.whl)

  2. Follow command below:

    $ sudo apt install python3-pip 
    $ sudo pip3 install torch-1.7.0a0-cp36-cp36m-linux_aarch64.whl
    $ sudo pip3 install torchvision-0.8.1a0+45f960c-cp36-cp36m-linux_aarch64.whl
    $ pip3 show torch    # to check path of the installed torch 
  3. After installation, check libtorch.so in path:

    $ cd /usr/local/lib/python3.6/dist-packages/torch/lib/      # that's consistent with output of command above
    $ ls
    $ export CC=/usr/bin/clang
    $ export CXX=/usr/bin/clang++
  4. Comment script in TorchConfig.cmake in file torch/share/cmake/Torch/

    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
       #set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0")
    endif()
  5. Sett CMakeLists.txt like below

    set(CMAKE_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=1")
    set(CMAKE_PREFIX_PATH "/usr/local/lib/python3.6/dist-packages/torch")
    find_package(Torch REQUIRED)
    if (Torch_FOUND)
        message(STATUS "Torch library found!")
        message(STATUS "    include path: ${TORCH_INCLUDE_DIRS}" \n)
    else ()
        message(FATAL_ERROR "Could not locate Torch" \n)
    endif()

NVIDIA Drive PX2

The steps to build it include:

  1. Log in to an NVIDIA Drive PX2 computer.
  2. Upgrade the system from Ubuntu 16.04 to Ubuntu 18.04 for a recent Python.
  3. Install Clang with sudo apt install -y clang.
  4. Set environment variables:
    export USE_CUDA=0
    export USE_QNNPACK=0
    export USE_PYTORCH_QNNPACK=0
  5. Run ./build_libtorch.sh to build and pack the zip file.

Raspberry Pi (32-bit)

  1. Install the latest Raspberry Pi OS (32-bit).
  2. Run sudo apt update && sudo apt upgrade.
  3. Run git clone git@github.com:ljk53/pytorch-rpi && cd pytorch-rpi.
  4. Run LIBTORCH_VARIANT=armv7l-cxx11-abi-shared-without-deps ./build_libtorch.sh.

Raspberry Pi (64-bit)

  1. Install the latest 64-bit Ubuntu 20.04 for Raspberry Pi.
  2. Run sudo apt update && sudo apt upgrade.
  3. Run git clone git@github.com:ljk53/pytorch-rpi && cd pytorch-rpi.
  4. Run MAX_JOBS=2 LIBTORCH_VARIANT=aarch64-cxx11-abi-shared-without-deps ./build_libtorch.sh. Note: set the max number of concurrent build jobs to 2 to avoid running out of the RAM.

References

About

📷 Share PyTorch binaries built for Raspberry Pi and Jetson.

Topics

Resources

Stars

Watchers

Forks

Languages

  • Shell 100.0%