I’m trying to optimize my code making concurrent executions with stream processing data batches, but it does not seem to not even in cuda stream examples.
Kernels always wait for memory copies and likewise arround.
My sample code is here:
cudaError cudaReturnCode;
cudaStream_t kernelStreams[streamCount];
clock_t start;
clock_t end;
float* inputHostPtrList[streamCount];
float* outputHostPtrList[streamCount];
float* inputDevPtrList[streamCount];
float* outputDevPtrList[streamCount];
for (int i = 0; i < streamCount; i++) {
cudaMallocHost((void**)&inputHostPtrList[i], size * sizeof(float));
cudaMallocHost((void**)&outputHostPtrList[i], size * sizeof(float));
cudaMalloc((void**)&inputDevPtrList[i], size * sizeof(float));
cudaMalloc((void**)&outputDevPtrList[i], size * sizeof(float));
cudaStreamCreateWithFlags(&kernelStreams[i], cudaStreamNonBlocking);
}
start = clock();
for (int i = 0; i < streamCount; i++) {
cudaMemcpyAsync(inputDevPtrList[i], inputHostPtrList[i],
size * sizeof(float), cudaMemcpyHostToDevice, kernelStreams[i]);
MyKernel << < 100, 512, 0, kernelStreams[i] >> >
(inputDevPtrList[i], outputDevPtrList[i], size);
cudaMemcpyAsync(outputHostPtrList[i], outputDevPtrList[i],
size * sizeof(float), cudaMemcpyDeviceToHost, kernelStreams[i]);
}
cudaEventQuery(0);
cudaDeviceSynchronize();
end = clock();
for (int i = 0; i < streamCount; i++) {
cudaStreamDestroy(kernelStreams[i]);
}
for (int i = 0; i < streamCount; i++) {
cudaFree(outputDevPtrList[i]);
cudaFree(inputDevPtrList[i]);
cudaFreeHost(outputHostPtrList[i]);
cudaFreeHost(inputHostPtrList[i]);
cudaStreamDestroy(kernelStreams[i]);
}
cout << "Computation time:" << end - start << endl;
Device specs are here:
Device 0: "NVIDIA TITAN V"
CUDA Driver Version / Runtime Version 12.6 / 12.6
CUDA Capability Major/Minor version number: 7.0
Total amount of global memory: 12287 MBytes (12884312064 bytes)
(80) Multiprocessors
GPU Max Clock rate: 1455 MHz (1.46 GHz)
Memory Clock rate: 850 Mhz
Memory Bus Width: 3072-bit
L2 Cache Size: 4718592 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 6 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
CUDA Device Driver Mode (TCC or WDDM): WDDM (Windows Display Driver Model)
Device supports Unified Addressing (UVA): Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
Am I missing something?