final class Scope extends AnyRef
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 }
- Alphabetic
- By Inheritance
- Scope
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- type ResourceType = Either[Tensor, TensorOptions]
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- 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 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.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @IntrinsicCandidate() @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @IntrinsicCandidate() @native()
- 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 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 release(): Unit
Immediately release the resources managed by this Scope
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)