prompt_constructor#

Prompt construction based on RAG databases, templates, and examples.

Functions

get_system_prompt(language)

Classes

PromptConstructor(language, gpu_arch, ...[, ...])

Builds generation prompts with templates, examples, and RAG inputs.

kernelfoundry.algorithm.prompts.prompt_constructor.get_system_prompt(language: str) → str[source]#
class kernelfoundry.algorithm.prompts.prompt_constructor.PromptConstructor(language: str, gpu_arch: str | list, prompt_config: DictConfig, reference_language: str = 'Pytorch', mode: str = 'functional', use_feedback_llm: bool = False, mcp_prompt_list: list[str] | None = None)[source]#

Builds generation prompts with templates, examples, and RAG inputs.

__init__(language: str, gpu_arch: str | list, prompt_config: DictConfig, reference_language: str = 'Pytorch', mode: str = 'functional', use_feedback_llm: bool = False, mcp_prompt_list: list[str] | None = None)[source]#

Initialize prompt construction dependencies and retrieval backends.

__call__(reference_src: str, problem_name: str, last_program: Program | None = None, second_ref_code: str | None = None, inspirations: list[Program] | None = None, top_program: Program | None = None, evolvable_content: dict[str, str] | None = None, target_optimization_profile: dict[str, int] | None = None, ref_keywords: list[str] | None = None) → str[source]#

Generate a prompt for the given reference source code.

Parameters:
  • reference_src – The reference source code to translate

  • problem_name – Name of the problem for RAG lookup

  • last_program – Previous iteration’s program (for feedback)

  • second_ref_code – Optional secondary reference code

  • inspirations – List of inspiration programs to include

  • top_program – Best performing program so far

  • evolvable_content – Optional evolved content for template regions

  • target_optimization_profile – Optimization coordinates selected for this iteration

  • ref_keywords – List of keywords for reference, usually computed in first iteration

get_examples(reference_src: str, problem_name: str, is_first_iter: bool, last_program=None, top_program=None, reference_keywords: list[str] | None = None, target_optimization_profile: dict[str, int] | None = None) → list[source]#

Generate an initial prompt for the given reference source code.

load_vector_add_example()[source]#

Load the canonical vector-add translation example for the active language. Returns None when the language ships no example.

static categorize_code(code: str, input_type: str = 'PyTorch code', allowed_keywords: list[str] | None = None, server_type: str = 'openai', model_name: str = 'default') → list[str][source]#

Categorize code using LLM to extract relevant topic keywords.

Parameters:
  • code – Source code to categorize.

  • input_type – Type of input code (e.g., “PyTorch code”, “CUDA kernel”).

  • allowed_keywords – List of keywords to use for categorization.

  • server_type – Inference server type (e.g., “openai”).

  • model_name – Model to use for categorization.

Returns:

List of extracted keywords.