org.apache.sysml.runtime.matrix.data

Class LibMatrixCUDA



  • public class LibMatrixCUDA
    extends Object
    • Constructor Summary

      Constructors 
      Constructor and Description
      LibMatrixCUDA() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static void axpy(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec, String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject in1, org.apache.sysml.runtime.controlprogram.caching.MatrixObject in2, String outputName, double constant)
      Performs daxpy operation
      static void batchNormalizationBackward(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject image, org.apache.sysml.runtime.controlprogram.caching.MatrixObject dout, org.apache.sysml.runtime.controlprogram.caching.MatrixObject scale, org.apache.sysml.runtime.controlprogram.caching.MatrixObject ret, org.apache.sysml.runtime.controlprogram.caching.MatrixObject retScale, org.apache.sysml.runtime.controlprogram.caching.MatrixObject retBias, double epsilon)
      This method computes the backpropagation errors for image, scale and bias of batch normalization layer
      static void batchNormalizationForwardInference(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject image, org.apache.sysml.runtime.controlprogram.caching.MatrixObject scale, org.apache.sysml.runtime.controlprogram.caching.MatrixObject bias, org.apache.sysml.runtime.controlprogram.caching.MatrixObject runningMean, org.apache.sysml.runtime.controlprogram.caching.MatrixObject runningVar, org.apache.sysml.runtime.controlprogram.caching.MatrixObject ret, double epsilon)
      Performs the forward BatchNormalization layer computation for inference
      static void batchNormalizationForwardTraining(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject image, org.apache.sysml.runtime.controlprogram.caching.MatrixObject scale, org.apache.sysml.runtime.controlprogram.caching.MatrixObject bias, org.apache.sysml.runtime.controlprogram.caching.MatrixObject runningMean, org.apache.sysml.runtime.controlprogram.caching.MatrixObject runningVar, org.apache.sysml.runtime.controlprogram.caching.MatrixObject ret, org.apache.sysml.runtime.controlprogram.caching.MatrixObject retRunningMean, org.apache.sysml.runtime.controlprogram.caching.MatrixObject retRunningVar, double epsilon, double exponentialAverageFactor)
      Performs the forward BatchNormalization layer computation for training
      static void biasAdd(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject input, org.apache.sysml.runtime.controlprogram.caching.MatrixObject bias, org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock)
      Performs the operation corresponding to the DML script: ones = matrix(1, rows=1, cols=Hout*Wout) output = input + matrix(bias %*% ones, rows=1, cols=F*Hout*Wout) This operation is often followed by conv2d and hence we have introduced bias_add(input, bias) built-in function
      static void biasMultiply(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject input, org.apache.sysml.runtime.controlprogram.caching.MatrixObject bias, org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock)
      Performs the operation corresponding to the DML script: ones = matrix(1, rows=1, cols=Hout*Wout) output = input * matrix(bias %*% ones, rows=1, cols=F*Hout*Wout) This operation is often followed by conv2d and hence we have introduced bias_add(input, bias) built-in function
      protected static void bothSparseMatmult(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject output, org.apache.sysml.runtime.controlprogram.caching.MatrixObject left, org.apache.sysml.runtime.controlprogram.caching.MatrixObject right, boolean isLeftTransposed, boolean isRightTransposed)
      Sparse C = Sparse op(A) * Sparse op(B) Reroutes call to sparse matrix-vector mult if needed
      static void conv2d(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject image, org.apache.sysml.runtime.controlprogram.caching.MatrixObject filter, org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock, int N, int C, int H, int W, int K, int R, int S, int pad_h, int pad_w, int stride_h, int stride_w, int P, int Q) 
      static void conv2dBackwardData(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject filter, org.apache.sysml.runtime.controlprogram.caching.MatrixObject dout, org.apache.sysml.runtime.controlprogram.caching.MatrixObject output, int N, int C, int H, int W, int K, int R, int S, int pad_h, int pad_w, int stride_h, int stride_w, int P, int Q)
      This method computes the backpropogation errors for previous layer of convolution operation
      static void conv2dBackwardFilter(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject image, org.apache.sysml.runtime.controlprogram.caching.MatrixObject dout, org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock, int N, int C, int H, int W, int K, int R, int S, int pad_h, int pad_w, int stride_h, int stride_w, int P, int Q)
      This method computes the backpropogation errors for filter of convolution operation
      static void conv2dBiasAdd(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject image, org.apache.sysml.runtime.controlprogram.caching.MatrixObject bias, org.apache.sysml.runtime.controlprogram.caching.MatrixObject filter, org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock, int N, int C, int H, int W, int K, int R, int S, int pad_h, int pad_w, int stride_h, int stride_w, int P, int Q) 
      protected static void denseDenseMatmult(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject output, org.apache.sysml.runtime.controlprogram.caching.MatrixObject left1, org.apache.sysml.runtime.controlprogram.caching.MatrixObject right1, boolean isLeftTransposed1, boolean isRightTransposed1)
      Dense dense matrix multiply C = op(A) * op(B), A and B are dense matrices
      static void denseDenseMatmult(String instName, jcuda.Pointer output, int leftRows1, int leftCols1, int rightRows1, int rightCols1, boolean isLeftTransposed1, boolean isRightTransposed1, jcuda.Pointer leftPtr, jcuda.Pointer rightPtr)
      Dense-dense matrix multiply C = op(A) * op(B), A and B are dense matrices On the host, the matrices are in row-major format; cuBLAS expects them in column-major format.
      protected static void denseSparseMatmult(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject output, org.apache.sysml.runtime.controlprogram.caching.MatrixObject right, org.apache.sysml.runtime.controlprogram.caching.MatrixObject left, boolean isLeftTransposed, boolean isRightTransposed, int transA, int transB, int m, int n, int k)
      C = op(A) * op(B) where A is dense and B is sparse If B is ultrasparse, A is converted to a sparse matrix and sparseSparseMatmult(MatrixObject, int, int, int, int, int, CSRPointer, CSRPointer) is invoked otherwise B is converted to a dense matrix and denseDenseMatmult(Pointer, int, int, int, int, boolean, boolean, Pointer, Pointer) is invoked.
      protected static void eitherSparseMatmult(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject output, org.apache.sysml.runtime.controlprogram.caching.MatrixObject left, org.apache.sysml.runtime.controlprogram.caching.MatrixObject right, boolean isLeftTransposed, boolean isRightTransposed)
      One of the matrices is sparse, the other dense C = op(A) x op(B)
      static void exp(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec, String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject in1, String outputName)
      Performs an "exp" operation on a matrix on the GPU
      static boolean isInSparseFormat(org.apache.sysml.runtime.controlprogram.caching.MatrixObject mo) 
      static org.apache.sysml.runtime.controlprogram.caching.MatrixObject matmult(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec, String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject left1, org.apache.sysml.runtime.controlprogram.caching.MatrixObject right1, String outputName, boolean isLeftTransposed1, boolean isRightTransposed1)
      Matrix multiply on GPU Examines sparsity and shapes and routes call to appropriate method from cuBLAS or cuSparse C = op(A) x op(B)
      static void matmultTSMM(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec, String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject left, String outputName, boolean isLeftTransposed)
      Performs tsmm, A %*% A' or A' %*% A, on GPU by exploiting cublasDsyrk(...)
      static void matrixScalarArithmetic(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec, String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject in1, org.apache.sysml.runtime.controlprogram.caching.MatrixObject in2, String outputName, boolean isLeftTransposed, boolean isRightTransposed, org.apache.sysml.runtime.matrix.operators.BinaryOperator op)
      Performs elementwise operation specified by op of two input matrices in1 and in2
      static void matrixScalarArithmetic(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec, String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject in, String outputName, boolean isInputTransposed, org.apache.sysml.runtime.matrix.operators.ScalarOperator op)
      Entry point to perform elementwise matrix-scalar operation specified by op
      static void maxpooling(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject image, org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock, int N, int C, int H, int W, int K, int R, int S, int pad_h, int pad_w, int stride_h, int stride_w, int P, int Q)
      performs maxpooling on GPU by exploiting cudnnPoolingForward(...)
      static void maxpoolingBackward(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject image, org.apache.sysml.runtime.controlprogram.caching.MatrixObject dout, org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock, int N, int C, int H, int W, int K, int R, int S, int pad_h, int pad_w, int stride_h, int stride_w, int P, int Q)
      Performs maxpoolingBackward on GPU by exploiting cudnnPoolingBackward(...) This method computes the backpropogation errors for previous layer of maxpooling operation
      static void performMaxpooling(String instName, jcuda.Pointer x, jcuda.jcudnn.cudnnTensorDescriptor xDesc, org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock, int N, int C, int H, int W, int K, int R, int S, int pad_h, int pad_w, int stride_h, int stride_w, int P, int Q) 
      static jcuda.Pointer pointerTo(double value) 
      static void relu(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec, String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject in, String outputName)
      Performs the relu operation on the GPU.
      static void reluBackward(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject input, org.apache.sysml.runtime.controlprogram.caching.MatrixObject dout, org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock)
      This method computes the backpropagation errors for previous layer of relu operation
      static void reluMaxpooling(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject image, org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock, int N, int C, int H, int W, int K, int R, int S, int pad_h, int pad_w, int stride_h, int stride_w, int P, int Q)
      performs relu followed by maxpooling on GPU by exploiting cudnnPoolingForward(...)
      protected static void sparseDenseMatmult(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject output, org.apache.sysml.runtime.controlprogram.caching.MatrixObject left, org.apache.sysml.runtime.controlprogram.caching.MatrixObject right, boolean isLeftTransposed, boolean isRightTransposed, int transA, int transB, int m, int n, int k)
      * C = op(A) * op(B) where A is sparse and B is dense If A is ultrasparse, B is converted to a sparse matrix and sparseSparseMatmult(MatrixObject, int, int, int, int, int, CSRPointer, CSRPointer) is invoked otherwise A is converted to a dense matrix and denseDenseMatmult(Pointer, int, int, int, int, boolean, boolean, Pointer, Pointer) is invoked.
      protected static void sparseMatrixDenseVectorMult(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject output, JCudaObject.CSRPointer A, jcuda.Pointer B_dense, int transA, int m, int k)
      C = op(A) x B A is a sparse matrix, B is a dense vector
      protected static void sparseMatrixVectorMult(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject output, int transA, int m, int n, int k, JCudaObject.CSRPointer A, JCudaObject.CSRPointer B)
      Does a sparse matrix-vector multiply.
      protected static void sparseSparseMatmult(String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject output, int transA, int transB, int m, int n, int k, JCudaObject.CSRPointer A, JCudaObject.CSRPointer B)
      Does a sparse-sparse Matrix multiply C = op(A) x op(B), A, B are sparse matrices
      static void transpose(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec, String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject in, String outputName)
      Transposes the input matrix using cublasDgeam
      static void unaryAggregate(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec, String instName, org.apache.sysml.runtime.controlprogram.caching.MatrixObject in1, String output, org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator op)
      Entry point to perform Unary aggregate operations on the GPU.
    • Field Detail

      • cudnnHandle

        public static jcuda.jcudnn.cudnnHandle cudnnHandle
      • cublasHandle

        public static jcuda.jcublas.cublasHandle cublasHandle
      • cusparseHandle

        public static jcuda.jcusparse.cusparseHandle cusparseHandle
    • Constructor Detail

      • LibMatrixCUDA

        public LibMatrixCUDA()
    • Method Detail

      • isInSparseFormat

        public static boolean isInSparseFormat(org.apache.sysml.runtime.controlprogram.caching.MatrixObject mo)
      • conv2dBiasAdd

        public static void conv2dBiasAdd(String instName,
                                         org.apache.sysml.runtime.controlprogram.caching.MatrixObject image,
                                         org.apache.sysml.runtime.controlprogram.caching.MatrixObject bias,
                                         org.apache.sysml.runtime.controlprogram.caching.MatrixObject filter,
                                         org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock,
                                         int N,
                                         int C,
                                         int H,
                                         int W,
                                         int K,
                                         int R,
                                         int S,
                                         int pad_h,
                                         int pad_w,
                                         int stride_h,
                                         int stride_w,
                                         int P,
                                         int Q)
                                  throws DMLRuntimeException
        Throws:
        DMLRuntimeException
      • conv2d

        public static void conv2d(String instName,
                                  org.apache.sysml.runtime.controlprogram.caching.MatrixObject image,
                                  org.apache.sysml.runtime.controlprogram.caching.MatrixObject filter,
                                  org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock,
                                  int N,
                                  int C,
                                  int H,
                                  int W,
                                  int K,
                                  int R,
                                  int S,
                                  int pad_h,
                                  int pad_w,
                                  int stride_h,
                                  int stride_w,
                                  int P,
                                  int Q)
                           throws DMLRuntimeException
        Throws:
        DMLRuntimeException
      • pointerTo

        public static jcuda.Pointer pointerTo(double value)
      • reluBackward

        public static void reluBackward(String instName,
                                        org.apache.sysml.runtime.controlprogram.caching.MatrixObject input,
                                        org.apache.sysml.runtime.controlprogram.caching.MatrixObject dout,
                                        org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock)
                                 throws DMLRuntimeException
        This method computes the backpropagation errors for previous layer of relu operation
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        input - input image
        dout - next layer error propogation
        outputBlock - output
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • biasMultiply

        public static void biasMultiply(String instName,
                                        org.apache.sysml.runtime.controlprogram.caching.MatrixObject input,
                                        org.apache.sysml.runtime.controlprogram.caching.MatrixObject bias,
                                        org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock)
                                 throws DMLRuntimeException
        Performs the operation corresponding to the DML script: ones = matrix(1, rows=1, cols=Hout*Wout) output = input * matrix(bias %*% ones, rows=1, cols=F*Hout*Wout) This operation is often followed by conv2d and hence we have introduced bias_add(input, bias) built-in function
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        input - input image
        bias - bias
        outputBlock - output
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • biasAdd

        public static void biasAdd(String instName,
                                   org.apache.sysml.runtime.controlprogram.caching.MatrixObject input,
                                   org.apache.sysml.runtime.controlprogram.caching.MatrixObject bias,
                                   org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock)
                            throws DMLRuntimeException
        Performs the operation corresponding to the DML script: ones = matrix(1, rows=1, cols=Hout*Wout) output = input + matrix(bias %*% ones, rows=1, cols=F*Hout*Wout) This operation is often followed by conv2d and hence we have introduced bias_add(input, bias) built-in function
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        input - input image
        bias - bias
        outputBlock - output
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • batchNormalizationForwardInference

        public static void batchNormalizationForwardInference(String instName,
                                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject image,
                                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject scale,
                                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject bias,
                                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject runningMean,
                                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject runningVar,
                                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject ret,
                                                              double epsilon)
                                                       throws DMLRuntimeException
        Performs the forward BatchNormalization layer computation for inference
        Parameters:
        instName - name of the instruction
        image - input image
        scale - scale (as per CuDNN) and gamma as per original paper: shape [1, C, 1, 1]
        bias - bias (as per CuDNN) and beta as per original paper: shape [1, C, 1, 1]
        runningMean - running mean accumulated during training phase: shape [1, C, 1, 1]
        runningVar - running variance accumulated during training phase: shape [1, C, 1, 1]
        ret - normalized input
        epsilon - epsilon value used in the batch normalization formula
        Throws:
        DMLRuntimeException - if error occurs
      • batchNormalizationForwardTraining

        public static void batchNormalizationForwardTraining(String instName,
                                                             org.apache.sysml.runtime.controlprogram.caching.MatrixObject image,
                                                             org.apache.sysml.runtime.controlprogram.caching.MatrixObject scale,
                                                             org.apache.sysml.runtime.controlprogram.caching.MatrixObject bias,
                                                             org.apache.sysml.runtime.controlprogram.caching.MatrixObject runningMean,
                                                             org.apache.sysml.runtime.controlprogram.caching.MatrixObject runningVar,
                                                             org.apache.sysml.runtime.controlprogram.caching.MatrixObject ret,
                                                             org.apache.sysml.runtime.controlprogram.caching.MatrixObject retRunningMean,
                                                             org.apache.sysml.runtime.controlprogram.caching.MatrixObject retRunningVar,
                                                             double epsilon,
                                                             double exponentialAverageFactor)
                                                      throws DMLRuntimeException
        Performs the forward BatchNormalization layer computation for training
        Parameters:
        instName - name of the instruction
        image - input image
        scale - scale (as per CuDNN) and gamma as per original paper: shape [1, C, 1, 1]
        bias - bias (as per CuDNN) and beta as per original paper: shape [1, C, 1, 1]
        runningMean - running mean accumulated during training phase: shape [1, C, 1, 1]
        runningVar - running variance accumulated during training phase: shape [1, C, 1, 1]
        ret - (output) normalized input
        retRunningMean - (output) running mean accumulated during training phase: shape [1, C, 1, 1]
        retRunningVar - (output) running variance accumulated during training phase: shape [1, C, 1, 1]
        epsilon - epsilon value used in the batch normalization formula
        exponentialAverageFactor - factor used in the moving average computation
        Throws:
        DMLRuntimeException - if error occurs
      • batchNormalizationBackward

        public static void batchNormalizationBackward(String instName,
                                                      org.apache.sysml.runtime.controlprogram.caching.MatrixObject image,
                                                      org.apache.sysml.runtime.controlprogram.caching.MatrixObject dout,
                                                      org.apache.sysml.runtime.controlprogram.caching.MatrixObject scale,
                                                      org.apache.sysml.runtime.controlprogram.caching.MatrixObject ret,
                                                      org.apache.sysml.runtime.controlprogram.caching.MatrixObject retScale,
                                                      org.apache.sysml.runtime.controlprogram.caching.MatrixObject retBias,
                                                      double epsilon)
                                               throws DMLRuntimeException
        This method computes the backpropagation errors for image, scale and bias of batch normalization layer
        Parameters:
        instName - name of the instruction
        image - input image
        dout - input errors of shape C, H, W
        scale - scale (as per CuDNN) and gamma as per original paper: shape [1, C, 1, 1]
        ret - (output) backpropagation errors for previous layer
        retScale - backpropagation error for scale
        retBias - backpropagation error for bias
        epsilon - epsilon value used in the batch normalization formula
        Throws:
        DMLRuntimeException - if error occurs
      • conv2dBackwardFilter

        public static void conv2dBackwardFilter(String instName,
                                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject image,
                                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject dout,
                                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock,
                                                int N,
                                                int C,
                                                int H,
                                                int W,
                                                int K,
                                                int R,
                                                int S,
                                                int pad_h,
                                                int pad_w,
                                                int stride_h,
                                                int stride_w,
                                                int P,
                                                int Q)
                                         throws DMLRuntimeException
        This method computes the backpropogation errors for filter of convolution operation
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        image - input image
        dout - errors from next layer
        outputBlock - output errors
        N - number of images
        C - number of channels
        H - height
        W - width
        K - number of filters
        R - filter height
        S - filter width
        pad_h - pad height
        pad_w - pad width
        stride_h - stride height
        stride_w - stride width
        P - output activation height
        Q - output activation width
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • conv2dBackwardData

        public static void conv2dBackwardData(String instName,
                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject filter,
                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject dout,
                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject output,
                                              int N,
                                              int C,
                                              int H,
                                              int W,
                                              int K,
                                              int R,
                                              int S,
                                              int pad_h,
                                              int pad_w,
                                              int stride_h,
                                              int stride_w,
                                              int P,
                                              int Q)
                                       throws DMLRuntimeException
        This method computes the backpropogation errors for previous layer of convolution operation
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        filter - filter used in conv2d
        dout - errors from next layer
        output - output errors
        N - number of images
        C - number of channels
        H - height
        W - width
        K - number of filters
        R - filter height
        S - filter width
        pad_h - pad height
        pad_w - pad width
        stride_h - stride height
        stride_w - stride width
        P - output activation height
        Q - output activation width
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • maxpooling

        public static void maxpooling(String instName,
                                      org.apache.sysml.runtime.controlprogram.caching.MatrixObject image,
                                      org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock,
                                      int N,
                                      int C,
                                      int H,
                                      int W,
                                      int K,
                                      int R,
                                      int S,
                                      int pad_h,
                                      int pad_w,
                                      int stride_h,
                                      int stride_w,
                                      int P,
                                      int Q)
                               throws DMLRuntimeException
        performs maxpooling on GPU by exploiting cudnnPoolingForward(...)
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        image - image as matrix object
        outputBlock - output matrix
        N - batch size
        C - number of channels
        H - height of image
        W - width of image
        K - number of filters
        R - height of filter
        S - width of filter
        pad_h - vertical padding
        pad_w - horizontal padding
        stride_h - horizontal stride
        stride_w - vertical stride
        P - (H - R + 1 + 2*pad_h)/stride_h
        Q - (W - S + 1 + 2*pad_w)/stride_w
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • performMaxpooling

        public static void performMaxpooling(String instName,
                                             jcuda.Pointer x,
                                             jcuda.jcudnn.cudnnTensorDescriptor xDesc,
                                             org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock,
                                             int N,
                                             int C,
                                             int H,
                                             int W,
                                             int K,
                                             int R,
                                             int S,
                                             int pad_h,
                                             int pad_w,
                                             int stride_h,
                                             int stride_w,
                                             int P,
                                             int Q)
                                      throws DMLRuntimeException
        Throws:
        DMLRuntimeException
      • reluMaxpooling

        public static void reluMaxpooling(String instName,
                                          org.apache.sysml.runtime.controlprogram.caching.MatrixObject image,
                                          org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock,
                                          int N,
                                          int C,
                                          int H,
                                          int W,
                                          int K,
                                          int R,
                                          int S,
                                          int pad_h,
                                          int pad_w,
                                          int stride_h,
                                          int stride_w,
                                          int P,
                                          int Q)
                                   throws DMLRuntimeException
        performs relu followed by maxpooling on GPU by exploiting cudnnPoolingForward(...)
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        image - image as matrix object
        outputBlock - output matrix
        N - batch size
        C - number of channels
        H - height of image
        W - width of image
        K - number of filters
        R - height of filter
        S - width of filter
        pad_h - vertical padding
        pad_w - horizontal padding
        stride_h - horizontal stride
        stride_w - vertical stride
        P - (H - R + 1 + 2*pad_h)/stride_h
        Q - (W - S + 1 + 2*pad_w)/stride_w
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • maxpoolingBackward

        public static void maxpoolingBackward(String instName,
                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject image,
                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject dout,
                                              org.apache.sysml.runtime.controlprogram.caching.MatrixObject outputBlock,
                                              int N,
                                              int C,
                                              int H,
                                              int W,
                                              int K,
                                              int R,
                                              int S,
                                              int pad_h,
                                              int pad_w,
                                              int stride_h,
                                              int stride_w,
                                              int P,
                                              int Q)
                                       throws DMLRuntimeException
        Performs maxpoolingBackward on GPU by exploiting cudnnPoolingBackward(...) This method computes the backpropogation errors for previous layer of maxpooling operation
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        image - image as matrix object
        dout - delta matrix, output of previous layer
        outputBlock - output matrix
        N - batch size
        C - number of channels
        H - height of image
        W - width of image
        K - number of filters
        R - height of filter
        S - width of filter
        pad_h - vertical padding
        pad_w - horizontal padding
        stride_h - horizontal stride
        stride_w - vertical stride
        P - (H - R + 1 + 2*pad_h)/stride_h
        Q - (W - S + 1 + 2*pad_w)/stride_w
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • relu

        public static void relu(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec,
                                String instName,
                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject in,
                                String outputName)
                         throws DMLRuntimeException
        Performs the relu operation on the GPU.
        Parameters:
        ec - currently active ExecutionContext
        instName - the invoking instruction's name for record Statistics.
        in - input matrix
        outputName - name of the output matrix
        Throws:
        DMLRuntimeException - if an error occurs
      • matmultTSMM

        public static void matmultTSMM(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec,
                                       String instName,
                                       org.apache.sysml.runtime.controlprogram.caching.MatrixObject left,
                                       String outputName,
                                       boolean isLeftTransposed)
                                throws DMLRuntimeException
        Performs tsmm, A %*% A' or A' %*% A, on GPU by exploiting cublasDsyrk(...)
        Parameters:
        ec - execution context
        instName - the invoking instruction's name for record Statistics.
        left - input matrix, as in a tsmm expression like A %*% A' or A' %*% A, we just need to check whether the left one is transposed or not, I named it 'left'
        outputName - output matrix name
        isLeftTransposed - if true, left transposed
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • matmult

        public static org.apache.sysml.runtime.controlprogram.caching.MatrixObject matmult(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec,
                                                                                           String instName,
                                                                                           org.apache.sysml.runtime.controlprogram.caching.MatrixObject left1,
                                                                                           org.apache.sysml.runtime.controlprogram.caching.MatrixObject right1,
                                                                                           String outputName,
                                                                                           boolean isLeftTransposed1,
                                                                                           boolean isRightTransposed1)
                                                                                    throws DMLRuntimeException
        Matrix multiply on GPU Examines sparsity and shapes and routes call to appropriate method from cuBLAS or cuSparse C = op(A) x op(B)
        Parameters:
        ec - Current ExecutionContext instance
        instName - name of the invoking instruction to recordStatistics.
        left1 - Matrix A
        right1 - Matrix B
        outputName - Name of the output matrix C (in code generated after LOP layer)
        isLeftTransposed1 - op for A, transposed or not
        isRightTransposed1 - op for B, tranposed or not
        Returns:
        output of matrix multiply
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • eitherSparseMatmult

        protected static void eitherSparseMatmult(String instName,
                                                  org.apache.sysml.runtime.controlprogram.caching.MatrixObject output,
                                                  org.apache.sysml.runtime.controlprogram.caching.MatrixObject left,
                                                  org.apache.sysml.runtime.controlprogram.caching.MatrixObject right,
                                                  boolean isLeftTransposed,
                                                  boolean isRightTransposed)
                                           throws DMLRuntimeException
        One of the matrices is sparse, the other dense C = op(A) x op(B)
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        output - allocated output object for C on host to which GPU output will be attached
        left - Matrix A on host
        right - Matrix B on host
        isLeftTransposed - op for A, tranposed or not
        isRightTransposed - op for B, transposed or not
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • denseSparseMatmult

        protected static void denseSparseMatmult(String instName,
                                                 org.apache.sysml.runtime.controlprogram.caching.MatrixObject output,
                                                 org.apache.sysml.runtime.controlprogram.caching.MatrixObject right,
                                                 org.apache.sysml.runtime.controlprogram.caching.MatrixObject left,
                                                 boolean isLeftTransposed,
                                                 boolean isRightTransposed,
                                                 int transA,
                                                 int transB,
                                                 int m,
                                                 int n,
                                                 int k)
                                          throws DMLRuntimeException
        C = op(A) * op(B) where A is dense and B is sparse If B is ultrasparse, A is converted to a sparse matrix and sparseSparseMatmult(MatrixObject, int, int, int, int, int, CSRPointer, CSRPointer) is invoked otherwise B is converted to a dense matrix and denseDenseMatmult(Pointer, int, int, int, int, boolean, boolean, Pointer, Pointer) is invoked.
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        output - ?
        right - ?
        left - ?
        isLeftTransposed - ?
        isRightTransposed - ?
        transA - ?
        transB - ?
        m - ?
        n - ?
        k - ?
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • sparseDenseMatmult

        protected static void sparseDenseMatmult(String instName,
                                                 org.apache.sysml.runtime.controlprogram.caching.MatrixObject output,
                                                 org.apache.sysml.runtime.controlprogram.caching.MatrixObject left,
                                                 org.apache.sysml.runtime.controlprogram.caching.MatrixObject right,
                                                 boolean isLeftTransposed,
                                                 boolean isRightTransposed,
                                                 int transA,
                                                 int transB,
                                                 int m,
                                                 int n,
                                                 int k)
                                          throws DMLRuntimeException
        * C = op(A) * op(B) where A is sparse and B is dense If A is ultrasparse, B is converted to a sparse matrix and sparseSparseMatmult(MatrixObject, int, int, int, int, int, CSRPointer, CSRPointer) is invoked otherwise A is converted to a dense matrix and denseDenseMatmult(Pointer, int, int, int, int, boolean, boolean, Pointer, Pointer) is invoked.
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        output - ?
        left - ?
        right - ?
        isLeftTransposed - ?
        isRightTransposed - ?
        transA - ?
        transB - ?
        m - ?
        n - ?
        k - ?
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • sparseMatrixDenseVectorMult

        protected static void sparseMatrixDenseVectorMult(String instName,
                                                          org.apache.sysml.runtime.controlprogram.caching.MatrixObject output,
                                                          JCudaObject.CSRPointer A,
                                                          jcuda.Pointer B_dense,
                                                          int transA,
                                                          int m,
                                                          int k)
                                                   throws DMLRuntimeException
        C = op(A) x B A is a sparse matrix, B is a dense vector
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        output - allocated output on the host, to which the GPU output C will be attached
        A - sparse matrix A on the GPU
        B_dense - dense matrix/vector B on the GPU
        transA - op for A, tranposed or not
        m - number of rows in A (not op(A))
        k - number of cols in A or number of rows in B (not op(A) or op(B))
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • bothSparseMatmult

        protected static void bothSparseMatmult(String instName,
                                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject output,
                                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject left,
                                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject right,
                                                boolean isLeftTransposed,
                                                boolean isRightTransposed)
                                         throws DMLRuntimeException
        Sparse C = Sparse op(A) * Sparse op(B) Reroutes call to sparse matrix-vector mult if needed
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        output - ?
        instName - name of the invoking instruction to recordStatistics.
        left - ?
        right - ?
        isLeftTransposed - ?
        isRightTransposed - ?
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • sparseMatrixVectorMult

        protected static void sparseMatrixVectorMult(String instName,
                                                     org.apache.sysml.runtime.controlprogram.caching.MatrixObject output,
                                                     int transA,
                                                     int m,
                                                     int n,
                                                     int k,
                                                     JCudaObject.CSRPointer A,
                                                     JCudaObject.CSRPointer B)
                                              throws DMLRuntimeException
        Does a sparse matrix-vector multiply. C = op(A) x B, A is a sparse matrix, B is a sparse vector with numCols = 1.
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        output - allocated output object C to which the GPU output matrix will be attached
        transA - if A is to be transposed or not (the op in op(A))
        m - number of rows in A (not op(A))
        n - number of cols in A (not op(A))
        k - number of rows in B, (cols in B is assumed to be 1)
        A - left sparse matrix on GPU
        B - right sparse vector on GPU
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • sparseSparseMatmult

        protected static void sparseSparseMatmult(String instName,
                                                  org.apache.sysml.runtime.controlprogram.caching.MatrixObject output,
                                                  int transA,
                                                  int transB,
                                                  int m,
                                                  int n,
                                                  int k,
                                                  JCudaObject.CSRPointer A,
                                                  JCudaObject.CSRPointer B)
                                           throws DMLRuntimeException
        Does a sparse-sparse Matrix multiply C = op(A) x op(B), A, B are sparse matrices
        Parameters:
        instName - the invoking instruction's name for record Statistics.
        output - allocated output object on host to which the GPU output matrix will be attached
        transA - op for A - to be transposed or not
        transB - op for B
        m - number of rows in op(A)
        n - number of cols in op(B)
        k - number of cols in op(A) or rows in op(B)
        A - left sparse matrix on GPU
        B - right sparse matrix on GPU
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • denseDenseMatmult

        protected static void denseDenseMatmult(String instName,
                                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject output,
                                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject left1,
                                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject right1,
                                                boolean isLeftTransposed1,
                                                boolean isRightTransposed1)
                                         throws DMLRuntimeException
        Dense dense matrix multiply C = op(A) * op(B), A and B are dense matrices
        Parameters:
        instName - name of the invoking instruction to recordStatistics.
        output - output object C on host with GPU data allocated
        left1 - left matrix A on host (in row-major order)
        right1 - right matrix B on host (in row-major order)
        isLeftTransposed1 - op for A, transposed or not
        isRightTransposed1 - op for B, transposed or not
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • denseDenseMatmult

        public static void denseDenseMatmult(String instName,
                                             jcuda.Pointer output,
                                             int leftRows1,
                                             int leftCols1,
                                             int rightRows1,
                                             int rightCols1,
                                             boolean isLeftTransposed1,
                                             boolean isRightTransposed1,
                                             jcuda.Pointer leftPtr,
                                             jcuda.Pointer rightPtr)
                                      throws DMLRuntimeException
        Dense-dense matrix multiply C = op(A) * op(B), A and B are dense matrices On the host, the matrices are in row-major format; cuBLAS expects them in column-major format. What we have as input is t(A) and t(B), t(X) = transpose of X. We do t(B) %*% t(A) to get t(C); If we were to calculate t(t(C), we would get the resultant matrix C, but this would be in column-major format. What we really want is t(C). This we already have as the result of t(B) %*% t(A).
        Parameters:
        instName - name of the invoking instruction to recordStatistics.
        output - output allocated on GPU in column major format
        leftRows1 - number of rows in A
        leftCols1 - number of cols in A
        rightRows1 - number of rows in B
        rightCols1 - number of cols in B
        isLeftTransposed1 - op for A, transposed or not
        isRightTransposed1 - op for B, transposed or not
        leftPtr - A allocated on the GPU in row-major format
        rightPtr - B allocated on the GPU in row-major format
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • unaryAggregate

        public static void unaryAggregate(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec,
                                          String instName,
                                          org.apache.sysml.runtime.controlprogram.caching.MatrixObject in1,
                                          String output,
                                          org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator op)
                                   throws DMLRuntimeException
        Entry point to perform Unary aggregate operations on the GPU. The execution context object is used to allocate memory for the GPU.
        Parameters:
        ec - Instance of ExecutionContext, from which the output variable will be allocated
        instName - name of the invoking instruction to recordStatistics.
        in1 - input matrix
        output - output matrix/scalar name
        op - Instance of AggregateUnaryOperator which encapsulates the direction of reduction/aggregation and the reduction operation.
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • matrixScalarArithmetic

        public static void matrixScalarArithmetic(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec,
                                                  String instName,
                                                  org.apache.sysml.runtime.controlprogram.caching.MatrixObject in,
                                                  String outputName,
                                                  boolean isInputTransposed,
                                                  org.apache.sysml.runtime.matrix.operators.ScalarOperator op)
                                           throws DMLRuntimeException
        Entry point to perform elementwise matrix-scalar operation specified by op
        Parameters:
        ec - execution context
        instName - the invoking instruction's name for record Statistics.
        in - input matrix
        outputName - output matrix name
        isInputTransposed - true if input transposed
        op - scalar operator
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • matrixScalarArithmetic

        public static void matrixScalarArithmetic(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec,
                                                  String instName,
                                                  org.apache.sysml.runtime.controlprogram.caching.MatrixObject in1,
                                                  org.apache.sysml.runtime.controlprogram.caching.MatrixObject in2,
                                                  String outputName,
                                                  boolean isLeftTransposed,
                                                  boolean isRightTransposed,
                                                  org.apache.sysml.runtime.matrix.operators.BinaryOperator op)
                                           throws DMLRuntimeException
        Performs elementwise operation specified by op of two input matrices in1 and in2
        Parameters:
        ec - execution context
        instName - the invoking instruction's name for record Statistics.
        in1 - input matrix 1
        in2 - input matrix 2
        outputName - output matrix name
        isLeftTransposed - true if left-transposed
        isRightTransposed - true if right-transposed
        op - binary operator
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • transpose

        public static void transpose(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec,
                                     String instName,
                                     org.apache.sysml.runtime.controlprogram.caching.MatrixObject in,
                                     String outputName)
                              throws DMLRuntimeException
        Transposes the input matrix using cublasDgeam
        Parameters:
        ec - execution context
        instName - the invoking instruction's name for record Statistics.
        in - input matrix
        outputName - output matrix name
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • exp

        public static void exp(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec,
                               String instName,
                               org.apache.sysml.runtime.controlprogram.caching.MatrixObject in1,
                               String outputName)
                        throws DMLRuntimeException
        Performs an "exp" operation on a matrix on the GPU
        Parameters:
        ec - execution context
        instName - the invoking instruction's name for record Statistics.
        in1 - input matrix
        outputName - output matrix name
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs
      • axpy

        public static void axpy(org.apache.sysml.runtime.controlprogram.context.ExecutionContext ec,
                                String instName,
                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject in1,
                                org.apache.sysml.runtime.controlprogram.caching.MatrixObject in2,
                                String outputName,
                                double constant)
                         throws DMLRuntimeException
        Performs daxpy operation
        Parameters:
        ec - execution context
        instName - the invoking instruction's name for record Statistics.
        in1 - input matrix 1
        in2 - input matrix 2
        outputName - output matrix name
        constant - pointer constant
        Throws:
        DMLRuntimeException - if DMLRuntimeException occurs

Copyright © 2017 The Apache Software Foundation. All rights reserved.