fitsread is not supported for GPU code generation

Hi! I am using GPU cores to accelerate analysis of images stored in '.fits' files. For this I am using GPU coder, in which I am converting function (see below) to mex format, but it is giving error " fitsread is not supported for GPU code generation ".
%first function
function F=T1(m,n)
file = ['G:\spatial ent\Intensity Correlation Imaging\EI_10mW_G1000_et3.5ms_X1.fits'];
frame1=fitsread(file,'PixelRegion',{[1 64],[1 64],(1)});
F=frame1(m,n);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I have successfully generated mex file for trail function (see below) and with 5X increase in speed it is working propoerly.
%second function
function F=T1(m,n)
A=zeros(64);
F=A(m,n);
end
I used second function for trail to generate mex file which I called in the follwing code,
tic;
T=zeros(64);
for m=1:64
for n=1:64
T(m,n)= T1(m,n);
end
end
toc;
Thanks,

 Accepted Answer

The GPU does not have access to file I/O .
For example for fprintf()
"This function accepts GPU arrays, but does not run on a GPU."

3 Comments

Thanks! what if I call the fit file before the mex function in main code?
example
file = ['G:\spatial ent\Intensity Correlation Imaging\EI_10mW_G1000_et3.5ms_X1.fits'];
frame1=fitsread(file,'PixelRegion',{[1 64],[1 64],(1)});
for m=1:64
for n=1:64
T1_mex(m,n)
end
end
where, T1_mex(m,n) is generated from below function
function F=T1(m,n)
F=frame1(m,n);
end
frame1 would be an object. You would have to pass the object to the function. I doubt that you can use objects on gpu.
Consider two possibilities:
  1. fitsread() returns a data structure of information about the file in the form of an object, and invoking the object with row and column values invokes action. In this case, if you move the action to the GPU then file I/O would have to take place on the GPU; OR
  2. fitsread() returns an array of data directly, and frame1(m,n) is direct indexing. In this case, your T1_mex would be plain array indexing. Moving that to the GPU would require that the entire array be transferred to the GPU, and indexing would be done on the GPU. However, indexing random elements on the GPU is one of the least efficient GPU operations (vectorized access to a slice of an array is much more efficient.) You would have higher efficiency leaving the array on the CPU and indexing there.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!