How to run a MEX function asynchronous in Matlab?
11 views (last 30 days)
Show older comments
Hi,
I have developed a MEX function (in CUDA) which uses a GPU for processing the data transfered from a device (let's call is D1) to my PC. D1 uses Matlab to communicate with my PC. In a sequential way, once the data is transferred from D1 to my PC, the MEX function starts to process. The transfer time from D1 to PC takes about 0.3 s. The MEX function takes about 0.4 s to finish the processing. So, it total I need 0.7 s to get the ouput of the MEX function.
Now, I've been thinking that maybe I could run the MEX function asynchronous to data transfer from D1 to PC; This means that in parallel of processing in the MEX function, I want to transfer the data from D1 to Matlab. In this way, I do not have to wait for 0.3 s (of data transfer) because it is done during processing of the MEX function. Could you please let me know if this is possible in Matlab or not. And if yes, how?
Thanks in advance.
Moein.
5 Comments
Joss Knight
on 12 Jul 2021
Right, so you can't do the data transfer in C++ code inside your MEX function?
In which case use some form of parallel pool and run your data transfer in the background. You might want to look at the documentation for parfeval. You can just set a whole bunch of data transfer going in the background and use fetchNext to pull data off the queue at the start of each iteration.
Answers (0)
See Also
Categories
Find more on GPU Computing in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!