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/c-names.sml
ViewVC logotype

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

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

revision 3094, Wed Mar 18 04:45:43 2015 UTC revision 3095, Wed Mar 18 13:12:57 2015 UTC
# Line 3  Line 3 
3   * COPYRIGHT (c) 2015 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2015 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * These are names and types used in the CPU-side C code.   * These are names and types used in the CPU-side C code.  It includes names from
7     * RuntimeNames (c-util/runtime-names.sml) and CTypeNames (c-util/c-type-names.sml),
8     * plus additional names.
9   *)   *)
10    
11  structure CNames =  structure CNames =
12    struct    struct
13    
14        open RuntimeNames
15    
16      local      local
17        structure Ty = TreeIL.Ty        structure CTyN = CTypeNames
18        structure F = Format        structure RN = RuntimeNames
19        structure CN = CNames        structure CL = CLang
20      in      in
21    
22    (* globals that specify the target characteristics.  These should be initialized    (* globals that specify the target characteristics.  These should be initialized
23     * when the program object is created.     * when the program object is created.
24     *)     *)
25      val gIntTy = CN.gIntTy              (* external API type for Diderot ints *)      val gIntTy = CTyN.gIntTy            (* external API type for Diderot ints *)
26      val gCPUIntTy = ref CLang.voidTy    (* CPU-side shadow type for Diderot ints *)      val gCPUIntTy = ref CLang.voidTy    (* CPU-side shadow type for Diderot ints *)
27      val gGPUIntTy = ref CLang.voidTy    (* GPU-side OpenCL type for Diderot ints *)      val gGPUIntTy = CTyN.gRealTy        (* OpenCL type matches C type *)
28      val gRealTy = CN.gRealTy            (* external API type for Diderot reals *)      val gRealTy = CTyN.gRealTy          (* external API type for Diderot reals *)
29      val gCPURealTy = ref CLang.voidTy   (* CPU-side shadow type for Diderot reals *)      val gCPURealTy = ref CLang.voidTy   (* CPU-side shadow type for Diderot reals *)
30      val gGPURealTy = ref CLang.voidTy   (* GPU-side OpenCL type for Diderot reals *)      val gGPURealTy = CTyN.gIntTy        (* OpenCL type matches C type *)
31      val gRealStem = ref "?"      val gRealStem = ref "?"
32      val gRealSuffix = CN.gRealSuffix      val gRealSuffix = CTyN.gRealSuffix
33      val gIntStem = ref "?"      val gIntStem = ref "?"
34      val gIntSuffix = CN.gIntSuffix      val gIntSuffix = CTyN.gIntSuffix
35      val gIntFormat = CN.gIntFormat      val gIntFormat = CTyN.gIntFormat
36    
37   (* initialize globals based on target precision *)   (* initialize globals based on target precision *)
38      fun initTargetSpec (tgt : TargetUtil.target_desc) = (      fun initTargetSpec (tgt : TargetUtil.target_desc) = (
39            CNames.initTargetSpec tgt;            CTypeNames.initTargetSpec tgt;
40            if #longint tgt            if #longint tgt
41              then (              then (
42                gCPUIntTy := CLang.T_Named "cl_long";                gCPUIntTy := CLang.T_Named "cl_long";
               gGPUIntTy := CLang.int64;  
43                gIntStem := "long";                gIntStem := "long";
44                gIntFormat := "%ld")                gIntFormat := "%ld")
45              else (              else (
46                gCPUIntTy := CLang.T_Named "cl_int";                gCPUIntTy := CLang.T_Named "cl_int";
               gGPUIntTy := CLang.int32;  
47                gIntStem := "int";                gIntStem := "int";
48                gIntFormat := "%d");                gIntFormat := "%d");
49            if #double tgt            if #double tgt
50              then (              then (
51                gCPURealTy := CLang.T_Named "cl_double";                gCPURealTy := CLang.T_Named "cl_double";
               gGPURealTy := CLang.double;  
52                gRealStem := "double")                gRealStem := "double")
53              else (              else (
54                gCPURealTy := CLang.T_Named "cl_float";                gCPURealTy := CLang.T_Named "cl_float";
               gGPURealTy := CLang.float;  
55                gRealStem := "float"))                gRealStem := "float"))
56    
57    (* type names *)    (* C-side OpenCL type names *)
58      fun vecTy n = concat["cl_", !gRealStem, Int.toString n]      fun clVecTy n = concat["cl_", !gRealStem, Int.toString n]
59      fun ivecTy n = concat["cl_", !gIntStem, Int.toString n]      fun clIntVecTy n = concat["cl_", !gIntStem, Int.toString n]
60      fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]  
61      fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]      fun mkCLVec n = concat["VEC", Int.toString n]
62    
63      fun mkVec n = concat["VEC", Int.toString n]    (* pointer to scheduler data structure *)
64        val schedTyName = RN.qualifyName "Sched_t"
65      val worldTy = CNames.worldTy      fun schedPtrTy tgt = CL.T_Ptr(CL.T_Named(schedTyName tgt))
66    
67    (* host-side names for OpenCL types *)    (* names inherited from RuntimeNames *)
68      fun shadowIntTy () = "Shadow_int_t"      val worldTyName = RN.worldTyName
69      fun shadowRealTy () = "Shadow_real_t"      val worldPtrTy = RN.worldPtrTy
70      fun shadowVecTy n = F.format "Shadow_vec%d_t" [F.INT n]      val inputsTyName = RN.inputsTyName
71      fun shadowMatTy (m, n) = F.format "Shadow_Mat%dx%d_t" [F.INT m, F.INT n]      val inputsPtrTy = RN.inputsPtrTy
72      fun convertToShadowVec n = "ShadowVec" ^ Int.toString n      val definedInpTyName = RN.definedInpTyName
73      fun convertToShadowMat (m,n) = F.format "ShadowMat%dx%d" [F.INT m, F.INT n]      val definedInpPtrTy = RN.definedInpPtrTy
74        val optionsTyName = RN.optionsTyName
75    (* generate names for input and output variables *)      val optionsPtrTy = RN.optionsPtrTy
76      val inputDesc = CN.inputDesc      val inputDesc = RN.inputDesc
77      val inputGet = CN.inputGet      val inputGet = RN.inputGet
78      val inputSet = CN.inputSet      val inputSet = RN.inputSet
79      val inputSetByName = CN.inputSetByName      val inputSetByName = RN.inputSetByName
80      val outputGet = CN.outputGet      val outputGet = RN.outputGet
81      val snapshotGet = CN.snapshotGet      val snapshotGet = RN.snapshotGet
82        val initDefaults = RN.initDefaults
83      val freeGlobals = CNames.freeGlobals      val registerOpts = RN.registerOpts
84      val definedInpTy = CNames.definedInpTy      val registerOutputOpts = RN.registerOutputOpts
85      fun freeImage dim = concat["Diderot_FreeImage", Int.toString dim, "D"]      val initInputs = RN.initInputs
86        val initDefined = RN.initDefined
87    (* functions for defining program inputs *)      val checkDefined = RN.checkDefined
88      fun input ty = (case ty      val shutdown = RN.shutdown
89             of Ty.StringTy => "Diderot_OptAddString"      val initially = RN.initially
90              | Ty.BoolTy => "Diderot_OptAddBool"      val allocInitially = RN.allocInitially
91              | Ty.IntTy => "Diderot_OptAddInt"      val strandDescTy = RN.strandDescTy
92              | Ty.TensorTy[] => "Diderot_OptAddReal"      val strandDesc = RN.strandDesc
93              | Ty.TensorTy[2] => "Diderot_OptAddReal2"      val strands = RN.strands
94              | Ty.TensorTy[3] => "Diderot_OptAddReal3"      val setImage = RN.setImage
95              | Ty.TensorTy[4] => "Diderot_OptAddReal4"      val loadImage = RN.loadImage
96              | ty => raise Fail("unsupported input type " ^ Ty.toString ty)      val freeImage = RN.freeImage
97            (* end case *))      val loadDynSeq = RN.loadDynSeq
98        val loadDynSeqFromFile = RN.loadDynSeqFromFile
99        val inputOpt = RN.inputOpt
100        val imageTyName = RN.imageTyName
101        val imagePtrTy = RN.imagePtrTy
102        val dynSeqTy = RN.dynSeqTy
103    
104      end (* local *)      end (* local *)
105    end    end

Legend:
Removed from v.3094  
changed lines
  Added in v.3095

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