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

SCM Repository

[diderot] Diff of /branches/pure-cfg/test/MIP/mip_opencl.c
ViewVC logotype

Diff of /branches/pure-cfg/test/MIP/mip_opencl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 191, Mon Aug 2 14:05:11 2010 UTC revision 218, Tue Aug 3 19:40:56 2010 UTC
# Line 1  Line 1 
1    /**
2     *
3     * To View the Image
4     * =========================
5     * ./unu reshape -i mip.txt -s 200 200 | ./unu quantize -b 8 -o new.png
6     */
7  #include <OpenCL/OpenCl.h>  #include <OpenCL/OpenCl.h>
8  #include <assert.h>  #include <assert.h>
9  #include <stdio.h>  #include <stdio.h>
# Line 7  Line 13 
13    
14  #include <teem/nrrd.h>  #include <teem/nrrd.h>
15    
16  #define SIZE 200  #define SIZE 201
17    
18  /*typedef float vec3[3];  /*typedef float vec3[3];
19    
# Line 110  Line 116 
116    
117          return source;          return source;
118  }  }
119    void saveResults (float * matrix, int size)
120    {
121            int i;
122            float max = -INFINITY;
123            FILE * out_file;
124            out_file = fopen("mip.txt", "w");
125        if (out_file == NULL) {
126            fprintf(stderr,"Can not open output file\n");
127            exit (8);
128        }
129    
130        for(i = 0; i < size; i++)
131        {
132            if(matrix[i] == -INFINITY || matrix[i] < 0)
133               fprintf(out_file,"%f\n",0.0f);
134            else
135               fprintf(out_file,"%f\n",matrix[i]);
136    
137             if(matrix[i] > max)
138                    max = matrix[i];
139    
140       }
141       printf("Max: %f\n",max);
142       fclose(out_file);
143    
144    
145    }
146  float det3x3(float a, float b, float c, float d, float e, float f, float g, float h, float i)  float det3x3(float a, float b, float c, float d, float e, float f, float g, float h, float i)
147  {  {
148     return ( (a)*(e)*(i)     return ( (a)*(e)*(i)
# Line 248  Line 281 
281              transformMatrix[((size + 1) * (size)) + i ] = 0;              transformMatrix[((size + 1) * (size)) + i ] = 0;
282          }          }
283          transformMatrix[((size + 1) * (size)) + size ] = 1;          transformMatrix[((size + 1) * (size)) + size ] = 1;
284    
285    printMatrix (transformMatrix, 4);
286  }  }
287  Nrrd * loadNrrdFile(char * filename)  Nrrd * loadNrrdFile(char * filename)
288  {  {
# Line 376  Line 411 
411          //Load the transformMatrix          //Load the transformMatrix
412          loadTransformMatrix(nin,transformMatrix);          loadTransformMatrix(nin,transformMatrix);
413          invMatrix(transformMatrix,inverseMatrix);          invMatrix(transformMatrix,inverseMatrix);
414    printf("Inverse\n"); printMatrix(inverseMatrix, 4);
415    
416          err |= clEnqueueWriteBuffer(queue,imageData_mem,CL_TRUE,0,imageDataSize,          err |= clEnqueueWriteBuffer(queue,imageData_mem,CL_TRUE,0,imageDataSize,
417                                                                  nin->data ,0,NULL,NULL);                                                                  nin->data ,0,NULL,NULL);
# Line 406  Line 442 
442          err |=clSetKernelArg(kernel,9,sizeof(float), &stepSize);          err |=clSetKernelArg(kernel,9,sizeof(float), &stepSize);
443          err |=clSetKernelArg(kernel,10,sizeof(int), &nin->axis[1].size);          err |=clSetKernelArg(kernel,10,sizeof(int), &nin->axis[1].size);
444          err |=clSetKernelArg(kernel,11,sizeof(int), &nin->axis[2].size);          err |=clSetKernelArg(kernel,11,sizeof(int), &nin->axis[2].size);
445            err |=clSetKernelArg(kernel,12,sizeof(int), &nin->axis[0].size);
446    
447            printf("Error: %d\n",err);
448          assert(err == CL_SUCCESS);          assert(err == CL_SUCCESS);
449    
450          /** Retrieve the Recommend Work Group Size */          /** Retrieve the Recommend Work Group Size */
# Line 425  Line 463 
463    
464          err = clEnqueueReadBuffer(queue,out_mem,CL_TRUE,0, sizeof(float) * (SIZE *SIZE),out,0,NULL,NULL);          err = clEnqueueReadBuffer(queue,out_mem,CL_TRUE,0, sizeof(float) * (SIZE *SIZE),out,0,NULL,NULL);
465    
466          printMatrix(out,20);          saveResults(out,SIZE * SIZE);
467    
468          clReleaseKernel(kernel);          clReleaseKernel(kernel);
469          clReleaseProgram(program);          clReleaseProgram(program);
# Line 439  Line 477 
477    
478          return CL_SUCCESS;          return CL_SUCCESS;
479  }  }
480    #define VOX1_Z
481  int main (int argc, char ** argv)  int main (int argc, char ** argv)
482  {  {
483          //Declaring and initializing input variables          //Declaring and initializing input variables
484          Nrrd * nin;          Nrrd * nin;
485    #ifdef TXS
486          char * dataFile = "txs.nrrd";          char * dataFile = "txs.nrrd";
487          cl_float4 eyeVector = {25,15,10};          cl_float4 eyeVector = {25,15,10, 1};
488          cl_float4 origVector = {8.83877,2.5911,7.65275};          cl_float4 origVector = {8.83877,2.5911,7.65275};
489          cl_float4 cVector = {-0.0151831,0.0278357,0};          cl_float4 cVector = {-0.0151831,0.0278357,0};
490          cl_float4 rVector = {0.0074887,0.00408474,-0.0305383};          cl_float4 rVector = {0.0074887,0.00408474,-0.0305383};
491    #endif
492    #ifdef VOX1_X
493            char * dataFile = "../../data/vox1.nrrd";
494            cl_float4 eyeVector = {-8,2,2, 1};
495            cl_float4 origVector = {0,3.4036,3.4036};
496            cl_float4 cVector = {0,-0.014036,0};
497            cl_float4 rVector = {0,0,-0.014036};
498    #endif
499    #ifdef VOX1_Y
500            char * dataFile = "../../data/vox1.nrrd";
501            cl_float4 eyeVector = {2,-8,2, 1};
502            cl_float4 origVector = {0.596402,0,3.4036, 1};
503            cl_float4 cVector = {0.014036,0,0};
504            cl_float4 rVector = {0,0,-0.014036};
505    #endif
506    #ifdef VOX1_Z
507            char * dataFile = "../../data/vox1-11.nrrd";
508            cl_float4 eyeVector = {2,2,-8, 1};
509            cl_float4 origVector = {3.4036,3.4036,0, 1};
510            cl_float4 cVector = {-0.014036,0,0,0};
511            cl_float4 rVector = {0,-0.014036,0};
512    #endif
513          float stepSize = 0.1;          float stepSize = 0.1;
514          float h1[] = {0.666667,0,-1,0.5};          float h1[] = {0.666667,0,-1,0.5};
515          float h2[] = {1.33333, -2, 1,-0.166667};          float h2[] = {1.33333, -2, 1,-0.166667};

Legend:
Removed from v.191  
changed lines
  Added in v.218

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