how to deploy an external function (say filter) on GPU variable in row wise ?

2 views (last 30 days)
Hello friends,
I have a matrix A of size 2000 X200000. I want to perform row wise operations on the matrix A using external functions (ex: exfun()). So far i am calling each row in a parfor loop and execute the function. After executing the each row output is saved in a matrix. (pasted few lines of code for ease of understanding). But it is very time consuming process, I would like to use GPU to speed up the row-wise operations. So could you please provide any suggestions or a code to use gpu for my job ? Thanks in Advance
A %MAtrix size of 2000X200000
parfor i =1:1:size(A,2)
row_data=A(i,:);
output(i,:)=exfun(row_data);
end
  2 Comments
Edric Ellis
Edric Ellis on 24 Nov 2021
Whether you can use the GPU to help here depends entirely on whether the operations in exfun are supported on the GPU. See https://www.mathworks.com/help/parallel-computing/run-matlab-functions-on-a-gpu.html for more.
I would also suggest that iterating over rows of a matrix is generally less efficient than iterating over columns. That's because MATLAB stores matrices in "column major" order - picking out a single column is a simpler operation. (Of course, far better to have exfun operate on the whole matrix, or even chunks of matrix). So, you might be better off transposing A before you start. Depending on the computational time needed by exfun, this might or might not be significant.
jagadeeshwar tabjula
jagadeeshwar tabjula on 24 Nov 2021
Thanks, Edric, for the prompt reply.
In case, if all the operations in exfun are supported by GPU, I would like to know that how GPU considers the data chunks ?. If it is row-wise or column-wise I can transpose the data with respect to the chunk direction and feed the GPU array to the supported functions.
I will also check the significance of the transposing of A before feeding it to Exfun in parfor.
Thanks Again.

Sign in to comment.

Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!