Skip to content

一个基于cuda13,在windows上用来测试显卡和cpu带宽的程序/A program based on cuda13 for testing graphics card and cpu bandwidth on windows

License

Notifications You must be signed in to change notification settings

Fin2003/Bandwidth_Test_CPU2GPU

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT 这是一个小工具,用来测试你的cpu和gpu直接的带宽速度

A program based on cuda13 for testing graphics card and cpu bandwidth on windows

如何使用:

一、在该文件夹打开终端

  • 文件资源管理器定位到本目录后,在地址栏输入 powershellcmd 回车;
  • 或者在空白处 Shift+右键 → 在终端中打开。
  • 运行 ./bandwidth.exe --size 512 --iters 50 --async

二、直接运行(无需安装 CUDA Toolkit)

  • 只下载 bandwidth.exe 到任意目录:
    • 双击运行:程序会使用默认参数并在结束时提示 “Press Enter to exit...”,窗口不会秒关;
    • 目标机器仅需安装兼容的 NVIDIA 显卡驱动(无需 CUDA Toolkit)。
    • 在终端中运行可以自定义参数(size以及迭代次数等)(见方法一):

三、在本机从源码编译(可选)

  1. 打开 PowerShell,执行下列命令(按需修改 nvcc 与 cl 的路径):
New-Item -ItemType Directory -Force C:\Temp | Out-Null
$env:TEMP='C:\Temp'; $env:TMP='C:\Temp'
$nvcc  = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe"
$ccbin = "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64"
& "$nvcc" -O3 -std=c++17 -ccbin "$ccbin" -Xcompiler "/utf-8 /MT" -cudart=static .\bandwidth.cu -o .\bandwidth.exe
.\bandwidth.exe --size 512 --iters 50 --async
  1. 运行示例:
./bandwidth.exe --size 512 --iters 50 --async

四、参数说明 Flags

  • --size <MiB>: 单次拷贝大小(MiB)。默认 256。
  • --iters <N>: 每项测试迭代次数。默认 50。
  • --async: 使用异步 cudaMemcpyAsync。开启后仅测试 Pinned H2D/D2H(Pageable 在异步下意义不大,已跳过)。
  • 无参数启动(例如双击):使用默认参数并在结束时暂停等待回车。

五、输出解读

  • Transfer: 测试类型(Pageable/Pinned,H2D/D2H;带 (A) 表示异步)。
  • Size/Iters/Time: 单次大小、迭代次数、累计时间(ms)。
  • BW: (Size×Iters)/Time 的平均带宽(GB/s)。
  • 最后一行 Best H2D/D2H 是各方向的最大值(在多项平均带宽中取最大)。

内存类型区别

  • Pageable: 普通主机内存(malloc/new),GPU 无法直接 DMA,需要临时页锁定/中转,带宽较低。
  • Pinned: 页锁定内存(cudaHostAlloc),GPU 可直接 DMA,带宽更高、更稳定。

异步 vs 同步

  • 同步 (cudaMemcpy): 调用线程阻塞到拷贝完成,无法与计算重叠。
  • 异步 (cudaMemcpyAsync): 立即返回,拷贝在后台执行,可与 GPU 计算或其他传输重叠,提升整体吞吐。
  • 注意: 只有 Pinned 内存才能真正实现异步重叠;Pageable 在异步下仍会被"同步化"。

六、常见问题

  • 中文乱码:先在终端执行 chcp 65001 再运行;程序也会尝试在 Windows 下设置 UTF-8 控制台。
  • 运行报错 “driver is insufficient for CUDA runtime”:说明目标机驱动版本低于可执行所需的 CUDA Runtime。
    • 解决 A:升级 NVIDIA 驱动到支持 CUDA 13 的版本;
    • 解决 B:如必须兼容旧驱动,可在本机用对应版本(例如 12.9)的 CUDA 重新编译一份。

⭐ 如果喜欢的话麻烦点一个star,我在找实习,对我十分重要 Star History Chart

About

一个基于cuda13,在windows上用来测试显卡和cpu带宽的程序/A program based on cuda13 for testing graphics card and cpu bandwidth on windows

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages