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

SCM Repository

[diderot] Annotation of /branches/vis12/src/compiler/cl-target/runtime-names.sml
ViewVC logotype

Annotation of /branches/vis12/src/compiler/cl-target/runtime-names.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2708 - (view) (download)

1 : jhr 1671 (* 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 : jhr 2708 val gIntTy = ref CLang.int32 (* external API type for Diderot ints *)
19 :     val gCLIntTy = ref CLang.voidTy (* CPU-side OpenCL type for Diderot ints *)
20 :     val gRealTy = ref CLang.float (* external API type for Diderot reals *)
21 :     val gCLRealTy = ref CLang.voidTy (* CPU-side OpenCL type for Diderot reals *)
22 : jhr 1671 val gRealStem = ref "?"
23 :     val gRealSuffix = ref "?"
24 :     val gIntSuffix = ref "?"
25 :     val gIntFormat = ref "?"
26 :    
27 :     (* initialize globals based on target precision *)
28 : jhr 2708 fun initTargetSpec (tgt : TargetUtil.target_desc) = (
29 :     if #longint tgt
30 :     then (
31 : jhr 1671 gIntTy := CLang.int64;
32 :     gIntSuffix := "l";
33 :     gIntFormat := "%ld")
34 :     else (
35 :     gIntTy := CLang.int32;
36 : jhr 2708 gIntSuffix := "i";
37 :     gIntFormat := "%d");
38 :     if #double tgt
39 :     then (
40 :     gRealTy := CLang.double;
41 :     gRealStem := "double";
42 :     gRealSuffix := "d")
43 :     else (
44 : jhr 1671 gRealTy := CLang.float;
45 :     gRealStem := "float";
46 : jhr 2708 gRealSuffix := "f"))
47 : jhr 1671
48 :     fun addRealSuffix stem = stem ^ !gRealSuffix
49 :     fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix]
50 :     fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix]
51 :     fun addBufferSuffix stem = concat[stem, "_cl"]
52 :     fun addBufferSuffixData stem = concat[stem, "_data_cl"]
53 :    
54 :     fun addTySuffix (stem, 1) = stem ^ !gRealSuffix
55 :     | addTySuffix (stem, n) = addVecSuffix stem n
56 :    
57 :     fun vecTy n = concat[!gRealStem, Int.toString n]
58 :     fun ivecTy n = concat["int", Int.toString n]
59 :     fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]
60 :     fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]
61 :    
62 :     (* host-side names for OpenCL types *)
63 :     fun shadowIntTy () = "cl_int" (* QUESTION: should this be precision dependent? *)
64 :     fun shadowRealTy () = "Shadow_real_t"
65 :     fun shadowVecTy n = F.format "Shadow_vec%d_t" [F.INT n]
66 :     fun shadowMatTy (m, n) = F.format "Shadow_Mat%dx%d_t" [F.INT m, F.INT n]
67 :     fun shadowImageTy d = concat["Shadow_image", Int.toString d, "D_t"]
68 :     fun shadowImageFunc d = concat["ShadowImage", Int.toString d, "D"]
69 :     val shadowGlobalsTy = "Shadow_globals_t"
70 :     val shadowGlaobalsName = "shadowGlobals"
71 :     fun convertToShadowVec n = "ShadowVec" ^ Int.toString n
72 :     fun convertToShadowMat (m,n) = F.format "ShadowMat%dx%d" [F.INT m, F.INT n]
73 :     (*GPU side image data types and functions *)
74 :     val imageDataType = "Diderot_data_ptr_t"
75 :     val globalImageDataName = "diderotDataPtrs"
76 :     fun imageDataName name = name ^ "Data"
77 :    
78 :     (* names of generated types, functions, and globals *)
79 :     val initGlobals = "Diderot_InitGlobals" (* function for initializing program globals *)
80 :     val initGlobalsHelper = "Diderot_InitGlobalsHelper" (* function for initializing program globals *)
81 :     val registerOpts = "Diderot_RegisterGlobalOpts" (* function for registering command-line options *)
82 :     val initially = "Diderot_Initially" (* function for creating initial strands *)
83 :     val shutdown = "Diderot_Shutdown" (* function that gets called at the end *)
84 :     val globalsTy = "Diderot_Globals_t"
85 :     val kernelFuncName = "Diderot_UpdateKernel"
86 :     fun strandInit strand = strand ^ "_InitState"
87 :     val strandInitSetup = "Diderot_Strand_Init"
88 :     val strandBlockCopyName = "StrandBlock_Copy"
89 :     fun strandTy strand = concat["Strand_", strand, "_t"]
90 :     fun strandShadowTy strand = concat["Shadow_", strand, "_t"]
91 :     fun strandDesc strand = concat["Strand_", strand]
92 :     val numStrands = "Diderot_NumStrands"
93 :     val strands = "Diderot_Strands"
94 :     (*fun strandUpdate strand = strand ^ StrandUtil.nameToString StrandUtil.Update *)
95 :     val strandUpdate = "Diderot_Update"
96 :     fun strandStabilize strand = strand ^ StrandUtil.nameToString StrandUtil.Stabilize
97 :     val strandCopy = "Diderot_StateCopy"
98 :     fun strandPrintName strand = strand ^ "Print"
99 :     fun strandConvertName strand = strand ^ "ConvertToShadow"
100 :    
101 :     val clLoaderFN = "Diderot_LoadKernel"
102 :     val getGlobalThreadId ="get_global_id"
103 :     val getLocalThreadId = "get_local_id"
104 :     val getGlobalSize = "get_global_size"
105 :     val getGroupId = "get_group_id"
106 :     val getNumGroups = "get_num_groups"
107 :     val getLocalSize = "get_local_size"
108 :     val globalsVarName = "diderotGlobals"
109 :     val globalsVarNameCL = "cl_diderotGlobals"
110 :     val globalsSetupName = "Diderot_LoadGlobals"
111 :    
112 :    
113 :     (* Scheduler runtime names *)
114 :     val globalPoolName = "globalPoolNextStrand"
115 :     val schedTy = "SchedState_t"
116 :     val strandBlkTy = "StrandBlock_t"
117 :     val schedFuncName = "Diderot_UpdateScheduler"
118 :     val getBlockFuncName = "GetBlock"
119 :     val barrier = "barrier"
120 :     val mem_fence = "mem_fence"
121 :     val local_fence = "CLK_LOCAL_MEM_FENCE"
122 :     val global_fence = "CLK_GLOBAL_MEM_FENCE"
123 :     val atom_add = "atom_add"
124 :     val atom_dec = "atom_dec"
125 :     val atom_inc = "atom_inc"
126 :    
127 :     (* Placeholders *)
128 :     val place_holders ="STRAND_TY"
129 :     val p_addGlobals = "SHOULD_ADD_GLOBALS"
130 :     val p_globals = "GLOBALS"
131 :     val p_addDatPtr = "SHOULD_ADD_DATA"
132 :     val p_dataPtr = "GLOBAL_DATA_PTRS"
133 :     val p_dataAssign = "GLOBAL_DATA_ASSIGN"
134 :     val p_globalVar = "GLOBAL_VAR"
135 :     val p_dataVar = "DATA_VAR"
136 :    
137 :     (* scalar math functions *)
138 :     val max = "max"
139 :     val min = "min"
140 :     val fabs = "fabs"
141 :    
142 :     (* clamp and lerp *)
143 :     val clamp = "clamp"
144 :     val lerp = "mix"
145 :    
146 :     (* vector math functions *)
147 :     fun mkVec 3 = "VEC3" (* for OpenCL 1.0 *)
148 :     | mkVec n = concat["(", !gRealStem, Int.toString n, ")"] (* cast syntax *)
149 :     val truncToInt = addVecSuffix "truncToInt"
150 :     val dot = "dot"
151 :     val cross = "cross"
152 :     val length = "length"
153 :     val normalize = "normalize"
154 :     fun vecitof n = concat["convert_float", Int.toString n]
155 :     fun vecftoi n = concat["convert_int", Int.toString n]
156 :     (* matrix operations *)
157 :     fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m, !gRealSuffix]
158 :     fun identityMat n = concat["identity", Int.toString n, "x", Int.toString n, !gRealSuffix]
159 :     fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix]
160 :     fun norm (n, m) = concat["norm", Int.toString n, "x", Int.toString m, !gRealSuffix]
161 :     fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix]
162 :     fun scaleMat (n, m) = concat["scale", Int.toString n, "x", Int.toString m, !gRealSuffix]
163 :     fun addMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix]
164 :     fun subMat (n, m) = concat["sub", Int.toString n, "x", Int.toString m, !gRealSuffix]
165 :     fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s"
166 :     [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)]
167 :     fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s"
168 :     [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)]
169 :     fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s"
170 :     [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)]
171 :    
172 :     (* Math utility functions *)
173 :     val evecs2x2 = "Diderot_evecs2x2"
174 :     val evecs3x3 = "Diderot_evecs3x3"
175 :     val evals2x2 = "Diderot_evals2x2"
176 :     val evals3x3 = "Diderot_evals3x3"
177 :     fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]
178 :    
179 :     (* Status_t symbols *)
180 :     val kActive = "DIDEROT_ACTIVE"
181 :     val kDie = "DIDEROT_DIE"
182 :     val kStabilize = "DIDEROT_STABILIZE"
183 :     val kStable = "DIDEROT_STABLE"
184 :    
185 :     (* Diderot runtime system hooks *)
186 :     val statusTy = "Status_t"
187 :     val toImageSpace = addVecSuffix "ToImageSpace"
188 :     fun toWorldSpace ty = let
189 :     val suffix = (case ty
190 :     of Ty.TensorTy[d] => [Int.toString d, !gRealSuffix]
191 :     | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n, !gRealSuffix]
192 :     (* end case *))
193 :     in
194 :     concat("ToWorldSpace" :: suffix)
195 :     end
196 :     val inside = addVecSuffix "Inside"
197 :     fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
198 :     val strandDescTy = "Strand_t"
199 :     val worldTy = "Diderot_World_t"
200 :     val optionsTy = "Diderot_Options_t"
201 :     val allocInitially = "Diderot_AllocInitially"
202 :     val inState = "Diderot_InState"
203 :    
204 :     (* functions for defining program inputs *)
205 :     fun input ty = (case ty
206 :     of Ty.StringTy => "Diderot_OptAddString"
207 :     | Ty.BoolTy => "Diderot_OptAddBool"
208 :     | Ty.IntTy => "Diderot_OptAddInt"
209 :     | Ty.TensorTy[] => "Diderot_OptAddReal"
210 :     | Ty.TensorTy[2] => "Diderot_OptAddReal2"
211 :     | Ty.TensorTy[3] => "Diderot_OptAddReal3"
212 :     | Ty.TensorTy[4] => "Diderot_OptAddReal4"
213 :     | ty => raise Fail("unsupported input type " ^ Ty.toString ty)
214 :     (* end case *))
215 :    
216 :     end (* local *)
217 :     end

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