use of org.nd4j.linalg.api.memory.MemoryWorkspace in project nd4j by deeplearning4j.
the class OperationProfilerTests method testScopePanic3.
@Test
public void testScopePanic3() throws Exception {
Nd4j.getExecutioner().setProfilingMode(OpExecutioner.ProfilingMode.SCOPE_PANIC);
INDArray array;
try (MemoryWorkspace workspace = Nd4j.getWorkspaceManager().getAndActivateWorkspace("WS121")) {
array = Nd4j.create(10);
assertTrue(array.isAttached());
assertEquals(1, workspace.getGenerationId());
try (MemoryWorkspace workspaceInner = Nd4j.getWorkspaceManager().getAndActivateWorkspace("WS122")) {
array.add(1.0);
}
}
}
use of org.nd4j.linalg.api.memory.MemoryWorkspace in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testToggle1.
@Test
public void testToggle1() throws Exception {
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().createNewWorkspace(loopFirstConfig);
Nd4j.getMemoryManager().setCurrentWorkspace(workspace);
assertNotEquals(null, Nd4j.getMemoryManager().getCurrentWorkspace());
assertEquals(0, workspace.getHostOffset());
try (MemoryWorkspace cW = workspace.notifyScopeEntered()) {
INDArray array1 = Nd4j.create(100);
cW.toggleWorkspaceUse(false);
INDArray arrayDetached = Nd4j.create(100);
arrayDetached.assign(1.0f);
double sum = arrayDetached.sumNumber().doubleValue();
assertEquals(100f, sum, 0.01);
cW.toggleWorkspaceUse(true);
INDArray array2 = Nd4j.create(100);
}
assertEquals(0, workspace.getHostOffset());
assertEquals(200 * Nd4j.sizeOfDataType(), workspace.getCurrentSize());
log.info("--------------------------");
try (MemoryWorkspace cW = workspace.notifyScopeEntered()) {
INDArray array1 = Nd4j.create(100);
cW.toggleWorkspaceUse(false);
INDArray arrayDetached = Nd4j.create(100);
arrayDetached.assign(1.0f);
double sum = arrayDetached.sumNumber().doubleValue();
assertEquals(100f, sum, 0.01);
cW.toggleWorkspaceUse(true);
assertEquals(100 * Nd4j.sizeOfDataType(), workspace.getHostOffset());
INDArray array2 = Nd4j.create(100);
assertEquals(200 * Nd4j.sizeOfDataType(), workspace.getHostOffset());
}
}
use of org.nd4j.linalg.api.memory.MemoryWorkspace in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testLoop4.
@Test
public void testLoop4() throws Exception {
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().createNewWorkspace(loopFirstConfig);
Nd4j.getMemoryManager().setCurrentWorkspace(workspace);
assertNotEquals(null, Nd4j.getMemoryManager().getCurrentWorkspace());
assertEquals(0, workspace.getHostOffset());
try (MemoryWorkspace cW = workspace.notifyScopeEntered()) {
INDArray array1 = Nd4j.create(100);
INDArray array2 = Nd4j.create(100);
}
assertEquals(0, workspace.getHostOffset());
assertEquals(200 * Nd4j.sizeOfDataType(), workspace.getCurrentSize());
try (MemoryWorkspace cW = workspace.notifyScopeEntered()) {
INDArray array1 = Nd4j.create(100);
assertEquals(100 * Nd4j.sizeOfDataType(), workspace.getHostOffset());
}
assertEquals(0, workspace.getHostOffset());
}
use of org.nd4j.linalg.api.memory.MemoryWorkspace in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testMmap1.
@Test
public void testMmap1() throws Exception {
// we don't support MMAP on cuda yet
if (Nd4j.getExecutioner().getClass().getName().toLowerCase().contains("cuda"))
return;
WorkspaceConfiguration mmap = WorkspaceConfiguration.builder().initialSize(1000000).policyLocation(LocationPolicy.MMAP).build();
MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(mmap, "M2");
INDArray mArray = Nd4j.create(100);
mArray.assign(10f);
assertEquals(1000f, mArray.sumNumber().floatValue(), 1e-5);
ws.close();
ws.notifyScopeEntered();
INDArray mArrayR = Nd4j.createUninitialized(100);
assertEquals(1000f, mArrayR.sumNumber().floatValue(), 1e-5);
ws.close();
}
use of org.nd4j.linalg.api.memory.MemoryWorkspace in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testMmap2.
@Test
public void testMmap2() throws Exception {
// we don't support MMAP on cuda yet
if (Nd4j.getExecutioner().getClass().getName().toLowerCase().contains("cuda"))
return;
File tmp = File.createTempFile("tmp", "fdsfdf");
tmp.deleteOnExit();
Nd4jWorkspace.fillFile(tmp, 100000);
WorkspaceConfiguration mmap = WorkspaceConfiguration.builder().policyLocation(LocationPolicy.MMAP).tempFilePath(tmp.getAbsolutePath()).build();
MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(mmap, "M3");
INDArray mArray = Nd4j.create(100);
mArray.assign(10f);
assertEquals(1000f, mArray.sumNumber().floatValue(), 1e-5);
ws.notifyScopeLeft();
}
Aggregations