diff --git a/S1/ICVXKH/example_cudacode.py b/S1/Example/example_cudacode.py similarity index 100% rename from S1/ICVXKH/example_cudacode.py rename to S1/Example/example_cudacode.py diff --git a/S1/ICVXKH/example_torchcode.py b/S1/Example/example_torchcode.py similarity index 100% rename from S1/ICVXKH/example_torchcode.py rename to S1/Example/example_torchcode.py diff --git a/S1/ICVXKH/prompt.txt b/S1/Example/prompt.txt similarity index 100% rename from S1/ICVXKH/prompt.txt rename to S1/Example/prompt.txt diff --git a/S1/ICVXKH/readme.md b/S1/Example/readme.md similarity index 100% rename from S1/ICVXKH/readme.md rename to S1/Example/readme.md diff --git a/S1/ICVXKH/run_code.py b/S1/Example/run_code.py similarity index 70% rename from S1/ICVXKH/run_code.py rename to S1/Example/run_code.py index 24e8694..a18a7cd 100644 --- a/S1/ICVXKH/run_code.py +++ b/S1/Example/run_code.py @@ -4,7 +4,7 @@ import torch import torch.nn as nn import time -from example_torchcode import Model, get_inputs, get_init_inputs +from example_torchcode import Model,get_inputs,get_init_inputs from example_cudacode import ModelNew def run_benchmark(): @@ -33,30 +33,17 @@ def run_benchmark(): print("-------------------- 精度对齐验证 --------------------") with torch.no_grad(): - output_torch = torch_model(*inputs) + output_torch = torch_model( *inputs) output_cuda = cuda_model(*inputs) - # 更严格的精度检查 - abs_diff = (output_torch - output_cuda).abs() - max_diff = abs_diff.max().item() - mean_diff = abs_diff.mean().item() - - print(f"最大差异: {max_diff:.6f}") - print(f"平均差异: {mean_diff:.6f}") - - precision_flag = torch.allclose(output_torch, output_cuda, rtol=1e-05, atol=1e-05) + precision_flag = torch.allclose(output_torch, output_cuda,rtol=1e-03) if precision_flag: print("✅ 精度对齐:两个模型的输出结果非常接近。") else: print("❌ 精度不一致!") print("\n-------------------- 性能加速比测试 --------------------") - num_iterations = 1000 # 增加迭代次数以获得更准确的时间测量 - - # Warm up - for _ in range(100): - _ = torch_model(*inputs) - _ = cuda_model(*inputs) + num_iterations = 100 # PyTorch 模型计时 torch.cuda.synchronize() @@ -74,15 +61,14 @@ def run_benchmark(): torch.cuda.synchronize() cuda_time = (time.time() - start_time) / num_iterations - print(f"PyTorch (matmul + relu) 平均执行时间: {torch_time:.6f} 秒") - print(f"自定义 CUDA ReLU 平均执行时间: {cuda_time:.6f} 秒") + print(f"PyTorch torch.relu 平均执行时间: {torch_time:.6f} 秒") + print(f"自定义 CUDA 内核 平均执行时间: {cuda_time:.6f} 秒") speedup = 0 if cuda_time > 0: speedup = torch_time / cuda_time print(f"加速比 (Speedup): {speedup:.2f}x") else: print("CUDA 内核执行时间为0,无法计算加速比。") - return precision_flag, speedup - + return precision_flag,speedup if __name__ == "__main__": - precision_flag, speedup = run_benchmark() \ No newline at end of file + precision_flag,speedup = run_benchmark() \ No newline at end of file diff --git a/S1/ICVXKH/参赛者需要提供的内容.md b/S1/Example/参赛者需要提供的内容.md similarity index 100% rename from S1/ICVXKH/参赛者需要提供的内容.md rename to S1/Example/参赛者需要提供的内容.md diff --git a/S1/README.md b/S1/README.md new file mode 100644 index 0000000..78fa8d9 --- /dev/null +++ b/S1/README.md @@ -0,0 +1,5 @@ +# 提交前的注意事项 + +- 确保已经阅读了[赛题入门](https://www.gitlink.org.cn/ccf-ai-infra/GPUCodeForces/tree/main/GPUCodeForces%E8%B5%9B%E9%A2%98%E5%85%A5%E9%97%A8.md)、[代码解读](https://www.gitlink.org.cn/ccf-ai-infra/GPUCodeForces/tree/main/GPUCodeForces%E4%BB%A3%E7%A0%81%E8%A7%A3%E8%AF%BB.md)的内容 +- 你的提交包含S1/Example下的四份完整文件 +- **提交时请不要更改原S1/Example/run_code.py的文件内容**