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 1286, Tue Jun 7 10:54:18 2011 UTC revision 1287, Tue Jun 7 13:01:44 2011 UTC
# Line 18  Line 18 
18    
19  // NOTE: we probably should put this in a file that supports runtime printing  // NOTE: we probably should put this in a file that supports runtime printing
20  static bool     VerboseFlg = false;  static bool     VerboseFlg = false;
21    static bool     TimingFlg = false;
22    
23  struct struct_world {  struct struct_world {
24        const char          *name;          // the program name
25      bool                isArray;        // is the initialization an array or collection?      bool                isArray;        // is the initialization an array or collection?
26      uint32_t            nDims;          // depth of iteration nesting      uint32_t            nDims;          // depth of iteration nesting
27      int32_t             *base;          // nDims array of base indices      int32_t             *base;          // nDims array of base indices
# Line 30  Line 32 
32      uint8_t             *status;        // array of strand status flags      uint8_t             *status;        // array of strand status flags
33  };  };
34    
 extern float getOutf (void *self);  
35  extern void Diderot_GPU_Init (cl_device_id device);  extern void Diderot_GPU_Init (cl_device_id device);
36    
37  int main (int argc, const char **argv)  int main (int argc, const char **argv)
# Line 67  Line 68 
68    printf("name:%s\n",clInfo->platforms[0].devices[0].name);    printf("name:%s\n",clInfo->platforms[0].devices[0].name);
69    Diderot_GPU_Init(clInfo->platforms[0].devices[0].id);    Diderot_GPU_Init(clInfo->platforms[0].devices[0].id);
70    
71  /*    Diderot_World_t *wrld = Diderot_Initially ();  // this may not be right for OpenCL      Diderot_World_t *wrld = Diderot_Initially ();  // this may not be right for OpenCL
72        double t0 = GetTime();
73    
74    /* SOMETHING */
75    
76        double totalTime = GetTime() - t0;
77    
78        if (VerboseFlg)
79            fprintf (stderr, "done in %f seconds\n", totalTime);
80        else if (TimingFlg)
81            printf ("usr=%f\n", totalTime);
82    
83    // 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
84      FILE *outS = fopen("mip.txt", "w");      int outFileNameLen = strlen(wrld->name) + 5;
85        char *outFileName = (char *)malloc(outFileNameLen);
86        snprintf (outFileName, outFileNameLen, "%s.txt", wrld->name);
87        FILE *outS = fopen(outFileName, "w");
88      if (outS == NULL) {      if (outS == NULL) {
89          fprintf (stderr, "Cannot open output file\n");          fprintf (stderr, "Cannot open output file %s\n", outFileName);
90          exit (8);          exit (8);
     }*/  
91  }  }
92    
93  /* Loads the Kernel from a file */      for (int i = 0;  i < wrld->numStrands;  i++) {
94  char *Diderot_LoadKernel (const char * filename)          if (wrld->status[i] == DIDEROT_STABLE)
95  {              Diderot_Strands[0]->print (outS, wrld->inState[i]);
96      struct stat statbuf;      }
97      FILE *fh;      fclose (outS);
     char *source;  
98    
99      fh = fopen(filename, "r");      Diderot_Shutdown (wrld);
     if (fh == 0)  
         return 0;  
100    
101      stat(filename, &statbuf);      return 0;
     source = (char *) malloc(statbuf.st_size + 1);  
     fread(source, statbuf.st_size, 1, fh);  
     source[statbuf.st_size] = '\0';  
102    
     printf("Reading worked fine!\n");  
     return source;  
103  }  }
104    
105    /***** FIXME: output results to outS  /*! \brief load OpenCL code from a file
106     */
107      fclose (outS);  char *Diderot_LoadSource (const char *filename)
108    {
109        struct stat statbuf;
110        if (stat(filename, &statbuf) < 0) {
111            fprintf (stderr, "unable to stat OpenCL source file %s\n", filename);
112            exit (1);
113        }
114    
115      Diderot_Shutdown (wrld);      char *source = (char *) malloc(statbuf.st_size + 1);
116        if (source == 0) {
117            fprintf (stderr, "unable to allocate memory for OpenCL source\n");
118            exit (1);
119        }
120    
121      return 0;      FILE *fh = fopen(filename, "r");
122        if ((fh == 0)
123        ||  (fread(source, statbuf.st_size, 1, fh) != 1)) {
124            fprintf (stderr, "unable to read OpenCL source from %s\n", filename);
125            exit (1);
126        }
127        source[statbuf.st_size] = '\0';
128        fclose (fh);
129    
130        return source;
131  }  }
132    
133  // this should be the part of the scheduler  // this should be the part of the scheduler
134  void *Diderot_AllocStrand (Strand_t *strand)  void *Diderot_AllocStrand (Strand_t *strand)
135  {  {
# Line 114  Line 138 
138    
139  // block allocation of an initial collection of strands  // block allocation of an initial collection of strands
140  Diderot_World_t *Diderot_AllocInitially (  Diderot_World_t *Diderot_AllocInitially (
141        const char *name,           // the name of the program
142      Strand_t *strand,           // the type of strands being allocated      Strand_t *strand,           // the type of strands being allocated
143      bool isArray,               // is the initialization an array or collection?      bool isArray,               // is the initialization an array or collection?
144      uint32_t nDims,             // depth of iteration nesting      uint32_t nDims,             // depth of iteration nesting
# Line 126  Line 151 
151          exit (1);          exit (1);
152      }      }
153    
154        wrld->name = name; /* NOTE: we are assuming that name is statically allocated! */
155      wrld->isArray = isArray;      wrld->isArray = isArray;
156      wrld->nDims = nDims;      wrld->nDims = nDims;
157      wrld->base = (int32_t *) malloc (nDims * sizeof(int32_t));      wrld->base = (int32_t *) malloc (nDims * sizeof(int32_t));
# Line 181  Line 207 
207  {  {
208      assert (i < wrld->numStrands);      assert (i < wrld->numStrands);
209      return !wrld->status[i];      return !wrld->status[i];
210  }*/  }

Legend:
Removed from v.1286  
changed lines
  Added in v.1287

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