hl_cuda_cublas.h 6.3 KB
Newer Older
Z
zhangjinchao01 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#ifndef HL_CUDA_CUBLAS_H_
#define HL_CUDA_CUBLAS_H_

#include "hl_base.h"

/**
 * @brief   Matrix transpose: C_d = T(A_d)
 *
L
lzhao4ever 已提交
23 24
 * @param[in]   A_d     input matrix (dimM x dimN).
 * @param[out]  C_d     output matrix (dimN x dimM).
Z
zhangjinchao01 已提交
25 26 27 28 29 30
 * @param[in]   dimM    matrix height.
 * @param[in]   dimN    matrix width.
 * @param[in]   lda     the first dimension of A_d.
 * @param[in]   ldc     the first dimension of C_d.
 *
 */
31 32
extern void hl_matrix_transpose(
    real *A_d, real *C_d, int dimM, int dimN, int lda, int ldc);
Z
zhangjinchao01 已提交
33 34 35 36

/*
 * @brief Matrix transpose, while lda = dimN, ldc = dimM.
 *
L
lzhao4ever 已提交
37 38
 * @param[in]   A_d     input matrix (dimM x dimN).
 * @param[out]  C_d     output matrix (dimN x dimM).
Z
zhangjinchao01 已提交
39 40 41 42
 * @param[in]   dimM    matrix height.
 * @param[in]   dimN    matrix width.
 *
 */
43
extern void hl_matrix_transpose(real *A_d, real *C_d, int dimM, int dimN);
Z
zhangjinchao01 已提交
44

L
lzhao4ever 已提交
45 46 47 48 49 50 51 52 53 54
/*
 * @brief Matrix inverse
 *
 * @param[in]   A_d    input matrix (dimN x dimN).
 * @param[out]  C_d    output matrix (dimN x dimN).
 * @param[in]   dimN   matrix height = matrix width
 * @param[in]   lda    the first dimension of A_d
 * @param[in]   ldc    the first dimension of C_d
 *
 */
55
extern void hl_matrix_inverse(real *A_d, real *C_d, int dimN, int lda, int ldc);
L
lzhao4ever 已提交
56

Z
zhangjinchao01 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
/**
 * @brief   C_d = alpha*(op(A_d) * op(B_d)) + beta*C_d
 *
 * @param[in]   A_d     input.
 * @param[in]   transa  operation op(A) that is non-or transpose.
 * @param[in]   B_d     input.
 * @param[in]   transb  operation op(B) that is non-or transpose.
 * @param[out]  C_d     output.
 * @param[in]   dimM    matrix height of op(A) & C
 * @param[in]   dimN    matrix width of op(B) & C
 * @param[in]   dimK    width of op(A) & height of op(B)
 * @param[in]   alpha   scalar used for multiplication.
 * @param[in]   beta    scalar used for multiplication.
 * @param[in]   lda     the first dimension of A_d.
 * @param[in]   ldb     the first dimension of B_d.
 * @param[in]   ldc     the first dimension of C_d.
 *
 */
75 76 77 78
extern void hl_matrix_mul(real *A_d,
                          hl_trans_op_t transa,
                          real *B_d,
                          hl_trans_op_t transb,
Z
zhangjinchao01 已提交
79
                          real *C_d,
80 81 82 83 84 85 86 87
                          int dimM,
                          int dimN,
                          int dimK,
                          real alpha,
                          real beta,
                          int lda,
                          int ldb,
                          int ldc);
Z
zhangjinchao01 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

/**
 * @brief   C_d = alpha*(op(A_d) * op(B_d)) + beta*C_d
 *
 * @param[in]   A_d     input.
 * @param[in]   transa  operation op(A) that is non-or transpose.
 * @param[in]   B_d     input.
 * @param[in]   transb  operation op(B) that is non-or transpose.
 * @param[out]  C_d     output.
 * @param[in]   dimM    matrix height of op(A) & C
 * @param[in]   dimN    matrix width of op(B) & C
 * @param[in]   dimK    width of op(A) & height of op(B)
 * @param[in]   alpha   scalar used for multiplication.
 * @param[in]   beta    scalar used for multiplication.
 *
 */
104 105 106 107
extern void hl_matrix_mul(real *A_d,
                          hl_trans_op_t transa,
                          real *B_d,
                          hl_trans_op_t transb,
Z
zhangjinchao01 已提交
108
                          real *C_d,
109 110 111 112 113
                          int dimM,
                          int dimN,
                          int dimK,
                          real alpha,
                          real beta);
Z
zhangjinchao01 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

/**
 * @brief   This function performs the matrix-vector multiplication.
 *          C_d = alpha*op(A_d)*B_d + beta*C_d
 *
 * @param[in]     A_d    matrix.
 * @param[in]     trans  operation op(A) that is non-or transpose.
 * @param[in]     B_d    vector with dimN(dimM) elements
 *                       if trans==HPPL_OP_N(HPPL_OP_T).
 * @param[in,out] C_d    vector with dimM(dimN) elements
 *                       if trans==HPPL_OP_N(HPPL_OP_T).
 * @param[in]     dimM   number of rows of matrix A_d.
 * @param[in]     dimN   number of columns of matrix A_d.
 * @param[in]     alpha  scalar used for multiplication.
 * @param[in]     beta   scalar used for multiplication.
 * @param[in]     lda    the first dimension of A_d.
 * @param[in]     incb   increase B_d size for compaction.
 * @param[in]     incc   increase C_d size for compaction.
 *
 */

135 136 137 138 139 140 141 142 143 144 145
extern void hl_matrix_mul_vector(real *A_d,
                                 hl_trans_op_t trans,
                                 real *B_d,
                                 real *C_d,
                                 int dimM,
                                 int dimN,
                                 real alpha,
                                 real beta,
                                 int lda,
                                 int incb,
                                 int incc);
Z
zhangjinchao01 已提交
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

/**
 * @brief   This function performs the matrix-vector multiplication.
 *          C_d = alpha*op(A_d)*B_d + beta*C_d
 *
 * @param[in]     A_d    matrix.
 * @param[in]     trans  operation op(A) that is non-or transpose.
 * @param[in]     B_d    vector with dimN(dimM) elements
 *                       if trans==HPPL_OP_N(HPPL_OP_T).
 * @param[in,out] C_d    vector with dimM(dimN) elements
 *                       if trans==HPPL_OP_N(HPPL_OP_T).
 * @param[in]     dimM   number of rows of matrix A_d.
 * @param[in]     dimN   number of columns of matrix A_d.
 * @param[in]     alpha  scalar used for multiplication.
 * @param[in]     beta   scalar used for multiplication.
 *
 */
163 164 165 166 167 168 169 170
extern void hl_matrix_mul_vector(real *A_d,
                                 hl_trans_op_t trans,
                                 real *B_d,
                                 real *C_d,
                                 int dimM,
                                 int dimN,
                                 real alpha,
                                 real beta);
Z
zhangjinchao01 已提交
171 172

#endif /* HL_CUDA_CUBLAS_H_ */