/** * Ths method returns current profiling * * @return */ @Override public ProfilingMode getProfilingMode() { return backendExecutioner.getProfilingMode(); }
public long helperStartTransaction() { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.BANDWIDTH) return System.nanoTime(); else return 0L; }
public void helperRegisterTransaction(int deviceId, long timeSpentNanos, long numberOfBytes, @NonNull MemcpyDirection direction) { // only do something if profiling is enabled if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.BANDWIDTH) { addMemoryTransaction(deviceId, System.nanoTime() - timeSpentNanos, numberOfBytes, direction); } }
public static void checkForInf(Op op) { if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.INF_PANIC && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.ANY_PANIC) return; if (op.z() != null && !(op instanceof MatchCondition)) { checkForInf(op.z()); } }
public static void checkForNaN(Op op) { if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.NAN_PANIC && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.ANY_PANIC) return; if (op.z() != null && !(op instanceof MatchCondition)) { checkForNaN(op.z()); } }
public static void checkForNaN(CustomOp op) { if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.NAN_PANIC && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.ANY_PANIC) return; for (val input: op.inputArguments()) checkForNaN(input); for (val output: op.outputArguments()) checkForNaN(output); }
public static void checkForInf(CustomOp op) { if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.INF_PANIC && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.ANY_PANIC) return; for (val input: op.inputArguments()) checkForInf(input); for (val output: op.outputArguments()) checkForInf(output); }
public static void checkForNaN(INDArray z) { if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.NAN_PANIC && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.ANY_PANIC) return; int match = 0; if (!z.isScalar()) { MatchCondition condition = new MatchCondition(z, Conditions.isNan()); match = Nd4j.getExecutioner().exec(condition, Integer.MAX_VALUE).getInt(0); } else { if (z.data().dataType() == DataBuffer.Type.DOUBLE) { if (Double.isNaN(z.getDouble(0))) match = 1; } else { if (Float.isNaN(z.getFloat(0))) match = 1; } } if (match > 0) throw new ND4JIllegalStateException("P.A.N.I.C.! Op.Z() contains " + match + " NaN value(s): "); }
public static void checkForInf(INDArray z) { if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.INF_PANIC && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.ANY_PANIC) return; int match = 0; if (!z.isScalar()) { MatchCondition condition = new MatchCondition(z, Conditions.isInfinite()); match = Nd4j.getExecutioner().exec(condition, Integer.MAX_VALUE).getInt(0); } else { if (z.data().dataType() == DataBuffer.Type.DOUBLE) { if (Double.isInfinite(z.getDouble(0))) match = 1; } else { if (Float.isInfinite(z.getFloat(0))) match = 1; } } if (match > 0) throw new ND4JIllegalStateException("P.A.N.I.C.! Op.Z() contains " + match + " Inf value(s)"); }
@Override public double getDouble(long i) { if (i >= length()) { throw new IllegalArgumentException("Unable to get linear index >= " + length()); } if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.DISABLED && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.SCOPE_PANIC) OpProfiler.getInstance().processScalarCall(); if (i == 0) return data().getDouble(i); long[] dimensions = ordering() == 'c' ? Shape.ind2subC(this, i) : Shape.ind2sub(this, i); Shape.assertShapeLessThan(dimensions, shape()); return getDouble(dimensions); }
@Override public int iamax(long n, INDArray arr, int stride) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, arr); if (arr.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, arr); return idamax(n, arr, stride); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, arr); return isamax(n, arr, stride); } }
@Override public INDArray putScalar(long i, double value) { if (i < 0) i += rank(); if (isScalar()) { if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.DISABLED && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.SCOPE_PANIC) OpProfiler.getInstance().processScalarCall(); addOrUpdate(new long[] {0, 0}, value); return this; } if (isRowVector()) { addOrUpdate(new long[] {0, i}, value); return this; } else if (isColumnVector()) { addOrUpdate(new long[] {i, 0}, value); return this; } long[] indexes = ordering() == 'c' ? Shape.ind2subC(this, i) : Shape.ind2sub(this, i); return putScalar(indexes, value); }
/** * tpsv solves a system of linear equations whose coefficients are in a triangular packed matrix. * * @param order * @param Uplo * @param TransA * @param Diag * @param Ap * @param X */ @Override public void tpsv(char order, char Uplo, char TransA, char Diag, INDArray Ap, INDArray X) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, Ap, X); // FIXME: int cast if (X.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, X, Ap); dtpsv(order, Uplo, TransA, Diag, (int) X.length(), Ap, X, X.majorStride()); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, Ap, X); stpsv(order, Uplo, TransA, Diag, (int) X.length(), Ap, X, X.majorStride()); } OpExecutionerUtil.checkForAny(X); }
/** * ?tbsv solves a system of linear equations whose coefficients are in a triangular band matrix. * * @param order * @param Uplo * @param TransA * @param Diag * @param A * @param X */ @Override public void tbsv(char order, char Uplo, char TransA, char Diag, INDArray A, INDArray X) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, A, X); // FIXME: int cast if (X.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, A, X); dtbsv(order, Uplo, TransA, Diag, (int) X.length(), (int) A.columns(), A, (int) A.size(0), X, X.majorStride()); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, A, X); stbsv(order, Uplo, TransA, Diag, (int) X.length(), (int) A.columns(), A, (int) A.size(0), X, X.majorStride()); } }
/** * finds the element of a * vector that has the largest absolute value. * * @param arr * @return */ @Override public int iamax(INDArray arr) { if (arr.isSparse()) { return Nd4j.getSparseBlasWrapper().level1().iamax(arr); } if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, arr); if (arr.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, arr); return idamax(arr.length(), arr, BlasBufferUtil.getBlasStride(arr)); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, arr); return isamax(arr.length(), arr, BlasBufferUtil.getBlasStride(arr)); } }
/** * @param order * @param Uplo * @param alpha * @param X * @param Y * @param A */ @Override public void syr2(char order, char Uplo, double alpha, INDArray X, INDArray Y, INDArray A) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, A, X, Y); // FIXME: int cast if (X.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, A, X, Y); dsyr2(order, Uplo, (int) X.length(), alpha, X, X.majorStride(), Y, Y.majorStride(), A, (int) A.size(0)); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, A, X, Y); ssyr2(order, Uplo, (int) X.length(), (float) alpha, X, X.majorStride(), Y, Y.majorStride(), A, (int) A.size(0)); } OpExecutionerUtil.checkForAny(A); }
/** * computes a vector by a scalar product. * * @param N * @param alpha * @param X */ @Override public void scal(long N, double alpha, INDArray X) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, X); if (X.isSparse()) { Nd4j.getSparseBlasWrapper().level1().scal(N, alpha, X); } else if (X.data().dataType() == DataBuffer.Type.DOUBLE) dscal(N, alpha, X, BlasBufferUtil.getBlasStride(X)); else if (X.data().dataType() == DataBuffer.Type.FLOAT) sscal(N, (float) alpha, X, BlasBufferUtil.getBlasStride(X)); else if (X.data().dataType() == DataBuffer.Type.HALF) Nd4j.getExecutioner().exec(new ScalarMultiplication(X, alpha)); }
/** * swaps a vector with another vector. * * @param x * @param y */ @Override public void copy(INDArray x, INDArray y) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, x, y); if (x.isSparse() || y.isSparse()) { Nd4j.getSparseBlasWrapper().level1().copy(x, y); return; } if (x.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, x, y); dcopy(x.length(), x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y)); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, x, y); scopy(x.length(), x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y)); } }
/** * swaps a vector with another vector. * * @param x * @param y */ @Override public void swap(INDArray x, INDArray y) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, x, y); if (x.isSparse() || y.isSparse()) { Nd4j.getSparseBlasWrapper().level1().swap(x, y); return; } if (x.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, x, y); dswap(x.length(), x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y)); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, x, y); sswap(x.length(), x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y)); } }
/** * computes the sum of magnitudes of all vector elements or, for a complex vector x, the sum * * @param arr * @return */ @Override public double asum(INDArray arr) { if (arr.isSparse()) { return Nd4j.getSparseBlasWrapper().level1().asum(arr); } if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, arr); if (arr.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, arr); return dasum(arr.length(), arr, BlasBufferUtil.getBlasStride(arr)); } else if (arr.data().dataType() == DataBuffer.Type.FLOAT) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, arr); return sasum(arr.length(), arr, BlasBufferUtil.getBlasStride(arr)); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.HALF, arr); return hasum(arr.length(), arr, BlasBufferUtil.getBlasStride(arr)); } }