Package org.nd4j.linalg.api.memory
Class BasicMemoryManager
- java.lang.Object
-
- org.nd4j.linalg.api.memory.BasicMemoryManager
-
- All Implemented Interfaces:
MemoryManager
public abstract class BasicMemoryManager extends Object implements MemoryManager
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicIntegeraverageLoopTimeprotected AtomicBooleanaveragingEnabledprotected AtomicLongfreqCounterprotected AtomicIntegerfrequencyprotected Queue<Integer>intervalsprotected static intintervalTailprotected AtomicLonglastGcTimeprotected AtomicIntegernoGcWindowprotected AtomicBooleanperiodicEnabled
-
Constructor Summary
Constructors Constructor Description BasicMemoryManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.bytedeco.javacpp.Pointerallocate(long bytes, MemoryKind kind, boolean initialize)This method returns PLEASE NOTE: Cache options depend on specific implementationsvoidcollect(INDArray... arrays)This method detaches off-heap memory from passed INDArray instances, and optionally stores them in cache for future reuse PLEASE NOTE: Cache options depend on specific implementationsintgetAutoGcWindow()This method reutrnsintgetAverageLoopTime()This method returns average time between invokeGCOccasionally() callsMemoryWorkspacegetCurrentWorkspace()longgetLastGcTime()This method returns time (in milliseconds) of the las System.gc() callintgetOccasionalGcFrequency()This method returnsvoidinvokeGc()This method calls for GC.voidinvokeGcOccasionally()This method calls for GC, and if frequency is met - System.gc() will be calledbooleanisPeriodicGcActive()This method returns true, if periodic GC is active.voidmemcpy(DataBuffer dstBuffer, DataBuffer srcBuffer)This method does memcpy from source buffer to destination buffer PLEASE NOTE: This method is NOT safe.voidnotifyScopeEntered()PLEASE NOTE: This method is under development yet.voidnotifyScopeLeft()PLEASE NOTE: This method is under development yet.voidpurgeCaches()This method purges all cached memory chunksvoidreleaseCurrentContext()This method releases Context (if current backend has one, sure)MemoryWorkspacescopeOutOfWorkspaces()This method temporary opens block out of any workspace scope.voidsetAutoGcWindow(int windowMillis)This method enables/disables periodic System.gc() calls.voidsetCurrentWorkspace(MemoryWorkspace workspace)voidsetOccasionalGcFrequency(int frequency)Sets manual GC invocation frequency.voidtoggleAveraging(boolean enabled)This method enables/disables calculation of average time spent within loops Default: falsevoidtogglePeriodicGc(boolean enabled)This method enables/disables periodic GC-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nd4j.linalg.api.memory.MemoryManager
allocatedMemory, getBandwidthUse, memset, release
-
-
-
-
Field Detail
-
frequency
protected AtomicInteger frequency
-
freqCounter
protected AtomicLong freqCounter
-
lastGcTime
protected AtomicLong lastGcTime
-
periodicEnabled
protected AtomicBoolean periodicEnabled
-
averageLoopTime
protected AtomicInteger averageLoopTime
-
noGcWindow
protected AtomicInteger noGcWindow
-
averagingEnabled
protected AtomicBoolean averagingEnabled
-
intervalTail
protected static final int intervalTail
- See Also:
- Constant Field Values
-
-
Method Detail
-
allocate
public org.bytedeco.javacpp.Pointer allocate(long bytes, MemoryKind kind, boolean initialize)This method returns PLEASE NOTE: Cache options depend on specific implementations- Specified by:
allocatein interfaceMemoryManager- Parameters:
bytes-kind-initialize-
-
collect
public void collect(INDArray... arrays)
This method detaches off-heap memory from passed INDArray instances, and optionally stores them in cache for future reuse PLEASE NOTE: Cache options depend on specific implementations- Specified by:
collectin interfaceMemoryManager- Parameters:
arrays-
-
toggleAveraging
public void toggleAveraging(boolean enabled)
Description copied from interface:MemoryManagerThis method enables/disables calculation of average time spent within loops Default: false- Specified by:
toggleAveragingin interfaceMemoryManager
-
purgeCaches
public void purgeCaches()
This method purges all cached memory chunks- Specified by:
purgeCachesin interfaceMemoryManager
-
memcpy
public void memcpy(DataBuffer dstBuffer, DataBuffer srcBuffer)
Description copied from interface:MemoryManagerThis method does memcpy from source buffer to destination buffer PLEASE NOTE: This method is NOT safe.- Specified by:
memcpyin interfaceMemoryManager
-
notifyScopeEntered
public void notifyScopeEntered()
Description copied from interface:MemoryManagerPLEASE NOTE: This method is under development yet. Do not use it.- Specified by:
notifyScopeEnteredin interfaceMemoryManager
-
notifyScopeLeft
public void notifyScopeLeft()
Description copied from interface:MemoryManagerPLEASE NOTE: This method is under development yet. Do not use it.- Specified by:
notifyScopeLeftin interfaceMemoryManager
-
invokeGcOccasionally
public void invokeGcOccasionally()
Description copied from interface:MemoryManagerThis method calls for GC, and if frequency is met - System.gc() will be called- Specified by:
invokeGcOccasionallyin interfaceMemoryManager
-
invokeGc
public void invokeGc()
Description copied from interface:MemoryManagerThis method calls for GC.- Specified by:
invokeGcin interfaceMemoryManager
-
isPeriodicGcActive
public boolean isPeriodicGcActive()
Description copied from interface:MemoryManagerThis method returns true, if periodic GC is active. False otherwise.- Specified by:
isPeriodicGcActivein interfaceMemoryManager- Returns:
-
setOccasionalGcFrequency
public void setOccasionalGcFrequency(int frequency)
Description copied from interface:MemoryManagerSets manual GC invocation frequency. If you set it to 5, only 1/5 of calls will result in GC invocation If 0 is used as frequency, it'll disable all manual invocation hooks. default value: 5- Specified by:
setOccasionalGcFrequencyin interfaceMemoryManager
-
setAutoGcWindow
public void setAutoGcWindow(int windowMillis)
Description copied from interface:MemoryManagerThis method enables/disables periodic System.gc() calls. Set to 0 to disable this option.- Specified by:
setAutoGcWindowin interfaceMemoryManager- Parameters:
windowMillis- minimal time milliseconds between calls.
-
getAutoGcWindow
public int getAutoGcWindow()
Description copied from interface:MemoryManagerThis method reutrns- Specified by:
getAutoGcWindowin interfaceMemoryManager
-
getOccasionalGcFrequency
public int getOccasionalGcFrequency()
Description copied from interface:MemoryManagerThis method returns- Specified by:
getOccasionalGcFrequencyin interfaceMemoryManager- Returns:
-
getLastGcTime
public long getLastGcTime()
Description copied from interface:MemoryManagerThis method returns time (in milliseconds) of the las System.gc() call- Specified by:
getLastGcTimein interfaceMemoryManager- Returns:
-
togglePeriodicGc
public void togglePeriodicGc(boolean enabled)
Description copied from interface:MemoryManagerThis method enables/disables periodic GC- Specified by:
togglePeriodicGcin interfaceMemoryManager
-
getAverageLoopTime
public int getAverageLoopTime()
Description copied from interface:MemoryManagerThis method returns average time between invokeGCOccasionally() calls- Specified by:
getAverageLoopTimein interfaceMemoryManager- Returns:
-
getCurrentWorkspace
public MemoryWorkspace getCurrentWorkspace()
- Specified by:
getCurrentWorkspacein interfaceMemoryManager
-
setCurrentWorkspace
public void setCurrentWorkspace(MemoryWorkspace workspace)
- Specified by:
setCurrentWorkspacein interfaceMemoryManager
-
scopeOutOfWorkspaces
public MemoryWorkspace scopeOutOfWorkspaces()
Description copied from interface:MemoryManagerThis method temporary opens block out of any workspace scope. PLEASE NOTE: Do not forget to close this block.- Specified by:
scopeOutOfWorkspacesin interfaceMemoryManager- Returns:
-
releaseCurrentContext
public void releaseCurrentContext()
Description copied from interface:MemoryManagerThis method releases Context (if current backend has one, sure)- Specified by:
releaseCurrentContextin interfaceMemoryManager
-
-