Coder Design Document

Overview

The Coder is a core component in the AI Kernel Generator that converts algorithm designs into concrete implementation code. It inherits from AgentBase and is responsible for transforming high-level algorithm sketches (generated by Designer) into executable kernel code for specific hardware platforms and frameworks.

Core Functions

  • Design-to-Code Translation: Converts algorithm designs into concrete implementation code
  • Doc-Driven Integration: Leverages custom reference documents for accurate code generation
  • Multi-DSL Support: Supports various target languages (Triton, SWFT, etc.)
  • Framework Adaptation: Generates code for different frontend frameworks (MindSpore, PyTorch, etc.)
  • Error-Guided Repair: Fixes generated code based on verification feedback
  • API Integration: Intelligently selects appropriate APIs based on documentation

Initialization Parameters

Parameter Name Type/Required Description
op_name str (Required) Kernel name, identifying the specific kernel
task_desc str (Required) Task description, detailing the kernel functional requirements
dsl str (Required) Target DSL: "triton_cuda", "triton_ascend", "swft", etc.
framework str (Required) Frontend framework: "mindspore", "torch", "numpy", etc.
backend str (Required) Hardware backend: "ascend", "cuda", etc.
arch str (Required) Hardware architecture: "ascend910b4", "a100", etc.
workflow_config_path str (Optional) Workflow configuration file path (usually injected by Task from the orchestration plan)
config dict (Required) Complete orchestration plan configuration, including log_dir, agent_model_config, docs_dir, etc. (see Task Orchestration Plan Configuration)

Related docs: Workflow details in Workflow; documentation integration in Doc-Driven Integration Guide.

Doc-Driven Integration

The Coder loads reference documents via docs_dir.coder in the orchestration plan. For document list, directory structure, and authoring guidelines, see the Doc-Driven Integration Guide. Details are not duplicated here.

Configuration Example

# In task orchestration plan file
docs_dir:
  coder: "resources/docs/triton_ascend_docs"  # Coder reference documents
  
agent_model_config:
  coder: "your_model_name"
  api_generator: "your_api_model"  # For API document compression

Execution Flow

  1. Initialization Stage

    • Load workflow configuration and create parser
    • Initialize code generation templates
    • Load all reference documents using Doc-Driven Integration
    • Prepare base document structure with loaded content
  2. Processing Stage

    • Extract algorithm design from task information
    • Process API documentation (compress if needed)
    • Incorporate conductor suggestions and error feedback
  3. Generation Stage

    • Execute LLM generation with comprehensive context
    • Return generated code, prompt, and reasoning process