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());
}
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());
}
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();
}
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());
}
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);
}
Aggregations