...

XcalableMPにおける GPU/CPUワークシェアリング

by user

on
Category: Documents
3

views

Report

Comments

Transcript

XcalableMPにおける GPU/CPUワークシェアリング
XcalableMPにおける
GPU/CPUワークシェアリング
小田嶋 哲哉†1,朴 泰祐†1,2,塙 敏博†3,児玉 祐悦†1,2,
Raymond Namyst†4,Samuel Thibault†4,
Olivier Aumage†4 ,佐藤 三久†1,2
†1 筑波大学
大学院 システム情報工学研究科
†2 筑波大学 計算科学研究センター
†3 東京大学 情報基盤センター
†4 Bordeaux Sud-Ouest INRIA research center
日仏共同研究 FP3C
第2回XcalableMPワーク
ショップ 2014/11/24
1
研究背景
•  GPUクラスタにおけるプログラミング
–  CUDAやOpenCLによるGPUの管理
–  プログラム記述量の増加(MPI+OpenMP
+CUDA)
–  >生産性の低下
•  実行モデル
–  オフローディング(機能分散)
–  >GPU+CPUで性能向上が得られるはず
(負荷分散)
•  CPUの性能を余らせるのはもったいない
第2回XcalableMPワーク
ショップ 2014/11/24
2
研究の目的
•  GPUクラスタ上でのGPU/CPUワークシェ
アリングを高い言語レベルで容易に行え
るプログラミング環境の提供
–  高性能
–  高生産性
第2回XcalableMPワーク
ショップ 2014/11/24
3
並列言語XcalableMP(XMP)
•  PCクラスタコンソーシ #pragma xmp nodes p(4)
アムの並列プログラミ #pragma xmp template t(0 : N-1)
ング言語XcalableMP
template t
規格部会で策定
#pragma xmp distribute t(BLOCK) onto p
•  分散メモリ型システム
node1 node2 node3 node4
を対象としたPGAS並列 #pragma xmp align x[i] with t(i)
プログラミングモデル
•  既存のプログラム+指示 node1 node2 node3 node4
文
x
node1
node2
–  プログラミングモデルが #pragma xmp loop on t(i)
分かりやすい
for (i = 0; i < N; i++) { … }
–  プログラムの生産性が高
い
第2回XcalableMPワーク
ショップ 2014/11/24
node3
node4
4
XcalableMP acceleration device
extension (XMP-dev)
•  筑波大学HPCS研究室,理研AICSで開発中
•  XMPのGPUクラスタ向け拡張仕様
–  李らのCUDA, 野水らのOpenCLの実装
–  XMP-dev/CUDAをベースに拡張
–  pragmaからnative cuda/OpenCLコードを
生成
•  CPU-GPU間のデータ転送,GPUへのオフ
ロードを指示文で簡潔に記述
第2回XcalableMPワーク
ショップ 2014/11/24
5
XMP-devの例
int x[16], y[16];
#pragma xmp nodes p(2)
#pragma xmp template t(0:16-1)
#pragma xmp distribute t(BLOCK) onto p
#pragma xmp align [i] with t(i) :: x, y
#pragma xmp shadow [*] :: y
int main() {
node1
x
y
…
#pragma xmp reflect (y)
#pragma xmp device replicate (x, y)
{
#pragma xmp device replicate_sync in (x, y)
node2
#pragma xmp device loop on t(i)
for (i = 0; i < 16; i++)
x
for (j = 0; j < 16; j++)
x[i] += y[j];
y
#pragma xmp device replicate_sync out (x)
}
}
HOST
DEVICE
HOST
DEVICE
第2回XcalableMPワーク
ショップ 2014/11/24
6
XMP-devの例
int x[16], y[16];
#pragma xmp nodes p(2)
#pragma xmp template t(0:16-1)
#pragma xmp distribute t(BLOCK) onto p
#pragma xmp align [i] with t(i) :: x, y
#pragma xmp shadow [*] :: y
int main() {
node1
x
y
…
x
#pragma xmp reflect (y)
y
#pragma xmp device replicate (x, y)
{
#pragma xmp device replicate_sync in (x, y)
node2
#pragma xmp device loop on t(i)
for (i = 0; i < 16; i++)
x
for (j = 0; j < 16; j++)
x[i] += y[j];
y
#pragma xmp device replicate_sync out (x)
}
}
x
y
第2回XcalableMPワーク
ショップ 2014/11/24
HOST
デバイスメモリ上に
データを確保
DEVICE
HOST
DEVICE
7
XMP-devの例
int x[16], y[16];
#pragma xmp nodes p(2)
#pragma xmp template t(0:16-1)
#pragma xmp distribute t(BLOCK) onto p
#pragma xmp align [i] with t(i) :: x, y
#pragma xmp shadow [*] :: y
int main() {
node1
x
…
x
#pragma xmp reflect (y)
y
#pragma xmp device replicate (x, y)
{
#pragma xmp device replicate_sync in (x, y)
node2
#pragma xmp device loop on t(i)
for (i = 0; i < 16; i++)
x
for (j = 0; j < 16; j++)
x[i] += y[j];
y
#pragma xmp device replicate_sync out (x)
}
}
x
y
第2回XcalableMPワーク
ショップ 2014/11/24
HOST
y
DEVICE
HOST->DEVICE
のデータ転送
HOST
DEVICE
8
XMP-devの例
int x[16], y[16];
#pragma xmp nodes p(2)
#pragma xmp template t(0:16-1)
#pragma xmp distribute t(BLOCK) onto p
#pragma xmp align [i] with t(i) :: x, y
#pragma xmp shadow [*] :: y
int main() {
node1
x
y
…
x
#pragma xmp reflect (y)
y
#pragma xmp device replicate (x, y)
{
#pragma xmp device replicate_sync in (x, y)
node2
#pragma xmp device loop on t(i)
for (i = 0; i < 16; i++)
x
for (j = 0; j < 16; j++)
GPUの計算
x[i] += y[j];
y
#pragma xmp device replicate_sync out (x)
}
}
x
y
第2回XcalableMPワーク
ショップ 2014/11/24
HOST
DEVICE
HOST
DEVICE
9
XMP-devの例
int x[16], y[16];
#pragma xmp nodes p(2)
#pragma xmp template t(0:16-1)
#pragma xmp distribute t(BLOCK) onto p
#pragma xmp align [i] with t(i) :: x, y
#pragma xmp shadow [*] :: y
int main() {
node1
x
…
x
#pragma xmp reflect (y)
y
#pragma xmp device replicate (x, y)
{
#pragma xmp device replicate_sync in (x, y)
node2
#pragma xmp device loop on t(i)
for (i = 0; i < 16; i++)
x
for (j = 0; j < 16; j++)
x[i] += y[j];
y
#pragma xmp device replicate_sync out (x)
}
}
x
y
第2回XcalableMPワーク
ショップ 2014/11/24
HOST
y
DEVICE
HOST->DEVICE
のデータ転送
HOST
DEVICE
10
XMP-devの例
int x[16], y[16];
#pragma xmp nodes p(2)
#pragma xmp template t(0:16-1)
#pragma xmp distribute t(BLOCK) onto p
#pragma xmp align [i] with t(i) :: x, y
#pragma xmp shadow [*] :: y
int main() {
node1
x
HOST
y
…
#pragma xmp reflect (y)
#pragma xmp device replicate (x, y)
{
#pragma xmp device replicate_sync in (x, y)
node2
#pragma xmp device loop on t(i)
for (i = 0; i < 16; i++)
x
for (j = 0; j < 16; j++)
x[i] += y[j];
y
#pragma xmp device replicate_sync out (x)
}
}
DEVICE
DEVICE上の
データがfree
される
HOST
DEVICE
XMPのノード間通信
第2回XcalableMPワーク
ショップ 2014/11/24
11
StarPU
•  フランスのINRIA
Bordeauxが開発
•  ノード内のデータの分
散,タスクのダイナ
ミックスケジューリン
グによるGPU/CPU負荷
分散
•  メモリの一貫性を保証
•  逐次のソースコードを
StarPUの形式に書き換
える必要がある
x
x_h
CPU0
CPU0
CPU0
CPU
GPU0
GPU
core
–  コストが大きい
第2回XcalableMPワーク
ショップ 2014/11/24
12
XMP-dev/StarPUの概要
•  XMP-devとStarPUを組み合わせる
–  GPUクラスタ上でのGPU/CPUのワークシェ
アリングが可能
•  XMP-devに対するメリット
–  GPUへのオフロードだけでなくCPUも計算に
利用できる
•  StarPUに対するメリット
–  StarPU形式で記述することなく、高いレベル
でのプログラミングが出来る
第2回XcalableMPワーク
ショップ 2014/11/24
13
XMP-dev/StarPUの実装
XMP-dev
で分割
Global array (aligned array with XMP-dev)
Local array
各ノードへ部
分配列を分散
managed
by
Local array
XMP-dev
Replicated array
CPU core
CPU core
CPU core
CPU core
Replicated array
GPU
GPU
node1
第2回XcalableMPワーク
ショップ 2014/11/24
XMP-dev/StarPU
ランタイムで
生成・分割
CPU core
CPU core
CPU core
CPU core
GPU
GPU
StarPUによるタス
managed
by
クスケジューリン
StarPU グ
node2
14
XMP-dev/CUDA(GPUのみを使用)
に対する相対性能
0.5
0.45
0.4
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
行列積
0.25
64tasks
128tasks
256tasks
Relative performance
Relative performance
N体問題
0.2
0.15
64
0.1
128
256
0.05
0
N (Number of particles)
4096 8192 16384
N (Matrix size)
HA-PACS 2ノード 1GPU,15CPU core使用
第2回XcalableMPワーク
ショップ 2014/11/24
15
一般的なHybrid Work Sharingの問題
•  十分なタスク数,十分なタスクサイズがあるとき
CPU
GPU
CPUが演算中に多数の
タスクをGPUが処理
↓
ロードバランスは良好
•  十分なタスク数がないとき
CPU
GPU
•  十分なタスクサイズがないとき
CPU
第2回XcalableMPワーク
ショップ 2014/11/24
トレードオフの関係
↓
最適解が見つからな
い可能性もある
↓
計算リソースごとに
タスクサイズを調節
する必要がある
GPU
16
負荷バランス調整
•  十分なタスクサイズを割り当てるためには,リソー
スごとに異なるサイズを設定する必要がある
•  計算リソースに応じた演算量を割り当てる
–  CPU Weight パラメータの定義
•  0 CPU Weight 1.0
•  Replicated arrayのCPUが計算を担当する領域を設定
•  それぞれの領域を分割し,StarPUで各デバイスにスケ
ジューリングをする
•  負荷バランスの調整が可能
–  CPU Weightは
• 
• 
• 
• 
問題
問題サイズ
アプリケーション特性
etc…
第2回XcalableMPワーク
ショップ 2014/11/24
17
動的負荷分散にむけて
•  静的にCPU Weightを設定することは困難
–  問題やサイズによって適切な値は異なる
–  パラメータを変えつつ値を求める必要がある
–  >コストが非常に大きい
•  プログラム中で動的に変化させる機能を導
入
–  時間発展するプログラム中でCPU Weightが
最適値に均衡することが期待できる
第2回XcalableMPワーク
ショップ 2014/11/24
18
XMP-dev/StarPUによる動的負荷分散機能
•  reset_weight指示文の導入
double cpu_weight;
#pragma xmp device reset_weight (cpu_weight) :: list
•  cpu_weight何らかの値で初期化する
–  Default : 0.2 (CPU 20%, GPU 80%)
•  時間発展ループ中に複数のfor文があると
き,それぞれにcpu_weightを設定するこ
ともできる
第2回XcalableMPワーク
ショップ 2014/11/24
19
reset_weight指示文の例
double new_cpu_weight = 0.2;
for (int t = 0; t < STEP; t++) {
// 演算など
double cpu_time = xmp_cpu_wtime();
double gpu_time = xmp_gpu_wtime();
double cpu_ratio =
cpu_time / (cpu_time + gpu_time) * 100;
各デバイスの
実行時間
CPUの実行時間
の割合計算
if (cpu_ratio > 51) {new_cpu_weight -= 0.01;
#pragma xmp device reset_weight (new_cpu_weight) }
else if (cpu_ratio < 49) {new_cpu_weight += 0.01;
#pragma xmp device reset_weight (new_cpu_weight) }
調整アルゴリズムは一例であり,ユーザがより最適なアル
}
ゴリズムを用いることでより速い収束を得ることが可能に
第2回XcalableMPワーク
なる
ショップ 2014/11/24
20
評価環境
•  ノード構成(HA-PACS)
CPU
Intel Xeon E5-2670 * 2 (16 cores)
Memory
DDR3 128GB
GPU
NVIDIA Tesla M2090 * 4
CUDA toolkit
4.2
MPI
MVAPICH2 1.8.1
Interconnection
Infiniband QDR 4x 2 rails
# of node
2∼16
–  StarPUは1GPUの管理に1 CPU core消費
•  ex) 4 GPUs -> 12 (=16 – 4) CPU cores
第2回XcalableMPワーク
ショップ 2014/11/24
21
評価手法
•  ベンチマーク
–  N体問題,行列積
•  最外ループを追加し,その中で何度も計算を行う
•  計算にはBLAS(MAGMA blas,Gotoblas)を用いる
•  評価について
–  計測はMPIの通信を含まない( 割合が小)
–  CPU Weightを0.2から始めてTIME SETPの1イテ
レーションごとに計算し,新たな値を設定する
–  問題サイズ,ノード内のGPU数を変化させ測定
–  CPU Weightの動的調整を利用
•  先ほどのアニーリングアルゴリズムを利用
第2回XcalableMPワーク
ショップ 2014/11/24
22
CPU Weightの推移
行列積 (行列サイズ : 16384)
2node, 1GPU/node
CPU time
GPU time
CPU time
GPU time
GPU only time
CPU Weight
GPU only time
CPU Weight
2
0.25
0.2
1.4
1.2
0.15
1
0.8
0.1
0.6
0.4
0.05
0.2
0
0
Execution time [sec]
1.6
CPU Weight
Execution time [sec]
1.8
12
0.35
10
0.3
8
6
4
0.25
0.2
0.15
CPU Weight
N体問題 (粒子数 : 102400)
2node, 4GPU/node
0.1
2
0.05
0
0
CPU
1 3 5Weightを設定していくことにより,CPUとGPUの実行
7 9 11 13 15 17 19
1 3 5 7 9 11 13 15 17 19
TIME STEP
TIME STEP
時間が近づいている
CPU Weight
→動的負荷分散がうまくいっている
初期値:0.2
第2回XcalableMPワーク
ショップ 2014/11/24
23
XMP-dev/CUDA(=GPUのみを使用)
に対する相対性能 :N体問題
102400
204800
409600
819200
1.6
Better
Relative performance
1.4
1.2
1
0.8
0.6
0.4
0.2
0
1GPU 2GPU 4GPU 1GPU 2GPU 4GPU 1GPU 2GPU 4GPU 1GPU 2GPU 4GPU
2node
第2回XcalableMPワーク
ショップ 2014/11/24
4node
8node
16node
24
XMP-dev/CUDA(=GPUのみを使用)
に対する相対性能 :行列積
1024x1024
2048x2048
4096x4096
8192x8192
16384x16384
1.6
Better
Relative performance
1.4
1.2
1
0.8
0.6
0.4
0.2
0
1GPU 2GPU 4GPU 1GPU 2GPU 4GPU 1GPU 2GPU 4GPU 1GPU 2GPU 4GPU
2node
第2回XcalableMPワーク
ショップ 2014/11/24
4node
8node
16node
25
スピードアップ
(2node 1GPUを基準)
N体問題
102400
204800
行列積
409600
819200
1024
25
4096
8192
16384
12
10
Speed up
20
15
10
5
8
6
4
2
2node
4node
8node
16node
2node
4node
8node
4GPU
2GPU
1GPU
4GPU
2GPU
1GPU
4GPU
2GPU
1GPU
4GPU
2GPU
4GPU
2GPU
1GPU
4GPU
2GPU
1GPU
4GPU
2GPU
1GPU
4GPU
2GPU
0
1GPU
0
1GPU
Speed up
2048
16node
・N体問題はリソースが増えるごとに性能が向上している
・行列積は性能向上が小さく,さらに性能が劣化している部
分が多く見られる
第2回XcalableMPワーク
ショップ 2014/11/24
26
スピードアップ比較:行列積
XMP-dev/CUDA
16384
1024
35
12
30
10
2node
4node
8node
16node
2node
4node
8node
・XMP-dev/CUDA:問題サイズが十分なときにはスケール
・XMP-dev/StarPU:収束したCPU Weightの時に最適な性能
が出るとは限らない -> あえてCPU Weightをずらす必要もあ
第2回XcalableMPワーク
る
ショップ 2014/11/24
4GPU
2GPU
1GPU
4GPU
2GPU
1GPU
4GPU
2GPU
1GPU
4GPU
2GPU
1GPU
0
4GPU
0
2GPU
2
1GPU
5
4GPU
4
2GPU
10
16384
6
1GPU
15
8192
8
4GPU
20
4096
2GPU
Speed up
Speed up
25
2048
1GPU
8192
4GPU
4096
2GPU
2048
1GPU
1024
XMP-dev/StarPU
16node
27
まとめ・今後の課題
•  動的負荷分散をユーザが意識することなく
記述することができた
•  動的にCPU Weightを調整することで,最
大で20%∼40%程度の速度向上を得ること
ができた
•  様々なアプリケーションでの評価
•  スケールアップ実験
–  行列積の2次元分割対応
第2回XcalableMPワーク
ショップ 2014/11/24
28
ご清聴ありがとうございました
第2回XcalableMPワーク
ショップ 2014/11/24
29
Fly UP