简体   繁体   English

在GPU上加速图像处理算法,并行处理Matlab

[英]Accelarating image processing algorithm on GPU, parallel processing Matlab

I want to accelerate my algorithm because I need to run it on hundreds of images,so I tried to use unvectorized GPU code, running the same code on GPU, I have nvidia Geforce GT 650M with 2 GB on my PC, however it was very slow than the CPU version. 我想加速算法,因为我需要在数百张图像上运行它,所以我尝试使用未矢量化的GPU代码,在GPU上运行相同的代码,我的PC上装有2 GB的nvidia Geforce GT 650M,但是它非常比CPU版本慢。 After searching I am convinced to pass to vectorized GPU code using batch process (pagefun, bsxfun), I tried so much to solve this problem without a solution. 搜索之后,我确信可以使用批处理(pagefun,bsxfun)传递给矢量化的GPU代码,因此我做了很多尝试来解决此问题,而没有解决方案。 can someone help me about this code: 有人可以帮我这个代码:

Q=100;
       for i=3:n-2
        for j=3:m-2 
         A(i,j)=0;
            for c=1:Q
                        if B(i,j,c)~=0
                        A(i,j)=A(i,j)+(-(B(i,j,c)).*log(B(i,j,c)));
                        end
            end
        end
       end

Another question Why Matlab uses just 20% of my CPU? 另一个问题为何Matlab仅使用20%的CPU? How I can take benefits of my CPU to accelerate my processing 如何利用CPU来加速处理

Is Matlab a single threaded app? Matlab是单线程应用程序吗?

Thanks in advance 提前致谢

The vectorized version is this: 向量化版本是这样的:

BB = B(3:(n-2),3:(m-2),:);
cutoff = 10^(-6);
logBB = log(BB);
logBB(BB<cutoff) = 0; % remove divergent terms
A = -sum(BB.*logBB,3);

This should already run much faster even on a CPU. 即使在CPU上,它应该已经运行得更快。 If you have a GPU, all you need to do is have the input array 如果您有GPU,那么您所需要做的就是拥有输入数组

BB = gpuArray(BB);

stored on the GPU, and then collect the results 存储在GPU上,然后收集结果

A = gather(A);

back to the CPU 回到CPU

You will need to buy the parallel computing toolbox . 您将需要购买并行计算工具箱 (using parfor). (使用parfor)。

This is a well known limitation of matlab where some of the underlying functions do not paralellize across multiple cores (not threads). 这是matlab的众所周知的局限性,其中某些基础功能不会在多个内核(非线程)之间并行化。 A quick ballpark is to look at how much CPU matlab uses and multiply that by the number of COREs you have in your pc (this should get you to somewhere around 100%). 快速了解一下matlab使用了多少CPU,并将其乘以PC中拥有的CORE数量(这应该使您达到100%左右)。

If you want to utilize your computers GPU, parallel computing toolbox is the only way to do so. 如果要利用计算机的GPU,那么并行计算工具箱是唯一的方法。

From mathworks 来自mathworks

This really depends on what you are doing. 这实际上取决于您在做什么。 For some code MATLAB can only utilize a single core of a single processor, for other code, MATLAB will automatically utilize all available cores (and maybe processors). 对于某些代码,MATLAB只能利用单个处理器的单个核,对于其他代码,MATLAB会自动利用所有可用的核(可能还有处理器)。 It really depends on the underlying functions. 它实际上取决于基础功能。 Some things cannot be easily parallelized. 有些事情不容易并行化。 Sometimes you can help MATLAB with things like parfor loops. 有时,您可以为MATLAB提供parfor循环之类的功能。 Other times you might need something like MPI. 有时您可能需要MPI之类的东西。 Still other times there really is nothing you can do. 在其他时候,您实际上无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM