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 1267 - (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 :     #include <string.h>
12 :     #include <stdio.h>
13 :     #include <assert.h>
14 :     #include <Diderot/diderot.h>
15 :     #include "clinfo.h"
16 :    
17 :     // NOTE: we probably should put this in a file that supports runtime printing
18 :     static bool VerboseFlg = false;
19 :    
20 :     struct struct_world {
21 :     bool isArray; // is the initialization an array or collection?
22 :     uint32_t nDims; // depth of iteration nesting
23 :     int32_t *base; // nDims array of base indices
24 :     uint32_t *size; // nDims array of iteration sizes
25 :     uint32_t numStrands; // number of strands in the world
26 :     void **inState;
27 :     void **outState;
28 :     uint8_t *status; // array of strand status flags
29 :     };
30 :    
31 :     extern float getOutf (void *self);
32 :    
33 :     int main (int argc, const char **argv)
34 :     {
35 :     // get information about OpenCL support
36 :     CLInfo_t *clInfo = GetCLInfo();
37 :     if (clInfo == 0) {
38 :     fprintf (stderr, "no OpenCL support\n");
39 :     exit (1);
40 :     }
41 :    
42 :     Diderot_Options_t *opts = Diderot_OptNew ();
43 :    
44 :     Diderot_OptAddFlag (opts, "verbose", "enable runtime-system messages", &VerboseFlg);
45 :     Diderot_RegisterGlobalOpts (opts);
46 :     Diderot_OptProcess (opts, argc, argv);
47 :     Diderot_OptFree (opts);
48 :    
49 :     // run the generated global initialization code
50 :     if (VerboseFlg) printf("initializing globals ...\n");
51 :     Diderot_InitGlobals ();
52 :    
53 :     /***** FIXME: OpenCL specific stuff goes here. Things to do:
54 :     **
55 :     ** 1) copy data to GPU
56 :     ** 2) initialize strands
57 :     ** 3) run strands to termination
58 :     ** 4) load results from GPU
59 :     **/
60 :    
61 :     if (VerboseFlg) printf("done: %d updates, %d steps\n", nUpdates, nSteps);
62 :     // here we have the final state of all of the strands in the "in" buffer
63 :     FILE *outS = fopen("mip.txt", "w");
64 :     if (outS == NULL) {
65 :     fprintf (stderr, "Cannot open output file\n");
66 :     exit (8);
67 :     }
68 :    
69 :     for (int i = 0; i < wrld->numStrands; i++) {
70 :     if (wrld->status[i] == DIDEROT_STABLE)
71 :     Diderot_Strands[0]->print (outS, wrld->inState[i]);
72 :     }
73 :     fclose (outS);
74 :    
75 :     Diderot_Shutdown (wrld);
76 :    
77 :     return 0;
78 :    
79 :     }
80 :    
81 :    
82 :     // this should be the part of the scheduler
83 :     void *Diderot_AllocStrand (Strand_t *strand)
84 :     {
85 :     return malloc(strand->stateSzb);
86 :     }
87 :    
88 :     // block allocation of an initial collection of strands
89 :     Diderot_World_t *Diderot_AllocInitially (
90 :     Strand_t *strand, // the type of strands being allocated
91 :     bool isArray, // is the initialization an array or collection?
92 :     uint32_t nDims, // depth of iteration nesting
93 :     int32_t *base, // nDims array of base indices
94 :     uint32_t *size) // nDims array of iteration sizes
95 :     {
96 :     Diderot_World_t *wrld = (Diderot_World_t *) malloc (sizeof(Diderot_World_t));
97 :     if (wrld == 0) {
98 :     fprintf (stderr, "unable to allocate world\n");
99 :     exit (1);
100 :     }
101 :    
102 :     wrld->isArray = isArray;
103 :     wrld->nDims = nDims;
104 :     wrld->base = (int32_t *) malloc (nDims * sizeof(int32_t));
105 :     wrld->size = (uint32_t *) malloc (nDims * sizeof(uint32_t));
106 :     size_t numStrands = 1;
107 :     for (int i = 0; i < wrld->nDims; i++) {
108 :     numStrands *= size[i];
109 :     wrld->base[i] = base[i];
110 :     wrld->size[i] = size[i];
111 :     }
112 :    
113 :     if (VerboseFlg) {
114 :     printf("AllocInitially: %d", size[0]);
115 :     for (int i = 1; i < nDims; i++) printf(" x %d", size[i]);
116 :     printf("\n");
117 :     }
118 :    
119 :     // allocate the strand state pointers
120 :     wrld->numStrands = numStrands;
121 :     wrld->inState = (void **) malloc (numStrands * sizeof(void *));
122 :     wrld->outState = (void **) malloc (numStrands * sizeof(void *));
123 :     wrld->status = (uint8_t *) malloc (numStrands * sizeof(uint8_t));
124 :     if ((wrld->inState == 0) || (wrld->outState == 0) || (wrld->status == 0)) {
125 :     fprintf (stderr, "unable to allocate strand states\n");
126 :     exit (1);
127 :     }
128 :    
129 :     // initialize strand state pointers etc.
130 :     for (size_t i = 0; i < numStrands; i++) {
131 :     wrld->inState[i] = Diderot_AllocStrand (strand);
132 :     wrld->outState[i] = Diderot_AllocStrand (strand);
133 :     wrld->status[i] = DIDEROT_ACTIVE;
134 :     }
135 :    
136 :     return wrld;
137 :    
138 :     }
139 :    
140 :     // get strand state pointers
141 :     void *Diderot_InState (Diderot_World_t *wrld, uint32_t i)
142 :     {
143 :     assert (i < wrld->numStrands);
144 :     return wrld->inState[i];
145 :     }
146 :    
147 :     void *Diderot_OutState (Diderot_World_t *wrld, uint32_t i)
148 :     {
149 :     assert (i < wrld->numStrands);
150 :     return wrld->outState[i];
151 :     }
152 :    
153 :     bool Diderot_IsActive (Diderot_World_t *wrld, uint32_t i)
154 :     {
155 :     assert (i < wrld->numStrands);
156 :     return !wrld->status[i];
157 :     }

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