Writing data from GPU

9 ビュー (過去 30 日間)
Benjamin Ballintyn
Benjamin Ballintyn 2020 年 1 月 21 日
回答済み: Erik Meade 2020 年 12 月 2 日
Hi,
I am trying to find the fastest way to write data to a binary file (currently using fwrite), from within a function that gets compiled by GPU Coder into a mex file. I currently have a function that simulates a system for N timesteps. At each timestep I need to save some data. Running the mex function without saving runs ~150x faster than real time. However, when saving data each timestep, it runs ~2.3x slower than real time. This means the vast amount of time is being spent writing to the file. My question is, what is the absolute fastest way to save data from within a function compiled by GPU Coder? Thanks!

回答 (1 件)

Erik Meade
Erik Meade 2020 年 12 月 2 日
Hi,
It is quite possible that after each timestep, your program is incurring cudaMemcpy's to copy memory from the GPU to CPU every timestep and then writing the results to a file. cudaMemcpy requires the GPU to synchronize all threads and is thus a very expensive operation.
If it's possible, you could just keep all the data in GPU memory in a separate variable after each step, and then after the N-steps, write all the data to your file at once. The downside is you will use more GPU memory saving , but if you are not writing large amounts of data per timestep, it should be fine.
Let me know if this works. If not, feel free to share your code and I'll take a further look at it.
-Erik

カテゴリ

Help Center および File ExchangeGet Started with GPU Coder についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by