ast
FreeManual AST construction with FunctionBuilder for kernels and callables without DSL sugar.
The English summary is being prepared. Showing the original description.
Project layout, module architecture, compiler pipeline, and design patterns.
The English summary is being prepared. Showing the original description.
See how to installReview the instructions the agent will receive before you install.
Layered architecture: Core → AST/XIR → DSL/Runtime → Backends. src/ + public headers include/luisa/. Dual build: CMake + XMake. Frontends: C++ and Python.
src/
├── ast/ AST (expressions, statements, types, function builder)
├── backends/ Plugins: CUDA, DX, Metal, Metal4, Vulkan, HIP, fallback, SIMD, remote, common, validation, tools
├── clangcxx/ Clang-based C++→GPU shader compiler (experimental)
├── core/ Foundation: types, math, logging, platform, STL wrappers
├── coro/ Coroutine (split-function) kernel schedulers
├── dsl/ Embedded C++ DSL (kernel/callable lambda tracing)
├── ext/ Third-party deps (git submodules + vendored libs)
├── gui/ Windowing, ImGui, framerate
├── osl/ Open Shading Language parser
├── py/ Python bindings (pybind11 + pure Python)
├── runtime/ Unified runtime: device, buffer, image, stream, RTX, raster
├── tests/ Unit/integration/example tests
├── tile/ Tile-level IR (TIRx/XIR bridges, layouts, verifier)
├── vstl/ Virtual STL: custom containers, allocators, hashes
└── xir/ Extended IR: SSA, basic blocks, passes, translators
include/luisa/ Public headers mirroring src/ layout (no py/, tests/, ext/; backends only as include/luisa/backends/{common,ext}/)
Root also has: examples/, tutorials/, utils/, docs/, cmake/, config/, scripts/
src/core/ — FoundationPlatform 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 codegensrc/vstl/ — Virtual STLHigh-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 TreeDSL 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, json2ast.cpp — AST↔JSON serializationcoro_suspend.cpp — coroutine suspend nodeconstant_data.cpp, callable_library.cpp, external_function.cpp, function_duplicator.cpp, atomic_ref_node.cppsrc/xir/ — Native C++ IRSSA IR with basic blocks, instructions, optimization passes. Receives AST via ast2xir.
instructions/ — 31 files: arithmetic, memory, control flow, resource, autodiff, atomic, coro, ray_query, raster_discard, thread_grouppasses/ — 89 pass sources: DCE, mem2reg, SROA, autodiff, outline, dom-tree, GEP tracing, local load/store elimination, ray-query lowering, unused callable removal, LICM, GVN, SCCP, inlining, CFG simplification (plus coro_, loop_, vectorization, alias/uniformity analysis)translators/ — ast2xir, xir2json, json2xir, xir2text, xir2ast, xir_interchangemetadata/ — source locations, names, comments, curve basistests/ — XIR unit tests: luisa_compute_xir_add_test(<name>) builds xir_test_<name> from tests/test_<name>.cpp (aggregate_field_bitmasks, mem2reg, debug_printer, dce, ray_query) when LUISA_COMPUTE_ENABLE_XIR_TESTS is set. The variable is read at src/xir/CMakeLists.txt:177 but never declared via option(), so it only takes effect when passed explicitly with -D; the targets are plain add_executable — no CTest registration.Module, Function, BasicBlock, Instruction, Value, Use, Buildersrc/dsl/ — Embedded DSLGPU 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.cppsrc/runtime/ — Unified RuntimeResource 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/ — command.cpp, command_encoder.cpp, device_interface.cpp, resource.cpp, pixel.cpp (headers: include/luisa/runtime/rhi/)rtx/ — accel.cpp, mesh.cpp, curve.cpp, motion_instance.cpp, procedural_primitive.cppraster/ — raster.cpp, depth_buffer.cppsrc/backends/ — Backend PluginsDynamically loaded (luisa-backend-<name>.dll/.so). Each: codegen (AST/XIR→native) + compiler (NVRTC/DXC/etc.) + resources + command encoder.
| Backend | Technology |
|---|---|
CUDA (cuda/) | AST → NVRTC, or XIR → LLVM → PTX (cuda_codegen_ast.h, llvm_codegen/), plus OptiX and CUDA driver |
DirectX (dx/) | DX12 + DXR + HLSL DXC |
Metal (metal/) | Metal 3 + MSL (metal_codegen_ast.h) |
Metal4 (metal4/) | Metal 4 AIR via LLVM codegen (llvm_codegen/, metal_xir_pipeline.cpp) |
Vulkan (vk/) | Vulkan + SPIR-V (native XIR→SPIR-V, or experimental AST→LLVM→SPIR-V) |
HIP (hip/) | AMD HIP + HIPRT ray tracing |
Fallback (fallback/) | Native C++ LLVM JIT (ExecutionEngine) + Embree |
SIMD (simd/) | Experimental CPU backend: XIR → schedule → LLVM (Embree packets) |
Remote (remote/) | Experimental client/server backend (remote_protocol.cpp, remote_server.cpp) |
Common (common/) | hlsl/, spirv/, spirv_llvm/, native_shader/, rtx/, llvm_native_math.*, Vulkan swapchain/instance, OIDN denoiser |
Validation (validation/) | Debug layer |
Tools (tools/) | Host AOT tool lc_compile_builtin (main.cpp), not a plugin backend |
Native shader injection (NativeShaderExt): include/luisa/backends/ext/native_shader_ext.h (public API),
src/backends/common/native_shader/native_shader_reflection.h (shared SPIR-V reflection parser),
src/backends/dx/DXApi/native_shader_ext.{h,cpp} (HLSL→DXIL + DXC reflection),
src/backends/vk/native_shader_ext.{h,cpp}, native_shader.{h,cpp}, glslang_compiler.{h,cpp}
(GLSL/HLSL→SPIR-V, Tier-B pipeline built from reflection), src/backends/validation/native_shader_ext_impl.*,
src/backends/cuda/native_shader_ext.{h,cpp}, native_shader.{h,cpp}, native_shader_reflection.h
(CUDA C++ -> PTX via NVRTC + driver-API module load; reflection from the __global__ signature crossed
with the compiled PTX parameter layout),
examples/compute/native_shader.cpp, and the test_native_shader* tests. Dispatch goes through
CustomCommandUUID::NATIVE_SHADER_DISPATCH (NativeShaderDispatchCommand), so the reorder pass and the per-backend
barriers use the declared per-argument Usage.
src/py/ — Pythonlcapi.cpp — pybind11 entry (pybind11_add_module(lcapi ...)); export_*.cpp — per-component bindingsluisa/ — pure Python package: buffer.py, accel.py, autodiff.py, gui.py, types.pyinterop.cpp/h — DX/VK↔CUDA device interop; export_dlpack.cpp + dlpack.h — DLPack (PyTorch) import/exportsrc/tile/ — Tile-level IRTile program IR, layouts, targets and verification (CMake target luisa-compute-tile, headers include/luisa/tile/*).
ir.cpp, layout.cpp, dimension.cpp, target.cpp, dsl.cpp, verifier.cppbridge/xir/ — TileIR↔XIR bridge; bridge/tirx/ — optional TVM TIRx bridge (LUISA_COMPUTE_ENABLE_TILE_TIRX_BRIDGE)src/coro/ — Coroutine kernelsSplit-function / coroutine kernel scheduling on top of DSL + XIR (CMake target luisa-compute-coro, headers include/luisa/coro/*).
coro_compile.cpp, coro_graph.cpp, coro_stub.cppschedulers/ — wavefront.cpp, graph_wavefront_policy.cpp, state_machine.cpp, persistent.cppsrc/clangcxx/, src/osl/, src/gui/, src/ext/.gitmodules): EASTL, glfw, glslang, imgui, pybind11, spdlog, reproc, SPIRV-Tools, spirv-headers, stb, yyjson, xxhash, marl, HIPRT, magic_enum, llvm-downgrade, tvm; vendored in-tree (not submodules): volk/, half/, liblmdb/, BTree/, tvm_ext/src/tests/unit/{core,ast,dsl,runtime,xir,coro,tile,ext,fallback,simd}/ — unit tests by layerintegration/runtime/ — cross-cutting tests (test_rtx.cpp, test_raster.cpp, test_aot.cpp, test_metal_xir_air*.cpp, …); integration/xir/ — test_xir2ast_roundtrip.cppbenchmark/, cuda/, ios/ — benchmark and platform-specific testscommon/ — shared headers (test_device.h, tiny_obj_loader.h, tinyexr.h, *_test_utils.h)cxx_shaders/ — C++ shader testspython/ — Python frontend tests (test-*.py)ut/ — vendored Boost.UT single header (ut.hpp)src/tests/ root; all live in the directories above (luisa_compute_add_test(name source) in src/tests/CMakeLists.txt)src/CMakeLists.txt, targets: luisa-compute-<name> (core, vstl, tile, ast, xir, runtime, dsl, coro, osl, gui, backends, clangcxx), aggregate interface compute with alias: luisa::compute. Backends built by luisa_compute_add_backend(<name>) as MODULE plugins (STATIC on iOS) with OUTPUT_NAME luisa-backend-<name>. Options: LUISA_COMPUTE_ENABLE_CUDA|DX|METAL|METAL4|VULKAN|HIP|FALLBACK|SIMD|REMOTE|DSL|GUI|CLANG_CXX|SAFE_MODE|... (there is no ..._ENABLE_TENSOR; the tensor module was removed). Outputs: ${CMAKE_BINARY_DIR}/bin (+ /bin/<config> for multi-config), libs to ${CMAKE_BINARY_DIR}/lib (scripts/setup_output_dirs.cmake).xmake.lua in root + src/ and subdirs; module targets lc-* (e.g. lc-runtime), plugin targets lc-backend-{dx,cuda,metal,vk,fallback} — hip/metal4/simd/remote have no xmake targets, CMake only. Options declared as option("lc_*") in the root xmake.lua (e.g. lc_dx_backend, lc_vk_backend, lc_cuda_backend, lc_metal_backend, lc_fallback_backend, lc_enable_dsl, lc_enable_simd); lc_enable_tensor does not exist.bootstrap.py at repo rootupdate_intellisense.luaDSL Tracing (src/dsl/, detail::FunctionBuilder)
│
▼
AST (src/ast/)
│
▼
ast2xir (src/xir/translators/ast2xir.cpp)
│
▼
XIR Module / CFG (src/xir/) + PassPipeline (src/xir/passes/)
│
▼ Backend codegen
├── DX: AST → HLSL (src/backends/common/hlsl/hlsl_codegen.cpp) → DXC
├── Metal: AST → MSL (src/backends/metal/metal_codegen_ast.cpp)
├── Vulkan: XIR → SPIR-V (src/backends/common/spirv/spirv_codegen/);
experimental AST → LLVM → SPIR-V (src/backends/common/spirv_llvm/)
├── CUDA: AST → device C++ → PTX via NVRTC (cuda_codegen_ast.cpp),
or AST → XIR → LLVM → PTX (cuda/llvm_codegen/); autodiff requires LLVM
├── HIP: AST → device C++ or XIR → LLVM (hip/llvm_codegen/)
├── Metal4: XIR → AIR via LLVM (src/backends/metal4/llvm_codegen/)
├── Fallback / SIMD: XIR → LLVM (JIT / CPU packet schedule)
└── xir2ast (src/xir/translators/xir2ast.cpp): XIR → AST, used by the DX/VK tile paths
│
▼
Runtime execution (src/runtime/)
| Header | Scope |
|---|---|
<luisa/luisa-compute.h> | Universal header: Core + vstl + AST + XIR + tile + Runtime + osl + DSL/GUI/clangcxx (the last three behind LUISA_ENABLE_DSL / LUISA_ENABLE_GUI / LUISA_ENABLE_CLANGCXX) |
<luisa/dsl/syntax.h> | DSL core |
<luisa/dsl/sugar.h> | Sugar macros |
<luisa/runtime/context.h> | Runtime entry |
<luisa/runtime/device.h> | Device & resources |
include/luisa/runtime/rhi/ (device_interface.h, command.h, command_encoder.h, resource.h; impl in src/runtime/rhi/) abstracts GPU APIs into common interfacesContext::load_backend() / DynamicModule::load(..., "luisa-backend-<name>") in src/runtime/context.cppBuffer, Image, Stream, Accel)Command → CommandList → Stream| Convention | Example |
|---|---|
| CMake target | luisa-compute-core |
| Backend binary | luisa-backend-cuda |
| PCH | lc_dsl_pch.h (also lc_runtime_pch.h, lc_vk_pch.h, …; there is no lc_core_pch.h) |
| Integration test | test_rtx.cpp (src/tests/integration/runtime/) |
| Python export | export_runtime.cpp |
src/backends/<name>/, implement DeviceInterface, add add_subdirectory(<name>) behind a LUISA_COMPUTE_ENABLE_<NAME> guard in src/backends/CMakeLists.txt and call luisa_compute_add_backend(<name> ...) theresrc/xir/passes/, register in src/xir/CMakeLists.txtinclude/luisa/runtime/rhi/resource.h, implement per-backend, expose in runtime/ + include/luisa/runtime/hip/, metal4/, simd/, remote/ backends and clangcxx/ are OFF by default (CMake) and experimental. There is no tensor/ module any more (add_subdirectory(tensor) is commented out in src/CMakeLists.txt and src/xmake.lua); examples/tensor/ is a hand-written DSL example.No reviews yet. Tell others what you thought.
No login needed. Share how it worked for you, ask a question, or note where it did not run.
No comments yet. Be the first to write one.
Manual AST construction with FunctionBuilder for kernels and callables without DSL sugar.
The English summary is being prepared. Showing the original description.
Backend plugin architecture, DeviceInterface, dynamic loading, and command encoding.
The English summary is being prepared. Showing the original description.
CMake build options, custom functions, and backend patterns for LuisaCompute.
The English summary is being prepared. Showing the original description.
C++ naming, formatting, static analysis, and RTTI rules for LuisaCompute.
The English summary is being prepared. Showing the original description.
Debug crashes and test failures via stack-traces, host/device logging, DSL buffer inspection, and add_debug_checks kernel restrict-mode guards.
The English summary is being prepared. Showing the original description.
Show uncommitted changes and commit history via git. Use when: (1) inspecting what changed in a file before committing, (2) checking diff of tracked/new/deleted files, (3) reviewing a specific commit's changes, (4) listing files changed in a commit.
The English summary is being prepared. Showing the original description.