Search in sources :

Example 56 with AllocationPoint

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());
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) TADManager(org.nd4j.linalg.cache.TADManager) DeviceTADManager(org.nd4j.jita.allocator.tad.DeviceTADManager) DeviceTADManager(org.nd4j.jita.allocator.tad.DeviceTADManager) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer) Test(org.junit.Test)

Example 57 with AllocationPoint

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());
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) PointersPair(org.nd4j.jita.allocator.pointers.PointersPair) AtomicAllocator(org.nd4j.jita.allocator.impl.AtomicAllocator) AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) Test(org.junit.Test)

Example 58 with AllocationPoint

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());
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) PointersPair(org.nd4j.jita.allocator.pointers.PointersPair) AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) Test(org.junit.Test)

Example 59 with AllocationPoint

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());
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) Test(org.junit.Test)

Example 60 with AllocationPoint

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());
}
Also used : AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) Test(org.junit.Test)

Aggregations

AllocationPoint (org.nd4j.jita.allocator.impl.AllocationPoint)67 INDArray (org.nd4j.linalg.api.ndarray.INDArray)33 Test (org.junit.Test)31 CudaContext (org.nd4j.linalg.jcublas.context.CudaContext)24 CudaPointer (org.nd4j.jita.allocator.pointers.CudaPointer)15 DataBuffer (org.nd4j.linalg.api.buffer.DataBuffer)11 ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)11 AtomicAllocator (org.nd4j.jita.allocator.impl.AtomicAllocator)7 BaseCudaDataBuffer (org.nd4j.linalg.jcublas.buffer.BaseCudaDataBuffer)7 Pointer (org.bytedeco.javacpp.Pointer)6 AllocationShape (org.nd4j.jita.allocator.impl.AllocationShape)5 PointersPair (org.nd4j.jita.allocator.pointers.PointersPair)5 MemoryWorkspace (org.nd4j.linalg.api.memory.MemoryWorkspace)4 JCublasNDArray (org.nd4j.linalg.jcublas.JCublasNDArray)3 CudaDoubleDataBuffer (org.nd4j.linalg.jcublas.buffer.CudaDoubleDataBuffer)3 CompressedDataBuffer (org.nd4j.linalg.compression.CompressedDataBuffer)2 DeviceLocalNDArray (org.nd4j.linalg.util.DeviceLocalNDArray)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 FileInputStream (java.io.FileInputStream)1