Class Nd4jWorkspace
- java.lang.Object
-
- org.nd4j.linalg.api.memory.abstracts.Nd4jWorkspace
-
- All Implemented Interfaces:
AutoCloseable
,Deallocatable
,MemoryWorkspace
public abstract class Nd4jWorkspace extends Object implements MemoryWorkspace
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.nd4j.linalg.api.memory.MemoryWorkspace
MemoryWorkspace.Type
-
-
Field Summary
-
Fields inherited from interface org.nd4j.linalg.api.memory.MemoryWorkspace
DEFAULT_ID
-
-
Constructor Summary
Constructors Constructor Description Nd4jWorkspace(@NonNull WorkspaceConfiguration configuration)
Nd4jWorkspace(@NonNull WorkspaceConfiguration configuration, @NonNull String workspaceId)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description PagedPointer
alloc(long requiredMemory, DataType type, boolean initialize)
This method does allocation from a given WorkspacePagedPointer
alloc(long requiredMemory, MemoryKind kind, DataType type, boolean initialize)
This method does allocation from a given Workspaceprotected abstract void
clearExternalAllocations()
protected abstract void
clearPinnedAllocations(boolean extended)
void
close()
This method is for compatibility with "try-with-resources" java blocks.void
destroyWorkspace()
This method causes Workspace destruction: all memory allocations are released after this call.void
destroyWorkspace(boolean extended)
This method basically deallocates workspace memoryvoid
enableDebug(boolean reallyEnable)
This method enabled debugging mode for this workspacestatic void
fillFile(File file, long length)
void
free(org.bytedeco.javacpp.Pointer pointer)
long
getCurrentOffset()
This mehtod returns current offset within bufferlong
getCurrentSize()
This method returns current amount of memory allocated for workspace.long
getCyclesCount()
long
getDeviceOffset()
This method returns current device memory offset within workspacelong
getGenerationId()
This method returns current generation Idlong
getHostOffset()
This method returns current host memory offset within workspacelong
getInitialBlockSize()
This method returns number of bytes for first block of circular workspace.long
getLastCycleAllocations()
This method returns number of bytes allocated during last full cyclelong
getMaxCycleAllocations()
This method returns number of bytes of biggest cycleint
getNumberOfExternalAllocations()
This method returns number of spilled allocations, that can be purged at the end of blockint
getNumberOfPinnedAllocations()
This method returns number of pinned allocations, they can be purged after 2 steps.MemoryWorkspace
getParentWorkspace()
This method returns parent Workspace, if any.long
getPinnedSize()
This method returns number of bytes in pinned allocations.long
getSpilledSize()
This method returns number of bytes in spilled allocations.long
getStepNumber()
This method returns step number.long
getThisCycleAllocations()
This method returns number of bytes allocated during THIS cycleMemoryWorkspace.Type
getWorkspaceType()
This method returns Type of this workspaceprotected void
init()
void
initializeWorkspace()
This method causes Workspace initialization PLEASE NOTE: This call will have no effect on previously initialized Workspaceboolean
isScopeActive()
This method returns True if scope was opened, and not closed yet.MemoryWorkspace
notifyScopeBorrowed()
This method TEMPORARY enters this workspace, without reset appliedMemoryWorkspace
notifyScopeEntered()
This method notifies given Workspace that new use cycle is starting nowMemoryWorkspace
notifyScopeLeft()
This method is shortcut to close() methodvoid
reset()
This method reset host/device offsets within workspace PLEASE NOTE: Never call this method unless you realize all consequencesprotected abstract void
resetWorkspace()
MemoryWorkspace
tagOutOfScopeUse()
This method temporary disables this workspacevoid
toggleWorkspaceUse(boolean isEnabled)
This method allows to temporary disable this workspace, and issue allocations directly.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.nd4j.linalg.api.memory.Deallocatable
deallocator, getUniqueId, targetDevice
-
Methods inherited from interface org.nd4j.linalg.api.memory.MemoryWorkspace
getDeviceId, getId, getPrimaryOffset, getThreadId, getWorkspaceConfiguration, setPreviousWorkspace
-
-
-
-
Field Detail
-
deviceId
protected int deviceId
-
threadId
protected Long threadId
-
workspaceType
protected MemoryWorkspace.Type workspaceType
-
SAFETY_OFFSET
protected static final long SAFETY_OFFSET
- See Also:
- Constant Field Values
-
id
protected String id
-
currentSize
protected AtomicLong currentSize
-
hostOffset
protected AtomicLong hostOffset
-
deviceOffset
protected AtomicLong deviceOffset
-
workspace
protected PointersPair workspace
-
memoryManager
protected MemoryManager memoryManager
-
isLearning
protected AtomicBoolean isLearning
-
isUsed
protected AtomicBoolean isUsed
-
disabledCounter
protected AtomicLong disabledCounter
-
cyclesCount
protected AtomicLong cyclesCount
-
stepsCount
protected AtomicLong stepsCount
-
stepsNumber
protected int stepsNumber
-
lastCycleAllocations
protected AtomicLong lastCycleAllocations
-
cycleAllocations
protected AtomicLong cycleAllocations
-
spilledAllocationsSize
protected AtomicLong spilledAllocationsSize
-
pinnedAllocationsSize
protected AtomicLong pinnedAllocationsSize
-
maxCycle
protected AtomicLong maxCycle
-
resetPlanned
protected AtomicBoolean resetPlanned
-
isOpen
protected AtomicBoolean isOpen
-
isInit
protected AtomicBoolean isInit
-
isOver
protected AtomicBoolean isOver
-
isBorrowed
protected AtomicBoolean isBorrowed
-
tagScope
protected AtomicInteger tagScope
-
isDebug
protected AtomicBoolean isDebug
-
externalCount
protected AtomicInteger externalCount
-
pinnedCount
protected AtomicInteger pinnedCount
-
trimmedMode
protected AtomicBoolean trimmedMode
-
trimmedStep
protected AtomicLong trimmedStep
-
workspaceConfiguration
protected final WorkspaceConfiguration workspaceConfiguration
-
externalAllocations
protected List<PointersPair> externalAllocations
-
pinnedAllocations
protected Queue<PointersPair> pinnedAllocations
-
previousWorkspace
protected MemoryWorkspace previousWorkspace
-
borrowingWorkspace
protected MemoryWorkspace borrowingWorkspace
-
initialBlockSize
protected AtomicLong initialBlockSize
-
guid
protected String guid
-
tempFile
protected File tempFile
-
generationId
protected AtomicLong generationId
-
alignmentBase
public static final int alignmentBase
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Nd4jWorkspace
public Nd4jWorkspace(@NonNull @NonNull WorkspaceConfiguration configuration)
-
Nd4jWorkspace
public Nd4jWorkspace(@NonNull @NonNull WorkspaceConfiguration configuration, @NonNull @NonNull String workspaceId)
-
-
Method Detail
-
getWorkspaceType
public MemoryWorkspace.Type getWorkspaceType()
Description copied from interface:MemoryWorkspace
This method returns Type of this workspace- Specified by:
getWorkspaceType
in interfaceMemoryWorkspace
- Returns:
-
getGenerationId
public long getGenerationId()
Description copied from interface:MemoryWorkspace
This method returns current generation Id- Specified by:
getGenerationId
in interfaceMemoryWorkspace
- Returns:
-
getStepNumber
public long getStepNumber()
This method returns step number. Viable only in circular mode.- Returns:
-
getSpilledSize
public long getSpilledSize()
This method returns number of bytes in spilled allocations.- Returns:
-
getPinnedSize
public long getPinnedSize()
This method returns number of bytes in pinned allocations.- Returns:
-
getInitialBlockSize
public long getInitialBlockSize()
This method returns number of bytes for first block of circular workspace.- Returns:
-
getParentWorkspace
public MemoryWorkspace getParentWorkspace()
This method returns parent Workspace, if any. Null if there's none.- Specified by:
getParentWorkspace
in interfaceMemoryWorkspace
- Returns:
-
getDeviceOffset
public long getDeviceOffset()
This method returns current device memory offset within workspace- Returns:
-
getHostOffset
public long getHostOffset()
This method returns current host memory offset within workspace- Returns:
-
getCurrentSize
public long getCurrentSize()
This method returns current amount of memory allocated for workspace. PLEASE NOTE: It shows only amount of HOST memory. If current backend assumes DEVICE/HOST memory pair, DEVICE memory will probably have the same size, but won't be accounted in this value.- Specified by:
getCurrentSize
in interfaceMemoryWorkspace
- Returns:
-
getCurrentOffset
public long getCurrentOffset()
Description copied from interface:MemoryWorkspace
This mehtod returns current offset within buffer- Specified by:
getCurrentOffset
in interfaceMemoryWorkspace
- Returns:
-
init
protected void init()
-
alloc
public PagedPointer alloc(long requiredMemory, DataType type, boolean initialize)
Description copied from interface:MemoryWorkspace
This method does allocation from a given Workspace- Specified by:
alloc
in interfaceMemoryWorkspace
- Parameters:
requiredMemory
- allocation size, in bytestype
- dataType that is going to be used- Returns:
-
enableDebug
public void enableDebug(boolean reallyEnable)
This method enabled debugging mode for this workspace- Specified by:
enableDebug
in interfaceMemoryWorkspace
- Parameters:
reallyEnable
-
-
alloc
public PagedPointer alloc(long requiredMemory, MemoryKind kind, DataType type, boolean initialize)
Description copied from interface:MemoryWorkspace
This method does allocation from a given Workspace- Specified by:
alloc
in interfaceMemoryWorkspace
- Parameters:
requiredMemory
- allocation size, in byteskind
- MemoryKind for allocationtype
- dataType that is going to be used- Returns:
-
free
public void free(org.bytedeco.javacpp.Pointer pointer)
-
initializeWorkspace
public void initializeWorkspace()
Description copied from interface:MemoryWorkspace
This method causes Workspace initialization PLEASE NOTE: This call will have no effect on previously initialized Workspace- Specified by:
initializeWorkspace
in interfaceMemoryWorkspace
-
getNumberOfExternalAllocations
public int getNumberOfExternalAllocations()
This method returns number of spilled allocations, that can be purged at the end of block- Returns:
-
getNumberOfPinnedAllocations
public int getNumberOfPinnedAllocations()
This method returns number of pinned allocations, they can be purged after 2 steps. PLEASE NOTE: This method can return non-zero calues only for circular workspace mode- Returns:
-
destroyWorkspace
public void destroyWorkspace()
Description copied from interface:MemoryWorkspace
This method causes Workspace destruction: all memory allocations are released after this call.- Specified by:
destroyWorkspace
in interfaceMemoryWorkspace
-
destroyWorkspace
public void destroyWorkspace(boolean extended)
This method basically deallocates workspace memory- Specified by:
destroyWorkspace
in interfaceMemoryWorkspace
- Parameters:
extended
-
-
notifyScopeBorrowed
public MemoryWorkspace notifyScopeBorrowed()
This method TEMPORARY enters this workspace, without reset applied- Specified by:
notifyScopeBorrowed
in interfaceMemoryWorkspace
- Returns:
-
getCyclesCount
public long getCyclesCount()
-
close
public void close()
Description copied from interface:MemoryWorkspace
This method is for compatibility with "try-with-resources" java blocks. Internally it should be equal to notifyScopeLeft() method- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceMemoryWorkspace
-
clearPinnedAllocations
protected abstract void clearPinnedAllocations(boolean extended)
-
clearExternalAllocations
protected abstract void clearExternalAllocations()
-
notifyScopeEntered
public MemoryWorkspace notifyScopeEntered()
Description copied from interface:MemoryWorkspace
This method notifies given Workspace that new use cycle is starting now- Specified by:
notifyScopeEntered
in interfaceMemoryWorkspace
- Returns:
-
reset
public void reset()
This method reset host/device offsets within workspace PLEASE NOTE: Never call this method unless you realize all consequences
-
resetWorkspace
protected abstract void resetWorkspace()
-
notifyScopeLeft
public MemoryWorkspace notifyScopeLeft()
This method is shortcut to close() method- Specified by:
notifyScopeLeft
in interfaceMemoryWorkspace
- Returns:
-
toggleWorkspaceUse
public void toggleWorkspaceUse(boolean isEnabled)
This method allows to temporary disable this workspace, and issue allocations directly.- Specified by:
toggleWorkspaceUse
in interfaceMemoryWorkspace
- Parameters:
isEnabled
-
-
getLastCycleAllocations
public long getLastCycleAllocations()
This method returns number of bytes allocated during last full cycle- Specified by:
getLastCycleAllocations
in interfaceMemoryWorkspace
- Returns:
-
getThisCycleAllocations
public long getThisCycleAllocations()
This method returns number of bytes allocated during THIS cycle- Specified by:
getThisCycleAllocations
in interfaceMemoryWorkspace
- Returns:
-
getMaxCycleAllocations
public long getMaxCycleAllocations()
This method returns number of bytes of biggest cycle- Specified by:
getMaxCycleAllocations
in interfaceMemoryWorkspace
- Returns:
-
isScopeActive
public boolean isScopeActive()
This method returns True if scope was opened, and not closed yet.- Specified by:
isScopeActive
in interfaceMemoryWorkspace
- Returns:
-
tagOutOfScopeUse
public MemoryWorkspace tagOutOfScopeUse()
Description copied from interface:MemoryWorkspace
This method temporary disables this workspace- Specified by:
tagOutOfScopeUse
in interfaceMemoryWorkspace
- Returns:
-
-