CUDA并行计算问题

在提问之前请确定你已经努力阅读了文档,并且尝试自己在互联网上搜索。

请尽可能提供你的demo代码或者GitHub的gist地址。

通过使用CUDA.jl库包进行GPU并行计算,想要提高程序运行速度,但是不知道为什么速度一点也没有提高,反而比CPU 并行跑的更慢了呢,请大神帮我看看!搞了两三个月了,十分着急!
# code
```        function kernel_Density(m,h,N,Pa,Nei,Ndist)
            index = (blockIdx().x - 1) * blockDim().x + threadIdx().x
            stride = blockDim().x * gridDim().x
            for i = index : stride : N
                Pa[i,7] = 4*m/(pi*h^2)
                for n = 1 : 60
                    if Nei[i,n] != 0
                        neighborRho = (h^2-(Ndist[i,n])^2)^3
                    else
                        neighborRho = 0
                    end
                    Pa[i,7] = Pa[i,7] + (4*m/(pi*h*h*h*h*h*h*h*h))*neighborRho
                end
            end
            return nothing
        end

        d_Pa = CuArray(Pa)
        d_Nei = CuArray(Nei)
        d_Ndist = CuArray(Ndist)
@cuda blocks=20 threads=500  kernel_Density(m,h,N,d_Pa,d_Nei,d_Ndist)

这是提问还是在考验别人水平?提问的话可以加QQ群,问群主大神

GPU分化会严重降低效率,尽量避免判断分支,比如你可以写
b = (flag == 0) * a
代替判断flag是否为0 而产生分支

3 个赞