ast

Construct raw kernel and callable ASTs with FunctionBuilder in C++.

1.0k|106|Updated Nov 20, 2020
One-click install
npx skills add https://github.com/LuisaGroup/LuisaCompute --skill ast-luisagroup
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ast
Source: https://github.com/LuisaGroup/LuisaCompute/tree/main/.agents/skills/ast
Command: npx skills add https://github.com/LuisaGroup/LuisaCompute --skill ast-luisagroup

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

LuisaCompute provides two approaches to construct kernels and callables: DSL Approach and Manual AST Approach. The manual AST approach uses FunctionBuilder to construct raw AST nodes directly, enabling code generation, metaprogramming, and fine-grained control when the DSL sugar is not suitable.

Core Features & Use Cases

  • Define kernels, callables, and raster stages programmatically with FunctionBuilder::define_kernel, define_callable, and define_raster_stage.
  • Build, manipulate, and reason about ASTs for code generation and tooling within C++ workflows.
  • Use cases include metaprogramming, programmatic kernel construction, and cases requiring lower-level control over kernel code.

Quick Start

Define a kernel with FunctionBuilder::define_kernel and build its AST inside the callback.

Frequently Asked Questions about ast

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I construct raw kernel ASTs programmatically in C++?

Use FunctionBuilder::define_kernel to construct raw kernel ASTs programmatically in C++. Build blocks, variables, and operations inside the callback to enable code generation and metaprogramming without DSL sugar.

What is the difference between manual AST construction and DSL in kernel code generation?

Manual AST construction differs from DSL by using FunctionBuilder to build raw AST nodes directly. It provides fine-grained control for code generation and metaprogramming when the DSL sugar is not suitable for the specific use case.

Does FunctionBuilder support defining callables and raster stages?

Yes, FunctionBuilder supports defining callables and raster stages. Use define_callable and define_raster_stage to programmatically construct these components across kernels and raster stages in C++ workflows.

How do I specify types when building ASTs with FunctionBuilder?

Specify types when building ASTs with FunctionBuilder by using Type::of<T>(). Combine this with FunctionBuilder::current() to build blocks, variables, and operations after including luisa/ast/function_builder.h.

When should I use manual AST construction for metaprogramming instead of DSL?

Use manual AST construction for metaprogramming instead of DSL when you need fine-grained control over kernel code or when programmatic kernel construction requires lower-level AST manipulation that DSL sugar cannot adequately express.