Class ArrayCacheMemoryMgr
- java.lang.Object
-
- org.nd4j.autodiff.samediff.internal.memory.AbstractMemoryMgr
-
- org.nd4j.autodiff.samediff.internal.memory.ArrayCacheMemoryMgr
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,SessionMemMgr
public class ArrayCacheMemoryMgr extends AbstractMemoryMgr
-
-
Constructor Summary
Constructors Constructor Description ArrayCacheMemoryMgr()
Create an ArrayCacheMemoryMgr with default settings as perArrayCacheMemoryMgr
ArrayCacheMemoryMgr(double maxMemFrac, long smallArrayThreshold, double largerArrayMaxMultiple)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description INDArray
allocate(boolean detached, DataType dataType, long... shape)
Allocate an array with the specified datatype and shape.
NOTE: This array should be assumed to be uninitialized - i.e., contains random values.INDArray
allocate(boolean detached, LongShapeDescriptor descriptor)
As perSessionMemMgr.allocate(boolean, DataType, long...)
but from a LongShapeDescriptor insteadvoid
close()
Close the session memory manager and clean up any memory / resources, if anyvoid
release(@NonNull INDArray array)
Release the array.-
Methods inherited from class org.nd4j.autodiff.samediff.internal.memory.AbstractMemoryMgr
dup, ulike
-
-
-
-
Constructor Detail
-
ArrayCacheMemoryMgr
public ArrayCacheMemoryMgr()
Create an ArrayCacheMemoryMgr with default settings as perArrayCacheMemoryMgr
-
ArrayCacheMemoryMgr
public ArrayCacheMemoryMgr(double maxMemFrac, long smallArrayThreshold, double largerArrayMaxMultiple)
- Parameters:
maxMemFrac
- Maximum memory fraction to use as cachesmallArrayThreshold
- Below this size (elements), don't apply the "largerArrayMaxMultiple" rulelargerArrayMaxMultiple
- Maximum multiple of the requested size to return from the cache. If an array of size 1024 is requested, and largerArrayMaxMultiple is 2.0, then we'll return from the cache the array with the smallest data buffer up to 2.0*1024 elements; otherwise we'll return a new array
-
-
Method Detail
-
allocate
public INDArray allocate(boolean detached, DataType dataType, long... shape)
Description copied from interface:SessionMemMgr
Allocate an array with the specified datatype and shape.
NOTE: This array should be assumed to be uninitialized - i.e., contains random values.- Parameters:
detached
- If true: the array is safe to return outside of the SameDiff session run (for example, the array is one that may be returned to the user)dataType
- Datatype of the returned arrayshape
- Array shape- Returns:
- The newly allocated (uninitialized) array
-
allocate
public INDArray allocate(boolean detached, LongShapeDescriptor descriptor)
Description copied from interface:SessionMemMgr
As perSessionMemMgr.allocate(boolean, DataType, long...)
but from a LongShapeDescriptor instead
-
release
public void release(@NonNull @NonNull INDArray array)
Description copied from interface:SessionMemMgr
Release the array. All arrays allocated via one of the allocate methods should be returned here once they are no longer used, and all references to them should be cleared. After calling release, anything could occur to the array - deallocated, workspace closed, reused, etc.- Parameters:
array
- The array that can be released
-
close
public void close()
Description copied from interface:SessionMemMgr
Close the session memory manager and clean up any memory / resources, if any
-
-