靜電位圖計算 練習題 (Practice - DCS Algorithm and Scatter vs Gather Kernel Design)


Question 1 - DCS 方法與複雜度 [recall]

說明 Direct Coulomb Summation (DCS) 如何計算單一 grid point 的靜電位,並寫出其計算複雜度與為何「隨體積平方成長」。

Question 2 - Loop Interchange 合法性與解鎖的最佳化 [recall]

Fig.18.4 把 atom 迴圈交換到最外層。(a) 為何此 loop interchange 合法?(b) 交換後解鎖了哪些 loop-invariant 計算的提取?

Question 3 - Scatter Kernel 與 atomicAdd [recall]

Fig.18.5 的 scatter kernel 如何把工作分給 thread?它為何必須使用 atomicAdd,且 CHUNK_SIZE 受什麼限制?

Question 4 - Gather Kernel 與無 Atomic [recall]

Fig.18.6 的 gather kernel 如何分配工作而不需 atomic?它建立在哪一份序列碼上?需要什麼小轉換才能平行化?

Question 5 - Gather 的 Arithmetic Intensity 與 Constant Cache [recall]

Fig.18.6 的 gather kernel 雖然每個 thread 要讀所有 atom,為何 global memory bandwidth 不是瓶頸?它的 arithmetic intensity 是多少?

Question 6 - Thread Coarsening 的 Register 重用 [recall]

Fig.18.8 的 thread coarsening 讓一個 thread 算同一 row 上 4 個 grid point。哪些量被取一次存進 register 重複使用?處理「1 個 atom × 4 個 grid point」的 constant 存取與 FP ops 從多少降到多少?

Question 7 - Cutoff Summation 的複雜度與遠端原子 [recall]

Cutoff summation 如何把 DCS 的複雜度從 O(V²) 降到 O(V)?被切掉的「遠端原子」貢獻如何處理?這屬於哪一類演算法策略?

Question 8 - Cutoff Binning 的 Control Divergence 與記憶體選擇 [recall]

在 grid-centric cutoff binning 中,(a) control divergence 從何而來?(b) 為何 atom 從 constant memory 改放 global memory,並如何緩解頻寬?

Question 9 - Binning 資料結構與 Neighborhood List [recall]

在 cutoff binning 中,atom 如何被組織成 bins?grid point 的「neighborhood」如何定義與表示?為何要在 launch grid 之前就先算好?

Question 10 - Exercise 2:Coarsening Factor 8 的運算量比較 [application]

對 coarsening factor 8,比較 Fig.18.8(coarsened,1 次迴圈迭代)與 Fig.18.6(gather,對應 8 次迭代)在 constant 存取、FP 運算與分支上的差異。

Question 11 - Per-Block Neighborhood 與 Supercircle 計算 [application]

假設 grid spacing = 0.5 Å、block = 8×8×8、cutoff = 12 Å。(a) 每個 block 覆蓋多大的 energy grid 體積?(b) supercircle 半徑公式與其數值為何?(c) 一個 block 有幾個 grid point 各自帶 cutoff 圈?

Question 12 - Dummy Atoms vs Overflow List [application]

某資料集的原子在空間中分佈不均。為了 memory coalescing 需讓所有 bin 同樣大小。(a) 用 dummy atoms 補滿有何兩個負面效應?(b) overflow list 是更好的設計,如何運作並隱藏延遲?

Question 13 - Scatter vs Gather 的平行化兩難 [analysis]

為何說「最佳化的序列碼反而更不適合平行化」?比較 scatter 與 gather 兩種 DCS kernel 的 thread 對應、寫入模式、效能瓶頸與單 thread 計算量,並說明本章如何化解此兩難。

Question 14 - Coalesced vs Strided 寫回 [analysis]

Fig.18.8(連續指派)與 Fig.18.10(interleaved 指派)運算量完全相同,為何後者效能更好?分析其 warp 寫入位址型態,並說明為何 coalescing 是「免費」的優化、以及為何它不影響對 atoms[] 的讀取。

Question 15 - DCS vs Cutoff 的演算法選擇權衡 [analysis]

同一問題常有多種演算法。比較 DCS 與 cutoff binning 在精度、複雜度、平行度、大型系統適用性上的取捨,並說明 cutoff binning 為何選擇 grid-centric (gather) 分解而非 atom-centric。