Implementation:Ggml org Ggml Virtgpu codegen
| File Name | src/ggml-virtgpu/regenerate_remoting.py
|
| Repository | ggml-org/ggml |
| Lines | 332 |
| Language | Python |
| Domain Tags | Code_Generation, VirtGPU, Build_Tools |
| Status | Active |
| Last Updated | 2025-05-15 12:00 GMT |
| Knowledge Sources | ggml-org/ggml repository |
Overview
regenerate_remoting.py is a Python code generator that reads ggmlremoting_functions.yaml and regenerates the three .gen.h header files for the remoting layer. It automates the tedious and error-prone task of keeping the frontend and backend APIs in sync, ensuring that adding a new remoted function only requires a YAML change plus regeneration.
Description
The RemotingCodebaseGenerator class loads the YAML configuration, then generates three files:
apir_backend.gen.h-- Command type enums (APIR_COMMAND_TYPE_*) for each remoted functionbackend-dispatched.gen.h-- Backend dispatch function declarations and a name-lookup switchvirtgpu-forward.gen.h-- Frontend function declarations for the guest side
The generator uses naming patterns from the YAML configuration:
enum_prefix-- Prefix for command type enumsbackend_function_prefix-- Prefix for backend function namesfrontend_function_prefix-- Prefix for frontend function names
Optionally runs clang-format on generated files for consistent formatting.
Usage
Run from the src/ggml-virtgpu/ directory:
cd src/ggml-virtgpu/ python regenerate_remoting.py
Code Reference
Source Location
| Repository | File | Lines |
|---|---|---|
| ggml-org/ggml | src/ggml-virtgpu/regenerate_remoting.py |
332 |
Key Signatures
class RemotingCodebaseGenerator:
def __init__(self, yaml_path: str = "ggmlremoting_functions.yaml"):
"""Initialize the generator with the YAML configuration."""
def generate_enum_name(self, group_name: str, function_name: str) -> str:
"""Generate the APIR_COMMAND_TYPE enum name for a function."""
def generate_backend_function_name(self, group_name: str, function_name: str) -> str:
"""Generate the backend function name."""
def generate_frontend_function_name(self, group_name: str, function_name: str) -> str:
"""Generate the frontend function name."""
def get_enabled_functions(self) -> List[Dict[str, Any]]:
"""Get all enabled functions with their metadata."""
I/O Contract
Inputs
ggmlremoting_functions.yaml-- YAML file defining all remoted functions, their parameters, groups, and naming patterns
Outputs
apir_backend.gen.h-- Generated command type enum headerbackend-dispatched.gen.h-- Generated backend dispatch headervirtgpu-forward.gen.h-- Generated frontend header- Console summary -- Report of what was generated
Usage Examples
Adding a new remoted function:
# 1. Edit ggmlremoting_functions.yaml: # functions: # buffer: # new_function: # enabled: true # params: [...] # 2. Regenerate headers: python regenerate_remoting.py # 3. Generated files are updated with the new function's # enum, backend dispatch, and frontend declaration
Related Pages
Implements Principle
Related Implementations
- Implementation:Ggml_org_Ggml_Virtgpu_command_stream -- Serialization used by generated code
- Implementation:Ggml_org_Ggml_Virtgpu_backend -- Backend consuming generated headers