Facebook
From Torrid Eider, 5 Years ago, written in C.
This paste is a reply to Re: Re: Untitled from Idiotic Parrot - go back
Embed
Viewing differences between Re: Re: Untitled and Re: Re: Re: Untitled
template  __global__ void
matrixMulCUDA_3_1w2w(float* matrixMulCUDA_3_2w1w(float* C, float* A, float* B, int wA, int wB)
{
        // Block index
        int bx = blockIdx.x;
        int by = blockIdx.y;

        // Thread index
        int tx = threadIdx.x;
x % BLOCK_SIZE;
        int ty = threadIdx.y;

        // Index of the first sub-matrix of A processed by the block
        int aBegin = wA * BLOCK_SIZE * by;

        // Index of the last sub-matrix of A processed by the block
        int aEnd = aBegin + wA - 1;

        // Step size used to iterate through the sub-matrices of A
        int aStep = 2 * BLOCK_SIZE;

        // Index of the first sub-matrix of B processed by the block
        int bBegin = BLOCK_SIZE * bx;

        // Step size used to iterate through the sub-matrices of B
        int bStep = BLOCK_SIZE * wB;

        // Csub is used to store the element of the block sub-matrix
        // that is computed by the thread
        float CSub[2] Csub { 0,0 };

0;

        // Loop over all the sub-matrices of A and B
        // required to compute the block sub-matrix
        for (int a = aBegin, b = bBegin;
                a <= aEnd;
                a += aStep, b += bStep)
        {

{
                // Declaration of the shared memory array As used to
                // store the sub-matrix of A
                __shared__ float As[BLOCK_SIZE][2 * BLOCK_SIZE];

As[BLOCK_SIZE][BLOCK_SIZE];

                // Declaration of the shared memory array Bs used to
                // store the sub-matrix of B
                
B

                
__shared__ float Bs[BLOCK_SIZE][2 * BLOCK_SIZE];

Bs[BLOCK_SIZE][BLOCK_SIZE];
                // Load the matrices from device memory
                // to shared memory; each thread loads
                // 2 elements one element of each matrix
                As[ty][tx] = A[a + wA * ty + tx];
                As[ty][tx + BLOCK_SIZE] = A[a + BLOCK_SIZE + wA * ty + tx];
                
Bs[ty][tx] = B[b + wB * ty + tx];
                Bs[ty][tx + BLOCK_SIZE] = B[b + BLOCK_SIZE * wB * ty + 
tx];

                // Synchronize to make sure the matrices are loaded
                __syncthreads();

                // Multiply the two matrices together;
                // each thread computes one element
                // of the block sub-matrix
                for (int g = 0; g < 2; g++) {
sub-matrix

#pragma unroll
                                        for (int k = 0; k < BLOCK_SIZE; ++k)
                        {
                                CSub[g] 
BLOCK_SIZE / 2; k++)
                {
                        Csub 
+= As[ty][k + (g (BLOCK_SIZE / 2) BLOCK_SIZE)] tx] Bs[k][tx Bs[k (g (BLOCK_SIZE / 2) BLOCK_SIZE)];
                        }
tx][tx];
                }

                // Synchronize to make sure that the preceding
                // computation is done before loading two new
                // sub-matrices of A and B in the next iteration
                __syncthreads();
        }

        // Write the block sub-matrix to device memory;
        // each thread writes one element
        int c = wB * BLOCK_SIZE * by + BLOCK_SIZE * bx;
        for (int g = 0; g < 2; g++) {
                
C[c + (BLOCK_SIZE * g) + wB * ty + tx] = CSub[g];
        }
+= Csub;
}

Replies to Re: Re: Re: Untitled rss

Title Name Language When
Re: Re: Re: Re: Untitled Capacious Earthworm c 5 Years ago.