Convert Figma logo to code with AI

oneapi-src logooneDNN

oneAPI Deep Neural Network Library (oneDNN)

3,577
984
3,577
69

Top Related Projects

185,446

An Open Source Machine Learning Framework for Everyone

82,049

Tensors and Dynamic neural networks in Python with strong GPU acceleration

17,765

Open standard for machine learning interoperability

11,694

Open deep learning compiler stack for cpu, gpu and specialized accelerators

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator

OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

Quick Overview

oneDNN (Deep Neural Network Library) is an open-source performance library for deep learning applications. It provides highly optimized building blocks for deep learning frameworks and applications, focusing on performance optimization for Intel architectures. oneDNN aims to accelerate deep learning workloads across various hardware platforms.

Pros

  • High performance optimizations for Intel CPUs and GPUs
  • Cross-platform support (Linux, Windows, macOS)
  • Extensive API support for various deep learning operations
  • Integration with popular frameworks like TensorFlow and PyTorch

Cons

  • Primarily optimized for Intel hardware, potentially less effective on other architectures
  • Steep learning curve for direct API usage
  • Documentation can be complex for beginners
  • Limited support for some advanced or newer deep learning operations

Code Examples

  1. Creating and initializing a tensor:
#include "oneapi/dnnl/dnnl.hpp"
using namespace dnnl;

memory::dims dims = {2, 3, 4, 5};
auto eng = engine(engine::kind::cpu, 0);
auto tensor = memory({{dims}, memory::data_type::f32, memory::format_tag::nchw}, eng);
  1. Performing a convolution operation:
auto conv_desc = convolution_forward::desc(prop_kind::forward_inference,
    algorithm::convolution_direct, src_md, weights_md, bias_md, dst_md,
    strides, padding_l, padding_r);
auto conv_prim_desc = convolution_forward::primitive_desc(conv_desc, eng);
auto conv = convolution_forward(conv_prim_desc);
  1. Executing a ReLU activation:
auto relu_desc = eltwise_forward::desc(prop_kind::forward_inference,
    algorithm::eltwise_relu, src_md, 0.0f, 0.0f);
auto relu_prim_desc = eltwise_forward::primitive_desc(relu_desc, eng);
auto relu = eltwise_forward(relu_prim_desc);

Getting Started

  1. Install oneDNN:

    git clone https://github.com/oneapi-src/oneDNN.git
    cd oneDNN && mkdir -p build && cd build
    cmake ..
    make
    sudo make install
    
  2. Include oneDNN in your C++ project:

    #include "oneapi/dnnl/dnnl.hpp"
    
    int main() {
        dnnl::engine eng(dnnl::engine::kind::cpu, 0);
        // Your oneDNN code here
        return 0;
    }
    
  3. Compile with oneDNN:

    g++ -std=c++11 your_file.cpp -ldnnl -o your_program
    

Competitor Comparisons

185,446

An Open Source Machine Learning Framework for Everyone

Pros of TensorFlow

  • Comprehensive ecosystem with high-level APIs and tools
  • Extensive community support and resources
  • Flexible deployment options (mobile, web, cloud)

Cons of TensorFlow

  • Steeper learning curve for beginners
  • Can be slower for certain operations compared to oneDNN
  • Larger footprint and resource requirements

Code Comparison

TensorFlow:

import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Dense(64, activation='relu'),
    tf.keras.layers.Dense(10, activation='softmax')
])

oneDNN:

#include "dnnl.hpp"

auto fc1 = dnnl::inner_product_forward::primitive_desc(
    {{64, 784}, dnnl::memory::data_type::f32, dnnl::memory::format_tag::nc},
    {{64, 64}, dnnl::memory::data_type::f32, dnnl::memory::format_tag::nc},
    engine);

oneDNN focuses on low-level performance optimizations for deep learning primitives, while TensorFlow provides a complete framework for building and deploying machine learning models. oneDNN offers fine-grained control over hardware-specific optimizations, whereas TensorFlow abstracts these details for ease of use. TensorFlow is more suitable for end-to-end machine learning workflows, while oneDNN is often used as a backend for other frameworks to enhance performance.

82,049

Tensors and Dynamic neural networks in Python with strong GPU acceleration

Pros of PyTorch

  • Broader scope: PyTorch is a complete deep learning framework, offering a wide range of tools and functionalities
  • Easier to use: PyTorch has a more intuitive API and is generally considered more user-friendly
  • Dynamic computation graphs: Allows for more flexible and dynamic model architectures

Cons of PyTorch

  • Performance: May be slower than oneDNN for certain operations, especially on Intel hardware
  • Memory usage: Can be less memory-efficient compared to oneDNN's optimized implementations
  • Specialization: Less focused on specific hardware optimizations compared to oneDNN's Intel-centric approach

Code Comparison

PyTorch example:

import torch

x = torch.tensor([1, 2, 3])
y = torch.tensor([4, 5, 6])
z = torch.matmul(x, y)

oneDNN example:

#include <dnnl.hpp>

dnnl::memory::dims dims = {3};
auto x = dnnl::memory({dims, dt::f32, tag::x}, eng);
auto y = dnnl::memory({dims, dt::f32, tag::x}, eng);
auto z = dnnl::inner_product_forward::primitive_desc(eng, dims, dims, dims);
17,765

Open standard for machine learning interoperability

Pros of ONNX

  • Broader ecosystem support and compatibility across various frameworks
  • Standardized format for representing machine learning models
  • Extensive tooling for model conversion and optimization

Cons of ONNX

  • Higher-level abstraction, potentially less optimized for specific hardware
  • May require additional runtime or inference engine for execution
  • Limited support for certain specialized or custom operations

Code Comparison

ONNX model definition:

import onnx

node = onnx.helper.make_node(
    'Conv',
    inputs=['x', 'W'],
    outputs=['y'],
    kernel_shape=[3, 3],
    strides=[1, 1],
)

graph = onnx.helper.make_graph(
    [node],
    'test-model',
    [onnx.helper.make_tensor_value_info('x', onnx.TensorProto.FLOAT, [1, 3, 224, 224]),
     onnx.helper.make_tensor_value_info('W', onnx.TensorProto.FLOAT, [16, 3, 3, 3])],
    [onnx.helper.make_tensor_value_info('y', onnx.TensorProto.FLOAT, [1, 16, 222, 222])]
)

model = onnx.helper.make_model(graph)
onnx.save(model, 'conv_model.onnx')

oneDNN convolution operation:

#include "oneapi/dnnl/dnnl.hpp"
using namespace dnnl;

auto engine = engine(engine::kind::cpu, 0);
auto stream = stream(engine);

memory::dims conv_src_tz = {1, 3, 224, 224};
memory::dims conv_weights_tz = {16, 3, 3, 3};
memory::dims conv_dst_tz = {1, 16, 222, 222};
memory::dims conv_strides = {1, 1};
memory::dims conv_padding = {0, 0};

auto conv_src_md = memory::desc({conv_src_tz}, memory::data_type::f32, memory::format_tag::nchw);
auto conv_weights_md = memory::desc({conv_weights_tz}, memory::data_type::f32, memory::format_tag::oihw);
auto conv_dst_md = memory::desc({conv_dst_tz}, memory::data_type::f32, memory::format_tag::nchw);

auto conv_desc = convolution_forward::desc(prop_kind::forward_inference,
    algorithm::convolution_direct, conv_src_md, conv_weights_md, conv_dst_md,
    conv_strides, conv_padding, conv_padding);

auto conv_prim_desc = convolution_forward::primitive_desc(conv_desc, engine);
11,694

Open deep learning compiler stack for cpu, gpu and specialized accelerators

Pros of TVM

  • Broader support for various hardware targets, including GPUs, CPUs, and specialized AI accelerators
  • More flexible and customizable, allowing for end-to-end optimization of deep learning models
  • Stronger focus on automatic optimization and tuning of tensor computations

Cons of TVM

  • Steeper learning curve due to its more complex architecture and broader scope
  • Potentially slower compilation times for simpler models compared to oneDNN's optimized primitives
  • Less mature and battle-tested in production environments than oneDNN

Code Comparison

TVM example (tensor computation):

import tvm
from tvm import te

n = te.var("n")
A = te.placeholder((n,), name="A")
B = te.compute(A.shape, lambda i: A[i] * 2, name="B")
s = te.create_schedule(B.op)

oneDNN example (convolution operation):

#include "oneapi/dnnl/dnnl.hpp"

auto src_md = memory::desc({batch, ic, ih, iw}, memory::data_type::f32, memory::format_tag::nchw);
auto weights_md = memory::desc({oc, ic, kh, kw}, memory::data_type::f32, memory::format_tag::oihw);
auto conv_desc = convolution_forward::desc(prop_kind::forward_inference, algorithm::convolution_direct,
    src_md, weights_md, dst_md, strides, padding_l, padding_r);

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator

Pros of ONNX Runtime

  • Broader support for multiple frameworks (TensorFlow, PyTorch, etc.)
  • Cross-platform compatibility (Windows, Linux, macOS, mobile)
  • Easier integration with existing ML pipelines

Cons of ONNX Runtime

  • May have lower performance for specific Intel hardware
  • Less optimized for deep learning primitives
  • Potentially larger runtime overhead

Code Comparison

oneDNN:

dnnl::memory::desc input_md({N, C, H, W}, dnnl::memory::data_type::f32, dnnl::memory::format_tag::nchw);
dnnl::convolution_forward::desc conv_d(dnnl::prop_kind::forward, dnnl::algorithm::convolution_direct,
    input_md, weights_md, bias_md, output_md, strides, padding_l, padding_r);

ONNX Runtime:

import onnxruntime as ort

session = ort.InferenceSession("model.onnx")
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name
result = session.run([output_name], {input_name: input_data})

oneDNN focuses on low-level optimizations for Intel hardware, providing fine-grained control over deep learning primitives. ONNX Runtime offers a higher-level API for running models across various platforms and frameworks, sacrificing some performance for flexibility and ease of use.

OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.

Pros of OpenBLAS

  • Highly optimized for various CPU architectures, including x86, ARM, and POWER
  • Supports a wide range of BLAS (Basic Linear Algebra Subprograms) operations
  • Lightweight and easy to integrate into existing projects

Cons of OpenBLAS

  • Limited to CPU-based computations, lacking GPU support
  • Primarily focused on BLAS operations, with less emphasis on deep learning primitives
  • May require manual tuning for optimal performance on specific hardware

Code Comparison

OpenBLAS example:

#include <cblas.h>

double x[] = {1, 2, 3, 4};
double y[] = {5, 6, 7, 8};
cblas_daxpy(4, 2.0, x, 1, y, 1);

oneDNN example:

#include <dnnl.hpp>

dnnl::memory::dims dims = {2, 2, 3, 4};
auto src_md = dnnl::memory::desc(dims, dnnl::memory::data_type::f32, dnnl::memory::format_tag::nchw);
auto dst_md = dnnl::memory::desc(dims, dnnl::memory::data_type::f32, dnnl::memory::format_tag::nhwc);
auto relu_d = dnnl::eltwise_forward::desc(dnnl::prop_kind::forward, dnnl::algorithm::eltwise_relu, src_md, 0.0f);

OpenBLAS focuses on basic linear algebra operations, while oneDNN provides more complex deep learning primitives and supports both CPU and GPU computations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

UXL Foundation Logo

oneAPI Deep Neural Network Library (oneDNN)

OpenSSF Best Practices OpenSSF Scorecard

oneAPI Deep Neural Network Library (oneDNN) is an open-source cross-platform performance library of basic building blocks for deep learning applications. oneDNN project is part of the UXL Foundation and is an implementation of the oneAPI specification for oneDNN component.

The library is optimized for Intel(R) Architecture Processors, Intel Graphics, and Arm(R) 64-bit Architecture (AArch64)-based processors. oneDNN has experimental support for the following architectures: NVIDIA* GPU, AMD* GPU, OpenPOWER* Power ISA (PPC64), IBMz* (s390x), and RISC-V.

oneDNN is intended for deep learning applications and framework developers interested in improving application performance on CPUs and GPUs. Deep learning practitioners should use one of the applications enabled with oneDNN.

Table of Contents

Documentation

  • Developer Guide explains the programming model, supported functionality, and implementation details, and includes annotated examples.
  • API Reference provides a comprehensive reference of the library API.

Installation

Binary distribution of this software is available in:

The packages do not include library dependencies and these need to be resolved in the application at build time. See the System Requirements section below and the Build Options section in the Developer Guide for more details on CPU and GPU runtimes.

If the configuration you need is not available, you can build the library from source.

System Requirements

oneDNN supports platforms based on the following architectures:

WARNING

Power ISA (PPC64), IBMz (s390x), and RISC-V (RV64) support is experimental with limited testing validation.

The library is optimized for the following CPUs:

  • Intel 64/AMD64 architecture
    • Intel Atom(R) processor (at least Intel SSE4.1 support is required)
    • Intel Core(TM) processor (at least Intel SSE4.1 support is required)
    • Intel Xeon(R) processor E3, E5, and E7 family (formerly Sandy Bridge, Ivy Bridge, Haswell, and Broadwell)
    • Intel Xeon Scalable processor (formerly Skylake, Cascade Lake, Cooper Lake, Ice Lake, Sapphire Rapids, and Emerald Rapids)
    • Intel Xeon CPU Max Series (formerly Sapphire Rapids HBM)
    • Intel Core Ultra processors (formerly Meteor Lake, Arrow Lake, and Lunar Lake)
    • Intel Xeon 6 processors (formerly Sierra Forest and Granite Rapids)
  • AArch64 architecture
    • Arm Neoverse(TM) N1 and V1 processors

On a CPU based on Intel 64 or on AMD64 architecture, oneDNN detects the instruction set architecture (ISA) at runtime and uses just-in-time (JIT) code generation to deploy the code optimized for the latest supported ISA. Future ISAs may have initial support in the library disabled by default and require the use of run-time controls to enable them. See CPU dispatcher control for more details.

WARNING

On macOS, applications that use oneDNN may need to request special entitlements if they use the hardened runtime. See the Linking Guide for more details.

The library is optimized for the following GPUs:

  • Intel Graphics for 11th-14th Generation Intel Core Processors
  • Intel Iris Xe MAX Graphics (formerly DG1)
  • Intel Arc(TM) graphics (formerly Alchemist)
  • Intel Data Center GPU Flex Series (formerly Arctic Sound)
  • Intel Data Center GPU Max Series (formerly Ponte Vecchio)
  • Intel Graphics and Intel Arc graphics for Intel Core Ultra processors (formerly Meteor Lake, Arrow Lake and Lunar Lake)
  • future Intel Arc graphics (code name Battlemage)

Requirements for Building from Source

oneDNN supports systems meeting the following requirements:

  • Operating system with Intel 64 / Arm 64 / Power / IBMz architecture support
  • C++ compiler with C++11 standard support
  • CMake 2.8.12 or later

The following tools are required to build oneDNN documentation:

Configurations of CPU and GPU engines may introduce additional build time dependencies.

CPU Engine

oneDNN CPU engine is used to execute primitives on Intel Architecture Processors, 64-bit Arm Architecture (AArch64) processors, 64-bit Power ISA (PPC64) processors, IBMz (s390x), and compatible devices.

The CPU engine is built by default but can be disabled at build time by setting DNNL_CPU_RUNTIME to NONE. In this case, GPU engine must be enabled. The CPU engine can be configured to use the OpenMP, TBB or SYCL runtime. The following additional requirements apply:

Some implementations rely on OpenMP 4.0 SIMD extensions. For the best performance results on Intel Architecture Processors we recommend using the Intel C++ Compiler.

On a CPU based on Arm AArch64 architecture, oneDNN CPU engine can be built with Arm Compute Library (ACL) integration. ACL is an open-source library for machine learning applications and provides AArch64 optimized implementations of core functions. This functionality currently requires that ACL is downloaded and built separately. See Build from Source section of the Developer Guide for details. oneDNN only supports Compute Library versions 24.08.1 or later.

GPU Engine

Intel Processor Graphics and Xe Architecture graphics are supported by the oneDNN GPU engine. The GPU engine is disabled in the default build configuration. The following additional requirements apply when GPU engine is enabled:

WARNING

Linux will reset GPU when kernel runtime exceeds several seconds. The user can prevent this behavior by disabling hangcheck for Intel GPU driver. Windows has built-in timeout detection and recovery mechanism that results in similar behavior. The user can prevent this behavior by increasing the TdrDelay value.

WARNING

NVIDIA GPU support is experimental. General information, build instructions, and implementation limitations are available in the NVIDIA backend readme.

WARNING

AMD GPU support is experimental. General information, build instructions, and implementation limitations are available in the AMD backend readme.

Runtime Dependencies

When oneDNN is built from source, the library runtime dependencies and specific versions are defined by the build environment.

Linux

Common dependencies:

  • GNU C Library (libc.so)
  • GNU Standard C++ Library v3 (libstdc++.so)
  • Dynamic Linking Library (libdl.so)
  • C Math Library (libm.so)
  • POSIX Threads Library (libpthread.so)

Runtime-specific dependencies:

Runtime configurationCompilerDependency
DNNL_CPU_RUNTIME=OMPGCCGNU OpenMP runtime (libgomp.so)
DNNL_CPU_RUNTIME=OMPIntel C/C++ CompilerIntel OpenMP runtime (libiomp5.so)
DNNL_CPU_RUNTIME=OMPClangIntel OpenMP runtime (libiomp5.so)
DNNL_CPU_RUNTIME=TBBanyTBB (libtbb.so)
DNNL_CPU_RUNTIME=SYCLIntel oneAPI DPC++ CompilerIntel oneAPI DPC++ Compiler runtime (libsycl.so), TBB (libtbb.so), OpenCL loader (libOpenCL.so)
DNNL_GPU_RUNTIME=OCLanyOpenCL loader (libOpenCL.so)
DNNL_GPU_RUNTIME=SYCLIntel oneAPI DPC++ CompilerIntel oneAPI DPC++ Compiler runtime (libsycl.so), OpenCL loader (libOpenCL.so), oneAPI Level Zero loader (libze_loader.so)

Windows

Common dependencies:

  • Microsoft Visual C++ Redistributable (msvcrt.dll)

Runtime-specific dependencies:

Runtime configurationCompilerDependency
DNNL_CPU_RUNTIME=OMPMicrosoft Visual C++ CompilerNo additional requirements
DNNL_CPU_RUNTIME=OMPIntel C/C++ CompilerIntel OpenMP runtime (iomp5.dll)
DNNL_CPU_RUNTIME=TBBanyTBB (tbb.dll)
DNNL_CPU_RUNTIME=SYCLIntel oneAPI DPC++ CompilerIntel oneAPI DPC++ Compiler runtime (sycl.dll), TBB (tbb.dll), OpenCL loader (OpenCL.dll)
DNNL_GPU_RUNTIME=OCLanyOpenCL loader (OpenCL.dll)
DNNL_GPU_RUNTIME=SYCLIntel oneAPI DPC++ CompilerIntel oneAPI DPC++ Compiler runtime (sycl.dll), OpenCL loader (OpenCL.dll), oneAPI Level Zero loader (ze_loader.dll)

macOS

Common dependencies:

  • System C/C++ runtime (libc++.dylib, libSystem.dylib)

Runtime-specific dependencies:

Runtime configurationCompilerDependency
DNNL_CPU_RUNTIME=OMPIntel C/C++ CompilerIntel OpenMP runtime (libiomp5.dylib)
DNNL_CPU_RUNTIME=TBBanyTBB (libtbb.dylib)

Validated Configurations

CPU engine was validated on RedHat* Enterprise Linux 8 with

on Windows Server* 2019 with

on macOS 11 (Big Sur) with

  • Apple LLVM version 13.0

on Ubuntu 20.04 AArch64 with

GPU engine was validated on Ubuntu* 22.04 with

on Windows Server 2019 with

Applications Enabled with oneDNN

Support

Submit questions, feature requests, and bug reports on the GitHub issues page.

You can also contact oneDNN developers via UXL Foundation Slack using #onednn channel.

Governance

oneDNN project is governed by the UXL Foundation and you can get involved in this project in multiple ways. It is possible to join the AI Special Interest Group (SIG) meetings where the groups discuss and demonstrate work using this project. Members can also join the Open Source and Specification Working Group meetings.

You can also join the mailing lists for the UXL Foundation to be informed of when meetings are happening and receive the latest information and discussions.

Contributing

We welcome community contributions to oneDNN. You can find the oneDNN release schedule and work already in progress towards future milestones in Github's Milestones section. If you are looking for a specific task to start, consider selecting from issues that are marked with the help wanted label.

If you have an idea on how to improve the library:

For additional details, see contribution guidelines. You can also contact oneDNN developers and maintainers via UXL Foundation Slack using #onednn channel.

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

oneDNN is licensed under Apache License Version 2.0. Refer to the "LICENSE" file for the full license text and copyright notice.

This distribution includes third party software governed by separate license terms.

3-clause BSD license:

2-clause BSD license:

Apache License Version 2.0:

Boost Software License, Version 1.0:

MIT License:

This third party software, even if included with the distribution of the Intel software, may be governed by separate license terms, including without limitation, third party license terms, other Intel software license terms, and open source software license terms. These separate license terms govern your use of the third party programs as set forth in the "THIRD-PARTY-PROGRAMS" file.

Security

Security Policy outlines our guidelines and procedures for ensuring the highest level of Security and trust for our users who consume oneDNN.

Trademark Information

Intel, the Intel logo, Arc, Intel Atom, Intel Core, Iris, OpenVINO, the OpenVINO logo, Pentium, VTune, and Xeon are trademarks of Intel Corporation or its subsidiaries.

Arm and Neoverse are trademarks, or registered trademarks of Arm Ltd.

* Other names and brands may be claimed as the property of others.

Microsoft, Windows, and the Windows logo are trademarks, or registered trademarks of Microsoft Corporation in the United States and/or other countries.

OpenCL and the OpenCL logo are trademarks of Apple Inc. used by permission by Khronos.

(C) Intel Corporation