kernelfoundry.algorithm.prompts.template_manager¶
Template rendering utilities for prompt assembly in kernel generation.
Classes
|
Template manager with optional evolvable prompt components. |
- class kernelfoundry.algorithm.prompts.template_manager.TemplateManager(gpu_arch: str | list, language: str, ref_language: str, n_tips: int = 2, include_top: bool = True, include_inspirations: bool = True, use_hardware_prompt: bool = True, allow_templated: bool = False, template_example: str | None = None, prompt_template_fn: str = 'main_prompt.j2')[source]¶
Template manager with optional evolvable prompt components.
Provides standard template construction and optionally supports: - Evolved optimization tips and strategies - Session tracking for fitness attribution - Automatic evolution based on kernel performance
- __init__(gpu_arch: str | list, language: str, ref_language: str, n_tips: int = 2, include_top: bool = True, include_inspirations: bool = True, use_hardware_prompt: bool = True, allow_templated: bool = False, template_example: str | None = None, prompt_template_fn: str = 'main_prompt.j2')[source]¶
Initialize the template manager.
- Parameters:
gpu_arch – Target GPU architecture(s)
language – Target language (SYCL, CUDA, triton)
ref_language – Reference language (Pytorch, CUDA, description)
n_tips – Number of optimization tips to include
include_top – Whether to include top program in prompt
include_inspirations – Whether to include inspiration programs
use_hardware_prompt – Whether to include hardware specs
allow_templated – Whether to allow templated kernels
template_example – Example of templated kernel format
output_dir – Directory for saving evolution database (optional)
llm_server – LLM server for mutation operations (optional)
prompt_template_fn – Filename of the main prompt template
- construct_prompt(reference_code: str, last_program: Program | None = None, prior_versions: List[Program] = [], top_program: Program | None = None, rag_input: str = '', second_ref_code: str | None = None, is_feedback: bool = False, evolvable_content: Dict[str, str] | None = None, is_backward: bool = False) str[source]¶
Construct prompt from optional components.
This method maintains compatibility with the existing API.
- Parameters:
evolvable_content – Optional dict of evolved content for template regions. Keys should match template variables without the
evolved_prefix: - optimization_philosophy - optimization_strategies - common_pitfalls - analysis_guidanceis_backward – whether the operation is a backward pass