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 PagedPointeralloc(long requiredMemory, DataType type, boolean initialize)This method does allocation from a given WorkspacePagedPointeralloc(long requiredMemory, MemoryKind kind, DataType type, boolean initialize)This method does allocation from a given Workspaceprotected abstract voidclearExternalAllocations()protected abstract voidclearPinnedAllocations(boolean extended)voidclose()This method is for compatibility with "try-with-resources" java blocks.voiddestroyWorkspace()This method causes Workspace destruction: all memory allocations are released after this call.voiddestroyWorkspace(boolean extended)This method basically deallocates workspace memoryvoidenableDebug(boolean reallyEnable)This method enabled debugging mode for this workspacestatic voidfillFile(File file, long length)voidfree(org.bytedeco.javacpp.Pointer pointer)longgetCurrentOffset()This mehtod returns current offset within bufferlonggetCurrentSize()This method returns current amount of memory allocated for workspace.longgetCyclesCount()longgetDeviceOffset()This method returns current device memory offset within workspacelonggetGenerationId()This method returns current generation IdlonggetHostOffset()This method returns current host memory offset within workspacelonggetInitialBlockSize()This method returns number of bytes for first block of circular workspace.longgetLastCycleAllocations()This method returns number of bytes allocated during last full cyclelonggetMaxCycleAllocations()This method returns number of bytes of biggest cycleintgetNumberOfExternalAllocations()This method returns number of spilled allocations, that can be purged at the end of blockintgetNumberOfPinnedAllocations()This method returns number of pinned allocations, they can be purged after 2 steps.MemoryWorkspacegetParentWorkspace()This method returns parent Workspace, if any.longgetPinnedSize()This method returns number of bytes in pinned allocations.longgetSpilledSize()This method returns number of bytes in spilled allocations.longgetStepNumber()This method returns step number.longgetThisCycleAllocations()This method returns number of bytes allocated during THIS cycleMemoryWorkspace.TypegetWorkspaceType()This method returns Type of this workspaceprotected voidinit()voidinitializeWorkspace()This method causes Workspace initialization PLEASE NOTE: This call will have no effect on previously initialized WorkspacebooleanisScopeActive()This method returns True if scope was opened, and not closed yet.MemoryWorkspacenotifyScopeBorrowed()This method TEMPORARY enters this workspace, without reset appliedMemoryWorkspacenotifyScopeEntered()This method notifies given Workspace that new use cycle is starting nowMemoryWorkspacenotifyScopeLeft()This method is shortcut to close() methodvoidreset()This method reset host/device offsets within workspace PLEASE NOTE: Never call this method unless you realize all consequencesprotected abstract voidresetWorkspace()MemoryWorkspacetagOutOfScopeUse()This method temporary disables this workspacevoidtoggleWorkspaceUse(boolean isEnabled)This method allows to temporary disable this workspace, and issue allocations directly.StringtoString()-
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:MemoryWorkspaceThis method returns Type of this workspace- Specified by:
getWorkspaceTypein interfaceMemoryWorkspace- Returns:
-
getGenerationId
public long getGenerationId()
Description copied from interface:MemoryWorkspaceThis method returns current generation Id- Specified by:
getGenerationIdin 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:
getParentWorkspacein 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:
getCurrentSizein interfaceMemoryWorkspace- Returns:
-
getCurrentOffset
public long getCurrentOffset()
Description copied from interface:MemoryWorkspaceThis mehtod returns current offset within buffer- Specified by:
getCurrentOffsetin interfaceMemoryWorkspace- Returns:
-
init
protected void init()
-
alloc
public PagedPointer alloc(long requiredMemory, DataType type, boolean initialize)
Description copied from interface:MemoryWorkspaceThis method does allocation from a given Workspace- Specified by:
allocin 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:
enableDebugin interfaceMemoryWorkspace- Parameters:
reallyEnable-
-
alloc
public PagedPointer alloc(long requiredMemory, MemoryKind kind, DataType type, boolean initialize)
Description copied from interface:MemoryWorkspaceThis method does allocation from a given Workspace- Specified by:
allocin 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:MemoryWorkspaceThis method causes Workspace initialization PLEASE NOTE: This call will have no effect on previously initialized Workspace- Specified by:
initializeWorkspacein 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:MemoryWorkspaceThis method causes Workspace destruction: all memory allocations are released after this call.- Specified by:
destroyWorkspacein interfaceMemoryWorkspace
-
destroyWorkspace
public void destroyWorkspace(boolean extended)
This method basically deallocates workspace memory- Specified by:
destroyWorkspacein interfaceMemoryWorkspace- Parameters:
extended-
-
notifyScopeBorrowed
public MemoryWorkspace notifyScopeBorrowed()
This method TEMPORARY enters this workspace, without reset applied- Specified by:
notifyScopeBorrowedin interfaceMemoryWorkspace- Returns:
-
getCyclesCount
public long getCyclesCount()
-
close
public void close()
Description copied from interface:MemoryWorkspaceThis method is for compatibility with "try-with-resources" java blocks. Internally it should be equal to notifyScopeLeft() method- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceMemoryWorkspace
-
clearPinnedAllocations
protected abstract void clearPinnedAllocations(boolean extended)
-
clearExternalAllocations
protected abstract void clearExternalAllocations()
-
notifyScopeEntered
public MemoryWorkspace notifyScopeEntered()
Description copied from interface:MemoryWorkspaceThis method notifies given Workspace that new use cycle is starting now- Specified by:
notifyScopeEnteredin 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:
notifyScopeLeftin interfaceMemoryWorkspace- Returns:
-
toggleWorkspaceUse
public void toggleWorkspaceUse(boolean isEnabled)
This method allows to temporary disable this workspace, and issue allocations directly.- Specified by:
toggleWorkspaceUsein interfaceMemoryWorkspace- Parameters:
isEnabled-
-
getLastCycleAllocations
public long getLastCycleAllocations()
This method returns number of bytes allocated during last full cycle- Specified by:
getLastCycleAllocationsin interfaceMemoryWorkspace- Returns:
-
getThisCycleAllocations
public long getThisCycleAllocations()
This method returns number of bytes allocated during THIS cycle- Specified by:
getThisCycleAllocationsin interfaceMemoryWorkspace- Returns:
-
getMaxCycleAllocations
public long getMaxCycleAllocations()
This method returns number of bytes of biggest cycle- Specified by:
getMaxCycleAllocationsin interfaceMemoryWorkspace- Returns:
-
isScopeActive
public boolean isScopeActive()
This method returns True if scope was opened, and not closed yet.- Specified by:
isScopeActivein interfaceMemoryWorkspace- Returns:
-
tagOutOfScopeUse
public MemoryWorkspace tagOutOfScopeUse()
Description copied from interface:MemoryWorkspaceThis method temporary disables this workspace- Specified by:
tagOutOfScopeUsein interfaceMemoryWorkspace- Returns:
-
-