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 2732 - (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 :     (* names of generated types, functions, and globals *)
70 :     val initGlobals = "Diderot_InitGlobals" (* function for initializing program globals *)
71 :     val initGlobalsHelper = "Diderot_InitGlobalsHelper" (* function for initializing program globals *)
72 :     val registerOpts = "Diderot_RegisterGlobalOpts" (* function for registering command-line options *)
73 :     val initially = "Diderot_Initially" (* function for creating initial strands *)
74 :     val shutdown = "Diderot_Shutdown" (* function that gets called at the end *)
75 :     val globalsTy = "Diderot_Globals_t"
76 :     val kernelFuncName = "Diderot_UpdateKernel"
77 :     fun strandInit strand = strand ^ "_InitState"
78 :     val strandInitSetup = "Diderot_Strand_Init"
79 :     val strandBlockCopyName = "StrandBlock_Copy"
80 :     fun strandTy strand = concat["Strand_", strand, "_t"]
81 :     fun strandDesc strand = concat["Strand_", strand]
82 :     val numStrands = "Diderot_NumStrands"
83 :     val strands = "Diderot_Strands"
84 :     (*fun strandUpdate strand = strand ^ StrandUtil.nameToString StrandUtil.Update *)
85 :     val strandUpdate = "Diderot_Update"
86 :     fun strandStabilize strand = strand ^ StrandUtil.nameToString StrandUtil.Stabilize
87 :     val strandCopy = "Diderot_StateCopy"
88 :     fun strandPrintName strand = strand ^ "Print"
89 :    
90 :     val clLoaderFN = "Diderot_LoadKernel"
91 :     val getGlobalThreadId ="get_global_id"
92 :     val getLocalThreadId = "get_local_id"
93 :     val getGlobalSize = "get_global_size"
94 :     val getGroupId = "get_group_id"
95 :     val getNumGroups = "get_num_groups"
96 :     val getLocalSize = "get_local_size"
97 :     val globalsVarName = "diderotGlobals"
98 :     val globalsVarNameCL = "cl_diderotGlobals"
99 :     val globalsSetupName = "Diderot_LoadGlobals"
100 :    
101 :     (* Scheduler runtime names *)
102 :     val globalPoolName = "globalPoolNextStrand"
103 :     val schedTy = "SchedState_t"
104 :     val strandBlkTy = "StrandBlock_t"
105 :     val schedFuncName = "Diderot_UpdateScheduler"
106 :     val getBlockFuncName = "GetBlock"
107 :     val barrier = "barrier"
108 :     val mem_fence = "mem_fence"
109 :     val local_fence = "CLK_LOCAL_MEM_FENCE"
110 :     val global_fence = "CLK_GLOBAL_MEM_FENCE"
111 :     val atom_add = "atom_add"
112 :     val atom_dec = "atom_dec"
113 :     val atom_inc = "atom_inc"
114 :    
115 :     (* Placeholders *)
116 :     val place_holders ="STRAND_TY"
117 :     val p_addGlobals = "SHOULD_ADD_GLOBALS"
118 :     val p_globals = "GLOBALS"
119 :     val p_addDatPtr = "SHOULD_ADD_DATA"
120 :     val p_dataPtr = "GLOBAL_DATA_PTRS"
121 :     val p_dataAssign = "GLOBAL_DATA_ASSIGN"
122 :     val p_globalVar = "GLOBAL_VAR"
123 :     val p_dataVar = "DATA_VAR"
124 :    
125 :     (* scalar math functions *)
126 :     val max = "max"
127 :     val min = "min"
128 :     val fabs = "fabs"
129 :    
130 :     (* clamp and lerp *)
131 :     val clamp = "clamp"
132 :     val lerp = "mix"
133 :    
134 :     (* vector math functions *)
135 :     fun mkVec 3 = "VEC3" (* for OpenCL 1.0 *)
136 :     | mkVec n = concat["(", !gRealStem, Int.toString n, ")"] (* cast syntax *)
137 :     val truncToInt = addVecSuffix "truncToInt"
138 :     val dot = "dot"
139 :     val cross = "cross"
140 :     val length = "length"
141 :     val normalize = "normalize"
142 :     fun vecitof n = concat["convert_float", Int.toString n]
143 :     fun vecftoi n = concat["convert_int", Int.toString n]
144 :     (* matrix operations *)
145 :     fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m, !gRealSuffix]
146 :     fun identityMat n = concat["identity", Int.toString n, "x", Int.toString n, !gRealSuffix]
147 :     fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix]
148 :     fun norm (n, m) = concat["norm", Int.toString n, "x", Int.toString m, !gRealSuffix]
149 :     fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix]
150 :     fun scaleMat (n, m) = concat["scale", Int.toString n, "x", Int.toString m, !gRealSuffix]
151 :     fun addMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix]
152 :     fun subMat (n, m) = concat["sub", Int.toString n, "x", Int.toString m, !gRealSuffix]
153 :     fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s"
154 :     [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)]
155 :     fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s"
156 :     [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)]
157 :     fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s"
158 :     [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)]
159 :    
160 :     (* Math utility functions *)
161 :     val evecs2x2 = "Diderot_evecs2x2"
162 :     val evecs3x3 = "Diderot_evecs3x3"
163 :     val evals2x2 = "Diderot_evals2x2"
164 :     val evals3x3 = "Diderot_evals3x3"
165 :     fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]
166 :    
167 :     (* Status_t symbols *)
168 :     val kActive = "DIDEROT_ACTIVE"
169 :     val kDie = "DIDEROT_DIE"
170 :     val kStabilize = "DIDEROT_STABILIZE"
171 :     val kStable = "DIDEROT_STABLE"
172 :    
173 :     (* Diderot runtime system hooks *)
174 :     val toImageSpace = addVecSuffix "ToImageSpace"
175 :     fun toWorldSpace ty = let
176 :     val suffix = (case ty
177 :     of Ty.TensorTy[d] => [Int.toString d, !gRealSuffix]
178 :     | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n, !gRealSuffix]
179 :     (* end case *))
180 :     in
181 :     concat("ToWorldSpace" :: suffix)
182 :     end
183 :     val inside = addVecSuffix "Inside"
184 :     fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
185 :     val strandDescTy = "Strand_t"
186 :     val worldTy = "Diderot_World_t"
187 :     val optionsTy = "Diderot_Options_t"
188 :     val allocInitially = "Diderot_AllocInitially"
189 :     val inState = "Diderot_InState"
190 :    
191 :     (* functions for defining program inputs *)
192 :     fun input ty = (case ty
193 :     of Ty.StringTy => "Diderot_OptAddString"
194 :     | Ty.BoolTy => "Diderot_OptAddBool"
195 :     | Ty.IntTy => "Diderot_OptAddInt"
196 :     | Ty.TensorTy[] => "Diderot_OptAddReal"
197 :     | Ty.TensorTy[2] => "Diderot_OptAddReal2"
198 :     | Ty.TensorTy[3] => "Diderot_OptAddReal3"
199 :     | Ty.TensorTy[4] => "Diderot_OptAddReal4"
200 :     | ty => raise Fail("unsupported input type " ^ Ty.toString ty)
201 :     (* end case *))
202 :    
203 :     end (* local *)
204 :     end

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