1. Profiling and measuring baseline


什麼是 profiling?

Profiling 是一隻用來分析 program 在 runtime 時的行為以及各種硬體資源使用量的 process

我們希望透過 profiling 知道 program 的效能瓶頸以便於後續優化,舉個例子,假設一個 program 他大多數的時間都花在資料的搬移,那優化他的計算的效益就遠不如優化記憶體分配

具體要分析的指標有如下

description insight
kernel execution time 各個 kernel 的執行時間 知道哪個 kernel 跑最慢
Memory Throughput 每秒鐘 data read write 的數量 知道 memory 是不是瓶頸
CU Utilization 可用 Unit 的比例 知道 GPU 的使用率有多高
Occupancy 可用 Warp 的比例 越高越能 hide latency
Branch divergence 知道 Warp 中 divergence 的比例 太多 divegence 的話平行效率會下降

<aside> <img src="/icons/info-alternate_blue.svg" alt="/icons/info-alternate_blue.svg" width="40px" />

Note

Occupancy 的定義是 Active Warp 的數量除以一個 CU 中最大可用的 Warp 數量,可以用多少 Warp 取決於硬體資源,有多少 Warp 可執行取決於 Kernel execution,舉例來說當一個Warp 要執行 I/O 指令時,但是他要存取的資料還沒準備好(可能還在傳輸),這時 Warp Scheduler 就會先執行其他的Warp,以 hide 這個 I/O 操作的 Latency,越高的 Occupancy 越可以 hide memory lantency。

</aside>

Warp State

Warp 的狀態在 HIP 的文件中是有明確定義的,總共有四種,四種狀態並不互斥,這邊的微架構用語,比較偏向 ROCm 的,CUDA 中的用語有些微差異,但不影響理解。

Active

一個 Warp 從他的 threads 開始執行到所有的 threads 完成 kernel 為止,被視為是 active 的,warp scheduler 每個 cycle 會從 active 的集合中挑選 warps;被挑選到的 warps 會發出(issue)它們的指令。

Eligible

Eligible warp 是指 Active 且已準備好發出下一條指令的 warp,一個 warps 要成為 Eligible,必須

Eligible Warps 是 issue 的候選人,如果 Eligible warps 很少,通常代表有 Dependency 或 Memory stalled,這通常是效能調校的重要目標。