Skip to content

Commit 497b23d

Browse files
committed
fix(ci): remove CUDA build job and fix clang-format violations
GitHub Actions has no GPU/CUDA environment, so the cuda-build job always fails. Remove it and keep only the format-check static analysis. Also fix all clang-format violations across source files.
1 parent 689dd5f commit 497b23d

16 files changed

Lines changed: 119 additions & 146 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Continuous Integration
2-
# Validates code formatting and CUDA compilation
2+
# Validates code formatting
33

44
name: CI
55

@@ -42,34 +42,3 @@ jobs:
4242
with:
4343
clang-format-version: '17'
4444
fallback-style: 'LLVM'
45-
46-
cuda-build:
47-
name: CUDA Build
48-
runs-on: ubuntu-latest
49-
container:
50-
image: nvidia/cuda:12.4.1-devel-ubuntu22.04
51-
steps:
52-
- name: Checkout
53-
uses: actions/checkout@v4
54-
55-
- name: Install dependencies
56-
run: |
57-
apt-get update
58-
apt-get install -y --no-install-recommends cmake git build-essential
59-
rm -rf /var/lib/apt/lists/*
60-
61-
- name: Configure
62-
run: >
63-
cmake -S . -B build
64-
-DCMAKE_BUILD_TYPE=Release
65-
-DBUILD_TESTS=OFF
66-
-DCMAKE_CUDA_ARCHITECTURES="70;75;80;86;89;90"
67-
68-
- name: Build
69-
run: cmake --build build --target sgemm_benchmark -j$(nproc)
70-
71-
- name: Info
72-
run: |
73-
echo "✅ CUDA compilation successful"
74-
echo "ℹ️ Supported architectures: sm_70, sm_75, sm_80, sm_86, sm_89, sm_90"
75-
echo "ℹ️ GPU runtime tests require a CUDA-capable machine"

src/benchmark_runner.cuh

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* 这是一个便利函数,减少调用点的重复代码。
2525
*/
2626
inline auto defaultTensorCoreFallback() {
27-
return [](const float* A, const float* B, float* C, int M, int K, int N,
28-
cudaStream_t stream) {
27+
return [](const float *A, const float *B, float *C, int M, int K, int N, cudaStream_t stream) {
2928
launch_bank_conflict_free_sgemm<32>(A, B, C, M, K, N, stream);
3029
};
3130
}
@@ -42,15 +41,15 @@ inline auto defaultTensorCoreFallback() {
4241
*/
4342
class BenchmarkRunner {
4443
public:
45-
explicit BenchmarkRunner(const BenchmarkConfig& config) : config_(config) {}
44+
explicit BenchmarkRunner(const BenchmarkConfig &config) : config_(config) {}
4645

4746
/**
4847
* 运行所有配置的 benchmark
4948
*/
5049
void runAll() {
5150
printHeader();
5251

53-
for (const auto& [M, K, N] : config_.dimensions) {
52+
for (const auto &[M, K, N] : config_.dimensions) {
5453
runBenchmarks(M, K, N);
5554
}
5655

@@ -125,41 +124,41 @@ class BenchmarkRunner {
125124
benchmark.exportRooflineData(filename);
126125
}
127126

128-
void runStandardKernels(SGEMMBenchmark& benchmark, int M, int K, int N) {
127+
void runStandardKernels(SGEMMBenchmark &benchmark, int M, int K, int N) {
129128
printf("Running Naive SGEMM...\n");
130129
benchmark.run(
131130
"Naive",
132-
[](const float* A, const float* B, float* C, int M, int K, int N) {
131+
[](const float *A, const float *B, float *C, int M, int K, int N) {
133132
launch_naive_sgemm<32>(A, B, C, M, K, N);
134133
},
135134
M, K, N, config_.warmup_runs, config_.benchmark_runs, kStandardVerifyTolerance);
136135

137136
printf("Running Tiled SGEMM...\n");
138137
benchmark.run(
139138
"Tiled (32x32)",
140-
[](const float* A, const float* B, float* C, int M, int K, int N) {
139+
[](const float *A, const float *B, float *C, int M, int K, int N) {
141140
launch_tiled_sgemm<32>(A, B, C, M, K, N);
142141
},
143142
M, K, N, config_.warmup_runs, config_.benchmark_runs, kStandardVerifyTolerance);
144143

145144
printf("Running Bank Conflict Free SGEMM...\n");
146145
benchmark.run(
147146
"Bank Conflict Free",
148-
[](const float* A, const float* B, float* C, int M, int K, int N) {
147+
[](const float *A, const float *B, float *C, int M, int K, int N) {
149148
launch_bank_conflict_free_sgemm<32>(A, B, C, M, K, N);
150149
},
151150
M, K, N, config_.warmup_runs, config_.benchmark_runs, kStandardVerifyTolerance);
152151

153152
printf("Running Double Buffer SGEMM...\n");
154153
benchmark.run(
155154
"Double Buffer",
156-
[](const float* A, const float* B, float* C, int M, int K, int N) {
155+
[](const float *A, const float *B, float *C, int M, int K, int N) {
157156
launch_double_buffer_sgemm<32>(A, B, C, M, K, N);
158157
},
159158
M, K, N, config_.warmup_runs, config_.benchmark_runs, kStandardVerifyTolerance);
160159
}
161160

162-
void runTensorCoreKernels(SGEMMBenchmark& benchmark, int M, int K, int N) {
161+
void runTensorCoreKernels(SGEMMBenchmark &benchmark, int M, int K, int N) {
163162
if (!tensorCoresAvailable()) {
164163
int device;
165164
CUDA_CHECK(cudaGetDevice(&device));
@@ -174,9 +173,9 @@ class BenchmarkRunner {
174173
"conversion/fallback)...\n");
175174
benchmark.run(
176175
"Tensor Core (WMMA end-to-end)",
177-
[](const float* A, const float* B, float* C, int M, int K, int N) {
176+
[](const float *A, const float *B, float *C, int M, int K, int N) {
178177
launch_tensor_core_sgemm_with_fallback(A, B, C, M, K, N,
179-
defaultTensorCoreFallback());
178+
defaultTensorCoreFallback());
180179
},
181180
M, K, N, config_.warmup_runs, config_.benchmark_runs, kTensorCoreVerifyTolerance);
182181

src/cli_parser.cuh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ const std::vector<std::tuple<int, int, int>> BenchmarkConfig::DEFAULT_CASES = {
4242
namespace detail {
4343

4444
// 安全的字符串到整数转换
45-
inline bool safeStrToInt(const char* str, int* result, const char* argName) {
45+
inline bool safeStrToInt(const char *str, int *result, const char *argName) {
4646
if (str == nullptr || str[0] == '\0') {
4747
fprintf(stderr, "Error: %s requires a valid number\n", argName);
4848
return false;
4949
}
5050

51-
char* endptr;
51+
char *endptr;
5252
errno = 0;
5353
long val = strtol(str, &endptr, 10);
5454

@@ -80,15 +80,15 @@ inline bool safeStrToInt(const char* str, int* result, const char* argName) {
8080
*/
8181
class CliParser {
8282
public:
83-
CliParser(int argc, char** argv) : argc_(argc), argv_(argv) {}
83+
CliParser(int argc, char **argv) : argc_(argc), argv_(argv) {}
8484

8585
/**
8686
* 解析命令行参数
8787
*
8888
* @param config 输出配置对象
8989
* @return 0 成功,1 错误,2 显示帮助后退出
9090
*/
91-
int parse(BenchmarkConfig& config) {
91+
int parse(BenchmarkConfig &config) {
9292
for (int i = 1; i < argc_; ++i) {
9393
std::string arg = argv_[i];
9494

@@ -143,7 +143,7 @@ class CliParser {
143143
return 0;
144144
}
145145

146-
void printUsage(const char* program) const {
146+
void printUsage(const char *program) const {
147147
printf("Usage: %s [options]\n", program);
148148
printf("\nOptions:\n");
149149
printf(" -s, --size SIZE Benchmark one square SIZE x SIZE x SIZE case\n");
@@ -163,7 +163,7 @@ class CliParser {
163163
}
164164

165165
private:
166-
int parseSizeArg(int& i, BenchmarkConfig& config) {
166+
int parseSizeArg(int &i, BenchmarkConfig &config) {
167167
if (i + 1 >= argc_) {
168168
fprintf(stderr, "Error: -s requires a size argument\n");
169169
return 1;
@@ -182,7 +182,7 @@ class CliParser {
182182
return 0;
183183
}
184184

185-
int parseDimsArg(int& i, BenchmarkConfig& config) {
185+
int parseDimsArg(int &i, BenchmarkConfig &config) {
186186
if (i + 3 >= argc_) {
187187
fprintf(stderr, "Error: --dims requires M K N arguments\n");
188188
return 1;
@@ -203,7 +203,7 @@ class CliParser {
203203
return 0;
204204
}
205205

206-
int parseWarmupArg(int& i, BenchmarkConfig& config) {
206+
int parseWarmupArg(int &i, BenchmarkConfig &config) {
207207
if (i + 1 >= argc_) {
208208
fprintf(stderr, "Error: --warmup requires a number argument\n");
209209
return 1;
@@ -222,7 +222,7 @@ class CliParser {
222222
return 0;
223223
}
224224

225-
int parseBenchmarkArg(int& i, BenchmarkConfig& config) {
225+
int parseBenchmarkArg(int &i, BenchmarkConfig &config) {
226226
if (i + 1 >= argc_) {
227227
fprintf(stderr, "Error: --benchmark requires a number argument\n");
228228
return 1;
@@ -242,5 +242,5 @@ class CliParser {
242242
}
243243

244244
int argc_;
245-
char** argv_;
245+
char **argv_;
246246
};

src/kernels/tensor_core_benchmark.cuh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
* @param tolerance 验证容差
3434
* @return BenchmarkResult 包含性能数据
3535
*/
36-
inline BenchmarkResult runTensorCoreComputeOnlyBenchmark(
37-
SGEMMBenchmark &benchmark, int M, int K, int N, int warmup_runs = 5, int benchmark_runs = 20,
38-
VerifyTolerance tolerance = kTensorCoreVerifyTolerance) {
36+
inline BenchmarkResult
37+
runTensorCoreComputeOnlyBenchmark(SGEMMBenchmark &benchmark, int M, int K, int N,
38+
int warmup_runs = 5, int benchmark_runs = 20,
39+
VerifyTolerance tolerance = kTensorCoreVerifyTolerance) {
3940

4041
if (!tensorCoresAvailable() || !tensorCoreDimensionsSupported(M, K, N)) {
4142
throw CudaError("Tensor Core compute-only benchmark requires sm_70+ and "
@@ -102,7 +103,8 @@ inline BenchmarkResult runTensorCoreComputeOnlyBenchmark(
102103
result.time_ms = total_time_ms / benchmark_runs;
103104
double flops = 2.0 * result.M * result.N * result.K;
104105
result.gflops = (flops / (result.time_ms * 1e-3)) / 1e9;
105-
double bytes = (result.M * result.K + result.K * result.N + result.M * result.N) * sizeof(float);
106+
double bytes =
107+
(result.M * result.K + result.K * result.N + result.M * result.N) * sizeof(float);
106108
result.bandwidth_gb_s = (bytes / (result.time_ms * 1e-3)) / 1e9;
107109

108110
d_C.copyToHost(h_C.data(), M * N);

src/kernels/tensor_core_capabilities.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ inline bool tensorCoreDimensionsSupported(int M, int K, int N) {
4141
/**
4242
* 获取当前设备的 Tensor Core 信息字符串
4343
*/
44-
inline const char* getTensorCoreArchName() {
44+
inline const char *getTensorCoreArchName() {
4545
int device;
4646
CUDA_CHECK(cudaGetDevice(&device));
4747

src/kernels/tensor_core_launcher.cuh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ inline constexpr VerifyTolerance kTensorCoreVerifyTolerance{5e-2f, 1e-2f};
2424
* 签名与所有标准 SGEMM 内核一致:
2525
* void(const float* A, const float* B, float* C, int M, int K, int N, cudaStream_t stream)
2626
*/
27-
using FallbackKernel = std::function<void(const float*, const float*, float*, int, int, int,
28-
cudaStream_t)>;
27+
using FallbackKernel =
28+
std::function<void(const float *, const float *, float *, int, int, int, cudaStream_t)>;
2929

3030
/**
3131
* 默认 fallback 策略
3232
*
3333
* 提供一个空的 fallback(用于测试或显式配置场景)
3434
*/
35-
inline void nullFallback(const float*, const float*, float*, int, int, int, cudaStream_t = 0) {
35+
inline void nullFallback(const float *, const float *, float *, int, int, int, cudaStream_t = 0) {
3636
// 空实现 - 用于测试
3737
}
3838

@@ -57,7 +57,7 @@ inline void nullFallback(const float*, const float*, float*, int, int, int, cuda
5757
* @param stream CUDA 流
5858
*/
5959
template <typename FallbackFunc>
60-
inline void launch_tensor_core_sgemm_with_fallback(const float* A, const float* B, float* C, int M,
60+
inline void launch_tensor_core_sgemm_with_fallback(const float *A, const float *B, float *C, int M,
6161
int K, int N, FallbackFunc fallback,
6262
cudaStream_t stream = 0) {
6363
if (M <= 0 || K <= 0 || N <= 0) {
@@ -94,8 +94,8 @@ inline void launch_tensor_core_sgemm_with_fallback(const float* A, const float*
9494
*
9595
* 允许运行时选择 fallback 策略。
9696
*/
97-
inline void launch_tensor_core_sgemm_with_fallback(const float* A, const float* B, float* C, int M,
98-
int K, int N, const FallbackKernel& fallback,
97+
inline void launch_tensor_core_sgemm_with_fallback(const float *A, const float *B, float *C, int M,
98+
int K, int N, const FallbackKernel &fallback,
9999
cudaStream_t stream = 0) {
100100
launch_tensor_core_sgemm_with_fallback(A, B, C, M, K, N, fallback, stream);
101101
}

src/kernels/tensor_core_sgemm.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// - 每个模块有独立的测试面
3232
// ============================================================================
3333

34+
#include "tensor_core_benchmark.cuh"
3435
#include "tensor_core_capabilities.cuh"
3536
#include "tensor_core_compute.cuh"
3637
#include "tensor_core_launcher.cuh"
37-
#include "tensor_core_benchmark.cuh"

src/main.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "benchmark_runner.cuh"
1414
#include "cli_parser.cuh"
1515

16-
int main(int argc, char** argv) {
16+
int main(int argc, char **argv) {
1717
BenchmarkConfig config;
1818
CliParser parser(argc, argv);
1919

src/utils/benchmark.cuh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class SGEMMBenchmark {
8181
* @param tolerance 验证容差
8282
*/
8383
template <typename KernelFunc>
84-
BenchmarkResult run(const std::string& name, KernelFunc kernel_func, int M, int K, int N,
84+
BenchmarkResult run(const std::string &name, KernelFunc kernel_func, int M, int K, int N,
8585
int warmup_runs = 5, int benchmark_runs = 20,
8686
VerifyTolerance tolerance = kStandardVerifyTolerance) {
8787
BenchmarkResult result;
@@ -208,15 +208,15 @@ class SGEMMBenchmark {
208208
printf("--------------------------------------------------------------------"
209209
"------------\n");
210210

211-
for (const auto& result : results_) {
211+
for (const auto &result : results_) {
212212
result.print();
213213
}
214214

215215
printf("===================================================================="
216216
"============\n");
217217
}
218218

219-
void exportRooflineData(const std::string& filename) const {
219+
void exportRooflineData(const std::string &filename) const {
220220
std::ofstream file(filename);
221221
if (!file.is_open()) {
222222
fprintf(stderr, "Failed to open file: %s\n", filename.c_str());
@@ -225,7 +225,7 @@ class SGEMMBenchmark {
225225

226226
file << "kernel,M,K,N,time_ms,gflops,bandwidth_gb_s,arithmetic_intensity\n";
227227

228-
for (const auto& result : results_) {
228+
for (const auto &result : results_) {
229229
double flops = 2.0 * result.M * result.N * result.K;
230230
double bytes =
231231
(result.M * result.K + result.K * result.N + result.M * result.N) * sizeof(float);
@@ -240,7 +240,7 @@ class SGEMMBenchmark {
240240
printf("Approximate roofline data exported to: %s\n", filename.c_str());
241241
}
242242

243-
const std::vector<BenchmarkResult>& getResults() const { return results_; }
243+
const std::vector<BenchmarkResult> &getResults() const { return results_; }
244244
void clearResults() { results_.clear(); }
245245
cublasHandle_t getCublasHandle() const { return cublas_handle_; }
246246

@@ -254,7 +254,7 @@ class SGEMMBenchmark {
254254
// 实用工具函数
255255
// ============================================================================
256256

257-
inline void printPerformanceComparison(const std::vector<BenchmarkResult>& results,
257+
inline void printPerformanceComparison(const std::vector<BenchmarkResult> &results,
258258
float cublas_gflops) {
259259
printf("\n");
260260
printf("Performance Comparison (vs cuBLAS):\n");
@@ -264,7 +264,7 @@ inline void printPerformanceComparison(const std::vector<BenchmarkResult>& resul
264264
printf("---------------------------------------------------------------------"
265265
"-----------\n");
266266

267-
for (const auto& result : results) {
267+
for (const auto &result : results) {
268268
float percentage = (result.gflops / cublas_gflops) * 100.0f;
269269
printf(" %-30s | %10.2f | %8.1f%%\n", result.kernel_name.c_str(), result.gflops,
270270
percentage);

src/utils/benchmark_core.cuh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class CudaTimer {
2626
}
2727

2828
// 禁用拷贝
29-
CudaTimer(const CudaTimer&) = delete;
30-
CudaTimer& operator=(const CudaTimer&) = delete;
29+
CudaTimer(const CudaTimer &) = delete;
30+
CudaTimer &operator=(const CudaTimer &) = delete;
3131

3232
// 记录开始事件
3333
void start() { CUDA_CHECK(cudaEventRecord(start_)); }

0 commit comments

Comments
 (0)