xref: /aosp_15_r20/external/pytorch/scripts/build_raspbian.sh (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1*da0073e9SAndroid Build Coastguard Worker#!/bin/bash
2*da0073e9SAndroid Build Coastguard Worker##############################################################################
3*da0073e9SAndroid Build Coastguard Worker# Example command to build the Raspbian target.
4*da0073e9SAndroid Build Coastguard Worker##############################################################################
5*da0073e9SAndroid Build Coastguard Worker#
6*da0073e9SAndroid Build Coastguard Worker# This script shows how one can build a Caffe2 binary for raspbian. The build
7*da0073e9SAndroid Build Coastguard Worker# is essentially much similar to a host build, with one additional change
8*da0073e9SAndroid Build Coastguard Worker# which is to specify -mfpu=neon for optimized speed.
9*da0073e9SAndroid Build Coastguard Worker
10*da0073e9SAndroid Build Coastguard WorkerCAFFE2_ROOT="$( cd "$(dirname -- "$0")"/.. ; pwd -P)"
11*da0073e9SAndroid Build Coastguard Workerecho "Caffe2 codebase root is: $CAFFE2_ROOT"
12*da0073e9SAndroid Build Coastguard WorkerBUILD_ROOT=${BUILD_ROOT:-"$CAFFE2_ROOT/build"}
13*da0073e9SAndroid Build Coastguard Workermkdir -p $BUILD_ROOT
14*da0073e9SAndroid Build Coastguard Workerecho "Build Caffe2 raspbian into: $BUILD_ROOT"
15*da0073e9SAndroid Build Coastguard Worker
16*da0073e9SAndroid Build Coastguard Worker# obtain dependencies.
17*da0073e9SAndroid Build Coastguard Workerecho "Installing dependencies."
18*da0073e9SAndroid Build Coastguard Workersudo apt-get install \
19*da0073e9SAndroid Build Coastguard Worker  cmake \
20*da0073e9SAndroid Build Coastguard Worker  libgflags-dev \
21*da0073e9SAndroid Build Coastguard Worker  libgoogle-glog-dev \
22*da0073e9SAndroid Build Coastguard Worker  libprotobuf-dev \
23*da0073e9SAndroid Build Coastguard Worker  libpython-dev \
24*da0073e9SAndroid Build Coastguard Worker  python-pip \
25*da0073e9SAndroid Build Coastguard Worker  python-numpy \
26*da0073e9SAndroid Build Coastguard Worker  protobuf-compiler \
27*da0073e9SAndroid Build Coastguard Worker  python-protobuf
28*da0073e9SAndroid Build Coastguard Worker# python dependencies
29*da0073e9SAndroid Build Coastguard Workersudo pip install hypothesis
30*da0073e9SAndroid Build Coastguard Worker
31*da0073e9SAndroid Build Coastguard Worker# Now, actually build the raspbian target.
32*da0073e9SAndroid Build Coastguard Workerecho "Building caffe2"
33*da0073e9SAndroid Build Coastguard Workercd $BUILD_ROOT
34*da0073e9SAndroid Build Coastguard Worker
35*da0073e9SAndroid Build Coastguard Worker# Note: you can add more dependencies above if you need libraries such as
36*da0073e9SAndroid Build Coastguard Worker# leveldb, lmdb, etc.
37*da0073e9SAndroid Build Coastguard Workercmake "$CAFFE2_ROOT" \
38*da0073e9SAndroid Build Coastguard Worker    -DCMAKE_VERBOSE_MAKEFILE=1 \
39*da0073e9SAndroid Build Coastguard Worker    -DCAFFE2_CPU_FLAGS="-mfpu=neon -mfloat-abi=hard" \
40*da0073e9SAndroid Build Coastguard Worker    || exit 1
41*da0073e9SAndroid Build Coastguard Worker
42*da0073e9SAndroid Build Coastguard Worker# Note: while Raspberry pi has 4 cores, running too many builds in parallel may
43*da0073e9SAndroid Build Coastguard Worker# cause out of memory errors so we will simply run -j 2 only.
44*da0073e9SAndroid Build Coastguard Workermake -j 2 || exit 1
45