Skip to content

Guide · Open source

How to use ggml: build the tensor library from source

Updated · written with AI from the project's own documentation and checked against our catalogue data

ggml is an open-source tensor library that provides the low-level math behind machine learning models, written in plain C and C++ with no outside dependencies. This guide walks through cloning the repository and building it with CMake, and explains which kinds of projects it suits. By the end you will know how to get a working build and whether ggml fits what you are doing.

ggmlggml-org/ggml · ★ 15.6k · MIT

Quick start

  1. 1Clone the repository. Run git clone https://github.com/ggml-org/ggml and change into the ggml folder.
  2. 2Create a build folder. Run mkdir build && cd build inside the project to keep build files separate from the source.
  3. 3Configure with CMake. Run cmake .. from the build folder to generate the build files.
  4. 4Build in Release mode. Run cmake --build . --config Release -j 8 to compile the library.
  5. 5Open the minimal example. Read examples/simple to see a commented matrix multiplication program.

What ggml is and who it is for

ggml is a tensor library, meaning it supplies the building blocks for the number crunching inside machine learning models. It is a foundation for other software rather than a finished end-user tool, and its README describes a library, not an application.

It is aimed at C/C++ developers who want to embed machine learning math in their own program, and at engineers running models on modest or unusual hardware such as ARM, RISC-V, or WebAssembly targets.

  • Good fit: C/C++ developers embedding ML math into their own programs
  • Good fit: low-level control over memory and quantized number formats
  • Good fit: learning how tensor libraries work under the hood
  • Poor fit: running a chatbot or model without writing code
  • Poor fit: Python-first data science, since the README shows only C/C++ build steps

What do you need before you install ggml?

The build uses CMake and requires a C/C++ compiler. The README lists no other prerequisites, and the library has no outside dependencies of its own.

  • CMake
  • A C/C++ compiler

How to build ggml from source

Clone the repository, create a build folder, configure the project with CMake, then build in Release mode. The README uses -j 8 to run eight parallel jobs; you can change that number to suit your machine.

git clone https://github.com/ggml-org/ggml cd ggml mkdir build && cd build cmake .. cmake --build . --config Release -j 8

Where to start with a first example

The README points to a minimal, fully commented example that performs matrix multiplication. It is the simplest way to see how ggml code is structured before writing your own program.

For background, the project documentation includes a page on the GGUF file format, an introduction to ggml on Hugging Face, and a community tips and tricks wiki.

  • examples/simple in the repository: a commented matrix multiplication example
  • docs/gguf.md: the GGUF file format
  • GGML tips & tricks wiki, hosted with llama.cpp

What ggml can do

ggml is designed to be simple, portable, and efficient, with minimal setup. It targets many CPU types and includes SIMD-optimised kernels for x86, ARM, and RISC-V. The README also lists backend support for CPU, GPU, NPU, and browser, plus 2- to 8-bit integer quantization and MXFP4 and NVFP4 microscaling formats.

It allocates no memory at runtime, which gives you control over memory use.

  • Plain C/C++ with no dependencies
  • Cross-platform: x86, ARM, RISC-V, LoongArch, PowerPC, s390x, WebAssembly
  • Backends: CPU, GPU, NPU, browser
  • Quantized formats from 2 to 8 bits, plus MXFP4 and NVFP4

Where to send changes to ggml

The README asks contributors to open pull requests for changes to the core ggml library, including the CMake build system, in the llama.cpp repository instead. The README says this makes a PR more visible, better tested, and more likely to be reviewed.

What people use it for

  • Embedding tensor math into a C or C++ application
  • Running machine learning workloads on ARM, RISC-V, or WebAssembly targets
  • Experimenting with quantized, lower-precision number formats
  • Studying how a tensor library is built under the hood

Frequently asked questions

Is ggml free to use?

ggml is released under the MIT licence, as shown in the project's badge. The MIT licence is a permissive open-source licence; check the repository's licence file for the exact terms.

What do I need to install ggml?

You need CMake and a C/C++ compiler. The build is done by cloning the repository and running the CMake commands shown in the README.

Can I run a chatbot with ggml?

Not directly. The README describes ggml as a library, not an application, so it does not provide a ready-made chatbot. It is a foundation that other software can be built on.

Does ggml have a Python interface?

The README shows only C/C++ build steps and does not describe a Python interface. Python-first users should look at tools with Python APIs.

How does ggml compare to llama.cpp?

The README names llama.cpp as the place to open changes to core ggml, and lists it among comparable projects. ggml is the lower-level tensor library, while llama.cpp is a project built with this kind of foundation.

What other projects are similar to ggml?

The README lists llama.cpp, PyTorch, TensorFlow, and ONNX Runtime as comparable projects. PyTorch and TensorFlow offer higher-level, Python-friendly APIs, which may suit users who do not want to write C/C++.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

ggml suits C/C++ developers who want lightweight, dependency-free machine learning math and control over memory and quantized formats, especially on unusual hardware. If you want to run a model without writing code, or you need a stable high-level or Python API, pick a higher-level project such as PyTorch, TensorFlow, or ONNX Runtime instead.

Install options & downloads