protected void checkWorkspace(String opName, INDArray array) { if (array.isAttached()) { val ws = array.data().getParentWorkspace(); if (ws.getWorkspaceType() != MemoryWorkspace.Type.CIRCULAR) { if (!ws.isScopeActive()) { throw new ND4JIllegalStateException("Op [" + opName + "] X argument uses leaked workspace pointer from workspace [" + ws.getId() + "]\nAll open workspaces: " + allOpenWorkspaces() + "\n" + SCOPE_PANIC_MSG); } if (ws.getGenerationId() != array.data().getGenerationId()) throw new ND4JIllegalStateException("Op [" + opName + "] X argument uses outdated workspace pointer from workspace [" + ws.getId() + "]\nAll open workspaces: " + allOpenWorkspaces() + "\n" + SCOPE_PANIC_MSG); } } }
/** * This method gets & activates workspace with a given Id * * @param id * @return */ @Override public MemoryWorkspace getAndActivateWorkspace(@NonNull String id) { return getWorkspaceForCurrentThread(id).notifyScopeEntered(); }
public BaseDataBuffer(double[] data, boolean copy, MemoryWorkspace workspace) { allocationMode = AllocUtil.getAllocationModeFromContext(); length = data.length; underlyingLength = data.length; attached = true; parentWorkspace = workspace; initTypeAndSize(); //log.info("Allocating FloatPointer from array of {} elements", data.length); pointer = workspace.alloc(data.length * getElementSize(), dataType(), false).asDoublePointer().put(data); workspaceGenerationId = workspace.getGenerationId(); indexer = DoubleIndexer.create((DoublePointer) pointer); //wrappedBuffer = pointer.asByteBuffer(); }
public GarbageWorkspaceReference(MemoryWorkspace referent, ReferenceQueue<? super MemoryWorkspace> queue) { super(referent, queue); this.pointersPair = ((Nd4jWorkspace) referent).workspace; this.id = referent.getId(); this.threadId = referent.getThreadId(); this.pinnedPointers = ((Nd4jWorkspace) referent).pinnedAllocations; this.externalPointers = ((Nd4jWorkspace) referent).externalAllocations; this.key = id + "_" + threadId; } }
private static List<String> allOpenWorkspaces(){ List<MemoryWorkspace> l = Nd4j.getWorkspaceManager().getAllWorkspacesForCurrentThread(); List<String> workspaces = new ArrayList<>(l.size()); for( MemoryWorkspace ws : l){ if(ws.isScopeActive()) { workspaces.add(ws.getId()); } } return workspaces; }
/** * This method destroys given workspace * * @param workspace */ @Override public void destroyWorkspace(MemoryWorkspace workspace) { if (workspace == null || workspace instanceof DummyWorkspace) return; //workspace.destroyWorkspace(); backingMap.get().remove(workspace.getId()); }
try (MemoryWorkspace ws = workspace.notifyScopeEntered()) { currInput = activationFromPrevLayer(i, currInput, train).leverageTo(workspaceExternal); Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(workspaceFeedForward).initializeWorkspace();
.getCurrentWorkspace().getId().equals(ComputationGraph.workspaceExternal) ? Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread( ComputationGraph.workspaceConfigurationLSTM, workspace.notifyScopeEntered(); workspace.close();
try (MemoryWorkspace ws = workspace.notifyScopeEntered()) { GraphVertex current = vertices[topologicalOrder[i]]; try (MemoryWorkspace wsB = Nd4j.getWorkspaceManager() .getWorkspaceForCurrentThread(workspaceExternal) .notifyScopeBorrowed()) { Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(workspaceFeedForward).initializeWorkspace();
public void shutdown() { while (!isShutdown.get()) LockSupport.parkNanos(100L); if (workspace != null) { log.debug("Manually destroying ADSI workspace"); workspace.destroyWorkspace(true); } } }
workspace.notifyScopeLeft(); workspace.destroyWorkspace(true); workspace.destroyWorkspace(true);
@Override public MemoryWorkspace notifyScopeBorrowed(@NonNull T arrayType) { validateConfig(arrayType); enforceExistsAndActive(arrayType); if(scopeOutOfWs.contains(arrayType)){ return Nd4j.getWorkspaceManager().scopeOutOfWorkspaces(); } else { MemoryWorkspace ws = Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread( getConfiguration(arrayType), getWorkspaceName(arrayType)); return ws.notifyScopeBorrowed(); } }
this.attached = true; this.parentWorkspace = workspace; workspaceGenerationId = workspace.getGenerationId();
.getWorkspaceForCurrentThread(ComputationGraph.workspaceCache).notifyScopeBorrowed()) { outputActivations = Nd4j.create(new int[] {miniBatchSize, hiddenLayerSize, timeSeriesLength}, 'f'); //F order to keep time steps together toReturn.fwdPassOutput = outputActivations; .notifyScopeBorrowed(); .notifyScopeLeft(); if (cacheMode != CacheMode.NONE) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(ComputationGraph.workspaceCache) .notifyScopeBorrowed(); .notifyScopeLeft(); if (cacheMode != CacheMode.NONE) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(ComputationGraph.workspaceCache) .notifyScopeBorrowed(); .notifyScopeLeft(); if (cacheMode != CacheMode.NONE) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(ComputationGraph.workspaceCache) .notifyScopeBorrowed(); .notifyScopeLeft(); if (cacheMode != CacheMode.NONE) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(ComputationGraph.workspaceCache) .notifyScopeBorrowed();
@Override public boolean checkIfWorkspaceExistsAndActive(@NonNull String id) { boolean exists = checkIfWorkspaceExists(id); if (!exists) return false; return backingMap.get().get(id).isScopeActive(); }
if (pointDst.getDeviceId() != Nd4j.getMemoryManager().getCurrentWorkspace().getDeviceId()) { pointDst.setDeviceId(Nd4j.getMemoryManager().getCurrentWorkspace().getDeviceId());
@Override public void close() { for( int i=workspaces.length-1; i>=0; i-- ){ workspaces[i].close(); } } }
@Override public void assertCurrentWorkspace(@NonNull T arrayType, String msg) { validateConfig(arrayType); MemoryWorkspace curr = Nd4j.getMemoryManager().getCurrentWorkspace(); if(!scopeOutOfWs.contains(arrayType) && (curr == null || !getWorkspaceName(arrayType).equals(curr.getId()))){ throw new ND4JWorkspaceException("Assertion failed: expected current workspace to be \"" + getWorkspaceName(arrayType) + "\" (for array type " + arrayType + ") - actual current workspace is " + (curr == null ? null : curr.getId()) + (msg == null ? "" : ": " + msg)); }; }