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

SCM Repository

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

Diff of /branches/pure-cfg/src/compiler/cl-target/cl-target.sml

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

revision 1312, Sat Jun 11 14:48:04 2011 UTC revision 1313, Sat Jun 11 16:57:31 2011 UTC
# Line 64  Line 64 
64      type stm = CL.stm      type stm = CL.stm
65    
66    (* OpenCL specific types *)    (* OpenCL specific types *)
67        val clIntTy = CL.T_Named "cl_int"
68      val clProgramTy = CL.T_Named "cl_program"      val clProgramTy = CL.T_Named "cl_program"
69      val clKernelTy  = CL.T_Named "cl_kernel"      val clKernelTy  = CL.T_Named "cl_kernel"
70      val clCmdQueueTy = CL.T_Named "cl_command_queue"      val clCmdQueueTy = CL.T_Named "cl_command_queue"
# Line 71  Line 72 
72      val clDeviceIdTy = CL.T_Named "cl_device_id"      val clDeviceIdTy = CL.T_Named "cl_device_id"
73      val clPlatformIdTy = CL.T_Named "cl_platform_id"      val clPlatformIdTy = CL.T_Named "cl_platform_id"
74      val clMemoryTy = CL.T_Named "cl_mem"      val clMemoryTy = CL.T_Named "cl_mem"
75        val globPtrTy = CL.T_Ptr(CL.T_Named RN.globalsTy)
76    
77    (* variable or field that is mirrored between host and GPU *)    (* variable or field that is mirrored between host and GPU *)
78      type mirror_var = {      type mirror_var = {
# Line 147  Line 149 
149                  print(concat["saveState ", cxt, ": length mismatch; ", Int.toString(List.length args), " args\n"]);                  print(concat["saveState ", cxt, ": length mismatch; ", Int.toString(List.length args), " args\n"]);
150                  raise Fail(concat["saveState ", cxt, ": length mismatch"]))                  raise Fail(concat["saveState ", cxt, ": length mismatch"]))
151          fun block (ENV{vMap, scope, ...}, blk) = (case scope          fun block (ENV{vMap, scope, ...}, blk) = (case scope
152                 of StrandScope stateVars => ToCL.trBlock (vMap, saveState "StrandScope" stateVars, blk)  (* NOTE: if we move strand initialization to the GPU, then we'll have to change the following line! *)
153                   of StrandScope stateVars => ToC.trBlock (vMap, saveState "StrandScope" stateVars, blk)
154                  | MethodScope stateVars => ToCL.trBlock (vMap, saveState "MethodScope" stateVars, blk)                  | MethodScope stateVars => ToCL.trBlock (vMap, saveState "MethodScope" stateVars, blk)
155                  | InitiallyScope => ToCL.trBlock (vMap, fn (_, _, stm) => [stm], blk)                  | InitiallyScope => ToCL.trBlock (vMap, fn (_, _, stm) => [stm], blk)
156                  | _ => ToC.trBlock (vMap, fn (_, _, stm) => [stm], blk)                  | _ => ToC.trBlock (vMap, fn (_, _, stm) => [stm], blk)
# Line 243  Line 246 
246    
247        (* register the global initialization part of a program *)        (* register the global initialization part of a program *)
248          fun init (Prog{topDecls, ...}, init) = let          fun init (Prog{topDecls, ...}, init) = let
               val globPtrTy = CL.T_Ptr(CL.T_Named RN.globalsTy)  
249                val initFn = CL.D_Func(                val initFn = CL.D_Func(
250                      [], CL.voidTy, RN.initGlobals, [CL.PARAM([], globPtrTy, RN.globalsVarName)],                      [], CL.voidTy, RN.initGlobals, [CL.PARAM([], globPtrTy, RN.globalsVarName)],
251                      init)                      init)
# Line 456  Line 458 
458                        CL.PARAM([],CL.T_Named("cl_kernel"), "kernel"),                        CL.PARAM([],CL.T_Named("cl_kernel"), "kernel"),
459                        CL.PARAM([],CL.T_Named("int"), "argStart")                        CL.PARAM([],CL.T_Named("int"), "argStart")
460                      ]                      ]
461                val clGlobalBuffers = getGlobalDataBuffers(!imgGlobals, "context", "err")                val clGlobalBuffers = getGlobalDataBuffers(!imgGlobals, "context", errVar)
462                val clGlobalArguments = genGlobalArguments(!imgGlobals, "argStart", "kernel", "err")                val clGlobalArguments = genGlobalArguments(!imgGlobals, "argStart", "kernel", errVar)
463              (* Body put all the statments together *)              (* Body put all the statments together *)
464                val body =  clGlobalBuffers @ clGlobalArguments                val body = CL.mkDecl(clIntTy, errVar, SOME(CL.I_Exp(CL.mkInt(0, CL.intTy))))
465                        :: clGlobalBuffers @ clGlobalArguments
466                in                in
467    (* FIXME: we ought to check the error condition! *)
468                  CL.D_Func([],CL.voidTy,RN.globalsSetupName,params,CL.mkBlock(body))                  CL.D_Func([],CL.voidTy,RN.globalsSetupName,params,CL.mkBlock(body))
469                end                end
470    
# Line 560  Line 564 
564                val cFileName = OS.Path.joinBaseExt{base=baseName, ext=SOME "c"}                val cFileName = OS.Path.joinBaseExt{base=baseName, ext=SOME "c"}
565                val clOutS = TextIO.openOut clFileName                val clOutS = TextIO.openOut clFileName
566                val cOutS = TextIO.openOut cFileName                val cOutS = TextIO.openOut cFileName
 (* FIXME: need to use PrintAsC and PrintAsCL *)  
567                val clppStrm = PrintAsCL.new clOutS                val clppStrm = PrintAsCL.new clOutS
568                val cppStrm = PrintAsC.new cOutS                val cppStrm = PrintAsC.new cOutS
569                fun cppDecl dcl = PrintAsC.output(cppStrm, dcl)                fun cppDecl dcl = PrintAsC.output(cppStrm, dcl)
# Line 581  Line 584 
584                  clppDecl (genStrandTyDef(#gpuTy, strand));                  clppDecl (genStrandTyDef(#gpuTy, strand));
585                  List.app clppDecl (!code);                  List.app clppDecl (!code);
586                  clppDecl (genKernelFun (strand, !numDims, globals, imgGlobals));                  clppDecl (genKernelFun (strand, !numDims, globals, imgGlobals));
   
587                (* Generate the Host C file *)                (* Generate the Host C file *)
588                  cppDecl (CL.D_Verbatim([                  cppDecl (CL.D_Verbatim([
589                      if double                      if double
# Line 661  Line 663 
663          fun init (Strand{name, tyName, code, init_code, ...}, params, init) = let          fun init (Strand{name, tyName, code, init_code, ...}, params, init) = let
664                val fName = RN.strandInit name                val fName = RN.strandInit name
665                val params =                val params =
666                        CL.PARAM([], globPtrTy, RN.globalsVarName) ::
667                      CL.PARAM([], CL.T_Ptr(CL.T_Named tyName), "selfOut") ::                      CL.PARAM([], CL.T_Ptr(CL.T_Named tyName), "selfOut") ::
668                        List.map (fn (ToCL.V(ty, x)) => CL.PARAM([], ty, x)) params                        List.map (fn (ToCL.V(ty, x)) => CL.PARAM([], ty, x)) params
669                val initFn = CL.D_Func([], CL.voidTy, fName, params, init)                val initFn = CL.D_Func([], CL.voidTy, fName, params, init)

Legend:
Removed from v.1312  
changed lines
  Added in v.1313

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