Writing topologies
This page walks through writing a topology document: start from the document structure, reuse vHost and device definitions through imports and templates, expand machine and device counts, and check the result with validate, run --dry-run and graph. The complete field set and defaults are in Topology YAML schema.
Document skeleton
A topology document is always version: 1 and may contain imports, templates, kinds and machines. Unknown fields are errors.
version: 1
imports:
- vhosts/qemu.yaml
- devices/gpu/mi300x.yaml
- devices/pci/qemu-edu.yaml
machines:
- id: m0
vhost: {use: vhost-x86-rocm, memory: 32G}
devices:
- {use: mi300x, count: 2}
- {use: qemu-edu, count: 2}
Each machine's
vhostowns its image,kernel,initrd,cmdlineanddisksfields.cosim schemaprints the JSON Schema of the complete topology format.Resource paths resolve against the workspace root, including executables containing
/, deviceconfigandpci.rom, vHostkernelandinitrd, and diskpathandbacking. A bare executable name is looked up inPATHwhile planning.
Imports and templates
Imports resolve against the importing file, then against the
--resourcesdirectory (defaultresources/); the#templatessuffix is accepted.Imported files contribute templates, kinds and further imports; only the top-level document contributes runnable machines.
useselects a template; mappings merge recursively, sequences are replaced, and explicit values override template values.Import cycles, template cycles, duplicate template or kind names and unknown references are errors; a file reached through several imports is loaded once.
The repository layout convention:
resources/vhosts/andresources/devices/import nothing,resources/machines/imports both, andresources/clusters/imports machine files.
These four configuration directories are siblings under resources/.
samples/ is reserved for programs run after a vHost boots; configuration
files belong under resources/.
Directory |
Responsibility |
|---|---|
|
Define QEMU vHost templates, including runtime CPU, memory, image selection and boot arguments. |
|
Define device models, adapters, PCI properties, ROM references and device memory regions. |
|
Combine one vHost and its devices into a machine. |
|
Compose or expand multiple machines. |
|
Use |
|
Reserve space for guest example programs; the directory migration adds no program runner. |
|
Hold external projects; |
flowchart LR
V[resources/vhosts] --> M[resources/machines]
D[resources/devices] --> M
M --> C[resources/clusters]
Each machine selects a recipe through vhost.image and declares its own
boot arguments and disks. Recipe provision parameters describe the temporary
VM used to build the image. machine.vhost determines QEMU parameters for
the simulation session. See vHost image recipes and
Topology YAML schema for the field contracts.
Machines, devices and count
countexpandsid: m, count: 4intom0tom3; a topology holds at most 4096 machines.Device identifiers default to the
usename or kind plus an index, such asmi300x-0; an explicitidis kept when count is one.Identifiers use 1 to 48 letters, digits, underscores and hyphens; machine, device and disk identifiers must differ in more than ASCII case.
The machine identifier
memoryand the device identifiersvhost,qmpandserialare reserved by the session layout.A machine may not exceed the
max_devicesof its vHost kind;qemu-vhostdeclares 64.placement.agentis parsed and stored only;cosim runrejects remote placement.
vHost and device fields
A vHost declares kind, runtime.binary, runtime.env, memory,
cpus, accel and the QEMU machine. Optional fields include its
image and direct-boot inputs. A device kind selects the launch contract:
kind |
Purpose |
Required fields |
|---|---|---|
|
gem5 MI300X performance model |
|
|
QEMU device exported over vfio-user |
|
Declared device kind |
Custom launch command (extension point) |
|
The complete field tables and adapter contracts are in Topology YAML schema and Device adapters; vHost profiles are in vHost profiles, device kinds in Device catalog.
vHost images and disks
The vhost mapping may select image or declare kernel, initrd
and cmdline directly. It also owns disks and snapshot. The write
mode of a disk follows its declaration:
Declaration |
Behavior |
|---|---|
|
Opens the source image read-only |
|
Writes |
No |
Writes a per-machine qcow2 overlay in the session directory; |
|
Creates a missing |
Several disks referencing one path |
A direct writer cannot share its image with other disks; creation requests must agree on size and format |
The authoritative vHost and disk field descriptions are in Topology YAML schema.
Validating, previewing and running
# Check structure, identifiers and memory layout; --assets also checks local files
just run-cli validate resources/machines/gpu-8.yaml --assets
# Print executables, arguments, environment, readiness probes, memory layout and disk targets
just run-topology resources/machines/mixed-models.yaml --dry-run
# Print a Mermaid graph of machines and vfio-user edges
just run-cli graph resources/clusters/cluster-4x8.yaml
# Print the JSON Schema of the format
just run-cli schema
# Start a session
just run-topology resources/machines/single-gpu.yaml
validatechecks the topology,run --dry-runprints image state and the execution plan, andgraphprints topology relationships. None starts simulation processes.--assetsand a real session start check that files such asruntime.binary,configandpci.romexist.Starting a session requires Linux glibc and
setpriv; other systems use the development container, see Development container.
Sources and evidence
Parsing and validation:
crates/cosim-topology/src/raw.rs,crates/cosim-topology/src/resolve.rs,crates/cosim-topology/src/model.rs.Planning and layout:
crates/cosim-topology/src/layout.rs,crates/cosim-runtime/src/plan.rs.Command entry point and options:
crates/cosim-cli/src/main.rs.Runnable samples:
resources/machines/,resources/clusters/.