Search in sources :

Example 11 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class GridExecutionerTest method isMatchingMetaOp4.

@Test
public void isMatchingMetaOp4() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray arrayX = Nd4j.create(10);
    INDArray arrayY = Nd4j.create(10);
    Set opA = new Set(arrayX, arrayY, arrayX, arrayX.length());
    ScalarAdd opB = new ScalarAdd(arrayX, 10f);
    executioner.exec(opA);
    assertEquals(CudaGridExecutioner.MetaType.INVERTED_PREDICATE, executioner.getMetaOpType(opB));
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) ScalarSet(org.nd4j.linalg.api.ops.impl.scalar.ScalarSet) Set(org.nd4j.linalg.api.ops.impl.transforms.Set) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test)

Example 12 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class GridExecutionerTest method testGridFlowFlush2.

@Test
public void testGridFlowFlush2() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray arrayX = Nd4j.create(10);
    INDArray arrayX2 = Nd4j.create(10);
    INDArray arrayY = Nd4j.create(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f });
    INDArray exp = Nd4j.create(new float[] { 3f, 3f, 3f, 3f, 3f, 3f, 3f, 3f, 3f, 3f });
    INDArray exp2 = Nd4j.create(new float[] { 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f });
    Set opA = new Set(arrayX, arrayY, arrayX, arrayX.length());
    executioner.exec(opA);
    assertEquals(1, executioner.getQueueLength());
    ScalarAdd opB = new ScalarAdd(arrayX2, 10f);
    executioner.exec(opB);
    assertEquals(0, executioner.getQueueLength());
    assertEquals(arrayY, arrayX);
    assertEquals(exp2, arrayX2);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) ScalarSet(org.nd4j.linalg.api.ops.impl.scalar.ScalarSet) Set(org.nd4j.linalg.api.ops.impl.transforms.Set) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Test(org.junit.Test)

Example 13 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class GridExecutionerTest method testGridPerformance1.

// ///////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////
/*
    Performance test for combined op
*/
// ///////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////
@Test
public void testGridPerformance1() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray arrayX = Nd4j.create(1024);
    INDArray arrayY = Nd4j.create(1024);
    Set opA = new Set(arrayX, arrayY, arrayX, arrayX.length());
    ScalarAdd opB = new ScalarAdd(arrayX, 2f);
    long time1 = System.nanoTime();
    for (int x = 0; x < 1000000; x++) {
        executioner.exec(opA);
        executioner.exec(opB);
    }
    long time2 = System.nanoTime();
    System.out.println("Execution time Meta: " + ((time2 - time1) / 1000000));
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) ScalarSet(org.nd4j.linalg.api.ops.impl.scalar.ScalarSet) Set(org.nd4j.linalg.api.ops.impl.transforms.Set) INDArray(org.nd4j.linalg.api.ndarray.INDArray) AllocationPoint(org.nd4j.jita.allocator.impl.AllocationPoint) Test(org.junit.Test)

Example 14 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class GridExecutionerTest method testGridFlow1.

// /////////////////////////////////////////////////////////////////////////
/*/////////////////////////////////////////////////////////////////////////

    GridFlow tests are checking how ops are getting queued upon exec() calls

*/
// ///////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
@Test
public void testGridFlow1() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    assertEquals(0, executioner.getQueueLength());
    INDArray array = Nd4j.create(10);
    ScalarAdd opA = new ScalarAdd(array, 10f);
    executioner.exec(opA);
    long time1 = System.nanoTime();
    Max opB = new Max(array);
    executioner.exec(opB);
    assertEquals(0, executioner.getQueueLength());
    long time2 = System.nanoTime();
    opB = new Max(array);
    executioner.exec(opB);
    long time3 = System.nanoTime();
    assertEquals(0, executioner.getQueueLength());
    long firstExec = time2 - time1;
    long secondExec = time3 - time2;
    System.out.println("First exec time: " + firstExec);
    System.out.println("Second exec time: " + secondExec);
    System.out.println("Array: " + array);
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Max(org.nd4j.linalg.api.ops.impl.accum.Max) Test(org.junit.Test)

Example 15 with ScalarAdd

use of org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd in project nd4j by deeplearning4j.

the class GridExecutionerTest method isMatchingMetaOp3.

@Test
public void isMatchingMetaOp3() throws Exception {
    CudaGridExecutioner executioner = new CudaGridExecutioner();
    INDArray array = Nd4j.create(10);
    ScalarAdd opA = new ScalarAdd(array, 10f);
    Max opB = new Max(array);
    executioner.exec(opA);
    assertEquals(CudaGridExecutioner.MetaType.NOT_APPLICABLE, executioner.getMetaOpType(opB));
}
Also used : ScalarAdd(org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Max(org.nd4j.linalg.api.ops.impl.accum.Max) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 INDArray (org.nd4j.linalg.api.ndarray.INDArray)21 ScalarAdd (org.nd4j.linalg.api.ops.impl.scalar.ScalarAdd)21 ScalarSet (org.nd4j.linalg.api.ops.impl.scalar.ScalarSet)4 Set (org.nd4j.linalg.api.ops.impl.transforms.Set)4 Ignore (org.junit.Ignore)3 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)3 Max (org.nd4j.linalg.api.ops.impl.accum.Max)3 PredicateMetaOp (org.nd4j.linalg.api.ops.impl.meta.PredicateMetaOp)3 GridDescriptor (org.nd4j.linalg.api.ops.grid.GridDescriptor)2 Abs (org.nd4j.linalg.api.ops.impl.transforms.Abs)2 AllocationPoint (org.nd4j.jita.allocator.impl.AllocationPoint)1 OpDescriptor (org.nd4j.linalg.api.ops.grid.OpDescriptor)1 Sum (org.nd4j.linalg.api.ops.impl.accum.Sum)1 ReduceMetaOp (org.nd4j.linalg.api.ops.impl.meta.ReduceMetaOp)1