読書活動 PPMP Ch.9, 10

CHAPTER 9 Parallel histogram

  • 面白くなってまいりました。
  • Baseline approach では、atomicAdd() を使います。Kernel から使える AtomicOps あるの?まじで?速いわけがないのはわかるだけに存在する事実にびっくり。しかも modern GPU の atomic ops は last level cache 上で完結できるらしい(hit した場合)。"Because the access time to the last-level cache is in tens of cycles rather than hundreds of cycles, the throughput of atomic operations is improved by at least an order of magnitude compared to early generations of GPU. This is an important reason why most modern GPUs support atomic operations in the last-level cache." すごいじゃん!
  • Privatization: は thread block 間で独立に histogram を計算しておき、最後に合算する。contention が減るので速くなる。ただし相変わらず atmicAdd は必要。
  • 発展形で、per-thread block の histogram を shared memory に置く。もっと速い。atomicAdd は shared memory に対しても使える。
  • Shared memory って要するにプログラマがコントロールできる L1 cache なのだね。consistency とかないので write back や inter-core の invalidation とかが必要ないぶん便利ではあるが、それをプログラマが exploit しないといけないので大変。CPU は基本的にそういうのナシなので諦めがつきやすい。むかしのゲーム機とかだと consistency level いじったりするので似てたといえば似てたかな。まともな OS を載せるにはそういうの負荷だけれど。

CHAPTER 10 Reduction

  • reduce() ね。
  • 並列でやるには reduction tree をつくる。概念的なツリーであってデータ構造ではない。
  • このあと最適化の話があり、control divergence の最小化、memory coalescing の最大化、そして thread coarsening と全部入りの最適化ステップを踏んでく。面白い。
  • 特に control divergence の最適化で同じコードパスを通るスレッドが同じ warp に収まるよう細工するのはお見事。
  • こういうの、レイテンシ以外にどういう指標をみてチューンできるのかプロファイラの機能を知りたいねえ。