cvjena / darknet

Extension of the public darknet repository with additional features and code improvements for YOLO.
Other
119 stars 70 forks source link

puzzled by partial sum calculation in gemm #20

Closed zhouweiscut closed 6 years ago

zhouweiscut commented 6 years ago

puzzled by partial sum calculation in gemm in forward_convolutional_layer sub-function, it calls "gemm(0,0,m,n,k,1,a,k,b,n,1,c,n);", for my understanding, 'a' point to weight, 'b' point to input data, and 'c' is output. in general convolution calculation, each weight value in a conv kernel is multiplied with corresponding input data and calculate partial sum, that's to say, each weight value will multiply different value and do partial sum. but in gemm_nn sub-function, the same weight value 'A[i*lda+k]' multiply different 'B' value, and do partial sum, i am puzzled by this, could you help me ?

void gemm_nn(int M, int N, int K, float ALPHA, 
        float *A, int lda, 
        float *B, int ldb,
        float *C, int ldc)
{
    int i,j,k;
    for(i = 0; i < M; ++i){
        for(k = 0; k < K; ++k){
            register float A_PART = ALPHA*A[i*lda+k];
            for(j = 0; j < N; ++j){
                C[i*ldc+j] += A_PART*B[k*ldb+j];
            }
        }
    }
}