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/gen-inputs.sml
ViewVC logotype

Diff of /branches/vis12-cl/src/compiler/cl-target/gen-inputs.sml

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

revision 3117, Sun Mar 22 08:30:03 2015 UTC revision 3118, Mon Mar 23 18:05:45 2015 UTC
# Line 13  Line 13 
13    
14      val gatherInputs : TreeIL.block -> input_desc list      val gatherInputs : TreeIL.block -> input_desc list
15    
16      (* extract the world struct fields for the image data buffers and initialization kernels *)
17        val getBuffersAndKernels : input_desc list -> (string list * string list)
18    
19    (*** Support for standalone executables ***)    (*** Support for standalone executables ***)
20    
21    (* generate the input initialization structure that we use to initialize input    (* generate the input initialization structure that we use to initialize input
# Line 59  Line 62 
62    (* world pointer cast to the world prefix type *)    (* world pointer cast to the world prefix type *)
63      val wrldPrefix = CL.mkCast(wrldPrefixTy, CL.mkVar "wrld")      val wrldPrefix = CL.mkCast(wrldPrefixTy, CL.mkVar "wrld")
64    
65    (* an l-value expression for accessing a global variable *)    (* extract the world struct fields for the image data buffers and initialization kernels *)
66      fun global gv = CL.mkIndirect(CL.mkIndirect(CL.mkVar "wrld", "globals"), GVar.name gv)      fun getBuffersAndKernels inputs = let
67              fun get ([], bufs, kerns) = (List.rev bufs, List.rev kerns)
68                | get ((gv, name, _, _)::inps, bufs, kerns) = (case GVar.ty gv
69                     of Ty.ImageTy _ => get (inps, (name ^ "Buf") :: bufs, (name ^ "Kern") :: kerns)
70                      | _ => get (inps, bufs, kerns)
71                    (* end case *))
72              in
73                get (inputs, [], [])
74              end
75    
76    (* generate code to initialize the global input variables from the command-line inputs *)    (* generate code to initialize the global input variables from the command-line inputs *)
77      fun genInitInputs (tgt, inputs) = let      fun genInitInputs (tgt, inputs) = let
# Line 69  Line 80 
80          (* the inputs pointer type *)          (* the inputs pointer type *)
81            val inputPtrTy = N.inputsPtrTy tgt            val inputPtrTy = N.inputsPtrTy tgt
82          (* some common variables *)          (* some common variables *)
83              val wrldV = CL.mkVar "wrld"
84            val inpV = CL.mkVar "inp"            val inpV = CL.mkVar "inp"
85          (* initialize a given input global; for sequences and images, this requires          (* initialize a given input global; for sequences and images, this requires
86           * loading the value from the specified nrrd file, while for other types           * loading the value from the specified nrrd file, while for other types
87           * we just copy the values.           * we just copy the values.
88           *)           *)
89  (* FIXME            fun initInputs ((gv, name, _, optDflt)::inps, flds, stms, kerns) = (case GVar.ty gv
90            fun initInput ((Ty.DynSeqTy elemTy, name, desc, optDflt), stms) = let                   of Ty.DynSeqTy elemTy =>
91                  val (loadFn, nDims, dims) = (case elemTy                        raise Fail "dynamic sequences not supported for OpenCL"
92                         of Ty.BoolTy => ("Diderot_DynSeqLoadBoolFromFile", CL.mkInt 0, CL.mkInt 0)                    | Ty.ImageTy info => let
                         | Ty.IntTy => ("Diderot_DynSeqLoadIntFromFile", CL.mkInt 0, CL.mkInt 0)  
                         | Ty.TensorTy[] => ("Diderot_DynSeqLoadRealFromFile", CL.mkInt 0, CL.mkInt 0)  
                         | Ty.TensorTy _ => raise Fail "TODO: sequences of tensors"  
                         | Ty.SeqTy elemTy => raise Fail "TODO: sequences of sequences"  
                         | _ => raise Fail "unsupported dynamic sequence type"  
                       (* end case *))  
                 in  
                   CL.mkAssign(global gv,  
                     CL.mkApply(loadFn, [wrldPrefix, CL.mkIndirect(inpV, name), nDims, dims])) ::  
                   CL.mkIfThen(CL.mkBinOp(global gv, CL.#==, CL.mkInt 0),  
                     CL.mkReturn(SOME(CL.mkVar "true"))) :: stms  
                 end  
             | initInput ((Ty.ImageTy info, name, desc, optDflt), stms) = let  
93                  val loadFn = (case ImageInfo.dim info                  val loadFn = (case ImageInfo.dim info
94                         of 1 => "Diderot_LoadImage1D"                               of 1 => "Diderot_LoadGPUImage1D"
95                          | 2 => "Diderot_LoadImage2D"                                | 2 => "Diderot_LoadGPUImage2D"
96                          | 3 => "Diderot_LoadImage3D"                                | 3 => "Diderot_LoadGPUImage3D"
97                          | _ => raise Fail "image with dimension > 3"                          | _ => raise Fail "image with dimension > 3"
98                        (* end case *))                        (* end case *))
99                          val stm = CL.mkIfThen(
100                                CL.mkApply(loadFn, [
101                                    CL.mkCast(CL.T_Ptr(CL.T_Named "OCLWorldPrefix_t"), CL.mkVar "wrld"),
102                                    CL.mkIndirect(wrldV, "globalsBuf"),
103                                    CL.mkIndirect(inpV, "gv_" ^ name),
104                                    CL.mkIndirect(wrldV, name ^ "Kern"),
105                                    CL.mkAddrOf(CL.mkIndirect(wrldV, name ^ "Buf"))
106                                  ]),
107                                CL.mkReturn(SOME(CL.mkVar "true")))
108                  in                  in
109                    CL.mkIfThen(                          initInputs (inps, name::flds, stm::stms, kerns)
                     CL.mkApply(loadFn, [wrldPrefix, CL.mkIndirect(inpV, name), CL.mkAddrOf(global gv)]),  
                     CL.mkReturn(SOME(CL.mkVar "true"))) :: stms  
110                  end                  end
111              | initInput ((ty, name, _, _), stms) =                    | ty => let
112                  TrTy.copyFromC{ty=ty, dst=global gv, src=CL.mkIndirect(inpV, name)} @ stms                        val stm = TrTy.copyFromC{
113  *)                                ty=ty,
114                                  dst=CL.mkSelect(CL.mkVar "inputs", name),
115                                  src=CL.mkIndirect(inpV, name)
116                                }
117            in            in
118              CL.D_Func(                          initInputs (inps, name::flds, List.revAppend(stm, stms), kerns)
119                          end
120                    (* end case *))
121                | initInputs ([], flds, stms, kerns) = (List.rev flds, List.rev stms, List.rev kerns)
122              val (flds, stms, kerns) = initInputs (inputs, [], [], [])
123    (* TODO: create struct type from fields and copy to GPU; also generate kernels for images *)
124              val initFn = CL.D_Func(
125                ["static"], CL.boolTy, N.initInputs,                ["static"], CL.boolTy, N.initInputs,
126                [CL.PARAM([], worldPtrTy, "wrld"), CL.PARAM([], inputPtrTy, "inp")],                [CL.PARAM([], worldPtrTy, "wrld"), CL.PARAM([], inputPtrTy, "inp")],
127                CL.mkReturn(SOME(CL.mkVar "false")))                  CL.mkBlock(stms @ [CL.mkReturn(SOME(CL.mkVar "false"))]))
128              in
129                initFn
130            end            end
131    
132    (* generate the functions that handle inputs for standalone executables.  These are:    (* generate the functions that handle inputs for standalone executables.  These are:

Legend:
Removed from v.3117  
changed lines
  Added in v.3118

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