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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/codegen/target-spec.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/codegen/target-spec.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5513 - (view) (download)

1 : jhr 3812 (* target-spec.sml
2 :     *
3 : jhr 3864 * Properties, including the target description, that affect code generation.
4 :     *
5 : jhr 3812 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
6 :     *
7 :     * COPYRIGHT (c) 2016 The University of Chicago
8 :     * All rights reserved.
9 :     *)
10 :    
11 :     structure TargetSpec =
12 :     struct
13 :    
14 :     datatype platform = datatype TargetOptions.platform
15 :    
16 :     type t = {
17 :     (* properties from the command line *)
18 :     diderotc : string, (* the diderotc command used to invoke this compiler *)
19 :     argv : string list, (* command-line arguments used to invoke this compiler *)
20 :     version : string, (* version message string for this compiler *)
21 : jhr 3864 (* properties from the target options *)
22 : jhr 3812 srcFile : string, (* source filename *)
23 :     outDir : string, (* directory to put output *)
24 :     outBase : string, (* basename for output or name of executable *)
25 :     exec : bool, (* generate standalone executable? *)
26 : jhr 5513 staticLib : bool, (* true if exec is false and the generated library *)
27 :     (* should be statically linked *)
28 : jhr 4965 jsonAPI : bool, (* generate a JSON description of library API? *)
29 : jhr 3812 snapshot : bool, (* generate functions to get snapshots? *)
30 : jhr 4317 platform : platform, (* target platform *)
31 : jhr 3812 namespace : string, (* optional namespace prefix *)
32 :     double : bool, (* true for double-precision candidates *)
33 :     longint : bool, (* true for 64-bit integers (not currently used) *)
34 : jhr 4317 scalar : bool, (* true if scalar code (not SSE) should be generated *)
35 : jhr 5009 debug : bool, (* true if debugging of the runtime/generated code is
36 :     * enabled. Note that this does not mean the Diderot
37 :     * debugger!! That is specified as a target "platform"
38 :     *)
39 : jhr 4842 runtimeLog : bool, (* true if runtime event logging is enabled *)
40 : jhr 3812 bsp : bool, (* true if BSP style execution should always be used *)
41 : jhr 4589 useKDTree : bool, (* true if a kdtree is used to accelerate spatial queries *)
42 : jhr 3812 (* properties from analysing the program *)
43 : jhr 4369 spatialDim : int option, (* the spatial dimension used for queries *)
44 : jhr 5108 hasConsts : bool, (* true if the program has const variables *)
45 :     hasGlobals : bool, (* true if the program has global variables; not including
46 :     * residual constants.
47 :     *)
48 : jhr 3812 hasInputs : bool, (* true if the program has input variables *)
49 : jhr 4317 hasGlobalInit : bool, (* true if the program has global initialization code *)
50 : jhr 3958 isGrid : bool, (* true for programs that use a fixed grid of strands *)
51 : jhr 3812 hasDynSeq : bool, (* true for programs that have create dynamic sequences;
52 :     * this does not include programs that just load sequences
53 :     * from nrrd files. *)
54 : jhr 4493 hasStartMeth : bool, (* true for programs with user-defined start methods *)
55 : jhr 4407 hasStabilizeMeth : bool, (* true for programs with user-defined stabilize methods *)
56 : jhr 3812 hasDie : bool, (* true for programs that have "die" *)
57 :     hasNew : bool, (* true for programs that have "new" *)
58 :     hasCom : bool, (* true for programs that have strand communication *)
59 : jhr 4589 dualState : bool, (* trur for programs with shared varying state *)
60 : jhr 4943 strandConstr : bool, (* true for programs where the strand state has dynamic
61 :     * sequences in its state (and so needs a constructor) *)
62 : jhr 4493 hasGlobalStart : bool, (* true for programs that have a global start block. *)
63 : jhr 4317 hasGlobalUpdate : bool, (* true for programs that have a global update block *)
64 : jhr 4628 hasKillAll : bool, (* true for programs that have a global die statement *)
65 : jhr 4589 hasStabilizeAll : bool, (* true for programs that have a global stabilize statement *)
66 : jhr 3812 hasReduce : bool (* true for programs that have global reduce *)
67 :     }
68 :    
69 : jhr 5108 local
70 :     structure P = Properties
71 :     in
72 : jhr 5261
73 : jhr 3812 (* create the property record from the target description and program properties *)
74 : jhr 4516 fun mk (tgt : TargetOptions.t, prog) : t = let
75 : jhr 4589 val TreeIR.Program{props, strand=TreeIR.Strand{state, spatialDim, ...}, ...} = prog
76 : jhr 5108 val hasCom = P.hasProp P.StrandCommunication props
77 : jhr 4589 in {
78 : jhr 3812 diderotc = CommandLine.name(),
79 :     argv = CommandLine.arguments(),
80 :     version = Version.message,
81 :     srcFile = #srcFile tgt,
82 :     outDir = #outDir tgt,
83 :     outBase = #outBase tgt,
84 :     exec = #exec tgt,
85 : jhr 5513 staticLib = #staticLib tgt,
86 : jhr 4965 jsonAPI = #jsonAPI tgt,
87 : jhr 3812 snapshot = #snapshot tgt,
88 :     platform = #platform tgt,
89 :     namespace = #namespace tgt,
90 :     double = #double tgt,
91 :     longint = #longint tgt,
92 : jhr 3864 scalar = #scalar tgt,
93 : jhr 3812 debug = #debug tgt,
94 : jhr 4842 runtimeLog = #runtimeLog tgt,
95 : jhr 5261 bsp = #bsp tgt orelse P.hasProp P.NeedsBSP props,
96 : jhr 4589 useKDTree = #kdtree tgt,
97 : jhr 4516 spatialDim = spatialDim,
98 : jhr 5108 hasConsts = P.hasProp P.HasConsts props,
99 :     hasGlobals = P.hasProp P.HasGlobals props,
100 :     hasInputs = P.hasProp P.HasInputs props,
101 :     hasGlobalInit = P.hasProp P.GlobalInit props,
102 :     isGrid = P.hasProp P.StrandArray props,
103 :     hasDynSeq = P.hasProp P.DynamicSeq props,
104 :     hasStartMeth = P.hasProp P.HasStartMethod props,
105 :     hasStabilizeMeth = P.hasProp P.HasStabilizeMethod props,
106 :     hasDie = P.hasProp P.StrandsMayDie props,
107 :     hasNew = P.hasProp P.NewStrands props,
108 : jhr 4516 hasCom = hasCom,
109 : jhr 4589 dualState = hasCom andalso List.exists TreeStateVar.inSharedStruct state,
110 : jhr 5072 strandConstr = true, (* FIXME: analyze strand state to see if constructor is required *)
111 : jhr 5108 hasGlobalStart = P.hasProp P.GlobalStart props,
112 :     hasGlobalUpdate = P.hasProp P.GlobalUpdate props,
113 :     hasKillAll = P.hasProp P.KillAll props,
114 :     hasStabilizeAll = P.hasProp P.StabilizeAll props,
115 :     hasReduce = P.hasProp P.GlobalReduce props
116 : jhr 4589 } end
117 : jhr 3812
118 : jhr 5108 end (* local *)
119 :    
120 : jhr 3906 (* return true if the target is parallel *)
121 :     fun isParallel (p : t) = (case #platform p of PARALLEL => true | _ => false)
122 :    
123 : jhr 5009 (* return true if the target is the Diderot debugger *)
124 :     fun isDebugger (p : t) = (case #platform p of DEBUGGER => true | _ => false)
125 :    
126 : jhr 4451 (* returns true if BSP style execution should be used.
127 :     * this property can be set on the command line, but
128 :     * also holds when the program has communication, etc.
129 :     *)
130 : jhr 4514 fun bsp (p : t) = #bsp p orelse #hasNew p orelse #hasCom p orelse #hasGlobalUpdate p
131 : jhr 4451
132 : jhr 3812 (* returns false if BSP style execution should always be used;
133 :     * this property can be set on the command line, but
134 :     * also holds when the program has communication, etc.
135 :     *)
136 : jhr 4451 fun noBSP (p : t) = not(bsp p)
137 : jhr 3812
138 :     (* returns true if the program does not use inter-strand communication *)
139 :     fun noComm (p : t) = not(#hasCom p)
140 :    
141 : jhr 3923 (* return true if we need to keep two copies of the state: in and out.
142 : jhr 4516 * NOTE: this function is more precise than Properties.dualState,
143 :     * but that is safe, since Properties.dualState is just used to enable
144 :     * optimizations.
145 : jhr 3923 *)
146 : jhr 4516 fun dualState (p : t) = (#dualState p)
147 : jhr 3812
148 : jhr 4451 (* return true if we need to use an indirect representation of the state. This is
149 :     * the case when the program uses the "new" operation or when it uses the "die"
150 :     * operation and BSP is in effect (if there is no BSP, the there is no need to
151 :     * compact the strand array and thus no need for indirect state access)
152 :     *)
153 :     fun indirectState (p : t) = (#hasNew p) orelse ((#hasDie p) andalso (bsp p))
154 : jhr 4445
155 : jhr 4753 (* does the world object have a "kill_all" method. We need this for programs
156 :     * that use "die" in global update and for standalone executables that generate
157 :     * collections, since kill_all is used when the step limit expires.
158 :     *)
159 :     fun killAll (p : t) = (#hasKillAll p) orelse ((#exec p) andalso not(#isGrid p))
160 :    
161 : jhr 3812 (* convert a target specification to the name of the runtime library *)
162 : jhr 3899 fun runtimeLibName (spec : t) = let
163 : jhr 4842 val l = if #debug spec
164 :     then ["-debug.o"]
165 :     else if #runtimeLog spec
166 :     then ["-log.o"]
167 :     else [".o"]
168 : jhr 3812 val t = (case #platform spec
169 :     of SEQUENTIAL => "-seq"
170 : jhr 4317 | PARALLEL => "-par"
171 : jhr 5012 | DEBUGGER => "-seq" (* QUESTION: should there be a special debugger version of the runtime? *)
172 : jhr 3812 | OPENCL => "-cl"
173 :     | CUDA => "-cuda"
174 :     (* end case *))
175 :     in
176 :     OS.Path.concat(
177 :     Paths.diderotLib(),
178 : jhr 3866 String.concat("diderot-rt" :: t :: l))
179 : jhr 3812 end
180 :    
181 :     (* return the CPP floating-point precision definition for the target *)
182 :     fun floatPrecisionDef (p : t) = if #double p
183 :     then "DIDEROT_DOUBLE_PRECISION"
184 :     else "DIDEROT_SINGLE_PRECISION"
185 :    
186 :     (* return the CPP integer precision definition for the target *)
187 :     fun intPrecisionDef (p : t) = if #longint p
188 :     then "DIDEROT_LONGINT"
189 :     else "DIDEROT_INT"
190 :    
191 :     (* return the CPP target definition for the target *)
192 :     fun targetDef (p : t) = "DIDEROT_TARGET_" ^ TargetOptions.platformToString (#platform p)
193 :    
194 : jhr 3924 (* qualify a C function or type name by the target namespace, but only for libraries *)
195 :     fun qualifyCId name (spec : t) =
196 : jhr 4317 if (#exec spec) then name else concat[#namespace spec, "_", name]
197 : jhr 3924 fun qualifyCId' base (spec : t, name) =
198 : jhr 4317 if (#exec spec)
199 :     then concat[base, "_", name]
200 :     else concat[#namespace spec, "_", base, "_", name]
201 : jhr 3899
202 : jhr 3812 end

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