|
| 1 | +# ABSTRACT: GPU-specific installation and usage information. |
| 2 | +# PODNAME: AI::TensorFlow::Libtensorflow::Manual::GPU |
| 3 | +=pod |
| 4 | + |
| 5 | +=head1 DESCRIPTION |
| 6 | + |
| 7 | +This guide provides information about using the GPU version of |
| 8 | +C<libtensorflow>. This is currently specific to NVIDIA GPUs as |
| 9 | +they provide the CUDA API that C<libtensorflow> targets for GPU devices. |
| 10 | + |
| 11 | +=head1 INSTALLATION |
| 12 | + |
| 13 | +In order to use a GPU with C<libtensorflow>, you will need to check that the |
| 14 | +L<hardware requirements|https://www.tensorflow.org/install/pip#hardware_requirements> and |
| 15 | +L<software requirements|https://www.tensorflow.org/install/pip#software_requirements> are |
| 16 | +met. Please refer to the official documentation for the specific |
| 17 | +hardware capabilities and software versions. |
| 18 | + |
| 19 | +An alternative to installing all the software listed on the "bare metal" host |
| 20 | +machine is to use C<libtensorflow> via a Docker container and the |
| 21 | +NVIDIA Container Toolkit. See L<AI::TensorFlow::Libtensorflow::Manual::Quickstart/DOCKER IMAGES> |
| 22 | +for more information. |
| 23 | + |
| 24 | +=head1 RUNTIME |
| 25 | + |
| 26 | +When running C<libtensorflow>, your program will attempt to acquire quite a bit |
| 27 | +of GPU VRAM. You can check if you have enough free VRAM by using the |
| 28 | +C<nvidia-smi> command which displays resource information as well as which |
| 29 | +processes are currently using the GPU. If C<libtensorflow> is not able to |
| 30 | +allocate enough memory, it will crash with an out-of-memory (OOM) error. This |
| 31 | +is typical when running multiple programs that both use the GPU. |
| 32 | + |
| 33 | +If you have multiple GPUs, you can control which GPUs your program can access |
| 34 | +by using the |
| 35 | +L<C<CUDA_VISIBLE_DEVICES> environment variable|https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars> |
| 36 | +provided by the underlying CUDA library. This is typically |
| 37 | +done by setting the variable in a C<BEGIN> block before loading |
| 38 | +L<AI::TensorFlow::Libtensorflow>: |
| 39 | + |
| 40 | + BEGIN { |
| 41 | + # Set the specific GPU device that is available |
| 42 | + # to this program to GPU index 0, which is the |
| 43 | + # first GPU as listed in the output of `nvidia-smi`. |
| 44 | + $ENV{CUDA_VISIBLE_DEVICES} = '0'; |
| 45 | + require AI::TensorFlow::Libtensorflow; |
| 46 | + } |
| 47 | + |
| 48 | +=cut |
0 commit comments