Skip to main content
1

Clone the repository

2

Install Python dependencies (optional)

Some examples require Python tooling to download model weights. Skip this step if you only want to build the library.
3

Build with CMake

Compiled binaries are placed in build/bin/.
4

Run the simple example

The simple-ctx example performs a matrix multiplication using the CPU backend.
Expected output:

Working examples

The two simple examples demonstrate the two main APIs.
This example allocates a context that owns tensor data, builds a matrix multiplication graph, and executes it on the CPU.
simple-ctx.cpp
Key points:
  • ggml_init() creates a context that owns tensor memory (no_alloc = false).
  • ggml_new_tensor_2d() allocates a tensor inside the context.
  • ggml_mul_mat() records the operation in the graph — no computation yet.
  • ggml_graph_compute_with_ctx() executes the graph on the CPU.
  • ggml_free() releases the entire context and all its tensors.