{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%%shell\n# Installs the latest dev build of TVM from PyPI. If you wish to build\n# from source, see https://tvm.apache.org/docs/install/from_source.html\npip install apache-tvm --pre" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Cross Compilation and RPC\n**Author**: [Ziheng Jiang](https://github.com/ZihengJiang/), [Lianmin Zheng](https://github.com/merrymercy/)\n\nThis tutorial introduces cross compilation and remote device\nexecution with RPC in TVM.\n\nWith cross compilation and RPC, you can **compile a program on your\nlocal machine then run it on the remote device**. It is useful when\nthe remote device resource are limited, like Raspberry Pi and mobile\nplatforms. In this tutorial, we will use the Raspberry Pi for a CPU example\nand the Firefly-RK3399 for an OpenCL example.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Build TVM Runtime on Device\n\nThe first step is to build the TVM runtime on the remote device.\n\n
All instructions in both this section and the next section should be\n executed on the target device, e.g. Raspberry Pi. We assume the target\n is running Linux.
Now we go back to the local machine, which has a full TVM installed\n (with LLVM).
To run this tutorial with a real remote device, change :code:`local_demo`\n to False and replace :code:`target` in :code:`build` with the appropriate\n target triple for your device. The target triple which might be\n different for different devices. For example, it is\n :code:`'llvm -mtriple=armv7l-linux-gnueabihf'` for Raspberry Pi 3B and\n :code:`'llvm -mtriple=aarch64-linux-gnu'` for RK3399.\n\n Usually, you can query the target by running :code:`gcc -v` on your\n device, and looking for the line starting with :code:`Target:`\n (Though it may still be a loose configuration.)\n\n Besides :code:`-mtriple`, you can also set other compilation options\n like:\n\n * -mcpu=
Raspberry Pi does not support OpenCL, the following code is tested on\n Firefly-RK3399. You may follow this [tutorial](https://gist.github.com/mli/585aed2cec0b5178b1a510f9f236afa2)\n to setup the OS and OpenCL driver for RK3399.\n\n Also we need to build the runtime with OpenCL enabled on rk3399 board. In the TVM\n root directory, execute