@@ -3,8 +3,7 @@ package is.hail.backend
33import is .hail .HailFeatureFlags
44import is .hail .annotations .{Region , RegionPool }
55import is .hail .asm4s .HailClassLoader
6- import is .hail .backend .local .LocalTaskContext
7- import is .hail .expr .ir .{BaseIR , CodeCacheKey , CompiledFunction }
6+ import is .hail .expr .ir .{BaseIR , CompileCache , Compiled }
87import is .hail .expr .ir .LoweredTableReader .LoweredTableReaderCoercer
98import is .hail .expr .ir .lowering .IrMetadata
109import is .hail .io .fs .FS
@@ -67,12 +66,12 @@ object ExecuteContext {
6766 flags : HailFeatureFlags ,
6867 irMetadata : IrMetadata ,
6968 blockMatrixCache : mutable.Map [String , BlockMatrix ],
70- codeCache : mutable. Map [ CodeCacheKey , CompiledFunction [_]] ,
69+ compileCache : CompileCache ,
7170 irCache : mutable.Map [Int , BaseIR ],
7271 coercerCache : mutable.Map [Any , LoweredTableReaderCoercer ],
7372 )(
7473 f : ExecuteContext => T
75- ): T = {
74+ ): T =
7675 RegionPool .scoped { pool =>
7776 pool.scopedRegion { region =>
7877 using(new ExecuteContext (
@@ -88,13 +87,12 @@ object ExecuteContext {
8887 flags,
8988 irMetadata,
9089 blockMatrixCache,
91- codeCache ,
90+ compileCache ,
9291 irCache,
9392 coercerCache,
9493 ))(f(_))
9594 }
9695 }
97- }
9896
9997 def createTmpPathNoCleanup (tmpdir : String , prefix : String , extension : String = null ): String = {
10098 val random = new SecureRandom ()
@@ -113,17 +111,17 @@ class ExecuteContext(
113111 val backend : Backend ,
114112 val references : Map [String , ReferenceGenome ],
115113 val fs : FS ,
116- val r : Region ,
114+ override val r : Region ,
117115 val timer : ExecutionTimer ,
118116 val tempFileManager : TempFileManager ,
119117 val theHailClassLoader : HailClassLoader ,
120118 val flags : HailFeatureFlags ,
121119 val irMetadata : IrMetadata ,
122120 val BlockMatrixCache : mutable.Map [String , BlockMatrix ],
123- val CodeCache : mutable. Map [ CodeCacheKey , CompiledFunction [_]] ,
121+ val CompileCache : CompileCache ,
124122 val PersistedIrCache : mutable.Map [Int , BaseIR ],
125123 val PersistedCoercerCache : mutable.Map [Any , LoweredTableReaderCoercer ],
126- ) extends Closeable {
124+ ) extends HailTaskContext with Closeable {
127125
128126 val rngNonce : Long =
129127 try
@@ -142,13 +140,14 @@ class ExecuteContext(
142140
143141 val memo : mutable.Map [Any , Any ] = new mutable.HashMap [Any , Any ]()
144142
145- val taskContext : HailTaskContext = new LocalTaskContext (0 , 0 )
143+ private [this ] val onCloseTasks = mutable.ArrayBuffer .empty[() => Unit ]
144+ override def onClose (f : () => Unit ): Unit = onCloseTasks += f
146145
147- def scopedExecution [ T ](
148- f : ( HailClassLoader , FS , HailTaskContext , Region ) => T
149- )( implicit E : Enclosing
150- ): T =
151- using( new LocalTaskContext ( 0 , 0 ))(tc => time(f(theHailClassLoader, fs, tc, r )))
146+ def run [ A ]( f : Compiled [ A ])( implicit E : Enclosing ) : A =
147+ time(f(theHailClassLoader, fs, this , r))
148+
149+ def scopedExecution [ T ]( f : Compiled [ T ])( implicit E : Enclosing ): T =
150+ r.pool.scopedRegion(r => local(r = r)(_.run(f )))
152151
153152 def createTmpPath (prefix : String , extension : String = null , local : Boolean = false ): String =
154153 tempFileManager.newTmpPath(if (local) localTmpdir else tmpdir, prefix, extension)
@@ -162,8 +161,8 @@ class ExecuteContext(
162161 def shouldLogIR (): Boolean = ! shouldNotLogIR()
163162
164163 override def close (): Unit = {
164+ onCloseTasks.foreach(_())
165165 tempFileManager.close()
166- taskContext.close()
167166 }
168167
169168 def time [A ](block : => A )(implicit E : Enclosing ): A =
@@ -182,7 +181,7 @@ class ExecuteContext(
182181 flags : HailFeatureFlags = this .flags,
183182 irMetadata : IrMetadata = this .irMetadata,
184183 blockMatrixCache : mutable.Map [String , BlockMatrix ] = this .BlockMatrixCache ,
185- codeCache : mutable. Map [ CodeCacheKey , CompiledFunction [_]] = this .CodeCache ,
184+ compileCache : CompileCache = this .CompileCache ,
186185 persistedIrCache : mutable.Map [Int , BaseIR ] = this .PersistedIrCache ,
187186 persistedCoercerCache : mutable.Map [Any , LoweredTableReaderCoercer ] = this .PersistedCoercerCache ,
188187 )(
@@ -201,7 +200,7 @@ class ExecuteContext(
201200 flags,
202201 irMetadata,
203202 blockMatrixCache,
204- codeCache ,
203+ compileCache ,
205204 persistedIrCache,
206205 persistedCoercerCache,
207206 ))(f)
0 commit comments