Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/pure-cfg/src/lib/cl-target/main.c
ViewVC logotype

Annotation of /branches/pure-cfg/src/lib/cl-target/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1275 - (view) (download) (as text)

1 : jhr 1267 /*! \file main.c
2 :     *
3 :     * \author John Reppy
4 :     */
5 :    
6 :     /*
7 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
8 :     * All rights reserved.
9 :     */
10 :    
11 : jhr 1275 #include <Diderot/diderot.h>
12 : jhr 1267 #include <string.h>
13 :     #include <stdio.h>
14 :     #include <assert.h>
15 :     #include "clinfo.h"
16 : lamonts 1271 #include <sys/sysctl.h>
17 :     #include <sys/stat.h>
18 : jhr 1267
19 :     // NOTE: we probably should put this in a file that supports runtime printing
20 :     static bool VerboseFlg = false;
21 :    
22 :     struct struct_world {
23 :     bool isArray; // is the initialization an array or collection?
24 :     uint32_t nDims; // depth of iteration nesting
25 :     int32_t *base; // nDims array of base indices
26 :     uint32_t *size; // nDims array of iteration sizes
27 :     uint32_t numStrands; // number of strands in the world
28 :     void **inState;
29 :     void **outState;
30 :     uint8_t *status; // array of strand status flags
31 :     };
32 :    
33 :     extern float getOutf (void *self);
34 : lamonts 1271 extern void Diderot_GPU_Init (cl_device_id device);
35 : jhr 1267
36 :     int main (int argc, const char **argv)
37 :     {
38 :     // get information about OpenCL support
39 :     CLInfo_t *clInfo = GetCLInfo();
40 :     if (clInfo == 0) {
41 :     fprintf (stderr, "no OpenCL support\n");
42 :     exit (1);
43 :     }
44 :    
45 :     Diderot_Options_t *opts = Diderot_OptNew ();
46 :    
47 :     Diderot_OptAddFlag (opts, "verbose", "enable runtime-system messages", &VerboseFlg);
48 :     Diderot_RegisterGlobalOpts (opts);
49 :     Diderot_OptProcess (opts, argc, argv);
50 :     Diderot_OptFree (opts);
51 :    
52 :     // run the generated global initialization code
53 : jhr 1275 if (VerboseFlg) printf("initializing globals ...\n");
54 : lamonts 1271
55 : jhr 1275 /* Globals are loaded from the openCL code */
56 : lamonts 1271 // Diderot_InitGlobals();
57 : jhr 1267
58 :     /***** FIXME: OpenCL specific stuff goes here. Things to do:
59 :     **
60 :     ** 1) copy data to GPU
61 :     ** 2) initialize strands
62 :     ** 3) run strands to termination
63 :     ** 4) load results from GPU
64 :     **/
65 : lamonts 1271
66 :     /* FIXME: For now we'll just use the very first platform */
67 :     printf("name:%s\n",clInfo->platforms[0].devices[0].name);
68 :     Diderot_GPU_Init(clInfo->platforms[0].devices[0].id);
69 :    
70 :    
71 :    
72 :     /* Diderot_World_t *wrld = Diderot_Initially (); // this may not be right for OpenCL
73 : jhr 1267
74 :     // here we have the final state of all of the strands in the "in" buffer
75 :     FILE *outS = fopen("mip.txt", "w");
76 :     if (outS == NULL) {
77 :     fprintf (stderr, "Cannot open output file\n");
78 :     exit (8);
79 : lamonts 1271 }*/
80 :     }
81 :     /* Loads the Kernel from a file */
82 :     char * loadKernel (const char * filename)
83 :     {
84 :     struct stat statbuf;
85 :     FILE *fh;
86 :     char *source;
87 :    
88 :     fh = fopen(filename, "r");
89 :     if (fh == 0)
90 :     return 0;
91 :    
92 :     stat(filename, &statbuf);
93 :     source = (char *) malloc(statbuf.st_size + 1);
94 :     fread(source, statbuf.st_size, 1, fh);
95 :     source[statbuf.st_size] = '\0';
96 :    
97 :     printf("Reading worked fine!\n");
98 :     return source;
99 :     }
100 : jhr 1267
101 : lamonts 1271 /***** FIXME: output results to outS
102 : jhr 1269
103 : jhr 1267 fclose (outS);
104 :    
105 :     Diderot_Shutdown (wrld);
106 :    
107 :     return 0;
108 :    
109 :     }
110 :     // this should be the part of the scheduler
111 :     void *Diderot_AllocStrand (Strand_t *strand)
112 :     {
113 :     return malloc(strand->stateSzb);
114 :     }
115 :    
116 :     // block allocation of an initial collection of strands
117 :     Diderot_World_t *Diderot_AllocInitially (
118 :     Strand_t *strand, // the type of strands being allocated
119 :     bool isArray, // is the initialization an array or collection?
120 :     uint32_t nDims, // depth of iteration nesting
121 :     int32_t *base, // nDims array of base indices
122 :     uint32_t *size) // nDims array of iteration sizes
123 :     {
124 :     Diderot_World_t *wrld = (Diderot_World_t *) malloc (sizeof(Diderot_World_t));
125 :     if (wrld == 0) {
126 :     fprintf (stderr, "unable to allocate world\n");
127 :     exit (1);
128 :     }
129 :    
130 :     wrld->isArray = isArray;
131 :     wrld->nDims = nDims;
132 :     wrld->base = (int32_t *) malloc (nDims * sizeof(int32_t));
133 :     wrld->size = (uint32_t *) malloc (nDims * sizeof(uint32_t));
134 :     size_t numStrands = 1;
135 :     for (int i = 0; i < wrld->nDims; i++) {
136 :     numStrands *= size[i];
137 :     wrld->base[i] = base[i];
138 :     wrld->size[i] = size[i];
139 :     }
140 :    
141 :     if (VerboseFlg) {
142 :     printf("AllocInitially: %d", size[0]);
143 :     for (int i = 1; i < nDims; i++) printf(" x %d", size[i]);
144 :     printf("\n");
145 :     }
146 :    
147 :     // allocate the strand state pointers
148 :     wrld->numStrands = numStrands;
149 :     wrld->inState = (void **) malloc (numStrands * sizeof(void *));
150 :     wrld->outState = (void **) malloc (numStrands * sizeof(void *));
151 :     wrld->status = (uint8_t *) malloc (numStrands * sizeof(uint8_t));
152 :     if ((wrld->inState == 0) || (wrld->outState == 0) || (wrld->status == 0)) {
153 :     fprintf (stderr, "unable to allocate strand states\n");
154 :     exit (1);
155 :     }
156 :    
157 :     // initialize strand state pointers etc.
158 :     for (size_t i = 0; i < numStrands; i++) {
159 :     wrld->inState[i] = Diderot_AllocStrand (strand);
160 :     wrld->outState[i] = Diderot_AllocStrand (strand);
161 :     wrld->status[i] = DIDEROT_ACTIVE;
162 :     }
163 :    
164 :     return wrld;
165 :    
166 :     }
167 :    
168 :     // get strand state pointers
169 :     void *Diderot_InState (Diderot_World_t *wrld, uint32_t i)
170 :     {
171 :     assert (i < wrld->numStrands);
172 :     return wrld->inState[i];
173 :     }
174 :    
175 :     void *Diderot_OutState (Diderot_World_t *wrld, uint32_t i)
176 :     {
177 :     assert (i < wrld->numStrands);
178 :     return wrld->outState[i];
179 :     }
180 :    
181 :     bool Diderot_IsActive (Diderot_World_t *wrld, uint32_t i)
182 :     {
183 :     assert (i < wrld->numStrands);
184 :     return !wrld->status[i];
185 : lamonts 1271 }*/

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