Upload
dasyprocta
View
626
Download
2
Embed Size (px)
DESCRIPTION
関西 GPGPU 勉強会 #2 (10/13/2012) HistoPyramid を使用した Stream Compaction 及び Marching Cubes への応用を紹介したスライドです. 内容の正確性は保証しません.
Citation preview
HistoPyramidStream Compaction
@dasyprocta関西 GPGPU 勉強会 #2
Outline
● Stream Compaction
● HistoPyramid Algorithm
● Example: Marching Cubes
Stream Compaction
(c) Jeremy Vandelhttp://www.flickr.com/photos/jeremy_vandel/208714007/
Stream Compaction
入力ストリームからいらない要素を取り除く● Stream Reduction● Stream Filtering
Sequential Compaction
● 逐次処理によるコンパクション
for (i = 0, j = 0; i < N; ++i) {if (input[i] is wanted) {
output[j] = input[i];++j;
}}
* size(input) >= size(output)
Compaction Presence or Absence
● コンパクションなし
for (value in input) {if (value is wanted) {
process(value);}
}
● コンパクションあり
wanted = compaction(input)for (value is wanted) {
process(value);}
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
Stream Compaction Library
Thrust -> Reordering -> Stream Compaction● copy_if● remove● remove_if● unique● etc...
Compaction Efficiency
● CPU, GPU 間のデータ転送量の削減
● カーネル実行数の削減
● インアクティブスレッドの抑制
Compaction Efficiency
CPU, GPU 間のデータ転送量の削減
必要なデータのみの転送が可能に
CPU GPUGPUへ転送
何らかの処理
CPU読み戻し
Compaction Efficiency
カーネル実行数の削減
処理する必要のあるデータのみカーネル割り当て
Compaction Efficiency
インアクティブスレッドの抑制
仕事をしないカーネルの排除
void kernel(input) {if (input is unwanted)
return;
some works...}
Performance Trade-off
● コンパクション作成のオーバーヘッド
● コンパクションのためのバッファ増
● データが疎であるほど効果大
● カーネル負荷が高いほど効果大
Stream Compaction Application
● 画像処理
● ボリューム (空間) データ
● ヘテロなストリームの均質化
● etc...
HistoPyramid Algorithm
(c) jaredhttp://www.flickr.com/photos/generated/1164823755/in/photostream/
what's HistoPyramid
short for Histogram Pyramid● ミップマップライクなデータ構造を利用した
コンパクション手法
On-the-fly Point Clouds through Histogram Pyramids [Ziegler2006]
Algorithm Outline
1. Preprocess入力データから Predicate 値を生成
2. Buildup PhasePredicate 値によるピラミッドの構築
3. Traversal Phaseピラミッドからのデータ取得
Algorithm Outline
Predicate 値とは?
データの扱い方を決定する値● value = 0
棄却する要素
● value = 1保持する要素
● value > 1複製する要素
Preprocess Phase
入力データを Predicate 値に変換
Example:入力データが 1 以下の場合に棄却
0 1 0 0 1 1 1 0
0 8 1 0 4 2 5 0
入力データ
Predicate 値
Buildup Phase
ピラミッドの構築
ベースレベルからのリダクション● 加算による畳み込み
0 1 0 0 1 1 1 0
1 0 2 1
1 3
4
Predicate 値
Buildup Phase
ピラミッドデータ構造
● 必要なバッファサイズ (2-1 リダクション)
ベースレベルサイズ × 2 - 1
● トップレベルの値
コンパクションされた有効値の数
Buildup Phase
GPU 実装
基本は Parallel Reduction● 各レベルのバッファを保存する必要あり
カーネル最適化の参考Optimizing Parallel Reduction in CUDA [Harris]
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 }
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
Traversal PhaseGPU 実装
インデックス 1 つにカーネルを割り当て● トップレベル値の数のカーネル起動
ピラミッドが大きくなるほど探索コスト大
Algorithm Optimization
● 4-1 リダクション
● 5-1 リダクション
Algorithm Optimization
トップレベルまでのリダクション回数
● 2 要素を 1 つにまとめる場合
log2N● 4 要素を 1 つにまとめる場合
log4N
データ数 N は底の累乗でなければならない
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
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
● ミップマップライク● テクスチャキャッシュを考慮
Algorithm Optimization
5-1 Reduction
GPU-accelerated data expansion forthe Marching Cubes Algorithm [Dyken2010]
1 4 3 3
14
● 上位レベル値があれば下位レベル値は1つ必要無い
● 少しトリッキー
?
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 スレッド
Example, Marching Cubes
(c) jurvetsonhttp://www.flickr.com/photos/jurvetson/148925935/
立方体格子にポリゴンを貼るアルゴリズム
Marching Cubes
Marching Cubes: A High Resolution 3D Surface Construction Algorithm [Lorensen1987]
立方体パターン
● 各セルは 0 ~ 5 枚のトライアングルを生成● 対称等を考慮して全 256 パターン
Marching Cubes
パターンの登録
● セルとの接触判定● パターンをセルに登録
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
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
● 有効セル数の算出
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
参照
入力値からセルパターンを取得
Marching Cubes
有効セル数を基に描画
頂点バッファ生成 or ジオメトリシェーダー
● 頂点バッファ生成1. カーネルで GPU メモリに頂点バッファを生成
2. 3D API で頂点バッファを描画
● ジオメトリシェーダー1. 3D API でポイントリストとしてセルを描画
2. ジオメトリシェーダーでポリゴンを生成
Marching Cubes
3D API
OpenGL or DirectX● DrawIndirect 系 API
GPU メモリのデータを引数にできる
HistoPyramid のトップレベル値を
CPU のリードバック無しで利用可能
Marching Cubes on GPU 参考文献
HistoPyramid を用いた Marching Cubes
High-speed Marching Cubes using Histogram Pyramids[Dyken2007]
GPU-accelerated data expansionfor the Marching Cubes Algorithm[Dyken2010]
Exploit the Massive Parallelism!