Skip to content

快速开始

本文档帮助你快速配置环境并运行第一个 benchmark。


环境要求

组件版本要求检查命令
CUDA Toolkit12.xnvcc --version
CMake3.18+cmake --version
C++ 编译器C++17 支持g++ --version
GPUSM 7.0+nvidia-smi

步骤 1: 克隆仓库

bash
git clone https://github.com/LessUp/mini-inference-engine.git
cd mini-inference-engine

步骤 2: Debug 构建 + 测试

如果当前 shell 中激活了 Conda 或其他自定义 C++ 工具链,优先使用系统 GCC 12 / G++ 12 预设。

bash
# 使用系统 GCC 12 / G++ 12 配置 Debug 构建
cmake --preset gcc-cuda

# 编译
cmake --build --preset gcc-cuda

# 运行测试
ctest --preset gcc-cuda

预期输出:

Test project /path/to/mini-inference-engine/build-gcc-cuda
    Start 1: test_config
1/8 Test #1: test_config .....................   Passed    0.01 sec
    Start 2: test_logger
2/8 Test #2: test_logger .....................   Passed    0.01 sec
...
8/8 Test #8: test_gemm .......................   Passed    0.52 sec

100% tests passed, 0 tests failed out of 8

步骤 3: Release 构建 + Benchmark

bash
# 使用系统 GCC 12 / G++ 12 配置 Release 构建
cmake --preset release-gcc-cuda

# 编译
cmake --build --preset release-gcc-cuda

# 运行 benchmark
./build-release-gcc-cuda/benchmark

预期输出:

=== Mini-Inference Engine Benchmark ===
GPU: NVIDIA GeForce RTX 3080
Matrix size: 1024 x 1024

Kernel              Time (ms)   TFLOPS    vs cuBLAS
----------------------------------------------------
Naive               15.23       0.14      10.2%
Tiled               7.61        0.28      20.4%
Coalesced           6.12        0.35      25.3%
Double Buffer       3.85        0.56      40.8%
Register Blocked    1.82        1.19      86.5%
Vectorized          1.71        1.25      91.2%
cuBLAS              1.56        1.37      100.0%

步骤 4: 运行 MNIST Demo

bash
./build-release/mnist_demo

这会使用推理引擎在 MNIST 数据集上验证正确性。


常见问题

Q: 找不到 CUDA?

确保 CUDA_PATH 环境变量正确设置:

bash
export CUDA_PATH=/usr/local/cuda
export PATH=$CUDA_PATH/bin:$PATH
export LD_LIBRARY_PATH=$CUDA_PATH/lib64:$LD_LIBRARY_PATH

Q: 测试被跳过?

如果没有可用的 NVIDIA GPU,GPU 测试会自动跳过。这是预期行为。

Q: 编译错误?

  1. 检查 CUDA 版本是否兼容
  2. 检查 C++ 编译器是否支持 C++17
  3. 如果 Conda 已激活,优先使用 cmake --preset gcc-cuda

下一步

MIT License | CUDA GEMM optimization tutorial