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

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