mesh-rt's device primitives on the CPU, and a launcher that runs a kernel's nodes as threads, for testing GPU programs without a GPU
$ sexc add @ajax/mesh-rt-sim- total 3
- drwxr-xr-x-../
- drwxr-xr-x-Oct 27 03:26v/# 1 version
- drwxr-xr-x-Oct 27 03:26files/# the files of 0.1.0
- latest
- 0.1.0, published Oct 27 03:26 by ajax
- owners
- ajax
- license
- MIT
- dependencies
- @ajax/mesh-abi-base ^0.1.0, @ajax/mesh-check ^0.1.0
- dependents
- @ajax/mesh-rt-prim, @ajax/mesh-rt-sim-mailbox
- keywords
- mesh alphaos gpu simulator testing runtime
- homepage
- https://github.com/thomasdavis/alpha-c-mesh/tree/main/packages/mesh-rt-sim
- repository
- https://github.com/thomasdavis/alpha-c-mesh
1# @ajax/mesh-rt-sim 2 3mesh-rt's device primitives on the CPU, and a launcher that runs a kernel's nodes as POSIX threads, so a 4mesh GPU program written in C can be tested without a GPU. 5 6- A node is `warps` x 32 threads with its own zeroed shared memory (`RT_SHARED_BYTES` + the program's). 7- The block barrier is a `pthread_barrier` over the node's threads. Every warp collective (shuffles, 8 ballot, `bar.warp.sync`) is an exchange through a per-warp array between two barriers over its 32 9 lanes, so programs that follow mesh-rt's rules (all lanes call warp collectives, all threads call block 10 ones) behave as on a GPU. 11- Loads, stores, atomics and fences are C11 atomics with the same orders; the global timer is 12 `CLOCK_MONOTONIC`; `trap` aborts with the node and thread. 13- Each simulated thread runs with f32 flush-to-zero (x86 MXCSR FTZ|DAZ, AArch64 FPCR.FZ), the PTX `.ftz` 14 semantics of the cluster float mode. 15 16```c 17mesh_sim_launch *l = mesh_sim_start(mesh_main, mailbox, slot, nodes, warps, shared_bytes); 18/* publish tickets, wait for marks (@ajax/mesh-rt-sim-mailbox) */ 19mesh_sim_join(l); 20``` 21 22- **Ported from:** the semantics of alpha-rust-mesh `crates/mesh-rt/src/ptx.rs` (the Rust has no CPU twin of 23 the GPU runtime; its native workers, `crates/mesh-worker`, run a different SDK). 24- **Tests:** every program under `programs/` runs its tasks on it and compares against the CPU references. 25- **Differences:** x86's FTZ/DAZ also applies to f64, which PTX never flushes: a program whose f64 values 26 become subnormal would differ here (none of the ported programs does). Divergent warp collectives (not 27 allowed by mesh-rt's rules) deadlock here rather than misbehave.