/tomo/pyhst

To get this branch, use:
bzr branch http://darksoft.org/webbzr/tomo/pyhst

« back to all changes in this revision

Viewing changes to docs/optimizations/kepler/hst_tex_uniform.h

  • Committer: Suren A. Chilingaryan
  • Date: 2012-05-10 15:06:33 UTC
  • Revision ID: csa@dside.dyndns.org-20120510150633-56gdy6t3tflz2gab
OpenCL clean-up

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 We are trying to fetch along the both bin & proj axes of the projection within each block (assuming
 
3
 the GPU is optimized for this use case). Minor modification going by 8 projections only and using 
 
4
 32 threads for acquring spatial data 8x4. Not finished, some artifcats present.
 
5
*/
 
6
 
 
7
 
 
8
__global__ static void hst_cuda_kernel(int num_proj, int num_bins, float *d_SLICE, float apos_off_x, float apos_off_y, int batch) {
 
9
    float h;
 
10
    float res[4][2] = {0};
 
11
 
 
12
#ifdef HST_OPTIMIZE_KEPLER
 
13
    __shared__ float buf[8][34]; // 64b for Kepler
 
14
    __shared__ float fill[48];
 
15
    __shared__ float fin[16][18];
 
16
#else /* HST_OPTIMIZE_KEPLER */
 
17
    __shared__ float buf[8][33]; // 32b for Fermi & GT200
 
18
    __shared__ float fill[56];
 
19
    __shared__ float fin[16][17];
 
20
#endif /* HST_OPTIMIZE_KEPLER */
 
21
 
 
22
    const int tidx = threadIdx.x;
 
23
    const int tidy = threadIdx.y;
 
24
 
 
25
    const int bidx = PPT * blockIdx.x * BLOCK_SIZE_X;
 
26
    const int bidy = batch + PPT * blockIdx.y * BLOCK_SIZE_Y;
 
27
 
 
28
    const int sidx = tidx % 8;
 
29
    const int sidy = 2 * (2 * (tidy%2) + tidx / 8);
 
30
 
 
31
    const int idx = bidx + sidx;
 
32
    const int idy = bidy + sidy;
 
33
 
 
34
    const float x = idx + apos_off_x;
 
35
    const float y = idy + apos_off_y;
 
36
 
 
37
    const float projf = tidy + 0.5f;
 
38
 
 
39
//    const int idx = blockIdx.x * BLOCK_SIZE_X + threadIdx.x;
 
40
//    const int idy = blockIdx.y * BLOCK_SIZE_Y + threadIdx.y + batch;
 
41
 
 
42
    for (int proje=0; proje<num_proj; proje+=8) {
 
43
        const float4 all = c_all[proje+tidy];
 
44
        h = all.z + x * all.x - y * all.y;
 
45
 
 
46
#pragma unroll 2
 
47
    for (int i = 0; i < 2; i++) {
 
48
#pragma unroll 2
 
49
        for (int j = 0; j < 2; j++) {
 
50
            float subh = h + 8 * j * all.x - 8 * i * all.y;
 
51
            res[2 * i][j] += tex2D(tex_projes, subh, proje + projf);
 
52
            subh -= all.y;
 
53
            res[2 * i + 1][j] += tex2D(tex_projes, subh, proje + projf);
 
54
//          d_SLICE[BLOCK_SIZE_X * gridDim.x * (idy + i * 4) + idx + j * 4] = res[i][j];
 
55
        }
 
56
    }
 
57
 
 
58
    }
 
59
 
 
60
    const int inx = 16 * (tidy%2) + tidx;
 
61
    const int iny = tidy / 2;
 
62
    
 
63
    const int outx = iny + 8 * (inx%4);
 
64
    const int outy = inx/4;
 
65
    
 
66
    const int finx = (tidy%2);
 
67
    const int finy = (2 * (tidx%2) + tidy/8);
 
68
 
 
69
#pragma unroll 4
 
70
    for (int i = 0; i < 4; i++) {
 
71
#pragma unroll 4
 
72
        for (int j = 0; j < 2; j++) {
 
73
            buf[iny][inx] = res[i][j];
 
74
 
 
75
            __syncthreads();
 
76
 
 
77
            float val = buf[outy][outx];
 
78
 
 
79
            for (int i=8; i>=1; i/=2)
 
80
                val += __shfl_xor(val, i, 8);
 
81
 
 
82
            const int rx = 8 * j + finx;
 
83
            const int ry = 4 * i + finy;
 
84
 
 
85
            if (!tidx) {
 
86
                fin[ry][rx] = val;
 
87
            }
 
88
 
 
89
            __syncthreads();
 
90
        }
 
91
    }
 
92
 
 
93
 
 
94
#pragma unroll 4
 
95
    for (int i = 0; i < 4; i++) {
 
96
#pragma unroll 4
 
97
        for (int j = 0; j < 4; j++) {
 
98
            d_SLICE[BLOCK_SIZE_X * gridDim.x * tidy + tidx] = fin[tidy][tidx];
 
99
        }
 
100
    }
 
101
 
 
102
//    d_SLICE[ BLOCK_SIZE_X*gridDim.x*idy + idx ] = res;
 
103
}