This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.nd4j.linalg.api.ndarray.INDArray | |
import org.nd4j.linalg.api.ops.impl.broadcast.BroadcastAddOp | |
import org.nd4j.linalg.api.rng.distribution.impl.UniformDistribution | |
import org.nd4j.linalg.factory.Nd4j | |
import scala.util.Random | |
object Xavier { | |
def init(shape: Array[Int]): INDArray = { | |
var n = shape.dropRight(1).product |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Slow { | |
public static void main(String[] args) { | |
int hiddenDim = 200; | |
int numChar = 100; | |
int length = 500; | |
int batchSize = 50; | |
int[] pshape = new int[]{numChar, hiddenDim}; | |
INDArray c2v = xavier(pshape); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Concat time: 24630 us | |
Concat time: 147 us | |
Concat time: 208 us | |
Concat time: 136 us | |
Concat time: 125 us | |
Concat time: 130 us | |
Concat time: 123 us | |
Concat time: 118 us | |
Concat time: 119 us | |
Concat time: 115 us |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
fast(); | |
slow(); | |
} | |
static void fast() { | |
int hiddenDim = 200; | |
int numChar = 100; | |
int length = 500; | |
int batchSize = 50; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2017-03-06 13:53:13,431 INFO [main] o.n.l.f.Nd4jBackend [Nd4jBackend.java:194] Loaded [CpuBackend] backend | |
2017-03-06 13:53:13,547 INFO [main] o.n.n.NativeOpsHolder [NativeOpsHolder.java:38] Number of threads used for NativeOps: 4 | |
2017-03-06 13:53:13,802 INFO [main] o.r.Reflections [Reflections.java:229] Reflections took 202 ms to scan 11 urls, producing 29 keys and 176 values | |
2017-03-06 13:53:14,055 INFO [main] o.n.n.Nd4jBlas [Nd4jBlas.java:38] Number of threads used for BLAS: 4 | |
2017-03-06 13:53:14,520 INFO [main] e.u.c.e.n.Slow [Slow.java:117] GEMM tests: | |
2017-03-06 13:53:14,534 INFO [main] e.u.c.e.n.Slow [Slow.java:125] Concat time: 7586 us | |
2017-03-06 13:53:14,556 INFO [main] e.u.c.e.n.Slow [Slow.java:125] Concat time: 138 us | |
2017-03-06 13:53:14,571 INFO [main] e.u.c.e.n.Slow [Slow.java:125] Concat time: 88 us | |
2017-03-06 13:53:14,602 INFO [main] e.u.c.e.n.Slow [Slow.java:125] Concat time: 65 us | |
2017-03-06 13:53:14,637 INFO [main] e.u.c.e.n.Slow [Slow.java:125] Concat time: 101 us |