lc_dsl

Write LuisaCompute DSL kernels, callables, structs, and GPU dispatch code in C++.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing GPU kernels with the LuisaCompute embedded DSL requires knowing many framework-specific idioms—Kernel1D/2D/3D definitions, LUISA_STRUCT registration, sugar macros, warp intrinsics, bindless arrays, and indirect dispatch—which are scattered across test files and headers.

Core Features & Use Cases

  • Kernel & Callable Authoring: Defines 1D/2D/3D kernels, reusable Callables with transitive captures, and multi-return compose patterns, then compiles and dispatches them through device streams.
  • Data & Memory Operations: Covers LUISA_STRUCT registration (including templates and methods), buffer read/write, atomics, shared memory, constants, and type casting.
  • Advanced GPU Features: Documents warp/wave intrinsics, ray-tracing DSL, indirect dispatch, coroutines, and cooperative vector/matrix operations (Vulkan backend).
  • Use Case: A graphics engineer needs a warp-level matrix multiplication kernel; the Skill provides the exact set_warp_size, warp_lane_id, and warp_active_sum pattern from the framework's own tests.

Quick Start

Ask the assistant to write a LuisaCompute DSL kernel, for example a 1D kernel that atomically increments a buffer, using the lc_dsl skill.

Frequently Asked Questions about lc_dsl

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

FAQPage Schema
How do I write a GPU kernel with the LuisaCompute DSL?

Define a Kernel1D, Kernel2D, or Kernel3D lambda taking BufferVar or image arguments, use dispatch_id() for indexing, then compile with device.compile(kernel) and launch via stream << shader(args).dispatch(size). Include <luisa/dsl/syntax.h> for core DSL types.

How do I register a C++ struct for use in LuisaCompute kernels?

Use the LUISA_STRUCT macro with the struct name and member list, e.g. LUISA_STRUCT(Material, albedo, roughness) {}. The macro body can also define DSL methods, and template structs use LUISA_TEMPLATE_STRUCT with template definition macros.

Does LuisaCompute DSL support warp-level intrinsics?

Yes, it provides warp vote, reduction, prefix scan, and lane exchange intrinsics such as warp_active_sum, warp_active_bit_mask, warp_prefix_sum, and warp_read_lane. Set the warp size with set_warp_size(32u) and query lanes with warp_lane_id().

Which backends support cooperative vector operations in LuisaCompute?

Cooperative vector operations currently only support the Vulkan backend. The DX backend requires Shader Model 6.8 with experimental features enabled through a DirectXDeviceConfigExt subclass returning true from UseExperimental().

How do I perform atomic operations on buffers in LuisaCompute DSL?

Call buf.atomic(index) to get an atomic accessor, then use fetch_add, fetch_sub, fetch_max, or compare_exchange. Atomics also work on vector components, matrix elements, struct members, and Shared memory arrays.

What is the difference between $ sugar macros and standard DSL syntax?

The $ macros from <luisa/dsl/sugar.h> are shorthand: $float declares Var<float>, $if/$for/$while replace if_ and loop calls, and $buffer declares buffer arguments. Both forms compile identically; sugar reduces boilerplate in kernel code.