For the complete documentation index, see llms.txt. This page is also available as Markdown.

cuDNN

cuDNN integration — installation, configuration, and performance benefits

What Is cuDNN?

cuDNN (CUDA Deep Neural Network library) is NVIDIA's GPU-accelerated library for deep learning primitives. It provides highly optimized implementations of convolutions, pooling, batch normalization, dropout, and RNN operations that are faster than the generic CUDA implementations used by default.

DL4J integrates cuDNN via an optional helper module. When cuDNN is available on the classpath and cuDNN is installed on the host, DL4J uses it automatically for supported layer types without any change to the model definition.

Supported Layers

The following DL4J layer types benefit from cuDNN acceleration:

  • ConvolutionLayer (2D convolution)

  • SubsamplingLayer (pooling)

  • BatchNormalization

  • Dropout

  • LocalResponseNormalization

  • LSTM

Layers without cuDNN support fall back to the standard CUDA implementation automatically.

Maven Dependency

Add the cuDNN helper module alongside the CUDA ND4J backend:

<!-- CUDA ND4J backend (required) -->
<dependency>
    <groupId>org.nd4j</groupId>
    <artifactId>nd4j-cuda-11.6-platform</artifactId>
    <version>1.0.0-M2.1</version>
</dependency>

<!-- cuDNN helper module -->
<dependency>
    <groupId>org.deeplearning4j</groupId>
    <artifactId>deeplearning4j-cuda-11.6</artifactId>
    <version>1.0.0-M2.1</version>
</dependency>

The deeplearning4j-cuda-11.6 module does not bundle the cuDNN library itself — it provides the Java bridge that DL4J uses to call cuDNN. The actual cuDNN shared library must be installed separately on the host.

Installing cuDNN

Download cuDNN from the NVIDIA Developer Portal:

https://developer.nvidia.com/cudnn

An NVIDIA Developer account is required. Select the cuDNN version compatible with your installed CUDA version:

CUDA Version
Supported cuDNN Versions

11.6

8.x

11.2

8.x

10.2

7.6+

Linux Installation

Windows Installation

Copy the cuDNN DLLs to the CUDA bin directory:

Copy headers to:

Using the JavaCPP Presets (Alternative)

For CUDA 11.x, cuDNN can be bundled via the JavaCPP Presets for CUDA, which include the cuDNN shared libraries as Maven/Gradle dependencies. This avoids a system-level installation but requires accepting the NVIDIA license:

Available classifiers: linux-x86_64-redist, windows-x86_64-redist, macosx-x86_64-redist.

Verifying cuDNN Is Loaded

After adding the dependency and installing cuDNN, run any inference or training call that exercises a supported layer. If cuDNN is NOT available, you will see:

If cuDNN is loaded successfully, no warning is logged. You can confirm programmatically:

AlgoMode Configuration

cuDNN supports multiple convolution algorithms with different speed/memory tradeoffs. DL4J exposes this via ConvolutionLayer.AlgoMode:

PREFER_FASTEST (default)

Uses the fastest cuDNN algorithm, determined by a benchmark run. This typically gives the best throughput but can use a lot of workspace memory.

NO_WORKSPACE

Uses algorithms that do not require cuDNN workspace memory. Slower than PREFER_FASTEST, but avoids the large memory allocations that can cause out-of-memory errors on GPUs with limited VRAM.

Use NO_WORKSPACE when you see errors like:

USER_SPECIFIED

Allows you to specify a particular cuDNN algorithm by index. This is an advanced option for users who have benchmarked specific algorithms on their hardware:

Performance Impact

The performance improvement from cuDNN depends on the model architecture, batch size, and GPU. As a rough guide:

Layer Type
Expected Speedup (vs. plain CUDA)

ConvolutionLayer (large kernels)

2x–5x

ConvolutionLayer (3x3, many channels)

1.5x–3x

LSTM

2x–4x

BatchNormalization

1.5x–2x

SubsamplingLayer (pooling)

1.3x–2x

These are estimates; actual speedup varies with GPU model, batch size, and input dimensions.

Troubleshooting

java.lang.UnsatisfiedLinkError at startup

The cuDNN shared library is not on the library search path. On Linux, add the CUDA lib directory to LD_LIBRARY_PATH:

On Windows, ensure the CUDA bin directory is on PATH.

CUDNN_STATUS_NOT_INITIALIZED

The cuDNN version installed does not match what the deeplearning4j-cuda-* module was compiled against. Verify that the cuDNN major version matches the deeplearning4j-cuda-* artifact you are using.

Out-of-memory errors with PREFER_FASTEST

Switch to NO_WORKSPACE mode or reduce batch size. Alternatively, increase the off-heap memory limit:

cuDNN not used even after adding dependency

Make sure the deeplearning4j-cuda-* version exactly matches the nd4j-cuda-* and deeplearning4j-core version. A version mismatch will prevent the helper from loading.

Last updated

Was this helpful?