xref: /aosp_15_r20/external/pytorch/scripts/build_tizen.sh (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1#!/usr/bin/env bash
2##############################################################################
3#  Example command to build the Tizen target (RPi3).
4##############################################################################
5#
6# This script shows how one can build a Caffe2 binary for a Tizen device (RPi3).
7# The build is essentially much similar to a host build, with one additional change
8# which is to specify -mfpu=neon for optimized speed.
9
10setup_environment(){
11# The rootfs image for a Tizen target (RPi3)is located at the below webpage:
12# http://download.tizen.org/releases/milestone/tizen/4.0.m1/tizen-unified_20170529.1/images/
13# If you do not have a Tizen device, Please, run qemu-arm-static and chroot command.
14# $ sudo chroot ~/tizen-rootfs qemu-arm-static /usr/bin/bash
15
16CAFFE2_ROOT="$( cd "$(dirname -- "$0")"/.. ; pwd -P)"
17echo "Caffe2 codebase root is: $CAFFE2_ROOT"
18BUILD_ROOT=${BUILD_ROOT:-"$CAFFE2_ROOT/build"}
19mkdir -p $BUILD_ROOT
20echo "Build Caffe2 Tizen into: $BUILD_ROOT"
21}
22
23caffe2_lite_dep_packages(){
24# Obtain necessary dependencies
25# You can set-up a rpm repository with zypper, yum, and dnf because Tizen
26# software platform officially support rpm format such as Fedora, OpenSUSE.
27# The official Tizen repository is as following:
28# http://download.tizen.org/releases/milestone/tizen/4.0.m1/
29echo "Installing dependencies."
30sudo zypper install \
31  make \
32  strace \
33  cmake \
34  gcc* \
35  binutils \
36  glibc* \
37  cpp \
38  protobuf-devel \
39  libstdc++*
40}
41
42caffe2_lite_build(){
43# Now, actually build the android target.
44echo "Building caffe2"
45cd $BUILD_ROOT
46
47# Note: add more dependencies above if you need libraries such as leveldb, lmdb, etc.
48# If you have to disable a specific package due to a package absence
49# from https://git.tizen.org/cgit/, append -Dxxx_xxx=OFF option before executing cmake.
50cmake .. \
51    -DCMAKE_VERBOSE_MAKEFILE=1 \
52    -DUSE_GFLAGS=OFF  \
53    -DUSE_GLOG=OFF -DUSE_NNPACK=OFF \
54    -DRUN_HAVE_STD_REGEX=0 \
55    -DRUN_HAVE_POSIX_REGEX=0 \
56    -DHAVE_GNU_POSIX_REGEX=0 \
57    -DUSE_MPI=OFF -DUSE_OPENMP=OFF \
58    -DBUILD_PYTHON=OFF \
59    -DUSE_GLOO=OFF \
60    -DUSE_OPENCV=OFF \
61    -DCAFFE2_CPU_FLAGS="-mfpu=neon -mfloat-abi=soft" \
62    || exit 1
63
64make -j`nproc` || exit 1
65}
66
67caffe2_full_dep_packages(){
68# Obtain necessary dependencies
69# You can set-up a rpm repository with zypper, yum, and dnf because Tizen
70# software platform officially support rpm format such as Fedora, OpenSUSE.
71# The official Tizen repository is as following:
72# http://download.tizen.org/releases/milestone/tizen/4.0.m1/
73echo "Installing dependencies."
74sudo zypper install \
75  cmake \
76  libgflags-dev \
77  libgoogle-glog-dev \
78  libprotobuf-dev \
79  protobuf-compiler
80
81# Obtain optional dependencies that are usually useful to have.
82echo "Installing optional dependencies."
83sudo zypper install \
84  libpython-dev \
85  python-numpy \
86  python-pip \
87  python-protobuf
88
89# Obtain python hypothesis, which Caffe2 uses for unit testing. Note that
90# the one provided by zypper is quite old so we install it via pip
91sudo pip install hypothesis
92}
93
94caffe2_full_build(){
95# Now, actually build the android target.
96echo "Building caffe2"
97cd $BUILD_ROOT
98
99# Note: add more dependencies above if you need libraries such as leveldb, lmdb, etc.
100# If you have to disable a specific package due to a package absence
101# from https://git.tizen.org/cgit/, append -Dxxx_xxx=OFF option before executing cmake.
102cmake "$CAFFE2_ROOT" \
103    -DCMAKE_VERBOSE_MAKEFILE=1 \
104    -DUSE_CUDA=OFF \
105    -DUSE_ITT=OFF \
106    -DUSE_OPENCV=OFF \
107    -DCAFFE2_CPU_FLAGS="-mfpu=neon -mfloat-abi=soft" \
108    || exit 1
109
110make -j`nproc` || exit 1
111}
112
113#### Main
114# Setup a build environment to compile Caffe2 deeplearning framework in Tizen platform.
115setup_environment
116# There are two build options to support 'full' version and 'lite' version (by default).
117caffe2_lite_dep_packages
118caffe2_lite_build
119