/** * @param alpha * @param x * @param y * @param a * @return */ public static IComplexNDArray geru(IComplexNumber alpha, IComplexNDArray x, IComplexNDArray y, IComplexNDArray a) { DataTypeValidation.assertSameDataType(x, y, a); throw new UnsupportedOperationException(); }
/** * @param da * @param A * @param B */ public static void axpy(IComplexNumber da, IComplexNDArray A, IComplexNDArray B) { DataTypeValidation.assertSameDataType(A, B); throw new UnsupportedOperationException(); }
/** * Dot product between two complex ndarrays * * @param x * @param y * @return */ public static IComplexDouble dot(IComplexNDArray x, IComplexNDArray y) { DataTypeValidation.assertSameDataType(x, y); throw new UnsupportedOperationException(); }
/** * Copy x to y * * @param x the origin * @param y the destination */ public static void copy(IComplexNDArray x, IComplexNDArray y) { DataTypeValidation.assertSameDataType(x, y); Nd4j.getExecutioner().exec(new CopyOp(x, y, y, x.length())); }
@Override protected float hdot(int N, INDArray X, int incX, INDArray Y, int incY) { DataTypeValidation.assertSameDataType(X, Y); // CudaContext ctx = allocator.getFlowController().prepareAction(null, X, Y); float ret = 1f; // CublasPointer xCPointer = new CublasPointer(X, ctx); // CublasPointer yCPointer = new CublasPointer(Y, ctx); Dot dot = new Dot(X, Y); Nd4j.getExecutioner().exec(dot); ret = dot.getFinalResult().floatValue(); /* cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { long result = cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); if (result != 0) throw new IllegalStateException("cublasSetStream failed"); FloatPointer resultPointer = new FloatPointer(0.0f); cuBlasSdot_v2(new cublasContext(handle), N, xCPointer.getDevicePointer(), incX, yCPointer.getDevicePointer(), incY, resultPointer); ret = resultPointer.get(); } */ // allocator.registerAction(ctx, null, X, Y); return ret; }
@Override protected float hdot(long N, INDArray X, int incX, INDArray Y, int incY) { DataTypeValidation.assertSameDataType(X, Y); // CudaContext ctx = allocator.getFlowController().prepareAction(null, X, Y); float ret = 1f; // CublasPointer xCPointer = new CublasPointer(X, ctx); // CublasPointer yCPointer = new CublasPointer(Y, ctx); Dot dot = new Dot(X, Y); Nd4j.getExecutioner().exec(dot); ret = dot.getFinalResult().floatValue(); /* cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { long result = cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); if (result != 0) throw new IllegalStateException("cublasSetStream failed"); FloatPointer resultPointer = new FloatPointer(0.0f); cuBlasSdot_v2(new cublasContext(handle), N, xCPointer.getDevicePointer(), incX, yCPointer.getDevicePointer(), incY, resultPointer); ret = resultPointer.get(); } */ // allocator.registerAction(ctx, null, X, Y); return ret; }
@Override protected float sdot(int N, INDArray X, int incX, INDArray Y, int incY) { if (Nd4j.dataType() != DataBuffer.Type.FLOAT) logger.warn("FLOAT dot called"); DataTypeValidation.assertSameDataType(X, Y); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(null, X, Y); float ret = 1f; CublasPointer xCPointer = new CublasPointer(X, ctx); CublasPointer yCPointer = new CublasPointer(Y, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { long result = cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); if (result != 0) throw new IllegalStateException("cublasSetStream failed"); FloatPointer resultPointer = new FloatPointer(0.0f); result = cublasSdot_v2(new cublasContext(handle), N, (FloatPointer) xCPointer.getDevicePointer(), incX, (FloatPointer) yCPointer.getDevicePointer(), incY, resultPointer); ret = resultPointer.get(); } allocator.registerAction(ctx, null, X, Y); return ret; }
@Override protected float sdot(long N, INDArray X, int incX, INDArray Y, int incY) { if (Nd4j.dataType() != DataBuffer.Type.FLOAT) logger.warn("FLOAT dot called"); DataTypeValidation.assertSameDataType(X, Y); Nd4j.getExecutioner().push(); CudaContext ctx = allocator.getFlowController().prepareAction(null, X, Y); float ret = 1f; CublasPointer xCPointer = new CublasPointer(X, ctx); CublasPointer yCPointer = new CublasPointer(Y, ctx); cublasHandle_t handle = ctx.getHandle(); synchronized (handle) { long result = cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream())); if (result != 0) throw new IllegalStateException("cublasSetStream failed"); FloatPointer resultPointer = new FloatPointer(0.0f); result = cublasSdot_v2(new cublasContext(handle), (int) N, (FloatPointer) xCPointer.getDevicePointer(), incX, (FloatPointer) yCPointer.getDevicePointer(), incY, resultPointer); ret = resultPointer.get(); } allocator.registerAction(ctx, null, X, Y); return ret; }
/** * @param da * @param A * @param B */ public static void axpy(IComplexNumber da, IComplexNDArray A, IComplexNDArray B) { DataTypeValidation.assertSameDataType(A, B); if (A.data().dataType() == DataBuffer.Type.FLOAT) NativeBlas.caxpy( A.length(), new org.jblas.ComplexFloat(da.realComponent().floatValue(), da.imaginaryComponent().floatValue()), A.data().asFloat(), A.offset(), A.majorStride(), B.data().asFloat(), B.offset(), A.majorStride()); else NativeBlas.zaxpy( A.length(), new org.jblas.ComplexDouble(da.realComponent().doubleValue(), da.imaginaryComponent().doubleValue()), A.data().asDouble(), A.offset(), A.majorStride(), B.data().asDouble(), B.offset(), B.majorStride()); }
DataTypeValidation.assertSameDataType(x, y); if (x.data().dataType() == DataBuffer.Type.FLOAT) { ComplexFloat f = new ComplexFloat(NativeBlas.cdotc(
/** * Dot product between to complex ndarrays * @param x * @param y * @return */ public static IComplexDouble dot(IComplexNDArray x, IComplexNDArray y) { DataTypeValidation.assertSameDataType(x, y); sync(); CublasPointer aCPointer = new CublasPointer(x); CublasPointer bCPointer = new CublasPointer(y); jcuda.cuDoubleComplex result = jcuda.cuDoubleComplex.cuCmplx(0,0); Pointer resultPointer = PointerUtil.getPointer(result); JCublas2.cublasZdotc( ContextHolder.getInstance().getHandle(), x.length(), aCPointer.getDevicePointer(), 1, bCPointer.getDevicePointer(), 1,resultPointer); IComplexDouble ret = Nd4j.createDouble(result.x, result.y); sync(); releaseCublasPointers(aCPointer, bCPointer); return ret; }
/** * Swap the elements in each ndarray * * @param x * @param y */ public static void swap(INDArray x, INDArray y) { DataTypeValidation.assertSameDataType(x, y); CublasPointer xCPointer = new CublasPointer(x); CublasPointer yCPointer = new CublasPointer(y); sync(); if (x.data().dataType() == DataBuffer.Type.FLOAT) { JCublas2.cublasSswap( ContextHolder.getInstance().getHandle(), x.length(), xCPointer.getDevicePointer(), 1, yCPointer.getDevicePointer(), 1); } else { JCublas2.cublasDswap( ContextHolder.getInstance().getHandle(), x.length(), xCPointer.getDevicePointer(), 1, yCPointer.getDevicePointer(), 1); } sync(); }
/** * Copy x to y * * @param x the origin * @param y the destination */ public static void copy(IComplexNDArray x, IComplexNDArray y) { DataTypeValidation.assertSameDataType(x, y); if (x.data().dataType() == DataBuffer.Type.FLOAT) BLAS.getInstance().scopy( x.length(), x.data().asFloat(), x.majorStride(), y.data().asFloat(), y.majorStride()); else BLAS.getInstance().dcopy( x.length(), x.data().asDouble(), x.majorStride(), y.data().asDouble(), y.majorStride()); }
/** * Copy x to y * * @param x the origin * @param y the destination */ public static void copy(IComplexNDArray x, IComplexNDArray y) { DataTypeValidation.assertSameDataType(x, y); if (x.data().dataType() == DataBuffer.Type.FLOAT) BLAS.getInstance().scopy( x.length(), x.data().asFloat(), x.majorStride(), y.data().asFloat(), y.majorStride()); else BLAS.getInstance().dcopy( x.length(), x.data().asDouble(), x.majorStride(), y.data().asDouble(), y.majorStride()); }
/** * Complex dot product * * @param x * @param y * @return */ public static IComplexNumber dotu(IComplexNDArray x, IComplexNDArray y) { DataTypeValidation.assertSameDataType(x, y); if (x.data().dataType() == DataBuffer.Type.FLOAT) { return new ComplexFloat(NativeBlas.cdotu( x.length(), x.data().asFloat(), x.offset(), x.majorStride(), y.data().asFloat(), y.offset(), y.majorStride())); } else { return new ComplexDouble(NativeBlas.zdotu( x.length(), x.data().asDouble(), x.offset(), x.majorStride(), y.data().asDouble(), y.offset(), y.majorStride())); } }
/** * Copy x to y * * @param x * @param y */ public static void copy(INDArray x, INDArray y) { DataTypeValidation.assertSameDataType(x, y); if (x.data().dataType() == DataBuffer.Type.FLOAT) BLAS.getInstance().scopy(x.length(), x.data().asFloat(), x.offset(), x.majorStride(), y.data().asFloat(), y.offset(), y.majorStride()); else BLAS.getInstance().dcopy( x.length(), x.data().asDouble(), x.offset(), x.majorStride(), y.data().asDouble(), y.offset(), y.majorStride()); }
/** * Swap the elements in each ndarray * * @param x * @param y */ public static void swap(INDArray x, INDArray y) { DataTypeValidation.assertSameDataType(x, y); if (x.data().dataType() == DataBuffer.Type.FLOAT) BLAS.getInstance().sswap( x.length(), x.data().asFloat(), x.offset(), x.majorStride(), y.data().asFloat(), y.offset(), y.majorStride()); else BLAS.getInstance().dswap( x.length(), x.data().asDouble(), x.offset(), x.majorStride(), y.data().asDouble(), y.offset(), y.majorStride()); }
/** * Copy x to y * * @param x * @param y */ public static void copy(INDArray x, INDArray y) { DataTypeValidation.assertSameDataType(x, y); if (x.data().dataType() == DataBuffer.Type.FLOAT) BLAS.getInstance().scopy(x.length(), x.data().asFloat(), x.offset(), x.majorStride(), y.data().asFloat(), y.offset(), y.majorStride()); else BLAS.getInstance().dcopy( x.length(), x.data().asDouble(), x.offset(), x.majorStride(), y.data().asDouble(), y.offset(), y.majorStride()); }
/** * Swap the elements in each ndarray * * @param x * @param y */ public static void swap(INDArray x, INDArray y) { DataTypeValidation.assertSameDataType(x, y); if (x.data().dataType() == DataBuffer.Type.FLOAT) BLAS.getInstance().sswap( x.length(), x.data().asFloat(), x.offset(), x.majorStride(), y.data().asFloat(), y.offset(), y.majorStride()); else BLAS.getInstance().dswap( x.length(), x.data().asDouble(), x.offset(), x.majorStride(), y.data().asDouble(), y.offset(), y.majorStride()); }
/** * Copy x to y * * @param x the src * @param y the destination */ public static void copy(INDArray x, INDArray y) { DataTypeValidation.assertSameDataType(x, y); sync(); CublasPointer xCPointer = new CublasPointer(x); CublasPointer yCPointer = new CublasPointer(y); if(x.data().dataType() == DataBuffer.Type.DOUBLE) JCublas2.cublasDcopy( ContextHolder.getInstance().getHandle() ,x.length(),xCPointer.getDevicePointer() ,x.majorStride() ,yCPointer.getDevicePointer() ,y.majorStride()); if(x.data().dataType() == DataBuffer.Type.FLOAT) JCublas2.cublasScopy(ContextHolder.getInstance().getHandle() ,x.length() ,xCPointer.getDevicePointer() ,x.majorStride() ,yCPointer.getDevicePointer() ,y.majorStride()); sync(); yCPointer.copyToHost(); releaseCublasPointers(yCPointer, xCPointer); }