Package org.nd4j.linalg.api.memory
Interface MemoryWorkspace
-
- All Superinterfaces:
AutoCloseable
,Deallocatable
- All Known Implementing Classes:
DummyWorkspace
,Nd4jWorkspace
public interface MemoryWorkspace extends AutoCloseable, Deallocatable
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
MemoryWorkspace.Type
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_ID
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description PagedPointer
alloc(long requiredMemory, DataType dataType, boolean initialize)
This method does allocation from a given WorkspacePagedPointer
alloc(long requiredMemory, MemoryKind kind, DataType dataType, boolean initialize)
This method does allocation from a given Workspacevoid
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)
void
enableDebug(boolean reallyEnable)
This method enabled debugging mode for this workspacelong
getCurrentOffset()
This mehtod returns current offset within bufferlong
getCurrentSize()
This methos returns current allocated size of this workspaceint
getDeviceId()
Returns deviceId for this workspacelong
getGenerationId()
This method returns current generation IdString
getId()
This method returns Id of this workspacelong
getLastCycleAllocations()
This method returns amount of memory consumed in last successful cycle, in byteslong
getMaxCycleAllocations()
This method returns amount of memory consumed by largest successful cycle, in bytesMemoryWorkspace
getParentWorkspace()
This method returns parent Workspace, if any.long
getPrimaryOffset()
long
getThisCycleAllocations()
This method returns amount of memory consumed in current cycle, in bytesLong
getThreadId()
This method returns threadId where this workspace was createdWorkspaceConfiguration
getWorkspaceConfiguration()
This method returns WorkspaceConfiguration bean that was used for given Workspace instanceMemoryWorkspace.Type
getWorkspaceType()
This method returns Type of this workspacevoid
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 notifies given Workspace that use cycle just endedvoid
setPreviousWorkspace(MemoryWorkspace memoryWorkspace)
Set the previous workspace, if any
NOTE: this method should only be used if you are fully aware of the consequences of doing so.MemoryWorkspace
tagOutOfScopeUse()
This method temporary disables this workspacevoid
toggleWorkspaceUse(boolean isEnabled)
This method allows you to temporary disable/enable given Workspace use.-
Methods inherited from interface org.nd4j.linalg.api.memory.Deallocatable
deallocator, getUniqueId, targetDevice
-
-
-
-
Field Detail
-
DEFAULT_ID
static final String DEFAULT_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
getWorkspaceConfiguration
WorkspaceConfiguration getWorkspaceConfiguration()
This method returns WorkspaceConfiguration bean that was used for given Workspace instance- Returns:
-
getWorkspaceType
MemoryWorkspace.Type getWorkspaceType()
This method returns Type of this workspace- Returns:
-
getId
String getId()
This method returns Id of this workspace- Returns:
-
getDeviceId
int getDeviceId()
Returns deviceId for this workspace- Returns:
-
getThreadId
Long getThreadId()
This method returns threadId where this workspace was created- Returns:
-
getGenerationId
long getGenerationId()
This method returns current generation Id- Returns:
-
alloc
PagedPointer alloc(long requiredMemory, DataType dataType, boolean initialize)
This method does allocation from a given Workspace- Parameters:
requiredMemory
- allocation size, in bytesdataType
- dataType that is going to be used- Returns:
-
getPrimaryOffset
long getPrimaryOffset()
-
alloc
PagedPointer alloc(long requiredMemory, MemoryKind kind, DataType dataType, boolean initialize)
This method does allocation from a given Workspace- Parameters:
requiredMemory
- allocation size, in byteskind
- MemoryKind for allocationdataType
- dataType that is going to be used- Returns:
-
notifyScopeEntered
MemoryWorkspace notifyScopeEntered()
This method notifies given Workspace that new use cycle is starting now- Returns:
-
notifyScopeBorrowed
MemoryWorkspace notifyScopeBorrowed()
This method TEMPORARY enters this workspace, without reset applied- Returns:
-
notifyScopeLeft
MemoryWorkspace notifyScopeLeft()
This method notifies given Workspace that use cycle just ended- Returns:
-
isScopeActive
boolean isScopeActive()
This method returns True if scope was opened, and not closed yet.- Returns:
-
initializeWorkspace
void initializeWorkspace()
This method causes Workspace initialization PLEASE NOTE: This call will have no effect on previously initialized Workspace
-
destroyWorkspace
void destroyWorkspace()
This method causes Workspace destruction: all memory allocations are released after this call.
-
destroyWorkspace
void destroyWorkspace(boolean extended)
-
toggleWorkspaceUse
void toggleWorkspaceUse(boolean isEnabled)
This method allows you to temporary disable/enable given Workspace use. If turned off - direct memory allocations will be used.- Parameters:
isEnabled
-
-
getThisCycleAllocations
long getThisCycleAllocations()
This method returns amount of memory consumed in current cycle, in bytes- Returns:
-
enableDebug
void enableDebug(boolean reallyEnable)
This method enabled debugging mode for this workspace- Parameters:
reallyEnable
-
-
getLastCycleAllocations
long getLastCycleAllocations()
This method returns amount of memory consumed in last successful cycle, in bytes- Returns:
-
getMaxCycleAllocations
long getMaxCycleAllocations()
This method returns amount of memory consumed by largest successful cycle, in bytes- Returns:
-
getCurrentSize
long getCurrentSize()
This methos returns current allocated size of this workspace- Returns:
-
close
void close()
This method is for compatibility with "try-with-resources" java blocks. Internally it should be equal to notifyScopeLeft() method- Specified by:
close
in interfaceAutoCloseable
-
getParentWorkspace
MemoryWorkspace getParentWorkspace()
This method returns parent Workspace, if any. Null if there's none.- Returns:
-
tagOutOfScopeUse
MemoryWorkspace tagOutOfScopeUse()
This method temporary disables this workspace- Returns:
-
setPreviousWorkspace
void setPreviousWorkspace(MemoryWorkspace memoryWorkspace)
Set the previous workspace, if any
NOTE: this method should only be used if you are fully aware of the consequences of doing so. Incorrect use of this method may leave workspace management in an invalid/indeterminant state!- Parameters:
memoryWorkspace
- Workspace to set as the previous workspace. This is the workspace that will become active when this workspace is closed.
-
getCurrentOffset
long getCurrentOffset()
This mehtod returns current offset within buffer- Returns:
-
-