CUDA Device Max Connections NVIDIA's CUDA_DEVICE_MAX_CONNECTIONS environment variable defaults to 8 concurrent hardware connections to the GPU, capping real concurrency regardless of how many CUDA streams a developer creates, according to a technical blog post by Lei Mao. The post benchmarks 32 CUDA streams with 32 threads and 200 queries per thread, showing that GPU utilization stays limited unless CUDA_DEVICE_MAX_CONNECTIONS is raised. The author published the example code in the leimao/CUDA-Device-Max-Connections GitHub repository with profiling traces. CUDA Device Max Connections To maximize GPU utilization, it is common to have multiple workers processing tasks concurrently on GPU. However, by default, the GPU hardware concurrency is limited, no matter how much software concurrency is implemented. As a consequence, GPU might still be under utilized, even if at the software level the concurrency appears high in the implementation. CUDA DEVICE MAX CONNECTIONS is an environment variable that can be set to control the number of hardware concurrency on GPU. In this blog post, I would like to quickly discuss the importance of setting CUDA DEVICE MAX CONNECTIONS https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/environment-variables.html cuda-device-max-connections for maximizing GPU concurrency and overall utilization. In CUDA programming, a CUDA stream is an abstraction which allows the programmer to express a sequence of operations. The developer could create multiple streams to enable concurrent execution of different tasks on the GPU, thereby improving overall utilization and performance. CUDA kernels launched in different streams can run concurrently, subject to hardware limitations and resource availability, such as the number of available Streaming Multiprocessors. There is one key factor that the developer might overlook, which is the CUDA DEVICE MAX CONNECTIONS environment variable that controls the maximum number of concurrent connections to the GPU. If this variable is not set appropriately, no matter how many CUDA streams are created, how lightweight the kernels are on each stream, the GPU concurrency will still be limited. In the following example https://github.com/leimao/CUDA-Device-Max-Connections , we created 32 CUDA streams to run concurrent tasks on GPU. The inference performances are benchmarked and profiling traces are collected. | 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 | include "multi stream.h" include "cuda utils.h" include "cuda worker.h" include