Skip to content

Commit 313da98

Browse files
author
shijiashuai
committed
fix: resolve CI workflow failures
1 parent cff9e6f commit 313da98

29 files changed

Lines changed: 709 additions & 857 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ jobs:
4242
- uses: actions/checkout@v4
4343

4444
- name: Install clang-format
45-
run: sudo apt-get update && sudo apt-get install -y clang-format-14
45+
run: sudo apt-get update && sudo apt-get install -y clang-format
4646

4747
- name: Check formatting
4848
run: |
4949
find include src tests examples -name '*.h' -o -name '*.cpp' -o -name '*.cu' -o -name '*.cuh' | \
50-
xargs clang-format-14 --dry-run --Werror
50+
xargs clang-format --dry-run --Werror

examples/demo_pipeline.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
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

1112
using 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);

include/memory_manager.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#pragma once
22

33
#include "types.h"
4+
45
#include <cuda_runtime.h>
5-
#include <vector>
6+
7+
#include <cstddef>
68
#include <mutex>
7-
#include <unordered_set>
89
#include <unordered_map>
9-
#include <cstddef>
10+
#include <unordered_set>
11+
#include <vector>
1012

1113
namespace mini_image_pipe {
1214

@@ -33,14 +35,10 @@ class MemoryManager {
3335
void freeDevice(void* ptr);
3436

3537
// Async copy host to device
36-
cudaError_t copyToDeviceAsync(
37-
void* dst, const void* src, size_t size, cudaStream_t stream
38-
);
38+
cudaError_t copyToDeviceAsync(void* dst, const void* src, size_t size, cudaStream_t stream);
3939

4040
// Async copy device to host
41-
cudaError_t copyToHostAsync(
42-
void* dst, const void* src, size_t size, cudaStream_t stream
43-
);
41+
cudaError_t copyToHostAsync(void* dst, const void* src, size_t size, cudaStream_t stream);
4442

4543
// Release all resources
4644
void shutdown();
@@ -70,12 +68,12 @@ class MemoryManager {
7068

7169
MemoryPool pinnedPool_;
7270
MemoryPool devicePool_;
73-
71+
7472
// Unified allocation tracking: ptr -> {ptr, size, isPinned}
7573
std::unordered_map<void*, MemoryBlock> activePinnedAllocs_;
7674
std::unordered_map<void*, MemoryBlock> activeDeviceAllocs_;
7775
std::mutex allocMutex_;
78-
76+
7977
bool usePinnedMemory_ = true;
8078
size_t pinnedAllocCount_ = 0;
8179
size_t pinnedReuseCount_ = 0;
@@ -84,4 +82,4 @@ class MemoryManager {
8482
void* findOrAllocateDevice(size_t size);
8583
};
8684

87-
} // namespace mini_image_pipe
85+
} // namespace mini_image_pipe

include/operator.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#pragma once
22

33
#include "types.h"
4+
45
#include <cuda_runtime.h>
5-
#include <string>
6+
67
#include <memory>
8+
#include <string>
79

810
namespace mini_image_pipe {
911

@@ -13,20 +15,13 @@ class IOperator {
1315
virtual ~IOperator() = default;
1416

1517
// Execute operator on GPU stream
16-
virtual cudaError_t execute(
17-
const void* input,
18-
void* output,
19-
int width,
20-
int height,
21-
int channels,
22-
cudaStream_t stream
23-
) = 0;
18+
virtual cudaError_t execute(const void* input, void* output, int width, int height,
19+
int channels, cudaStream_t stream) = 0;
2420

2521
// Get output dimensions given input dimensions
26-
virtual void getOutputDimensions(
27-
int inputWidth, int inputHeight, int inputChannels,
28-
int& outputWidth, int& outputHeight, int& outputChannels
29-
) const = 0;
22+
virtual void getOutputDimensions(int inputWidth, int inputHeight, int inputChannels,
23+
int& outputWidth, int& outputHeight,
24+
int& outputChannels) const = 0;
3025

3126
// Get operator name for debugging
3227
virtual const char* getName() const = 0;
@@ -42,4 +37,4 @@ class IOperator {
4237
// Shared pointer type for operators
4338
using OperatorPtr = std::shared_ptr<IOperator>;
4439

45-
} // namespace mini_image_pipe
40+
} // namespace mini_image_pipe

include/operators/color_convert.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,11 @@ class ColorConvertOperator : public IOperator {
1010
explicit ColorConvertOperator(ColorConversionType type);
1111
~ColorConvertOperator() override = default;
1212

13-
cudaError_t execute(
14-
const void* input,
15-
void* output,
16-
int width,
17-
int height,
18-
int channels,
19-
cudaStream_t stream
20-
) override;
21-
22-
void getOutputDimensions(
23-
int inputWidth, int inputHeight, int inputChannels,
24-
int& outputWidth, int& outputHeight, int& outputChannels
25-
) const override;
13+
cudaError_t execute(const void* input, void* output, int width, int height, int channels,
14+
cudaStream_t stream) override;
15+
16+
void getOutputDimensions(int inputWidth, int inputHeight, int inputChannels, int& outputWidth,
17+
int& outputHeight, int& outputChannels) const override;
2618

2719
const char* getName() const override { return "ColorConvert"; }
2820

@@ -37,4 +29,4 @@ class ColorConvertOperator : public IOperator {
3729
ColorConversionType type_;
3830
};
3931

40-
} // namespace mini_image_pipe
32+
} // namespace mini_image_pipe

include/operators/gaussian_blur.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,11 @@ class GaussianBlurOperator : public IOperator {
1010
explicit GaussianBlurOperator(GaussianKernelSize size, float sigma = 0.0f);
1111
~GaussianBlurOperator() override;
1212

13-
cudaError_t execute(
14-
const void* input,
15-
void* output,
16-
int width,
17-
int height,
18-
int channels,
19-
cudaStream_t stream
20-
) override;
21-
22-
void getOutputDimensions(
23-
int inputWidth, int inputHeight, int inputChannels,
24-
int& outputWidth, int& outputHeight, int& outputChannels
25-
) const override;
13+
cudaError_t execute(const void* input, void* output, int width, int height, int channels,
14+
cudaStream_t stream) override;
15+
16+
void getOutputDimensions(int inputWidth, int inputHeight, int inputChannels, int& outputWidth,
17+
int& outputHeight, int& outputChannels) const override;
2618

2719
const char* getName() const override { return "GaussianBlur"; }
2820

@@ -36,12 +28,12 @@ class GaussianBlurOperator : public IOperator {
3628
private:
3729
GaussianKernelSize kernelSize_;
3830
float sigma_;
39-
float* d_kernel_ = nullptr; // 1D kernel on device
40-
void* d_intermediate_ = nullptr; // Intermediate buffer for separable filter
31+
float* d_kernel_ = nullptr; // 1D kernel on device
32+
void* d_intermediate_ = nullptr; // Intermediate buffer for separable filter
4133
size_t intermediateSize_ = 0;
4234

4335
void generateKernel();
4436
void freeResources();
4537
};
4638

47-
} // namespace mini_image_pipe
39+
} // namespace mini_image_pipe

include/operators/resize.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,15 @@ namespace mini_image_pipe {
77

88
class ResizeOperator : public IOperator {
99
public:
10-
ResizeOperator(int targetWidth, int targetHeight, InterpolationMode mode = InterpolationMode::BILINEAR);
10+
ResizeOperator(int targetWidth, int targetHeight,
11+
InterpolationMode mode = InterpolationMode::BILINEAR);
1112
~ResizeOperator() override = default;
1213

13-
cudaError_t execute(
14-
const void* input,
15-
void* output,
16-
int width,
17-
int height,
18-
int channels,
19-
cudaStream_t stream
20-
) override;
14+
cudaError_t execute(const void* input, void* output, int width, int height, int channels,
15+
cudaStream_t stream) override;
2116

22-
void getOutputDimensions(
23-
int inputWidth, int inputHeight, int inputChannels,
24-
int& outputWidth, int& outputHeight, int& outputChannels
25-
) const override;
17+
void getOutputDimensions(int inputWidth, int inputHeight, int inputChannels, int& outputWidth,
18+
int& outputHeight, int& outputChannels) const override;
2619

2720
const char* getName() const override { return "Resize"; }
2821

@@ -40,4 +33,4 @@ class ResizeOperator : public IOperator {
4033
InterpolationMode mode_;
4134
};
4235

43-
} // namespace mini_image_pipe
36+
} // namespace mini_image_pipe

include/operators/sobel.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,13 @@ class SobelOperator : public IOperator {
1010
SobelOperator();
1111
~SobelOperator() override = default;
1212

13-
cudaError_t execute(
14-
const void* input,
15-
void* output,
16-
int width,
17-
int height,
18-
int channels,
19-
cudaStream_t stream
20-
) override;
13+
cudaError_t execute(const void* input, void* output, int width, int height, int channels,
14+
cudaStream_t stream) override;
2115

22-
void getOutputDimensions(
23-
int inputWidth, int inputHeight, int inputChannels,
24-
int& outputWidth, int& outputHeight, int& outputChannels
25-
) const override;
16+
void getOutputDimensions(int inputWidth, int inputHeight, int inputChannels, int& outputWidth,
17+
int& outputHeight, int& outputChannels) const override;
2618

2719
const char* getName() const override { return "Sobel"; }
2820
};
2921

30-
} // namespace mini_image_pipe
22+
} // namespace mini_image_pipe

0 commit comments

Comments
 (0)