Stream synchronization

Hi,

I’m trying to implement a best-effort video player using two streams, and i’m getting problems with the synchronisation of streams, here is the timeline

External Media

Copy host to device (in brown) and kernels (green,blue) are alternated depending on the stream in order to give full computation power to the frame getting processed. What I want is the second copy of stream 2 to begin earlier, after the first copy of stream 3 and not after the end of kernels. Can’t manage to make it work.

Here is the code :

cudaEvent_t endLoadFlip,endComputeFlip,endDisplayFlip;

	cudaEvent_t endLoadFlop,endComputeFlop,endDisplayFlop;

	cudaEventCreate(&endLoadFlip,cudaEventDisableTiming);

	cudaEventCreate(&endComputeFlip,cudaEventDisableTiming);

	cudaEventCreate(&endLoadFlop,cudaEventDisableTiming);

	cudaEventCreate(&endComputeFlop,cudaEventDisableTiming);

	int i = 0;

	while(i < 3){

		cudaStreamWaitEvent(flip.stream,endLoadFlop,0);

		flip.load(*flux);

		cudaEventRecord(endLoadFlip,flip.stream);

		

		cudaStreamWaitEvent(flop.stream,endLoadFlip,0);

		flop.load(*flux);

		cudaEventRecord(endLoadFlop,flop.stream);

		cudaStreamWaitEvent(flip.stream,endComputeFlop,0);

		flip.compute();

		cudaEventRecord(endComputeFlip,flip.stream);

		

		cudaStreamWaitEvent(flop.stream,endComputeFlip,0);

		flop.compute();	

		cudaEventRecord(endComputeFlop,flop.stream);

		i++;

	}

Thank you,

Testi