1- #include " pipeline.h"
2- #include " operators/resize.h"
1+ #include " memory_manager.h"
32#include " operators/color_convert.h"
43#include " operators/gaussian_blur.h"
4+ #include " operators/resize.h"
55#include " operators/sobel.h"
6- #include " memory_manager.h"
6+ #include " pipeline.h"
7+
8+ #include < cstring>
79#include < iostream>
810#include < vector>
9- #include < cstring>
1011
1112using namespace mini_image_pipe ;
1213
@@ -15,16 +16,19 @@ void generateTestImage(uint8_t* data, int width, int height, int channels) {
1516 for (int y = 0 ; y < height; y++) {
1617 for (int x = 0 ; x < width; x++) {
1718 int idx = (y * width + x) * channels;
18-
19+
1920 // Create a gradient pattern
2021 uint8_t r = static_cast <uint8_t >((x * 255 ) / width);
2122 uint8_t g = static_cast <uint8_t >((y * 255 ) / height);
2223 uint8_t b = static_cast <uint8_t >(((x + y) * 255 ) / (width + height));
23-
24+
2425 data[idx] = r;
25- if (channels >= 2 ) data[idx + 1 ] = g;
26- if (channels >= 3 ) data[idx + 2 ] = b;
27- if (channels >= 4 ) data[idx + 3 ] = 255 ; // Alpha
26+ if (channels >= 2 )
27+ data[idx + 1 ] = g;
28+ if (channels >= 3 )
29+ data[idx + 2 ] = b;
30+ if (channels >= 4 )
31+ data[idx + 3 ] = 255 ; // Alpha
2832 }
2933 }
3034}
@@ -46,15 +50,10 @@ int main() {
4650 Pipeline pipeline (config);
4751
4852 // Create operators
49- auto resizeOp = std::make_shared<ResizeOperator>(
50- targetWidth, targetHeight, InterpolationMode::BILINEAR
51- );
52- auto colorConvertOp = std::make_shared<ColorConvertOperator>(
53- ColorConversionType::RGB_TO_GRAY
54- );
55- auto gaussianOp = std::make_shared<GaussianBlurOperator>(
56- GaussianKernelSize::KERNEL_5x5
57- );
53+ auto resizeOp =
54+ std::make_shared<ResizeOperator>(targetWidth, targetHeight, InterpolationMode::BILINEAR);
55+ auto colorConvertOp = std::make_shared<ColorConvertOperator>(ColorConversionType::RGB_TO_GRAY);
56+ auto gaussianOp = std::make_shared<GaussianBlurOperator>(GaussianKernelSize::KERNEL_5x5);
5857 auto sobelOp = std::make_shared<SobelOperator>();
5958
6059 // Add operators to pipeline
@@ -69,17 +68,18 @@ int main() {
6968 pipeline.connect (colorNode, blurNode);
7069 pipeline.connect (blurNode, sobelNode);
7170
72- std::cout << " Pipeline created with " << pipeline.getTaskGraph ().size () << " operators" << std::endl;
73- std::cout << " - Resize: " << inputWidth << " x" << inputHeight
74- << " -> " << targetWidth << " x" << targetHeight << std::endl;
71+ std::cout << " Pipeline created with " << pipeline.getTaskGraph ().size () << " operators"
72+ << std::endl;
73+ std::cout << " - Resize: " << inputWidth << " x" << inputHeight << " -> " << targetWidth << " x"
74+ << targetHeight << std::endl;
7575 std::cout << " - ColorConvert: RGB -> Grayscale" << std::endl;
7676 std::cout << " - GaussianBlur: 5x5 kernel" << std::endl;
7777 std::cout << " - Sobel: Edge detection" << std::endl;
7878
7979 // Allocate input image on host
8080 size_t inputSize = inputWidth * inputHeight * inputChannels;
8181 MemoryManager& memMgr = MemoryManager::getInstance ();
82-
82+
8383 uint8_t * h_input = static_cast <uint8_t *>(memMgr.allocatePinned (inputSize));
8484 if (!h_input) {
8585 std::cerr << " Failed to allocate input buffer" << std::endl;
@@ -88,8 +88,8 @@ int main() {
8888
8989 // Generate test image
9090 generateTestImage (h_input, inputWidth, inputHeight, inputChannels);
91- std::cout << " Generated test image: " << inputWidth << " x" << inputHeight
92- << " x " << inputChannels << std::endl;
91+ std::cout << " Generated test image: " << inputWidth << " x" << inputHeight << " x "
92+ << inputChannels << std::endl;
9393
9494 // Allocate device memory for input
9595 uint8_t * d_input = static_cast <uint8_t *>(memMgr.allocateDevice (inputSize));
@@ -128,7 +128,7 @@ int main() {
128128 // Output is single-channel edge map
129129 size_t outputSize = targetWidth * targetHeight;
130130 uint8_t * h_output = static_cast <uint8_t *>(memMgr.allocatePinned (outputSize));
131-
131+
132132 if (h_output) {
133133 memMgr.copyToHostAsync (h_output, d_output, outputSize, stream);
134134 cudaStreamSynchronize (stream);
@@ -137,14 +137,16 @@ int main() {
137137 int nonZeroCount = 0 ;
138138 int maxVal = 0 ;
139139 for (size_t i = 0 ; i < outputSize; i++) {
140- if (h_output[i] > 0 ) nonZeroCount++;
141- if (h_output[i] > maxVal) maxVal = h_output[i];
140+ if (h_output[i] > 0 )
141+ nonZeroCount++;
142+ if (h_output[i] > maxVal)
143+ maxVal = h_output[i];
142144 }
143145
144146 std::cout << " Output statistics:" << std::endl;
145147 std::cout << " - Size: " << targetWidth << " x" << targetHeight << std::endl;
146- std::cout << " - Non-zero pixels: " << nonZeroCount
147- << " ( " << (100.0 * nonZeroCount / outputSize) << " %)" << std::endl;
148+ std::cout << " - Non-zero pixels: " << nonZeroCount << " ( "
149+ << (100.0 * nonZeroCount / outputSize) << " %)" << std::endl;
148150 std::cout << " - Max edge value: " << maxVal << std::endl;
149151
150152 memMgr.freePinned (h_output);
0 commit comments