Package ai.djl.ndarray
Interface NDResource
-
- All Superinterfaces:
java.lang.AutoCloseable
- All Known Subinterfaces:
LazyNDArray,NDArray,SparseNDArray
- All Known Implementing Classes:
NDArrayAdapter,NDList
public interface NDResource extends java.lang.AutoCloseableAn object which is managed by anNDManagerand tracks the manager it is attached to.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidattach(NDManager manager)Attaches thisNDResourceto the specifiedNDManager.voidclose()voiddetach()Detaches theNDResourcefrom currentNDManager's lifecycle.NDManagergetManager()Returns theNDManagerthat manages this.default voidreturnResource(NDManager manager)Attaches thisNDResourceto the specifiedNDManagerfrom which it was previously detached and temp-attached to the current manager of this resource.voidtempAttach(NDManager manager)Temporarily attaches thisNDResourceto the specifiedNDManager.
-
-
-
Method Detail
-
getManager
NDManager getManager()
Returns theNDManagerthat manages this.- Returns:
- the
NDManagerthat manages this.
-
attach
void attach(NDManager manager)
Attaches thisNDResourceto the specifiedNDManager.Attached resource will be closed when the
NDManageris closed.- Parameters:
manager- theNDManagerto be attached to
-
returnResource
default void returnResource(NDManager manager)
Attaches thisNDResourceto the specifiedNDManagerfrom which it was previously detached and temp-attached to the current manager of this resource. This is functionally equivalent to the attach method, however the cap-state disregarded when adding the resource back to the original manager.- Parameters:
manager- theNDManagerto be attached to
-
tempAttach
void tempAttach(NDManager manager)
Temporarily attaches thisNDResourceto the specifiedNDManager.Attached resource will be returned to the original manager when the
NDManageris closed.- Parameters:
manager- theNDManagerto be attached to
-
detach
void detach()
Detaches theNDResourcefrom currentNDManager's lifecycle.This becomes un-managed and it is the user's responsibility to close this. Failure to close the resource might cause your machine to run out of native memory.
- See Also:
NDManager
-
close
void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
-