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

SCM Repository

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

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

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

revision 1704, Tue Mar 6 15:44:37 2012 UTC revision 1705, Tue Mar 6 21:59:47 2012 UTC
# Line 165  Line 165 
165        }        }
166    
167      datatype program = Prog of {      datatype program = Prog of {
168          name : string,                  (* stem of source file *)          tgt : TargetUtil.target_desc,   (* info about target *)
         exec : bool,                    (* true for standalone program *)  
         double : bool,                  (* true for double-precision support *)  
         parallel : bool,                (* true for multithreaded (or multi-GPU) target *)  
         debug : bool,                   (* true for debug support in executable *)  
169          globals : mirror_var list ref,          globals : mirror_var list ref,
170          topDecls : CL.decl list ref,          topDecls : CL.decl list ref,
171          strands : strand AtomTable.hash_table,          strands : strand AtomTable.hash_table,
# Line 282  Line 278 
278    (* programs *)    (* programs *)
279      structure Program =      structure Program =
280        struct        struct
281          fun new {name, exec, double, parallel, debug} = (          fun new (tgt : TargetUtil.target_desc) = (
282                RN.initTargetSpec double;                RN.initTargetSpec (#double tgt);
283                CNames.initTargetSpec {double=double, long=false};                CNames.initTargetSpec {double = #double tgt, long = false};
284                Prog{                Prog{
285                    name = name,                    tgt = tgt,
                   exec = exec,  
                   double = double, parallel = parallel, debug = debug,  
286                    globals = ref [],                    globals = ref [],
287                    topDecls = ref [],                    topDecls = ref [],
288                    strands = AtomTable.mkTable (16, Fail "strand table"),                    strands = AtomTable.mkTable (16, Fail "strand table"),
# Line 333  Line 327 
327    
328        (* create and register the initially function for a program *)        (* create and register the initially function for a program *)
329          fun initially {          fun initially {
330                prog = Prog{name=progName, strands, initially,numDims, ...},                prog = Prog{strands, initially, numDims, ...},
331                isArray : bool,                isArray : bool,
332                iterPrefix : stm list,                iterPrefix : stm list,
333                iters : (var * exp * exp) list,                iters : (var * exp * exp) list,
# Line 455  Line 449 
449                  prFn                  prFn
450                end                end
451    
452          fun genStrandTyDef(targetTy,Strand{state,...},tyName) =          fun genStrandTyDef (targetTy,Strand{state,...}, tyName) = (case state
                 (case state  
453                     of [] => CL.D_Comment(["No Strand Defintiion Included"])                     of [] => CL.D_Comment(["No Strand Defintiion Included"])
454                      | _ => CL.D_StructDef(revmap (fn x => (targetTy x, #var x)) state,                  | _ => CL.D_StructDef(revmap (fn x => (targetTy x, #var x)) state, tyName)
                                         tyName)  
455                                   (* end case *))                                   (* end case *))
456    
   
   
457       (* generates the globals buffers and arguments function *)       (* generates the globals buffers and arguments function *)
458          fun genConvertShadowTypes (Strand{name, tyName, state,...}) = let          fun genConvertShadowTypes (Strand{name, tyName, state,...}) = let
459              (* Delcare opencl setup objects *)              (* Declare opencl setup objects *)
460                val errVar = "err"                val errVar = "err"
461                val params = [                val params = [
462                        CL.PARAM([], CL.T_Ptr(CL.T_Named tyName), "selfOut"),                        CL.PARAM([], CL.T_Ptr(CL.T_Named tyName), "selfOut"),
# Line 703  Line 693 
693    
694          fun genSrc (baseName, prog) = let          fun genSrc (baseName, prog) = let
695                val Prog{                val Prog{
696                        name, double, globals, topDecls, strands, initially,                        tgt={srcFile, double, ...},
697                          globals, topDecls, strands, initially,
698                        imgGlobals, numDims,outFn, ...                        imgGlobals, numDims,outFn, ...
699                      } = prog                      } = prog
700                val clFileName = OS.Path.joinBaseExt{base=baseName, ext=SOME "cl"}                val clFileName = OS.Path.joinBaseExt{base=baseName, ext=SOME "cl"}
# Line 712  Line 703 
703                val cOutS = TextIO.openOut cFileName                val cOutS = TextIO.openOut cFileName
704                val clppStrm = PrintAsCL.new clOutS                val clppStrm = PrintAsCL.new clOutS
705                val cppStrm = PrintAsC.new cOutS                val cppStrm = PrintAsC.new cOutS
               val progName = name  
706                fun cppDecl dcl = PrintAsC.output(cppStrm, dcl)                fun cppDecl dcl = PrintAsC.output(cppStrm, dcl)
707                fun clppDecl dcl = PrintAsCL.output(clppStrm, dcl)                fun clppDecl dcl = PrintAsCL.output(clppStrm, dcl)
708                val strands = AtomTable.listItems strands                val strands = AtomTable.listItems strands
# Line 752  Line 742 
742                      "#define DIDEROT_TARGET_CL\n",                      "#define DIDEROT_TARGET_CL\n",
743                      "#include \"Diderot/diderot.h\"\n"                      "#include \"Diderot/diderot.h\"\n"
744                    ]);                    ]);
745                  cppDecl (CL.D_Verbatim[                  case !globals
746                    (case !globals                   of [] => cppDecl (CL.D_Verbatim[concat["typedef void ", RN.globalsTy, ";\n"] ])
747                       of [] => concat["typedef void ", RN.globalsTy,";\n"]                    | _ => ()
748                        |  _ => ""                  (* end case *);
                      (*end of case*))  
                   ]);  
749                  cppDecl (CL.D_Var(["static"], CL.charPtr, "ProgramName",                  cppDecl (CL.D_Var(["static"], CL.charPtr, "ProgramName",
750                    SOME(CL.I_Exp(CL.mkStr progName))));                    SOME(CL.I_Exp(CL.mkStr srcFile))));
751                  cppDecl (genGlobalStruct (#hostTy, !globals, RN.globalsTy));                  cppDecl (genGlobalStruct (#hostTy, !globals, RN.globalsTy));
752                  cppDecl (genGlobalStruct (#shadowTy, !globals, RN.shadowGlobalsTy));                  cppDecl (genGlobalStruct (#shadowTy, !globals, RN.shadowGlobalsTy));
753  (* FIXME: does this really need to be a global? *)  (* FIXME: does this really need to be a global? *)
# Line 782  Line 770 
770                end                end
771    
772        (* output the code to the filesystem.  The string is the basename of the source file *)        (* output the code to the filesystem.  The string is the basename of the source file *)
773          fun generate (basename, prog as Prog{exec, double, parallel, debug, ...}) = let          fun generate (prog as Prog{tgt, ...}) = let
774                  val {outDir, outBase, exec, double, parallel, debug, ...} = tgt
775                fun condCons (true, x, xs) = x::xs                fun condCons (true, x, xs) = x::xs
776                  | condCons (false, _, xs) = xs                  | condCons (false, _, xs) = xs
777              (* generate the C compiler flags *)              (* generate the C compiler flags *)
# Line 801  Line 790 
790                        parallel = parallel, double = double, debug = debug                        parallel = parallel, double = double, debug = debug
791                      }                      }
792                val ldOpts = rtLib :: extraLibs                val ldOpts = rtLib :: extraLibs
793                  val basename = OS.Path.joinDirFile{dir=outDir, file=outBase}
794                in                in
795                  genSrc (basename, prog);                  genSrc (basename, prog);
796                  RunCC.compile (basename, cflags);                  RunCC.compile (basename, cflags);

Legend:
Removed from v.1704  
changed lines
  Added in v.1705

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