Implementation:Ggml org Llama cpp Common Header
| Knowledge Sources | |
|---|---|
| Domains | API, Infrastructure |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Central header file declaring all shared types, parameter structures, and utility function prototypes used across llama.cpp examples and tools.
Description
This is the foundational header that virtually every file in the common/ library and all example programs include. It defines the common_params mega-struct containing all configurable parameters (model paths, sampling settings, speculative decoding, CPU affinity, LoRA adapters, etc.), along with enums for example types (llama_example), sampler types (common_sampler_type), conversation modes, and grammar trigger types. It declares cpu_params for thread configuration, common_adapter_lora_info for LoRA management, common_time_meas for RAII timing, and provides function declarations for CPU detection, model/context initialization, tokenization, batch helpers, string utilities, and control vector loading.
Usage
Include this header in any llama.cpp tool or example program to access the unified parameter system, type definitions, and utility function declarations.
Code Reference
Source Location
- Repository: Ggml_org_Llama_cpp
- File: common/common.h
- Lines: 1-888
Signature
#pragma once
#include "ggml-opt.h"
#include "llama-cpp.h"
struct common_time_meas {
common_time_meas(int64_t & t_acc, bool disable = false);
~common_time_meas();
const int64_t t_start_us;
int64_t & t_acc;
};
struct common_adapter_lora_info {
std::string path;
float scale;
std::string task_name;
std::string prompt_prefix;
struct llama_adapter_lora * ptr;
};
struct cpu_params {
int n_threads = -1;
bool cpumask[GGML_MAX_N_THREADS] = {false};
bool mask_valid = false;
enum ggml_sched_priority priority = GGML_SCHED_PRIO_NORMAL;
bool strict_cpu = false;
uint32_t poll = 50;
};
enum llama_example { LLAMA_EXAMPLE_BATCHED, ..., LLAMA_EXAMPLE_COUNT };
enum common_sampler_type { COMMON_SAMPLER_TYPE_NONE, ..., COMMON_SAMPLER_TYPE_ADAPTIVE_P };
int32_t cpu_get_num_physical_cores();
int32_t cpu_get_num_math();
Import
#include "common.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| N/A | N/A | N/A | This is a header file; it declares types and function prototypes for use by other translation units |
Outputs
| Name | Type | Description |
|---|---|---|
| common_params | struct | Mega-struct defining all configurable parameters for llama.cpp tools |
| cpu_params | struct | CPU thread configuration including affinity masks and scheduling priority |
| llama_example | enum | Enumeration of all supported example program types |
| common_sampler_type | enum | Enumeration of all available sampling strategies |
| common_time_meas | struct | RAII timer for measuring elapsed time in microseconds |
Usage Examples
#include "common.h"
// Access the unified parameter structure
common_params params;
params.model.path = "path/to/model.gguf";
params.cpuparams.n_threads = 8;
params.sampling.temp = 0.7f;
// Use CPU detection
int physical_cores = cpu_get_num_physical_cores();
// Use RAII timer
int64_t elapsed = 0;
{
common_time_meas timer(elapsed);
// ... timed operation ...
}
printf("Elapsed: %" PRId64 " us\n", elapsed);