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>>backingMapprotected AtomicLongcounterprotected SynchronizedObject<DebugMode>debugModeprotected WorkspaceConfigurationdefaultConfigurationstatic StringWorkspaceDeallocatorThreadNameDeprecated.
-
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 booleananyWorkspaceActiveForCurrentThread()Determine if there are any workspaces open for the current thread.booleancheckIfWorkspaceExists(@NonNull String id)This method checks, if Workspace with a given Id was created before this callbooleancheckIfWorkspaceExistsAndActive(@NonNull String id)This method checks, if Workspace with a given Id was created before this call, AND is active at the moment of callvoiddestroyAllWorkspacesForCurrentThread()This method destroys all workspaces allocated in current threadvoiddestroyWorkspace()This method destroy default workspace, if anyvoiddestroyWorkspace(MemoryWorkspace workspace)This method destroys given workspaceprotected voidensureThreadExistense()List<MemoryWorkspace>getAllWorkspacesForCurrentThread()This method returns all workspaces for current threadList<String>getAllWorkspacesIdsForCurrentThread()This method returns list of workspace IDs for current threadMemoryWorkspacegetAndActivateWorkspace()This method gets & activates default workspaceMemoryWorkspacegetAndActivateWorkspace(@NonNull String id)This method gets & activates workspace with a given IdMemoryWorkspacegetAndActivateWorkspace(@NonNull WorkspaceConfiguration configuration, @NonNull String id)This method gets & activates default with a given configuration and IdDebugModegetDebugMode()This method returns current debug mode active in this JVMStringgetUUID()Returns globally unique IDMemoryWorkspacegetWorkspaceForCurrentThread()This method will return workspace with default configuration and default id.MemoryWorkspacegetWorkspaceForCurrentThread(@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 voidpickReference(MemoryWorkspace workspace)voidprintAllocationStatisticsForCurrentThread()This method prints out basic statistics for workspaces allocated in current threadMemoryWorkspacescopeOutOfWorkspaces()This method temporary opens block out of any workspace scope.voidsetDebugMode(DebugMode mode)This method allows to enable (and pick one) global debug mode for workspaces Default value: DISABLEDvoidsetDefaultWorkspaceConfiguration(@NonNull WorkspaceConfiguration configuration)This method allows to specify "Default" configuration, that will be used in signatures which do not have WorkspaceConfiguration argumentvoidsetWorkspaceForCurrentThread(@NonNull MemoryWorkspace workspace, @NonNull String id)This method allows you to set given Workspace for spacific Id for current ThreadvoidsetWorkspaceForCurrentThread(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:
getUUIDin 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:
setDefaultWorkspaceConfigurationin interfaceMemoryWorkspaceManager- Parameters:
configuration-
-
getWorkspaceForCurrentThread
public MemoryWorkspace getWorkspaceForCurrentThread()
This method will return workspace with default configuration and default id.- Specified by:
getWorkspaceForCurrentThreadin interfaceMemoryWorkspaceManager- Returns:
-
getWorkspaceForCurrentThread
public MemoryWorkspace getWorkspaceForCurrentThread(@NonNull @NonNull String id)
Description copied from interface:MemoryWorkspaceManagerThis 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:
getWorkspaceForCurrentThreadin interfaceMemoryWorkspaceManager- Returns:
-
getDebugMode
public DebugMode getDebugMode()
Description copied from interface:MemoryWorkspaceManagerThis method returns current debug mode active in this JVM- Specified by:
getDebugModein interfaceMemoryWorkspaceManager- Returns:
-
setDebugMode
public void setDebugMode(DebugMode mode)
Description copied from interface:MemoryWorkspaceManagerThis method allows to enable (and pick one) global debug mode for workspaces Default value: DISABLED- Specified by:
setDebugModein interfaceMemoryWorkspaceManager
-
pickReference
protected abstract void pickReference(MemoryWorkspace workspace)
-
setWorkspaceForCurrentThread
public void setWorkspaceForCurrentThread(MemoryWorkspace workspace)
Description copied from interface:MemoryWorkspaceManagerThis method allows you to set given Workspace as default for current Thread- Specified by:
setWorkspaceForCurrentThreadin interfaceMemoryWorkspaceManager
-
setWorkspaceForCurrentThread
public void setWorkspaceForCurrentThread(@NonNull @NonNull MemoryWorkspace workspace, @NonNull @NonNull String id)Description copied from interface:MemoryWorkspaceManagerThis method allows you to set given Workspace for spacific Id for current Thread- Specified by:
setWorkspaceForCurrentThreadin interfaceMemoryWorkspaceManager
-
destroyWorkspace
public void destroyWorkspace(MemoryWorkspace workspace)
This method destroys given workspace- Specified by:
destroyWorkspacein interfaceMemoryWorkspaceManager- Parameters:
workspace-
-
destroyWorkspace
public void destroyWorkspace()
This method destroy default workspace, if any- Specified by:
destroyWorkspacein interfaceMemoryWorkspaceManager
-
destroyAllWorkspacesForCurrentThread
public void destroyAllWorkspacesForCurrentThread()
This method destroys all workspaces allocated in current thread- Specified by:
destroyAllWorkspacesForCurrentThreadin interfaceMemoryWorkspaceManager
-
ensureThreadExistense
protected void ensureThreadExistense()
-
getAndActivateWorkspace
public MemoryWorkspace getAndActivateWorkspace()
This method gets & activates default workspace- Specified by:
getAndActivateWorkspacein interfaceMemoryWorkspaceManager- Returns:
-
getAndActivateWorkspace
public MemoryWorkspace getAndActivateWorkspace(@NonNull @NonNull String id)
This method gets & activates workspace with a given Id- Specified by:
getAndActivateWorkspacein 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:
getAndActivateWorkspacein 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:
checkIfWorkspaceExistsin interfaceMemoryWorkspaceManager- Parameters:
id-- Returns:
-
checkIfWorkspaceExistsAndActive
public boolean checkIfWorkspaceExistsAndActive(@NonNull @NonNull String id)Description copied from interface:MemoryWorkspaceManagerThis method checks, if Workspace with a given Id was created before this call, AND is active at the moment of call- Specified by:
checkIfWorkspaceExistsAndActivein 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:
scopeOutOfWorkspacesin interfaceMemoryWorkspaceManager- Returns:
-
printAllocationStatisticsForCurrentThread
public void printAllocationStatisticsForCurrentThread()
This method prints out basic statistics for workspaces allocated in current thread- Specified by:
printAllocationStatisticsForCurrentThreadin interfaceMemoryWorkspaceManager
-
getAllWorkspacesIdsForCurrentThread
public List<String> getAllWorkspacesIdsForCurrentThread()
Description copied from interface:MemoryWorkspaceManagerThis method returns list of workspace IDs for current thread- Specified by:
getAllWorkspacesIdsForCurrentThreadin interfaceMemoryWorkspaceManager- Returns:
-
getAllWorkspacesForCurrentThread
public List<MemoryWorkspace> getAllWorkspacesForCurrentThread()
Description copied from interface:MemoryWorkspaceManagerThis method returns all workspaces for current thread- Specified by:
getAllWorkspacesForCurrentThreadin interfaceMemoryWorkspaceManager
-
anyWorkspaceActiveForCurrentThread
public boolean anyWorkspaceActiveForCurrentThread()
Description copied from interface:MemoryWorkspaceManagerDetermine if there are any workspaces open for the current thread.- Specified by:
anyWorkspaceActiveForCurrentThreadin interfaceMemoryWorkspaceManager- Returns:
- True if any workspaces are open for this thread, false otherwise
-
-