MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ windowed_kernel_config()

GpuComputeConfig MayaFlux::Yantra::windowed_kernel_config ( const std::string & body,
const WindowedKernelShape & shape = {} )
inlinenodiscard

Config of a GLSL body wrapped in the layout.

Parameters
bodyStatements run for each window.
shapeLanes per window and inputs.
Returns
A config whose shader_id is INVALID_SHADER when the body does not compile or the shape is unusable.

Definition at line 154 of file WindowedKernelAnalyzer.hpp.

154 {})
155{
157 if (!windowed_kernel_diagnose(shape).empty()) {
158 return {};
159 }
160
161 std::string text;
162 if (shape.lanes > 1) {
163 text += " uint window = gl_WorkGroupID.x;\n";
164 text += " uint lane = gl_LocalInvocationID.x;\n";
165 text += " uint lanes = gl_WorkGroupSize.x;\n";
166 text += " if (window >= window_count) { return; }\n";
167 text += " uint window_base = offset + window * stride;\n";
168 text += " uint result_base = window * outputs;\n";
169 } else {
170 text += " if (i >= window_count) { return; }\n";
171 text += " uint window_base = offset + i * stride;\n";
172 text += " uint result_base = i * outputs;\n";
173 }
174 text += body;
175
176 auto assemble = Portal::Graphics::ShaderSpec::Assemble {};
177 assemble.ssbo("samples", BindingDirection::Input, Kakshya::GpuDataFormat::FLOAT32);
178 for (uint32_t input = 2; input <= shape.inputs; ++input) {
179 assemble.ssbo("samples" + std::to_string(input), BindingDirection::Input, Kakshya::GpuDataFormat::FLOAT32);
180 }
181 assemble.ssbo("parameters", BindingDirection::Input, Kakshya::GpuDataFormat::FLOAT32)
182 .ssbo("results", BindingDirection::Output, Kakshya::GpuDataFormat::FLOAT32)
183 .pc("window_length", Kakshya::GpuDataFormat::UINT32)
184 .pc("stride", Kakshya::GpuDataFormat::UINT32)
185 .pc("offset", Kakshya::GpuDataFormat::UINT32)
186 .pc("window_count", Kakshya::GpuDataFormat::UINT32)
187 .pc("outputs", Kakshya::GpuDataFormat::UINT32);
188 for (uint32_t input = 2; input <= shape.inputs; ++input) {
189 assemble.pc("stride" + std::to_string(input), Kakshya::GpuDataFormat::UINT32)
190 .pc("offset" + std::to_string(input), Kakshya::GpuDataFormat::UINT32);
191 }
192 assemble.function("float", "sample_at", "uint window, uint k",
193 " return samples[pc.offset + window * pc.stride + k];");
194 for (uint32_t input = 2; input <= shape.inputs; ++input) {
195 const std::string tag = std::to_string(input);
196 assemble.function("float", "sample" + tag + "_at", "uint window, uint k",
197 " return samples" + tag + "[pc.offset" + tag + " + window * pc.stride" + tag + " + k];");
198 }
199 if (shape.lanes > 1) {
200 assemble.preamble(detail::lane_preamble(shape.lanes))
201 .function("float", "lane_reduce_sum", "float v",
202 detail::lane_reduction("lane_scratch", "float", "lane_scratch[l] + lane_scratch[l + s]"))
203 .function("float", "lane_reduce_max", "float v",
204 detail::lane_reduction("lane_scratch", "float", "max(lane_scratch[l], lane_scratch[l + s])"))
205 .function("float", "lane_reduce_min", "float v",
206 detail::lane_reduction("lane_scratch", "float", "min(lane_scratch[l], lane_scratch[l + s])"))
207 .function("uint", "lane_first", "bool condition",
208 " uint v = condition ? gl_LocalInvocationID.x : gl_WorkGroupSize.x;\n"
209 + detail::lane_reduction("lane_scratch_u", "uint", "min(lane_scratch_u[l], lane_scratch_u[l + s])"));
210 }
211
212 return config_from_spec(assemble.kernel(Portal::Graphics::KernelSource { .body = std::move(text) })
213 .workgroup(shape.workgroup())
214 .build());
215}
@ FLOAT32
32-bit float (standard GPU)
BindingDirection
Data flow direction for a shader binding slot.
std::string lane_reduction(std::string_view scratch, std::string_view type, std::string_view combine)
std::string lane_preamble(uint32_t lanes)
std::string windowed_kernel_diagnose(const WindowedKernelShape &shape)
Why a shape cannot be used, empty when it can.
GpuComputeConfig config_from_spec(const Portal::Graphics::ShaderSpec &spec)
Derive a GpuComputeConfig from a ShaderSpec.

Referenced by MayaFlux::Yantra::WindowedKernelAnalyzer< std::vector< Kakshya::DataVariant >, Eigen::MatrixXd >::context(), and MayaFlux::Yantra::WaveformAnalyzer< std::vector< Kakshya::DataVariant >, Eigen::MatrixXd >::ensure_native().

Here is the caller graph for this function: