-
Notifications
You must be signed in to change notification settings - Fork 0
/
gemv.h
111 lines (103 loc) · 3.44 KB
/
gemv.h
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
/**
* Copyright 2014 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
#if !defined(_GEMV_H_)
#define _GEMV_H_
#include <cuda.h> // CUDA_VERSION
#include <cublas_v2.h>
#include "error_util.h"
//#define DISABLE_GEMV
void gemv(cublasHandle_t cublasHandle, int m, int n, double alpha,
const double *A, const double *x,
double beta, double *y)
{
#ifdef DISABLE_GEMV
checkCublasErrors( cublasDgemm (cublasHandle,
CUBLAS_OP_T,
CUBLAS_OP_N,
n,
1,
m,
&alpha,
A,
m,
x,
m,
&beta,
y,
m) );
#else
checkCublasErrors( cublasDgemv(cublasHandle, CUBLAS_OP_T,
m, n,
&alpha,
A, m,
x, 1,
&beta,
y, 1) );
#endif
};
void gemv(cublasHandle_t cublasHandle, int m, int n, float alpha,
const float *A, const float *x,
float beta, float *y)
{
#ifdef DISABLE_GEMV
checkCublasErrors( cublasSgemm (cublasHandle,
CUBLAS_OP_T,
CUBLAS_OP_N,
n,
1,
m,
&alpha,
A,
m,
x,
m,
&beta,
y,
m) );
#else
// this branch is executed
checkCublasErrors( cublasSgemv(cublasHandle, CUBLAS_OP_T,
m, n,
&alpha,
A, m,
x, 1,
&beta,
y, 1) );
#endif
};
#if defined(CUDA_VERSION) && (CUDA_VERSION > 7000)
#if (CUDA_VERSION < 8000)
#define CUDA_R_16F CUBLAS_DATA_HALF
#endif
void gemv(cublasHandle_t cublasHandle, int m, int n, float alpha,
const half1 *A, const half1 *x,
float beta, half1 *y)
{
checkCublasErrors( cublasSgemmEx ( cublasHandle,
CUBLAS_OP_T,
CUBLAS_OP_N,
n,
1,
m,
&alpha,
A,
CUDA_R_16F,
m,
x,
CUDA_R_16F,
m,
&beta,
y,
CUDA_R_16F,
m) );
};
#endif
#endif // _GEMV_H_