use of org.nd4j.linalg.memory.abstracts.Nd4jWorkspace in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testLoops3.
@Test
public void testLoops3() throws Exception {
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().createNewWorkspace(loopFirstConfig);
Nd4j.getMemoryManager().setCurrentWorkspace(workspace);
assertNotEquals(null, Nd4j.getMemoryManager().getCurrentWorkspace());
assertEquals(0, workspace.getHostOffset());
workspace.notifyScopeEntered();
INDArray arrayCold1 = Nd4j.create(100);
INDArray arrayCold2 = Nd4j.create(10);
assertEquals(0, workspace.getHostOffset());
assertEquals(0, workspace.getCurrentSize());
workspace.notifyScopeLeft();
assertEquals(0, workspace.getHostOffset());
long reqMem = 110 * Nd4j.sizeOfDataType();
assertEquals(reqMem + reqMem % 8, workspace.getCurrentSize());
}
use of org.nd4j.linalg.memory.abstracts.Nd4jWorkspace in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testLoops1.
@Test
public void testLoops1() throws Exception {
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().createNewWorkspace(loopOverTimeConfig);
Nd4j.getMemoryManager().setCurrentWorkspace(workspace);
assertNotEquals(null, Nd4j.getMemoryManager().getCurrentWorkspace());
assertEquals(0, workspace.getHostOffset());
workspace.notifyScopeEntered();
INDArray arrayCold = Nd4j.create(10);
assertEquals(0, workspace.getHostOffset());
assertEquals(0, workspace.getCurrentSize());
arrayCold.assign(1.0f);
assertEquals(10f, arrayCold.sumNumber().floatValue(), 0.01f);
workspace.notifyScopeLeft();
workspace.initializeWorkspace();
long reqMemory = 11 * Nd4j.sizeOfDataType();
assertEquals(reqMemory + reqMemory % 8, workspace.getCurrentSize());
log.info("-----------------------");
for (int x = 0; x < 10; x++) {
assertEquals(0, workspace.getHostOffset());
workspace.notifyScopeEntered();
INDArray array = Nd4j.create(10);
long reqMem = 10 * Nd4j.sizeOfDataType();
assertEquals(reqMem + reqMem % 8, workspace.getHostOffset());
array.addi(1.0f);
assertEquals(reqMem + reqMem % 8, workspace.getHostOffset());
assertEquals("Failed on iteration " + x, 10, array.sumNumber().doubleValue(), 0.01);
workspace.notifyScopeLeft();
assertEquals(0, workspace.getHostOffset());
}
}
use of org.nd4j.linalg.memory.abstracts.Nd4jWorkspace in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testAllocation5.
@Test
public void testAllocation5() throws Exception {
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().getAndActivateWorkspace(basicConfig, "testAllocation5");
Nd4j.getMemoryManager().setCurrentWorkspace(workspace);
assertNotEquals(null, Nd4j.getMemoryManager().getCurrentWorkspace());
assertEquals(0, workspace.getHostOffset());
INDArray array = Nd4j.create(new int[] { 1, 5 }, 'c');
// checking if allocation actually happened
long reqMemory = 5 * Nd4j.sizeOfDataType();
assertEquals(reqMemory + reqMemory % 8, workspace.getHostOffset());
array.assign(1.0f);
INDArray dup = array.dup();
assertEquals((reqMemory + reqMemory % 8) * 2, workspace.getHostOffset());
assertEquals(5, dup.sumNumber().doubleValue(), 0.01);
workspace.close();
}
use of org.nd4j.linalg.memory.abstracts.Nd4jWorkspace in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testIsAttached2.
@Test
public void testIsAttached2() {
INDArray array = Nd4j.create(100);
try (Nd4jWorkspace wsI = (Nd4jWorkspace) Nd4j.getWorkspaceManager().getAndActivateWorkspace(loopFirstConfig, "ITER")) {
INDArray arrayL = array.leverageTo("ITER");
assertFalse(array.isAttached());
assertFalse(arrayL.isAttached());
}
INDArray array2 = Nd4j.create(100);
assertFalse(array.isAttached());
assertFalse(array2.isAttached());
}
use of org.nd4j.linalg.memory.abstracts.Nd4jWorkspace in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testLoops2.
@Test
public void testLoops2() throws Exception {
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().createNewWorkspace(loopOverTimeConfig);
Nd4j.getMemoryManager().setCurrentWorkspace(workspace);
assertNotEquals(null, Nd4j.getMemoryManager().getCurrentWorkspace());
assertEquals(0, workspace.getHostOffset());
for (int x = 1; x <= 100; x++) {
workspace.notifyScopeEntered();
INDArray arrayCold = Nd4j.create(x);
assertEquals(0, workspace.getHostOffset());
assertEquals(0, workspace.getCurrentSize());
workspace.notifyScopeLeft();
}
workspace.initializeWorkspace();
long reqMem = 100 * Nd4j.sizeOfDataType();
// assertEquals(reqMem + reqMem % 8, workspace.getCurrentSize());
assertEquals(0, workspace.getHostOffset());
workspace.notifyScopeEntered();
INDArray arrayHot = Nd4j.create(10);
reqMem = 10 * Nd4j.sizeOfDataType();
assertEquals(reqMem + reqMem % 8, workspace.getHostOffset());
workspace.notifyScopeLeft();
}
Aggregations