/perf/kseta

To get this branch, use:
bzr branch http://darksoft.org/webbzr/perf/kseta

« back to all changes in this revision

Viewing changes to sources/mm/opencl4.cl

  • Committer: Suren A. Chilingaryan
  • Date: 2013-09-30 06:47:09 UTC
  • Revision ID: csa@dside.dyndns.org-20130930064709-55cde0k5ci76t8z5
Simple matrix multiplication

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define A(i, j) shmem[(i) * PPT * BLOCK_SIZE + (j)]
 
2
#define B(i, j) shmem[PPT * PPT * BLOCK_SIZE * BLOCK_SIZE + (i) * PPT * BLOCK_SIZE + (j)]
 
3
 
 
4
__kernel void multiply(__global float *res, __global float *a, __global float *b, unsigned long size, __local float *shmem) {
 
5
    float sum[PPT][PPT] = {0};
 
6
    
 
7
    int bx = get_group_id(0) * get_local_size(0) * PPT;
 
8
    int by = get_group_id(1) * get_local_size(1) * PPT;
 
9
    
 
10
    int tx = get_local_id(0);
 
11
    int ty = get_local_id(1);
 
12
 
 
13
    int i = get_global_id(1);
 
14
    int j = get_global_id(0);
 
15
 
 
16
    int x, y;
 
17
    int k, l;
 
18
 
 
19
 
 
20
    for(k = 0; k < size; k += PPT * BLOCK_SIZE) {
 
21
#pragma unroll PPT
 
22
        for (y = 0; y < PPT; ++y) {
 
23
#pragma unroll PPT
 
24
            for (x = 0; x < PPT; ++x) {
 
25
                A(y * BLOCK_SIZE + ty, x * BLOCK_SIZE + tx) = a[(by + y * BLOCK_SIZE + ty) * size + (k + x * BLOCK_SIZE + tx)];
 
26
                B(y * BLOCK_SIZE + ty, x * BLOCK_SIZE + tx) = b[(k + y * BLOCK_SIZE + ty) * size + (bx + x * BLOCK_SIZE + tx)];
 
27
            }
 
28
        }
 
29
        
 
30
        barrier(CLK_LOCAL_MEM_FENCE);
 
31
        
 
32
#pragma unroll PPT * BLOCK_SIZE
 
33
        for (l = 0; l < PPT * BLOCK_SIZE; ++l) {
 
34
#pragma unroll PPT
 
35
            for (y = 0; y < PPT; ++y) {
 
36
#pragma unroll PPT
 
37
                for (x = 0; x < PPT; ++x) {
 
38
                    sum[y][x]  += A(y * BLOCK_SIZE + ty, l) * B(l, x * BLOCK_SIZE + tx);
 
39
                }
 
40
            }
 
41
        }
 
42
 
 
43
        barrier(CLK_LOCAL_MEM_FENCE);
 
44
    }
 
45
    
 
46
#pragma unroll PPT
 
47
        for (y = 0; y < PPT; ++y) {
 
48
#pragma unroll PPT
 
49
            for (x = 0; x < PPT; ++x) {
 
50
                res[(by + y * BLOCK_SIZE + ty) * size + bx + x * BLOCK_SIZE + tx] = sum[y][x];
 
51
            }
 
52
        }
 
53
}