use of org.nd4j.linalg.api.ops.impl.scalar.ScalarMultiplication in project nd4j by deeplearning4j.
the class GridExecutionerTest method testOpPointerizeScalar1.
// ///////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////
/*
Pointerize tests are checking how Ops are converted into GridPointers
*/
// ///////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////
@Test
public void testOpPointerizeScalar1() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
INDArray array = Nd4j.create(10);
ScalarMultiplication opA = new ScalarMultiplication(array, 10f);
GridPointers pointers = executioner.pointerizeOp(opA, null);
assertEquals(opA.opNum(), pointers.getOpNum());
assertEquals(Op.Type.SCALAR, pointers.getType());
CudaContext context = (CudaContext) AtomicAllocator.getInstance().getDeviceContext().getContext();
Pointer x = AtomicAllocator.getInstance().getPointer(array, context);
Pointer xShapeInfo = AtomicAllocator.getInstance().getPointer(array.shapeInfoDataBuffer(), context);
assertEquals(x, pointers.getX());
assertEquals(null, pointers.getY());
assertEquals(x, pointers.getZ());
assertEquals(1, pointers.getXStride());
assertEquals(-1, pointers.getYStride());
assertEquals(1, pointers.getZStride());
assertEquals(xShapeInfo, pointers.getXShapeInfo());
assertEquals(null, pointers.getYShapeInfo());
assertEquals(xShapeInfo, pointers.getZShapeInfo());
assertEquals(null, pointers.getDimensions());
assertEquals(0, pointers.getDimensionsLength());
assertEquals(null, pointers.getTadShape());
assertEquals(null, pointers.getTadOffsets());
assertEquals(null, pointers.getExtraArgs());
}
use of org.nd4j.linalg.api.ops.impl.scalar.ScalarMultiplication in project nd4j by deeplearning4j.
the class MetaOpTests method testEnqueuePerformance1.
@Test
public void testEnqueuePerformance1() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
INDArray arrayX = Nd4j.create(65536);
INDArray arrayY = Nd4j.create(65536);
Set opA = new Set(arrayX, arrayY, arrayX, arrayX.length());
ScalarMultiplication opB = new ScalarMultiplication(arrayX, 2.0f);
// ScalarAdd opB = new ScalarAdd(arrayX, 3.0f);
PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);
executioner.prepareGrid(metaOp);
GridDescriptor descriptor = metaOp.getGridDescriptor();
assertEquals(2, descriptor.getGridDepth());
assertEquals(2, descriptor.getGridPointers().size());
assertEquals(Op.Type.PAIRWISE, descriptor.getGridPointers().get(0).getType());
assertEquals(Op.Type.SCALAR, descriptor.getGridPointers().get(1).getType());
long time1 = System.nanoTime();
for (int x = 0; x < 10000000; x++) {
executioner.exec(opA);
executioner.purgeQueue();
}
long time2 = System.nanoTime();
System.out.println("Enqueue time: " + ((time2 - time1) / 10000000));
}
use of org.nd4j.linalg.api.ops.impl.scalar.ScalarMultiplication in project nd4j by deeplearning4j.
the class MetaOpTests method testPerformance1.
@Test
public void testPerformance1() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
/* INDArray array = Nd4j.create(new float[]{-11f, -12f, -13f, -14f, -15f, -16f, -17f, -18f, -19f, -20f});
INDArray exp = Nd4j.create(new float[]{1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f});
INDArray exp2 = Nd4j.create(new float[]{11f, 12f, 13f, 14f, 15f, 16f, 17f, 18f, 19f, 20f});
*/
INDArray arrayX = Nd4j.create(65536);
INDArray arrayY = Nd4j.create(65536);
INDArray exp2 = Nd4j.create(65536);
Set opA = new Set(arrayX, arrayY, arrayX, arrayX.length());
ScalarMultiplication opB = new ScalarMultiplication(arrayX, 2.0f);
// ScalarAdd opB = new ScalarAdd(arrayX, 3.0f);
PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);
executioner.prepareGrid(metaOp);
GridDescriptor descriptor = metaOp.getGridDescriptor();
assertEquals(2, descriptor.getGridDepth());
assertEquals(2, descriptor.getGridPointers().size());
assertEquals(Op.Type.PAIRWISE, descriptor.getGridPointers().get(0).getType());
assertEquals(Op.Type.SCALAR, descriptor.getGridPointers().get(1).getType());
long time1 = System.nanoTime();
for (int x = 0; x < 1000000; x++) {
executioner.exec(metaOp);
}
long time2 = System.nanoTime();
System.out.println("Execution time Meta: " + ((time2 - time1) / 1000000));
// assertEquals(exp, array);
time1 = System.nanoTime();
for (int x = 0; x < 1000000; x++) {
Nd4j.getExecutioner().exec(opA);
Nd4j.getExecutioner().exec(opB);
}
time2 = System.nanoTime();
System.out.println("Execution time Linear: " + ((time2 - time1) / 1000000));
// assertEquals(exp2, array);
}
use of org.nd4j.linalg.api.ops.impl.scalar.ScalarMultiplication in project nd4j by deeplearning4j.
the class MetaOpTests method testPredicateScalarPairwise3.
/*
@Ignore
@Test
public void testPredicateScalarPairwise1() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
INDArray arrayX = Nd4j.create(new float[]{0f, 0f, 0f, 0f, 0f, 0f});
INDArray arrayY = Nd4j.create(new float[]{2f, 2f, 2f, 2f, 2f, 2f});
INDArray exp = Nd4j.create(new float[]{3f, 3f, 3f, 3f, 3f, 3f});
ScalarAdd opA = new ScalarAdd(arrayX, 1.0f);
AddOp opB = new AddOp(arrayX, arrayY, arrayX);
PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);
executioner.prepareGrid(metaOp);
long time1 = System.nanoTime();
executioner.exec(metaOp);
long time2 = System.nanoTime();
System.out.println("Execution time Meta: " + ((time2 - time1) / 1));
assertEquals(exp, arrayX);
}
@Ignore
@Test
public void testPredicateScalarPairwise2() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
INDArray arrayX = Nd4j.create(new float[]{0f, 0f, 0f, 0f, 0f, 0f});
INDArray arrayY = Nd4j.create(new float[]{2f, 2f, 2f, 2f, 2f, 2f});
INDArray exp = Nd4j.create(new float[]{1f, 1f, 1f, 1f, 1f, 1f});
ScalarSubtraction opA = new ScalarSubtraction(arrayX, 1.0f);
AddOp opB = new AddOp(arrayX, arrayY, arrayX);
PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);
executioner.prepareGrid(metaOp);
long time1 = System.nanoTime();
executioner.exec(metaOp);
long time2 = System.nanoTime();
System.out.println("Execution time Meta: " + ((time2 - time1) / 1));
assertEquals(exp, arrayX);
}
*/
/**
* This is the MOST crucial test, basically it's test for dup() + following linear op
*
* @throws Exception
*/
@Test
public void testPredicateScalarPairwise3() throws Exception {
CudaGridExecutioner executioner = new CudaGridExecutioner();
INDArray arrayX = Nd4j.create(new float[] { 0f, 0f, 0f, 0f, 0f, 0f });
INDArray arrayY = Nd4j.create(new float[] { 1f, 2f, 3f, 4f, 5f, 6f });
INDArray exp = Nd4j.create(new float[] { 2f, 4f, 6f, 8f, 10f, 12f });
Set opA = new Set(arrayX, arrayY, arrayX, arrayX.length());
ScalarMultiplication opB = new ScalarMultiplication(arrayX, 2.0f);
// ScalarAdd opB = new ScalarAdd(arrayX, 3.0f);
PredicateMetaOp metaOp = new PredicateMetaOp(opA, opB);
executioner.prepareGrid(metaOp);
long time1 = System.nanoTime();
executioner.exec(metaOp);
long time2 = System.nanoTime();
System.out.println("Execution time Meta: " + ((time2 - time1) / 1));
assertEquals(exp, arrayX);
}
Aggregations