Skip to content

Instantly share code, notes, and snippets.

@vmlinz
Created May 4, 2015 11:17
Show Gist options
  • Save vmlinz/e38f77de3e7694787b3b to your computer and use it in GitHub Desktop.
Save vmlinz/e38f77de3e7694787b3b to your computer and use it in GitHub Desktop.

Notes for building Torch7 for Android

Since I am familiar with Ubuntu Linux, I followed the tutorial using Ubuntu 14.04 64 desktop to build and test Torch7 for Android.

Refer the readme file for Torch7 for Android and the official Torch7 getting started.

The Torch7 project is easy to build following the official guide but the torch-android project is poorly maintained and not well documented, so I wrote this document as a note.

Requirements

  • Ubuntu 12.04 64(Ubuntu 14.04 64)
  • Android NDK(r9c or r10d, I am using r10d and successfully get the android demo in the end)
  • Android SDK(install at least one sdk platform, I am uisng api 19)
  • Prebuilt torch7
  • Add NDK and SDK to path

Build and install Torch7

Follow the getting stared documentation of Torch.

Install dependencies

curl -sk https://raw.githubusercontent.com/torch/ezinstall/master/install-deps | bash
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; ./install.sh

Adds torch to PATH

On Linux
source ~/.bashrc
On OSX
source ~/.profile

Test if torch is installed

luarocks list
th

Build Torch7 for Android

Requirements

  • Using the development system as we install the Torch7
  • Torch7 is successfully installed following the prior document
  • Install ipython using sudo apt-get install ipython if it is not installed

Build Torch7 for Android

  • clone the torch-android repo: git clone https://github.com/soumith/torch-android ~/Projects/torch-android
  • Add SDK, NDK path in Ubuntu: i.e, export PATH=/opt/android-sdk-linux/tools/:/opt/android-sdk-linux/platform-tools/, export PATH=~/bin:/opt/android-sdk-linux_x86/tools/:/opt/android-ndk-rxy, refer to setting up the android development environment
  • export ANDROID_NDK to your ndk root, i.e, export ANDROID_NDK=~/ndk
  • goto torch-android repo root and run sh build.sh
  • move static libraries to torch-android/lib, run find . -name "*.a" | xargs cp -t lib
  • copy the libgomp.a to torch-android/lib, i.e, cp ~/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/lib/libgomp.a lib/. You need to goto the ndk installation and find the libgomp.a then copy it to torch-android/lib. See the issue 4
  • Now we have built the torch-android environment and we can proceed to build the demo

Build android-demo

  • Make sure you have gone through the prior setting ups correctly
  • Goto the android-demo directory of the torch-android repo
  • Update the project settings using android update project -p . -t 1, you can get a list of targets using android list target and select one of the target as the parameter for the -t of the previous command
  • Make sure you have android sdk and android ndk in path
  • run sh build.sh in the demo directory to make the android demo and run on your connected device

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment