
はじめに
分子動力学をシミュレーションするOpenMMというライブラリがあります。このOpenMMはGPUを利用することで計算を高速化することができます。
「GPUといえばNVIDIA」というイメージがある方も多いとは思いますが、このOpenMMはAMDのGPUでも動作することが公式にサポートされています。
本記事では、Dockerを用いてAMDのGPU上でOpenMMを動作させる方法を紹介します。
前提
今回紹介するホストマシンの構成は次のとおりです。これに加え、Dockerのインストールが必要となります。
- OS: Ubuntu 18.04
- GPU: Radeon RX Vega 56 (4枚, 今回は1枚のみ使用)
- ROCm: ROCm v4.2
ROCmとは、AMDのGPUを扱うことができるGPU演算用のプラットフォームです。事前にホストマシンにこのROCmをインストールしておくことで、Dockerを用いたOpenMMの実行が可能となります。
ホストマシンへのROCmのインストールに関しては、公式のドキュメントをご覧ください。
Dockerコンテナの起動
以下のコマンドでOpenMM環境が構築されたDocker Imageをpullできます。
docker pull amdih/openmm:7.4.2
その後、次のコマンドを実行することで対話的にコンテナを起動することができます。
docker run –rm -it –device=/dev/kfd –device=/dev/dri –security-opt seccomp=unconfined amdih/openmm:7.4.2 bin/bash
GPUの確認
まず、Dockerコンテナ内からAMD GPUが認識できているかを確認します。
rocm-smiというコマンドを用いると、認識しているGPUのステータスが表示されます。
$ rocm-smi
======================= ROCm System Management Interface =======================
================================= Concise Info =================================
GPU Temp AvgPwr SCLK MCLK Fan Perf PwrCap VRAM% GPU%
0 27.0c 9.0W 852Mhz 167Mhz 0.78% auto 165.0W 0% 0%
1 27.0c 3.0W 852Mhz 167Mhz 0.78% auto 165.0W 0% 0%
2 27.0c 3.0W 852Mhz 167Mhz 0.78% auto 165.0W 0% 0%
3 28.0c 6.0W 852Mhz 167Mhz 0.78% auto 165.0W 0% 0%
================================================================================
============================= End of ROCm SMI Log ==============================
ベンチマークの実行
run-benchmarksコマンドを実行すると、OpenMMを利用した計算のベンチマークが走ります。
$ run-benchmarks
Platform: HIP
Precision: single
Test: gbsa
Step Size: 2 fs
Integrated 79539 steps in 59.1745 seconds
232.268 ns/day
Platform: HIP
Precision: mixed
Test: gbsa
Step Size: 2 fs
Integrated 79045 steps in 59.5847 seconds
229.236 ns/day
Platform: HIP
Precision: double
Test: gbsa
Step Size: 2 fs
Integrated 78571 steps in 58.8258 seconds
230.801 ns/day
Platform: HIP
Precision: single
Test: rf
Step Size: 2 fs
Integrated 70017 steps in 59.4981 seconds
203.35 ns/day
Platform: HIP
Precision: mixed
Test: rf
Step Size: 2 fs
Integrated 70145 steps in 59.5929 seconds
203.398 ns/day
Platform: HIP
Precision: double
Test: rf
Step Size: 2 fs
Integrated 70473 steps in 59.8672 seconds
203.412 ns/day
Platform: HIP
Precision: single
Test: pme (cutoff=0.9)
Step Size: 2 fs
Integrated 49259 steps in 60.3033 seconds
141.152 ns/day
Platform: HIP
Precision: mixed
Test: pme (cutoff=0.9)
Step Size: 2 fs
Integrated 49394 steps in 60.6124 seconds
140.817 ns/day
Platform: HIP
Precision: double
Test: pme (cutoff=0.9)
Step Size: 2 fs
Integrated 49705 steps in 61.0592 seconds
140.667 ns/day
Platform: HIP
Precision: single
Test: apoa1rf
Step Size: 2 fs
Integrated 22905 steps in 62.8632 seconds
62.9619 ns/day
Platform: HIP
Precision: mixed
Test: apoa1rf
Step Size: 2 fs
Integrated 22665 steps in 62.2873 seconds
62.8781 ns/day
Platform: HIP
Precision: double
Test: apoa1rf
Step Size: 2 fs
Integrated 22879 steps in 62.87 seconds
62.8836 ns/day
Platform: HIP
Precision: single
Test: apoa1pme
Step Size: 2 fs
Integrated 14608 steps in 62.2579 seconds
40.5453 ns/day
Platform: HIP
Precision: mixed
Test: apoa1pme
Step Size: 2 fs
Integrated 14526 steps in 61.9431 seconds
40.5226 ns/day
Platform: HIP
Precision: double
Test: apoa1pme
Step Size: 2 fs
Integrated 14581 steps in 62.2003 seconds
40.5078 ns/day
Platform: HIP
Precision: single
Test: apoa1ljpme
Step Size: 2 fs
Integrated 10693 steps in 61.7964 seconds
29.9006 ns/day
Platform: HIP
Precision: mixed
Test: apoa1ljpme
Step Size: 2 fs
Integrated 10632 steps in 61.4902 seconds
29.8781 ns/day
Platform: HIP
Precision: double
Test: apoa1ljpme
Step Size: 2 fs
Integrated 10596 steps in 61.4264 seconds
29.8079 ns/day
ベンチマークスクリプトを実行中にホストマシンでrocm-smiを実行すると、GPU利用率が90%台になっていることが確認できます。
これで、OpenMMがAMDのGPUを利用できることが確認できました。
$ rocm-smi
======================= ROCm System Management Interface =======================
================================= Concise Info =================================
GPU Temp AvgPwr SCLK MCLK Fan Perf PwrCap VRAM% GPU%
0 51.0c 153.0W 1622Mhz 800Mhz 36.86% auto 165.0W 0% 93%
1 27.0c 3.0W 852Mhz 167Mhz 0.78% auto 165.0W 0% 0%
2 27.0c 3.0W 852Mhz 167Mhz 0.78% auto 165.0W 0% 0%
3 25.0c 6.0W 852Mhz 167Mhz 0.78% auto 165.0W 0% 0%
================================================================================
============================= End of ROCm SMI Log ==============================
OpenMMを用いた自作プログラムを動かす
このコンテナ内ではPython 3.8でOpenMMが動作するようになっています。
/opt/openmm/examples以下のソースコードを参考にPythonスクリプトを実装した後、python3 xxx.pyで実行することが可能です。
まとめ
ここまで、OpenMMをAMDのGPUを用いて実行する方法を紹介してきました。
OpenMMのような、科学計算をGPUで行うニーズをお持ちの方は、ぜひ参考にして頂けますと幸いです。
また、当社モルゲンロットが提供する「M:CPP」ではAMD社のGPUが搭載されたサーバを科学計算用にクラウド提供しています。
安価な価格と、カスタマイズ性に優れていることが特徴です。GPUクラウドの利用をご検討中の場合には、お気軽にご相談ください。