SCM Repository
Annotation of /branches/pure-cfg/src/compiler/cl-target/runtime-names.sml
Parent Directory
|
Revision Log
Revision 1462 - (view) (download)
1 : | lamonts | 1244 | (* runtime-names.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | *) | ||
6 : | |||
7 : | structure RuntimeNames = | ||
8 : | struct | ||
9 : | |||
10 : | local | ||
11 : | structure Ty = TreeIL.Ty | ||
12 : | structure F = Format | ||
13 : | in | ||
14 : | |||
15 : | (* globals that specify the target characteristics. These should be initialized | ||
16 : | * when the program object is created. | ||
17 : | *) | ||
18 : | val doublePrecision = ref false | ||
19 : | val gIntTy = ref CLang.int32 | ||
20 : | val gRealTy = ref CLang.float | ||
21 : | jhr | 1273 | val gRealStem = ref "?" |
22 : | lamonts | 1244 | val gRealSuffix = ref "?" |
23 : | val gIntSuffix = ref "?" | ||
24 : | val gIntFormat = ref "?" | ||
25 : | |||
26 : | (* initialize globals based on target precision *) | ||
27 : | fun initTargetSpec double = ( | ||
28 : | jhr | 1324 | doublePrecision := double; |
29 : | if double | ||
30 : | then ( | ||
31 : | gIntTy := CLang.int64; | ||
32 : | gRealTy := CLang.double; | ||
33 : | jhr | 1273 | gRealStem := "double"; |
34 : | jhr | 1324 | gRealSuffix := "d"; |
35 : | gIntSuffix := "l"; | ||
36 : | gIntFormat := "%ld") | ||
37 : | else ( | ||
38 : | gIntTy := CLang.int32; | ||
39 : | gRealTy := CLang.float; | ||
40 : | jhr | 1273 | gRealStem := "float"; |
41 : | jhr | 1324 | gRealSuffix := "f"; |
42 : | gIntSuffix := "i"; | ||
43 : | gIntFormat := "%d")) | ||
44 : | lamonts | 1244 | |
45 : | fun addRealSuffix stem = stem ^ !gRealSuffix | ||
46 : | fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix] | ||
47 : | fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix] | ||
48 : | jhr | 1261 | fun addBufferSuffix stem = concat[stem, "_cl"] |
49 : | fun addBufferSuffixData stem = concat[stem, "_data_cl"] | ||
50 : | lamonts | 1244 | |
51 : | fun addTySuffix (stem, 1) = stem ^ !gRealSuffix | ||
52 : | | addTySuffix (stem, n) = addVecSuffix stem n | ||
53 : | |||
54 : | jhr | 1273 | fun vecTy n = concat[!gRealStem, Int.toString n] |
55 : | fun ivecTy n = concat["int", Int.toString n] | ||
56 : | lamonts | 1244 | fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"] |
57 : | fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"] | ||
58 : | |||
59 : | jhr | 1358 | (* host-side names for OpenCL types *) |
60 : | fun shadowIntTy () = "cl_int" (* QUESTION: should this be precision dependent? *) | ||
61 : | fun shadowRealTy () = "Shadow_real_t" | ||
62 : | fun shadowVecTy n = F.format "Shadow_vec%d_t" [F.INT n] | ||
63 : | fun shadowMatTy (m, n) = F.format "Shadow_Mat%dx%d_t" [F.INT m, F.INT n] | ||
64 : | fun shadowImageTy d = concat["Shadow_image", Int.toString d, "D_t"] | ||
65 : | lamonts | 1398 | fun shadowImageFunc d = concat["ShadowImage", Int.toString d, "D"] |
66 : | jhr | 1431 | val shadowGlobalsTy = "Shadow_globals_t" |
67 : | jhr | 1405 | val shadowGlaobalsName = "shadowGlobals" |
68 : | lamonts | 1408 | fun convertToShadowVec n = concat["ShadowVec",Int.toString n] |
69 : | lamonts | 1429 | fun unshadowVec n = concat["UnshadowVec",Int.toString n] |
70 : | lamonts | 1408 | fun convertToShadowMat (m,n) = F.format "ShadowMat%dx%d" [F.INT m, F.INT n] |
71 : | lamonts | 1398 | (*GPU side image data types and functions *) |
72 : | jhr | 1431 | val imageDataType = "Diderot_data_ptr_t" |
73 : | val globalImageDataName = "diderotDataPtrs" | ||
74 : | fun imageDataName name = name ^ "Data" | ||
75 : | lamonts | 1398 | |
76 : | lamonts | 1244 | (* names of generated tyes, functions, and globals *) |
77 : | jhr | 1324 | val initGlobals = "Diderot_InitGlobals" (* function for initializing program globals *) |
78 : | jhr | 1326 | val initGlobalsHelper = "Diderot_InitGlobalsHelper" (* function for initializing program globals *) |
79 : | jhr | 1324 | val registerOpts = "Diderot_RegisterGlobalOpts" (* function for registering command-line options *) |
80 : | val initially = "Diderot_Initially" (* function for creating initial strands *) | ||
81 : | val shutdown = "Diderot_Shutdown" (* function that gets called at the end *) | ||
82 : | jhr | 1282 | val globalsTy = "Diderot_Globals_t" |
83 : | lamonts | 1461 | val kernelFuncName = "Diderot_UpdateKernel" |
84 : | lamonts | 1271 | fun strandInit strand = strand ^ "_InitState" |
85 : | jhr | 1273 | val strandInitSetup = "Diderot_Strand_Init" |
86 : | lamonts | 1244 | fun strandTy strand = concat["Strand_", strand, "_t"] |
87 : | lamonts | 1399 | fun strandCopy strand = strand ^ "_Copy" |
88 : | lamonts | 1244 | fun strandUpdate strand = concat[strand,"_update"] |
89 : | fun strandStabilize strand = concat[strand,"_stabilize"] | ||
90 : | fun strandDesc strand = concat["Strand_", strand] | ||
91 : | val numStrands = "Diderot_NumStrands" | ||
92 : | val strands = "Diderot_Strands" | ||
93 : | lamonts | 1462 | val strandConvertName = "Diderot_Strand_Covert_To_Shadow" |
94 : | fun strandShadowTy strand = concat["Shadow_",strand] | ||
95 : | |||
96 : | jhr | 1282 | val clLoaderFN = "Diderot_LoadKernel" |
97 : | lamonts | 1244 | val getGlobalThreadId ="get_global_id" |
98 : | lamonts | 1457 | val getLocalThreadId = "get_local_id" |
99 : | val getGlobalSize = "get_global_size" | ||
100 : | lamonts | 1458 | val getGroupId = "get_group_id" |
101 : | val getNumGroups = "get_num_groups" | ||
102 : | lamonts | 1457 | val getLocalSize = "get_local_size" |
103 : | lamonts | 1244 | val globalsVarName = "diderotGlobals" |
104 : | lamonts | 1256 | val globalsVarNameCL = "cl_diderotGlobals" |
105 : | jhr | 1313 | val globalsSetupName = "Diderot_LoadGlobals" |
106 : | lamonts | 1462 | |
107 : | lamonts | 1351 | |
108 : | lamonts | 1457 | (* Scheduler runtime names *) |
109 : | val globalPoolName = "globalPoolNextStrand" | ||
110 : | val workerTy = "WorkerArg_t" | ||
111 : | val barrier = "barrier" | ||
112 : | lamonts | 1458 | val atom_add = "atom_add" |
113 : | val atom_dec = "atom_dec" | ||
114 : | lamonts | 1457 | |
115 : | lamonts | 1244 | (* scalar math functions *) |
116 : | jhr | 1273 | val max = "max" |
117 : | val min = "min" | ||
118 : | val fabs = "fabs" | ||
119 : | lamonts | 1244 | |
120 : | jhr | 1297 | (* clamp and lerp *) |
121 : | val clamp = "clamp" | ||
122 : | jhr | 1273 | val lerp = "mix" |
123 : | lamonts | 1244 | |
124 : | (* vector math functions *) | ||
125 : | jhr | 1273 | fun mkVec 3 = "VEC3" (* for OpenCL 1.0 *) |
126 : | | mkVec n = concat["(", !gRealStem, Int.toString n, ")"] (* cast syntax *) | ||
127 : | lamonts | 1244 | val truncToInt = addVecSuffix "truncToInt" |
128 : | jhr | 1273 | val dot = "dot" |
129 : | val cross = "cross" | ||
130 : | val length = "length" | ||
131 : | val normalize = "normalize" | ||
132 : | jhr | 1324 | fun vecitof n = if n <> 3 |
133 : | then concat["convert_float", Int.toString n] | ||
134 : | else "convert_float4" (* for OpenCL 1.0 *) | ||
135 : | fun vecftoi n = if n <> 3 | ||
136 : | then concat["convert_int", Int.toString n] | ||
137 : | else "convert_int4" (* for OpenCL 1.0 *) | ||
138 : | lamonts | 1244 | (* matrix operations *) |
139 : | fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m, !gRealSuffix] | ||
140 : | fun identityMat n = concat["identity", Int.toString n, "x", Int.toString n, !gRealSuffix] | ||
141 : | fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix] | ||
142 : | fun norm (n, m) = concat["norm", Int.toString n, "x", Int.toString m, !gRealSuffix] | ||
143 : | fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix] | ||
144 : | fun scaleMat (n, m) = concat["scale", Int.toString n, "x", Int.toString m, !gRealSuffix] | ||
145 : | fun addMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix] | ||
146 : | fun subMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix] | ||
147 : | fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s" | ||
148 : | jhr | 1324 | [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)] |
149 : | lamonts | 1244 | fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s" |
150 : | jhr | 1324 | [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)] |
151 : | lamonts | 1244 | fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s" |
152 : | jhr | 1324 | [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)] |
153 : | lamonts | 1244 | |
154 : | (* Status_t symbols *) | ||
155 : | val kActive = "DIDEROT_ACTIVE" | ||
156 : | val kDie = "DIDEROT_DIE" | ||
157 : | val kStabilize = "DIDEROT_STABILIZE" | ||
158 : | lamonts | 1458 | val kStable = "DIDEROT_STABLE" |
159 : | lamonts | 1244 | |
160 : | (* Diderot runtime system hooks *) | ||
161 : | val statusTy = "Status_t" | ||
162 : | lamonts | 1398 | val toImageSpace = addVecSuffix "ToImageSpace" |
163 : | lamonts | 1244 | fun toWorldSpace ty = let |
164 : | jhr | 1324 | val suffix = (case ty |
165 : | of Ty.TensorTy[d] => [Int.toString d, !gRealSuffix] | ||
166 : | | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n, !gRealSuffix] | ||
167 : | (* end case *)) | ||
168 : | in | ||
169 : | concat("ToWorldSpace" :: suffix) | ||
170 : | end | ||
171 : | lamonts | 1244 | val inside = addVecSuffix "Inside" |
172 : | fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"] | ||
173 : | val strandDescTy = "Strand_t" | ||
174 : | val worldTy = "Diderot_World_t" | ||
175 : | jhr | 1261 | val optionsTy = "Diderot_Options_t" |
176 : | lamonts | 1346 | val allocInitially = "Diderot_AllocInitially" |
177 : | lamonts | 1244 | val inState = "Diderot_InState" |
178 : | |||
179 : | fun input ty = (case ty | ||
180 : | jhr | 1324 | of Ty.StringTy => "Diderot_InputString" |
181 : | | Ty.TensorTy[] => "Diderot_Input" ^ !gRealSuffix | ||
182 : | | Ty.TensorTy[3] => "Diderot_InputVec3" ^ !gRealSuffix | ||
183 : | | ty => raise Fail("unsupported input type " ^ Ty.toString ty) | ||
184 : | (* end case *)) | ||
185 : | lamonts | 1244 | |
186 : | end (* local *) | ||
187 : | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |