【发布时间】:2018-07-08 00:19:00
【问题描述】:
我是 opencl 的新手,现在我正在优化与 OpenCL 的模板匹配。我用较小的模板做了一些实验,发现我的 OpenCL 实现比 OpenCV 的 CPU 版本快。但在这种特殊情况下,模板尺寸非常大(2048x2048),原始图像尺寸为(3072x3072),OpenCV cpu 实现(137 秒)远远领先于 OpenCL(2000 秒)。请提出一些优化我的代码的方法,如下所示。
void __kernel corrln(global const unsigned char* ref_image, global const
unsigned char* template, global float* corrln )
{
const uint Width = get_global_size(0);
const int2 pos = {get_global_id(0), get_global_id(1)};
float sum = 0;
for(int y = pos.y; y < 2048; y++ )
{
for(int x =pos.x; x < 2048; x++ )
{
const int2 xy = { x, y };
const int2 txy = { x - pos.x, y - pos.y };
sum += ref_image[index(xy, Width)] * template[index(txy,
2048)];
}
}
corrln[index(pos, Width)]= sum;
}
【问题讨论】:
标签: opencl gpu template-matching