Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/pure-cfg/test/MIP/mip.cl
ViewVC logotype

Annotation of /branches/pure-cfg/test/MIP/mip.cl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 477 - (view) (download)

1 : lamonts 302 /* mip.cl
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : lamonts 302 * All rights reserved.
5 :     *
6 :     * An OpenCL file containing a probe kernel and mip kernel implementation
7 :     */
8 :    
9 :     __constant float h[4][4] = { // bspln3
10 :     { 1.33333, 2.0, 1.0, 0.166667 }, // -2 .. -1
11 :     { 0.666667, 0.0, -1.0, -0.5 }, // -1 .. 0
12 :     { 0.666667, 0.0, -1.0, 0.5 }, // 0 .. 1
13 :     { 1.33333, -2.0, 1.0, -0.166667 }, // 1 .. 2
14 :     };
15 :    
16 : jhr 310 //__constant float4 eyeVec = (float4)(25,15,10,1);
17 :     //__constant float4 origVec = (float4)(8.83877,2.5911,7.65275,0);
18 :     //__constant float4 cVec= (float4)(-0.0151831,0.0278357,0,0);
19 :     //__constant float4 rVec = (float4)(0.0074887,0.00408474,-0.0305383,0);
20 :     __constant float4 eyeVec = (float4)(127.331, -1322.05, 272.53, 0);
21 :     __constant float4 origVec = (float4)(122.835,17.7112,188.044, 0);
22 :     __constant float4 cVec= (float4)(-0.00403611,-0.029826,-0.244066, 0);
23 :     __constant float4 rVec = (float4)(-0.245595,-0.0112916,0.00544129, 0);
24 :     __constant float stepSize = 0.5;
25 : lamonts 302 __constant int s = 2;
26 :    
27 :    
28 : jhr 441 __kernel float probe(float * img, int * sAxis, float4 imgPos)
29 :     {
30 : lamonts 302
31 : jhr 441 float probedVal;
32 :     float4 f, nf, t, hx, hy, hz;
33 :     int4 n;
34 : lamonts 302
35 : jhr 441 float4 d = (float4) (h[3][0],h[2][0],h[1][0],h[0][0]);
36 :     float4 c = (float4) (h[3][1],h[2][1],h[1][1],h[0][1]);
37 :     float4 b = (float4) (h[3][2],h[2][2],h[1][2],h[0][2]);
38 :     float4 a = (float4) (h[3][3],h[2][3],h[1][3],h[0][3]);
39 : lamonts 302
40 : jhr 441 f = modf(imgPos,&nf);
41 :     n = convert_int4(nf);
42 :    
43 : lamonts 302
44 : jhr 441 t = (float4) (f.x + 1, f.x, f.x -1, f.x - 2);
45 :     hx = d + t * (c + t * (b + t*a));
46 :     t = (float4) (f.y + 1, f.y, f.y - 1, f.y - 2);
47 :     hy = d + t * (c + t * (b + t*a));
48 :     t = (float4) (f.z + 1, f.z, f.z - 1, f.z -2);
49 :     hz = d + t * (c + t * (b + t*a));
50 : lamonts 302
51 : jhr 441 float vx[4];
52 :     float vy[4];
53 :    
54 :     for(int k = 1-s; k <= s; k++) { // z is the slowest dimension
55 :     for(int j = 1-s; j <= s; j++) { // y is the medium dimension
56 :     int index = sAxis[0]*sAxis[1]*(n.z+k) + sAxis[0]*(n.y+j) + (n.x-1);
57 :     float4 v = (float4)(img[index], img[index+1], img[index+2], img[index+3]);
58 :     vx[j+s-1] = dot(v,hx);
59 :     }
60 :     vy[k+s-1] = dot ((float4) (vx[0],vx[1],vx[2],vx[3]),hy);
61 :     }
62 : lamonts 302
63 : jhr 441 probedVal = dot((float4) (vy[0],vy[1],vy[2],vy[3]),hz);
64 : lamonts 302
65 : jhr 441 return probedVal;
66 : lamonts 302
67 :     }
68 : jhr 441
69 : lamonts 302 __kernel void mip ( float * img,
70 : jhr 441 float * out,
71 :     float16 transformMatrix,
72 :     int2 workDim,
73 :     int * sAxis)
74 :     {
75 : lamonts 302
76 : jhr 441 int row = get_global_id(0), col = get_global_id(1);
77 : lamonts 302
78 : jhr 441 if(row <= workDim.x && col <= workDim.y) {
79 :     float t, probedVal, maxValue = -INFINITY;
80 :     float4 imgPt;
81 : lamonts 177
82 : jhr 441 float4 pos = origVec + (float)row * rVec + (float)col * cVec;
83 :     float4 dir = normalize(pos - eyeVec);
84 : lamonts 177
85 : jhr 441 pos.w = 0.0;
86 :     dir.w = 0.0;
87 : lamonts 177
88 : jhr 441 for(t = 0.0; t < 200; t+= stepSize) {
89 :     pos = pos + stepSize * dir;
90 :    
91 :     // Transform the value to image space position.
92 :     imgPt = (float4) (dot(pos,transformMatrix.s0123),
93 :     dot(pos,transformMatrix.s4567),
94 :     dot(pos,transformMatrix.s89ab),
95 :     dot(pos,transformMatrix.scdef));
96 :    
97 :     if ((imgPt.x > 1 && imgPt.x < (sAxis[0] - 2)
98 :     && (imgPt.y > 1 && imgPt.y < (sAxis[1] - 2))
99 :     && (imgPt.z > 1 && imgPt.z < (sAxis[2] - 2))) {
100 :     probedVal = probe(img,sAxis,imgPt);
101 :     if (maxValue < probedVal)
102 :     maxValue = probedVal;
103 :     }
104 :     }
105 :     out[row * workDim.x + col] = maxValue;
106 :     }
107 : jhr 435 }

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0