Search in sources :

Example 61 with AllocationPoint

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

the class CudaFloatDataBufferTest method testDataCreation2.

@Test
public void testDataCreation2() throws Exception {
    BaseCudaDataBuffer buffer = (BaseCudaDataBuffer) Nd4j.createBuffer(new int[] { 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)

Example 62 with AllocationPoint

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

the class CudaFloatDataBufferTest method testDataCreation5.

@Test
public void testDataCreation5() throws Exception {
    INDArray array = Nd4j.create(new double[][] { { 0, 2 }, { 2, 1 } });
    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 63 with AllocationPoint

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

the class WeirdSparkTests method testMultithreadedFree1.

@Test
@Ignore
public void testMultithreadedFree1() throws Exception {
    final DataBuffer buffer = Nd4j.createBuffer(500000000, 0);
    Thread.sleep(5000);
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            System.out.println("Current device: " + AtomicAllocator.getInstance().getDeviceId());
            AllocationPoint point = AtomicAllocator.getInstance().getAllocationPoint(buffer);
            AtomicAllocator.getInstance().getMemoryHandler().getMemoryProvider().free(point);
            System.out.println("Pointer released");
            try {
                Thread.sleep(100000);
            } catch (Exception e) {
            }
        }
    });
    thread.start();
    thread.join();
}
Also used : AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 64 with AllocationPoint

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

the class ProtectedCudaShapeInfoProviderTest method testPurge2.

@Test
public void testPurge2() throws Exception {
    INDArray arrayA = Nd4j.create(10, 10);
    DataBuffer shapeInfoA = arrayA.shapeInfoDataBuffer();
    INDArray arrayE = Nd4j.create(10, 10);
    DataBuffer shapeInfoE = arrayE.shapeInfoDataBuffer();
    int[] arrayShapeA = shapeInfoA.asInt();
    assertTrue(shapeInfoA == shapeInfoE);
    ShapeDescriptor descriptor = new ShapeDescriptor(arrayA.shape(), arrayA.stride(), 0, arrayA.elementWiseStride(), arrayA.ordering());
    ConstantProtector protector = ConstantProtector.getInstance();
    AllocationPoint pointA = AtomicAllocator.getInstance().getAllocationPoint(arrayA.shapeInfoDataBuffer());
    assertEquals(true, protector.containsDataBuffer(0, descriptor));
    // //////////////////////////////////
    Nd4j.getMemoryManager().purgeCaches();
    // //////////////////////////////////
    assertEquals(false, protector.containsDataBuffer(0, descriptor));
    INDArray arrayB = Nd4j.create(10, 10);
    DataBuffer shapeInfoB = arrayB.shapeInfoDataBuffer();
    assertFalse(shapeInfoA == shapeInfoB);
    AllocationPoint pointB = AtomicAllocator.getInstance().getAllocationPoint(arrayB.shapeInfoDataBuffer());
    assertArrayEquals(arrayShapeA, shapeInfoB.asInt());
    // pointers should be equal, due to offsets reset
    assertEquals(pointA.getPointers().getDevicePointer().address(), pointB.getPointers().getDevicePointer().address());
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) ShapeDescriptor(org.nd4j.linalg.api.shape.ShapeDescriptor) DataBuffer(org.nd4j.linalg.api.buffer.DataBuffer) Test(org.junit.Test)

Example 65 with AllocationPoint

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

the class CudaDirectProviderTest method mallocHost.

@Test
public void mallocHost() throws Exception {
    CudaDirectProvider provider = new CudaDirectProvider();
    AllocationShape shape = new AllocationShape(100000, 4, DataBuffer.Type.FLOAT);
    AllocationPoint point = new AllocationPoint();
    point.setShape(shape);
    point.setPointers(provider.malloc(shape, point, AllocationStatus.HOST));
    System.out.println("Allocated...");
    Thread.sleep(1000);
    provider.free(point);
    System.out.println("Deallocated...");
    Thread.sleep(1000);
}
Also used : AllocationShape(org.nd4j.jita.allocator.impl.AllocationShape) 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