use of org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration in project nd4j by deeplearning4j.
the class FloatDataBufferTest method testReallocationWorkspace.
@Test
public void testReallocationWorkspace() {
WorkspaceConfiguration initialConfig = WorkspaceConfiguration.builder().initialSize(10 * 1024L * 1024L).policyAllocation(AllocationPolicy.STRICT).policyLearning(LearningPolicy.NONE).build();
MemoryWorkspace workspace = Nd4j.getWorkspaceManager().getAndActivateWorkspace(initialConfig, "SOME_ID");
DataBuffer buffer = Nd4j.createBuffer(new float[] { 1, 2, 3, 4 });
assertTrue(buffer.isAttached());
float[] old = buffer.asFloat();
assertEquals(4, buffer.capacity());
buffer.reallocate(6);
assertEquals(6, buffer.capacity());
float[] newBuf = buffer.asFloat();
assertArrayEquals(old, newBuf, 1e-4F);
workspace.close();
}
use of org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration in project nd4j by deeplearning4j.
the class IntDataBufferTests method testReallocationWorkspace.
@Test
public void testReallocationWorkspace() {
WorkspaceConfiguration initialConfig = WorkspaceConfiguration.builder().initialSize(10 * 1024L * 1024L).policyAllocation(AllocationPolicy.STRICT).policyLearning(LearningPolicy.NONE).build();
MemoryWorkspace workspace = Nd4j.getWorkspaceManager().getAndActivateWorkspace(initialConfig, "SOME_ID");
DataBuffer buffer = Nd4j.createBuffer(new int[] { 1, 2, 3, 4 });
int[] old = buffer.asInt();
assertTrue(buffer.isAttached());
assertEquals(4, buffer.capacity());
buffer.reallocate(6);
assertEquals(6, buffer.capacity());
assertArrayEquals(old, buffer.asInt());
workspace.close();
}
use of org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration in project nd4j by deeplearning4j.
the class CompressionTests method testThresholdCompression0.
@Ignore
@Test
public void testThresholdCompression0() throws Exception {
INDArray initial = Nd4j.rand(new int[] { 1, 150000000 }, 119L);
log.info("DTYPE: {}", Nd4j.dataType());
WorkspaceConfiguration configuration = WorkspaceConfiguration.builder().initialSize(2 * 1024L * 1024L * 1024L).overallocationLimit(0).policyAllocation(AllocationPolicy.STRICT).policyLearning(LearningPolicy.NONE).policyReset(ResetPolicy.BLOCK_LEFT).build();
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(configuration, "IIIA")) {
INDArray compressed = Nd4j.getExecutioner().thresholdEncode(initial.dup(), 0.999);
}
long timeS = 0;
for (int i = 0; i < 100; i++) {
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(configuration, "IIIA")) {
INDArray d = initial.dup();
long time1 = System.nanoTime();
INDArray compressed = Nd4j.getExecutioner().thresholdEncode(d, 0.999);
long time2 = System.nanoTime();
timeS += (time2 - time1) / 1000;
}
}
log.info("Elapsed time: {} us", (timeS) / 100);
}
use of org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testOverallocation2.
@Test
public void testOverallocation2() throws Exception {
WorkspaceConfiguration overallocationConfig = WorkspaceConfiguration.builder().initialSize(0).maxSize(10 * 1024 * 1024).overallocationLimit(1.0).policyAllocation(AllocationPolicy.OVERALLOCATE).policyLearning(LearningPolicy.FIRST_LOOP).policyMirroring(MirroringPolicy.FULL).policySpill(SpillPolicy.EXTERNAL).build();
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().createNewWorkspace(overallocationConfig);
// Nd4j.getMemoryManager().setCurrentWorkspace(workspace);
assertEquals(0, workspace.getCurrentSize());
try (MemoryWorkspace cW = workspace.notifyScopeEntered()) {
INDArray array = Nd4j.create(100);
}
// should be 800 = 100 elements * 4 bytes per element * 2 as overallocation coefficient
assertEquals(200 * Nd4j.sizeOfDataType(), workspace.getCurrentSize());
}
use of org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration in project nd4j by deeplearning4j.
the class BasicWorkspaceTests method testOverallocation3.
@Test
public void testOverallocation3() throws Exception {
WorkspaceConfiguration overallocationConfig = WorkspaceConfiguration.builder().initialSize(0).maxSize(10 * 1024 * 1024).overallocationLimit(1.0).policyAllocation(AllocationPolicy.OVERALLOCATE).policyLearning(LearningPolicy.OVER_TIME).policyMirroring(MirroringPolicy.FULL).policySpill(SpillPolicy.EXTERNAL).build();
Nd4jWorkspace workspace = (Nd4jWorkspace) Nd4j.getWorkspaceManager().createNewWorkspace(overallocationConfig);
Nd4j.getMemoryManager().setCurrentWorkspace(workspace);
assertEquals(0, workspace.getCurrentSize());
for (int x = 10; x <= 100; x += 10) {
try (MemoryWorkspace cW = workspace.notifyScopeEntered()) {
INDArray array = Nd4j.create(x);
}
}
assertEquals(0, workspace.getCurrentSize());
workspace.initializeWorkspace();
// should be 800 = 100 elements * 4 bytes per element * 2 as overallocation coefficient
assertEquals(200 * Nd4j.sizeOfDataType(), workspace.getCurrentSize());
}
Aggregations