42
HistoPyramid Stream Compaction @dasyprocta 関西 GPGPU 勉強会 #2

HistoPyramid Stream Compaction

Embed Size (px)

DESCRIPTION

関西 GPGPU 勉強会 #2 (10/13/2012) HistoPyramid を使用した Stream Compaction 及び Marching Cubes への応用を紹介したスライドです. 内容の正確性は保証しません.

Citation preview

Page 1: HistoPyramid Stream Compaction

HistoPyramidStream Compaction

@dasyprocta関西 GPGPU 勉強会 #2

Page 2: HistoPyramid Stream Compaction

Outline

● Stream Compaction

● HistoPyramid Algorithm

● Example: Marching Cubes

Page 3: HistoPyramid Stream Compaction

Stream Compaction

(c) Jeremy Vandelhttp://www.flickr.com/photos/jeremy_vandel/208714007/

Page 4: HistoPyramid Stream Compaction

Stream Compaction

入力ストリームからいらない要素を取り除く● Stream Reduction● Stream Filtering

Page 5: HistoPyramid Stream Compaction

Sequential Compaction

● 逐次処理によるコンパクション

for (i = 0, j = 0; i < N; ++i) {if (input[i] is wanted) {

output[j] = input[i];++j;

}}

* size(input) >= size(output)

Page 6: HistoPyramid Stream Compaction

Compaction Presence or Absence

● コンパクションなし

for (value in input) {if (value is wanted) {

process(value);}

}

● コンパクションあり

wanted = compaction(input)for (value is wanted) {

process(value);}

Page 7: HistoPyramid Stream Compaction

GPU Stream Compaction

● Prefix Sum を利用したコンパクション

0 0 1 0 1 1 1 0

0 0 0 1 1 2 3 4

Predicate

Prefix Sum (exclusive scan)

Scatter

Page 8: HistoPyramid Stream Compaction

Stream Compaction Library

Thrust -> Reordering -> Stream Compaction● copy_if● remove● remove_if● unique● etc...

Page 9: HistoPyramid Stream Compaction

Compaction Efficiency

● CPU, GPU 間のデータ転送量の削減

● カーネル実行数の削減

● インアクティブスレッドの抑制

Page 10: HistoPyramid Stream Compaction

Compaction Efficiency

CPU, GPU 間のデータ転送量の削減

必要なデータのみの転送が可能に

CPU GPUGPUへ転送

何らかの処理

CPU読み戻し

Page 11: HistoPyramid Stream Compaction

Compaction Efficiency

カーネル実行数の削減

処理する必要のあるデータのみカーネル割り当て

Page 12: HistoPyramid Stream Compaction

Compaction Efficiency

インアクティブスレッドの抑制

仕事をしないカーネルの排除

void kernel(input) {if (input is unwanted)

return;

some works...}

Page 13: HistoPyramid Stream Compaction

Performance Trade-off

● コンパクション作成のオーバーヘッド

● コンパクションのためのバッファ増

● データが疎であるほど効果大

● カーネル負荷が高いほど効果大

Page 14: HistoPyramid Stream Compaction

Stream Compaction Application

● 画像処理

● ボリューム (空間) データ

● ヘテロなストリームの均質化

● etc...

Page 15: HistoPyramid Stream Compaction

HistoPyramid Algorithm

(c) jaredhttp://www.flickr.com/photos/generated/1164823755/in/photostream/

Page 16: HistoPyramid Stream Compaction

what's HistoPyramid

short for Histogram Pyramid● ミップマップライクなデータ構造を利用した

コンパクション手法

On-the-fly Point Clouds through Histogram Pyramids [Ziegler2006]

Page 17: HistoPyramid Stream Compaction

Algorithm Outline

1. Preprocess入力データから Predicate 値を生成

2. Buildup PhasePredicate 値によるピラミッドの構築

3. Traversal Phaseピラミッドからのデータ取得

Page 18: HistoPyramid Stream Compaction

Algorithm Outline

Predicate 値とは?

データの扱い方を決定する値● value = 0

棄却する要素

● value = 1保持する要素

● value > 1複製する要素

Page 19: HistoPyramid Stream Compaction

Preprocess Phase

入力データを Predicate 値に変換

Example:入力データが 1 以下の場合に棄却

0 1 0 0 1 1 1 0

0 8 1 0 4 2 5 0

入力データ

Predicate 値

Page 20: HistoPyramid Stream Compaction

Buildup Phase

ピラミッドの構築

ベースレベルからのリダクション● 加算による畳み込み

0 1 0 0 1 1 1 0

1 0 2 1

1 3

4

Predicate 値

Page 21: HistoPyramid Stream Compaction

Buildup Phase

ピラミッドデータ構造

● 必要なバッファサイズ (2-1 リダクション)

ベースレベルサイズ × 2 - 1

● トップレベルの値

コンパクションされた有効値の数

Page 22: HistoPyramid Stream Compaction

Buildup Phase

GPU 実装

基本は Parallel Reduction● 各レベルのバッファを保存する必要あり

カーネル最適化の参考Optimizing Parallel Reduction in CUDA [Harris]

Page 23: HistoPyramid Stream Compaction

Traversal Phase

トップレベルからベースレベルへ

トップレベル値範囲のインデックスから入力データの有効インデックスを取得

0 1 0 0 1 1 1 0

1 0 2 1

1 3

4

1 4 5 6

0,1,2,3{ 0, 1, 2, 3 }

{ 1, 4, 5, 6 }

Page 24: HistoPyramid Stream Compaction

Traversal Phase

探索範囲の決定

Example: インデックス 2 を探索レベル降下時に属する範囲の先頭値を引く

1 3

4

[0, 1) [1, 4)

2 1

1 1

key = 2

key = 1 = 2-1

key = 1 = 1-0

[0, 2) [2, 3)

[0, 1) [1, 2)

5

Page 25: HistoPyramid Stream Compaction

Traversal PhaseGPU 実装

インデックス 1 つにカーネルを割り当て● トップレベル値の数のカーネル起動

ピラミッドが大きくなるほど探索コスト大

Page 26: HistoPyramid Stream Compaction

Algorithm Optimization

● 4-1 リダクション

● 5-1 リダクション

Page 27: HistoPyramid Stream Compaction

Algorithm Optimization

トップレベルまでのリダクション回数

● 2 要素を 1 つにまとめる場合

log2N● 4 要素を 1 つにまとめる場合

log4N

データ数 N は底の累乗でなければならない

Page 28: HistoPyramid Stream Compaction

Algorithm Optimization

4-1 Reduction 1D Pyramid

0 1 0 0 1 1 1 1

1 4 3 3

11

0 1 1 1 1 0 1 1

Page 29: HistoPyramid Stream Compaction

Algorithm Optimization4-1 Reduction 2D Pyramid

0 1

0 0

1 1

1 1 1 4

3 311

0 1

1 1

1 0

1 1

● ミップマップライク● テクスチャキャッシュを考慮

Page 30: HistoPyramid Stream Compaction

Algorithm Optimization

5-1 Reduction

GPU-accelerated data expansion forthe Marching Cubes Algorithm [Dyken2010]

1 4 3 3

14

● 上位レベル値があれば下位レベル値は1つ必要無い

● 少しトリッキー

?

Page 31: HistoPyramid Stream Compaction

Comparison with the OtherPrefix Sum コンパクションとの違い

出力駆動と入力駆動の差

● HistoPyramid ● Prefix Sum

0 0 1 0 1 1 1 0

0 0 0 1 1 2 3 4

0 0 1 0 1 1 1 0

0 1 2 1

1 3

4

Scatter による 8 スレッド頂点値による 4 スレッド

Page 32: HistoPyramid Stream Compaction

Example, Marching Cubes

(c) jurvetsonhttp://www.flickr.com/photos/jurvetson/148925935/

Page 33: HistoPyramid Stream Compaction

立方体格子にポリゴンを貼るアルゴリズム

Marching Cubes

Marching Cubes: A High Resolution 3D Surface Construction Algorithm [Lorensen1987]

Page 34: HistoPyramid Stream Compaction

立方体パターン

● 各セルは 0 ~ 5 枚のトライアングルを生成● 対称等を考慮して全 256 パターン

Page 35: HistoPyramid Stream Compaction

Marching Cubes

パターンの登録

● セルとの接触判定● パターンをセルに登録

Page 36: HistoPyramid Stream Compaction

0 0 0 1 1 0 0 0

0 0 1 1 1 1 0 0

0 1 1 0 1 1 0 0

0 1 0 0 1 0 0 0

0 1 0 0 1 1 1 1

0 1 1 0 0 0 0 1

0 0 1 1 1 1 1 1

0 0 0 0 0 0 0 0

Marching Cubes

HistoPyramid ベースレベルの生成

● ポリゴンを貼るセルValue = 1

● 空のセルValue = 0

Page 37: HistoPyramid Stream Compaction

Marching Cubes

HistoPyramid の構築

0 0 0 1 1 0 0 0

0 0 1 1 1 1 0 0

0 1 1 0 1 1 0 0

0 1 0 0 1 0 0 0

0 1 0 0 1 1 1 1

0 1 1 0 0 0 0 1

0 0 1 1 1 1 1 1

0 0 0 0 0 0 0 0

0 3 3 0

2 1 3 0

2 1 2 3

0 2 2 2

6 6

5 926

● 有効セル数の算出

Page 38: HistoPyramid Stream Compaction

Marching Cubes

HistoPyramid の探索

0 0 0 1 1 0 0 0

0 0 1 1 1 1 0 0

0 1 1 0 1 0 0

0 1 0 0 1 0 0 0

0 1 0 0 1 1 1 1

0 1 1 0 0 0 0 1

0 0 1 1 1 1 1 1

0 0 0 0 0 0 0 0

0 3 3 0

2 1 0

2 1 2 3

0 2 2 2

6

5 926

入力値: 10

6 3

1

参照

入力値からセルパターンを取得

Page 39: HistoPyramid Stream Compaction

Marching Cubes

有効セル数を基に描画

頂点バッファ生成 or ジオメトリシェーダー

● 頂点バッファ生成1. カーネルで GPU メモリに頂点バッファを生成

2. 3D API で頂点バッファを描画

● ジオメトリシェーダー1. 3D API でポイントリストとしてセルを描画

2. ジオメトリシェーダーでポリゴンを生成

Page 40: HistoPyramid Stream Compaction

Marching Cubes

3D API

OpenGL or DirectX● DrawIndirect 系 API

GPU メモリのデータを引数にできる

HistoPyramid のトップレベル値を

CPU のリードバック無しで利用可能

Page 41: HistoPyramid Stream Compaction

Marching Cubes on GPU 参考文献

HistoPyramid を用いた Marching Cubes

High-speed Marching Cubes using Histogram Pyramids[Dyken2007]

GPU-accelerated data expansionfor the Marching Cubes Algorithm[Dyken2010]

Page 42: HistoPyramid Stream Compaction

Exploit the Massive Parallelism!