Search in sources :

Example 16 with CublasPointer

use of org.nd4j.linalg.jcublas.CublasPointer in project nd4j by deeplearning4j.

the class JcublasLevel3 method dgemm.

@Override
protected void dgemm(char Order, char TransA, char TransB, int M, int N, int K, double alpha, INDArray A, int lda, INDArray B, int ldb, double beta, INDArray C, int ldc) {
    // B = Shape.toOffsetZero(B);
    if (Nd4j.dataType() != DataBuffer.Type.DOUBLE)
        logger.warn("DOUBLE gemm called");
    Nd4j.getExecutioner().push();
    CudaContext ctx = allocator.getFlowController().prepareAction(C, A, B);
    DataTypeValidation.assertDouble(A, B, C);
    CublasPointer cAPointer = new CublasPointer(A, ctx);
    CublasPointer cBPointer = new CublasPointer(B, ctx);
    CublasPointer cCPointer = new CublasPointer(C, ctx);
    cublasHandle_t handle = ctx.getHandle();
    synchronized (handle) {
        cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream()));
        cublasDgemm_v2(new cublasContext(handle), convertTranspose(TransA), convertTranspose(TransB), M, N, K, new DoublePointer(alpha), (DoublePointer) cAPointer.getDevicePointer(), lda, (DoublePointer) cBPointer.getDevicePointer(), ldb, new DoublePointer(beta), (DoublePointer) cCPointer.getDevicePointer(), ldc);
    }
    allocator.registerAction(ctx, C, A, B);
    OpExecutionerUtil.checkForAny(C);
}
Also used : org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t(org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t) CudaContext(org.nd4j.linalg.jcublas.context.CudaContext) DoublePointer(org.bytedeco.javacpp.DoublePointer) CublasPointer(org.nd4j.linalg.jcublas.CublasPointer)

Example 17 with CublasPointer

use of org.nd4j.linalg.jcublas.CublasPointer in project nd4j by deeplearning4j.

the class JcublasLevel1 method dcopy.

@Override
protected void dcopy(int N, INDArray X, int incX, INDArray Y, int incY) {
    if (Nd4j.dataType() != DataBuffer.Type.DOUBLE)
        logger.warn("DOUBLE copy called");
    Nd4j.getExecutioner().push();
    CudaContext ctx = allocator.getFlowController().prepareAction(Y, X);
    CublasPointer xCPointer = new CublasPointer(X, ctx);
    CublasPointer yCPointer = new CublasPointer(Y, ctx);
    cublasHandle_t handle = ctx.getHandle();
    synchronized (handle) {
        cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream()));
        cublasDcopy_v2(new cublasContext(handle), N, (DoublePointer) xCPointer.getDevicePointer(), incX, (DoublePointer) yCPointer.getDevicePointer(), incY);
    }
    allocator.registerAction(ctx, Y, X);
    OpExecutionerUtil.checkForAny(Y);
}
Also used : CUstream_st(org.bytedeco.javacpp.cuda.CUstream_st) org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t(org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t) CudaContext(org.nd4j.linalg.jcublas.context.CudaContext) CublasPointer(org.nd4j.linalg.jcublas.CublasPointer)

Example 18 with CublasPointer

use of org.nd4j.linalg.jcublas.CublasPointer in project nd4j by deeplearning4j.

the class JcublasLevel1 method isamax.

@Override
protected int isamax(int N, INDArray X, int incX) {
    if (Nd4j.dataType() != DataBuffer.Type.FLOAT)
        logger.warn("FLOAT iamax called");
    Nd4j.getExecutioner().push();
    CudaContext ctx = allocator.getFlowController().prepareAction(null, X);
    int ret2;
    CublasPointer xCPointer = new CublasPointer(X, ctx);
    cublasHandle_t handle = ctx.getHandle();
    synchronized (handle) {
        cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream()));
        IntPointer resultPointer = new IntPointer(new int[] { 0 });
        cublasIsamax_v2(new cublasContext(handle), N, (FloatPointer) xCPointer.getDevicePointer(), incX, resultPointer);
        ret2 = resultPointer.get();
    }
    allocator.registerAction(ctx, null, X);
    return ret2 - 1;
}
Also used : CUstream_st(org.bytedeco.javacpp.cuda.CUstream_st) org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t(org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t) IntPointer(org.bytedeco.javacpp.IntPointer) CudaContext(org.nd4j.linalg.jcublas.context.CudaContext) CublasPointer(org.nd4j.linalg.jcublas.CublasPointer)

Example 19 with CublasPointer

use of org.nd4j.linalg.jcublas.CublasPointer in project nd4j by deeplearning4j.

the class JcublasLevel1 method scopy.

@Override
protected void scopy(int N, INDArray X, int incX, INDArray Y, int incY) {
    if (Nd4j.dataType() != DataBuffer.Type.FLOAT)
        logger.warn("FLOAT copy called");
    Nd4j.getExecutioner().push();
    CudaContext ctx = allocator.getFlowController().prepareAction(Y, X);
    CublasPointer xCPointer = new CublasPointer(X, ctx);
    CublasPointer yCPointer = new CublasPointer(Y, ctx);
    cublasHandle_t handle = ctx.getHandle();
    synchronized (handle) {
        cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream()));
        cublasScopy_v2(new cublasContext(handle), N, (FloatPointer) xCPointer.getDevicePointer(), incX, (FloatPointer) yCPointer.getDevicePointer(), incY);
    }
    allocator.registerAction(ctx, Y, X);
    OpExecutionerUtil.checkForAny(Y);
}
Also used : CUstream_st(org.bytedeco.javacpp.cuda.CUstream_st) org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t(org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t) CudaContext(org.nd4j.linalg.jcublas.context.CudaContext) CublasPointer(org.nd4j.linalg.jcublas.CublasPointer)

Example 20 with CublasPointer

use of org.nd4j.linalg.jcublas.CublasPointer in project nd4j by deeplearning4j.

the class JcublasLevel1 method sscal.

@Override
protected void sscal(int N, float alpha, INDArray X, int incX) {
    if (Nd4j.dataType() != DataBuffer.Type.FLOAT)
        logger.warn("FLOAT scal called");
    Nd4j.getExecutioner().push();
    CudaContext ctx = allocator.getFlowController().prepareAction(X);
    CublasPointer xCPointer = new CublasPointer(X, ctx);
    cublasHandle_t handle = ctx.getHandle();
    synchronized (handle) {
        cublasSetStream_v2(new cublasContext(handle), new CUstream_st(ctx.getOldStream()));
        cublasSscal_v2(new cublasContext(handle), N, new FloatPointer(alpha), (FloatPointer) xCPointer.getDevicePointer(), incX);
    }
    allocator.registerAction(ctx, X);
    OpExecutionerUtil.checkForAny(X);
}
Also used : CUstream_st(org.bytedeco.javacpp.cuda.CUstream_st) org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t(org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t) FloatPointer(org.bytedeco.javacpp.FloatPointer) CudaContext(org.nd4j.linalg.jcublas.context.CudaContext) CublasPointer(org.nd4j.linalg.jcublas.CublasPointer)

Aggregations

CublasPointer (org.nd4j.linalg.jcublas.CublasPointer)36 CudaContext (org.nd4j.linalg.jcublas.context.CudaContext)35 org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t (org.nd4j.jita.allocator.pointers.cuda.cublasHandle_t)25 CUstream_st (org.bytedeco.javacpp.cuda.CUstream_st)24 DoublePointer (org.bytedeco.javacpp.DoublePointer)20 FloatPointer (org.bytedeco.javacpp.FloatPointer)19 IntPointer (org.bytedeco.javacpp.IntPointer)12 INDArray (org.nd4j.linalg.api.ndarray.INDArray)11 Pointer (org.bytedeco.javacpp.Pointer)10 CudaPointer (org.nd4j.jita.allocator.pointers.CudaPointer)10 org.nd4j.jita.allocator.pointers.cuda.cusolverDnHandle_t (org.nd4j.jita.allocator.pointers.cuda.cusolverDnHandle_t)10 DataBuffer (org.nd4j.linalg.api.buffer.DataBuffer)10 GridExecutioner (org.nd4j.linalg.api.ops.executioner.GridExecutioner)10 BlasException (org.nd4j.linalg.api.blas.BlasException)8 INDArrayIndex (org.nd4j.linalg.indexing.INDArrayIndex)4 ShortPointer (org.bytedeco.javacpp.ShortPointer)1 JCudaBuffer (org.nd4j.linalg.jcublas.buffer.JCudaBuffer)1