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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2738, Sat Sep 27 15:46:27 2014 UTC revision 2739, Sat Sep 27 17:23:34 2014 UTC
# Line 1  Line 1 
1  (* runtime-names.sml  (* runtime-names.sml
2   *   *
3   * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2014 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *)   *)
6    
# Line 10  Line 10 
10      local      local
11        structure Ty = TreeIL.Ty        structure Ty = TreeIL.Ty
12        structure F = Format        structure F = Format
13          structure CN = CNames
14      in      in
15    
16    (* globals that specify the target characteristics.  These should be initialized    (* globals that specify the target characteristics.  These should be initialized
17     * when the program object is created.     * when the program object is created.
18     *)     *)
19      val gIntTy = ref CLang.int32        (* external API type for Diderot ints *)      val gIntTy = CN.gIntTy              (* external API type for Diderot ints *)
20      val gCLIntTy = ref CLang.voidTy     (* CPU-side OpenCL type for Diderot ints *)      val gCPUIntTy = ref CLang.voidTy    (* CPU-side shadow type for Diderot ints *)
21      val gRealTy = ref CLang.float       (* external API type for Diderot reals *)      val gGPUIntTy = ref CLang.voidTy    (* GPU-side OpenCL type for Diderot ints *)
22      val gCLRealTy = ref CLang.voidTy    (* CPU-side OpenCL type for Diderot reals *)      val gRealTy = CN.gRealTy            (* external API type for Diderot reals *)
23        val gCPURealTy = ref CLang.voidTy   (* CPU-side shadow type for Diderot reals *)
24        val gGPURealTy = ref CLang.voidTy   (* GPU-side OpenCL type for Diderot reals *)
25      val gRealStem = ref "?"      val gRealStem = ref "?"
26      val gRealSuffix = ref "?"      val gRealSuffix = CN.gRealSuffix
27      val gIntSuffix = ref "?"      val gIntStem = ref "?"
28      val gIntFormat = ref "?"      val gIntSuffix = CN.gIntSuffix
29        val gIntFormat = CN.gIntFormat
30    
31   (* initialize globals based on target precision *)   (* initialize globals based on target precision *)
32      fun initTargetSpec (tgt : TargetUtil.target_desc) = (      fun initTargetSpec (tgt : TargetUtil.target_desc) = (
33              CNames.initTargetSpec tgt;
34            if #longint tgt            if #longint tgt
35              then (              then (
36                gIntTy := CLang.int64;                gCPUIntTy := CLang.T_Named "cl_long";
37                gCLIntTy := CLang.T_Named "cl_long";                gGPUIntTy := CLang.int64;
38                gIntSuffix := "l";                gIntStem := "long";
39                gIntFormat := "%ld")                gIntFormat := "%ld")
40              else (              else (
41                gIntTy := CLang.int32;                gCPUIntTy := CLang.T_Named "cl_int";
42                gCLIntTy := CLang.T_Named "cl_int";                gGPUIntTy := CLang.int32;
43                gIntSuffix := "i";                gIntStem := "int";
44                gIntFormat := "%d");                gIntFormat := "%d");
45            if #double tgt            if #double tgt
46              then (              then (
47                gRealTy := CLang.double;                gCPURealTy := CLang.T_Named "cl_double";
48                gCLRealTy := CLang.T_Named "cl_double";                gGPURealTy := CLang.double;
49                gRealStem := "double";                gRealStem := "double")
               gRealSuffix := "d")  
50              else (              else (
51                gRealTy := CLang.float;                gCPURealTy := CLang.T_Named "cl_float";
52                gCLRealTy := CLang.T_Named "cl_float";                gGPURealTy := CLang.float;
53                gRealStem := "float";                gRealStem := "float"))
               gRealSuffix := "f"))  
   
     fun addRealSuffix stem = stem ^ !gRealSuffix  
     fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix]  
     fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix]  
     fun addBufferSuffix stem = concat[stem, "_cl"]  
     fun addBufferSuffixData stem = concat[stem, "_data_cl"]  
54    
55      fun addTySuffix (stem, 1) = stem ^ !gRealSuffix      fun vecTy n = concat["cl_", !gRealStem, Int.toString n]
56        | addTySuffix (stem, n) = addVecSuffix stem n      fun ivecTy n = concat["cl_", !gIntStem, Int.toString n]
   
     fun vecTy n = concat[!gRealStem, Int.toString n]  
     fun ivecTy n = concat["int", Int.toString n]  
57      fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]      fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]
58      fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]      fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]
59    
60        fun mkVec n = concat["VEC", Int.toString n]
61    
62        val worldTy = CNames.worldTy
63    
64        val initGlobals = CNames.initGlobals
65        val freeGlobals = CNames.freeGlobals
66        val definedInpTy = CNames.definedInpTy
67        val initially = CNames.initially
68        val allocInitially = CNames.allocInitially
69    
70    (* host-side names for OpenCL types *)    (* host-side names for OpenCL types *)
71      fun shadowIntTy () = "Shadow_int_t"      fun shadowIntTy () = "Shadow_int_t"
72      fun shadowRealTy () = "Shadow_real_t"      fun shadowRealTy () = "Shadow_real_t"
# Line 71  Line 75 
75      fun convertToShadowVec n = "ShadowVec" ^ Int.toString n      fun convertToShadowVec n = "ShadowVec" ^ Int.toString n
76      fun convertToShadowMat (m,n) = F.format "ShadowMat%dx%d" [F.INT m, F.INT n]      fun convertToShadowMat (m,n) = F.format "ShadowMat%dx%d" [F.INT m, F.INT n]
77    
   (* names of generated types, functions, and globals *)  
     val initGlobals = "Diderot_InitGlobals"     (* function for initializing program globals *)  
     val initGlobalsHelper = "Diderot_InitGlobalsHelper" (* function for initializing program globals *)  
     val registerOpts = "Diderot_RegisterGlobalOpts"     (* function for registering command-line options *)  
     val initially = "Diderot_Initially"         (* function for creating initial strands *)  
     val shutdown = "Diderot_Shutdown"           (* function that gets called at the end *)  
     val globalsTy = "Diderot_Globals_t"  
     val kernelFuncName = "Diderot_UpdateKernel"  
     fun strandInit strand = strand ^ "_InitState"  
     val strandInitSetup = "Diderot_Strand_Init"  
     val strandBlockCopyName = "StrandBlock_Copy"  
     fun strandTy strand = concat["Strand_", strand, "_t"]  
     fun strandDesc strand = concat["Strand_", strand]  
     val numStrands = "Diderot_NumStrands"  
     val strands = "Diderot_Strands"  
     (*fun strandUpdate strand = strand ^ StrandUtil.nameToString StrandUtil.Update *)  
     val strandUpdate = "Diderot_Update"  
     fun strandStabilize strand = strand ^ StrandUtil.nameToString StrandUtil.Stabilize  
     val strandCopy = "Diderot_StateCopy"  
     fun strandPrintName strand = strand ^ "Print"  
   
     val clLoaderFN = "Diderot_LoadKernel"  
     val getGlobalThreadId ="get_global_id"  
     val getLocalThreadId = "get_local_id"  
     val getGlobalSize = "get_global_size"  
     val getGroupId = "get_group_id"  
     val getNumGroups = "get_num_groups"  
     val getLocalSize = "get_local_size"  
     val globalsVarName = "diderotGlobals"  
     val globalsVarNameCL = "cl_diderotGlobals"  
     val globalsSetupName = "Diderot_LoadGlobals"  
   
   (* Scheduler runtime names *)  
     val globalPoolName = "globalPoolNextStrand"  
     val schedTy = "SchedState_t"  
     val strandBlkTy = "StrandBlock_t"  
     val schedFuncName = "Diderot_UpdateScheduler"  
     val getBlockFuncName = "GetBlock"  
     val barrier = "barrier"  
     val mem_fence = "mem_fence"  
     val local_fence = "CLK_LOCAL_MEM_FENCE"  
     val global_fence = "CLK_GLOBAL_MEM_FENCE"  
     val atom_add = "atom_add"  
     val atom_dec = "atom_dec"  
     val atom_inc = "atom_inc"  
   
   (* Placeholders  *)  
     val place_holders ="STRAND_TY"  
     val p_addGlobals = "SHOULD_ADD_GLOBALS"  
     val p_globals = "GLOBALS"  
     val p_addDatPtr = "SHOULD_ADD_DATA"  
     val p_dataPtr = "GLOBAL_DATA_PTRS"  
     val p_dataAssign = "GLOBAL_DATA_ASSIGN"  
     val p_globalVar = "GLOBAL_VAR"  
     val p_dataVar = "DATA_VAR"  
   
   (* scalar math functions *)  
     val max = "max"  
     val min = "min"  
     val fabs = "fabs"  
   
   (* clamp and lerp *)  
     val clamp = "clamp"  
     val lerp = "mix"  
   
   (* vector math functions *)  
     fun mkVec 3 = "VEC3" (* for OpenCL 1.0 *)  
       | mkVec n = concat["(", !gRealStem, Int.toString n, ")"]  (* cast syntax *)  
     val truncToInt = addVecSuffix "truncToInt"  
     val dot = "dot"  
     val cross = "cross"  
     val length = "length"  
     val normalize = "normalize"  
     fun vecitof n = concat["convert_float", Int.toString n]  
     fun vecftoi n = concat["convert_int", Int.toString n]  
   (* matrix operations *)  
     fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun identityMat n = concat["identity", Int.toString n, "x", Int.toString n, !gRealSuffix]  
     fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix]  
     fun norm (n, m) = concat["norm", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun scaleMat (n, m) = concat["scale", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun addMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun subMat (n, m) = concat["sub", Int.toString n, "x", Int.toString m, !gRealSuffix]  
     fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s"  
           [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)]  
     fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s"  
           [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)]  
     fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s"  
           [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)]  
   
   (* Math utility functions *)  
     val evecs2x2 = "Diderot_evecs2x2"  
     val evecs3x3 = "Diderot_evecs3x3"  
     val evals2x2 = "Diderot_evals2x2"  
     val evals3x3 = "Diderot_evals3x3"  
     fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]  
   
   (* Status_t symbols *)  
     val kActive = "DIDEROT_ACTIVE"  
     val kDie = "DIDEROT_DIE"  
     val kStabilize = "DIDEROT_STABILIZE"  
     val kStable = "DIDEROT_STABLE"  
   
   (* Diderot runtime system hooks *)  
     val toImageSpace = addVecSuffix "ToImageSpace"  
     fun toWorldSpace ty = let  
           val suffix = (case ty  
                  of Ty.TensorTy[d] => [Int.toString d, !gRealSuffix]  
                   | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n, !gRealSuffix]  
                 (* end case *))  
           in  
             concat("ToWorldSpace" :: suffix)  
           end  
     val inside = addVecSuffix "Inside"  
     fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]  
     val strandDescTy = "Strand_t"  
     val worldTy = "Diderot_World_t"  
     val optionsTy = "Diderot_Options_t"  
     val allocInitially = "Diderot_AllocInitially"  
     val inState = "Diderot_InState"  
   
78      (* functions for defining program inputs *)      (* functions for defining program inputs *)
79      fun input ty = (case ty      fun input ty = (case ty
80             of Ty.StringTy => "Diderot_OptAddString"             of Ty.StringTy => "Diderot_OptAddString"

Legend:
Removed from v.2738  
changed lines
  Added in v.2739

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