CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
operation_pipeline_executor_gpu.cpp
Go to the documentation of this file.
1
11
12#include <spdlog/spdlog.h>
13
15
17{
18 Halide::Var x("x"), y("y"), c("c");
19
20 // 1. Chunky input from Halide::ImageParam (x,y,c) -> (x,y,c)
21 Halide::Func rgb_input("rgb_input");
22 rgb_input(x, y, c) = m_input(x, y, c);
23
24 // ====================================================================
25 // OKLAB DIRECT (No Transpose) + OPERATIONS
26 // ====================================================================
27 Halide::Func oklab_image { ColorSpace::rgbToOklab(rgb_input, x, y, c) };
28 Halide::Func ops_result { applyOperations(oklab_image, x, y, c) };
29 Halide::Func final_rgb_output { ColorSpace::oklabToRgb(ops_result, x, y, c) };
30
31 // ====================================================================
32 // SCHEDULING & COMPILATION GPU
33 // ====================================================================
34 final_rgb_output.output_buffer().dim(0).set_stride(4);
35 final_rgb_output.output_buffer().dim(2).set_stride(1);
36
37 Halide::Target target { Config::AppConfig::getHalideTarget() };
38 applyScheduling(final_rgb_output, x, y, c);
39
40 try {
41 final_rgb_output.compile_jit(target);
42 m_pipeline = Halide::Pipeline(final_rgb_output);
43 m_chain_built = true;
44 spdlog::info("[OperationPipelineExecutorGPU::buildOperationChain]: Pipeline compiled (Direct Chunky Oklab).");
45 } catch (const Halide::CompileError& e) {
46 spdlog::critical("[OperationPipelineExecutorGPU::buildOperationChain]: {}", e.what());
47 m_chain_built = false;
48 }
49}
50
51void OperationPipelineExecutorGPU::applyScheduling(Halide::Func& pipeline, Halide::Var& x, Halide::Var& y, Halide::Var &c) const
52{
53 Halide::Var xo, yo, xi, yi;
54 pipeline.gpu_tile(x, y, xo, yo, xi, yi, 16, 16);
55 spdlog::trace("[OperationPipelineExecutorGPU::applyScheduling]: Applying GPU scheduling.");
56}
57
59{
60 auto* gpu_impl{dynamic_cast<ImageProcessing::WorkingImageGPU_Halide*>(&working_image)};
61
62 if (!gpu_impl || !gpu_impl->isHalideBufferValid() || !gpu_impl->isOriginalHalideBufferValid()) {
63 spdlog::error("[OperationPipelineExecutorGPU::execute]: Invalid Halide buffer or GPU implementation.");
64 return false;
65 }
66
67 return executeOnHalideBuffer(gpu_impl->getOriginalHalideBuffer(), gpu_impl->getHalideBuffer());
68}
69
70} // namespace CaptureMoment::Core::Pipeline
static const Halide::Target & getHalideTarget()
Gets the configured Halide Target object.
Abstract interface representing an image used as a working buffer.
Concrete implementation of WorkingImageGPU using Halide for processing.
Halide::ImageParam m_input
The shared Halide Input Parameter.
void buildOperationChain() override
Builds the Halide function graph based on m_operations.
bool execute(ImageProcessing::IWorkingImageHardware &working_image) override
Executes the compiled pipeline on a generic working image.
bool m_chain_built
Flag indicating if the pipeline has been successfully built and compiled.
Halide::Func applyOperations(const Halide::Func &input, const Halide::Var &x, const Halide::Var &y, const Halide::Var &c)
Applies all operations to the input function.
bool executeOnHalideBuffer(Halide::Buffer< float > &input_buffer, Halide::Buffer< float > &output_buffer) override
Executes the compiled pipeline directly on a Halide buffer.
Halide::Pipeline m_pipeline
The compiled Halide pipeline object.
Halide::Func oklabToRgb(const Halide::Func &input, const Halide::Var &x, const Halide::Var &y, const Halide::Var &c)
Converts a Chunky Oklab Halide::Func back to linear RGB.
Halide::Func rgbToOklab(const Halide::Func &input, const Halide::Var &x, const Halide::Var &y, const Halide::Var &c)
Converts RGB Halide::Func to Oklab.
Declaration of OperationPipelineExecutorGPU (Fused Adjustment Pipeline).
Concrete implementation of image working buffer on GPU using Halide for processing.
CaptureMoment — footer