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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2743 - (download) (annotate)
Sun Sep 28 02:54:54 2014 UTC (5 years, 1 month ago) by jhr
File size: 3494 byte(s)
  Working on OpenCL support
(* runtime-names.sml
 *
 * COPYRIGHT (c) 2014 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure RuntimeNames =
  struct

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

  (* globals that specify the target characteristics.  These should be initialized
   * when the program object is created.
   *)
    val gIntTy = CN.gIntTy		(* external API type for Diderot ints *)
    val gCPUIntTy = ref CLang.voidTy	(* CPU-side shadow type for Diderot ints *)
    val gGPUIntTy = ref CLang.voidTy	(* GPU-side OpenCL type for Diderot ints *)
    val gRealTy = CN.gRealTy		(* external API type for Diderot reals *)
    val gCPURealTy = ref CLang.voidTy	(* CPU-side shadow type for Diderot reals *)
    val gGPURealTy = ref CLang.voidTy	(* GPU-side OpenCL type for Diderot reals *)
    val gRealStem = ref "?"
    val gRealSuffix = CN.gRealSuffix
    val gIntStem = ref "?"
    val gIntSuffix = CN.gIntSuffix
    val gIntFormat = CN.gIntFormat

 (* initialize globals based on target precision *)
    fun initTargetSpec (tgt : TargetUtil.target_desc) = (
	  CNames.initTargetSpec tgt;
	  if #longint tgt
	    then (
              gCPUIntTy := CLang.T_Named "cl_long";
              gGPUIntTy := CLang.int64;
	      gIntStem := "long";
              gIntFormat := "%ld")
            else (
              gCPUIntTy := CLang.T_Named "cl_int";
              gGPUIntTy := CLang.int32;
	      gIntStem := "int";
              gIntFormat := "%d");
          if #double tgt
            then (
              gCPURealTy := CLang.T_Named "cl_double";
              gGPURealTy := CLang.double;
              gRealStem := "double")
            else (
              gCPURealTy := CLang.T_Named "cl_float";
              gGPURealTy := CLang.float;
              gRealStem := "float"))

  (* type names *)
    fun vecTy n = concat["cl_", !gRealStem, Int.toString n]
    fun ivecTy n = concat["cl_", !gIntStem, 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"]

    fun mkVec n = concat["VEC", Int.toString n]

    val worldTy = CNames.worldTy

  (* host-side names for OpenCL types *)
    fun shadowIntTy () = "Shadow_int_t"
    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 convertToShadowVec n = "ShadowVec" ^ Int.toString n
    fun convertToShadowMat (m,n) = F.format "ShadowMat%dx%d" [F.INT m, F.INT n]
    
  (* generate names for input and output variables *)
    val inputDesc = CN.inputDesc
    val inputGet = CN.inputGet
    val inputSet = CN.inputSet
    val inputSetByName = CN.inputSetByName
    val outputGet = CN.outputGet
    val snapshotGet = CN.snapshotGet

    val freeGlobals = CNames.freeGlobals
    val definedInpTy = CNames.definedInpTy

  (* functions for defining program inputs *)
    fun input ty = (case ty
	   of Ty.StringTy => "Diderot_OptAddString"
	    | Ty.BoolTy => "Diderot_OptAddBool"
	    | Ty.IntTy => "Diderot_OptAddInt"
	    | Ty.TensorTy[] => "Diderot_OptAddReal"
	    | Ty.TensorTy[2] => "Diderot_OptAddReal2"
	    | Ty.TensorTy[3] => "Diderot_OptAddReal3"
	    | Ty.TensorTy[4] => "Diderot_OptAddReal4"
	    | 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