Class BasicWorkspaceManager
- java.lang.Object
-
- org.nd4j.linalg.api.memory.provider.BasicWorkspaceManager
-
- All Implemented Interfaces:
MemoryWorkspaceManager
public abstract class BasicWorkspaceManager extends Object implements MemoryWorkspaceManager
-
-
Field Summary
Fields Modifier and Type Field Description protected ThreadLocal<Map<String,MemoryWorkspace>>
backingMap
protected AtomicLong
counter
protected SynchronizedObject<DebugMode>
debugMode
protected WorkspaceConfiguration
defaultConfiguration
static String
WorkspaceDeallocatorThreadName
Deprecated.
-
Constructor Summary
Constructors Constructor Description BasicWorkspaceManager()
BasicWorkspaceManager(@NonNull WorkspaceConfiguration defaultConfiguration)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
anyWorkspaceActiveForCurrentThread()
Determine if there are any workspaces open for the current thread.boolean
checkIfWorkspaceExists(@NonNull String id)
This method checks, if Workspace with a given Id was created before this callboolean
checkIfWorkspaceExistsAndActive(@NonNull String id)
This method checks, if Workspace with a given Id was created before this call, AND is active at the moment of callvoid
destroyAllWorkspacesForCurrentThread()
This method destroys all workspaces allocated in current threadvoid
destroyWorkspace()
This method destroy default workspace, if anyvoid
destroyWorkspace(MemoryWorkspace workspace)
This method destroys given workspaceprotected void
ensureThreadExistense()
List<MemoryWorkspace>
getAllWorkspacesForCurrentThread()
This method returns all workspaces for current threadList<String>
getAllWorkspacesIdsForCurrentThread()
This method returns list of workspace IDs for current threadMemoryWorkspace
getAndActivateWorkspace()
This method gets & activates default workspaceMemoryWorkspace
getAndActivateWorkspace(@NonNull String id)
This method gets & activates workspace with a given IdMemoryWorkspace
getAndActivateWorkspace(@NonNull WorkspaceConfiguration configuration, @NonNull String id)
This method gets & activates default with a given configuration and IdDebugMode
getDebugMode()
This method returns current debug mode active in this JVMString
getUUID()
Returns globally unique IDMemoryWorkspace
getWorkspaceForCurrentThread()
This method will return workspace with default configuration and default id.MemoryWorkspace
getWorkspaceForCurrentThread(@NonNull String id)
This method returns you Workspace for a given Id for current Thread PLEASE NOTE: If Workspace wasn't defined, new Workspace will be created using current default configurationprotected abstract void
pickReference(MemoryWorkspace workspace)
void
printAllocationStatisticsForCurrentThread()
This method prints out basic statistics for workspaces allocated in current threadMemoryWorkspace
scopeOutOfWorkspaces()
This method temporary opens block out of any workspace scope.void
setDebugMode(DebugMode mode)
This method allows to enable (and pick one) global debug mode for workspaces Default value: DISABLEDvoid
setDefaultWorkspaceConfiguration(@NonNull WorkspaceConfiguration configuration)
This method allows to specify "Default" configuration, that will be used in signatures which do not have WorkspaceConfiguration argumentvoid
setWorkspaceForCurrentThread(@NonNull MemoryWorkspace workspace, @NonNull String id)
This method allows you to set given Workspace for spacific Id for current Threadvoid
setWorkspaceForCurrentThread(MemoryWorkspace workspace)
This method allows you to set given Workspace as default for current Thread-
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.MemoryWorkspaceManager
createNewWorkspace, createNewWorkspace, createNewWorkspace, createNewWorkspace, getWorkspaceForCurrentThread
-
-
-
-
Field Detail
-
counter
protected AtomicLong counter
-
defaultConfiguration
protected WorkspaceConfiguration defaultConfiguration
-
backingMap
protected ThreadLocal<Map<String,MemoryWorkspace>> backingMap
-
debugMode
protected SynchronizedObject<DebugMode> debugMode
-
WorkspaceDeallocatorThreadName
@Deprecated public static final String WorkspaceDeallocatorThreadName
Deprecated.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BasicWorkspaceManager
public BasicWorkspaceManager()
-
BasicWorkspaceManager
public BasicWorkspaceManager(@NonNull @NonNull WorkspaceConfiguration defaultConfiguration)
-
-
Method Detail
-
getUUID
public String getUUID()
Returns globally unique ID- Specified by:
getUUID
in interfaceMemoryWorkspaceManager
- Returns:
-
setDefaultWorkspaceConfiguration
public void setDefaultWorkspaceConfiguration(@NonNull @NonNull WorkspaceConfiguration configuration)
This method allows to specify "Default" configuration, that will be used in signatures which do not have WorkspaceConfiguration argument- Specified by:
setDefaultWorkspaceConfiguration
in interfaceMemoryWorkspaceManager
- Parameters:
configuration
-
-
getWorkspaceForCurrentThread
public MemoryWorkspace getWorkspaceForCurrentThread()
This method will return workspace with default configuration and default id.- Specified by:
getWorkspaceForCurrentThread
in interfaceMemoryWorkspaceManager
- Returns:
-
getWorkspaceForCurrentThread
public MemoryWorkspace getWorkspaceForCurrentThread(@NonNull @NonNull String id)
Description copied from interface:MemoryWorkspaceManager
This method returns you Workspace for a given Id for current Thread PLEASE NOTE: If Workspace wasn't defined, new Workspace will be created using current default configuration- Specified by:
getWorkspaceForCurrentThread
in interfaceMemoryWorkspaceManager
- Returns:
-
getDebugMode
public DebugMode getDebugMode()
Description copied from interface:MemoryWorkspaceManager
This method returns current debug mode active in this JVM- Specified by:
getDebugMode
in interfaceMemoryWorkspaceManager
- Returns:
-
setDebugMode
public void setDebugMode(DebugMode mode)
Description copied from interface:MemoryWorkspaceManager
This method allows to enable (and pick one) global debug mode for workspaces Default value: DISABLED- Specified by:
setDebugMode
in interfaceMemoryWorkspaceManager
-
pickReference
protected abstract void pickReference(MemoryWorkspace workspace)
-
setWorkspaceForCurrentThread
public void setWorkspaceForCurrentThread(MemoryWorkspace workspace)
Description copied from interface:MemoryWorkspaceManager
This method allows you to set given Workspace as default for current Thread- Specified by:
setWorkspaceForCurrentThread
in interfaceMemoryWorkspaceManager
-
setWorkspaceForCurrentThread
public void setWorkspaceForCurrentThread(@NonNull @NonNull MemoryWorkspace workspace, @NonNull @NonNull String id)
Description copied from interface:MemoryWorkspaceManager
This method allows you to set given Workspace for spacific Id for current Thread- Specified by:
setWorkspaceForCurrentThread
in interfaceMemoryWorkspaceManager
-
destroyWorkspace
public void destroyWorkspace(MemoryWorkspace workspace)
This method destroys given workspace- Specified by:
destroyWorkspace
in interfaceMemoryWorkspaceManager
- Parameters:
workspace
-
-
destroyWorkspace
public void destroyWorkspace()
This method destroy default workspace, if any- Specified by:
destroyWorkspace
in interfaceMemoryWorkspaceManager
-
destroyAllWorkspacesForCurrentThread
public void destroyAllWorkspacesForCurrentThread()
This method destroys all workspaces allocated in current thread- Specified by:
destroyAllWorkspacesForCurrentThread
in interfaceMemoryWorkspaceManager
-
ensureThreadExistense
protected void ensureThreadExistense()
-
getAndActivateWorkspace
public MemoryWorkspace getAndActivateWorkspace()
This method gets & activates default workspace- Specified by:
getAndActivateWorkspace
in interfaceMemoryWorkspaceManager
- Returns:
-
getAndActivateWorkspace
public MemoryWorkspace getAndActivateWorkspace(@NonNull @NonNull String id)
This method gets & activates workspace with a given Id- Specified by:
getAndActivateWorkspace
in interfaceMemoryWorkspaceManager
- Parameters:
id
-- Returns:
-
getAndActivateWorkspace
public MemoryWorkspace getAndActivateWorkspace(@NonNull @NonNull WorkspaceConfiguration configuration, @NonNull @NonNull String id)
This method gets & activates default with a given configuration and Id- Specified by:
getAndActivateWorkspace
in interfaceMemoryWorkspaceManager
- Parameters:
configuration
-id
-- Returns:
-
checkIfWorkspaceExists
public boolean checkIfWorkspaceExists(@NonNull @NonNull String id)
This method checks, if Workspace with a given Id was created before this call- Specified by:
checkIfWorkspaceExists
in interfaceMemoryWorkspaceManager
- Parameters:
id
-- Returns:
-
checkIfWorkspaceExistsAndActive
public boolean checkIfWorkspaceExistsAndActive(@NonNull @NonNull String id)
Description copied from interface:MemoryWorkspaceManager
This method checks, if Workspace with a given Id was created before this call, AND is active at the moment of call- Specified by:
checkIfWorkspaceExistsAndActive
in interfaceMemoryWorkspaceManager
- Returns:
-
scopeOutOfWorkspaces
public MemoryWorkspace scopeOutOfWorkspaces()
This method temporary opens block out of any workspace scope.PLEASE NOTE: Do not forget to close this block.
- Specified by:
scopeOutOfWorkspaces
in interfaceMemoryWorkspaceManager
- Returns:
-
printAllocationStatisticsForCurrentThread
public void printAllocationStatisticsForCurrentThread()
This method prints out basic statistics for workspaces allocated in current thread- Specified by:
printAllocationStatisticsForCurrentThread
in interfaceMemoryWorkspaceManager
-
getAllWorkspacesIdsForCurrentThread
public List<String> getAllWorkspacesIdsForCurrentThread()
Description copied from interface:MemoryWorkspaceManager
This method returns list of workspace IDs for current thread- Specified by:
getAllWorkspacesIdsForCurrentThread
in interfaceMemoryWorkspaceManager
- Returns:
-
getAllWorkspacesForCurrentThread
public List<MemoryWorkspace> getAllWorkspacesForCurrentThread()
Description copied from interface:MemoryWorkspaceManager
This method returns all workspaces for current thread- Specified by:
getAllWorkspacesForCurrentThread
in interfaceMemoryWorkspaceManager
-
anyWorkspaceActiveForCurrentThread
public boolean anyWorkspaceActiveForCurrentThread()
Description copied from interface:MemoryWorkspaceManager
Determine if there are any workspaces open for the current thread.- Specified by:
anyWorkspaceActiveForCurrentThread
in interfaceMemoryWorkspaceManager
- Returns:
- True if any workspaces are open for this thread, false otherwise
-
-