Modules
Optional modules are not part of the default library. They are loaded only when named in VECMAT_MODULES. Public modules live in the vecmat-vendors repository. The recommended layout is a vendors/ checkout under this tree. That checkout may be a git submodule; it is optional. If the repository is checked out elsewhere, pass its path in VECMAT_MODULES_PATH. Private modules are loaded the same way from their own tree.
The loader accepts four kinds: backend, width, feature, and device. A missing module.cmake, or any other kind, is Unknown Vecmat module.
Kinds
| Kind | What it does | Lists it appends |
|---|---|---|
backend | Registers a complete _ptr table with vm_. A schedule. | VECMAT_MODULE_HOOKS, register includes and calls. |
width | Overrides a slot on a core width such as fp16. Does not fill vm_. | That width's lists (VECMAT_FP16_MODULE_HOOKS, ...). |
feature | Domain helpers. Contributes sources and headers. Does not register. | VECMAT_MODULE_HOOKS (sources), optionally test/bench sources. Not the register lists. |
device | GPU, NPU, or accelerator. Registers with vm_. | Its own library. Not VECMAT_MODULE_HOOKS or a backend register list. |
A backend owns identity, extra HWCAP bits, and the tuned kernels. There is no vm_cpu_part() in the base library: the backend probes, then registers VM_. A width module does not register a backend. The core owns the storage type; the module only overrides a slot. See doc/. Backend and width headers are standalone include/vecmat_*.h files.
A feature module contributes sources via VECMAT_MODULE_HOOKS (the same hook the float object libraries call) and may append VECMAT_MODULE_TEST_SOURCES / VECMAT_MODULE_BENCH_SOURCES. It must not append to a backend or width register list. Its public header is include/vecmat/feature/<name>.h, included as <vecmat/feature/<name>.h>.
Layout
A module is a directory with module.cmake. Under the recommended layout that is vendors/<vendor>/<name>/. module.cmake is the only file the top-level build includes. It must set VECMAT_MODULE_KIND. Use CMAKE_CURRENT_LIST_DIR for its own sources.
A backend module:
vendors/arm/cortex-a5x ├── doc │ └── cortex-a5x.md ├── include │ └── vecmat_cortex_a5x.h ├── module.cmake └── src ├── a5x.h ├── gemm_a53.c ├── gemm_a55.c ├── probe.c ├── register.c └── sched.c
A width module:
vendors/arm/fp16 ├── doc │ └── fp16.md ├── include │ └── vecmat_arm_fp16.h ├── module.cmake └── src ├── arm_fp16.h ├── neon.c ├── probe.c └── register.c
A feature module:
vendors/alkontek/spectral-graph ├── doc │ └── spectral-graph.md ├── include │ └── vecmat │ └── feature │ └── spectral_graph.h ├── module.cmake └── src ├── bitset.c ├── laplacian.c └── unrank.c
Callers include that header as <vecmat/feature/spectral_graph.h>.
A device module is a GPU, NPU, or accelerator. It uses the device API (vm_). It does not fill vm_, and it must not append VECMAT_MODULE_HOOKS or a backend register list. It builds its own library.
nvidia/ga10x:
vendors/nvidia/ga10x ├── doc │ └── ga10x.md ├── include │ └── vecmat_nvidia_ga10x.h ├── module.cmake └── src ├── ga10x.cu └── register.c
module.cmake sets device and builds vecmat_nvidia_ga10x. The module's register function calls vm_.
Build
Empty VECMAT_MODULES is the default. With vendors/ checked out under this tree:
cmake -S . -B build -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DVECMAT_MODULES=arm/fp16 \ -DVECMAT_RUNTIME_DISPATCH=ON cmake --build build
If the modules are elsewhere, add -DVECMAT_MODULES_PATH=../vecmat-vendors. VECMAT_MODULES entries are paths relative to vendors/ (or to each VECMAT_MODULES_PATH root). A private vendors tree is the same.
module.cmake appends, depending on kind:
backend:VECMAT_MODULE_HOOKS(called fromvecmat_add_float_objects, once per float width),VECMAT_MODULE_REGISTER_INCLUDES,VECMAT_MODULE_REGISTER_CALLS, and optionallyVECMAT_MODULE_TEST_HOOKS,VECMAT_MODULE_TEST_SOURCES,VECMAT_MODULE_BENCH_SOURCES.width: the lists for the width it implements (VECMAT_FP16_MODULE_HOOKS,VECMAT_FP16_MODULE_REGISTER_CALLS). Those lists are consumed only by that width's object lib. The module's ownmodule.cmakeerrors if that width's switch is off. A width module must not append to the backend lists; the loader rejects that.feature:VECMAT_MODULE_HOOKS, and optionallyVECMAT_MODULE_TEST_HOOKS,VECMAT_MODULE_TEST_SOURCES,VECMAT_MODULE_BENCH_SOURCES. Not the backend or width register lists.device: its own library, and optionally the test and bench lists. NotVECMAT_MODULE_HOOKSand not a backend register list. The loader rejects those lists. Width lists stay with width modules.
Test and bench sources live in the vendor tree. The mains do not include a module header. VECMAT_MODULE_TEST_HOOKS runs after the test targets exist and may add the public include dir. Do not define a module macro in the test mains.
Dispatch model
Bits are probed facts. vm_ sets one flat bit per CPU capability (VM_, VM_, VM_, ...). Levels are what a kernel file was compiled to need. VM_ is VM_; the others, VM_ included, are one bit. A direct-call kernel runs only when vm_cpu_has(level) sees every bit. A file built with -mfma must gate on a level that includes FMA, except AVX-512, where FMA is implied (every AVX-512F CPU has FMA3; a hypervisor that hides it is unsupported). The vm_soa3_* AVX2 file is also exempt because it disables contraction and emits no FMA, so it checks plain VM_.
Bits sit in per-family ranges of the 32-bit vm_. The values are C11 enum constants, so they stay within bits 0..30; bit 31 is unused. Placeholders are commented in cpu.h and not probed yet. VM_, VM_, VM_, VM_, VM_, VM_, and VM_ are features, not tiers.
| Bits | Family | Mask | Defined | Reserved placeholders |
|---|---|---|---|---|
| 0..3 | generic | VM_ | SCALAR 0, BACKEND 1 | bits 2, 3 reserved |
| 4..15 | x86 | VM_ | AVX 4, AVX2 5, AVX512F 6, FMA 10, F16C 11, AVX512BW 12, AVX512VL 13, AVX512BF16 14 | AVX10 7, AMX 8, ACE 9 |
| 16..23 | ARM | VM_ | NEON 16, SVE 17, SVE2 18, ARM_FP16 21, ARM_BF16 22, I8MM 23 | SME 19, SME2 20 |
| 24..30 | RISC-V | VM_ | none | RVV 24, ZVFH 25, ZVBB 26 |
AVX10.1 is the AVX-512 set, so its probe will set VM_; VM_CPU_AVX10_2 is for everything beyond that baseline (AVX10.2 and later).
AMX is a feature, not a tier, and Linux needs the arch_prctl opt-in before tile use.
ACE (AI Compute Extensions, v1) is the future standard matrix acceleration (outer-product tiles under a new AMX palette, AVX10 inputs, OCP MX formats with block scaling); a bit is reserved for it. Compare masks with the VM_CPU_* names, never stored numbers.
Tiers come from one ladder. vm_ walks a table of {level, tier} rows in priority order (SVE2, SVE, NEON, AVX-512F, AVX2, AVX); the first level fully present wins, else scalar. Without FMA, AVX2 falls to AVX.
Backends are code that targets a level, plus an optional microarchitecture match in their own register hook; a registered backend still wins. A richer backend descriptor may come later.
RISC-V Vector (RVV) will be one new bit (VM_CPU_RVV, bit 24) and one VM_LEVEL_RVV row in the ladder.
GPUs, NPUs, and accelerators use the device API (vm_), never a CPU feature bit or a vm_ table.
Backend registration
The base library keeps this surface for backends:
vm_/backend_ register() VM_— a registered table winsCPU_ BACKEND vm_— copy a compiled ISA table and override slots. NEON, SVE, and SVE2 are provided. Returns NULL if that ISA was not compiled.backend_ builtin() vm_/cpu_ set_ note() vm_— one extra banner line, printed only if setcpu_ note() vm_backend_modules_register()— test and benchmark hook, generated, not a library exportVECMAT_FORCE_ISA— override the ISA bound for the table-dispatched_ptrset (vec4, mat4, quat, GEMM ukernel) throughvm_, when no backend is registered and that ISA is compiled in. By design, it does not reach the direct-call kernels (cpu_ selected_ features() vm_array_*,vm_,axpy vm_,rsqrt_ array vm_soa3_*,vm_batch3_*,vm_eos_*_n, and the SIMDvm_sph_*kernels): they test the rawvm_mask on each callcpu_ runtime_ features()
Tests and benchmarks do not include a backend header. They call the generated hook, then vm_:
vm_backend_modules_register(); vm_cpu_init(); if (vm_cpu_note()) printf("%s\n", vm_cpu_note());
With no backends selected, the generated function is empty. A backend that does not match the CPU returns 0 and leaves the builtin table in place. A registered backend wins over VECMAT_FORCE_ISA. The same pointer is idempotent. A table with a missing slot is rejected. VM_ is 8.
The descriptor:
| Field | Role |
|---|---|
name | Stable string. vm_ returns it when this backend is selected. |
features | VM_ if the schedule is not itself an ISA bit. |
priority | Higher wins among registered backends. |
ops | Complete vm_. Must outlive the process. |
Copy the builtin table, then replace the slots this schedule owns. vm_ is NULL when NEON was not compiled.
const vm_backend_ops *builtin = vm_backend_builtin(VM_CPU_NEON); ops = *builtin; ops.vm_gemm_ukernel = my_ukernel; ops.quat_mul_ptr = my_quat_mul; backend.name = "my-backend"; backend.features = VM_CPU_BACKEND; backend.priority = 100; backend.ops = &ops; vm_cpu_set_note("backend my-backend part=..."); return vm_backend_register(&backend);
Floats interfaces and ABI
vm_gemm_ukernel is the 8×8 tile, including when a backend is registered. vm_ rejects (8, 8). The core also has a scalar 4×4 tile and, when those kernels are compiled, an AVX2 12×8 tile and an AVX-512 16×14 tile. With no backend, AVX-512 selects 16×14 and AVX2 selects 12×8. Another shape uses vm_. See Numerics extras.
Float symbols are width-suffixed. Internal functions that both object libs define need the same treatment.
A vendor float entry point uses VECMAT_. It pastes 32 or 64 with the same rule as include/: VECMAT_ABI_BITS when the library object sets it, otherwise VECMAT_USE_F64, otherwise 32.
When ABI 32 is also built, the f64 object libraries define VECMAT_ABI_REPLICA. Integer bodies compile when it is unset and are skipped on that replica. A function that takes or returns vm_ stays outside the guard and uses VECMAT_.
The
string(APPEND VECMAT_MODULE_REGISTER_INCLUDES "#include <vecmat_cortex_a5x.h>\n") string(APPEND VECMAT_MODULE_REGISTER_CALLS " vm_cortex_a5x_register();\n")
The header rename (vm_cortex_a5x_register to vm_cortex_a5x_register64 on an f64 TU) happens because the generated file includes that header and the test target defines VECMAT_USE_F64.
Adding a module
- Add
vendors/<vendor>/<name>/withmodule.cmake,include/,src/, anddoc/<name>.md. - In
module.cmake, setVECMAT_MODULE_KINDtobackend,width,feature, ordevice. - Append the lists for that kind. Do not add an
#ifdeftotest/test_main.cortest/bench_main.c. - For a
feature: put the public header atinclude/vecmat/feature/<name>.hand appendVECMAT_MODULE_HOOKS. Do not append a backend or width register list. - For a backend: probe in the module, not in
src/. Build the ops table fromfeatures/ cpu.c vm_plus overrides. Passbackend_ builtin() VM_unless the schedule is one of the existing ISA bits. The public header staysCPU_ BACKEND include/vecmat_*.h. - For a
device: setVECMAT_MODULE_KINDtodevice, build a separate library, and do not appendVECMAT_MODULE_HOOKSor a backend register list. Register withvm_. Do not filldevice_ register vm_. Seebackend_ ops nvidia/ga10x. - Document the register call and any
VECMAT_FORCE_*knobs in the module's own doc.