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 2725, Wed Sep 24 12:22:21 2014 UTC revision 2726, Wed Sep 24 19:12:59 2014 UTC
# Line 36  Line 36 
36          props : props,                  (* info about target *)          props : props,                  (* info about target *)
37          inputs : GenInputs.input_desc list ref,          inputs : GenInputs.input_desc list ref,
38          globals : global_var list ref,          globals : global_var list ref,
39            kernels : string list ref,      (* a list of the OpenCL kernels used by this program *)
40          topCDecls : CL.decl list ref,   (* top-level decls for the C file *)          topCDecls : CL.decl list ref,   (* top-level decls for the C file *)
41          topOCLDecls : CL.decl list ref, (* top-level decls for the OpenCL file *)          topOCLDecls : CL.decl list ref, (* top-level decls for the OpenCL file *)
42          strands : strand AtomTable.hash_table,          strands : strand AtomTable.hash_table,
# Line 260  Line 261 
261                    props = Properties.mkProps (tgt, props),                    props = Properties.mkProps (tgt, props),
262                    inputs = ref [],                    inputs = ref [],
263                    globals = ref [],                    globals = ref [],
264                      kernels = ref [],
265                    topCDecls = ref [],                    topCDecls = ref [],
266                    topOCLDecls = ref [],                    topOCLDecls = ref [],
267                    strands = AtomTable.mkTable (16, Fail "strand table"),                    strands = AtomTable.mkTable (16, Fail "strand table"),
268                    nAxes = ref(SOME ~1),                    nAxes = ref(SOME ~1),
269                    initially = ref(CL.D_Comment["missing initially"])                    initially = ref(CL.D_Comment["missing initially"])
270                  })                  })
 (* FIXME: for standalone exes, the defaults should be set in the inputs struct;  
  * not sure how to handle library inputs yet.  
  *)  
 (* DEPRECATED  
       (* register the code that is used to set defaults for input variables *)  
         fun inputs (Prog{props, inputs, topCDecls, ...}, env, blk) = let  
               val worldTy = CL.T_Ptr(CL.T_Named(N.worldTy props))  
               val globTy = CL.T_Ptr(CL.T_Named(N.globalTy props))  
               val body = CL.mkBlock(  
                     CL.mkDeclInit(globTy, "glob", CL.mkIndirect(CL.mkVar "wrld", "globals")) ::  
                     CL.unBlock (Tr.block (env, blk)))  
               val inputsFn = CL.D_Func(  
                     ["static"], CL.voidTy, N.initDefaults,  
                     [CL.PARAM([], worldTy, "wrld")],  
                     body)  
               in  
                 inputs := GenInputs.gatherInputs blk;  
                 topCDecls := inputsFn :: !topCDecls  
               end  
 *)  
271        (* gather the inputs *)        (* gather the inputs *)
272          fun inputs (Prog{inputs, ...}, env, blk) = inputs := GenInputs.gatherInputs blk          fun inputs (Prog{inputs, ...}, env, blk) = inputs := GenInputs.gatherInputs blk
273        (* register the global initialization part of a program *)        (* register the global initialization part of a program *)
# Line 419  Line 401 
401          fun mkSubs (props : props, Strand{name, tyName, ...}) = [          fun mkSubs (props : props, Strand{name, tyName, ...}) = [
402                  ("CFILE",       OS.Path.joinBaseExt{base= #outBase props, ext= SOME "c"}),                  ("CFILE",       OS.Path.joinBaseExt{base= #outBase props, ext= SOME "c"}),
403                  ("HDRFILE",     OS.Path.joinBaseExt{base= #outBase props, ext= SOME "h"}),                  ("HDRFILE",     OS.Path.joinBaseExt{base= #outBase props, ext= SOME "h"}),
404                    ("CLFILE",      OS.Path.joinBaseExt{base= #outBase props, ext= SOME "cl"}),
405                  ("PREFIX",      #namespace props),                  ("PREFIX",      #namespace props),
406                  ("SRCFILE",     #srcFile props),                  ("SRCFILE",     #srcFile props),
407                  ("STRAND",      name),                  ("STRAND",      name),
408                  ("STRANDTY",    tyName)                  ("STRANDTY",    tyName),
409                    ("DIDEROT_FLOAT_PRECISION", Properties.floatPrecisionDef props),
410                    ("DIDEROT_INT_PRECISION", Properties.intPrecisionDef props),
411                    ("DIDEROT_TARGET", Properties.targetDef props)
412                ]                ]
413    
414          fun condCons (true, x, xs) = x::xs          fun condCons (true, x, xs) = x::xs
# Line 478  Line 464 
464          local          local
465            fun genField (projTy : global_var -> CL.ty) gv = (projTy gv, #name gv)            fun genField (projTy : global_var -> CL.ty) gv = (projTy gv, #name gv)
466          in          in
467        (* generate a C struct definition that describes the GPU representation of the globals *)        (* generate a C struct definition that describes the GPU representation of the globals;
468           * this structure is used to  *)
469          fun genGlobalShadowStruct [] = []          fun genGlobalShadowStruct [] = []
470            | genGlobalShadowStruct globals = [            | genGlobalShadowStruct globals = [
471                  CL.D_StructDef(                  CL.D_StructDef(
# Line 558  Line 545 
545                TextIO.closeOut outS)                TextIO.closeOut outS)
546    
547        (* generate the OpenCL source code. *)        (* generate the OpenCL source code. *)
548          fun outputCLSrc (out : output, prog as Prog{props, strands, nAxes, globals, ...}) = let          fun outputCLSrc (out : output, prog, strand, substitutions) = let
549                val [strand as Strand{output, ...}] = AtomTable.listItems strands                val Prog{props, nAxes, globals, ...} = prog
550                  val Strand{output, ...} = strand
551                val outputs = GenOutput.genKernels (props, !nAxes) output                val outputs = GenOutput.genKernels (props, !nAxes) output
552                fun ppDecl dcl = PrintAsCL.output(#ppStrm out, dcl)                fun ppDecl dcl = PrintAsCL.output(#ppStrm out, dcl)
553                in                in
554                (* Retrieve the header information *)                (* Retrieve the header information *)
555                  ppDecl (CL.verbatimDcl [CLHeadFrag.text] [                  ppDecl (CL.verbatimDcl [CLHeadFrag.text] substitutions);
                     ("CLFILE", #file out),  
                     ("SRCFILE", #srcFile props),  
                     ("DIDEROT_FLOAT_PRECISION", Properties.floatPrecisionDef props),  
                     ("DIDEROT_INT_PRECISION", Properties.intPrecisionDef props)  
                   ]);  
556  (* FIXME: check to see if we really need the DUAL_STATE define for OpenCL *)  (* FIXME: check to see if we really need the DUAL_STATE define for OpenCL *)
557                  if Properties.dualState props                  if Properties.dualState props
558                    then ppDecl (CL.D_Verbatim ["#define DIDEROT_DUAL_STATE\n"])                    then ppDecl (CL.D_Verbatim ["#define DIDEROT_DUAL_STATE\n"])
559                    else ();                    else ();
560                (* type definitions *)                (* type definitions *)
561                  List.app ppDecl (genGlobalStruct (!globals));                  List.app ppDecl (genGlobalStruct (!globals));
562                  ppDecl (genWorldStruct(prog, strand));                (* kernel for computing sizes of runtime data structures *)
563                    ppDecl (CL.verbatimDcl [CLSizesFrag.text] substitutions);
564                (* Specialize the scheduler kernels and functions *)                (* Specialize the scheduler kernels and functions *)
565                  ppDecl (CL.D_Verbatim[CLSchedFrag.text]);                  ppDecl (CL.D_Verbatim[CLSchedFrag.text]);
566  (* FIXME: should only include eigen code fragments if they are being used! *)  (* FIXME: should only include eigen code fragments if they are being used! *)
# Line 588  Line 572 
572                  List.app ppDecl outputs                  List.app ppDecl outputs
573                end                end
574    
575          fun outputLibSrc (out : output, prog as Prog{        (* output common C source that is common to both the library and standalone targets *)
576                  props, inputs, globals, topCDecls, strands, nAxes, initially, ...          fun outputCSrc (out : output, prog, strand, substitutions) = let
577                }) = let                val Prog{props, nAxes, inputs, globals, ...} = prog
               val [strand as Strand{name, tyName, state, output, ...}] = AtomTable.listItems strands  
               val outputs = GenOutput.gen (props, !nAxes) output  
               val substitutions = mkSubs (props, strand)  
578                fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)                fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)
579                in                in
                 ppDecl (CL.verbatimDcl [CHeadFrag.text] substitutions);  
580                  if Properties.dualState props                  if Properties.dualState props
581                    then ppDecl (CL.D_Verbatim ["#define DIDEROT_DUAL_STATE\n"])                    then ppDecl (CL.D_Verbatim ["#define DIDEROT_DUAL_STATE\n"])
582                    else ();                    else ();
583                (* generate the type definitions *)                (* generate the host-side type definitions *)
584                  ppDecl (CL.verbatimDcl [CShadowTypesFrag.text] substitutions);                  ppDecl (CL.verbatimDcl [CShadowTypesFrag.text] substitutions);
585                  List.app ppDecl (genGlobalShadowStruct (!globals));                  List.app ppDecl (genGlobalShadowStruct (!globals));
586                  ppDecl (genWorldStruct(prog, strand));                  ppDecl (genWorldStruct(prog, strand));
587                  ppDecl (GenInputs.genInputsStruct (props, !inputs));                  ppDecl (GenInputs.genInputsStruct (props, !inputs));
588                    ppDecl (CL.verbatimDcl [CSizesFrag.text] substitutions);
589                (* support code for OpenCL *)                (* support code for OpenCL *)
590                  ppDecl (CL.verbatimDcl [                  ppDecl (CL.verbatimDcl [
591                      COpenCLErrFrag.text,                      COpenCLErrFrag.text,
592                      CCheckCLStatusFrag.text                      CCheckCLStatusFrag.text
593                    ] substitutions);                    ] substitutions)
594                  end
595    
596            fun outputLibSrc (out : output, prog, strand, substitutions) = let
597                  val Prog{props, inputs, globals, topCDecls, nAxes, initially, ...} = prog
598                  val Strand{output, ...} = strand
599                  val outputs = GenOutput.gen (props, !nAxes) output
600                  fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)
601                  in
602                    ppDecl (CL.verbatimDcl [CHeadFrag.text] substitutions);
603                    outputCSrc (out, prog, strand, substitutions);
604                  List.app ppDecl (GenInputs.genInputFuns(props, !inputs));                  List.app ppDecl (GenInputs.genInputFuns(props, !inputs));
605                  List.app ppDecl (!topCDecls);                  List.app ppDecl (!topCDecls);
606                  List.app ppDecl (genStrand strand);                  List.app ppDecl (genStrand strand);
# Line 625  Line 616 
616    
617          fun generateLib (prog as Prog{props, inputs, strands, ...}) = let          fun generateLib (prog as Prog{props, inputs, strands, ...}) = let
618                val {outDir, outBase, exec, double, parallel, debug, ...} = props                val {outDir, outBase, exec, double, parallel, debug, ...} = props
619                  val [strand] = AtomTable.listItems strands
620                val basename = OS.Path.joinDirFile{dir=outDir, file=outBase}                val basename = OS.Path.joinDirFile{dir=outDir, file=outBase}
621                val [Strand{state, output, ...}] = AtomTable.listItems strands                val [Strand{state, output, ...}] = AtomTable.listItems strands
622                val {cOut, oclOut} = openOut basename                val {cOut, oclOut} = openOut basename
623                  val substitutions = mkSubs(props, strand)
624                in                in
625                (* generate the library .h file *)                (* generate the library .h file *)
626                  GenLibraryInterface.gen {                  GenLibraryInterface.gen {
# Line 636  Line 629 
629                      inputs = !inputs,                      inputs = !inputs,
630                      outputs = output                      outputs = output
631                    };                    };
632                (* *)                (* generate source code *)
633                  outputLibSrc (cOut, prog);                  outputLibSrc (cOut, prog, strand, substitutions);
634                  outputCLSrc (oclOut, prog);                  outputCLSrc (oclOut, prog, strand, substitutions);
635                (* close the output streams *)                (* close the output streams *)
636                  closeOut cOut;                  closeOut cOut;
637                  closeOut oclOut;                  closeOut oclOut;
# Line 647  Line 640 
640                  RunCC.linkLib (basename, ldFlags props)                  RunCC.linkLib (basename, ldFlags props)
641                end                end
642    
643          fun outputExecSrc (out : output, prog) = let          fun outputExecSrc (out : output, prog, strand, substitutions) = let
644                val Prog{props, inputs, globals, topCDecls, strands, nAxes, initially, ...} = prog                val Prog{props, inputs, globals, topCDecls, strands, nAxes, initially, ...} = prog
645                val [strand as Strand{name, tyName, state, output, ...}] = AtomTable.listItems strands                val Strand{output, ...} = strand
646                val outputs = GenOutput.gen (props, !nAxes) output                val outputs = GenOutput.gen (props, !nAxes) output
               val substitutions =  
                     ("DIDEROT_FLOAT_PRECISION", Properties.floatPrecisionDef props) ::  
                     ("DIDEROT_INT_PRECISION", Properties.intPrecisionDef props) ::  
                     ("DIDEROT_TARGET", Properties.targetDef props) ::  
                     mkSubs (props, strand)  
647                fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)                fun ppDecl dcl = PrintAsC.output(#ppStrm out, dcl)
648                in                in
649                  ppDecl (CL.verbatimDcl [ExecHdrFrag.text] substitutions);                  ppDecl (CL.verbatimDcl [ExecHdrFrag.text] substitutions);
650                  if Properties.dualState props                  outputCSrc (out, prog, strand, substitutions);
                   then ppDecl (CL.D_Verbatim ["#define DIDEROT_DUAL_STATE\n"])  
                   else ();  
               (* generate the type definitions *)  
                 ppDecl (CL.verbatimDcl [CShadowTypesFrag.text] substitutions);  
                 List.app ppDecl (genGlobalShadowStruct (!globals));  
                 ppDecl (genWorldStruct(prog, strand));  
                 ppDecl (GenInputs.genInputsStruct (props, !inputs));  
               (* support code for OpenCL *)  
                 ppDecl (CL.verbatimDcl [  
                     COpenCLErrFrag.text,  
                     CCheckCLStatusFrag.text  
                   ] substitutions);  
651                  List.app ppDecl (GenInputs.genExecInputFuns (props, !inputs));                  List.app ppDecl (GenInputs.genExecInputFuns (props, !inputs));
652                  List.app ppDecl (!topCDecls);                  List.app ppDecl (!topCDecls);
653                  List.app ppDecl (genStrand strand);                  List.app ppDecl (genStrand strand);
# Line 688  Line 664 
664        (* output the code to a file.  The string is the basename of the file, the extension        (* output the code to a file.  The string is the basename of the file, the extension
665         * is provided by the target.         * is provided by the target.
666         *)         *)
667          fun generateExec (prog as Prog{props, ...}) = let          fun generateExec (prog as Prog{props, strands, ...}) = let
668                val {outDir, outBase, exec, double, parallel, debug, ...} = props                val {outDir, outBase, exec, double, parallel, debug, ...} = props
669                  val [strand] = AtomTable.listItems strands
670                val basename = OS.Path.joinDirFile{dir=outDir, file=outBase}                val basename = OS.Path.joinDirFile{dir=outDir, file=outBase}
671                val {cOut, oclOut} = openOut basename                val {cOut, oclOut} = openOut basename
672                  val substitutions = mkSubs(props, strand)
673                in                in
674                  outputExecSrc (cOut, prog);                  outputExecSrc (cOut, prog, strand, substitutions);
675                  outputCLSrc (oclOut, prog);                  outputCLSrc (oclOut, prog, strand, substitutions);
676                (* close the output streams *)                (* close the output streams *)
677                  closeOut cOut;                  closeOut cOut;
678                  closeOut oclOut;                  closeOut oclOut;

Legend:
Removed from v.2725  
changed lines
  Added in v.2726

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