@Override public MemoryWorkspace notifyScopeEntered() { // we should block stuff since we're going to invalidate spilled allocations // TODO: block on spilled allocations probably? MemoryWorkspace prev = Nd4j.getMemoryManager().getCurrentWorkspace(); // if we're opening the same workspace - just increase counter, and skip everything else if (prev == this && isOpen.get()) { tagScope.incrementAndGet(); return this; } // we'll need this in close() call, to restore previous workspace (if any) previousWorkspace = prev; Nd4j.getMemoryManager().setCurrentWorkspace(this); isOpen.set(true); // resetting workspace to 0 offset (if anything), not applicable to circular mode, sure if (workspaceConfiguration.getPolicyReset() == ResetPolicy.BLOCK_LEFT) { reset(); } // if we have any spilled allocations left from last cycle - purge them. if (externalCount.get() > 0 && (workspaceConfiguration.getPolicyReset() == ResetPolicy.BLOCK_LEFT || resetPlanned.get())) { clearExternalAllocations(); resetPlanned.set(false); } cycleAllocations.set(0); disabledCounter.set(0); generationId.incrementAndGet(); return this; }
&& (workspaceConfiguration.getMaxSize() == 0 || (maxCycle.get() < workspaceConfiguration.getMaxSize()))) { if (workspaceConfiguration.getPolicyReset() != ResetPolicy.ENDOFBUFFER_REACHED) { destroyWorkspace(true); isInit.set(false); if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED) { currentSize.set((long) (currentSize.get() * 1.3)); currentSize.addAndGet(8 - (currentSize.get() % 8)); if (externalCount.get() > 0 && (workspaceConfiguration.getPolicyReset() == ResetPolicy.BLOCK_LEFT || resetPlanned.get())) { clearExternalAllocations();
if (externalCount.get() > 0 && (workspaceConfiguration.getPolicyReset() == ResetPolicy.BLOCK_LEFT || resetPlanned.get())) { clearExternalAllocations(); } else if (currentSize.get() > 0 && cycleAllocations.get() > 0 && workspaceConfiguration.getPolicySpill() == SpillPolicy.REALLOCATE && workspaceConfiguration.getPolicyReset() != ResetPolicy.ENDOFBUFFER_REACHED) { if (workspaceConfiguration.getPolicyReset() == ResetPolicy.BLOCK_LEFT) { reset(); } else if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && currentSize.get() > 0) {
boolean trimmer = (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && requiredMemory + cycleAllocations.get() > initialBlockSize.get() && initialBlockSize.get() > 0) || trimmedMode.get(); if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && currentSize.get() > 0 && !trimmer) { reset();
if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED) workspaceType = Type.CIRCULAR; else workspaceType = Type.SCOPED; if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && workspaceConfiguration.getPolicyAllocation() == AllocationPolicy.OVERALLOCATE) { if (workspaceConfiguration.getOverallocationLimit() < 1.0)
@Override public MemoryWorkspace notifyScopeEntered() { // we should block stuff since we're going to invalidate spilled allocations // TODO: block on spilled allocations probably? MemoryWorkspace prev = Nd4j.getMemoryManager().getCurrentWorkspace(); // if we're opening the same workspace - just increase counter, and skip everything else if (prev == this && isOpen.get()) { tagScope.incrementAndGet(); return this; } // we'll need this in close() call, to restore previous workspace (if any) previousWorkspace = prev; Nd4j.getMemoryManager().setCurrentWorkspace(this); isOpen.set(true); // resetting workspace to 0 offset (if anything), not applicable to circular mode, sure if (workspaceConfiguration.getPolicyReset() == ResetPolicy.BLOCK_LEFT) { reset(); } // if we have any spilled allocations left from last cycle - purge them. if (externalCount.get() > 0 && (workspaceConfiguration.getPolicyReset() == ResetPolicy.BLOCK_LEFT || resetPlanned.get())) { clearExternalAllocations(); resetPlanned.set(false); } cycleAllocations.set(0); disabledCounter.set(0); return this; }
public Nd4jWorkspace(@NonNull WorkspaceConfiguration configuration, @NonNull String workspaceId) { this.workspaceConfiguration = configuration; this.id = workspaceId; this.threadId = Thread.currentThread().getId(); this.guid = java.util.UUID.randomUUID().toString(); this.memoryManager = Nd4j.getMemoryManager(); this.deviceId = Nd4j.getAffinityManager().getDeviceForCurrentThread(); // and actual workspace allocation currentSize.set(workspaceConfiguration.getInitialSize()); if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && workspaceConfiguration.getPolicyAllocation() == AllocationPolicy.OVERALLOCATE) { if (workspaceConfiguration.getOverallocationLimit() < 1.0) throw new ND4JIllegalStateException("For cyclic workspace overallocation should be positive integral value."); stepsNumber = (int) (workspaceConfiguration.getOverallocationLimit() + 1); log.debug("Steps: {}", stepsNumber); } //if (workspaceConfiguration.getPolicyLearning() == LearningPolicy.OVER_TIME && workspaceConfiguration.getCyclesBeforeInitialization() < 1) //log.warn("Workspace [{}]: initialization OVER_TIME was selected, but number of cycles isn't positive value!", id); init(); }
if (workspaceConfiguration.getPolicyReset() != ResetPolicy.ENDOFBUFFER_REACHED) { destroyWorkspace(true); isInit.set(false); if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED) { currentSize.set((long) (currentSize.get() * 1.3)); currentSize.addAndGet(8 - (currentSize.get() % 8)); if (externalCount.get() > 0 && (workspaceConfiguration.getPolicyReset() == ResetPolicy.BLOCK_LEFT || resetPlanned.get())) { clearExternalAllocations(); resetPlanned.set(false);
if (externalCount.get() > 0 && (workspaceConfiguration.getPolicyReset() == ResetPolicy.BLOCK_LEFT || resetPlanned.get())) { clearExternalAllocations(); resetPlanned.set(false); } else if (currentSize.get() > 0 && cycleAllocations.get() > 0 && workspaceConfiguration.getPolicySpill() == SpillPolicy.REALLOCATE && workspaceConfiguration.getPolicyReset() != ResetPolicy.ENDOFBUFFER_REACHED) { if (workspaceConfiguration.getPolicyReset() == ResetPolicy.BLOCK_LEFT) { reset(); } else if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && currentSize.get() > 0) {
boolean trimmer = (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && requiredMemory + cycleAllocations.get() > initialBlockSize.get() && initialBlockSize.get() > 0) || trimmedMode.get(); if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && currentSize.get() > 0 && !trimmer) { reset(); resetPlanned.set(true);
requiredMemory += div; boolean trimmer = (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && requiredMemory + cycleAllocations.get() > initialBlockSize.get() && initialBlockSize.get() > 0 && kind == MemoryKind.DEVICE) || trimmedMode.get(); if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && currentSize.get() > 0 && !trimmer) {
requiredMemory += div; boolean trimmer = (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && requiredMemory + cycleAllocations.get() > initialBlockSize.get() && initialBlockSize.get() > 0 && kind == MemoryKind.DEVICE) || trimmedMode.get(); if (workspaceConfiguration.getPolicyReset() == ResetPolicy.ENDOFBUFFER_REACHED && currentSize.get() > 0 && !trimmer && Nd4j.getWorkspaceManager().getDebugMode() != DebugMode.SPILL_EVERYTHING) {