use of org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration in project nd4j by deeplearning4j.
the class EndlessWorkspaceTests method endlessTest6.
@Test
public void endlessTest6() throws Exception {
Nd4j.getMemoryManager().togglePeriodicGc(false);
WorkspaceConfiguration wsConf = WorkspaceConfiguration.builder().initialSize(10 * 1024L * 1024L).policyLearning(LearningPolicy.NONE).build();
final AtomicLong cnt = new AtomicLong(0);
while (true) {
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(wsConf, "PEW-PEW")) {
INDArray array = Nd4j.create(new float[] { 1f, 2f, 3f, 4f, 5f });
}
if (cnt.incrementAndGet() % 1000000 == 0)
log.info("TotalBytes: {}", Pointer.totalBytes());
}
}
use of org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration in project nd4j by deeplearning4j.
the class SpecialWorkspaceTests method testViewDetach_1.
@Test
public void testViewDetach_1() throws Exception {
WorkspaceConfiguration configuration = WorkspaceConfiguration.builder().initialSize(10000000).overallocationLimit(3.0).policyAllocation(AllocationPolicy.OVERALLOCATE).policySpill(SpillPolicy.REALLOCATE).policyLearning(LearningPolicy.FIRST_LOOP).policyReset(ResetPolicy.BLOCK_LEFT).build();
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(configuration, "WS109");
INDArray row = Nd4j.linspace(1, 10, 10);
INDArray exp = Nd4j.create(1, 10).assign(2.0);
INDArray result = null;
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(configuration, "WS109")) {
INDArray matrix = Nd4j.create(10, 10);
for (int e = 0; e < matrix.rows(); e++) matrix.getRow(e).assign(row);
INDArray column = matrix.getColumn(1);
assertTrue(column.isView());
assertTrue(column.isAttached());
result = column.detach();
}
assertFalse(result.isView());
assertFalse(result.isAttached());
assertEquals(exp, result);
}
use of org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration in project nd4j by deeplearning4j.
the class SpecialWorkspaceTests method testVariableTimeSeries2.
@Test
public void testVariableTimeSeries2() throws Exception {
WorkspaceConfiguration configuration = WorkspaceConfiguration.builder().initialSize(0).overallocationLimit(3.0).policyAllocation(AllocationPolicy.OVERALLOCATE).policySpill(SpillPolicy.REALLOCATE).policyLearning(LearningPolicy.FIRST_LOOP).policyReset(ResetPolicy.ENDOFBUFFER_REACHED).build();
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(configuration, "WS1");
workspace.enableDebug(true);
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(configuration, "WS1")) {
Nd4j.create(500);
Nd4j.create(500);
}
assertEquals(0, workspace.getStepNumber());
long requiredMemory = 1000 * Nd4j.sizeOfDataType();
long shiftedSize = ((long) (requiredMemory * 1.3)) + (8 - (((long) (requiredMemory * 1.3)) % 8));
assertEquals(requiredMemory, workspace.getSpilledSize());
assertEquals(shiftedSize, workspace.getInitialBlockSize());
assertEquals(workspace.getInitialBlockSize() * 4, workspace.getCurrentSize());
for (int i = 0; i < 100; i++) {
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(configuration, "WS1")) {
Nd4j.create(500);
Nd4j.create(500);
Nd4j.create(500);
}
}
assertEquals(workspace.getInitialBlockSize() * 4, workspace.getCurrentSize());
assertEquals(0, workspace.getNumberOfPinnedAllocations());
assertEquals(0, workspace.getNumberOfExternalAllocations());
assertEquals(0, workspace.getSpilledSize());
assertEquals(0, workspace.getPinnedSize());
}
use of org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration in project nd4j by deeplearning4j.
the class WorkspaceProviderTests method testMemcpy1.
@Ignore
@Test
public void testMemcpy1() {
INDArray warmUp = Nd4j.create(100000);
for (int x = 0; x < 5000; x++) {
warmUp.addi(0.1);
}
WorkspaceConfiguration configuration = WorkspaceConfiguration.builder().policyMirroring(MirroringPolicy.HOST_ONLY).initialSize(1024L * 1024L * 1024L).policyLearning(LearningPolicy.NONE).build();
INDArray array = Nd4j.createUninitialized(150000000);
MemoryWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().createNewWorkspace(configuration, "HOST");
workspace.notifyScopeEntered();
INDArray memcpy = array.unsafeDuplication(false);
workspace.notifyScopeLeft();
}
Aggregations