LuisaCompute Project Structure
SkillMediaProject layout, module architecture, compiler pipeline, and design patterns.
Available today. Use it from your connected AI after setup.
No other account needed.
Connect ahel once, and every AI you use reads what you have installed.
Then ask your AI: use the LuisaCompute Project Structure skill
What this skill tells your AI
The instructions your AI receives, as published by luisagroup/luisacompute in .agents/skills/project_structure/SKILL.md and read by ahel’s review.
Layered architecture: Core → AST/IR → DSL/Runtime → Backends. src/ + public headers include/luisa/. Dual build: CMake + XMake. Frontends: C++, Python, Rust.
Top-Level Directory Map
src/
├── api/ C API & runtime API layer
├── ast/ AST (expressions, statements, types, function builder)
├── backends/ Plugins: CUDA, DX, Metal, CPU, Vulkan, HIP, remote, fallback, common
├── clangcxx/ Clang-based C++→GPU shader compiler (experimental)
├── core/ Foundation: types, math, logging, platform, STL wrappers
├── dsl/ Embedded C++ DSL (kernel/callable lambda tracing)
├── ext/ Third-party deps (git submodules)
├── gui/ Windowing, ImGui, framerate
├── ir/ IR bridge: AST↔IR transforms
├── osl/ Open Shading Language parser
├── py/ Python bindings (pybind11 + pure Python)
├── runtime/ Unified runtime: device, buffer, image, stream, RTX, raster
├── rust/ Rust workspace: IR, CPU backend, remote
├── tensor/ Tensor ops & compute graph
├── tests/ Unit/integration/example tests
├── vstl/ Virtual STL: custom containers, allocators, hashes
└── xir/ Extended IR: SSA, basic blocks, passes, translators
include/luisa/ Public headers mirroring src/ layout (+ ir_v2/)
Root also has: examples/, tests/, tutorials/, utils/, docs/
Modules
src/core/ — Foundation
Platform abstractions, math, logging, binary I/O, dynamic modules.
basic_types.cpp— vector/matrix instantiationslogging.cpp— spdlog-based loggingplatform.cpp— OS abstraction (paths, threads, DLL)dynamic_module.cpp— cross-platform shared library loaderbinary_io.cpp,binary_file_stream.cpp— binary serializationfirst_fit.cpp,pool.cpp,string_scratch.cpp— allocators/scratch buffersstl/— custom STL:vector,string,unordered_map,optional,variant, etc.generate_swizzles.py— swizzle codegen
src/vstl/ — Virtual STL
High-perf containers beyond core/stl: stack_allocator, string_builder, lmdb, md5, v_guid. Headers: include/luisa/vstl/* (hash maps, arenas, lockfree queues, ranges).
src/ast/ — Abstract Syntax Tree
DSL traces C++ lambdas → AST nodes.
expression.cpp— literal, binary, unary, call, swizzle, memberstatement.cpp— if, loop, switch, break, return, ray_querytype.cpp— scalars, vectors, matrices, buffers, textures, structsfunction.cpp— kernel/callable metadatafunction_builder.cpp— manual AST construction APIvariable.cpp— local variablesop.cpp—BinaryOp,UnaryOp,CallOpast2json.cpp— AST→JSON serializationconstant_data.cpp,callable_library.cpp,external_function.cpp,function_duplicator.cpp,atomic_ref_node.cpp
src/xir/ — Extended IR (Next-Gen)
SSA IR with basic blocks, instructions, optimization passes. Receives AST via ast2xir.
instructions/— 30+ types: arithmetic, memory, control flow, resource, autodiff, atomicpasses/— DCE, mem2reg, SROA, autodiff, outline, dom-tree, GEP tracing, local load/store elimination, ray-query lowering, unused callable removal, LICM, GVN, SCCP, inlining, CFG simplificationtranslators/—ast2xir,xir2json,json2xir,xir2text,xir2astmetadata/— source locations, names, comments, curve basistests/— XIR unit tests (enabled byLUISA_COMPUTE_ENABLE_XIR_TESTS)- Key classes:
Module,Function,BasicBlock,Instruction,Value,Use,Builder
src/ir/ — IR Bridge (Legacy)
AST↔IR transforms, high-level transforms: ast2ir.cpp, ir2ast.cpp, transform.cpp.
src/dsl/ — Embedded DSL
GPU kernels via lambda tracing.
func.cpp—Kernel1D/2D/3D,Callablebuiltin.cpp—dispatch_id,thread_id, mathresource.cpp— buffer/image/volume/bindless DSL wrapperslocal.cpp— local/thread storage helperssugar.cpp—$if,$for,$whilertx/— ray tracing:Accel,Ray,RayQuery,Curve,TriangleHitraster/—RasterKernelext/— DSL extensionssoa.cpp,polymorphic.cpp,dispatch_indirect.cpp
src/runtime/ — Unified Runtime
Resource management, command scheduling, RHI abstraction.
device.cpp,context.cpp— device creation, backend loadingstream.cpp,command_list.cpp— command batching/submissionbuffer.cpp,image.cpp,volume.cpp— GPU memorybyte_buffer.cpp,dispatch_buffer.cpp,mipmap.cpp— auxiliary bufferssparse_buffer.cpp,sparse_texture.cpp,sparse_heap.cpp,sparse_command_list.cpp— sparse resourcesbindless_array.cpp,swapchain.cpp,event.cpp,builtin_kernel.cpprhi/—device_interface.h,command.h,command_encoder.h,resource.hrtx/—accel.cpp,mesh.cpp,curve.cpp,motion_instance.cpp,procedural_primitive.cppraster/—raster.cpp,depth_buffer.cppremote/— remote device client/server
src/backends/ — Backend Plugins
Dynamically loaded (luisa-backend-<name>.dll/.so). Each: codegen (AST/XIR→native) + compiler (NVRTC/DXC/etc.) + resources + command encoder.
| Backend | Technology |
|---|---|
CUDA (cuda/) | NVRTC + OptiX + CUDA driver |
DirectX (dx/) | DX12 + DXR + HLSL DXC |
Metal (metal/) | Metal 3 + MSL |
CPU (cpu/) | Rust-based (via src/rust/) |
Vulkan (vk/) | Vulkan + SPIR-V |
HIP (hip/) | AMD HIP |
Remote (remote/) | Network-distributed |
Fallback (fallback/) | Reference interpreter |
Common (common/) | c_codegen/, hlsl/, spirv/, spirv_llvm/, Vulkan swapchain helpers |
Validation (validation/) | Debug layer |
Toy C (toy_c/) | Minimal C codegen |
src/rust/ — Rust Workspace
luisa_compute_ir— core IR: AST→IR, analysis, transforms (DCE, inliner, SSA, autodiff, vectorize)luisa_compute_ir_v2— IR v2 bindingsluisa_compute_ir_staticlib— static library wrapper for C++ linkingluisa_compute_backend— backend proxy/message protocolluisa_compute_backend_impl— CPU backend: LLVM JIT, C++ codegen, texture sampling, remote backendluisa_compute_cpu_kernel_defs— CPU kernel ABI definitionsluisa_compute_api_types— C API types- Built via CMake/Cargo interop, linked into C++
src/api/ — C API
Stable C API for language bindings: runtime.cpp, logging.cpp, Rust binding/RPC generators.
src/py/ — Python
lcapi.cpp— pybind11 entry;export_*.cpp— per-component bindingsluisa/— pure Python package:buffer.py,accel.py,autodiff.py,gui.py,types.pyinterop.cpp/h— PyTorch/DLPack
src/tensor/ — Tensor & Compute Graph
High-level tensor ops, expression DAG, graph passes.
fallback/— CPU kernels (matmul, softmax)pass/— graph passes
src/clangcxx/, src/osl/, src/gui/, src/ext/
- clangcxx: Clang/libTooling C++→GPU compiler (experimental)
- osl: OSO bytecode parser for shader interop
- gui: Cross-platform windowing + ImGui
- ext: git submodules: EASTL, glfw, glslang, imgui, pybind11, spdlog, reproc, SPIRV-Tools, spirv-headers, stb, volk, yyjson, xxhash, marl, half, HIPRT, liblmdb, magic_enum
src/tests/
unit/{core,ast,dsl,runtime,ext,xir}/— unit tests by layerintegration/{runtime,ir}/— cross-cutting integration testscommon/— shared headers (test_device.h,ut/, asset loaders)cxx_shaders/— C++ shader testspython/— Python frontend testsut/— extra UT harness directory- Root: integration tests (
test_path_tracing,test_dsl,test_rtx,test_raster,test_tensor,test_autodiff, etc.)
Build System
- CMake (primary): root +
src/CMakeLists.txt, targets:luisa-compute-<name>, alias:luisa::compute. Backends asMODULEplugins namedluisa-backend-<name>. Options:LUISA_COMPUTE_ENABLE_CUDA|DX|METAL|CPU|VULKAN|HIP|DSL|RUST|TENSOR|GUI|... - XMake (secondary):
xmake.luain root +src/and subdirs - Bootstrap:
bootstrap.pyat repo root - IntelliSense:
update_intellisense.lua
Compiler Pipeline
DSL Tracing (src/dsl/) → AST (src/ast/)
│
┌─────────┴─────────┐
▼ ▼
XIR (src/xir/) IR (src/ir/ → src/rust/)
│ │
└─────────┬─────────┘
▼
Backend Codegen (src/backends/<name>/)
│
▼
GPU Execution (src/runtime/)
Rust IR path: luisa_compute_ir does autodiff, DCE, SSA, vectorize before codegen.
Key Headers
| Header | Scope |
|---|---|
<luisa/luisa-compute.h> | Core + AST + DSL + Runtime + GUI |
<luisa/dsl/syntax.h> | DSL core |
<luisa/dsl/sugar.h> | Sugar macros |
<luisa/runtime/context.h> | Runtime entry |
<luisa/runtime/device.h> | Device & resources |
Design Patterns
- RHI:
src/runtime/rhi/abstracts GPU APIs into common interfaces - Plugin Architecture: Backends as runtime-loaded dynamic modules
- RAII Resources: Move-only handles (
Buffer,Image,Stream,Accel) - Command-Based: Work encoded as
Command→CommandList→Stream - DSL Tracing: Operator overloading + lambda capture builds AST at definition time
- Dual IR: AST (frontend tree) + XIR (SSA backend with optimization passes)
- Rust + C++ Hybrid: IR/CPU backend in Rust; API/DSL in C++
Naming
| Convention | Example |
|---|---|
| CMake target | luisa-compute-core |
| Backend binary | luisa-backend-cuda |
| PCH | lc_core_pch.h |
| Integration test | test_path_tracing.cpp |
| Python export | export_runtime.cpp |
Maintenance
- New backend:
src/backends/<name>/, implementDeviceInterface, register insrc/backends/CMakeLists.txt - New XIR pass:
src/xir/passes/, register insrc/xir/CMakeLists.txt - New runtime resource: define in
rhi/resource.h, implement per-backend, expose inruntime/+include/luisa/runtime/ tensor/is opt-in, less mature.clangcxx/is experimental.
Signals
- GitHub stars
- 1k
- Forks
- 108
- Last commit
- Sep 2026
Advanced
- Catalog kind
- skill
- Gateway key
project-structure-luisagroup- Source
- github.com/luisagroup/luisacompute