如何迭代两个数组?
__global__ void euclidean(float *x, float *y, int dim_x, int dim_y, int ms, float *solution) {
int idx = threadIdx.x + blockDim.x * blockIdx.x;
int idy = threadIdx.y + blockDim.y * blockIdx.y;
float result = 0.0;
for (int iter = 0; iter < ms; iter++) {
float x_e = x[idy * ms + iter];
float y_e = y[idx * ms + iter];
result += (x_e * y_e);
}
}
输入: X = [[1,2], [3,4], [5,6], [7,8], [9,10]]
和Y = [[0,0], [1,1]]
预期输出: [[0, 3], [0, 7], [0, 11], [0, 15]. [0, 19]]
我怎样才能做到这一点?我的困难是在 X 和 Y 上进行迭代。
预期的:
[idx: 0 idy: 0 = 0] [idx: 1 idy: 0 = 3] [idx: 2 idy: 0 = 0] [idx: 3 idy: 0 = 7] [idx: 4 idy: 0 = 0] [idx: 0 idy: 1 = 11] [idx: 1 idy: 1 = 0] [idx: 2 idy: 1 = 15] [idx: 3 idy: 1 = 0] [idx: 4 idy: 1 = 19]