Implementation:Ggml org Ggml Zendnn backend api
Metadata
| Field | Value |
|---|---|
| Page Type | Implementation (API Doc) |
| Knowledge Sources | GGML |
| Domains | ML_Infrastructure, Tensor_Computing, CPU_Computing |
| Last Updated | 2025-05-15 12:00 GMT |
Overview
Public C header declaring the ZenDNN backend interface for running tensor operations on AMD CPUs using the AMD ZenDNN optimized library.
Description
ggml-zendnn.h declares the ZenDNN backend's public API (22 lines). It provides four functions:
ggml_backend_zendnn_init: Initializes and returns a ZenDNN backend instance. Takes no parameters; it uses the default AMD CPU configuration.ggml_backend_is_zendnn: Type-checks whether a given backend handle is a ZenDNN backend.ggml_backend_zendnn_set_n_threads: Configures the number of threads used for ZenDNN operations. This allows tuning parallelism based on the available CPU cores.ggml_backend_zendnn_reg: Returns the backend registration handle for the auto-discovery system.
All functions are marked with GGML_BACKEND_API and wrapped in extern "C" for C++ compatibility.
ZenDNN is AMD's optimized library for deep learning primitives on Zen-architecture CPUs, providing hardware-specific optimizations for operations like matrix multiplication, convolution, and normalization.
Usage
Include this header to use the ZenDNN backend on AMD Zen-architecture CPUs. The backend is typically discovered automatically by ggml_backend_load_all() when built with ZenDNN support.
Code Reference
Source Location
GGML repo, file: include/ggml-zendnn.h (22 lines).
Signatures
GGML_BACKEND_API ggml_backend_t ggml_backend_zendnn_init(void);
GGML_BACKEND_API bool ggml_backend_is_zendnn(ggml_backend_t backend);
GGML_BACKEND_API void ggml_backend_zendnn_set_n_threads(ggml_backend_t backend_zendnn, int n_threads);
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_zendnn_reg(void);
Import
#include "ggml-zendnn.h"
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
| (none for init) | -- | -- | ggml_backend_zendnn_init takes no parameters.
|
backend |
ggml_backend_t |
Yes | Backend handle for type checking (for ggml_backend_is_zendnn).
|
backend_zendnn |
ggml_backend_t |
Yes | ZenDNN backend handle for thread configuration. |
n_threads |
int |
Yes | Number of threads to use for ZenDNN operations. |
Outputs
| Output | Type | Description |
|---|---|---|
| Backend handle | ggml_backend_t |
Initialized ZenDNN backend, or NULL on failure.
|
| Type check | bool |
true if the backend is ZenDNN-based.
|
| Registration | ggml_backend_reg_t |
Registration handle for backend auto-discovery. |
Usage Examples
#include "ggml-zendnn.h"
// Initialize the ZenDNN backend
ggml_backend_t backend = ggml_backend_zendnn_init();
if (backend && ggml_backend_is_zendnn(backend)) {
// Configure threading for optimal performance on AMD CPU
ggml_backend_zendnn_set_n_threads(backend, 8);
// Use with scheduler like any other backend
ggml_backend_sched_t sched = ggml_backend_sched_new(
&backend, NULL, 1, GGML_DEFAULT_GRAPH_SIZE, false);
ggml_backend_sched_graph_compute(sched, graph);
ggml_backend_sched_free(sched);
ggml_backend_free(backend);
}