Show HN: Lockstep – 데이터 지향 프로그래밍 언어

hackernews | | 📦 오픈소스
#데이터지향 #데이터처리 #반도체 #시스템프로그래밍 #하드웨어 #하드웨어/반도체
원문 출처: hackernews · Genesis Park에서 요약 및 분석

요약

데이터 지향 시스템 프로그래밍 언어인 'Lockstep'이 공개되었습니다. 이 언어는 고성능 GPU 컴퓨트 셰이더의 실행 효율성과 C 언어의 생산성을 결합하여, CPU 벡터 장치를 최대로 활용하는 것을 목표로 합니다. 내부 커널에서 분기 명령어(if, for)를 엄격히 금지하고 정적 메모리 구조를 강제함으로써, 런타임 오버헤드 없는 결정론적이고 예측 가능한 병렬 처리를 보장합니다. 또한 LLVM 백엔드를 통해 하드웨어 친화적인 머신 코드를 생성하며, C, Rust 등의 호스트 언어와 쉽게 연동할 수 있도록 설계되었습니다.

본문

Lockstep is a data-oriented systems programming language designed for high-throughput, deterministic compute pipelines. It bridges the gap between the productivity of C and the brutal execution efficiency of GPU compute shaders. By enforcing a strict Straight-Line SIMD execution model and Static Memory Topology, Lockstep allows the compiler to generate machine code that is mathematically guaranteed to saturate CPU vector units without the overhead of branch misprediction or cache contention. - Data-Oriented by Design: Logic is secondary to data flow. Programs are modeled as physical circuits (pipelines) rather than sequences of instructions. - Zero Branching: Standard control flow ( if ,for ,while ) is banned inside compute kernels. Branching is replaced by hardware-native masking and stream-splitting. - Predictable Performance: No malloc , no hidden threads, and no garbage collection. Memory is a static arena provided by the Host. - Deterministic Parallelism: Race conditions are impossible by construction. State updates are strictly isolated to out streams or linearaccumulator types. A Lockstep program is a Directed Acyclic Graph (DAG) of compute nodes. shader : A 1-to-1 mapping. Processes one input element and produces one output element.filter : A 1-to-0/1 mapping. Conditionally passes data to downstream nodes.pure : A side-effect-free mathematical transform. Strictly inlined.pipeline : The "circuit board" that binds streams and uniforms to kernels. Lockstep uses a Host-Owned Static Arena. The compiler calculates the exact byte-offset for every Struct-of-Arrays (SoA) member at compile-time. - SoA by Default: Structs are automatically decomposed into parallel primitive arrays to maximize cache line utilization and SIMD width. - Saturated Writes: To eliminate boundary checks, stream indices use saturation arithmetic. If a stream capacity is exceeded, the final element acts as a "trash can," absorbing further writes without memory corruption or branching. Since if/else is banned, conditional logic is performed using branchless intrinsics like step , mix , clamp , min , max , abs , sign , and smoothstep . shader ApplyPhysics(in Entity ent, out Entity updated, uniform float dt) { // Standard math float fall_vy = ent.vy - (9.81 * dt); float bounce_vy = -ent.vy * 0.8; // Branchless Branching: step returns 1.0 if ent.y particles; accumulator energy_sum; bind { particles = Calculate(particles, energy_sum); // fold sum consumes the linear type and produces a global scalar uniform float total_e = fold sum(energy_sum); } } Lockstep's semantic validator enforces a strict type system with no implicit coercions. The currently supported primitive declared types are: int float bool string uint anddouble are not currently supported as declared types in source-level type annotations (for locals, params, uniforms, struct fields, etc.). Using unknown declared types producesLCK310 . Struct members may use: - primitives, - previously declared struct names, - array suffixes ( T[4] ), and - generic wrappers ( Ctor /Ctor ), including nested forms. Examples: Particle[4] vector matrix,4> Type identity is name-based and exact. Field access chains (a.b.c ) are valid only when each link resolves to a struct type and an existing field. Type checking is strict and explicit: - No implicit widening or narrowing. - No implicit int ⇄float promotion. - Assignment, variable initialization, pure-function arguments, pure-function returns, and bind argument/target checks all require exact type equality. - Mixed numeric operators ( int withfloat ) without an explicit cast are rejected withLCK424 (implicit_numeric_widening ). When conversion is desired, use an explicit cast. Lockstep targets LLVM IR directly to leverage industrial-grade optimization passes. noalias Guarantee: Because Lockstep forbids arbitrary pointers, the compiler decorates all IR pointers withnoalias , enabling aggressive auto-vectorization.- SSA Purity: Local variables are mapped directly to SSA registers. Struct member access ( ent.pos.x ) is lowered to LLVMextractvalue andinsertvalue instructions, allowing for total Scalar Replacement of Aggregates (SROA). - Fast-Math Reductions: Reduction loops are emitted with fast math flags, permitting LLVM to reassociate floating-point operations into horizontal SIMD shuffles. The compiler generates a C-compatible header for the Host application (C/C++, Rust, or Zig). - Allocate: Host allocates a contiguous block of size LOCKSTEP_ARENA_BYTES . - Bind: Host calls Lockstep_BindMemory(ptr) . - Prime: Host writes initial data into the SoA offsets provided by the header. - Tick: Host calls Lockstep_Tick() to execute the pipeline. See examples/ for a minimal end-to-end host app in C (examples/minimal_host.c ) that includes a generated header, allocates arena memory, primes initial data, and calls Lockstep_Tick . Install in editable mode to enable the packaged CLI entrypoint: pip install -e . lockstepc path/to/program.lock # or read source fro

Genesis Park 편집팀이 AI를 활용하여 작성한 분석입니다. 원문은 출처 링크를 통해 확인할 수 있습니다.

공유

관련 저널 읽기

전체 보기 →