Skip to main content

Class: ReduceBuffer

Reduce a buffer of data to a single value by running an associative binary operation over every element.

The binary operation is specified by a BinOpModule. Possible binary operations include sum, min, and max.

Hierarchy

  • HasReactive

    ReduceBuffer

Implements

Constructors

constructor

new ReduceBuffer(params): ReduceBuffer

Parameters

NameType
paramsBufferReduceParams

Returns

ReduceBuffer

Overrides

HasReactive.constructor

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:104

Properties

binOps

binOps: BinOpModule

macros to customize wgsl shader for size of data and type of reduce

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:76


blockLength

blockLength: number

number of elements to reduce in each invocation (4)

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:88


device

device: GPUDevice

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:100


forceMaxWorkgroups

Optional forceMaxWorkgroups: number

Override to set max number of workgroups for dispatch e.g. for testing.

Default Value

maxComputeWorkgroupsPerDimension from the GPUDevice (65535)

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:98


forceWorkgroupLength

Optional forceWorkgroupLength: number

Override to set compute workgroup size e.g. for testing.

Default Value

maxComputeInvocationsPerWorkgroup of the GPUDevice (256)

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:93


label

Optional label: string

Debug label attached to gpu objects for error reporting

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:79


resultOffset

resultOffset: number

start emitting results at this element offset in the results. (0)

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:85


source

source: GPUBuffer

Source data to be reduced

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:73


sourceOffset

sourceOffset: number

start scan at this element offset in the source. (0)

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:82

Accessors

result

get result(): GPUBuffer

Buffer containing results of the reduce after the shader has run.

Returns

GPUBuffer

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:160


workgroupWGSL

get workgroupWGSL(): string

Returns

string

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:164

Methods

commands

commands(commandEncoder): void

Add compute or render passes for this shader to the provided GPUCommandEncoder

Parameters

NameType
commandEncoderGPUCommandEncoder

Returns

void

Implementation of

ComposableShader.commands

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:109


destroy

destroy(): void

Release the result buffer and intermediate buffers for destruction.

Returns

void

Implementation of

ComposableShader.destroy

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:146


reduce

reduce(): Promise<number[]>

Execute the reduce immediately and copy the results back to the CPU. (results are copied from the ReduceBuffer.result GPUBuffer)

Returns

Promise<number[]>

a single reduced result value in an array

Defined in

packages/stoneberry/src/reduce-buffer/ReduceBuffer.ts:154