Published Date : 2020年8月30日2:37

【Python】PyOptiXとcupyをインストールして試してみる
【Python】Install and try PyOptiX and cupy


This blog has an English translation


YouTubeにアップした動画、「【Python】PyOptiXとcupyをインストールして試してみる」の補足説明の記事です。

Here's a little more about the 「【Python】PyOptiXとcupyをインストールして試してみる」 video I uploaded to YouTube.


目次

Table of Contents




① 動画の説明
① Video Description



大量な数値を3Dで素早く可視化できるPythonモジュール、PyOptiXを試してみます。

Try PyOptiX, A Python module for quickly visualizing large numbers in 3D.

まず、PyOptiXをpipでインストールします。

First, install PyOptiX with pip.

サンプルを試してみるため、Githubのコードをダウンロードします。

Download the Github code to try the exemples.

アニメーション機能を試す為、ジュピターノートブックを開きます。

To experiment with the animation features, open the Jupyter Notebook.

おまけとして、numpyより速い(場合による)cupyをインストールしてみましょう。

As a bonus, install cupy which is faster than numpy (depending on the circumstances).

GeForceの最新のドライバーをインストールしてください。

Install the latest driver for GeForce.

因みにCUDAのバージョンはtensorflowを使うなら10.1をインストールしてください。

The CUDA version is 10.1 if you are using tensorflow.

それ以外の深層学習用ライブラリを使う際にも対応するバージョンは調べてからインストールしてください。

If you want to use other deep learning libraries, check the corresponding versions before installing.

今回僕は深層学習用ライブラリを使う予定は無いので、CUDAのバージョンは最新の11にしました。

I don't plan to use the deep learning library this time, so I decided to upgrade the CUDA version to the latest 11.

Python3の64bitとcuDNNをインストールしてください。

Install Python 3 64 bit and cuDNN.

ダウンロードしたcuDNNの中のcudaの中の「binとincludeとlibのフォルダ」をC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/にコピペします。

Copy and paste [bin, include, and lib folders] in cuda of downloaded cuDNN to [C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/].

cuDNNへのパスを通します。

Sets the path to cuDNN.

パスが通っているか確認します。[cudnn64_x]の[x]はダウンロードしたバージョンによって違うので各自で確認してください。

we'll check if the pass is working. Please check [x] of [cudnn64_x] on your own as it depends on the version you downloaded.

setuptoolsをアップグレードして、numpyをインストールしてください。

Please upgrade setuptools to install numpy.

そして、インストールしたcudaのバージョンに合ったcupyをインストールします。

Next, install the appropriate cupy for the version of cuda you installed.

単純な行列の積を計算して、numpyとcupyの計算速度を比較してみましょう。まずはNが2000の場合です。

Let's compute the product of a simple matrix and compare the computation speeds of numpy and cupy. First, when N is 2000.

import numpy as np
import cupy as cp
import time

n = 2000
start_time = time()
a = np.random.rand(n, n)
b = np.random.rand(n, n)
np.dot(a, b)
# elapsed time of numpy
elapsed_time_np = time()
a = cp.random.rand(n, n)
b = cp.random.rand(n, n)
cp.dot(a, b)
# elapsed time of cupy
elapsed_time_cp = time()
# First time in the calculation of numpy and the time after the calculation
print('np:', elapsed_time_np-start_time)
# First time in the calculation of cupy and the time after the calculation
print('cp:', elapsed_time_cp-elapsed_time_np)

numpyのほうが速いですが、各自の環境やアルゴリズムにより異なると思いますので、あくまで参考程度にとどめてください。

numpy is faster, but it depends on your environment and algorithm, so please keep it as a reference.

Nが10000だと少しだけcupyのほうが速いです。

If N is 10,000 cupy is a little faster.

Nが5000の場合。cupyのほうが約2倍速いです。

N=5000. Cupy is about twice as fast.

Nが8000の場合。cupyのほうが約6倍速いです。そしてNが8000くらいで分かりやすい速度の差が出てきました。

N=8000. Cupy is about six times faster. And when N was about 8000, there was a clear difference in speed.



以上です。お疲れ様です。

That's all. Thank you for your hard work.





See You Next Page!