Hyper-Q / MPS: Difference between revisions

From Alliance Doc
Jump to navigation Jump to search
No edit summary
No edit summary
 
(15 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Draft}}
<languages/>
==Overview==


Hyper-Q (or MPS) is a new hardware/software feature of NVIDIA GPUs. It is available in GPUs with CUDA capability 3.5 and higher. It is available on P100 and newer GPUs on the Alliance clusters cedar, graham, beluga, and narval.
<translate>


According to NVIDIA,
==Overview== <!--T:1-->


MPS (Multi-Process Service; formerly known as Hyper-Q) enables multiple CPU cores to launch work on a single GPU simultaneously, thereby dramatically increasing GPU utilization and significantly reducing CPU idle times. MPS increases the total number of connections (work queues) between the host and the  GPU by allowing multiple simultaneous, hardware-managed connections (compared to the single connection available with Fermi generation GPUs). Hyper-Q is a flexible solution that allows separate connections from multiple CUDA streams, from multiple Message Passing Interface (MPI) processes, or even from multiple threads within a process. Applications that previously encountered false serialization across tasks, thereby limiting achieved GPU utilization, can see up to dramatic performance increase without changing any existing code.
<!--T:2-->
Hyper-Q (or MPS) is a feature of NVIDIA GPUs.
It is available in GPUs with CUDA compute capability 3.5 and higher,<ref>For a table relating NVIDIA GPU model names, architecture names, and CUDA compute capabilities, see [https://en.wikipedia.org/wiki/Nvidia_Tesla https://en.wikipedia.org/wiki/Nvidia_Tesla]</ref>
which is all GPUs currently deployed on Alliance general-purpose clusters (Béluga, Cedar, Graham, and Narval).


In our tests, MPS increases the total GPU flop rate even when the GPU is being shared by unrelated CPU processes ("GPU farming"). That means that MPS is great for CUDA codes with relatively small problem sizes, which on their own cannot efficiently saturate modern GPUs with thousands of cores.  
<!--T:3-->
[https://docs.nvidia.com/deploy/mps/index.html According to NVIDIA],
::<i>The MPS runtime architecture is designed to transparently enable co-operative multi-process CUDA applications, typically MPI jobs, to utilize Hyper-Q capabilities on the latest NVIDIA (Kepler and later) GPUs. Hyper-Q allows CUDA kernels to be processed concurrently on the same GPU; this can benefit performance when the GPU compute capacity is underutilized by a single application process.</i>


MPS is not enabled by default, but it is straightforward to do. If you use the GPU interactively, execute the following commands before running your CUDA code(s):


export CUDA_MPS_PIPE_DIRECTORY=/tmp/nvidia-mps
<!--T:4-->
export CUDA_MPS_LOG_DIRECTORY=/tmp/nvidia-log
In our tests, MPS may increase the total GPU flop rate even when the GPU is being shared by unrelated CPU processes. That means that MPS is great for CUDA applications with relatively small problem sizes, which on their own cannot efficiently saturate modern GPUs with thousands of cores.
nvidia-cuda-mps-control -d


If you are using a scheduler, you should submit a script which contains the above lines, and then executes your code.
<!--T:5-->
MPS is not enabled by default, but it is straightforward to do.  Execute the following commands before running your CUDA application:


Then you can avail the MPS feature if you have more than one CPU thread accessing the GPU. This will happen if you run an MPI/CUDA, OpenMP/CUDA code, or multiple instances of a serial CUDA code (GPU farming).
<!--T:6-->
{{Commands|export CUDA_MPS_PIPE_DIRECTORY{{=}}/tmp/nvidia-mps
|export CUDA_MPS_LOG_DIRECTORY{{=}}/tmp/nvidia-log
|nvidia-cuda-mps-control -d}}


Many additional details on MPS can be found in this document: [https://docs.nvidia.com/deploy/mps/index.html|CUDA Multi Process Service (MPS) - NVIDIA Documentation].
<!--T:7-->
Then you can use the MPS feature if you have more than one CPU thread accessing the GPU. This will happen if you run a hybrid MPI/CUDA application, a hybrid OpenMP/CUDA application, or multiple instances of a serial CUDA application (<i>GPU farming</i>).


==GPU farming==
<!--T:8-->
Additional details on MPS can be found here: [https://docs.nvidia.com/deploy/mps/index.html CUDA Multi Process Service (MPS) - NVIDIA Documentation].


One situation when the MPS feature can be very useful is when you need to run multiple instances of your CUDA code, when your code is too small to saturate a modern GPU. What you can do is to run multiple instances of your code sharing a single GPU. (This will work as long as there is enough of GPU memory for all of your code instances.) In many cases this should result in a significantly increased collective throughput from all of your GPU processes.
==GPU farming== <!--T:9-->


<!--T:10-->
One situation when the MPS feature can be very useful is when you need to run multiple instances of a CUDA application, but the application is too small to saturate a modern GPU.  MPS allows you to run multiple instances of the application sharing a single GPU, as long as there is enough of GPU memory for all of the instances of the application.  In many cases this should result in a significantly increased throughput from all of your GPU processes.
<!--T:11-->
Here is an example of a job script to set up GPU farming:
Here is an example of a job script to set up GPU farming:


  #!/bin/bash
  <!--T:12-->
#SBATCH --gpus-per-node=v100:1
{{File|name=script.sh
#SBATCH -t 0-10:00
|contents=
#SBATCH --mem=64G
#!/bin/bash
#SBATCH -c 8
#SBATCH --gpus-per-node=v100:1
#SBATCH --time=0-10:00
#SBATCH --mem-per-cpu=8G
#SBATCH --cpus-per-task=8
   
   
mkdir -p $HOME/tmp
mkdir -p $HOME/tmp
export CUDA_MPS_LOG_DIRECTORY=$HOME/tmp
export CUDA_MPS_LOG_DIRECTORY=$HOME/tmp
nvidia-cuda-mps-control -d
nvidia-cuda-mps-control -d
   
   
for ((i=0; i<8; i++))
for ((i=0; i<SLURM_CPUS_PER_TASK; i++))
  do
do
  echo $i
echo $i
  ./my_code $i  &
./my_code $i  &
  done
done
   
   
wait
wait
}}


In the above example, we are sharing a single V100 gpu between 8 instances of "my_code" (which takes a single argument - the loop index $i). We request 8 CPU cores (#SBATCH -c 8) for the farm, so there is one CPU core per code instance. The two important elements are "&" on the code execution line (this sends the code processes to the background), and the "wait" command at the end of the script (which ensures that the job runs until all background processes finished running.)
<!--T:13-->
In the above example, we share a single V100 GPU between 8 instances of <code>my_code</code> (which takes a single argument-- the loop index <code>$i</code>). We request 8 CPU cores (#SBATCH -c 8) so there is one CPU core per application instance. The two important elements are
* <code>&</code> on the code execution line, which sends the code processes to the background, and
* the <code>wait</code> command at the end of the script, which ensures that the job runs until all background processes end.


<!--T:14-->
[[Category:Software]]
[[Category:Software]]
</translate>

Latest revision as of 17:50, 14 December 2023

Other languages:


Overview[edit]

Hyper-Q (or MPS) is a feature of NVIDIA GPUs. It is available in GPUs with CUDA compute capability 3.5 and higher,[1] which is all GPUs currently deployed on Alliance general-purpose clusters (Béluga, Cedar, Graham, and Narval).

According to NVIDIA,

The MPS runtime architecture is designed to transparently enable co-operative multi-process CUDA applications, typically MPI jobs, to utilize Hyper-Q capabilities on the latest NVIDIA (Kepler and later) GPUs. Hyper-Q allows CUDA kernels to be processed concurrently on the same GPU; this can benefit performance when the GPU compute capacity is underutilized by a single application process.


In our tests, MPS may increase the total GPU flop rate even when the GPU is being shared by unrelated CPU processes. That means that MPS is great for CUDA applications with relatively small problem sizes, which on their own cannot efficiently saturate modern GPUs with thousands of cores.

MPS is not enabled by default, but it is straightforward to do. Execute the following commands before running your CUDA application:

[name@server ~]$ export CUDA_MPS_PIPE_DIRECTORY=/tmp/nvidia-mps
[name@server ~]$ export CUDA_MPS_LOG_DIRECTORY=/tmp/nvidia-log
[name@server ~]$ nvidia-cuda-mps-control -d


Then you can use the MPS feature if you have more than one CPU thread accessing the GPU. This will happen if you run a hybrid MPI/CUDA application, a hybrid OpenMP/CUDA application, or multiple instances of a serial CUDA application (GPU farming).

Additional details on MPS can be found here: CUDA Multi Process Service (MPS) - NVIDIA Documentation.

GPU farming[edit]

One situation when the MPS feature can be very useful is when you need to run multiple instances of a CUDA application, but the application is too small to saturate a modern GPU. MPS allows you to run multiple instances of the application sharing a single GPU, as long as there is enough of GPU memory for all of the instances of the application. In many cases this should result in a significantly increased throughput from all of your GPU processes.

Here is an example of a job script to set up GPU farming:


File : script.sh

#!/bin/bash
#SBATCH --gpus-per-node=v100:1
#SBATCH --time=0-10:00
#SBATCH --mem-per-cpu=8G
#SBATCH --cpus-per-task=8
 
mkdir -p $HOME/tmp
export CUDA_MPS_LOG_DIRECTORY=$HOME/tmp
nvidia-cuda-mps-control -d
 
for ((i=0; i<SLURM_CPUS_PER_TASK; i++))
 do
 echo $i
 ./my_code $i  &
 done
 
wait


In the above example, we share a single V100 GPU between 8 instances of my_code (which takes a single argument-- the loop index $i). We request 8 CPU cores (#SBATCH -c 8) so there is one CPU core per application instance. The two important elements are

  • & on the code execution line, which sends the code processes to the background, and
  • the wait command at the end of the script, which ensures that the job runs until all background processes end.
  1. For a table relating NVIDIA GPU model names, architecture names, and CUDA compute capabilities, see https://en.wikipedia.org/wiki/Nvidia_Tesla