use of org.nd4j.linalg.api.memory.MemoryWorkspace in project nd4j by deeplearning4j.
the class WorkspaceProviderTests method testCircularBufferReset1.
@Test
public void testCircularBufferReset1() throws Exception {
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(circularConfiguration, "WSR_1");
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace("WSR_1")) {
Nd4j.create(10000);
assertEquals(0, workspace.getCurrentSize());
assertEquals(1, workspace.getNumberOfExternalAllocations());
}
assertEquals(10 * 1024L * 1024L, workspace.getCurrentSize());
assertEquals(0, workspace.getHostOffset());
assertEquals(1, workspace.getNumberOfExternalAllocations());
for (int i = 0; i < 11 * 1024 * 1024; i += 10000 * Nd4j.sizeOfDataType()) {
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace("WSR_1")) {
Nd4j.create(10000);
}
/*
if (i < 10480000)
assertEquals("I: " + i,1, workspace.getNumberOfExternalAllocations());
else
assertEquals(0, workspace.getNumberOfExternalAllocations());
*/
}
assertEquals(0, workspace.getNumberOfExternalAllocations());
}
use of org.nd4j.linalg.api.memory.MemoryWorkspace in project nd4j by deeplearning4j.
the class WorkspaceProviderTests method testNestedWorkspaces8.
@Test
public void testNestedWorkspaces8() throws Exception {
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(loopConfiguration, "WS_1")) {
INDArray array = Nd4j.create(100);
}
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(loopConfiguration, "WS_1");
workspace.initializeWorkspace();
assertEquals(100 * Nd4j.sizeOfDataType(), workspace.getCurrentSize());
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(loopConfiguration, "WS_1")) {
INDArray array = Nd4j.create(1000);
}
Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(loopConfiguration, "WS_1").initializeWorkspace();
assertEquals(100 * Nd4j.sizeOfDataType(), workspace.getCurrentSize());
}
Aggregations