gpu.cpp 0.1.0
 
Loading...
Searching...
No Matches
gpu::Bindings< N > Struct Template Reference

Represents an ordered collection of WGPUBuffers (wrapped as tensors, non-overlapping views, or arrays) for the purpose of binding them to a kernel operation to make them accessible to the GPU kernel. More...

#include <gpu.h>

Public Member Functions

 Bindings (const std::initializer_list< Tensor > &init)
 
 Bindings (const std::initializer_list< TensorView > &init)
 
 Bindings (const std::initializer_list< Array > &init)
 
Tensoroperator[] (std::size_t index)
 
const Tensoroperator[] (std::size_t index) const
 

Public Attributes

std::array< Tensor, N > data
 
std::array< size_t, N > viewOffsets
 
std::array< size_t, N > viewSpans
 

Detailed Description

template<std::size_t N>
struct gpu::Bindings< N >

Represents an ordered collection of WGPUBuffers (wrapped as tensors, non-overlapping views, or arrays) for the purpose of binding them to a kernel operation to make them accessible to the GPU kernel.

The ordering of the bindings should match the binding indices in the WGSL code.

Definition at line 124 of file gpu.h.

Constructor & Destructor Documentation

◆ Bindings() [1/3]

template<std::size_t N>
gpu::Bindings< N >::Bindings ( const std::initializer_list< Tensor > & init)
inline

Definition at line 128 of file gpu.h.

128 {
129 std::copy(begin(init), end(init), begin(data));
130 std::fill(begin(viewOffsets), end(viewOffsets), 0);
131 for (size_t i = 0; i < N; ++i) {
132 viewSpans[i] = data[i].data.size;
133 }
134 }
std::array< size_t, N > viewSpans
Definition gpu.h:127
std::array< size_t, N > viewOffsets
Definition gpu.h:126
std::array< Tensor, N > data
Definition gpu.h:125

◆ Bindings() [2/3]

template<std::size_t N>
gpu::Bindings< N >::Bindings ( const std::initializer_list< TensorView > & init)
inline

Definition at line 136 of file gpu.h.

136 {
137 size_t i = 0;
138 for (const auto &tv : init) {
139 data[i] = tv.data;
140 viewOffsets[i] = tv.offset;
141 viewSpans[i] = tv.span;
142 ++i;
143 }
144 }

◆ Bindings() [3/3]

template<std::size_t N>
gpu::Bindings< N >::Bindings ( const std::initializer_list< Array > & init)
inline

Definition at line 146 of file gpu.h.

146 {
147 std::copy(begin(init), end(init), begin(data));
148 std::fill(begin(viewOffsets), end(viewOffsets), 0);
149 for (size_t i = 0; i < N; ++i) {
150 viewSpans[i] = data[i].size;
151 }
152 }

Member Function Documentation

◆ operator[]() [1/2]

template<std::size_t N>
Tensor & gpu::Bindings< N >::operator[] ( std::size_t index)
inline

Definition at line 154 of file gpu.h.

154{ return data[index]; }

◆ operator[]() [2/2]

template<std::size_t N>
const Tensor & gpu::Bindings< N >::operator[] ( std::size_t index) const
inline

Definition at line 155 of file gpu.h.

155{ return data[index]; }

Member Data Documentation

◆ data

template<std::size_t N>
std::array<Tensor, N> gpu::Bindings< N >::data

Definition at line 125 of file gpu.h.

◆ viewOffsets

template<std::size_t N>
std::array<size_t, N> gpu::Bindings< N >::viewOffsets

Definition at line 126 of file gpu.h.

◆ viewSpans

template<std::size_t N>
std::array<size_t, N> gpu::Bindings< N >::viewSpans

Definition at line 127 of file gpu.h.


The documentation for this struct was generated from the following file: