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

SCM Repository

[diderot] Diff of /trunk/test/probe/probe.c
ViewVC logotype

Diff of /trunk/test/probe/probe.c

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

revision 261, Tue Aug 10 15:36:13 2010 UTC revision 262, Tue Aug 10 17:35:56 2010 UTC
# Line 331  Line 331 
331    
332     fclose(infile);     fclose(infile);
333  }  }
334  int exe_Probe_Kernel(Nrrd * nin, float * probedPositions, float * h1, float * h2, float * out)  int exe_Probe_Kernel(Nrrd * nin, float * probedPositions, float *h[4], float * out)
335  {  {
336    
337          cl_program program;          cl_program program;
# Line 349  Line 349 
349    
350          int imageDataSize =  (int)nrrdElementNumber(nin);          int imageDataSize =  (int)nrrdElementNumber(nin);
351    
352          cl_mem imageData_mem, out_mem, h1_mem, h2_mem, positions_mem;      cl_mem imageData_mem, out_mem, h_mem[4], positions_mem;
353    
354          /** Setup Device **/          /** Setup Device **/
355          err = clGetDeviceIDs(NULL,CL_DEVICE_TYPE_CPU,1,&cpu,NULL);          err = clGetDeviceIDs(NULL,CL_DEVICE_TYPE_CPU,1,&cpu,NULL);
# Line 410  Line 410 
410    
411          /** Memory Allocation for the Matrices **/          /** Memory Allocation for the Matrices **/
412    
413          h1_mem = clCreateBuffer(context,CL_MEM_READ_ONLY,sizeof(float) * 4,NULL,NULL);      for (int i = 0;  i < 4;  i++) {
414          err |= clEnqueueWriteBuffer(queue,h1_mem,CL_TRUE,0,sizeof(float) * 4,          h_mem[i] = clCreateBuffer(context,CL_MEM_READ_ONLY,sizeof(float) * 4,NULL,NULL);
415                                                                  (void *)h1 ,0,NULL,NULL);          err |= clEnqueueWriteBuffer(queue,h_mem[i],CL_TRUE,0,sizeof(float) * 4,
416                                    (void *)h[i] ,0,NULL,NULL);
417          h2_mem = clCreateBuffer(context,CL_MEM_READ_ONLY,sizeof(float) * 4,NULL,NULL);      }
         err |= clEnqueueWriteBuffer(queue,h2_mem,CL_TRUE,0,sizeof(float) * 4,  
                                                                 (void *)h2 ,0,NULL,NULL);  
   
418    
419          positions_mem = clCreateBuffer(context,CL_MEM_READ_ONLY,sizeof(float) * (SIZE *3),NULL,NULL);          positions_mem = clCreateBuffer(context,CL_MEM_READ_ONLY,sizeof(float) * (SIZE *3),NULL,NULL);
420          err |= clEnqueueWriteBuffer(queue,positions_mem,CL_TRUE,0,sizeof(float) * (SIZE *3),          err |= clEnqueueWriteBuffer(queue,positions_mem,CL_TRUE,0,sizeof(float) * (SIZE *3),
# Line 445  Line 442 
442          global_work_size[0] = SIZE;          global_work_size[0] = SIZE;
443          local_work_size[0] = 1;          local_work_size[0] = 1;
444    
445          err  =clSetKernelArg(kernel,0,sizeof(cl_mem), &imageData_mem);      int idx = 0;
446          err |=clSetKernelArg(kernel,1,sizeof(cl_mem), &h1_mem);      err  =clSetKernelArg(kernel, idx++, sizeof(cl_mem), &imageData_mem);
447          err |=clSetKernelArg(kernel,2,sizeof(cl_mem), &h2_mem);      err |=clSetKernelArg(kernel, idx++, sizeof(cl_mem), &(h_mem[0]));
448          err |=clSetKernelArg(kernel,3,sizeof(cl_mem), &positions_mem);      err |=clSetKernelArg(kernel, idx++, sizeof(cl_mem), &(h_mem[1]));
449          err |=clSetKernelArg(kernel,4,sizeof(cl_mem), &out_mem);      err |=clSetKernelArg(kernel, idx++, sizeof(cl_mem), &(h_mem[2]));
450          err |=clSetKernelArg(kernel,5,sizeof(cl_float16), &inverseMatrix);      err |=clSetKernelArg(kernel, idx++, sizeof(cl_mem), &(h_mem[3]));
451          err |=clSetKernelArg(kernel,6,sizeof(int), &nin->axis[1].size);      err |=clSetKernelArg(kernel, idx++, sizeof(cl_mem), &positions_mem);
452          err |=clSetKernelArg(kernel,7,sizeof(int), &nin->axis[2].size);      err |=clSetKernelArg(kernel, idx++, sizeof(cl_mem), &out_mem);
453          err |=clSetKernelArg(kernel,8,sizeof(int), &nin->axis[0].size);      err |=clSetKernelArg(kernel, idx++, sizeof(cl_float16), &inverseMatrix);
454        err |=clSetKernelArg(kernel, idx++, sizeof(int), &nin->axis[1].size);
455        err |=clSetKernelArg(kernel, idx++, sizeof(int), &nin->axis[2].size);
456        err |=clSetKernelArg(kernel, idx++, sizeof(int), &nin->axis[0].size);
457    
458          assert(err == CL_SUCCESS);          assert(err == CL_SUCCESS);
459    
# Line 482  Line 482 
482          clReleaseContext(context);          clReleaseContext(context);
483    
484          clReleaseMemObject(imageData_mem);          clReleaseMemObject(imageData_mem);
485          clReleaseMemObject(h1_mem);      for (int i = 0;  i < 4;  i++)
486          clReleaseMemObject(h2_mem);          clReleaseMemObject(h_mem[i]);
487          clReleaseMemObject(out_mem);          clReleaseMemObject(out_mem);
488          clReleaseMemObject(positions_mem);          clReleaseMemObject(positions_mem);
489          return CL_SUCCESS;          return CL_SUCCESS;
# Line 493  Line 493 
493  {  {
494          //Declaring and initializing input variables          //Declaring and initializing input variables
495          Nrrd * nin;          Nrrd * nin;
496          char * probeValuesFile = "../../../data/plane-probe-pos-x.txt";      char * probeValuesFile = "../../data/plane-probe-pos-x.txt";
497          char * dataFile = "../../../data/plane-x9.nrrd";      char * dataFile = "../../data/plane-x9.nrrd";
498          float h1[] = {0.666667,0,-1,0.5};      float h0[] = {1.33333,  2,  1,  0.166667};          /* -2..-1 */
499          float h2[] = {1.33333, -2, 1,-0.166667};      float h1[] = {0.666667, 0, -1, -0.5};               /* -1..0 */
500        float h2[] = {0.666667, 0, -1,  0.5};               /* 0..1 */
501        float h3[] = {1.33333, -2,  1, -0.166667};          /* 1..2 */
502        float *h[4] = {h0, h1, h2, h3};
503          float * out;          float * out;
504          float * posValues;          float * posValues;
505    
506        if (argc == 3) {
507            probeValuesFile = argv[1];
508            dataFile = argv[2];
509        }
510        else if (argc > 1) {
511            fprintf (stderr, "usage: probe values-file data-file\n");
512            exit (1);
513        }
514    
515          out = (float *) malloc(sizeof(float) * SIZE);          out = (float *) malloc(sizeof(float) * SIZE);
516          posValues = (float *) malloc(sizeof(float) * (SIZE * 3));          posValues = (float *) malloc(sizeof(float) * (SIZE * 3));
517    
518          nin = loadNrrdFile(dataFile);          nin = loadNrrdFile(dataFile);
519          loadProbePositions(probeValuesFile,posValues);          loadProbePositions(probeValuesFile,posValues);
520    
521          exe_Probe_Kernel(nin,posValues,h1,h2,out);      exe_Probe_Kernel(nin,posValues,h,out);
   
522    
523          return 0;          return 0;
524  }  }

Legend:
Removed from v.261  
changed lines
  Added in v.262

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