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 1345, Tue Jun 14 16:19:21 2011 UTC revision 1346, Wed Jun 15 06:43:14 2011 UTC
# Line 27  Line 27 
27      int32_t             *base;          // nDims array of base indices      int32_t             *base;          // nDims array of base indices
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      unsigned int        strandSize;     // the sizeof of the strand buffers
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 40  Line 40 
40  static bool InitCL (CLInfo_t *clInfo, Diderot_World_t *wrld);  static bool InitCL (CLInfo_t *clInfo, Diderot_World_t *wrld);
41    
42  extern void  Diderot_LoadGlobals (cl_context context, cl_kernel kernel, cl_command_queue cmdQ, int argStart);  extern void  Diderot_LoadGlobals (cl_context context, cl_kernel kernel, cl_command_queue cmdQ, int argStart);
43    extern void printArray(FILE *outS,void * array) ;
44  int main (int argc, const char **argv)  int main (int argc, const char **argv)
45  {  {
46    // get information about OpenCL support    // get information about OpenCL support
# Line 94  Line 94 
94          exit(1);          exit(1);
95      }      }
96    
97       cl_mem statusMem  = clCreateBuffer (wrld->context, CL_MEM_READ_WRITE| CL_MEM_COPY_HOST_PTR,
98            sizeof(uint8_t) * wrld->numStrands, wrld->status, &sts);
99    
100        clFinish (wrld->cmdQ);
101    
102        if (sts != CL_SUCCESS) {
103            fprintf (stderr, "error creating OpenCL world status buffer\n");
104            exit(1);
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      clFinish (wrld->cmdQ);      clFinish (wrld->cmdQ);
# Line 109  Line 119 
119          exit(1);          exit(1);
120      }      }
121    
122    /* Setup up global/local work sizes and fire the kernel for execution */      sts = clSetKernelArg (wrld->kernel,  argCount++, sizeof(cl_mem), &statusMem);
123        clFinish (wrld->cmdQ);
124        if (sts != CL_SUCCESS) {
125            fprintf (stderr, "error Setting OpenCL world status argument\n");
126            exit(1);
127        }
128    
129       double t0 = GetTime();
130    /* FIXME: Also, what happens if nDims != 2?  We never output results! */
131    
132      if (wrld->nDims == 2) {      if (wrld->nDims == 2) {
133          size_t global_work_size[2], local_work_size[2];          size_t global_work_size[2], local_work_size[2];
134    
# Line 136  Line 155 
155              exit(1);              exit(1);
156          }          }
157    
158          sts = clEnqueueReadBuffer(wrld->cmdQ, stateOutMem, CL_TRUE, 0, sizeof(float) * wrld->numStrands,          sts = clEnqueueReadBuffer(wrld->cmdQ, stateOutMem, CL_TRUE, 0,   wrld->strandSize,
159              wrld->outState, 0, NULL, NULL);              wrld->outState, 0, NULL, NULL);
160          clFinish(wrld->cmdQ);          clFinish(wrld->cmdQ);
161          if (sts != CL_SUCCESS) {          if (sts != CL_SUCCESS) {
162              fprintf (stderr, "error in reading back output code:%d\n",sts);              fprintf (stderr, "error in reading back output code:%d\n",sts);
163              exit(1);              exit(1);
164          }          }
     }  
165    
166  /* FIXME: from here on down, things don't make sense!!! The "SOMETHING" below should be          sts = clEnqueueReadBuffer(wrld->cmdQ, statusMem, CL_TRUE, 0, sizeof(uint8_t) * wrld->numStrands,
167   * the code above.  Also, what happens if nDims != 2?  We never output results!              wrld->status, 0, NULL, NULL);
168   */          clFinish(wrld->cmdQ);
169          fprintf(stderr,"DONE!\n");          if (sts != CL_SUCCESS) {
170                fprintf (stderr, "error in reading back output code:%d\n",sts);
171          exit(1);          exit(1);
172            }
173    
174        }
175    
176  /* FIXME: release all OpenCL objects */  /* FIXME: release all OpenCL objects */
177      clReleaseKernel(wrld->kernel);      clReleaseKernel(wrld->kernel);
178      clReleaseCommandQueue(wrld->cmdQ);      clReleaseCommandQueue(wrld->cmdQ);
179      clReleaseContext(wrld->context);      clReleaseContext(wrld->context);
180    
     double t0 = GetTime();  
   
          /* SOMETHING */  
181    
182      double totalTime = GetTime() - t0;      double totalTime = GetTime() - t0;
183    
# Line 177  Line 196 
196          exit (8);          exit (8);
197      }      }
198    
199      for (int i = 0;  i < wrld->numStrands;  i++) {      /*for (int i = 0;  i < wrld->numStrands;  i++) {
200          if (wrld->status[i] == DIDEROT_STABLE)          if (wrld->status[i] == DIDEROT_STABILIZE)
201              Diderot_Strands[0]->print (outS, &wrld->outState[i]);              Diderot_Strands[0]->print (outS, &wrld->outState[i]);
202      }      }*/
203        Diderot_Strands[0]->print (outS,wrld->status,wrld->numStrands, wrld->outState);
204      fclose (outS);      fclose (outS);
205    
206      Diderot_Shutdown (wrld);      Diderot_Shutdown (wrld);
# Line 306  Line 326 
326  }  }
327    
328  // block allocation of an initial collection of strands  // block allocation of an initial collection of strands
329  Diderot_World_t *Diderot_AllocInitiallyCL (  Diderot_World_t *Diderot_AllocInitially(
330      const char *name,           // the name of the program      const char *name,           // the name of the program
331      Strand_t *strand,           // the type of strands being allocated      Strand_t *strand,           // the type of strands being allocated
          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 341  Line 360 
360    
361    // allocate the strand state pointers    // allocate the strand state pointers
362      wrld->numStrands = numStrands;      wrld->numStrands = numStrands;
363      wrld->strandSize = strand_size * numStrands;      wrld->strandSize = strand->stateSzb * 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 =  malloc (wrld->strandSize);      wrld->inState =  malloc (wrld->strandSize);
# Line 356  Line 375 
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_NEW;
379      }      }
380    
381      return wrld;      return wrld;

Legend:
Removed from v.1345  
changed lines
  Added in v.1346

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