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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1431 - (view) (download)

1 : lamonts 1244 (* 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 : jhr 1273 val gRealStem = ref "?"
22 : lamonts 1244 val gRealSuffix = ref "?"
23 :     val gIntSuffix = ref "?"
24 :     val gIntFormat = ref "?"
25 :    
26 :     (* initialize globals based on target precision *)
27 :     fun initTargetSpec double = (
28 : jhr 1324 doublePrecision := double;
29 :     if double
30 :     then (
31 :     gIntTy := CLang.int64;
32 :     gRealTy := CLang.double;
33 : jhr 1273 gRealStem := "double";
34 : jhr 1324 gRealSuffix := "d";
35 :     gIntSuffix := "l";
36 :     gIntFormat := "%ld")
37 :     else (
38 :     gIntTy := CLang.int32;
39 :     gRealTy := CLang.float;
40 : jhr 1273 gRealStem := "float";
41 : jhr 1324 gRealSuffix := "f";
42 :     gIntSuffix := "i";
43 :     gIntFormat := "%d"))
44 : lamonts 1244
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 : jhr 1261 fun addBufferSuffix stem = concat[stem, "_cl"]
49 :     fun addBufferSuffixData stem = concat[stem, "_data_cl"]
50 : lamonts 1244
51 :     fun addTySuffix (stem, 1) = stem ^ !gRealSuffix
52 :     | addTySuffix (stem, n) = addVecSuffix stem n
53 :    
54 : jhr 1273 fun vecTy n = concat[!gRealStem, Int.toString n]
55 :     fun ivecTy n = concat["int", Int.toString n]
56 : lamonts 1244 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 : jhr 1358 (* 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 : lamonts 1398 fun shadowImageFunc d = concat["ShadowImage", Int.toString d, "D"]
66 : jhr 1431 val shadowGlobalsTy = "Shadow_globals_t"
67 : jhr 1405 val shadowGlaobalsName = "shadowGlobals"
68 : lamonts 1408 fun convertToShadowVec n = concat["ShadowVec",Int.toString n]
69 : lamonts 1429 fun unshadowVec n = concat["UnshadowVec",Int.toString n]
70 : lamonts 1408 fun convertToShadowMat (m,n) = F.format "ShadowMat%dx%d" [F.INT m, F.INT n]
71 : lamonts 1398 (*GPU side image data types and functions *)
72 : jhr 1431 val imageDataType = "Diderot_data_ptr_t"
73 :     val globalImageDataName = "diderotDataPtrs"
74 :     fun imageDataName name = name ^ "Data"
75 : lamonts 1398
76 : lamonts 1244 (* names of generated tyes, functions, and globals *)
77 : jhr 1324 val initGlobals = "Diderot_InitGlobals" (* function for initializing program globals *)
78 : jhr 1326 val initGlobalsHelper = "Diderot_InitGlobalsHelper" (* function for initializing program globals *)
79 : jhr 1324 val registerOpts = "Diderot_RegisterGlobalOpts" (* function for registering command-line options *)
80 :     val initially = "Diderot_Initially" (* function for creating initial strands *)
81 :     val shutdown = "Diderot_Shutdown" (* function that gets called at the end *)
82 : jhr 1282 val globalsTy = "Diderot_Globals_t"
83 : jhr 1326 val kernelFuncName = "Diderot_KernelMain"
84 : lamonts 1271 fun strandInit strand = strand ^ "_InitState"
85 : jhr 1273 val strandInitSetup = "Diderot_Strand_Init"
86 : lamonts 1244 fun strandTy strand = concat["Strand_", strand, "_t"]
87 : lamonts 1399 fun strandCopy strand = strand ^ "_Copy"
88 : lamonts 1244 fun strandUpdate strand = concat[strand,"_update"]
89 :     fun strandStabilize strand = concat[strand,"_stabilize"]
90 :     fun strandDesc strand = concat["Strand_", strand]
91 :     val numStrands = "Diderot_NumStrands"
92 :     val strands = "Diderot_Strands"
93 :    
94 : jhr 1282 val clLoaderFN = "Diderot_LoadKernel"
95 : lamonts 1244 val getGlobalThreadId ="get_global_id"
96 :     val globalsVarName = "diderotGlobals"
97 : lamonts 1256 val globalsVarNameCL = "cl_diderotGlobals"
98 : jhr 1313 val globalsSetupName = "Diderot_LoadGlobals"
99 : lamonts 1351
100 : lamonts 1244 (* scalar math functions *)
101 : jhr 1273 val max = "max"
102 :     val min = "min"
103 :     val fabs = "fabs"
104 : lamonts 1244
105 : jhr 1297 (* clamp and lerp *)
106 :     val clamp = "clamp"
107 : jhr 1273 val lerp = "mix"
108 : lamonts 1244
109 :     (* vector math functions *)
110 : jhr 1273 fun mkVec 3 = "VEC3" (* for OpenCL 1.0 *)
111 :     | mkVec n = concat["(", !gRealStem, Int.toString n, ")"] (* cast syntax *)
112 : lamonts 1244 val truncToInt = addVecSuffix "truncToInt"
113 : jhr 1273 val dot = "dot"
114 :     val cross = "cross"
115 :     val length = "length"
116 :     val normalize = "normalize"
117 : jhr 1324 fun vecitof n = if n <> 3
118 :     then concat["convert_float", Int.toString n]
119 :     else "convert_float4" (* for OpenCL 1.0 *)
120 :     fun vecftoi n = if n <> 3
121 :     then concat["convert_int", Int.toString n]
122 :     else "convert_int4" (* for OpenCL 1.0 *)
123 : lamonts 1244 (* matrix operations *)
124 :     fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m, !gRealSuffix]
125 :     fun identityMat n = concat["identity", Int.toString n, "x", Int.toString n, !gRealSuffix]
126 :     fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix]
127 :     fun norm (n, m) = concat["norm", Int.toString n, "x", Int.toString m, !gRealSuffix]
128 :     fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix]
129 :     fun scaleMat (n, m) = concat["scale", Int.toString n, "x", Int.toString m, !gRealSuffix]
130 :     fun addMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix]
131 :     fun subMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix]
132 :     fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s"
133 : jhr 1324 [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)]
134 : lamonts 1244 fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s"
135 : jhr 1324 [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)]
136 : lamonts 1244 fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s"
137 : jhr 1324 [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)]
138 : lamonts 1244
139 :     (* Status_t symbols *)
140 :     val kActive = "DIDEROT_ACTIVE"
141 :     val kDie = "DIDEROT_DIE"
142 :     val kStabilize = "DIDEROT_STABILIZE"
143 :    
144 :     (* Diderot runtime system hooks *)
145 :     val statusTy = "Status_t"
146 : lamonts 1398 val toImageSpace = addVecSuffix "ToImageSpace"
147 : lamonts 1244 fun toWorldSpace ty = let
148 : jhr 1324 val suffix = (case ty
149 :     of Ty.TensorTy[d] => [Int.toString d, !gRealSuffix]
150 :     | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n, !gRealSuffix]
151 :     (* end case *))
152 :     in
153 :     concat("ToWorldSpace" :: suffix)
154 :     end
155 : lamonts 1244 val inside = addVecSuffix "Inside"
156 :     fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
157 :     val strandDescTy = "Strand_t"
158 :     val worldTy = "Diderot_World_t"
159 : jhr 1261 val optionsTy = "Diderot_Options_t"
160 : lamonts 1346 val allocInitially = "Diderot_AllocInitially"
161 : lamonts 1244 val inState = "Diderot_InState"
162 :    
163 :     fun input ty = (case ty
164 : jhr 1324 of Ty.StringTy => "Diderot_InputString"
165 :     | Ty.TensorTy[] => "Diderot_Input" ^ !gRealSuffix
166 :     | Ty.TensorTy[3] => "Diderot_InputVec3" ^ !gRealSuffix
167 :     | ty => raise Fail("unsupported input type " ^ Ty.toString ty)
168 :     (* end case *))
169 : lamonts 1244
170 :     end (* local *)
171 :     end

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