public abstract class Nd4jWorkspace extends Object implements MemoryWorkspace
MemoryWorkspace.Type
DEFAULT_ID
Constructor and Description |
---|
Nd4jWorkspace(@NonNull WorkspaceConfiguration configuration) |
Nd4jWorkspace(@NonNull WorkspaceConfiguration configuration,
@NonNull String workspaceId) |
Modifier and Type | Method and Description |
---|---|
PagedPointer |
alloc(long requiredMemory,
DataType type,
boolean initialize)
This method does allocation from a given Workspace
|
PagedPointer |
alloc(long requiredMemory,
MemoryKind kind,
DataType type,
boolean initialize)
This method does allocation from a given Workspace
|
protected 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 memory
|
void |
enableDebug(boolean reallyEnable)
This method enabled debugging mode for this workspace
|
static void |
fillFile(File file,
long length) |
void |
free(org.bytedeco.javacpp.Pointer pointer) |
long |
getCurrentOffset()
This mehtod returns current offset within buffer
|
long |
getCurrentSize()
This method returns current amount of memory allocated for workspace.
|
long |
getCyclesCount() |
long |
getDeviceOffset()
This method returns current device memory offset within workspace
|
long |
getGenerationId()
This method returns current generation Id
|
long |
getHostOffset()
This method returns current host memory offset within workspace
|
long |
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 cycle
|
long |
getMaxCycleAllocations()
This method returns number of bytes of biggest cycle
|
int |
getNumberOfExternalAllocations()
This method returns number of spilled allocations, that can be purged at the end of block
|
int |
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 cycle
|
MemoryWorkspace.Type |
getWorkspaceType()
This method returns Type of this workspace
|
protected void |
init() |
void |
initializeWorkspace()
This method causes Workspace initialization
PLEASE NOTE: This call will have no effect on previously initialized Workspace
|
boolean |
isScopeActive()
This method returns True if scope was opened, and not closed yet.
|
MemoryWorkspace |
notifyScopeBorrowed()
This method TEMPORARY enters this workspace, without reset applied
|
MemoryWorkspace |
notifyScopeEntered()
This method notifies given Workspace that new use cycle is starting now
|
MemoryWorkspace |
notifyScopeLeft()
This method is shortcut to close() method
|
void |
reset()
This method reset host/device offsets within workspace
PLEASE NOTE: Never call this method unless you realize all consequences
|
protected abstract void |
resetWorkspace() |
MemoryWorkspace |
tagOutOfScopeUse()
This method temporary disables this workspace
|
void |
toggleWorkspaceUse(boolean isEnabled)
This method allows to temporary disable this workspace, and issue allocations directly.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDeviceId, getId, getPrimaryOffset, getThreadId, getWorkspaceConfiguration, setPreviousWorkspace
deallocator, getUniqueId, targetDevice
protected int deviceId
protected Long threadId
protected MemoryWorkspace.Type workspaceType
protected static final long SAFETY_OFFSET
protected String id
protected AtomicLong currentSize
protected AtomicLong hostOffset
protected AtomicLong deviceOffset
protected PointersPair workspace
protected MemoryManager memoryManager
protected AtomicBoolean isLearning
protected AtomicBoolean isUsed
protected AtomicLong disabledCounter
protected AtomicLong cyclesCount
protected AtomicLong stepsCount
protected int stepsNumber
protected AtomicLong lastCycleAllocations
protected AtomicLong cycleAllocations
protected AtomicLong spilledAllocationsSize
protected AtomicLong pinnedAllocationsSize
protected AtomicLong maxCycle
protected AtomicBoolean resetPlanned
protected AtomicBoolean isOpen
protected AtomicBoolean isInit
protected AtomicBoolean isOver
protected AtomicBoolean isBorrowed
protected AtomicInteger tagScope
protected AtomicBoolean isDebug
protected AtomicInteger externalCount
protected AtomicInteger pinnedCount
protected AtomicBoolean trimmedMode
protected AtomicLong trimmedStep
protected final WorkspaceConfiguration workspaceConfiguration
protected List<PointersPair> externalAllocations
protected Queue<PointersPair> pinnedAllocations
protected MemoryWorkspace previousWorkspace
protected MemoryWorkspace borrowingWorkspace
protected AtomicLong initialBlockSize
protected String guid
protected File tempFile
protected AtomicLong generationId
public static final int alignmentBase
public Nd4jWorkspace(@NonNull @NonNull WorkspaceConfiguration configuration)
public Nd4jWorkspace(@NonNull @NonNull WorkspaceConfiguration configuration, @NonNull @NonNull String workspaceId)
public MemoryWorkspace.Type getWorkspaceType()
MemoryWorkspace
getWorkspaceType
in interface MemoryWorkspace
public long getGenerationId()
MemoryWorkspace
getGenerationId
in interface MemoryWorkspace
public long getStepNumber()
public long getSpilledSize()
public long getPinnedSize()
public long getInitialBlockSize()
public MemoryWorkspace getParentWorkspace()
getParentWorkspace
in interface MemoryWorkspace
public long getDeviceOffset()
public long getHostOffset()
public long getCurrentSize()
getCurrentSize
in interface MemoryWorkspace
public long getCurrentOffset()
MemoryWorkspace
getCurrentOffset
in interface MemoryWorkspace
protected void init()
public PagedPointer alloc(long requiredMemory, DataType type, boolean initialize)
MemoryWorkspace
alloc
in interface MemoryWorkspace
requiredMemory
- allocation size, in bytestype
- dataType that is going to be usedpublic void enableDebug(boolean reallyEnable)
enableDebug
in interface MemoryWorkspace
reallyEnable
- public PagedPointer alloc(long requiredMemory, MemoryKind kind, DataType type, boolean initialize)
MemoryWorkspace
alloc
in interface MemoryWorkspace
requiredMemory
- allocation size, in byteskind
- MemoryKind for allocationtype
- dataType that is going to be usedpublic void free(org.bytedeco.javacpp.Pointer pointer)
public void initializeWorkspace()
MemoryWorkspace
initializeWorkspace
in interface MemoryWorkspace
public int getNumberOfExternalAllocations()
public int getNumberOfPinnedAllocations()
public void destroyWorkspace()
MemoryWorkspace
destroyWorkspace
in interface MemoryWorkspace
public void destroyWorkspace(boolean extended)
destroyWorkspace
in interface MemoryWorkspace
extended
- public MemoryWorkspace notifyScopeBorrowed()
notifyScopeBorrowed
in interface MemoryWorkspace
public long getCyclesCount()
public void close()
MemoryWorkspace
close
in interface AutoCloseable
close
in interface MemoryWorkspace
protected abstract void clearPinnedAllocations(boolean extended)
protected abstract void clearExternalAllocations()
public MemoryWorkspace notifyScopeEntered()
MemoryWorkspace
notifyScopeEntered
in interface MemoryWorkspace
public void reset()
protected abstract void resetWorkspace()
public MemoryWorkspace notifyScopeLeft()
notifyScopeLeft
in interface MemoryWorkspace
public void toggleWorkspaceUse(boolean isEnabled)
toggleWorkspaceUse
in interface MemoryWorkspace
isEnabled
- public long getLastCycleAllocations()
getLastCycleAllocations
in interface MemoryWorkspace
public long getThisCycleAllocations()
getThisCycleAllocations
in interface MemoryWorkspace
public long getMaxCycleAllocations()
getMaxCycleAllocations
in interface MemoryWorkspace
public boolean isScopeActive()
isScopeActive
in interface MemoryWorkspace
public MemoryWorkspace tagOutOfScopeUse()
MemoryWorkspace
tagOutOfScopeUse
in interface MemoryWorkspace
Copyright © 2021. All rights reserved.