Build and Install oneDNN from source

Get FREE domain for 1st year and build your brand new site

OneDNN is a Machine Learning Inference library developed by Intel. It is, often, used by linking to other Machine Learning frameworks like TensorFlow which in turns improves performance on Intel systems.

OneDNN is an open-source project. It was, initially, named as MKLDNN.

Get the source code

Get the latest source code of OneDNN which we will build:

git clone https://github.com/oneapi-src/oneDNN.git
cd oneDNN

Optionally, you can go to a specific point (Tag or commit) instead of building the latest code:

git checkout <tag>

Example:

git checkout v1.0

Define runtime environment

We need to define the environment variable "DNNL_CPU_RUNTIME" to specific the threading backend to be used. There are three specific options:

  • OMP: GCC, Clang, Intel GCC
  • TBB: TBB (libtbb.so)
  • OCL: OpenCL
export DNNL_CPU_RUNTIME=OMP

Other optional environment variables that you may set to customize your OneDNN build are as follows:

  • DNNL_LIBRARY_TYPE: specifies if it is shared or static library
  • DNNL_CPU_RUNTIME: threading run-time like GCC
  • DNNL_GPU_RUNTIME: threading run-time like OpenCL
  • DNNL_BUILD_EXAMPLES: builds example codebase
  • DNNL_BUILD_TESTS: builds test suite of OneDNN
  • DNNL_ARCH_OPT_FLAGS: compiler optimization flags
  • DNNL_ENABLE_CONCURRENT_EXEC: sharing of common scratchpad memory
  • DNNL_ENABLE_JIT_PROFILING: integrates with performance profilers
  • DNNL_ENABLE_PRIMITIVE_CACHE: uses primitive cache
  • DNNL_ENABLE_MAX_CPU_ISA: uses CPU dispatcher controls
  • DNNL_VERBOSE: enables logging
  • DNNL_BLAS_VENDOR: link BLAS library (default: MKL)

Take a look at other environment variables (https://oneapi-src.github.io/oneDNN/dev_guide_build_options.html)

Create build space

We will create a new folder where we will process the building of oneDNN files.

mkdir -p build && cd build

Generate makefile

We will generate the makefile using CMAKE.

cmake ..

If you do not have cmake installed, you can install it using:

sudo apt-get install cmake

Build OneDNN

We will build OneDNN at this point.

make -j16

16 is the number of threads to be utilized. This will make it faster.

Install OneDNN

Once OneDNN has been built, you need to install it using the following command:

make install

Test the build

To test the build, you can run the in-build test suite using the following command:

ctest

If you disabled it, yoy may link it in your C/ C++ code and test it.

#include <dnnl.h>

With this, you have installed the latest or specific build of OneDNN from source. Enjoy.