Beaver.MLIR.ThreadPool (beaver v0.4.8)

Copy Markdown

Owns an LLVM thread pool that can be shared by multiple MLIR contexts.

The application starts one pool under default_name/0. MLIR.Context.create/1 checks out a lease from it by default and returns the lease when the context is destroyed. Calling close/1 while contexts are attached defers native pool destruction until the final lease is returned.

If an owner is forcibly terminated while leases remain, the native pool is deliberately retained so attached MLIR contexts never hold a dangling pool pointer. Use close/1 for deterministic reclamation.

An explicit owner can be selected with thread_pool: owner, or a raw Beaver.MLIR.LLVMThreadPool can be supplied when its lifetime is managed by the caller.

Summary

Functions

Returns a specification to start this module under a supervisor.

Closes the owner. Returns :deferred if attached contexts still hold leases.

Create a caller-owned native pool for use with MLIR.Context.create/1.

Destroy a caller-owned native pool after all attached contexts are gone.

Functions

checkin(owner \\ Beaver.MLIR.ThreadPool, lease)

@spec checkin(GenServer.server(), reference()) :: :ok

checkout(owner \\ Beaver.MLIR.ThreadPool)

@spec checkout(GenServer.server()) ::
  {Beaver.MLIR.LLVMThreadPool.t(), reference()} | {:error, :closing}

child_spec(init_arg)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a specification to start this module under a supervisor.

See Supervisor.

close(owner \\ Beaver.MLIR.ThreadPool)

@spec close(GenServer.server()) :: :ok | :deferred

Closes the owner. Returns :deferred if attached contexts still hold leases.

create()

@spec create() :: Beaver.MLIR.LLVMThreadPool.t()

Create a caller-owned native pool for use with MLIR.Context.create/1.

default_name()

@spec default_name() :: module()

destroy(pool)

@spec destroy(Beaver.MLIR.LLVMThreadPool.t()) :: :ok

Destroy a caller-owned native pool after all attached contexts are gone.

max_concurrency(owner \\ Beaver.MLIR.ThreadPool)

pool(owner \\ Beaver.MLIR.ThreadPool)

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()