我正在尝试在 OpenCL 中实现 hausdorff 距离,以下内核构成了它的基础,或者我认为它确实如此,因为我仍然必须完全实现它。也就是说,我能得到一些建议还是有办法优化这个内核?基本上我怎样才能删除调用辅助函数的内核函数中的for循环.....
OpenCL 内核及其辅助函数:
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(n 2 )。
顺便说一句,这个简单的实现本身会在 2.5 秒内产生结果。对此的串行实现将需要几分钟才能完成执行。