ast
無料Manual AST construction with FunctionBuilder for kernels and callables without DSL sugar.
日本語の概要は準備中です。原文の説明を表示しています。
Project layout, module architecture, compiler pipeline, and design patterns.
インストールする前に、エージェントに与えられる指示の中身を確認できます。
Layered architecture: Core → AST/IR → DSL/Runtime → Backends. src/ + public headers include/luisa/. Dual build: CMake + XMake. Frontends: C++, Python, Rust.
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/
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 — AST→JSON serializationconstant_data.cpp, callable_library.cpp, external_function.cpp, function_duplicator.cpp, atomic_ref_node.cppsrc/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 by LUISA_COMPUTE_ENABLE_XIR_TESTS)Module, Function, BasicBlock, Instruction, Value, Use, Buildersrc/ir/ — IR Bridge (Legacy)AST↔IR transforms, high-level transforms: ast2ir.cpp, ir2ast.cpp, transform.cpp.
src/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/ — 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/serversrc/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/) | 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 Workspaceluisa_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 typessrc/api/ — C APIStable C API for language bindings: runtime.cpp, logging.cpp, Rust binding/RPC generators.
src/py/ — Pythonlcapi.cpp — pybind11 entry; export_*.cpp — per-component bindingsluisa/ — pure Python package: buffer.py, accel.py, autodiff.py, gui.py, types.pyinterop.cpp/h — PyTorch/DLPacksrc/tensor/ — Tensor & Compute GraphHigh-level tensor ops, expression DAG, graph passes.
fallback/ — CPU kernels (matmul, softmax)pass/ — graph passessrc/clangcxx/, src/osl/, src/gui/, src/ext/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 directorytest_path_tracing, test_dsl, test_rtx, test_raster, test_tensor, test_autodiff, etc.)src/CMakeLists.txt, targets: luisa-compute-<name>, alias: luisa::compute. Backends as MODULE plugins named luisa-backend-<name>. Options: LUISA_COMPUTE_ENABLE_CUDA|DX|METAL|CPU|VULKAN|HIP|DSL|RUST|TENSOR|GUI|...xmake.lua in root + src/ and subdirsbootstrap.py at repo rootupdate_intellisense.luaDSL 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.
| 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 |
src/runtime/rhi/ abstracts GPU APIs into common interfacesBuffer, Image, Stream, Accel)Command → CommandList → Stream| 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 |
src/backends/<name>/, implement DeviceInterface, register in src/backends/CMakeLists.txtsrc/xir/passes/, register in src/xir/CMakeLists.txtrhi/resource.h, implement per-backend, expose in runtime/ + include/luisa/runtime/tensor/ is opt-in, less mature. clangcxx/ is experimental.まだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
Manual AST construction with FunctionBuilder for kernels and callables without DSL sugar.
日本語の概要は準備中です。原文の説明を表示しています。
Backend plugin architecture, DeviceInterface, dynamic loading, and command encoding.
日本語の概要は準備中です。原文の説明を表示しています。
CMake build options, custom functions, and backend patterns for LuisaCompute.
日本語の概要は準備中です。原文の説明を表示しています。
C++ naming, formatting, static analysis, and RTTI rules for LuisaCompute.
日本語の概要は準備中です。原文の説明を表示しています。
Debug crashes and test failures via stack-traces, host/device logging, and DSL buffer inspection.
日本語の概要は準備中です。原文の説明を表示しています。
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.
日本語の概要は準備中です。原文の説明を表示しています。