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
|
#include <algorithm>
#include <cctype>
#include BLAS_HEADER
#include <interfaces/blas/F77/xerbla.h>
#include <ulmblas/level3/gemm.h>
extern "C" {
void
F77BLAS(dgemm)(const char *transA_,
const char *transB_,
const int *m_,
const int *n_,
const int *k_,
const double *alpha_,
const double *A,
const int *ldA_,
const double *B,
const int *ldB_,
const double *beta_,
double *C,
const int *ldC_)
{
//
// Dereference scalar parameters
//
bool transA = (toupper(*transA_) == 'T' || toupper(*transA_) == 'C');
bool transB = (toupper(*transB_) == 'T' || toupper(*transB_) == 'C');
int m = *m_;
int n = *n_;
int k = *k_;
double alpha = *alpha_;
int ldA = *ldA_;
int ldB = *ldB_;
double beta = *beta_;
int ldC = *ldC_;
//
// Set numRowsA and numRowsB as the number of rows of A and B
//
int numRowsA = (!transA) ? m : k;
int numRowsB = (!transB) ? k : n;
//
// Test the input parameters
//
int info = 0;
if (toupper(*transA_)!='N'
&& toupper(*transA_)!='T'
&& toupper(*transA_)!='C'
&& toupper(*transA_)!='R')
{
info = 1;
} else if (toupper(*transB_)!='N'
&& toupper(*transB_)!='T'
&& toupper(*transB_)!='C'
&& toupper(*transB_)!='R')
{
info = 2;
} else if (m<0) {
info = 3;
} else if (n<0) {
info = 4;
} else if (k<0) {
info = 5;
} else if (ldA<std::max(1,numRowsA)) {
info = 8;
} else if (ldB<std::max(1,numRowsB)) {
info = 10;
} else if (ldC<std::max(1,m)) {
info = 13;
}
if (info!=0) {
F77BLAS(xerbla)("DGEMM ", &info);
}
//
// Start the operations.
//
if (!transB) {
if (!transA) {
//
// Form C := alpha*A*B + beta*C.
//
ulmBLAS::gemm(m, n, k,
alpha,
A, 1, ldA,
B, 1, ldB,
beta,
C, 1, ldC);
} else {
//
// Form C := alpha*A**T*B + beta*C
//
ulmBLAS::gemm(m, n, k,
alpha,
A, ldA, 1,
B, 1, ldB,
beta,
C, 1, ldC);
}
} else {
if (!transA) {
//
// Form C := alpha*A*B**T + beta*C
//
ulmBLAS::gemm(m, n, k,
alpha,
A, 1, ldA,
B, ldB, 1,
beta,
C, 1, ldC);
} else {
//
// Form C := alpha*A**T*B**T + beta*C
//
ulmBLAS::gemm(m, n, k,
alpha,
A, ldA, 1,
B, ldB, 1,
beta,
C, 1, ldC);
}
}
}
} // extern "C"
|