ParallelExecutor¶
Overview¶
Executes a kernel in parallel, using async/await to simulate the WGPU execution model.
Designed so that we can test WGPU-like code, but use the debugging facilities of the browser to debug it.
We'll randomly choose which item to execute next, so that as much as possible things are executed with a random order
Things are structured so that execution thread functions will: - await context.start() - at the very start of the call - await all of the inter-thread primitives (like get/set) - resolve when complete
Thus the executor will keep ONE thread going at a time, and every time one of those actions is taken, we'll toss the function to resolve that in a list (with the others), and will randomly choose which one to resolve next. This will execute things with a fairly random order.
(needs a working knowledge of the WGSL execution model to understand)
@author Jonathan Olson <jonathan.olson@colorado.edu>
Class ParallelExecutor¶
Constructor¶
new ParallelExecutor( kernel : ParallelKernel<WorkgroupValues> )¶
Instance Methods¶
dispatch( dispatchX, dispatchY, dispatchZ ) : Promise<void>¶
Execute the kernel in parallel, with the given dispatch dimensions (controls how many workgroups there are)
next()¶
Kick off the next pending execution thread action.
start() : Promise<void>¶
Called from execution threads at the start of their execution. We'll pause all of them until we're ready to proceed.
workgroupBarrier( workgroup : ParallelWorkgroup<WorkgroupValues> ) : Promise<void>¶
Called from execution threads through the context
storageBarrier( workgroup : ParallelWorkgroup<WorkgroupValues> ) : Promise<void>¶
Called from execution threads through the context
afterSet() : Promise<void>¶
Called indirectly from execution threads through the context (when they set a value in a storage/workgroup array)
afterGet() : Promise<void>¶
Called indirectly from execution threads through the context (when they get a value in a storage/workgroup array)
Instance Properties¶
resolves : ( () => void )[]¶
(readonly)
A list of functions to call when we're ready to execute the next item. Each one will resolve a promise that one kernel execution thread is waiting on, which SHOULD trigger another method on this executor (OR will resolve the promise for the kernel execution thread).
donePromises : Promise<void>[]¶
(readonly)
All of the promises returned by the async kernel execution thread functions. When all of these are done, our dispatch is complete (and dispatch() will resolve shortly thereafter).
Source Code¶
See the source for ParallelExecutor.ts in the alpenglow repository.