Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions cpu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
title: CPU and AVX
short_title: CPU
description: CPU and AVX support in ND4J/Deeplearning4j
layout: default
redirect_from: "/cpu"
---

# ND4J - CPU (nd4j-native) AVX Configuration

### What is AVX, and why does it matter?

AVX (Advanced Vector Extensions) is a set of CPU instructions for accelerating numerical computations. See [Wikipedia](https://en.wikipedia.org/wiki/Advanced_Vector_Extensions) for more details.

Note that AVX only applies to nd4j-native (CPU) backend for x86 devices, not GPUs and not ARM/PPC devices.

Why AVX matters: performance. You want to use the version of ND4J compiled with the highest level of AVX supported by your system.


AVX support for different CPUs - summary:
* Most modern x86 CPUs: AVX2 is supported
* Some high-end server CPUs: AVX512 may be supported
* Old CPUs (pre 2012) and low power x86 (Atom, Celeron): No AVX support (usually)

AVX is backward compatible, so for example it's possible run a generic x86 or AVX2 binary on a system supporting AVX512.
However it is not possible to run

Note on current snapshots (and in future releases, after 1.0.0-beta5) you may get a warning as follows, if AVX is not configured optimally:
```
o.n.l.c.n.CpuNDArrayFactory - *********************************** CPU Feature Check Warning ***********************************
o.n.l.c.n.CpuNDArrayFactory - Warning: Initializing ND4J with Generic x86 binary on a CPU with AVX/AVX2 support
o.n.l.c.n.CpuNDArrayFactory - Using ND4J with AVX/AVX2 will improve performance. See deeplearning4j.org/cpu for more details
o.n.l.c.n.CpuNDArrayFactory - Or set environment variable ND4J_IGNORE_AVX=true to suppress this warning
o.n.l.c.n.CpuNDArrayFactory - ************************************************************************************************
```


### Configuring AVX in ND4J/DL4J

As noted earlier, for best performance you should use the version of ND4J that matches your CPU's supported AVX level.

ND4J defaults configuration (when just including the nd4j-native or nd4j-native-platform dependencies without maven classifier configuration):
* 1.0.0-beta5 and earlier: "generic x86" (no AVX) is the default for nd4j/nd4j-platform dependencies
* Current snapshots and later versions of ND4J: AVX2 is the default


To configure AVX2 and AVX512, you need to specify a classifier for the appropriate architecture.

The following binaries (nd4j-native classifiers) are provided for x86 architectures:
* Generic x86 (no AVX): `linux-x86_64`, `windows-x86_64`, `macosx-x86_64`
* AVX2: `linux-x86_64-avx2`, `windows-x86_64-avx2`, `macosx-x86_64-avx2`
* AVX512: `linux-x86_64-avx512`


**Example: Configuring AVX2 on Windows (Maven pom.xml)**
```
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>${nd4j.version}</version>
</dependency>

<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>${nd4j.version}</version>
<classifier>windows-x86_64-avx2</classifier>
</dependency>
```


**Example: Configuring AVX512 on Linux (Maven pom.xml)**
```
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>${nd4j.version}</version>
</dependency>

<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>${nd4j.version}</version>
<classifier>linux-x86_64-avx512</classifier>
</dependency>
```

Note that you need *both* nd4j-native dependencies - with and without the classifier.