Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ggml org Ggml Virtgpu codegen

From Leeroopedia
Revision as of 15:02, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Ggml_org_Ggml_Virtgpu_codegen.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Implementation Metadata
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:

  1. apir_backend.gen.h -- Command type enums (APIR_COMMAND_TYPE_*) for each remoted function
  2. backend-dispatched.gen.h -- Backend dispatch function declarations and a name-lookup switch
  3. virtgpu-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 enums
  • backend_function_prefix -- Prefix for backend function names
  • frontend_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 header
  • backend-dispatched.gen.h -- Generated backend dispatch header
  • virtgpu-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

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment