我正在使用OpenCL计算n维点之间的欧氏距离.我得到两个n维点列表,我应该返回一个数组,其中只包含第一个表中每个点到第二个表中每个点的距离.
我的方法是做常规的doble循环(对于Table1中的每个点{对于Table2 {...}}中的每个点,然后对并行中的每对点进行计算.
然后将欧氏距离分成3个部分:1.取两个点之间的差值2.平方差(仍为每个维度)3.求和2中得到的所有值.4.取平方根在3中获得的值.(此示例中省略了此步骤.)
在尝试累积所有差异的总和之前,一切都像魅力一样(即,执行上述过程的第3步,下面代码的第49行).
作为测试数据,我使用的DescriptorLists各有2个点:DescriptorList1:001,002,003,...,127,128; (p1)129,130,131,...,255,256; (P2)
DescriptorList2:000,001,002,...,126,127; (p1)128,129,130,...,254,255; (P2)
因此,结果向量应该具有值:128,2064512,2130048,128现在我得到的随机数随每次运行而变化.
我感谢任何帮助或引导我做错了什么.希望一切都清楚我正在工作的场景.
#define BLOCK_SIZE 128
typedef struct
{
//How large each point is
int length;
//How many points in every list
int num_elements;
//Pointer to the elements of the descriptor (stored as a raw array)
__global float *elements;
} DescriptorList;
__kernel void CompareDescriptors_deb(__global float *C, DescriptorList A, DescriptorList B, int elements, __local float As[BLOCK_SIZE])
{
int gpidA = get_global_id(0);
int featA = get_local_id(0);
//temporary array to store the difference …Run Code Online (Sandbox Code Playgroud)