Skip to content

Commit b9262da

Browse files
authored
Refactor (#21)
* Refactor * adds comments * typo * update docs
1 parent c8b03e9 commit b9262da

File tree

7 files changed

+39
-29
lines changed

7 files changed

+39
-29
lines changed

docs/api.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ <h1><a class="toc-backref" href="#18">Templates</a></h1>
815815
<div class="twelve-columns footer">
816816
<span class="nim-sprite"></span>
817817
<br>
818-
<small style="color: var(--hint);">Made with Nim. Generated: 2025-01-20 16:18:11 UTC</small>
818+
<small style="color: var(--hint);">Made with Nim. Generated: 2025-05-10 16:49:07 UTC</small>
819819
</div>
820820
</div>
821821
</div>

docs/computesim.html

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ <h1 class="title">src/computesim</h1>
8585
</ul>
8686
</details>
8787
</li>
88+
<li>
89+
<a class="reference reference-toplevel" href="#19" id="69">Exports</a>
90+
</li>
8891

8992
</ul>
9093

@@ -96,7 +99,7 @@ <h1 class="title">src/computesim</h1>
9699
<div id="tocRoot"></div>
97100

98101
<p class="module-desc">
99-
<h2><a class="toc-backref" id="description" href="#description">Description</a></h2><p><tt class="docutils literal"><span class="pre"><span class="Identifier">runComputeOnCpu</span></span></tt> is a function that simulates a GPU-like compute wgironment on the CPU. It organizes work into workgroups and invocations, similar to how compute shaders operate on GPUs.</p>
102+
<h2><a class="toc-backref" id="description" href="#description">Description</a></h2><p><tt class="docutils literal"><span class="pre"><span class="Identifier">runComputeOnCpu</span></span></tt> is a function that simulates a GPU-like compute environment on the CPU. It organizes work into workgroups and invocations, similar to how compute shaders operate on GPUs.</p>
100103
<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
101104
The thread pool size must be at least <em>MaxConcurrentWorkGroups * (ceilDiv(workgroupSizeX * workgroupSizeY * workgroupSizeZ, SubgroupSize) + 1)</em>. Compile with: <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="Identifier">d</span><span class="Punctuation">:</span><span class="Identifier">ThreadPoolSize</span><span class="Operator">=</span><span class="Identifier">N</span></span></tt> where N meets this requirement.</div>
102105
<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
@@ -207,8 +210,8 @@ <h1><a class="toc-backref" href="#18">Templates</a></h1>
207210
<dd>
208211

209212

210-
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim.nim#L216" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
211-
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim.nim#L216" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
213+
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim.nim#L219" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
214+
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim.nim#L219" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
212215

213216
</dd>
214217
</div>
@@ -218,8 +221,8 @@ <h1><a class="toc-backref" href="#18">Templates</a></h1>
218221
<dd>
219222

220223

221-
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim.nim#L222" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
222-
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim.nim#L222" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
224+
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim.nim#L225" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
225+
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim.nim#L225" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
223226

224227
</dd>
225228
</div>
@@ -228,14 +231,20 @@ <h1><a class="toc-backref" href="#18">Templates</a></h1>
228231

229232
</dl>
230233
</div>
234+
<div class="section" id="19">
235+
<h1><a class="toc-backref" href="#19">Exports</a></h1>
236+
<dl class="item">
237+
<a href="vectors.html#DVec4"><span class="Identifier">DVec4</span></a>, <a href="vectors.html#dvec4,float64,float64,float64,float64"><span class="Identifier">dvec4</span></a>, <a href="vectors.html#IVec3"><span class="Identifier">IVec3</span></a>, <a href="vectors.html#bvec4,BVec3,bool"><span class="Identifier">bvec4</span></a>, <a href="vectors.html#w=.t,TVec,typed"><span class="Identifier">w=</span></a>, <a href="vectors.html#BVec2"><span class="Identifier">BVec2</span></a>, <a href="vectors.html#bvec2,bool,bool"><span class="Identifier">bvec2</span></a>, <a href="vectors.html#uvec3,uint32"><span class="Identifier">uvec3</span></a>, <a href="vectors.html#dvec4,DVec3,float64"><span class="Identifier">dvec4</span></a>, <a href="vectors.html#ivec3,int32"><span class="Identifier">ivec3</span></a>, <a href="vectors.html#bvec4,bool,bool,bool,bool"><span class="Identifier">bvec4</span></a>, <a href="vectors.html#bvec4,BVec2,BVec2"><span class="Identifier">bvec4</span></a>, <a href="vectors.html#z=.t,TVec,typed"><span class="Identifier">z=</span></a>, <a href="vectors.html#vec3,Vec4"><span class="Identifier">vec3</span></a>, <a href="vectors.html#dvec4,float64"><span class="Identifier">dvec4</span></a>, <a href="vectors.html#w.t,TVec"><span class="Identifier">w</span></a>, <a href="vectors.html#bvec2,BVec3"><span class="Identifier">bvec2</span></a>, <a href="vectors.html#vec4,float32,float32,float32,float32"><span class="Identifier">vec4</span></a>, <a href="vectors.html#$,TVec3[T]"><span class="Identifier">$</span></a>, <a href="vectors.html#uvec4,UVec2,UVec2"><span class="Identifier">uvec4</span></a>, <a href="vectors.html#bvec2,bool"><span class="Identifier">bvec2</span></a>, <a href="vectors.html#dvec2,float64,float64"><span class="Identifier">dvec2</span></a>, <a href="vectors.html#dvec3,DVec4"><span class="Identifier">dvec3</span></a>, <a href="vectors.html#vec4,Vec2,Vec2"><span class="Identifier">vec4</span></a>, <a href="vectors.html#TVec4"><span class="Identifier">TVec4</span></a>, <a href="vectors.html#x=.t,TVec,typed"><span class="Identifier">x=</span></a>, <a href="vectors.html#TVec2"><span class="Identifier">TVec2</span></a>, <a href="vectors.html#uvec4,uint32,uint32,uint32,uint32"><span class="Identifier">uvec4</span></a>, <a href="vectors.html#UVec3"><span class="Identifier">UVec3</span></a>, <a href="vectors.html#uvec2,uint32,uint32"><span class="Identifier">uvec2</span></a>, <a href="vectors.html#dvec4,DVec2,DVec2"><span class="Identifier">dvec4</span></a>, <a href="vectors.html#dvec3,float64,float64,float64"><span class="Identifier">dvec3</span></a>, <a href="vectors.html#uvec2,UVec3"><span class="Identifier">uvec2</span></a>, <a href="vectors.html#DVec3"><span class="Identifier">DVec3</span></a>, <a href="vectors.html#ivec3,int32,int32,int32"><span class="Identifier">ivec3</span></a>, <a href="vectors.html#BVec3"><span class="Identifier">BVec3</span></a>, <a href="vectors.html#y=.t,TVec,typed"><span class="Identifier">y=</span></a>, <a href="vectors.html#ivec2,int32,int32"><span class="Identifier">ivec2</span></a>, <a href="vectors.html#vec2,float32,float32"><span class="Identifier">vec2</span></a>, <a href="vectors.html#uvec4,UVec3,uint32"><span class="Identifier">uvec4</span></a>, <a href="vectors.html#UVec2"><span class="Identifier">UVec2</span></a>, <a href="vectors.html#uvec2,uint32"><span class="Identifier">uvec2</span></a>, <a href="vectors.html#bvec4,bool"><span class="Identifier">bvec4</span></a>, <a href="vectors.html#dvec2,float64"><span class="Identifier">dvec2</span></a>, <a href="vectors.html#ivec3,IVec4"><span class="Identifier">ivec3</span></a>, <a href="vectors.html#vec2,float32"><span class="Identifier">vec2</span></a>, <a href="vectors.html#ivec4,int32,int32,int32,int32"><span class="Identifier">ivec4</span></a>, <a href="vectors.html#bvec4,BVec2,bool,bool"><span class="Identifier">bvec4</span></a>, <a href="vectors.html#dvec3,float64"><span class="Identifier">dvec3</span></a>, <a href="vectors.html#DVec2"><span class="Identifier">DVec2</span></a>, <a href="vectors.html#bvec3,BVec2,bool"><span class="Identifier">bvec3</span></a>, <a href="vectors.html#Vec3"><span class="Identifier">Vec3</span></a>, <a href="vectors.html#IVec4"><span class="Identifier">IVec4</span></a>, <a href="vectors.html#ivec3,IVec2,int32"><span class="Identifier">ivec3</span></a>, <a href="vectors.html#dvec4,DVec2,float64,float64"><span class="Identifier">dvec4</span></a>, <a href="vectors.html#z.t,TVec"><span class="Identifier">z</span></a>, <a href="vectors.html#$,TVec2[T]"><span class="Identifier">$</span></a>, <a href="vectors.html#ivec4,IVec3,int32"><span class="Identifier">ivec4</span></a>, <a href="vectors.html#UVec4"><span class="Identifier">UVec4</span></a>, <a href="vectors.html#uvec3,UVec2,uint32"><span class="Identifier">uvec3</span></a>, <a href="vectors.html#bvec3,bool"><span class="Identifier">bvec3</span></a>, <a href="vectors.html#bvec2,BVec4"><span class="Identifier">bvec2</span></a>, <a href="vectors.html#vec4,float32"><span class="Identifier">vec4</span></a>, <a href="vectors.html#TVec"><span class="Identifier">TVec</span></a>, <a href="vectors.html#vec4,Vec2,float32,float32"><span class="Identifier">vec4</span></a>, <a href="vectors.html#TVec3"><span class="Identifier">TVec3</span></a>, <a href="vectors.html#$,TVec4[T]"><span class="Identifier">$</span></a>, <a href="vectors.html#ivec2,int32"><span class="Identifier">ivec2</span></a>, <a href="vectors.html#ivec2,IVec4"><span class="Identifier">ivec2</span></a>, <a href="vectors.html#vec3,float32,float32,float32"><span class="Identifier">vec3</span></a>, <a href="vectors.html#[]=,TVec[N,T],int,T"><span class="Identifier">[]=</span></a>, <a href="vectors.html#uvec4,uint32"><span class="Identifier">uvec4</span></a>, <a href="vectors.html#Vec4"><span class="Identifier">Vec4</span></a>, <a href="vectors.html#y.t,TVec"><span class="Identifier">y</span></a>, <a href="vectors.html#uvec3,uint32,uint32,uint32"><span class="Identifier">uvec3</span></a>, <a href="vectors.html#BVec4"><span class="Identifier">BVec4</span></a>, <a href="vectors.html#ivec4,IVec2,int32,int32"><span class="Identifier">ivec4</span></a>, <a href="vectors.html#dvec3,DVec2,float64"><span class="Identifier">dvec3</span></a>, <a href="vectors.html#vec3,Vec2,float32"><span class="Identifier">vec3</span></a>, <a href="vectors.html#bvec3,BVec4"><span class="Identifier">bvec3</span></a>, <a href="vectors.html#ivec2,IVec3"><span class="Identifier">ivec2</span></a>, <a href="vectors.html#vec2,Vec3"><span class="Identifier">vec2</span></a>, <a href="vectors.html#uvec2,UVec4"><span class="Identifier">uvec2</span></a>, <a href="vectors.html#x.t,TVec"><span class="Identifier">x</span></a>, <a href="vectors.html#dvec2,DVec4"><span class="Identifier">dvec2</span></a>, <a href="vectors.html#Vec2"><span class="Identifier">Vec2</span></a>, <a href="vectors.html#dvec2,DVec3"><span class="Identifier">dvec2</span></a>, <a href="vectors.html#uvec4,UVec2,uint32,uint32"><span class="Identifier">uvec4</span></a>, <a href="vectors.html#bvec3,bool,bool,bool"><span class="Identifier">bvec3</span></a>, <a href="vectors.html#ivec4,int32"><span class="Identifier">ivec4</span></a>, <a href="vectors.html#IVec2"><span class="Identifier">IVec2</span></a>, <a href="vectors.html#vec3,float32"><span class="Identifier">vec3</span></a>, <a href="vectors.html#vec2,Vec4"><span class="Identifier">vec2</span></a>, <a href="vectors.html#ivec4,IVec2,IVec2"><span class="Identifier">ivec4</span></a>, <a href="vectors.html#uvec3,UVec4"><span class="Identifier">uvec3</span></a>, <a href="vectors.html#vec4,Vec3,float32"><span class="Identifier">vec4</span></a>, <a href="vectors.html#[],TVec[N,T],int"><span class="Identifier">[]</span></a>, <a href="transform.html#optimizeReconvergePoints,NimNode"><span class="Identifier">optimizeReconvergePoints</span></a>, <a href="transform.html#computeShader.m,untyped"><span class="Identifier">computeShader</span></a>, <a href="api.html#subgroupAny.t,bool"><span class="Identifier">subgroupAny</span></a>, <a href="api.html#gl_SubgroupGtMask.t"><span class="Identifier">gl_SubgroupGtMask</span></a>, <a href="api.html#subgroupBallot.t,bool"><span class="Identifier">subgroupBallot</span></a>, <a href="api.html#atomicAdd,T,T"><span class="Identifier">atomicAdd</span></a>, <a href="api.html#atomicCompSwap,T,T,T"><span class="Identifier">atomicCompSwap</span></a>, <a href="api.html#subgroupShuffleXor.t,T,uint32"><span class="Identifier">subgroupShuffleXor</span></a>, <a href="api.html#subgroupAllEqual.t,T"><span class="Identifier">subgroupAllEqual</span></a>, <a href="api.html#subgroupBallotFindLSB,UVec4"><span class="Identifier">subgroupBallotFindLSB</span></a>, <a href="api.html#subgroupElect.t"><span class="Identifier">subgroupElect</span></a>, <a href="api.html#gl_SubgroupLeMask.t"><span class="Identifier">gl_SubgroupLeMask</span></a>, <a href="api.html#subgroupMemoryBarrier.t"><span class="Identifier">subgroupMemoryBarrier</span></a>, <a href="api.html#subgroupAdd.t,T"><span class="Identifier">subgroupAdd</span></a>, <a href="api.html#gl_SubgroupLtMask.t"><span class="Identifier">gl_SubgroupLtMask</span></a>, <a href="api.html#gl_SubgroupSize.t"><span class="Identifier">gl_SubgroupSize</span></a>, <a href="api.html#atomicOr,T,T"><span class="Identifier">atomicOr</span></a>, <a href="api.html#subgroupMin.t,T"><span class="Identifier">subgroupMin</span></a>, <a href="api.html#subgroupInverseBallot.t,UVec4"><span class="Identifier">subgroupInverseBallot</span></a>, <a href="api.html#atomicXor,T,T"><span class="Identifier">atomicXor</span></a>, <a href="api.html#atomicExchange,T,T"><span class="Identifier">atomicExchange</span></a>, <a href="api.html#AtomicInt"><span class="Identifier">AtomicInt</span></a>, <a href="api.html#subgroupExclusiveAdd.t,T"><span class="Identifier">subgroupExclusiveAdd</span></a>, <a href="api.html#subgroupShuffleDown.t,T,uint32"><span class="Identifier">subgroupShuffleDown</span></a>, <a href="api.html#subgroupBallotInclusiveBitCount.t,UVec4"><span class="Identifier">subgroupBallotInclusiveBitCount</span></a>, <a href="api.html#subgroupBallotBitCount,UVec4"><span class="Identifier">subgroupBallotBitCount</span></a>, <a href="api.html#subgroupBroadcastFirst.t,T"><span class="Identifier">subgroupBroadcastFirst</span></a>, <a href="api.html#atomicAnd,T,T"><span class="Identifier">atomicAnd</span></a>, <a href="api.html#subgroupAll.t,bool"><span class="Identifier">subgroupAll</span></a>, <a href="api.html#subgroupBallotExclusiveBitCount.t,UVec4"><span class="Identifier">subgroupBallotExclusiveBitCount</span></a>, <a href="api.html#subgroupShuffle.t,T,uint32"><span class="Identifier">subgroupShuffle</span></a>, <a href="api.html#subgroupMax.t,T"><span class="Identifier">subgroupMax</span></a>, <a href="api.html#barrier.t"><span class="Identifier">barrier</span></a>, <a href="api.html#memoryBarrier.t"><span class="Identifier">memoryBarrier</span></a>, <a href="api.html#gl_SubgroupEqMask.t"><span class="Identifier">gl_SubgroupEqMask</span></a>, <a href="api.html#subgroupInclusiveAdd.t,T"><span class="Identifier">subgroupInclusiveAdd</span></a>, <a href="api.html#subgroupBallotFindMSB,UVec4"><span class="Identifier">subgroupBallotFindMSB</span></a>, <a href="api.html#subgroupBroadcast.t,T,uint32"><span class="Identifier">subgroupBroadcast</span></a>, <a href="api.html#subgroupBallotBitExtract,UVec4,uint32"><span class="Identifier">subgroupBallotBitExtract</span></a>, <a href="api.html#subgroupBarrier.t"><span class="Identifier">subgroupBarrier</span></a>, <a href="api.html#subgroupShuffleUp.t,T,uint32"><span class="Identifier">subgroupShuffleUp</span></a>, <a href="api.html#groupMemoryBarrier.t"><span class="Identifier">groupMemoryBarrier</span></a>, <a href="api.html#gl_SubgroupGeMask.t"><span class="Identifier">gl_SubgroupGeMask</span></a>, <a href="core.html#SubgroupSize"><span class="Identifier">SubgroupSize</span></a>
238+
</dl>
239+
</div>
231240

232241
</div>
233242
</div>
234243

235244
<div class="twelve-columns footer">
236245
<span class="nim-sprite"></span>
237246
<br>
238-
<small style="color: var(--hint);">Made with Nim. Generated: 2025-01-20 16:26:58 UTC</small>
247+
<small style="color: var(--hint);">Made with Nim. Generated: 2025-05-10 16:49:06 UTC</small>
239248
</div>
240249
</div>
241250
</div>

docs/transform.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ <h1><a class="toc-backref" href="#12">Procs</a></h1>
105105
<dd>
106106

107107

108-
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim/transform.nim#L168" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
109-
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim/transform.nim#L168" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
108+
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim/transform.nim#L167" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
109+
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim/transform.nim#L167" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
110110

111111
</dd>
112112
</div>
@@ -124,8 +124,8 @@ <h1><a class="toc-backref" href="#17">Macros</a></h1>
124124
<dd>
125125

126126

127-
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim/transform.nim#L195" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
128-
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim/transform.nim#L195" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
127+
<a href="https://github.com/planetis-m/compute-sim/tree/master/src/computesim/transform.nim#L194" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
128+
<a href="https://github.com/planetis-m/compute-sim/edit/master/src/computesim/transform.nim#L194" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
129129

130130
</dd>
131131
</div>
@@ -141,7 +141,7 @@ <h1><a class="toc-backref" href="#17">Macros</a></h1>
141141
<div class="twelve-columns footer">
142142
<span class="nim-sprite"></span>
143143
<br>
144-
<small style="color: var(--hint);">Made with Nim. Generated: 2025-01-20 16:18:12 UTC</small>
144+
<small style="color: var(--hint);">Made with Nim. Generated: 2025-05-10 16:49:08 UTC</small>
145145
</div>
146146
</div>
147147
</div>

docs/vectors.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ <h1><a class="toc-backref" href="#18">Templates</a></h1>
13341334
<div class="twelve-columns footer">
13351335
<span class="nim-sprite"></span>
13361336
<br>
1337-
<small style="color: var(--hint);">Made with Nim. Generated: 2025-01-20 16:18:11 UTC</small>
1337+
<small style="color: var(--hint);">Made with Nim. Generated: 2025-05-10 16:49:07 UTC</small>
13381338
</div>
13391339
</div>
13401340
</div>

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# computesim
22

3-
A compute shader emulator for learning and debugging GPU compute shaders.
3+
A compute shader simulator for learning and debugging GPU compute shaders.
44

55
## Features
66
- Emulates GPU compute shader execution on CPU
@@ -99,7 +99,7 @@ See the examples directory for more patterns and use cases.
9999

100100
> [!WARNING]
101101
> ### Workgroup Scheduling
102-
> While this emulator runs workgroups using CPU threads, real GPU compute shaders have no fairness guarantees between workgroups. This means your code might work correctly in this CPU emulator but fail on real GPU hardware where workgroups can execute in any order and with varying levels of parallelism. Do not rely on any assumptions about workgroup execution order or scheduling that might be true in this CPU emulator but not guaranteed on actual GPUs.
102+
> While this simulator runs workgroups using CPU threads, real GPU compute shaders have no fairness guarantees between workgroups. This means your code might work correctly in this CPU simulator but fail on real GPU hardware where workgroups can execute in any order and with varying levels of parallelism. Do not rely on any assumptions about workgroup execution order or scheduling that might be true in this CPU simulator but not guaranteed on actual GPUs.
103103
104104
## Compile-time Defines
105105

0 commit comments

Comments
 (0)