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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1463 - (download) (annotate)
Tue Aug 9 12:48:06 2011 UTC (8 years ago) by jhr
File size: 7781 byte(s)
  Fixing indentation etc.
(* runtime-names.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure RuntimeNames =
  struct

    local
      structure Ty = TreeIL.Ty
      structure F = Format
    in

  (* globals that specify the target characteristics.  These should be initialized
   * when the program object is created.
   *)
    val doublePrecision = ref false
    val gIntTy = ref CLang.int32
    val gRealTy = ref CLang.float
    val gRealStem = ref "?"
    val gRealSuffix = ref "?"
    val gIntSuffix = ref "?"
    val gIntFormat = ref "?"

 (* initialize globals based on target precision *)
    fun initTargetSpec double = (
          doublePrecision := double;
          if double
            then (
              gIntTy := CLang.int64;
              gRealTy := CLang.double;
              gRealStem := "double";
              gRealSuffix := "d";
              gIntSuffix := "l";
              gIntFormat := "%ld")
            else (
              gIntTy := CLang.int32;
              gRealTy := CLang.float;
              gRealStem := "float";
              gRealSuffix := "f";
              gIntSuffix := "i";
              gIntFormat := "%d"))

    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"] 

    fun addTySuffix (stem, 1) = stem ^ !gRealSuffix
      | addTySuffix (stem, n) = addVecSuffix stem n

    fun vecTy n = concat[!gRealStem, Int.toString n]
    fun ivecTy n = concat["int", Int.toString n]
    fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]
    fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]

  (* host-side names for OpenCL types *)
    fun shadowIntTy () = "cl_int"       (* QUESTION: should this be precision dependent? *)
    fun shadowRealTy () = "Shadow_real_t"
    fun shadowVecTy n = F.format "Shadow_vec%d_t" [F.INT n]
    fun shadowMatTy (m, n) = F.format "Shadow_Mat%dx%d_t" [F.INT m, F.INT n]
    fun shadowImageTy d = concat["Shadow_image", Int.toString d, "D_t"]
    fun shadowImageFunc d = concat["ShadowImage", Int.toString d, "D"]
    val shadowGlobalsTy = "Shadow_globals_t"
    val shadowGlaobalsName = "shadowGlobals"
    fun convertToShadowVec n = concat["ShadowVec",Int.toString n]
    fun unshadowVec n = concat["UnshadowVec",Int.toString n] 
    fun convertToShadowMat (m,n) = F.format "ShadowMat%dx%d" [F.INT m, F.INT n]
  (*GPU side image data types and functions *) 
    val imageDataType = "Diderot_data_ptr_t" 
    val globalImageDataName = "diderotDataPtrs" 
    fun imageDataName name = name ^ "Data"
    
  (* names of generated tyes, 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" 
    fun strandTy strand = concat["Strand_", strand, "_t"]
    fun strandCopy strand = strand ^ "_Copy" 
    fun strandUpdate strand = concat[strand,"_update"]
    fun strandStabilize strand = concat[strand,"_stabilize"] 
    fun strandDesc strand = concat["Strand_", strand]
    val numStrands = "Diderot_NumStrands"
    val strands = "Diderot_Strands"
    val strandConvertName = "Diderot_Strand_Covert_To_Shadow" 
    fun strandShadowTy strand = concat["Shadow_",strand]

    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 workerTy = "WorkerArg_t" 
    val barrier = "barrier" 
    val atom_add = "atom_add"
    val atom_dec = "atom_dec"

  (* 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 = if n <> 3
          then concat["convert_float", Int.toString n]
          else "convert_float4" (* for OpenCL 1.0 *)
    fun vecftoi n = if n <> 3
          then concat["convert_int", Int.toString n]
          else "convert_int4" (* for OpenCL 1.0 *)
  (* 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["add", 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)]

  (* Status_t symbols *)
    val kActive = "DIDEROT_ACTIVE"
    val kDie = "DIDEROT_DIE"
    val kStabilize = "DIDEROT_STABILIZE"
    val kStable = "DIDEROT_STABLE"

  (* Diderot runtime system hooks *)
    val statusTy = "Status_t"
    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"

    fun input ty = (case ty
           of Ty.StringTy => "Diderot_InputString"
            | Ty.TensorTy[] => "Diderot_Input" ^ !gRealSuffix
            | Ty.TensorTy[3] => "Diderot_InputVec3" ^ !gRealSuffix
            | ty => raise Fail("unsupported input type " ^ Ty.toString ty)
          (* end case *))

    end (* local *)
  end

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