- Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathcommon_thread.h
216 lines (173 loc) · 6.91 KB
/
common_thread.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*********************************************************************/
/* Copyright 2009, 2010 The University of Texas at Austin. */
/* All rights reserved. */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* 1. Redistributions of source code must retain the above */
/* copyright notice, this list of conditions and the following */
/* disclaimer. */
/* */
/* 2. Redistributions in binary form must reproduce the above */
/* copyright notice, this list of conditions and the following */
/* disclaimer in the documentation and/or other materials */
/* provided with the distribution. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
/* POSSIBILITY OF SUCH DAMAGE. */
/* */
/* The views and conclusions contained in the software and */
/* documentation are those of the authors and should not be */
/* interpreted as representing official policies, either expressed */
/* or implied, of The University of Texas at Austin. */
/*********************************************************************/
#ifndefCOMMON_THREAD
#defineCOMMON_THREAD
#ifdefUSE_OPENMP
#include<omp.h>
externvoidgoto_set_num_threads(intnthreads);
#endif
/* Basic Thread Debugging */
#undef SMP_DEBUG
/* Thread Timing Debugging */
#undef TIMING_DEBUG
/* Global Parameter */
externintblas_cpu_number;
externintblas_num_threads;
externintblas_num_threads_set;
externintblas_omp_linked;
#defineBLAS_LEGACY 0x8000U
#defineBLAS_PTHREAD 0x4000U
#defineBLAS_NODE 0x2000U
#defineBLAS_PREC 0x000FU
#defineBLAS_INT8 0x0000U
#defineBLAS_BFLOAT16 0x0001U
#defineBLAS_SINGLE 0x0002U
#defineBLAS_DOUBLE 0x0003U
#defineBLAS_XDOUBLE 0x0004U
#defineBLAS_STOBF16 0x0008U
#defineBLAS_DTOBF16 0x0009U
#defineBLAS_BF16TOS 0x000AU
#defineBLAS_BF16TOD 0x000BU
#defineBLAS_REAL 0x0000U
#defineBLAS_COMPLEX 0x1000U
#defineBLAS_TRANSA 0x0030U /* 2bit */
#defineBLAS_TRANSA_N 0x0000U
#defineBLAS_TRANSA_T 0x0010U
#defineBLAS_TRANSA_R 0x0020U
#defineBLAS_TRANSA_C 0x0030U
#defineBLAS_TRANSA_SHIFT 4
#defineBLAS_TRANSB 0x0300U /* 2bit */
#defineBLAS_TRANSB_N 0x0000U
#defineBLAS_TRANSB_T 0x0100U
#defineBLAS_TRANSB_R 0x0200U
#defineBLAS_TRANSB_C 0x0300U
#defineBLAS_TRANSB_SHIFT 8
#defineBLAS_RSIDE 0x0400U
#defineBLAS_RSIDE_SHIFT 10
#defineBLAS_UPLO 0x0800U
#defineBLAS_UPLO_SHIFT 11
#defineBLAS_STATUS_NOTYET 0
#defineBLAS_STATUS_QUEUED 1
#defineBLAS_STATUS_RUNNING 2
#defineBLAS_STATUS_FINISHED 4
typedefstructblas_queue {
void*routine;
BLASLONGposition;
BLASLONGassigned;
blas_arg_t*args;
void*range_m;
void*range_n;
void*sa, *sb;
structblas_queue*next;
#if defined( __WIN32__) || defined(__CYGWIN32__) || defined(_WIN32) || defined(__CYGWIN__)
CRITICAL_SECTIONlock;
HANDLEfinish;
#else
pthread_mutex_tlock;
pthread_cond_tfinished;
#endif
intmode, status;
#ifdefCONSISTENT_FPCSR
unsigned intsse_mode, x87_mode;
#endif
#ifdefSMP_DEBUG
intnum;
#endif
#ifdefTIMING_DEBUG
unsigned intclocks;
#endif
} blas_queue_t;
#ifdefSMP_SERVER
externintblas_server_avail;
static __inline intnum_cpu_avail(intlevel) {
#ifdefUSE_OPENMP
intopenmp_nthreads;
if (blas_num_threads_set==0)
openmp_nthreads=omp_get_max_threads();
else
openmp_nthreads=blas_cpu_number;
#endif
#ifndefUSE_OPENMP
if (blas_cpu_number==1
#endif
#ifdefUSE_OPENMP
if (openmp_nthreads==1||omp_in_parallel()
#endif
) return1;
#ifdefUSE_OPENMP
if (blas_cpu_number!=openmp_nthreads) {
goto_set_num_threads(openmp_nthreads);
}
#endif
returnblas_cpu_number;
}
static __inline voidblas_queue_init(blas_queue_t*queue){
queue->sa=NULL;
queue->sb=NULL;
queue->next=NULL;
}
intblas_thread_init(void);
intBLASFUNC(blas_thread_shutdown)(void);
intexec_blas(BLASLONG, blas_queue_t*);
intexec_blas_async(BLASLONG, blas_queue_t*);
intexec_blas_async_wait(BLASLONG, blas_queue_t*);
#else
intexec_blas_async(BLASLONGnum_cpu, blas_param_t*param, pthread_t*);
intexec_blas_async_wait(BLASLONGnum_cpu, pthread_t*blas_threads);
intexec_blas(BLASLONGnum_cpu, blas_param_t*param, void*buffer);
#endif
#ifndefASSEMBLER
intblas_level1_thread(intmode, BLASLONGm, BLASLONGn, BLASLONGk, void*alpha,
void*a, BLASLONGlda,
void*b, BLASLONGldb,
void*c, BLASLONGldc, int (*function)(), intthreads);
intgemm_thread_m (intmode, blas_arg_t*, BLASLONG*, BLASLONG*, int (*function)(), void*, void*, BLASLONG);
intgemm_thread_n (intmode, blas_arg_t*, BLASLONG*, BLASLONG*, int (*function)(), void*, void*, BLASLONG);
intgemm_thread_mn(intmode, blas_arg_t*, BLASLONG*, BLASLONG*, int (*function)(), void*, void*, BLASLONG);
intgemm_thread_variable(intmode, blas_arg_t*, BLASLONG*, BLASLONG*, int (*function)(), void*, void*, BLASLONG, BLASLONG);
inttrsm_thread(intmode, BLASLONGm, BLASLONGn,
doublealpha_r, doublealpha_i,
void*a, BLASLONGlda,
void*c, BLASLONGldc, int (*function)(), void*buffer);
intsyrk_thread(intmode, blas_arg_t*, BLASLONG*, BLASLONG*, int (*function)(), void*, void*, BLASLONG);
intgetrf_thread(intmode, BLASLONGm, BLASLONGn, BLASLONGk,
void*offsetA, BLASLONGlda,
void*offsetB, BLASLONGjb,
void*ipiv, BLASLONGoffset, int (*function)(), void*buffer);
#endif/* ENDIF ASSEMBLER */
#endif