Configure Multiple Tasks#

Your application might be designed to perform multiple tasks in a multi-GPU environment; for example, rendering a game and applying a video effect filter. In this situation, select the best GPU for each task before calling NvVFX_Load().

  1. Call cudaGetDeviceCount() to determine the number of GPUs in your environment.

  2. Get the properties of each GPU and determine whether it is the best GPU for each task by performing the following operations for each GPU in a loop.

    1. Call cudaSetDevice() to set the current GPU.

    2. Call cudaGetDeviceProperties() or preferably cudaDeviceGetAttribute() to get the properties of the current GPU.

    3. Use custom code in your application to analyze the properties retrieved by cudaGetDeviceProperties() or cudaDeviceGetAttribute() to determine whether the GPU is the best GPU for each specific task.

    This example uses the compute capability to determine whether a GPU’s properties should be analyzed to determine whether the GPU is the best GPU for applying a video effect filter. A GPU’s properties are analyzed only if the compute capability is 7.5, 8.6, or 8.9. This value denotes a GPU based on the NVIDIA Turing, NVIDIA Ampere, or NVIDIA Ada architecture, respectively.

  3. In the loop for performing the application’s tasks, select the best GPU for each task before performing the task.

    1. Call cudaSetDevice() to select the GPU for the task.

    2. Make all the function calls required to perform the task.

In this way, you select the best GPU for each task only once without setting the GPU for every function call.

This example selects the best GPU to render a game and uses custom code to render the game. It then selects the best GPU to apply a video effect filter before calling the NvCVImage_Transfer() and NvVFX_Run() functions to apply the filter. This step avoids the need to save and restore the GPU for every NVIDIA Video Effects SDK API call.