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.leak.
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
- All
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( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @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
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @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(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()