# Increasing kernel dispatch overhead for multiple GPUs

**URL:** <https://forums.developer.nvidia.com/t/increasing-kernel-dispatch-overhead-for-multiple-gpus/63634>\
**Category:** CUDA Programming and Performance\
**Created:** [July 30, 2018, 3:46am UTC](https://forums.developer.nvidia.com/t/increasing-kernel-dispatch-overhead-for-multiple-gpus/63634 "2018-07-30T03:46:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkhaled0ohsr](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mkhaled0ohsr](https://forums.developer.nvidia.com/u/mkhaled0ohsr)\
**Post date:** [July 30, 2018, 3:46am UTC](https://forums.developer.nvidia.com/t/increasing-kernel-dispatch-overhead-for-multiple-gpus/63634/1 "2018-07-30T03:46:24Z")

</div>

Hi all,

I am using the following Amazon AWS instances to test an OpenCL-based program:  
1- p3.2xlarge containing 1 NVIDIA Tesla V100 GPU  
1- p3.16xlarge containing 8 NVIDIA Tesla V100 GPUs

With a single GPU, the program works smoothly as expected.  
However, the program runs slower and slower as i increase the number of GPUs !  
I did some profiling and measurement of each Opencl-API-call, as well as, the execution times of the kernel functions.  
The bottleneck is found to be the call to the (enqueueNDRangeKernel), C++ binding function, which is simply wrapper around the OpenCL C function (clEnqueueNDRangeKernel).

With one GPU device, the call to (enqueueNDRangeKernel) is acceptable (less than one microsecond).  
However, it increases more and more as I increase the number of devices.  
With 8 devices, the call overhead is around 90 milliseconds !  
Here are the technical details:

0- The Amazon machines come with NVIDIA drivers version 9.0.176 and run on Amazon Linux (Linux Kernel 4.14).  
1- I create a single OpenCL context to group all devices in one context.  
2- For each device, I create a command queue with in-order execution.  
2- I create buffers in the context to be shared among the devices.  
3- For each opencl-kernel-function, and for each command-queue, I create an OpenCl-kernel and assign its arguments using sub-buffers of the main buffer.  
4- My program calls (enqueueNDRangeKernel) several times to enqueue all kernels to the command-queues/devices and at this point the bottleneck is observed.  
5- My program flushes (calls the C++ wrapper of clFlush()) the command-queues. No bottleneck is observed here.  
6- My program waits for all kernels to finish (calls the C++ wrapper of clFinish()). Kernels were found to run with predictable execution time at this point.

Notes:

- I measure the delay of the call to (clEnqueueNDRangeKernel) from the host side (i.e. C++ time measurement functions).
- I measure the execution times of the kernels by the OpenCL API (events + getProfilingInfo() function)

A similar thread is here ([url][https://devtalk.nvidia.com/default/topic/1001155/dispatch-kernel-overhead-opencl-/[/url]](https://devtalk.nvidia.com/default/topic/1001155/dispatch-kernel-overhead-opencl-/%5B/url%5D)) but it is for one GPU and the cause was probably from NVIDIA Windows drivers.  
Also, a similar one here [url][https://devtalk.nvidia.com/default/topic/466227/?comment=3312620[/url]](https://devtalk.nvidia.com/default/topic/466227/?comment=3312620%5B/url%5D) for a single GPU and no one replied to the poor guy.

I’d appreciate if some one can help or answer the following questions:

- Has any one faced a similar behavior ?
- Can it be a driver issue ?
- Any possible work-around ?

Regards,
