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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/lib/cl-target/main.c
ViewVC logotype

Diff of /branches/pure-cfg/src/lib/cl-target/main.c

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

revision 1341, Tue Jun 14 07:05:07 2011 UTC revision 1342, Tue Jun 14 13:35:43 2011 UTC
# Line 28  Line 28 
28      uint32_t            *size;          // nDims array of iteration sizes      uint32_t            *size;          // nDims array of iteration sizes
29      uint32_t            numStrands;     // number of strands in the world      uint32_t            numStrands;     // number of strands in the world
30      size_t              strandSize;     // the sizeof of the strand buffers      size_t              strandSize;     // the sizeof of the strand buffers
     //void                **inState;  
     //void                **outState;  
31      void                *inState;      void                *inState;
32      void                *outState;      void                *outState;
33      uint8_t             *status;        // array of strand status flags      uint8_t             *status;        // array of strand status flags
# Line 77  Line 75 
75          exit (1);          exit (1);
76    
77      int argCount = 0;      int argCount = 0;
   
78      cl_int sts = CL_SUCCESS;      cl_int sts = CL_SUCCESS;
79    
80      /* Create the strand in-state and out-state buffers */      /* Create the strand in-state and out-state buffers */
81      cl_mem stateInMem, stateOutMem;      cl_mem stateInMem = clCreateBuffer (wrld->context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
   
   
     stateInMem = clCreateBuffer (wrld->context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,  
82          wrld->strandSize, wrld->inState, &sts);          wrld->strandSize, wrld->inState, &sts);
83         clFinish(wrld->cmdQ);         clFinish(wrld->cmdQ);
84      if (sts != CL_SUCCESS) {      if (sts != CL_SUCCESS) {
# Line 92  Line 86 
86          exit(1);          exit(1);
87      }      }
88    
89        cl_mem stateOutMem = clCreateBuffer (wrld->context, CL_MEM_READ_WRITE| CL_MEM_COPY_HOST_PTR,
     stateOutMem = clCreateBuffer (wrld->context, CL_MEM_READ_WRITE| CL_MEM_COPY_HOST_PTR,  
90          wrld->strandSize, wrld->outState, &sts);          wrld->strandSize, wrld->outState, &sts);
   
   
91          clFinish(wrld->cmdQ);          clFinish(wrld->cmdQ);
92      if (sts != CL_SUCCESS) {      if (sts != CL_SUCCESS) {
93          fprintf (stderr, "error creating OpenCL strand in-state buffer\n");          fprintf (stderr, "error creating OpenCL strand in-state buffer\n");
94          exit(1);          exit(1);
95      }      }
96    
   
97    /* Set the in-state and out-state strand agruments */    /* Set the in-state and out-state strand agruments */
98      sts = clSetKernelArg (wrld->kernel,  argCount++, sizeof(cl_mem), &stateInMem);      sts = clSetKernelArg (wrld->kernel,  argCount++, sizeof(cl_mem), &stateInMem);
   
99          clFinish(wrld->cmdQ);          clFinish(wrld->cmdQ);
100      if (sts != CL_SUCCESS) {      if (sts != CL_SUCCESS) {
101          fprintf (stderr, "error Setting OpenCL strand in-state argument\n");          fprintf (stderr, "error Setting OpenCL strand in-state argument\n");
102          exit(1);          exit(1);
103      }      }
104    
   
   
105      sts = clSetKernelArg (wrld->kernel, argCount++, sizeof(cl_mem), &stateOutMem);      sts = clSetKernelArg (wrld->kernel, argCount++, sizeof(cl_mem), &stateOutMem);
   
106     clFinish(wrld->cmdQ);     clFinish(wrld->cmdQ);
107   if (sts != CL_SUCCESS) {   if (sts != CL_SUCCESS) {
108          fprintf (stderr, "error Setting OpenCL strand out-state argument\n");          fprintf (stderr, "error Setting OpenCL strand out-state argument\n");
# Line 134  Line 120 
120          cl_int width = global_work_size[1];          cl_int width = global_work_size[1];
121    
122          sts = clSetKernelArg(wrld->kernel, argCount++, sizeof(cl_int), &width);          sts = clSetKernelArg(wrld->kernel, argCount++, sizeof(cl_int), &width);
   
   
123          clFinish(wrld->cmdQ);          clFinish(wrld->cmdQ);
   
124          if (sts != CL_SUCCESS) {          if (sts != CL_SUCCESS) {
125              fprintf (stderr, "error Setting OpenCL width argument\n");              fprintf (stderr, "error Setting OpenCL width argument\n");
126              exit(1);              exit(1);
# Line 147  Line 130 
130    
131          sts = clEnqueueNDRangeKernel(wrld->cmdQ, wrld->kernel, 2, NULL, global_work_size,          sts = clEnqueueNDRangeKernel(wrld->cmdQ, wrld->kernel, 2, NULL, global_work_size,
132              local_work_size, 0, NULL, NULL);              local_work_size, 0, NULL, NULL);
   
133          clFinish(wrld->cmdQ);          clFinish(wrld->cmdQ);
   
134               if (sts != CL_SUCCESS) {               if (sts != CL_SUCCESS) {
135              fprintf (stderr, "error in executing kernel code:%d\n",sts);              fprintf (stderr, "error in executing kernel code:%d\n",sts);
136              exit(1);              exit(1);
137          }          }
138    
   
139         sts = clEnqueueReadBuffer(wrld->cmdQ, stateOutMem, CL_TRUE, 0, sizeof(float) * wrld->numStrands,         sts = clEnqueueReadBuffer(wrld->cmdQ, stateOutMem, CL_TRUE, 0, sizeof(float) * wrld->numStrands,
140              wrld->outState, 0, NULL, NULL);              wrld->outState, 0, NULL, NULL);
   
141         clFinish(wrld->cmdQ);         clFinish(wrld->cmdQ);
   
142          if (sts != CL_SUCCESS) {          if (sts != CL_SUCCESS) {
143              fprintf (stderr, "error in reading back output code:%d\n",sts);              fprintf (stderr, "error in reading back output code:%d\n",sts);
144              exit(1);              exit(1);
145          }          }
146      }      }
147    
148    /* FIXME: from here on down, things don't make sense!!! The "SOMETHING" below should be
149     * the code above.  Also, what happens if nDims != 2?  We never output results!
150     */
151          fprintf(stderr,"DONE!\n");          fprintf(stderr,"DONE!\n");
152          exit(1);          exit(1);
153    
154  /* FIXME: release all OpenCL objects */  /* FIXME: release all OpenCL objects */
155      clReleaseKernel(wrld->kernel);      clReleaseKernel(wrld->kernel);
156      clReleaseCommandQueue(wrld->cmdQ);      clReleaseCommandQueue(wrld->cmdQ);
# Line 233  Line 216 
216    
217      return source;      return source;
218  }  }
219  void clLogMessagesToStdoutAPPLE(   const char * errstr ,  
220                                            const void * private_info,  void clLogMessagesToStdoutAPPLE (const char *errstr, const void *private_info, size_t cb, void *user_data)
                                           size_t  cb ,  
                                           void * user_data  )  
221  {  {
222          fprintf(stderr,"%s\n",errstr);          fprintf(stderr,"%s\n",errstr);
   
223  }  }
224    
225  /*! \brief build an OpenCL program from source.  /*! \brief build an OpenCL program from source.
226   */   */
227  static bool InitCL (CLInfo_t *clInfo, Diderot_World_t *wrld)  static bool InitCL (CLInfo_t *clInfo, Diderot_World_t *wrld)
# Line 363  Line 344 
344      wrld->strandSize = strand_size * numStrands;      wrld->strandSize = strand_size * numStrands;
345    /*  wrld->inState = (void **) malloc (numStrands * sizeof(void *));    /*  wrld->inState = (void **) malloc (numStrands * sizeof(void *));
346      wrld->outState = (void **) malloc (numStrands * sizeof(void *)); */      wrld->outState = (void **) malloc (numStrands * sizeof(void *)); */
347           wrld->inState =  (void *)malloc(wrld->strandSize);      wrld->inState =  malloc (wrld->strandSize);
348           wrld->outState = (void *)malloc(wrld->strandSize);      wrld->outState = malloc (wrld->strandSize);
349      wrld->status = (uint8_t *) malloc (numStrands * sizeof(uint8_t));      wrld->status = (uint8_t *) malloc (numStrands * sizeof(uint8_t));
350      if ((wrld->inState == 0) || (wrld->outState == 0) || (wrld->status == 0)) {      if ((wrld->inState == 0) || (wrld->outState == 0) || (wrld->status == 0)) {
351          fprintf (stderr, "unable to allocate strand states\n");          fprintf (stderr, "unable to allocate strand states\n");

Legend:
Removed from v.1341  
changed lines
  Added in v.1342

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