====== Cupy: calcul numpy avec CUDA ====== **CuPy – NumPy-like API accelerated with CUDA** [[https://developer.download.nvidia.com/video/gputechconf/gtc/2019/presentation/s9738-using-gpu-power-for-numpy-syntax-calculations.pdf|s9738-using-gpu-power-for-numpy-syntax-calculations.pdf]] sur developer.download.nvidia.com [[https://docs-cupy.chainer.org/en/stable/reference/difference.html|Difference between CuPy and NumPy — CuPy 7.8.0 documentation]] sur docs-cupy.chainer.org ===== Ressources ===== * **Un pdf de présentation de [[https://developer.download.nvidia.com/video/gputechconf/gtc/2019/presentation/s9738-using-gpu-power-for-numpy-syntax-calculations.pdf|Nvidia]]** {{:media_10:using-gpu-power-for-numpy-syntax-calculations-10.png?400|}} {{:media_10:using-gpu-power-for-numpy-syntax-calculations-16.png?400|}} {{:media_10:using-gpu-power-for-numpy-syntax-calculations-11.png?400|}} * **[[https://cupy.chainer.org/|cupy.chainer.org]]** * **[[https://docs-cupy.chainer.org/en/stable/|Read the Docs de CuPy]]** * **[[https://pypi.org/project/cupy/|pypi.org: cupy]]** ===Version de CUDA=== * Les exemples de cette page sont réalisés sur Xubuntu 18.04 et CUDA 10.0 ==== Bibliothèques associées==== * **[[https://github.com/rapidsai/cudf/tree/master|github.com: cudf]]** {{ :media_10:rapids_arrow.png?500 |}} * **scipy** * **opencv** =====Installation===== sudo pip3 install cupy-cuda102 =====Comment adapter un fichier numpy en cupy===== [[https://docs-cupy.chainer.org/en/stable/reference/difference.html|docs-cupy.chainer.org: Difference between CuPy and NumPy]] =====Exemple avec l'intelligence du sémaphore===== * Exemple avec: [[l_intelligence_du_semaphore|L'intelligence du sémaphore]] * [[https://github.com/sergeLabo/semaphore_cupy|Les sources sur GitHub: semaphore_cupy]] ====Numpy==== Avec le script semaphore_ia.py AMD FX(tm)-8320 Eight-Core Processor Calcul avec numpy ... numpy ... numpy ... numpy ... Training: Shot 60000 Lettre 60000; Testing: Shot 10000 Lettre 10000 Training... type(weight_list :) len(weight_list) = 3 0 100 1 100 2 27 weights.npy enregistré Testing... Learningrate: 0.023 Résultat 87.4 Calcul en: 139.8 s ====Cupy==== Avec le script cupy_ia.py cupy 7.3 Successfully installed cupy-7.3.0 fastrlock-0.4 Nvidia 1060 GTX Calcul avec cupy ... cupy ... cupy ... cupy ... Training: Shot 60000 Lettre 60000; Testing: Shot 10000 Lettre 10000 Training... type(weight_list :) len(weight_list) = 3 0 100 1 100 2 27 weights_cupy.npy enregistré Testing... Learningrate: 0.023 Résultat 89.9 Calcul en: 91.7 s **Soit un gain de 34% avec cupy** Il faut vérifier que toutes les datas sont bien chargées dans la RAM GPU: cupy.array [[https://docs-cupy.chainer.org/en/stable/tutorial/basic.html|docs-cupy.chainer.org: basic]] ===== OpenCV ===== https://docs-cupy.chainer.org/en/stable/reference/ndimage.html#module-cupyx.scipy.ndimage {{tag> ia python sb }}