开发者

Parallelizing a for loop to run simultaneously on multiple GPU cores?

开发者 https://www.devze.com 2023-02-20 17:45 出处:网络
I understand that you can use a matlabpool and parfor to run for loop iterations in parallel, however, I want to try and take advantage of using the high number of cores in my GPU to run a larger numb

I understand that you can use a matlabpool and parfor to run for loop iterations in parallel, however, I want to try and take advantage of using the high number of cores in my GPU to run a larger number of simultaneous iterations. I was wondering if there is any built in functionality to do this?

To my understanding, the method in which MATLAB runs code on the GPU is through a GPUarray, but that does not seem to parallelize a loop, only certain functions inside the loop.

For the loop that I am running, each iteration can run independently and the only variables that need to exist outside of the loop is the data to be processed (a 3-D array, where the first index is time, and each iteration is operating on a different ti开发者_StackOverflowme) and a 2-D output array where each iteration is storing the result for a particular time. Each time is independent.

Thanks


With a GPUArray, you can run elementwise operations in parallel by structuring your algorithm in terms of MATLAB's arrayfun. Effectively, this implicitly loops over each element of your arrays, and can apply the body of a MATLAB function to each element. The doc is: here.

There's a simple demo: here.

0

精彩评论

暂无评论...
验证码 换一张
取 消