Skip to content

Commit 90e136b

Browse files
committed
refactor(benchmark): hide CudaTimer as internal detail and remove dead code
- Move CudaTimer into detail namespace as implementation detail - Only measureGpuTime() needs it, not part of public API - Remove unused startEvent()/stopEvent() methods - Delete SgemmReferenceCalculator class (unused for 78 lines) - Was designed for reference computation but never used - SGEMMBenchmark and tests use inline cuBLAS calls instead
1 parent 2a2c98d commit 90e136b

2 files changed

Lines changed: 6 additions & 91 deletions

File tree

src/utils/benchmark_core.cuh

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
#include <cuda_runtime.h>
55

66
// ============================================================================
7-
// CUDA 事件计时器
7+
// CUDA 性能测量器
88
// ============================================================================
99

10+
namespace detail {
11+
1012
/**
11-
* RAII 包装的 CUDA 事件计时器
12-
*
13-
* 提供精确的 GPU 时间测量,使用 CUDA 事件机制。
14-
* 适用于内核执行时间、数据传输时间等测量。
13+
* RAII 包装的 CUDA 事件计时器(内部实现)
1514
*/
1615
class CudaTimer {
1716
public:
@@ -45,18 +44,12 @@ class CudaTimer {
4544
return ms;
4645
}
4746

48-
// 获取开始和结束事件(用于手动记录)
49-
cudaEvent_t startEvent() { return start_; }
50-
cudaEvent_t stopEvent() { return stop_; }
51-
5247
private:
5348
cudaEvent_t start_;
5449
cudaEvent_t stop_;
5550
};
5651

57-
// ============================================================================
58-
// 性能测量器
59-
// ============================================================================
52+
} // namespace detail
6053

6154
/**
6255
* 通用的 GPU 操作性能测量器
@@ -75,7 +68,7 @@ float measureGpuTime(RunFunc func, int warmup_runs = 5, int benchmark_runs = 20)
7568
CUDA_CHECK(cudaDeviceSynchronize());
7669

7770
// 计时运行
78-
CudaTimer timer;
71+
detail::CudaTimer timer;
7972
timer.start();
8073
for (int i = 0; i < benchmark_runs; ++i) {
8174
func();

src/utils/benchmark_cublas.cuh

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -73,81 +73,3 @@ class CublasSgemm {
7373
private:
7474
cublasHandle_t handle_;
7575
};
76-
77-
// ============================================================================
78-
// SGEMM 参考计算器
79-
// ============================================================================
80-
81-
/**
82-
* 计算参考 SGEMM 结果并验证
83-
*
84-
* 提供完整的参考计算流程:
85-
* - 设备内存分配
86-
* - 随机矩阵初始化
87-
* - cuBLAS 参考计算
88-
* - 结果验证
89-
*/
90-
class SgemmReferenceCalculator {
91-
public:
92-
SgemmReferenceCalculator() = default;
93-
94-
/**
95-
* 初始化参考数据
96-
*
97-
* @param M, K, N 矩阵维度
98-
* @param seed 随机种子(可重现)
99-
*/
100-
void initialize(int M, int K, int N, unsigned int seed_A = 42, unsigned int seed_B = 123) {
101-
M_ = M;
102-
K_ = K;
103-
N_ = N;
104-
105-
h_A_.resize(M * K);
106-
h_B_.resize(K * N);
107-
108-
initRandomMatrix(h_A_.data(), M, K, -1.0f, 1.0f, seed_A);
109-
initRandomMatrix(h_B_.data(), K, N, -1.0f, 1.0f, seed_B);
110-
111-
d_A_ = std::make_unique<DeviceMemory<float>>(M * K);
112-
d_B_ = std::make_unique<DeviceMemory<float>>(K * N);
113-
d_C_ref_ = std::make_unique<DeviceMemory<float>>(M * N);
114-
115-
d_A_->copyFromHost(h_A_.data(), M * K);
116-
d_B_->copyFromHost(h_B_.data(), K * N);
117-
}
118-
119-
/**
120-
* 计算参考结果
121-
*/
122-
void computeReference() {
123-
cublas_.sgemm(d_A_->get(), d_B_->get(), d_C_ref_->get(), M_, K_, N_);
124-
}
125-
126-
/**
127-
* 获取主机端参考结果
128-
*/
129-
std::vector<float> getReferenceResult() {
130-
std::vector<float> h_ref(M_ * N_);
131-
d_C_ref_->copyToHost(h_ref.data(), M_ * N_);
132-
return h_ref;
133-
}
134-
135-
// 访问器
136-
const std::vector<float> &hostA() const { return h_A_; }
137-
const std::vector<float> &hostB() const { return h_B_; }
138-
float *deviceA() { return d_A_->get(); }
139-
float *deviceB() { return d_B_->get(); }
140-
float *deviceCRef() { return d_C_ref_->get(); }
141-
CublasSgemm &cublas() { return cublas_; }
142-
int M() const { return M_; }
143-
int K() const { return K_; }
144-
int N() const { return N_; }
145-
146-
private:
147-
int M_ = 0, K_ = 0, N_ = 0;
148-
std::vector<float> h_A_, h_B_;
149-
std::unique_ptr<DeviceMemory<float>> d_A_;
150-
std::unique_ptr<DeviceMemory<float>> d_B_;
151-
std::unique_ptr<DeviceMemory<float>> d_C_ref_;
152-
CublasSgemm cublas_;
153-
};

0 commit comments

Comments
 (0)