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

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