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 1267, Sun Jun 5 11:25:29 2011 UTC revision 1287, Tue Jun 7 13:01:44 2011 UTC
# Line 8  Line 8 
8   * All rights reserved.   * All rights reserved.
9   */   */
10    
11    #include <Diderot/diderot.h>
12  #include <string.h>  #include <string.h>
13  #include <stdio.h>  #include <stdio.h>
14  #include <assert.h>  #include <assert.h>
 #include <Diderot/diderot.h>  
15  #include "clinfo.h"  #include "clinfo.h"
16    #include <sys/sysctl.h>
17    #include <sys/stat.h>
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 28  Line 32 
32      uint8_t             *status;        // array of strand status flags      uint8_t             *status;        // array of strand status flags
33  };  };
34    
35  extern float getOutf (void *self);  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)
38  {  {
# Line 48  Line 52 
52    
53    // run the generated global initialization code    // run the generated global initialization code
54  if (VerboseFlg) printf("initializing globals ...\n");  if (VerboseFlg) printf("initializing globals ...\n");
55      Diderot_InitGlobals ();  
56      /* Globals are loaded from the openCL code */
57      //  Diderot_InitGlobals();
58    
59    /***** FIXME: OpenCL specific stuff goes here.  Things to do:    /***** FIXME: OpenCL specific stuff goes here.  Things to do:
60     **     **
# Line 58  Line 64 
64     ** 4) load results from GPU     ** 4) load results from GPU
65     **/     **/
66    
67  if (VerboseFlg) printf("done: %d updates, %d steps\n", nUpdates, nSteps);    /* FIXME: For now we'll just use the very first platform */
68      printf("name:%s\n",clInfo->platforms[0].devices[0].name);
69      Diderot_GPU_Init(clInfo->platforms[0].devices[0].id);
70    
71        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    
# Line 78  Line 102 
102    
103  }  }
104    
105    /*! \brief load OpenCL code from a file
106     */
107    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        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        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)
# Line 87  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 99  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));

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

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