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 1340, Mon Jun 13 19:57:19 2011 UTC revision 1341, Tue Jun 14 07:05:07 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
31      void                **inState;      //void                **inState;
32      void                **outState;      //void                **outState;
33        void                *inState;
34        void                *outState;
35      uint8_t             *status;        // array of strand status flags      uint8_t             *status;        // array of strand status flags
36      cl_device_id        device;         // OpenCL device      cl_device_id        device;         // OpenCL device
37      cl_context          context;        // OpenCL execution context      cl_context          context;        // OpenCL execution context
# Line 39  Line 41 
41    
42  static bool InitCL (CLInfo_t *clInfo, Diderot_World_t *wrld);  static bool InitCL (CLInfo_t *clInfo, Diderot_World_t *wrld);
43    
44  extern void Diderot_LoadGlobals (cl_context context, cl_kernel kernel, int argStart);  extern void  Diderot_LoadGlobals (cl_context context, cl_kernel kernel, cl_command_queue cmdQ, int argStart);
45    
46  int main (int argc, const char **argv)  int main (int argc, const char **argv)
47  {  {
48    // get information about OpenCL support    // get information about OpenCL support
# Line 80  Line 83 
83      /* Create the strand in-state and out-state buffers */      /* Create the strand in-state and out-state buffers */
84      cl_mem stateInMem, stateOutMem;      cl_mem stateInMem, stateOutMem;
85    
86    
87      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,
88          wrld->strandSize, *(wrld->inState), &sts);          wrld->strandSize, wrld->inState, &sts);
89           clFinish(wrld->cmdQ);
90      if (sts != CL_SUCCESS) {      if (sts != CL_SUCCESS) {
91          fprintf (stderr, "error creating OpenCL strand in-state buffer\n");          fprintf (stderr, "error creating OpenCL strand in-state buffer\n");
92          exit(1);          exit(1);
93      }      }
94    
95    
96      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,
97          wrld->strandSize, *(wrld->outState), &sts);          wrld->strandSize, wrld->outState, &sts);
98    
99    
100            clFinish(wrld->cmdQ);
101      if (sts != CL_SUCCESS) {      if (sts != CL_SUCCESS) {
102          fprintf (stderr, "error creating OpenCL strand in-state buffer\n");          fprintf (stderr, "error creating OpenCL strand in-state buffer\n");
103          exit(1);          exit(1);
104      }      }
105    
106    
107    /* Set the in-state and out-state strand agruments */    /* Set the in-state and out-state strand agruments */
108      sts = clSetKernelArg (wrld->kernel,  argCount++, sizeof(cl_mem), &stateInMem);      sts = clSetKernelArg (wrld->kernel,  argCount++, sizeof(cl_mem), &stateInMem);
109    
110            clFinish(wrld->cmdQ);
111      if (sts != CL_SUCCESS) {      if (sts != CL_SUCCESS) {
112          fprintf (stderr, "error Setting OpenCL strand in-state argument\n");          fprintf (stderr, "error Setting OpenCL strand in-state argument\n");
113          exit(1);          exit(1);
114      }      }
115    
116    
117    
118      sts = clSetKernelArg (wrld->kernel, argCount++, sizeof(cl_mem), &stateOutMem);      sts = clSetKernelArg (wrld->kernel, argCount++, sizeof(cl_mem), &stateOutMem);
119    
120       clFinish(wrld->cmdQ);
121      if (sts != CL_SUCCESS) {      if (sts != CL_SUCCESS) {
122          fprintf (stderr, "error Setting OpenCL strand out-state argument\n");          fprintf (stderr, "error Setting OpenCL strand out-state argument\n");
123          exit(1);          exit(1);
# Line 110  Line 126 
126    /* Setup up global/local work sizes and fire the kernel for execution */    /* Setup up global/local work sizes and fire the kernel for execution */
127      if (wrld->nDims == 2) {      if (wrld->nDims == 2) {
128          size_t global_work_size[2], local_work_size[2];          size_t global_work_size[2], local_work_size[2];
129    
130          global_work_size[0] = wrld->size[0];          global_work_size[0] = wrld->size[0];
131          global_work_size[1] = wrld->size[1];          global_work_size[1] = wrld->size[1];
132          local_work_size[0] = 1;          local_work_size[0] = 1;
# Line 117  Line 134 
134          cl_int width = global_work_size[1];          cl_int width = global_work_size[1];
135    
136          sts = clSetKernelArg(wrld->kernel, argCount++, sizeof(cl_int), &width);          sts = clSetKernelArg(wrld->kernel, argCount++, sizeof(cl_int), &width);
137    
138    
139            clFinish(wrld->cmdQ);
140    
141          if (sts != CL_SUCCESS) {          if (sts != CL_SUCCESS) {
142              fprintf (stderr, "error Setting OpenCL width argument\n");              fprintf (stderr, "error Setting OpenCL width argument\n");
143              exit(1);              exit(1);
144          }          }
145    
146          Diderot_LoadGlobals(wrld->context, wrld->kernel, argCount);          Diderot_LoadGlobals(wrld->context, wrld->kernel,wrld->cmdQ, argCount);
147    
148          sts = clEnqueueNDRangeKernel(wrld->cmdQ, wrld->kernel, 2, NULL, global_work_size,          sts = clEnqueueNDRangeKernel(wrld->cmdQ, wrld->kernel, 2, NULL, global_work_size,
149              local_work_size, 0, NULL, NULL);              local_work_size, 0, NULL, NULL);
150    
151            clFinish(wrld->cmdQ);
152    
153          if (sts != CL_SUCCESS) {          if (sts != CL_SUCCESS) {
154              fprintf (stderr, "error in executing kernel code:%d\n",sts);              fprintf (stderr, "error in executing kernel code:%d\n",sts);
155              exit(1);              exit(1);
156          }          }
157    
         clFinish(wrld->cmdQ);  
158    
159          sts = clEnqueueReadBuffer(wrld->cmdQ, stateOutMem, CL_TRUE, 0, wrld->strandSize,         sts = clEnqueueReadBuffer(wrld->cmdQ, stateOutMem, CL_TRUE, 0, sizeof(float) * wrld->numStrands,
160              wrld->outState, 0, NULL, NULL);              wrld->outState, 0, NULL, NULL);
161    
162           clFinish(wrld->cmdQ);
163    
164          if (sts != CL_SUCCESS) {          if (sts != CL_SUCCESS) {
165              fprintf (stderr, "error in reading back output code:%d\n",sts);              fprintf (stderr, "error in reading back output code:%d\n",sts);
166              exit(1);              exit(1);
167          }          }
168      }      }
169            fprintf(stderr,"DONE!\n");
170            exit(1);
171  /* FIXME: release all OpenCL objects */  /* FIXME: release all OpenCL objects */
172      clReleaseKernel(wrld->kernel);      clReleaseKernel(wrld->kernel);
173      clReleaseCommandQueue(wrld->cmdQ);      clReleaseCommandQueue(wrld->cmdQ);
# Line 170  Line 196 
196    
197      for (int i = 0;  i < wrld->numStrands;  i++) {      for (int i = 0;  i < wrld->numStrands;  i++) {
198          if (wrld->status[i] == DIDEROT_STABLE)          if (wrld->status[i] == DIDEROT_STABLE)
199              Diderot_Strands[0]->print (outS, wrld->outState[i]);              Diderot_Strands[0]->print (outS, &wrld->outState[i]);
200      }      }
201      fclose (outS);      fclose (outS);
202    
# Line 299  Line 325 
325  }  }
326    
327  // block allocation of an initial collection of strands  // block allocation of an initial collection of strands
328  Diderot_World_t *Diderot_AllocInitially (  Diderot_World_t *Diderot_AllocInitiallyCL (
329      const char *name,           // the name of the program      const char *name,           // the name of the program
330      Strand_t *strand,           // the type of strands being allocated      Strand_t *strand,           // the type of strands being allocated
331             size_t strand_size,              // the sizeof the strand structure
332      bool isArray,               // is the initialization an array or collection?      bool isArray,               // is the initialization an array or collection?
333      uint32_t nDims,             // depth of iteration nesting      uint32_t nDims,             // depth of iteration nesting
334      int32_t *base,              // nDims array of base indices      int32_t *base,              // nDims array of base indices
# Line 333  Line 360 
360    
361    // allocate the strand state pointers    // allocate the strand state pointers
362      wrld->numStrands = numStrands;      wrld->numStrands = numStrands;
363      wrld->strandSize = sizeof(strand) * numStrands;      wrld->strandSize = strand_size * numStrands;
364      wrld->inState = (void **) malloc (numStrands * sizeof(void *));    /*  wrld->inState = (void **) malloc (numStrands * sizeof(void *));
365      wrld->outState = (void **) malloc (numStrands * sizeof(void *));      wrld->outState = (void **) malloc (numStrands * sizeof(void *)); */
366             wrld->inState =  (void *)malloc(wrld->strandSize);
367             wrld->outState = (void *)malloc(wrld->strandSize);
368      wrld->status = (uint8_t *) malloc (numStrands * sizeof(uint8_t));      wrld->status = (uint8_t *) malloc (numStrands * sizeof(uint8_t));
369      if ((wrld->inState == 0) || (wrld->outState == 0) || (wrld->status == 0)) {      if ((wrld->inState == 0) || (wrld->outState == 0) || (wrld->status == 0)) {
370          fprintf (stderr, "unable to allocate strand states\n");          fprintf (stderr, "unable to allocate strand states\n");
# Line 344  Line 373 
373    
374    // initialize strand state pointers etc.    // initialize strand state pointers etc.
375      for (size_t i = 0;  i < numStrands;  i++) {      for (size_t i = 0;  i < numStrands;  i++) {
376          wrld->inState[i] = Diderot_AllocStrand (strand);         // wrld->inState[i] = Diderot_AllocStrand (strand);
377          wrld->outState[i] = Diderot_AllocStrand (strand);         // wrld->outState[i] = Diderot_AllocStrand (strand);
378          wrld->status[i] = DIDEROT_ACTIVE;          wrld->status[i] = DIDEROT_ACTIVE;
379      }      }
380    
# Line 357  Line 386 
386  void *Diderot_InState (Diderot_World_t *wrld, uint32_t i)  void *Diderot_InState (Diderot_World_t *wrld, uint32_t i)
387  {  {
388      assert (i < wrld->numStrands);      assert (i < wrld->numStrands);
389      return wrld->inState[i];      return &wrld->inState[i];
390  }  }
391    
392  void *Diderot_OutState (Diderot_World_t *wrld, uint32_t i)  void *Diderot_OutState (Diderot_World_t *wrld, uint32_t i)
393  {  {
394      assert (i < wrld->numStrands);      assert (i < wrld->numStrands);
395      return wrld->outState[i];      return &wrld->outState[i];
396  }  }
397    
398  bool Diderot_IsActive (Diderot_World_t *wrld, uint32_t i)  bool Diderot_IsActive (Diderot_World_t *wrld, uint32_t i)

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

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