README.md 2.59 KB
Newer Older
one's avatar
one committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# FastPT-C Host-side Overhead MRE

使用 FastPT 不转码模式适配 MatPL 的过程中发现了一定的性能损失,因此单独建立该项目来观察 FastPT 不转码模式 CUDA 兼容路径带来的 host 侧开销。它不依赖 MatPL 训练流程,只保留两个实验:

1. `device_query`:对比原生 HIP 路径的 `hipGetDevice` 和 FastPT-C 路径的 `cudaGetDevice`
2. `guard_loop`:通过 PyTorch C++ extension 对比 `c10::hip::HIPGuard``c10::cuda::CUDAGuard` 的循环调用开销。

第二个实验更接近 MatPL 的性能现象:当 CUDA ABI 的 PyTorch C++ extension 通过 FastPT-C 运行时,频繁使用 c10 device guard/device query 可能产生额外的 host 侧开销。

## 目录结构

```text
.
├── CMakeLists.txt
├── README.md
├── scripts
│   ├── bench_guard.py
│   ├── build.sh
│   ├── compare.py
│   ├── run_compare.sh
│   ├── run_one.sh
│   └── run_with_probe.sh
└── src
    ├── device_query.cpp
    ├── guard_ext.cpp
    └── runtime_probe.cpp
```

## 运行方式

在 DTK/FastPT 容器中执行:

```bash
cd /workspace/tools/fastpt_c_overhead_mre
bash scripts/run_compare.sh
```

脚本会构建并运行两种模式:

- `hip`:原生 DTK/HIP/PyTorch HIP 路径。
- `fastpt-C`:FastPT-C CUDA 兼容路径。

结果会写入:

```text
results/hip/
results/fastpt-C/
results/compare.csv
```

常用参数可以通过环境变量调整:

```bash
DEVICE=0 \
DEVICE_QUERY_LOOPS=1000000 \
DEVICE_QUERY_ROUNDS=7 \
GUARD_STEPS=10000 \
GUARD_WARMUP=1000 \
GUARD_ROUNDS=5 \
GUARD_INNER_LOOPS=0,1,2,4,8,16,32,64 \
bash scripts/run_compare.sh
```

## 结果解读

- 如果 `device_query``fastpt-C` 下明显更慢,说明 FastPT-C 的 CUDA runtime 兼容调用本身有额外开销。
- 如果 `guard_loop` 的差异随着 `inner_loops` 增大而扩大,说明 c10 CUDA guard/device query 路径已经足以复现主机侧开销。

这个复现的目标是帮助定位 FastPT-C 兼容层的主机侧开销来源;它不是 MatPL 训练性能测试,也不包含历史调查过程中使用过的所有实验分支。

## 可选 probe

如果需要进一步确认 `guard_loop` 中触发了多少 CUDA runtime 调用,可以使用 `LD_PRELOAD` probe:

```bash
cd /workspace/tools/fastpt_c_overhead_mre
bash scripts/run_with_probe.sh fastpt-C 0
```

结果写入:

```text
results-probe/fastpt-C/runtime_probe.csv
```

该 probe 统计 `cudaGetDevice``cudaSetDevice``hipGetDevice``hipSetDevice` 的调用次数、总耗时和平均耗时;默认 `run_compare.sh` 不会使用它。