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 CenterFile Exchange에서 Get 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