Building the compiler
This document contains detailed information about building the compiler on different systems and with different options.
Building with JIT/OpenCL Backends
By default Glow builds with only the interpreter backend enabled. To enable support for the JIT and/or OpenCL backends, pass additional options to cmake:
OpenCL on Ubuntu
If you decide to use OpenCL, the easiest way is to install portable open source implementation of the OpenCL standard, pocl. Glow relies on pocl to run OpenCL tests on CI. All required steps are outlined in the [install_pocl] (https://github.com/pytorch/glow/blob/master/.circleci/build.sh#L9) method.
Alternatively, you can follow these steps:
- Install necessary packages:
sudo apt-get install ocl-icd-opencl-dev ocl-icd-libopencl1 opencl-headers \ clinfo
Install the appropriate runtime for your CPU/GPU. This will depend on your hardware. If you have an Intel CPU with onboard graphics, you can navigate to Intel's compute-runtime releases page on Github at https://github.com/intel/compute-runtime/releases/ and follow their instructions. You will probably want to choose the latest release and then download and install about ~4 prebuilt packages. At the time of this writing, the prebuilt packages of compute-runtime Release 18.45.11804 ran successfully with Glow on an Intel Core i7-7600U running Ubuntu 16.04.1.
To determine if installation was successful, you can run the following command:
This will display information about your OpenCL platforms and devices (if
found). Lastly, build Glow with the cmake flag
-DGLOW_WITH_OPENCL=ON and run
Supporting multiple targets
The JIT is able to target all environments supported by LLVM. If the
build_llvm.sh script is used to build LLVM for Glow, all the currently stable
architectures will be enabled. If you wish to control which architectures are
built, you can use the
LLVM_TARGETS_TO_BUILD cmake parameter when building
Building with the Sanitizers
The clang-sanitizer project provides a number of libraries which can be used with compiler inserted instrumentation to find a variety of bugs at runtime. These include memory issues due such as use-after-free or double-free. They can also detect other types of problems like memory leaks. Glow can be built with the sanitizers enabled using an additional parameter to cmake.
The following sanitizers are currently configurable:
You can pass one of the above as a value to the cmake parameter
Undefined are special in that they may be
enabled simultaneously by passing
Address;Undefined as the value.
Memory sanitizer can also track the origin of the memory
which can be enabled by using
MemoryWithOrigins instead of
Building with clang-tidy
The clang project provides an additional utility to scan your source code for
possible issues. Enabling
clang-tidy checks on the source code is easy and
can be done by passing an additional cmake parameter during the configure step.
Adding this to the configure step will automatically run clang-tidy on the source tree during compilation. Use the following configuration to enable auto-fix and to enable/disable specific checks:
Building with coverage
Glow uses gcov, lcov, and genhtml to generate coverage reports for the code base. Using this tool allows you to make sure that corner cases are covered with the unit tests as well as keep the unit test coverage at a healthy level. You can generate a coverage report by providing additional options to cmake:
and then invoke
glow_coverage make target.
Building Doxygen documentation
Building documentation can be enabled by passing an additional cmake parameter:
The output will be placed in the
docs/html subdirectory of the build output
Generate dependency graph for cmake targets
Run cmake normally and then execute
dependency_graph target. The
file contains dependencies for all project targets. It might look a bit overwhelming,
in that case you could check