第13章計算の性能
13.2. Asynchronous Computation13.2 非同期計算
Today’s computers are highly parallel systems, consisting of multiple CPU cores (often multiple threads per core), multiple processing elements per GPU, and often multiple GPUs per device. In short, we can process many different things at the same time, often on different devices. Unfortunately Python is not a great way of writing parallel and asynchronous code, at least not without some extra help. After all, Python is single-threaded and this is unlikely to change in the future. Deep learning frameworks such as MXNet and TensorFlow adopt an asynchronous programming model to improve performance, while PyTorch uses Python’s own scheduler leading to a different performance trade-off. For PyTorch, by default, GPU operations are asynchronous. When you call a function that uses the GPU, the operations are enqueued to the particular device, but not necessarily executed until later. This allows us to execute more computations in parallel, including operations on the CPU or other GPUs.
英語のヒント
今日のコンピュータは高度に並列なシステムであり、複数のCPUコア(しばしばコアごとに複数のスレッド)、GPUごとに複数の処理要素、そしてしばしば装置ごとに複数のGPUからなる。手短に言えば、多くの異なることを、しばしば異なる装置の上で、同時に処理できる。残念ながら、Pythonは、少なくとも何らかの追加の助けなしには、並列で非同期なコードを書くのによいやり方ではない。結局のところ、Pythonはシングルスレッドであり、これが将来変わる見込みは低い。MXNetやTensorFlowのような深層学習のフレームワークは、性能を上げるために非同期プログラミングのモデルを採用しているが、PyTorchはPython自身のスケジューラを使っており、性能のトレードオフが異なる。PyTorchでは、デフォルトでGPUの演算は非同期である。GPUを使う関数を呼び出すと、演算はその装置のキューに入れられるが、必ずしもすぐには実行されない。これにより、CPUやほかのGPUでの演算を含め、もっと多くの計算を並列に実行できる。
Hence, understanding how asynchronous programming works helps us to develop more efficient programs, by proactively reducing computational requirements and mutual dependencies. This allows us to reduce memory overhead and increase processor utilization.
英語のヒント
したがって、非同期プログラミングがどう働くかを理解すると、計算の要求と相互の依存を前もって減らすことで、もっと効率的なプログラムを作るのに役立つ。これにより、メモリのオーバーヘッドを減らし、プロセッサの利用率を上げられる。
import os
import subprocess
import numpy
import torch
from torch import nn
from d2l import torch as d2l