ggml
C tensor computation library for ML inference and training. Use when working with ggml graphs, GGUF model files, backend scheduling, quantization, or implementing low-level ML ops in C/C++.
Best use case
ggml is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
C tensor computation library for ML inference and training. Use when working with ggml graphs, GGUF model files, backend scheduling, quantization, or implementing low-level ML ops in C/C++.
Teams using ggml should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/ggml/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How ggml Compares
| Feature / Agent | ggml | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
C tensor computation library for ML inference and training. Use when working with ggml graphs, GGUF model files, backend scheduling, quantization, or implementing low-level ML ops in C/C++.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# ggml
## Overview
ggml is a minimalistic C tensor computation library powering llama.cpp and many other ML inference engines. It provides:
- A define-and-run computation graph model (similar to TensorFlow 1.x)
- CPU, CUDA, Metal, Vulkan, and other hardware backends
- 41+ quantization formats (Q4_0, Q8_0, Q5_K, NVFP4, etc.)
- GGUF binary file format for model weights and metadata
- Automatic differentiation and AdamW/SGD optimizers
- Zero runtime allocations — all memory is pre-reserved
**Version:** v0.9.11
**Language:** C (C++ optional)
**License:** MIT
**Repo:** https://github.com/ggml-org/ggml
## Quick Start
```c
#include "ggml.h"
#include "ggml-cpu.h"
#include "ggml-backend.h"
int main(void) {
struct ggml_init_params params = {
.mem_size = 64 * 1024 * 1024, // 64 MB scratch buffer
.mem_buffer = NULL,
.no_alloc = false,
};
struct ggml_context * ctx = ggml_init(params);
struct ggml_tensor * a = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 4);
struct ggml_tensor * b = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 4);
struct ggml_tensor * c = ggml_add(ctx, a, b);
struct ggml_cgraph * gf = ggml_new_graph(ctx);
ggml_build_forward_expand(gf, c);
ggml_backend_t backend = ggml_backend_cpu_init();
ggml_backend_graph_compute(backend, gf);
ggml_backend_free(backend);
ggml_free(ctx);
return 0;
}
```
## Core Concepts
- **ggml_context** — memory pool that owns all tensors; freed all at once
- **ggml_tensor** — N-D array (max 4 dims); stores type, shape, strides, and a data pointer
- **ggml_cgraph** — lazy computation graph; ops are recorded then executed via a backend
- **ggml_backend_t** — execution engine (CPU, CUDA, Metal, …); use `ggml_backend_load_all()` to discover available hardware
- **ggml_backend_sched_t** — multi-device scheduler that splits a graph across backends automatically
- **GGUF** — binary model format: metadata key-value store + packed tensor data
## API Reference
| Domain | File | Description |
|--------|------|-------------|
| Context, tensors & graphs | [api-core.md](references/api-core.md) | Init, create tensors, graph ops, scalar access, constants |
| Arithmetic & matrix ops | [api-arithmetic.md](references/api-arithmetic.md) | add/mul/matmul, reductions, loss functions, quantize |
| Activations, norms & shapes | [api-activations.md](references/api-activations.md) | relu/gelu/silu, RMS norm, reshape/permute/concat, custom ops |
| Attention, convolution & RoPE | [api-attention.md](references/api-attention.md) | Flash Attention, RoPE variants, 1D/2D/3D conv, pooling, padding |
| Backend, memory & scheduler | [api-backend.md](references/api-backend.md) | Backends, buffer types, scheduler, gallocr, CPU threadpool, F16 conversions |
| GGUF file format | [api-gguf.md](references/api-gguf.md) | Read/write GGUF v3: KV metadata, tensor layout, serialization |
| Optimization & training | [api-optimization.md](references/api-optimization.md) | Datasets, AdamW/SGD optimizer, epoch loop, ggml_opt_fit |
| Working examples | [workflows.md](references/workflows.md) | Quick start, GGUF loading, multi-backend, attention, training, quantize |
## Common Workflows
See [references/workflows.md](references/workflows.md) for complete examples.
Quick reference:
- **Tensor computation on CPU** → workflows.md#quick-start
- **Load GGUF model** → workflows.md#load-a-gguf-model-file
- **Multi-backend (CPU+GPU)** → workflows.md#multi-backend-inference-cpu--gpu
- **Transformer attention** → workflows.md#transformer-attention-block
- **Train a model** → workflows.md#simple-linear-layer-training-adamw
- **Quantize weights** → workflows.md#quantize-model-weights
- **Write GGUF file** → workflows.md#write-a-gguf-file
- **Custom operator** → workflows.md#custom-operator
- **Load GGUF from FILE pointer** → workflows.md#load-gguf-from-file-pointer
## Key Considerations
- **Memory is pre-allocated** — choose `mem_size` generously; `ggml_init` fails silently if too small
- **Dimensions are reversed** — `ne[0]` is the innermost (fastest) dimension; for a `[rows × cols]` matrix use `ne0=cols`, `ne1=rows`
- **Graph building does not execute** — operations are recorded lazily; call `ggml_backend_graph_compute()` to run
- **Backend discovery** — call `ggml_backend_load_all()` at startup; use `ggml_backend_init_best()` to pick the best available device
- **Quantized matmul** — `ggml_mul_mat` supports mixed precision (e.g. Q4_0 weights × F32 activations) natively
- **Inplace variants** — `ggml_add_inplace` overwrites tensor `a` and avoids an allocation; only safe when `a` is not used elsewhere in the graph
- **Thread count** — default is 4 threads; use `ggml_backend_cpu_set_n_threads()` or a custom threadpoolRelated Skills
rocm
AMD ROCm GPU computing stack for HIP kernel development and GPU-accelerated library usage. Use when: writing HIP kernels (.hip files), using rocBLAS/rocFFT/rocRAND/rocSOLVER/rocSPARSE/hipBLAS/hipBLASLt/hipTensor/hipSPARSELt/rocALUTION compute libraries, profiling with rocProfiler or rocprof, porting CUDA code to HIP, building CMake/Makefile projects targeting AMD GPUs, using HIP Graphs for low-overhead kernel replay, or debugging GPU code with rocGDB.
powergridmodel
Python library for steady-state distribution power system analysis (power flow, state estimation, short-circuit calculations). Use when working with the power-grid-model library to: (1) perform load flow or Newton-Raphson/iterative calculations on electrical grids, (2) run state estimation with sensor data, (3) compute IEC 60909 short-circuit currents, (4) execute batch/time-series or N-1 contingency simulations, or (5) work with grid component types (node, line, transformer, source, sym_load, etc.) and numpy structured arrays.
pandapower
Power systems analysis and optimization library (pandapower v3.4.0). Use when working with electric power networks: building network models (buses, lines, transformers, loads, generators), running AC/DC power flow, optimal power flow (OPF), short circuit calculations (IEC 60909), state estimation, time series simulations, network topology analysis, or visualizing power grids in Python.
opencl
OpenCL SDK (Khronos Group) for cross-platform GPU/CPU parallel computing in C and C++. Use when writing OpenCL kernels, managing devices/contexts/queues, allocating and transferring buffers or images, building and executing programs, or using the C++ wrapper (opencl.hpp / cl::CommandQueue, cl::Buffer, cl::KernelFunctor). Covers OpenCL C API, C++ bindings, and SDK utility libraries (OpenCLUtils, OpenCLSDK).
ollama
Run and manage local LLMs via Ollama REST API — text generation, chat completions, embeddings, tool calling, structured output, and model management. Use when code imports ollama, references localhost:11434, or user asks about local LLM inference.
llamacpp
Complete llama.cpp C/C++ API reference covering model loading, inference, text generation, embeddings, chat, tokenization, sampling, batching, KV cache, LoRA adapters, and state management. Triggers on: llama.cpp questions, LLM inference code, GGUF models, local AI/ML inference, C/C++ LLM integration, "how do I use llama.cpp", API function lookups, implementation questions, troubleshooting llama.cpp issues, and any llama-cpp or ggerganov/llama.cpp mentions.
greycat
Build, run, and edit GreyCat projects. GreyCat is a statically-typed language plus runtime for graph-persistent, time-series-aware applications. Use when reading or writing `.gcl` source, when the user mentions GreyCat / project.gcl / nodeTime / nodeList / nodeIndex / nodeGeo / @expose / @library, or when the task involves running `greycat <command>`, deploying a project, or reasoning about gcdata/, lib/, files/, webroot/.
greycat-c
GreyCat C API and GCL Standard Library reference. Use for: (1) Native C development with gc_machine_t context, tensors, objects, memory management, crypto, I/O; (2) GCL Standard Library modules - std::core (Date/Time/Tuple/geospatial types), std::runtime (Scheduler/Task/Logger/User/Security/System/OpenAPI/MCP), std::io (CSV/JSON/XML/HTTP/Email/FileWalker), std::util (Queue/Stack/SlidingWindow/Gaussian/Histogram/Quantizers/Random/Plot); (3) Plugin development patterns - lifecycle hooks, type configuration, nativegen, module-level and type-level function linking, global state, thread safety, conditional logging. Keywords: GreyCat, GCL, native functions, tensors, task automation, scheduler, plugin development.
cuda
NVIDIA CUDA parallel computing platform — use when writing .cu kernels, using cuBLAS/cuDNN/cuFFT/cuSPARSE/cuRAND/cuSolver, Thrust, or Cooperative Groups for GPU-accelerated computing
blas_lapack
Complete CBLAS and LAPACKE C API reference (LAPACK v3.12.1) covering 1284 functions for numerical linear algebra: BLAS Level 1/2/3 vector and matrix operations, linear system solvers (LU, Cholesky, LDL), eigenvalue/eigenvector computation, singular value decomposition, least squares, QR/LQ factorizations, and auxiliary routines. Triggers on: BLAS/LAPACK questions, CBLAS/LAPACKE code, linear algebra in C/C++, matrix operations, numerical computing, scientific computing, HPC, linking BLAS/LAPACK.
skill-creator
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.
swe-cli-skills
Senior engineer CLI expertise for AI agents — workflows, safety guardrails, gotchas, and anti-patterns across cloud, IaC, containers, databases, dev tools, and platforms