Ich muss berechnen wie: A [x] [y] = Summe {von z = 0 bis z = n} {B [x] [y] [z] + C [x] [ y] [z]}, wobei Matrix A Abmessungen [Höhe] [Breite] und Matrix B hat, C Abmessungen [Höhe] [Breite] [n] hat.Summe 3D-Matrix cuda
Werte in dem Speicher mit so etwas wie abgebildet werden:
index = 0;
for (z = 0; z<n; ++z)
for(y = 0; y<width; ++y)
for(x = 0; x<height; ++x) {
matrix[index] = value;
index++;
}
Q1: Ist das Cuda Kernel ok?
idx = blockIdx.x*blockDim.x + threadIdx.x;
idy = blockIdx.y*blockDim.y + threadIdx.y;
for(z=0; z<n; z++){
A[idx*width+idy] += B[idx*width+idy+z*width*height] + C[idx*width+idy+z*width*height];
}
Q2: Ist dies der schnellere Weg, um die Berechnung durchzuführen?
idx = blockIdx.x*blockDim.x + threadIdx.x;
idy = blockIdx.y*blockDim.y + threadIdx.y;
idz = blockIdx.z*blockDim.z + threadIdx.z;
int stride_x = blockDim.x * gridDim.x;
int stride_y = blockDim.y * gridDim.y;
int stride_z = blockDim.z * gridDim.z;
while (idx < height && idy < width && idz < n) {
atomicAdd(&(A[idx*width+idy]), B[idx*width+idy+idz*width*height] + C[idx*width+idy+idz*width*height]);
idx += stride_x;
idy += stride_y;
idz += stride_z;
}
Maximum Dimensionalität des Gewindesatzes = 3, Maximum Dimensionalität des Gitters von Gewindesätzen = 2 (für CC <2) = 3 (für CC> = 2). also denke ich, dass es kein Problem gibt. Ich habe große Matrizen, sehe aber das Problem nicht. – user1281071
Okay gut zu wissen. Ich habe meine Antwort aktualisiert. – Azrael3000
Sie sagen: 'if (idx> = Höhe || idy> = Breite || idz> = n) zurück;'? – user1281071