from_source.rst 7.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
..  Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

..    http://www.apache.org/licenses/LICENSE-2.0

..  Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

18 19 20 21
.. _install-from-source:

Install from Source
===================
22
This page gives instructions on how to build and install the TVM package from
23 24
scratch on various systems. It consists of two steps:

25
1. First build the shared library from the C++ codes (`libtvm.so` for linux, `libtvm.dylib` for macOS and `libtvm.dll` for windows).
26 27
2. Setup for the language packages (e.g. Python Package).

28
To get started, clone TVM repo from github. It is important to clone the submodules along, with ``--recursive`` option.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

.. code:: bash

    git clone --recursive https://github.com/dmlc/tvm

For windows users who use github tools, you can open the git shell, and type the following command.

.. code:: bash

   git submodule init
   git submodule update


Build the Shared Library
------------------------

Our goal is to build the shared libraries:

- On Linux the target library are `libtvm.so, libtvm_topi.so`
48
- On macOS the target library are `libtvm.dylib, libtvm_topi.dylib`
49 50 51 52 53 54
- On Windows the target library are `libtvm.dll, libtvm_topi.dll`


.. code:: bash

    sudo apt-get update
55
    sudo apt-get install -y python python-dev python-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake
56 57 58 59 60 61

The minimal building requirements are

- A recent c++ compiler supporting C++ 11 (g++-4.8 or higher)
- CMake 3.5 or higher
- We highly recommend to build with LLVM to enable all the features.
62 63
- It is possible to build TVM without the LLVM dependency if you only want to use CUDA/OpenCL
- If you want to use the NNVM compiler, then LLVM is required
64 65

We use cmake to build the library.
66
The configuration of TVM can be modified by `config.cmake`.
67 68


69
- First, check the cmake in your system. If you do not have cmake,
70 71 72 73 74 75 76 77 78 79
  you can obtain the latest version from `official website <https://cmake.org/download/>`_
- First create a build directory, copy the ``cmake/config.cmake`` to the directory.

  .. code:: bash

      mkdir build
      cp cmake/config.cmake build

- Edit ``build/config.cmake`` to customize the compilation options

80
  - On macOS, for some versions of Xcode, you need to add ``-lc++abi`` in the LDFLAGS or you'll get link errors.
81 82
  - Change ``set(USE_CUDA OFF)`` to ``set(USE_CUDA ON)`` to enable CUDA backend. So do other backends and libraries
    (OpenCL, RCOM, METAL, VULKAN, ...).
83 84 85 86 87

- TVM optionally depends on LLVM. LLVM is required for CPU codegen that needs LLVM.

  - LLVM 4.0 or higher is needed for build with LLVM. Note that verison of LLVM from default apt may lower than 4.0.
  - Since LLVM takes long time to build from source, you can download pre-built version of LLVM from
88
    `LLVM Download Page <http://releases.llvm.org/download.html>`_.
89 90 91 92 93


    - Unzip to a certain location, modify ``build/config.cmake`` to add ``set(USE_LLVM /path/to/your/llvm/bin/llvm-config)``
    - You can also directly set ``set(USE_LLVM ON)`` and let cmake search for a usable version of LLVM.

94
  - You can also use `LLVM Nightly Ubuntu Build <https://apt.llvm.org/>`_
95 96 97 98 99 100 101 102 103 104 105 106

    - Note that apt-package append ``llvm-config`` with version number.
      For example, set ``set(LLVM_CONFIG llvm-config-4.0)`` if you installed 4.0 package

- We can then build tvm and related libraries.

  .. code:: bash

      cd build
      cmake ..
      make -j4

107
If everything goes well, we can go to :ref:`python-package-installation`
108 109 110 111 112 113

Building on Windows
~~~~~~~~~~~~~~~~~~~

TVM support build via MSVC using cmake. The minimum required VS version is **Visual Studio Community 2015 Update 3**.
In order to generate the VS solution file using cmake,
114
make sure you have a recent version of cmake added to your path and then from the TVM directory:
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

.. code:: bash

  mkdir build
  cd build
  cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES="Release" ..

This will generate the VS project using the MSVC 14 64 bit generator.
Open the .sln file in the build directory and build with Visual Studio.
In order to build with LLVM in windows, you will need to build LLVM from source.
You need to run build the nnvm by running the same script under the nnvm folder.

Building ROCm support
~~~~~~~~~~~~~~~~~~~~~

Currently, ROCm is supported only on linux, so all the instructions are written with linux in mind.

- Set ``set(USE_ROCM ON)``, set ROCM_PATH to the correct path.
- You need to first install HIP runtime from ROCm. Make sure the installation system has ROCm installed in it.
- Install latest stable version of LLVM (v6.0.1), and LLD, make sure ``ld.lld`` is available via command line.

136 137
.. _python-package-installation:

138 139 140
Python Package Installation
---------------------------

141 142 143 144
TVM package
~~~~~~~~~~~

The python package is located at `tvm/python`
145
There are two ways to install the package:
146

147 148 149 150
Method 1
   This method is **recommended for developers** who may change the codes.

   Set the environment variable `PYTHONPATH` to tell python where to find
151 152
   the library. For example, assume we cloned `tvm` on the home directory
   `~`. then we can added the following line in `~/.bashrc`.
153
   The changes will be immediately reflected once you pull the code and rebuild the project (no need to call ``setup`` again)
154 155 156

   .. code:: bash

157 158
       export TVM_HOME=/path/to/tvm
       export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/topi/python:$TVM_HOME/nnvm/python:${PYTHONPATH}
159 160


161
Method 2
162
   Install TVM python bindings by `setup.py`:
163 164 165 166 167 168 169 170 171 172 173 174 175

   .. code:: bash

       # install tvm package for the current user
       # NOTE: if you installed python via homebrew, --user is not needed during installaiton
       #       it will be automatically installed to your user directory.
       #       providing --user flag may trigger error during installation in such case.
       export MACOSX_DEPLOYMENT_TARGET=10.9  # This is required for mac to avoid symbol conflicts with libstdc++
       cd python; python setup.py install --user; cd ..
       cd topi/python; python setup.py install --user; cd ../..
       cd nnvm/python; python setup.py install --user; cd ../..


176 177 178 179 180 181
Python dependencies
~~~~~~~~~~~~~~~~~~~
   * Necessary dependencies:

   .. code:: bash

MORINAGA committed
182
       pip install --user numpy decorator attrs
183 184 185 186 187 188 189 190 191 192 193 194

   * If you want to use RPC Tracker

   .. code:: bash

       pip install --user tornado

   * If you want to use auto-tuning module

   .. code:: bash

       pip install --user tornado psutil xgboost
195 196 197 198 199 200
       
   * If you want to parse Relay text format progams, you must use Python 3 and run the following

   .. code:: bash

       pip install --user mypy orderedset antlr4-python3-runtime
201 202


203 204 205 206 207 208 209
Install Contrib Libraries
-------------------------

.. toctree::
   :maxdepth: 1

   nnpack