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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2403 - (view) (download)

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

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