Search in sources :

Example 21 with Nd4jWorkspace

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());
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Nd4jWorkspace(org.nd4j.linalg.memory.abstracts.Nd4jWorkspace) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 22 with Nd4jWorkspace

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());
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Nd4jWorkspace(org.nd4j.linalg.memory.abstracts.Nd4jWorkspace) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 23 with Nd4jWorkspace

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();
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Nd4jWorkspace(org.nd4j.linalg.memory.abstracts.Nd4jWorkspace) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 24 with Nd4jWorkspace

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());
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Nd4jWorkspace(org.nd4j.linalg.memory.abstracts.Nd4jWorkspace) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 25 with Nd4jWorkspace

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();
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Nd4jWorkspace(org.nd4j.linalg.memory.abstracts.Nd4jWorkspace) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Aggregations

Test (org.junit.Test)51 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)51 Nd4jWorkspace (org.nd4j.linalg.memory.abstracts.Nd4jWorkspace)51 INDArray (org.nd4j.linalg.api.ndarray.INDArray)47 MemoryWorkspace (org.nd4j.linalg.api.memory.MemoryWorkspace)18 WorkspaceConfiguration (org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration)11 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 Ignore (org.junit.Ignore)1 ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)1