Search in sources :

Example 21 with AllocationPoint

use of org.nd4j.jita.allocator.impl.AllocationPoint in project nd4j by deeplearning4j.

the class CudaFloatDataBufferTest method testDataCreation9.

@Test
public void testDataCreation9() throws Exception {
    INDArray array = Nd4j.create(20);
    AllocationPoint pointMain = ((BaseCudaDataBuffer) array.data()).getAllocationPoint();
    AllocationPoint pointShape = ((BaseCudaDataBuffer) array.shapeInfoDataBuffer()).getAllocationPoint();
    assertFalse(pointMain.isConstant());
    assertTrue(pointShape.isConstant());
    assertEquals(true, pointMain.isActualOnDeviceSide());
    assertEquals(true, pointMain.isActualOnHostSide());
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) Test(org.junit.Test)

Example 22 with AllocationPoint

use of org.nd4j.jita.allocator.impl.AllocationPoint in project nd4j by deeplearning4j.

the class CudaFloatDataBufferTest method testDataCreation7.

@Test
public void testDataCreation7() throws Exception {
    INDArray array = Nd4j.zeros(1500, 150);
    AllocationPoint pointMain = ((BaseCudaDataBuffer) array.data()).getAllocationPoint();
    AllocationPoint pointShape = ((BaseCudaDataBuffer) array.shapeInfoDataBuffer()).getAllocationPoint();
    assertEquals(true, pointMain.isActualOnDeviceSide());
    assertEquals(true, pointMain.isActualOnHostSide());
    assertEquals(true, pointShape.isActualOnDeviceSide());
    assertEquals(true, pointShape.isActualOnHostSide());
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) Test(org.junit.Test)

Example 23 with AllocationPoint

use of org.nd4j.jita.allocator.impl.AllocationPoint in project nd4j by deeplearning4j.

the class CudaFloatDataBufferTest method testDataCreation1.

@Test
public void testDataCreation1() throws Exception {
    BaseCudaDataBuffer buffer = (BaseCudaDataBuffer) Nd4j.createBuffer(10);
    AllocationPoint point = buffer.getAllocationPoint();
    CudaContext context = AtomicAllocator.getInstance().getContextPool().acquireContextForDevice(0);
    assertEquals(true, point.isActualOnHostSide());
    buffer.put(0, 10f);
    assertEquals(true, point.isActualOnHostSide());
    assertEquals(false, point.isActualOnDeviceSide());
    buffer.put(1, 10f);
    assertEquals(true, point.isActualOnHostSide());
    assertEquals(false, point.isActualOnDeviceSide());
    AtomicAllocator.getInstance().getPointer(buffer, context);
    assertEquals(true, point.isActualOnHostSide());
    assertEquals(true, point.isActualOnDeviceSide());
    System.out.println("AM ------------------------------------");
    AtomicAllocator.getInstance().getHostPointer(buffer);
    System.out.println("AN ------------------------------------");
    assertEquals(true, point.isActualOnHostSide());
    assertEquals(true, point.isActualOnDeviceSide());
}
Also used : CudaContext(org.nd4j.linalg.jcublas.context.CudaContext) AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) Test(org.junit.Test)

Example 24 with AllocationPoint

use of org.nd4j.jita.allocator.impl.AllocationPoint in project nd4j by deeplearning4j.

the class CudaFloatDataBufferTest method testDataCreation6.

@Test
public void testDataCreation6() throws Exception {
    INDArray array = Nd4j.create(new double[] { 0, 1, 2, 3 });
    AllocationPoint pointMain = ((BaseCudaDataBuffer) array.data()).getAllocationPoint();
    AllocationPoint pointShape = ((BaseCudaDataBuffer) array.shapeInfoDataBuffer()).getAllocationPoint();
    assertEquals(true, pointShape.isActualOnDeviceSide());
    assertEquals(true, pointShape.isActualOnHostSide());
    assertEquals(true, pointMain.isActualOnDeviceSide());
    assertEquals(false, pointMain.isActualOnHostSide());
    assertEquals(AllocationStatus.DEVICE, pointMain.getAllocationStatus());
    assertEquals(AllocationStatus.CONSTANT, pointShape.getAllocationStatus());
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) Test(org.junit.Test)

Example 25 with AllocationPoint

use of org.nd4j.jita.allocator.impl.AllocationPoint in project nd4j by deeplearning4j.

the class CudaFloatDataBufferTest method testDataCreation3.

@Test
public void testDataCreation3() throws Exception {
    BaseCudaDataBuffer buffer = (BaseCudaDataBuffer) Nd4j.createBuffer(new float[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
    AllocationPoint point = buffer.getAllocationPoint();
    CudaContext context = AtomicAllocator.getInstance().getContextPool().acquireContextForDevice(0);
    assertEquals(true, point.isActualOnDeviceSide());
    assertEquals(false, point.isActualOnHostSide());
    System.out.println("AX --------------------------");
    buffer.put(0, 10f);
    System.out.println("AZ --------------------------");
    assertEquals(true, point.isActualOnHostSide());
    assertEquals(false, point.isActualOnDeviceSide());
    buffer.put(1, 10f);
    assertEquals(true, point.isActualOnHostSide());
    assertEquals(false, point.isActualOnDeviceSide());
    AtomicAllocator.getInstance().getPointer(buffer, context);
    assertEquals(true, point.isActualOnHostSide());
    assertEquals(true, point.isActualOnDeviceSide());
    System.out.println("AM ------------------------------------");
    AtomicAllocator.getInstance().getHostPointer(buffer);
    System.out.println("AN ------------------------------------");
    assertEquals(true, point.isActualOnHostSide());
    assertEquals(true, point.isActualOnDeviceSide());
    assertEquals(AllocationStatus.DEVICE, point.getAllocationStatus());
}
Also used : CudaContext(org.nd4j.linalg.jcublas.context.CudaContext) 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