Scope

final class Scope

Faciliates memory management of off-heap data structures.

Tracks allocations of aten.Tensor and aten.TensorOption instances.

aten.Tensor and aten.TensorOption instances are not freed up by the garbage collector. Lamp implements zoned memory management around these object. The managed counterpart of aten.Tensor is lamp.STen, while for aten.TensorOption it is lamp.STenOptions.

One can only create a lamp.STen instance with a lamp.Scope in implicit scope.

Create new scopes with lamp.Scope.root, lamp.Scope.apply or lamp.Scope.root.

=Examples=

// Scope.root returns Unit
Scope.root { implicit scope =>
   val sum = Scope { implicit scope =>
   // Intermediate values allocated in this block (`ident` and `ones`) are freed when
   // this block returns
   // The return value (`ident + ones`) of this block is moved to the outer scope
   val ident = STen.eye(3, STenOptions.d)
   val ones = STen.ones(List(3, 3), STenOptions.d)
   ident + ones
   }
   assert(sum.toMat == mat.ones(3, 3) + mat.ident(3))
   // `sum` is freed once this block exits
}
Companion:
object
class Object
trait Matchable
class Any

Type members

Types

type ResourceType = Either[Tensor, TensorOptions]

Value members

Concrete methods

def apply(resource: Tensor): Tensor

Adds a resource to the managed resources, then returns it unchanged.

Adds a resource to the managed resources, then returns it unchanged.

The resources will be released when this Scope goes out of scope or otherwise releases.

def apply(resource: TensorOptions): TensorOptions

Adds a resource to the managed resources, then returns it unchanged.

Adds a resource to the managed resources, then returns it unchanged.

The resources will be released when this Scope goes out of scope or otherwise releases.

def register(resource: Tensor): Unit

Adds a resource to the managed resources.

Adds a resource to the managed resources.

The resources will be released when this Scope goes out of scope or otherwise releases.

def register(resource: TensorOptions): Unit

Adds a resource to the managed resources.

Adds a resource to the managed resources.

The resources will be released when this Scope goes out of scope or otherwise releases.

def release(): Unit

Immediately release the resources managed by this Scope

Immediately release the resources managed by this Scope