GPU是否适用于基于案例的图像过滤?

Der*_*rek 7 cuda gpu image-processing

我试图弄清楚某个问题是否适合使用CUDA将问题放在GPU上.

我基本上做了一个基于一些边缘检测而改变的盒式过滤器.因此,基本上有8个案例针对每个像素进行测试,然后其余的操作发生 - 典型的平均计算等.我的循环中是否存在这些switch语句会导致这个问题成为转向GPU的不良选择?

我不确定如何避免切换语句,因为这种边缘检测必须发生在每个像素上.我想整个图像可能会将边缘检测部分从处理算法中分离出来,并且您可以存储一个缓冲区,该缓冲区对应于每个像素使用哪个滤镜,但这似乎会为算法添加大量预处理.

编辑:只是为了给出一些上下文 - 这个算法已经编写好了,OpenMP已经被用来加速它的效果.但是,与GPU中的512核相比,我的开发盒上的8个核心相形见绌.

Cia*_*ran 0

使用 GPU 进行处理通常是违反直觉的;如果用普通串行代码完成,效率显然很低,但实际上是使用 GPU 并行完成的最佳方法。

下面的伪代码看起来效率很低(因为它为每个像素计算 8 个过滤值),但可以在 GPU 上高效运行:


# Compute the 8 possible filtered values for each pixel
for i = 1...8
    # filter[i] is the box filter that you want to apply
    # to pixels of the i'th edge-type
    result[i] = GPU_RunBoxFilter(filter[i], Image)

# Compute the edge type of each pixel
# This is the value you would normally use to 'switch' with
edge_type = GPU_ComputeEdgeType(Image)

# Setup an empty result image
final_result = zeros(sizeof(Image))
# For each possible switch value, replace all pixels of that edge-type
# with its corresponding filtered value
for i = 1..8
    final_result = GPU_ReplacePixelIfTrue(final_result, result[i], edge_type==i)
Run Code Online (Sandbox Code Playgroud)

希望这有帮助!