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 1471, Sat Aug 13 11:46:41 2011 UTC revision 1472, Fri Aug 19 01:54:43 2011 UTC
# Line 115  Line 115 
115          exit (1);          exit (1);
116    
117    /* Conversion of strands from their host types to their shadow types */    /* Conversion of strands from their host types to their shadow types */
118      void *shadowInState = malloc(Diderot_Strands[0]->shadowStrandSzb * wrld->numStrands);      void *shadowInState = CheckedAlloc(Diderot_Strands[0]->shadowStrandSzb * wrld->numStrands);
119      uint8_t *strandPtr = (uint8_t *)wrld->inState;      uint8_t *strandPtr = (uint8_t *)wrld->inState;
120      uint8_t *strandShadowPtr = (uint8_t *)shadowInState;      uint8_t *strandShadowPtr = (uint8_t *)shadowInState;
121      size_t shadowSize = Diderot_Strands[0]->shadowStrandSzb * wrld->numStrands;      size_t shadowSize = Diderot_Strands[0]->shadowStrandSzb * wrld->numStrands;
# Line 187  Line 187 
187      CheckErrorCode (sts,"error creating OpenCL number of avaliable  buffer\n");      CheckErrorCode (sts,"error creating OpenCL number of avaliable  buffer\n");
188    
189      workerQueueSize = sizeof(int) * numberOfWorkGroups;      workerQueueSize = sizeof(int) * numberOfWorkGroups;
190        if ((workQueue = (int *)CheckedAlloc(workerQueueSize)) == NULL) {
     if ((workQueue = (int *)malloc(workerQueueSize)) == NULL) {  
191          fprintf(stderr, "error in allocationg workqueue");          fprintf(stderr, "error in allocationg workqueue");
192          exit(1);          exit(1);
193      }      }
# Line 264  Line 263 
263    
264    // here we have the final state of all of the strands in the "in" buffer    // here we have the final state of all of the strands in the "in" buffer
265      int outFileNameLen = strlen(wrld->name) + 5;      int outFileNameLen = strlen(wrld->name) + 5;
266      char *outFileName = (char *)malloc(outFileNameLen);      char *outFileName = (char *)CheckedAlloc(outFileNameLen);
267      snprintf (outFileName, outFileNameLen, "%s.txt", wrld->name);      snprintf (outFileName, outFileNameLen, "%s.txt", wrld->name);
268      FILE *outS = fopen(outFileName, "w");      FILE *outS = fopen(outFileName, "w");
269      if (outS == NULL) {      if (outS == NULL) {
# Line 353  Line 352 
352          exit (1);          exit (1);
353      }      }
354    
355      char *source = (char *) malloc(statbuf.st_size + 1);      char *source = (char *)CheckedAlloc(statbuf.st_size + 1);
356      if (source == 0) {      if (source == 0) {
357          fprintf (stderr, "unable to allocate memory for OpenCL source\n");          fprintf (stderr, "unable to allocate memory for OpenCL source\n");
358          exit (1);          exit (1);
# Line 391  Line 390 
390      int i;      int i;
391      for (i = 0;  i < clInfo->platforms[0].numDevices;  i++) {      for (i = 0;  i < clInfo->platforms[0].numDevices;  i++) {
392          if (isGPUDevice (&(clInfo->platforms[0].devices[i]))          if (isGPUDevice (&(clInfo->platforms[0].devices[i]))
393          &&  clInfo->platforms[0].devices[i].isAvail)          &&  clInfo->platforms[0].devices[i].isAvail) {
         {  
394              dev = &(clInfo->platforms[0].devices[i]);              dev = &(clInfo->platforms[0].devices[i]);
395              break;              break;
396          }          }
# Line 416  Line 414 
414    
415    // create the program from the source    // create the program from the source
416      int fnameLen = strlen(wrld->name) + 4;  // name + ".cl\0"      int fnameLen = strlen(wrld->name) + 4;  // name + ".cl\0"
417      char *fname = (char *)malloc(fnameLen);      char *fname = (char *)CheckedAlloc(fnameLen);
418      snprintf(fname, fnameLen, "%s.cl", wrld->name);      snprintf(fname, fnameLen, "%s.cl", wrld->name);
419      char *updateSource = LoadSource (fname);      char *updateSource = LoadSource (fname);
420      free (fname);      free (fname);
# Line 431  Line 429 
429    // build the program    // build the program
430      char options[1024];      char options[1024];
431      snprintf (options, sizeof(options),      snprintf (options, sizeof(options),
432          "-D DIDEROT_CL_VERSION=%d -I %s -w",          "-D DIDEROT_CL_VERSION=%d -D DIDEROT_CU_WIDTH=%d -I %s -w",
433          100*dev->majorVersion + dev->minorVersion,          100*dev->majorVersion + dev->minorVersion,
434            dev->cuWidth,
435          DIDEROT_INCLUDE_PATH);          DIDEROT_INCLUDE_PATH);
436        if (VerboseFlg) {
437            fprintf (stderr, "clBuildProgram options: %s\n", options);
438        }
439      sts = clBuildProgram (prog, 1, &(dev->id), options, 0, 0);      sts = clBuildProgram (prog, 1, &(dev->id), options, 0, 0);
440      if (sts != CL_SUCCESS) {      if (sts != CL_SUCCESS) {
441          size_t logSzb;          size_t logSzb;
442          clGetProgramBuildInfo (prog, dev->id, CL_PROGRAM_BUILD_LOG, 0, 0, &logSzb);          clGetProgramBuildInfo (prog, dev->id, CL_PROGRAM_BUILD_LOG, 0, 0, &logSzb);
443          char *log = malloc(logSzb+1);          char *log = CheckedAlloc(logSzb+1);
444          clGetProgramBuildInfo (prog, dev->id, CL_PROGRAM_BUILD_LOG, logSzb, log, &logSzb);          clGetProgramBuildInfo (prog, dev->id, CL_PROGRAM_BUILD_LOG, logSzb, log, &logSzb);
445          log[logSzb] = '\0';          log[logSzb] = '\0';
446          fprintf (stderr, "error compiling program:\n%s\n", log);          fprintf (stderr, "error compiling program:\n%s\n", log);
# Line 477  Line 479 
479  // this should be the part of the scheduler  // this should be the part of the scheduler
480  void *Diderot_AllocStrand (Strand_t *strand)  void *Diderot_AllocStrand (Strand_t *strand)
481  {  {
482      return malloc(strand->stateSzb);      return CheckedAlloc(strand->stateSzb);
483  }  }
484    
485  // block allocation of an initial collection of strands  // block allocation of an initial collection of strands
# Line 489  Line 491 
491      int32_t *base,              // nDims array of base indices      int32_t *base,              // nDims array of base indices
492      uint32_t *size)             // nDims array of iteration sizes      uint32_t *size)             // nDims array of iteration sizes
493  {  {
494      Diderot_World_t *wrld = (Diderot_World_t *) malloc (sizeof(Diderot_World_t));      Diderot_World_t *wrld = NEW(Diderot_World_t);
495      if (wrld == 0) {      if (wrld == 0) {
496          fprintf (stderr, "unable to allocate world\n");          fprintf (stderr, "unable to allocate world\n");
497          exit (1);          exit (1);
# Line 498  Line 500 
500      wrld->name = name; /* NOTE: we are assuming that name is statically allocated! */      wrld->name = name; /* NOTE: we are assuming that name is statically allocated! */
501      wrld->isArray = isArray;      wrld->isArray = isArray;
502      wrld->nDims = nDims;      wrld->nDims = nDims;
503      wrld->base = (int32_t *) malloc (nDims * sizeof(int32_t));      wrld->base = NEWVEC(int32_t, nDims);
504      wrld->size = (uint32_t *) malloc (nDims * sizeof(uint32_t));      wrld->size = NEWVEC(uint32_t, nDims);
505      size_t numStrands = 1;      size_t numStrands = 1;
506      for (int i = 0;  i < wrld->nDims;  i++) {      for (int i = 0;  i < wrld->nDims;  i++) {
507          numStrands *= size[i];          numStrands *= size[i];
# Line 516  Line 518 
518    // allocate the strand state pointers    // allocate the strand state pointers
519      wrld->numStrands = numStrands;      wrld->numStrands = numStrands;
520      wrld->strandSize = strand->stateSzb * numStrands;      wrld->strandSize = strand->stateSzb * numStrands;
521    /*  wrld->inState = (void **) malloc (numStrands * sizeof(void *));  /*
522      wrld->outState = (void **) malloc (numStrands * sizeof(void *)); */      wrld->inState = NEWVEC(void *, numStrands);
523      wrld->inState =  malloc (wrld->strandSize);      wrld->outState = NEWVEC(void *, numStrands);
524      wrld->outState = malloc (strand->shadowStrandSzb * numStrands);  */
525      wrld->status = (int *) malloc (numStrands * sizeof(int));      wrld->inState =  CheckedAlloc (wrld->strandSize);
526        wrld->outState = CheckedAlloc (strand->shadowStrandSzb * numStrands);
527        wrld->status = NEWVEC(int, numStrands);
528      if ((wrld->inState == 0) || (wrld->outState == 0) || (wrld->status == 0)) {      if ((wrld->inState == 0) || (wrld->outState == 0) || (wrld->status == 0)) {
529          fprintf (stderr, "unable to allocate strand states\n");          fprintf (stderr, "unable to allocate strand states\n");
530          exit (1);          exit (1);

Legend:
Removed from v.1471  
changed lines
  Added in v.1472

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