gpuScan (Function)

Signature: gpuScan(buffer: GpuBuffer<int8> | GpuBuffer<int16> | GpuBuffer<int32> | GpuBuffer<int> | GpuBuffer<uint8> | GpuBuffer<uint16> | GpuBuffer<uint32> | GpuBuffer<float16> | GpuBuffer<float32> | GpuBuffer<float> | GpuBuffer<bool>, initial: t0, combine: (t0, t0) -> t0) -> Result<GpuBuffer<t0>, Error>

Description: Inclusive prefix scan: element i is combine folded left to right through element i. Allocation, dispatch or synchronization failure returns Error with its reason.

Parameters

  • buffer (GpuBuffer<int8> | GpuBuffer<int16> | GpuBuffer<int32> | GpuBuffer<int> | GpuBuffer<uint8> | GpuBuffer<uint16> | GpuBuffer<uint32> | GpuBuffer<float16> | GpuBuffer<float32> | GpuBuffer<float> | GpuBuffer<bool>): The buffer to scan
  • initial (t0): The initial scalar accumulator
  • combine ((t0, t0) -> t0): The pure (accumulator, element) function

Returns: Result<GpuBuffer<t0>, Error>

Example

match toGpu([1, 2, 3]) {
    Success { value } => { let buffer = value
    match gpuScan(buffer, 0, wrapAdd) {
        Success { value } => match fromGpu(value) {
            Success { value } => forEachList(value, print)
            Error { message } => print(message)
        }
        Error { message } => print(message)
    }
    }
    Error { message } => print(message)
}