Search in sources :

Example 16 with WorkspaceConfiguration

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());
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) INDArray(org.nd4j.linalg.api.ndarray.INDArray) WorkspaceConfiguration(org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration) MemoryWorkspace(org.nd4j.linalg.api.memory.MemoryWorkspace) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 17 with WorkspaceConfiguration

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

Example 18 with WorkspaceConfiguration

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

Example 19 with WorkspaceConfiguration

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

Aggregations

Test (org.junit.Test)19 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)19 WorkspaceConfiguration (org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration)19 MemoryWorkspace (org.nd4j.linalg.api.memory.MemoryWorkspace)14 INDArray (org.nd4j.linalg.api.ndarray.INDArray)13 Nd4jWorkspace (org.nd4j.linalg.memory.abstracts.Nd4jWorkspace)11 File (java.io.File)2 Ignore (org.junit.Ignore)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 DataSet (org.nd4j.linalg.dataset.DataSet)1 ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)1