how to create streams in CUDA?

4 views (last 30 days)
shir rabi
shir rabi on 28 Dec 2017
hello, so I'm using CUDA for a project. my code is simple- many blocks that have the same amount of threads each and calculate the same equation. I want to create a few streams of blocks, each stream runs a few blocks. how can I create streams in Matlab? in all the examples I see people use C. from what I read I concluded that the streams should be created outside my kernel. I'll note that my kernel is written in C, and the rest of my code in Matlab. thank you!

Answers (1)

Francisco Ramírez Gil
Francisco Ramírez Gil on 13 Dec 2019
Hi, I have the same question.
I know that running a mex-function it is possible to setup the kernel launch using a code similar to the following:
cudaStream_t stream; // CUDA streams are of type `cudaStream_t`.
cudaStreamCreate(&stream); // Note that a pointer must be passed to `cudaCreateStream`.
someKernel<<<number_of_blocks, threads_per_block, 0, stream>>>(); // `stream` is passed as 4th EC argument.
cudaStreamDestroy(stream); // Note that a value, not a pointer, is passed to `cudaDestroyStream`.
However, is there any way to create a non-default CUDA stream while constructing the CUDAKernel Objec? For instance, is there a command in which the "stream" can be specified? e.g.
k = parallel.gpu.CUDAKernel('myfun.ptx','myfun.cu','stream');
Or maybe during CUDAKernel Object Properties? e.g.
k.ThreadBlockSize = [1024,1,1];
k.GridSize = [500,1,1];
k.Stream = 'stream1'
If someone knows something... Please, help me!

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!