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/cl-target.sml
ViewVC logotype

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

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

revision 3087, Tue Mar 17 16:35:47 2015 UTC revision 3088, Tue Mar 17 18:27:27 2015 UTC
# Line 42  Line 42 
42          props : props,                  (* info about target *)          props : props,                  (* info about target *)
43          inputs : GenInputs.input_desc list ref,          inputs : GenInputs.input_desc list ref,
44          globals : global_var list ref,          globals : global_var list ref,
45          globInit : CL.stm list ref,     (* global initialization code; this gets combined with *)          globInit : CL.stm list ref,     (* global initialization code (OpenCL); this code gets *)
46                                          (* the setInitDim code. *)                                          (* combined with the setInitDim code. *)
47          kernels : string list ref,      (* a list of the OpenCL kernels used by this program *)          kernels : string list ref,      (* a list of the OpenCL kernels used by this program *)
48          topCDecls : CL.decl list ref,   (* top-level decls for the C file *)          topCDecls : CL.decl list ref,   (* top-level decls for the C file *)
49          topOCLDecls : CL.decl list ref, (* top-level decls for the OpenCL file *)          topOCLDecls : CL.decl list ref, (* top-level decls for the OpenCL file *)
# Line 85  Line 85 
85    (* OpenCL global pointer type *)    (* OpenCL global pointer type *)
86      fun globalPtrTy props = CL.T_Ptr(CL.T_Named(CLN.globalsTy props))      fun globalPtrTy props = CL.T_Ptr(CL.T_Named(CLN.globalsTy props))
87    
     fun worldPtrTy props = CL.T_Ptr(CL.T_Named(RN.worldTy props))  
   
88    (* TreeIL to target translations *)    (* TreeIL to target translations *)
89      structure Tr =      structure Tr =
90        struct        struct
# Line 275  Line 273 
273                end                end
274        (* gather the inputs *)        (* gather the inputs *)
275          fun inputs (Prog{inputs, ...}, env, blk) = inputs := GenInputs.gatherInputs blk          fun inputs (Prog{inputs, ...}, env, blk) = inputs := GenInputs.gatherInputs blk
276        (* register the global initialization part of a program *)        (* register the global initialization part of a program; the C-side code is responsible
277          fun init (Prog{globInit, ...}, init) = globInit := CL.unBlock init         * for allocating GPU memory and handling the inputs.  The GPU-side code is included
278           * in the globals initialization kernel (see genGlobInitKern)
279           *)
280            fun init (Prog{props, topCDecls, globInit, ...}, init) = if #hasGlobals props
281                  then let
282                    val worldTy = RN.worldPtrTy props
283                    val wrldV = CL.mkVar "wrld"
284                  (* the body of the global initializtion code *)
285                    val initStms = [CL.mkReturn(SOME(CL.mkVar "false"))]
286                  (* for libraries, we need to make sure that the inputs are initialized *)
287                    val initStms = if not(#exec props) andalso #hasInputs props
288                          then CL.mkIfThen(
289                            CL.mkApply(RN.checkDefined props, [wrldV]),
290                            CL.mkReturn(SOME(CL.mkBool true))) :: initStms
291                          else initStms
292                    val initFn = CL.D_Func(
293                          ["static"], CL.boolTy, RN.initGlobals,
294                          [CL.PARAM([], worldTy, "wrld")],
295                          CL.mkBlock initStms)
296                    in
297                      topCDecls := initFn :: !topCDecls;
298                      globInit := CL.unBlock init
299                    end
300                  else ()
301        (* register the global destruction part of a program *)        (* register the global destruction part of a program *)
302  (* TODO: factor out common code from c-target.sml *)  (* TODO: factor out common code from c-target.sml *)
303          (* for the OpenCL target, we need to free the GPU-side resources and the CPU-side inputs *)
304          fun free (Prog{props, topCDecls, ...}, env, globals) = let          fun free (Prog{props, topCDecls, ...}, env, globals) = let
305                val worldTy = CL.T_Ptr(CL.T_Named(RN.worldTy props))                val worldTy = RN.worldPtrTy props
306                val globTy = CL.T_Ptr(CL.T_Named(CLN.globalsTy props))                val globTy = CL.T_Ptr(CL.T_Named(CLN.globalsTy props))
307                fun global x = CL.mkIndirect(CL.mkVar "glob", "gv_" ^ IL.GlobalVar.name x)                fun global x = CL.mkIndirect(CL.mkVar "glob", "gv_" ^ IL.GlobalVar.name x)
308                fun freeGlob (x, stms) = (case IL.GlobalVar.ty x                fun freeGlob (x, stms) = (case IL.GlobalVar.ty x
# Line 481  Line 503 
503    
504        (* generate the C function for binding the kernels used by the program *)        (* generate the C function for binding the kernels used by the program *)
505          fun genBindKernels (props, kernels) = let          fun genBindKernels (props, kernels) = let
506                val worldTy = worldPtrTy props                val worldTy = RN.worldPtrTy props
507                  val wrldV = CL.mkVar "wrld"
508                  val stsV = CL.mkVar "sts"
509                fun bindKern (k, stms) =                fun bindKern (k, stms) =
510                      CL.mkAssign(                      CL.mkAssign(
511                        CL.mkIndirect(CL.mkVar "wrld", k),                        CL.mkIndirect(CL.mkVar "wrld", k),
512                        CL.mkApply("clCreateKernel", [                        CL.mkApply("clCreateKernel", [
513                            CL.mkIndirect(CL.mkVar "wrld", "prog"), CL.mkStr k, CL.mkAddrOf(CL.mkVar "sts")                            CL.mkIndirect(wrldV, "prog"), CL.mkStr k, CL.mkAddrOf(CL.mkVar "sts")
514                          ])) ::                          ])) ::
515                      CL.mkIfThen(CL.mkBinOp(CL.mkVar "sts", CL.#!=, CL.mkVar "CL_SUCCESS"),                      CL.mkIfThen(
516                          CL.mkApply("CheckOCLStatus", [wrldV, stsV, CL.mkStr("binding "^k)]),
517                        CL.mkReturn(SOME(CL.mkVar "true"))) ::                        CL.mkReturn(SOME(CL.mkVar "true"))) ::
518                      stms                      stms
519                val stms = List.foldr bindKern [CL.mkReturn(SOME(CL.mkVar "false"))] kernels                val stms = List.foldr bindKern [CL.mkReturn(SOME(CL.mkVar "false"))] kernels
# Line 629  Line 654 
654                    then ppDecl (CL.D_Verbatim ["#define DIDEROT_DUAL_STATE\n"])                    then ppDecl (CL.D_Verbatim ["#define DIDEROT_DUAL_STATE\n"])
655                    else ();                    else ();
656                (* generate the host-side type definitions *)                (* generate the host-side type definitions *)
                 ppDecl (CL.verbatimDcl [CShadowTypesFrag.text] substitutions);  
657                  ppDecl (CL.verbatimDcl [CSizesFrag.text] substitutions);                  ppDecl (CL.verbatimDcl [CSizesFrag.text] substitutions);
658                  List.app ppDecl (GenInputs.genDefinedInpStruct (props, !inputs));                  List.app ppDecl (GenInputs.genDefinedInpStruct (props, !inputs));
659                  ppDecl (genWorldStruct prog);                  ppDecl (genWorldStruct prog);

Legend:
Removed from v.3087  
changed lines
  Added in v.3088

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