Search in sources :

Example 1 with GridDescriptor

use of org.nd4j.linalg.api.ops.grid.GridDescriptor 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));
}
Also used : GridDescriptor(org.nd4j.linalg.api.ops.grid.GridDescriptor) Set(org.nd4j.linalg.api.ops.impl.transforms.Set) INDArray(org.nd4j.linalg.api.ndarray.INDArray) PredicateMetaOp(org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp) ScalarMultiplication(org.nd4j.linalg.api.ops.impl.scalar.ScalarMultiplication) Test(org.junit.Test)

Example 2 with GridDescriptor

use of org.nd4j.linalg.api.ops.grid.GridDescriptor in project nd4j by deeplearning4j.

the class BaseGridOp method getGridDescriptor.

@Override
public GridDescriptor getGridDescriptor() {
    GridDescriptor descriptor = new GridDescriptor();
    descriptor.setGridDepth(grid.size());
    descriptor.setGridPointers(grid);
    return descriptor;
}
Also used : GridDescriptor(org.nd4j.linalg.api.ops.grid.GridDescriptor)

Example 3 with GridDescriptor

use of org.nd4j.linalg.api.ops.grid.GridDescriptor in project nd4j by deeplearning4j.

the class MetaOpTests method testLinearMetaOp1.

@Ignore
@Test
public void testLinearMetaOp1() 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 });
    ScalarAdd opA = new ScalarAdd(array, 10f);
    Abs opB = new Abs(array);
    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.SCALAR, descriptor.getGridPointers().get(0).getType());
    assertEquals(Op.Type.TRANSFORM, descriptor.getGridPointers().get(1).getType());
    long time1 = System.nanoTime();
    executioner.exec(metaOp);
    long time2 = System.nanoTime();
    System.out.println("Execution time Meta: " + ((time2 - time1) / 1));
    assertEquals(exp, array);
    time1 = System.nanoTime();
    Nd4j.getExecutioner().exec(opA);
    Nd4j.getExecutioner().exec(opB);
    time2 = System.nanoTime();
    System.out.println("Execution time Linear: " + ((time2 - time1) / 1));
    assertEquals(exp2, array);
}
Also used : GridDescriptor(org.nd4j.linalg.api.ops.grid.GridDescriptor) ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) Abs(org.nd4j.linalg.api.ops.impl.transforms.Abs) INDArray(org.nd4j.linalg.api.ndarray.INDArray) PredicateMetaOp(org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with GridDescriptor

use of org.nd4j.linalg.api.ops.grid.GridDescriptor 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);
}
Also used : GridDescriptor(org.nd4j.linalg.api.ops.grid.GridDescriptor) Set(org.nd4j.linalg.api.ops.impl.transforms.Set) INDArray(org.nd4j.linalg.api.ndarray.INDArray) PredicateMetaOp(org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp) ScalarMultiplication(org.nd4j.linalg.api.ops.impl.scalar.ScalarMultiplication) Test(org.junit.Test)

Example 5 with GridDescriptor

use of org.nd4j.linalg.api.ops.grid.GridDescriptor in project nd4j by deeplearning4j.

the class MetaOpTests method testLinearMetaOp2.

@Ignore
@Test
public void testLinearMetaOp2() 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[] { 21f, 22f, 23f, 24f, 25f, 26f, 27f, 28f, 29f, 30f });
    INDArray exp2 = Nd4j.create(new float[] { 31f, 32f, 33f, 34f, 35f, 36f, 37f, 38f, 39f, 40f });
    Abs opA = new Abs(array);
    ScalarAdd opB = new ScalarAdd(array, 10f);
    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.TRANSFORM, descriptor.getGridPointers().get(0).getType());
    assertEquals(Op.Type.SCALAR, descriptor.getGridPointers().get(1).getType());
    long time1 = System.nanoTime();
    executioner.exec(metaOp);
    long time2 = System.nanoTime();
    System.out.println("Execution time Meta: " + ((time2 - time1) / 1));
    assertEquals(exp, array);
    time1 = System.nanoTime();
    Nd4j.getExecutioner().exec(opA);
    Nd4j.getExecutioner().exec(opB);
    time2 = System.nanoTime();
    System.out.println("Execution time Linear: " + ((time2 - time1) / 1));
    assertEquals(exp2, array);
}
Also used : GridDescriptor(org.nd4j.linalg.api.ops.grid.GridDescriptor) ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) Abs(org.nd4j.linalg.api.ops.impl.transforms.Abs) INDArray(org.nd4j.linalg.api.ndarray.INDArray) PredicateMetaOp(org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

GridDescriptor (org.nd4j.linalg.api.ops.grid.GridDescriptor)5 Test (org.junit.Test)4 INDArray (org.nd4j.linalg.api.ndarray.INDArray)4 PredicateMetaOp (org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp)4 Ignore (org.junit.Ignore)2 ScalarAdd (org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd)2 ScalarMultiplication (org.nd4j.linalg.api.ops.impl.scalar.ScalarMultiplication)2 Abs (org.nd4j.linalg.api.ops.impl.transforms.Abs)2 Set (org.nd4j.linalg.api.ops.impl.transforms.Set)2