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
Optionally, you can go to a specific point (Tag or commit) instead of building the latest code:
git checkout <tag>
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
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
We will generate the makefile using CMAKE.
If you do not have cmake installed, you can install it using:
sudo apt-get install cmake
We will build OneDNN at this point.
16 is the number of threads to be utilized. This will make it faster.
Once OneDNN has been built, you need to install it using the following command:
Test the build
To test the build, you can run the in-build test suite using the following command:
If you disabled it, yoy may link it in your C/ C++ code and test it.
With this, you have installed the latest or specific build of OneDNN from source. Enjoy.