use of org.nd4j.jita.allocator.impl.AllocationPoint in project nd4j by deeplearning4j.
the class DelayedMemoryTest method testDelayedTAD1.
@Test
public void testDelayedTAD1() throws Exception {
TADManager tadManager = new DeviceTADManager();
INDArray array = Nd4j.create(128, 256);
Pair<DataBuffer, DataBuffer> tadBuffers = tadManager.getTADOnlyShapeInfo(array, new int[] { 0 });
DataBuffer tadBuffer = tadBuffers.getFirst();
DataBuffer offBuffer = tadBuffers.getSecond();
AllocationPoint pointTad = AtomicAllocator.getInstance().getAllocationPoint(tadBuffer);
AllocationPoint pointOff = AtomicAllocator.getInstance().getAllocationPoint(offBuffer);
assertEquals(AllocationStatus.CONSTANT, pointTad.getAllocationStatus());
assertEquals(AllocationStatus.DEVICE, pointOff.getAllocationStatus());
}
use of org.nd4j.jita.allocator.impl.AllocationPoint in project nd4j by deeplearning4j.
the class DelayedMemoryTest method testDelayedAllocation2.
/**
* This test should be run manually
*
* @throws Exception
*/
@Test
public void testDelayedAllocation2() throws Exception {
AtomicAllocator allocator = AtomicAllocator.getInstance();
INDArray array = Nd4j.create(10, 10);
AllocationPoint pointer = allocator.getAllocationPoint(array);
PointersPair pair = pointer.getPointers();
// pointers should be equal, device memory wasn't allocated yet
assertEquals(pair.getDevicePointer(), pair.getHostPointer());
// ////////////
AllocationPoint shapePointer = allocator.getAllocationPoint(array.shapeInfoDataBuffer());
// pointers should be equal, device memory wasn't allocated yet
assertEquals(shapePointer.getPointers().getDevicePointer(), shapePointer.getPointers().getHostPointer());
assertEquals(pointer.getAllocationStatus(), AllocationStatus.HOST);
assertEquals(shapePointer.getAllocationStatus(), AllocationStatus.HOST);
float sum = array.sumNumber().floatValue();
assertEquals(0.0f, sum, 0.0001f);
shapePointer = allocator.getAllocationPoint(array.shapeInfoDataBuffer());
pointer = allocator.getAllocationPoint(array);
assertEquals(AllocationStatus.CONSTANT, shapePointer.getAllocationStatus());
assertEquals(AllocationStatus.DEVICE, pointer.getAllocationStatus());
// at this point all pointers show be different, since we've used OP (sumNumber)
assertNotEquals(shapePointer.getPointers().getDevicePointer(), shapePointer.getPointers().getHostPointer());
}
use of org.nd4j.jita.allocator.impl.AllocationPoint in project nd4j by deeplearning4j.
the class DelayedMemoryTest method testDelayedAllocation3.
@Test
public void testDelayedAllocation3() throws Exception {
INDArray array = Nd4j.create(new float[] { 1f, 2f, 3f, 4f, 5f });
AllocationPoint pointer = AtomicAllocator.getInstance().getAllocationPoint(array);
PointersPair pair = pointer.getPointers();
// pointers should be equal, device memory wasn't allocated yet
assertEquals(pair.getDevicePointer(), pair.getHostPointer());
assertEquals(2.0f, array.getFloat(1), 0.001f);
assertEquals(pair.getDevicePointer(), pair.getHostPointer());
}
use of org.nd4j.jita.allocator.impl.AllocationPoint in project nd4j by deeplearning4j.
the class CudaFloatDataBufferTest method testDataCreation8.
@Test
public void testDataCreation8() throws Exception {
INDArray array = Nd4j.create(new float[] { 1, 2, 3, 4, 5 });
AllocationPoint pointMain = ((BaseCudaDataBuffer) array.data()).getAllocationPoint();
AllocationPoint pointShape = ((BaseCudaDataBuffer) array.shapeInfoDataBuffer()).getAllocationPoint();
assertFalse(pointMain.isConstant());
assertTrue(pointShape.isConstant());
}
use of org.nd4j.jita.allocator.impl.AllocationPoint in project nd4j by deeplearning4j.
the class CudaFloatDataBufferTest method testDataCreation4.
@Test
public void testDataCreation4() throws Exception {
BaseCudaDataBuffer buffer = (BaseCudaDataBuffer) Nd4j.createBuffer(new int[8]);
AllocationPoint point = buffer.getAllocationPoint();
assertEquals(true, point.isActualOnDeviceSide());
assertEquals(false, point.isActualOnHostSide());
System.out.println("AX --------------------------");
buffer.put(0, 10f);
System.out.println("AZ --------------------------");
assertEquals(AllocationStatus.DEVICE, point.getAllocationStatus());
}
Aggregations