The ggml_tensor struct
The core data structure is defined in ggml.h:
GGML_MAX_DIMS is 4, so every tensor is at most 4-dimensional. ne[0] is the innermost (fastest-varying) dimension — the number of columns in a matrix.
Data types
ggml_type covers floating-point formats, integer formats, and a large family of quantized types:
ggml_type_name(type) to get a human-readable string, and ggml_is_quantized(type) to test whether a type uses block quantization.
Creating tensors
Tensors are always allocated from aggml_context. The context owns a fixed-size memory buffer; every tensor carves out space from it.
Dimension ordering follows column-major convention:
ne[0] is the number of elements in the fastest-varying (innermost) dimension. For a matrix, ne[0] is columns and ne[1] is rows.Reading and writing values
For CPU-resident tensors the scalar helpers fromggml-cpu.h are the safest way to access individual elements:
tensor->data using the stride fields:
Tensor metadata
Each tensor carries metadata that describes how it was produced:
The
src array lets you walk the computation graph upward:
Contiguous vs strided tensors
ggml supports non-contiguous tensors produced by operations such asggml_transpose, ggml_permute, and ggml_view_*. A tensor is contiguous when its elements are laid out in memory with no gaps and in the expected order.
nb strides and do not assume contiguity. If you need a contiguous copy for an external library, call ggml_cont:
