有序合併與 Co-rank 概念 練習題 (Practice - Merge Foundations and the Co-rank Concept)


Question 1 - Sequential Merge 結構與複雜度 [recall]

描述 merge_sequential 的兩段式結構,並說明其演算法複雜度為何。

Question 2 - Stability 與比較運算子 [recall]

Merge 的 tie-breaking 為何使用 A[i] <= B[j](而非 A[i] < B[j])?改用嚴格小於會發生什麼?

Question 3 - Rank、Co-rank 與不變式 [recall]

定義 rank k 與 co-rank (i, j),並寫出它們之間恆成立的不變式(invariant)。

Question 4 - co_rank 的搜尋邊界初始化 [recall]

co_rank 函式中 ii_lowj_low 的初始值各是什麼?為何 i_low 不直接設為 0?

Question 5 - co_rank 的接受條件與 delta [recall]

co_rank 的 while-loop 在什麼條件下停止(接受當前 ij)?delta 為何用 ceil 而非 floor?

Question 6 - Basic Merge Kernel 的兩次 co_rank [recall]

Basic merge kernel 中每個 thread 為何要呼叫 co_rank 兩次?各取得什麼?

Question 7 - Circular Buffer 的 Simplified Model [recall]

為何 circular buffer kernel 要引入「simplified buffer access model」?co_rank_circular 比原 co_rank 多了哪些參數?

Question 8 - 為何載 2x 元素只保證生成 x [recall]

Tiled merge kernel 每輪在 shared memory 載入 A、B 各 tile_size 個(共 2×tile_size),為何只能保證生成 tile_size 個輸出元素?

Question 9 - Exercise 1:計算 C[8] 的 co-rank [application]

合併 A=(1,7,8,9,10)B=(7,10,10,12),求 C[8] 的 co-rank 值。

Question 10 - Exercise 4:幾個 thread 做 binary search [application]

合併兩陣列大小 1,030,400 與 608,000,每 thread 合併 8 個元素,block size = 1024。(a) basic kernel 中幾個 thread 在 global memory 做 binary search?(b) tiled kernel 中幾個在 global memory?(c) tiled kernel 中幾個在 shared memory?

Question 11 - Tiled Kernel 的 shared memory 與迭代次數 [application]

tiled kernel 使用 tile_size = 1024,每 block 需配置多少 shared memory(bytes)?若 m=33000, n=31000、用 16 個 block,每 block 的 while-loop 跑幾輪?

Question 12 - Basic vs Tiled vs Circular 的記憶體效率比較 [analysis]

比較 basic、tiled、circular buffer 三種 merge kernel 在 coalescing 與 shared memory 利用率上的差異,並說明為何這個演進方向對 merge 是值得的。

Question 13 - Thread Coarsening 對 Merge 的必要性與取捨 [analysis]

為何 thread coarsening 對 merge 是「必需品」而非單純優化?它攤提的成本與 reduction/scan 中 coarsening 攤提的成本有何不同?過度 coarsening 的代價是什麼?