-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use singleton mlir context (#1454)
Co-authored-by: José Valim <[email protected]>
- Loading branch information
1 parent
bd346ab
commit 7b087da
Showing
21 changed files
with
214 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
defmodule EXLA.MLIR.ContextPool do | ||
@moduledoc false | ||
# Internal pool for MLIRContext reference management | ||
@behaviour NimblePool | ||
|
||
def checkout(fun) when is_function(fun, 1) do | ||
NimblePool.checkout!( | ||
__MODULE__, | ||
:checkout, | ||
fn _pool, context -> {fun.(context), :ok} end, | ||
:infinity | ||
) | ||
end | ||
|
||
@impl NimblePool | ||
def init_worker(pool_state) do | ||
{:ok, context} = EXLA.NIF.new_mlir_context() | ||
{:ok, context, pool_state} | ||
end | ||
|
||
@impl NimblePool | ||
def handle_checkout(:checkout, _from, context, pool_state) do | ||
{:ok, context, context, pool_state} | ||
end | ||
|
||
@impl NimblePool | ||
def handle_checkin(:ok, _from, context, pool_state) do | ||
# We just keep the references around and let them die out upon worker termination/GC | ||
{:ok, context, pool_state} | ||
end | ||
|
||
@impl NimblePool | ||
def terminate_worker(_reason, _context, pool_state) do | ||
# GC will clean it up | ||
{:ok, pool_state} | ||
end | ||
end |
Oops, something went wrong.