forked from kaldi-asr/kaldi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcublas-wrappers.h
More file actions
177 lines (163 loc) · 8.32 KB
/
cublas-wrappers.h
File metadata and controls
177 lines (163 loc) · 8.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// cudamatrix/cublas-wrappers.h
// Copyright 2013 Johns Hopkins University (author: Daniel Povey);
// See ../../COPYING for clarification regarding multiple authors
//
// 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
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABLITY OR NON-INFRINGEMENT.
// See the Apache 2 License for the specific language governing permissions and
// limitations under the License.
#ifndef KALDI_CUDAMATRIX_CUBLAS_WRAPPERS_H_
#define KALDI_CUDAMATRIX_CUBLAS_WRAPPERS_H_ 1
// Do not include this file directly. It is to be included
// by .cc files in this directory.
namespace kaldi {
#if HAVE_CUDA == 1
inline cublasStatus_t cublas_gemm(cublasHandle_t handle, cublasOperation_t transa,
cublasOperation_t transb, int m, int n,int k, float alpha,
const float *A, int lda, const float *B, int ldb, float beta,
float *C, int ldc) {
return cublasSgemm_v2(handle,transa,transb,m,n,k,&alpha,A,lda,B,ldb,&beta,C,ldc);
}
inline cublasStatus_t cublas_gemm(cublasHandle_t handle, cublasOperation_t transa,
cublasOperation_t transb, int m, int n,int k, double alpha,
const double *A, int lda, const double *B, int ldb, double beta,
double *C, int ldc) {
return cublasDgemm_v2(handle,transa,transb,m,n,k,&alpha,A,lda,B,ldb,&beta,C,ldc);
}
inline cublasStatus_t cublas_ger(cublasHandle_t handle, int m, int n, float alpha,
const float *x, int incx, const float *y, int incy, float *A, int lda ) {
return cublasSger_v2(handle,m,n,&alpha,x,incx,y,incy,A,lda);
}
inline cublasStatus_t cublas_ger(cublasHandle_t handle, int m, int n, double alpha,
const double *x, int incx, const double *y, int incy, double *A, int lda ) {
return cublasDger_v2(handle,m,n,&alpha,x,incx,y,incy,A,lda);
}
inline cublasStatus_t cublas_gemmBatched(cublasHandle_t handle, cublasOperation_t transa,
cublasOperation_t transb, int m, int n, int k, float alpha,
const float *A[], int lda, const float *B[], int ldb, float beta,
float *C[], int ldc, int batchCount) {
return cublasSgemmBatched(handle, transa, transb, m, n, k, &alpha, A, lda, B, ldb, &beta, C, ldc, batchCount);
}
inline cublasStatus_t cublas_gemmBatched(cublasHandle_t handle, cublasOperation_t transa,
cublasOperation_t transb, int m, int n, int k, double alpha,
const double *A[], int lda, const double *B[], int ldb, double beta,
double *C[], int ldc, int batchCount) {
return cublasDgemmBatched(handle, transa, transb, m, n, k, &alpha, A, lda, B, ldb, &beta, C, ldc, batchCount);
}
inline cublasStatus_t cublas_trsm(cublasHandle_t handle, int m, int n, float alpha,
const float* A, int lda, float* B, int ldb) {
return cublasStrsm_v2(handle,CUBLAS_SIDE_LEFT,CUBLAS_FILL_MODE_UPPER,CUBLAS_OP_N,CUBLAS_DIAG_NON_UNIT,m,n,&alpha,A,lda,B,ldb);
}
inline cublasStatus_t cublas_trsm(cublasHandle_t handle, int m, int n, double alpha,
const double* A, int lda, double* B, int ldb) {
return cublasDtrsm_v2(handle,CUBLAS_SIDE_LEFT,CUBLAS_FILL_MODE_UPPER,CUBLAS_OP_N,CUBLAS_DIAG_NON_UNIT,m,n,&alpha,A,lda,B,ldb);
}
inline cublasStatus_t cublas_syrk(cublasHandle_t handle, cublasFillMode_t uplo,
cublasOperation_t trans, int n, int k, float alpha,
const float *A, int lda, float beta, float *C, int ldc) {
return cublasSsyrk_v2(handle,uplo,trans,n,k,&alpha,A,lda,&beta,C,ldc);
}
inline cublasStatus_t cublas_syrk(cublasHandle_t handle, cublasFillMode_t uplo,
cublasOperation_t trans, int n, int k, double alpha,
const double *A, int lda, double beta, double *C, int ldc) {
return cublasDsyrk_v2(handle,uplo,trans,n,k,&alpha,A,lda,&beta,C,ldc);
}
inline cublasStatus_t cublas_dot(cublasHandle_t handle, int n, const float *x,
int incx, const float *y, int incy, float *result) {
return cublasSdot_v2(handle, n, x, incx, y, incy, result);
}
inline cublasStatus_t cublas_dot(cublasHandle_t handle, int n, const double *x,
int incx, const double *y, int incy, double *result) {
return cublasDdot_v2(handle, n, x, incx, y, incy, result);
}
inline cublasStatus_t cublas_asum(cublasHandle_t handle, int n, const float* x,
int incx, float *result) {
return cublasSasum_v2(handle, n, x, incx, result);
}
inline cublasStatus_t cublas_asum(cublasHandle_t handle, int n, const double* x,
int incx, double *result) {
return cublasDasum_v2(handle, n, x, incx, result);
}
inline cublasStatus_t cublas_nrm2(cublasHandle_t handle, int n, const float* x,
int incx, float *result) {
return cublasSnrm2_v2(handle, n, x, incx, result);
}
inline cublasStatus_t cublas_nrm2(cublasHandle_t handle, int n, const double* x,
int incx, double *result) {
return cublasDnrm2_v2(handle, n, x, incx, result);
}
inline cublasStatus_t cublas_copy(cublasHandle_t handle, int n, const float* x,
int incx, float* y, int incy) {
return cublasScopy_v2(handle,n,x,incx,y,incy);
}
inline cublasStatus_t cublas_copy(cublasHandle_t handle, int n, const double* x,
int incx, double* y, int incy) {
return cublasDcopy_v2(handle,n,x,incx,y,incy);
}
inline cublasStatus_t cublas_scal(cublasHandle_t handle, int n, float alpha,
float* mat, int incx) {
return cublasSscal_v2(handle, n, &alpha, mat, incx);
}
inline cublasStatus_t cublas_scal(cublasHandle_t handle, int n, double alpha,
double* mat, int incx) {
return cublasDscal_v2(handle, n, &alpha, mat, incx);
}
inline cublasStatus_t cublas_axpy(cublasHandle_t handle, int n, float alpha,
const float* x, int incx, float* y, int incy) {
return cublasSaxpy_v2(handle, n, &alpha, x, incx, y, incy);
}
inline cublasStatus_t cublas_axpy(cublasHandle_t handle, int n, double alpha,
const double* x, int incx, double* y, int incy) {
return cublasDaxpy_v2(handle, n, &alpha, x, incx, y, incy);
}
inline cublasStatus_t cublas_gemv(cublasHandle_t handle, cublasOperation_t trans,
int m, int n, float alpha, const float* A, int lda, const float* x,
int incx, float beta, float* y, int incy) {
return cublasSgemv_v2(handle,trans,m,n,&alpha,A,lda,x,incx,&beta,y,incy);
}
inline cublasStatus_t cublas_gemv(cublasHandle_t handle, cublasOperation_t trans,
int m, int n, double alpha, const double* A, int lda, const double* x,
int incx, double beta, double* y, int incy) {
return cublasDgemv_v2(handle,trans,m,n,&alpha,A,lda,x,incx,&beta,y,incy);
}
inline cublasStatus_t cublas_spmv(cublasHandle_t handle, cublasFillMode_t uplo,
int n, float alpha, const float *AP, const float *x, int incx,
float beta, float *y, int incy) {
return cublasSspmv_v2(handle, uplo, n, &alpha, AP, x, incx, &beta, y, incy);
}
inline cublasStatus_t cublas_spmv(cublasHandle_t handle, cublasFillMode_t uplo,
int n, double alpha, const double *AP, const double *x, int incx,
double beta, double *y, int incy) {
return cublasDspmv_v2(handle, uplo, n, &alpha, AP, x, incx, &beta, y, incy);
}
// Use caution with these, the 'transpose' argument is the opposite of what it
// should really be, due to CUDA storing things in column major order. We also
// had to switch 'l' to 'u'; we view our packed matrices as lower-triangular,
// row-by-row, but CUDA views the same layout as upper-triangular,
// column-by-column.
inline cublasStatus_t cublas_tpmv(cublasHandle_t handle, cublasOperation_t trans,
int n, const float* Ap, float* x, int incx) {
return cublasStpmv_v2(handle, CUBLAS_FILL_MODE_UPPER, trans, CUBLAS_DIAG_NON_UNIT, n, Ap, x, incx);
}
inline cublasStatus_t cublas_tpmv(cublasHandle_t handle, cublasOperation_t trans,
int n, const double* Ap, double* x,int incx) {
return cublasDtpmv_v2(handle, CUBLAS_FILL_MODE_UPPER, trans, CUBLAS_DIAG_NON_UNIT, n, Ap, x, incx);
}
inline cublasStatus_t cublas_spr(cublasHandle_t handle, cublasFillMode_t uplo,
int n, float alpha, const float *x, int incx, float *AP) {
return cublasSspr_v2(handle, uplo, n, &alpha, x, incx, AP);
}
inline cublasStatus_t cublas_spr(cublasHandle_t handle, cublasFillMode_t uplo,
int n, double alpha, const double *x, int incx, double *AP) {
return cublasDspr_v2(handle, uplo, n, &alpha, x, incx, AP);
}
#endif
}
// namespace kaldi
#endif