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 AtomicInteger
averageLoopTime
protected AtomicBoolean
averagingEnabled
protected AtomicLong
freqCounter
protected AtomicInteger
frequency
protected Queue<Integer>
intervals
protected static int
intervalTail
protected AtomicLong
lastGcTime
protected AtomicInteger
noGcWindow
protected AtomicBoolean
periodicEnabled
-
Constructor Summary
Constructors Constructor Description BasicMemoryManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.bytedeco.javacpp.Pointer
allocate(long bytes, MemoryKind kind, boolean initialize)
This method returns PLEASE NOTE: Cache options depend on specific implementationsvoid
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 implementationsint
getAutoGcWindow()
This method reutrnsint
getAverageLoopTime()
This method returns average time between invokeGCOccasionally() callsMemoryWorkspace
getCurrentWorkspace()
long
getLastGcTime()
This method returns time (in milliseconds) of the las System.gc() callint
getOccasionalGcFrequency()
This method returnsvoid
invokeGc()
This method calls for GC.void
invokeGcOccasionally()
This method calls for GC, and if frequency is met - System.gc() will be calledboolean
isPeriodicGcActive()
This method returns true, if periodic GC is active.void
memcpy(DataBuffer dstBuffer, DataBuffer srcBuffer)
This method does memcpy from source buffer to destination buffer PLEASE NOTE: This method is NOT safe.void
notifyScopeEntered()
PLEASE NOTE: This method is under development yet.void
notifyScopeLeft()
PLEASE NOTE: This method is under development yet.void
purgeCaches()
This method purges all cached memory chunksvoid
releaseCurrentContext()
This method releases Context (if current backend has one, sure)MemoryWorkspace
scopeOutOfWorkspaces()
This method temporary opens block out of any workspace scope.void
setAutoGcWindow(int windowMillis)
This method enables/disables periodic System.gc() calls.void
setCurrentWorkspace(MemoryWorkspace workspace)
void
setOccasionalGcFrequency(int frequency)
Sets manual GC invocation frequency.void
toggleAveraging(boolean enabled)
This method enables/disables calculation of average time spent within loops Default: falsevoid
togglePeriodicGc(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:
allocate
in 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:
collect
in interfaceMemoryManager
- Parameters:
arrays
-
-
toggleAveraging
public void toggleAveraging(boolean enabled)
Description copied from interface:MemoryManager
This method enables/disables calculation of average time spent within loops Default: false- Specified by:
toggleAveraging
in interfaceMemoryManager
-
purgeCaches
public void purgeCaches()
This method purges all cached memory chunks- Specified by:
purgeCaches
in interfaceMemoryManager
-
memcpy
public void memcpy(DataBuffer dstBuffer, DataBuffer srcBuffer)
Description copied from interface:MemoryManager
This method does memcpy from source buffer to destination buffer PLEASE NOTE: This method is NOT safe.- Specified by:
memcpy
in interfaceMemoryManager
-
notifyScopeEntered
public void notifyScopeEntered()
Description copied from interface:MemoryManager
PLEASE NOTE: This method is under development yet. Do not use it.- Specified by:
notifyScopeEntered
in interfaceMemoryManager
-
notifyScopeLeft
public void notifyScopeLeft()
Description copied from interface:MemoryManager
PLEASE NOTE: This method is under development yet. Do not use it.- Specified by:
notifyScopeLeft
in interfaceMemoryManager
-
invokeGcOccasionally
public void invokeGcOccasionally()
Description copied from interface:MemoryManager
This method calls for GC, and if frequency is met - System.gc() will be called- Specified by:
invokeGcOccasionally
in interfaceMemoryManager
-
invokeGc
public void invokeGc()
Description copied from interface:MemoryManager
This method calls for GC.- Specified by:
invokeGc
in interfaceMemoryManager
-
isPeriodicGcActive
public boolean isPeriodicGcActive()
Description copied from interface:MemoryManager
This method returns true, if periodic GC is active. False otherwise.- Specified by:
isPeriodicGcActive
in interfaceMemoryManager
- Returns:
-
setOccasionalGcFrequency
public void setOccasionalGcFrequency(int frequency)
Description copied from interface:MemoryManager
Sets 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:
setOccasionalGcFrequency
in interfaceMemoryManager
-
setAutoGcWindow
public void setAutoGcWindow(int windowMillis)
Description copied from interface:MemoryManager
This method enables/disables periodic System.gc() calls. Set to 0 to disable this option.- Specified by:
setAutoGcWindow
in interfaceMemoryManager
- Parameters:
windowMillis
- minimal time milliseconds between calls.
-
getAutoGcWindow
public int getAutoGcWindow()
Description copied from interface:MemoryManager
This method reutrns- Specified by:
getAutoGcWindow
in interfaceMemoryManager
-
getOccasionalGcFrequency
public int getOccasionalGcFrequency()
Description copied from interface:MemoryManager
This method returns- Specified by:
getOccasionalGcFrequency
in interfaceMemoryManager
- Returns:
-
getLastGcTime
public long getLastGcTime()
Description copied from interface:MemoryManager
This method returns time (in milliseconds) of the las System.gc() call- Specified by:
getLastGcTime
in interfaceMemoryManager
- Returns:
-
togglePeriodicGc
public void togglePeriodicGc(boolean enabled)
Description copied from interface:MemoryManager
This method enables/disables periodic GC- Specified by:
togglePeriodicGc
in interfaceMemoryManager
-
getAverageLoopTime
public int getAverageLoopTime()
Description copied from interface:MemoryManager
This method returns average time between invokeGCOccasionally() calls- Specified by:
getAverageLoopTime
in interfaceMemoryManager
- Returns:
-
getCurrentWorkspace
public MemoryWorkspace getCurrentWorkspace()
- Specified by:
getCurrentWorkspace
in interfaceMemoryManager
-
setCurrentWorkspace
public void setCurrentWorkspace(MemoryWorkspace workspace)
- Specified by:
setCurrentWorkspace
in interfaceMemoryManager
-
scopeOutOfWorkspaces
public MemoryWorkspace scopeOutOfWorkspaces()
Description copied from interface:MemoryManager
This method temporary opens block out of any workspace scope. PLEASE NOTE: Do not forget to close this block.- Specified by:
scopeOutOfWorkspaces
in interfaceMemoryManager
- Returns:
-
releaseCurrentContext
public void releaseCurrentContext()
Description copied from interface:MemoryManager
This method releases Context (if current backend has one, sure)- Specified by:
releaseCurrentContext
in interfaceMemoryManager
-
-