【发布时间】:2012-10-24 19:09:33
【问题描述】:
我正在尝试在 OpenCL 中实现 hausdorff 距离,以下内核构成了它的基础,或者我认为它确实如此,因为我仍然必须完全实现它。也就是说,我可以得到一些建议还是有办法优化这个内核?基本上我怎样才能删除调用辅助函数的内核函数中的for循环.....
OpenCL Kernel 及其辅助函数:
void helper( int a_1, __global int* b_1, __global int* c_1 ){
int i = get_global_id(0);
c_1[i] = a_1 - b_1[i];
}
__kernel void test_call( __global int* a, //input buffer of size [100000, 1]
__global int* b, //input buffer of size [100000, 1]
__global int* c ){ //output buffer of size [100000, 1]
for ( int iter = 0 ; iter < 100000 ; iter++ ){
helper ( a[iter], b, c );
// once array c is obtained by calling the above function,
// it will be used in further processing that will take place inside
// this for loop itself
}
基本上我在这里尝试做的是用输入缓冲区“b”中的每个元素减去输入缓冲区“a”中的每个元素。复杂度为 O(n2)。
顺便说一句,这个简单的实现本身会在 2.5 秒内产生结果。对此的串行实现将需要几分钟才能完成执行。
【问题讨论】:
-
我建议删除对 helper 的函数调用并使其内联。此外,使用 pragma 展开 for 循环,让 GPU 更有效地利用 ILP。
标签: parallel-processing opencl