-
-
Save krk/27a835d34ae47d8dbc224eef53176206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__global__ | |
void matMul3( | |
float* d_C, | |
float* d_A, | |
float* d_B, | |
int m, | |
int n, | |
int r) | |
{ | |
__shared__ float Ais[BLOCK_SIZE][BLOCK_SIZE]; | |
__shared__ float Bis[BLOCK_SIZE][BLOCK_SIZE]; | |
int i = blockIdx.x * BLOCK_SIZE + threadIdx.x; | |
int k = blockIdx.y * BLOCK_SIZE + threadIdx.y; | |
int cIdx = i*m + k; | |
float val = 0; // ara toplam değişkeni | |
for(int j=0; j < n / BLOCK_SIZE; j++) | |
{ | |
Ais[threadIdx.y][threadIdx.x] = *loc( d_A, n, i, j ); | |
Bis[threadIdx.y][threadIdx.x] = *loc( d_B, n, j, k ); | |
// kullanılacak elemanlar paylaşık hafızaya yüklenir. | |
__syncthreads(); | |
for(int k=0; k<BLOCK_SIZE;k++) | |
{ | |
val += Ais[threadIdx.y][k] * Bis[k][threadIdx.x]; | |
} | |
// tüm threadlerin sonucu yazması beklenir. | |
__syncthreads(); | |
} | |
// C matrisine bir kere yazılır. | |
d_C[ cIdx ] = val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment