/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/opencl2.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 * BLOCK_SIZE + j]
 
2
#define B(i, j) shmem[BLOCK_SIZE * BLOCK_SIZE + i * 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 = 0;
 
6
    
 
7
    int tx = get_local_id(0);
 
8
    int ty = get_local_id(1);
 
9
 
 
10
    int i = get_global_id(1);
 
11
    int j = get_global_id(0);
 
12
 
 
13
 
 
14
    int k, l;
 
15
 
 
16
    for(k = 0; k < size; k += BLOCK_SIZE) {
 
17
        A(ty, tx) = a[i * size + (k + tx)];
 
18
        B(ty, tx) = b[(k + ty) * size + j];
 
19
        
 
20
        barrier(CLK_LOCAL_MEM_FENCE);
 
21
        
 
22
#pragma unroll BLOCK_SIZE
 
23
        for (l = 0; l < BLOCK_SIZE; ++l) {
 
24
            sum  += A(ty, l) * B(l, tx);
 
25
        }
 
26
 
 
27
        barrier(CLK_LOCAL_MEM_FENCE);
 
28
    }
 
29
    
 
30
    res[i * size +j] = sum;
 
31
}