fread directly to GPU memory

9 次查看(过去 30 天)
Hi Everybody,
I'm new to GPU processing with matlab, and I'm wondering if anybody has solved this problem before. I have a binary file that I read through using the fread function. Currently I read in a range of data, fft it, and dump it to another file. I just got a new NVIDIA GPU and would like to process the fft on the GPU. I can easily do this if I read it into the cpu memory and then create a gpuArray.
The caveat is that I don't want to read it to the workspace first. since there is significant overhead with that, I would like to import the data directly to the RAM on the GPU without putting it into the memory of the workspace.
Any help or links are greatly appreciated.

采纳的回答

Edric Ellis
Edric Ellis 2012-2-29
Unfortunately, there's no way to do that. The nearest you can get is to pre-allocate the gpuArray, fread chunks of data, and then assign into the gpuArray. The only benefit here is that you don't need the whole array in host memory at any one time.
% Create a test file
a = rand(100);
fh = fopen( 'test.bin', 'wb' );
fwrite( fh, a, 'double' );
fclose( fh );
% Read the test file into a gpuArray one column at a time
g = parallel.gpu.GPUArray.zeros(100);
fh = fopen( 'test.bin', 'rb' );
for ii = 1:100
col = fread( fh, 100, 'double' );
g(:,ii) = col;
end
assert( isequal( a, g ) );
You'd probably want to read bigger chunks than that to get good performance. Also, note that gpuArrays can be saved into MAT files.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 GPU Computing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by