@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(); } }
@Override public INDArray activate(boolean training) { if (input == null) { throw new IllegalArgumentException("Cannot perform forward pass with null input " + layerId()); } if (cacheMode == null) cacheMode = CacheMode.NONE; applyDropOutIfNecessary(training); INDArray z = preOutput(training); // we do cache only if cache workspace exists. Skip otherwise if (training && cacheMode != CacheMode.NONE && Nd4j.getWorkspaceManager().checkIfWorkspaceExists(ComputationGraph.workspaceCache)) { try (MemoryWorkspace wsB = Nd4j.getWorkspaceManager() .getWorkspaceForCurrentThread(ComputationGraph.workspaceCache).notifyScopeBorrowed()) { preOutput = z.unsafeDuplication(); } } //String afn = conf.getLayer().getActivationFunction(); IActivation afn = layerConf().getActivationFn(); if (helper != null) { INDArray ret = helper.activate(z, layerConf().getActivationFn()); if (ret != null) { return ret; } } INDArray activation = afn.getActivation(z, training); return activation; }
protected void applyDropOutIfNecessary(boolean training) { if (layerConf().getDropOut() > 0 && !conf.isUseDropConnect() && training && !dropoutApplied) { if (Nd4j.getWorkspaceManager().checkIfWorkspaceExists(ComputationGraph.workspaceExternal)) { try (MemoryWorkspace ws = Nd4j.getWorkspaceManager() .getWorkspaceForCurrentThread(ComputationGraph.workspaceExternal) .notifyScopeBorrowed()) { input = input.isView() ? input.dup() : input.unsafeDuplication(); } } else input = input.isView() ? input.dup() : input.unsafeDuplication(); Dropout.applyDropout(input, layerConf().getDropOut()); dropoutApplied = true; } }
try (MemoryWorkspace wsB = Nd4j.getWorkspaceManager() .getWorkspaceForCurrentThread(workspaceExternal) .notifyScopeBorrowed()) {
ComputationGraph.workspaceExternal)) { try (MemoryWorkspace wsB = Nd4j.getWorkspaceManager() .getWorkspaceForCurrentThread(workspaceExternal).notifyScopeBorrowed()) { try (MemoryWorkspace wsB = Nd4j.getWorkspaceManager() .getWorkspaceForCurrentThread(workspaceExternal) .notifyScopeBorrowed()) {
.getWorkspaceForCurrentThread(ComputationGraph.workspaceCache).notifyScopeBorrowed()) { outputActivations = Nd4j.create(new int[] {miniBatchSize, hiddenLayerSize, timeSeriesLength}, 'f'); //F order to keep time steps together toReturn.fwdPassOutput = outputActivations; .notifyScopeBorrowed(); if (cacheMode != CacheMode.NONE) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(ComputationGraph.workspaceCache) .notifyScopeBorrowed(); if (cacheMode != CacheMode.NONE) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(ComputationGraph.workspaceCache) .notifyScopeBorrowed(); if (cacheMode != CacheMode.NONE) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(ComputationGraph.workspaceCache) .notifyScopeBorrowed(); if (cacheMode != CacheMode.NONE) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(ComputationGraph.workspaceCache) .notifyScopeBorrowed(); if (cacheMode != CacheMode.NONE) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(ComputationGraph.workspaceCache) .notifyScopeBorrowed(); .notifyScopeBorrowed(); if (cacheMode != CacheMode.NONE)
.getWorkspaceForCurrentThread(ComputationGraph.workspaceExternal)) { try (MemoryWorkspace wsB = Nd4j.getWorkspaceManager() .getWorkspaceForCurrentThread(ComputationGraph.workspaceExternal).notifyScopeBorrowed()) { z = im2col2d.mmul(reshapedW); .getWorkspaceForCurrentThread(ComputationGraph.workspaceCache).notifyScopeBorrowed()) { i2d = im2col2d.unsafeDuplication();
.getWorkspaceForCurrentThread(ComputationGraph.workspaceExternal)) { try (MemoryWorkspace wsB = Nd4j.getWorkspaceManager() .getWorkspaceForCurrentThread(ComputationGraph.workspaceExternal).notifyScopeBorrowed()) { epsNextOrig = Nd4j.create(new int[] {inDepth, miniBatch, inH, inW}, 'c');