fix build error
[platform/upstream/openblas.git] / common_thread.h
1 /*********************************************************************/
2 /* Copyright 2009, 2010 The University of Texas at Austin.           */
3 /* All rights reserved.                                              */
4 /*                                                                   */
5 /* Redistribution and use in source and binary forms, with or        */
6 /* without modification, are permitted provided that the following   */
7 /* conditions are met:                                               */
8 /*                                                                   */
9 /*   1. Redistributions of source code must retain the above         */
10 /*      copyright notice, this list of conditions and the following  */
11 /*      disclaimer.                                                  */
12 /*                                                                   */
13 /*   2. Redistributions in binary form must reproduce the above      */
14 /*      copyright notice, this list of conditions and the following  */
15 /*      disclaimer in the documentation and/or other materials       */
16 /*      provided with the distribution.                              */
17 /*                                                                   */
18 /*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
19 /*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
20 /*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
21 /*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
22 /*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
23 /*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
24 /*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
25 /*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
26 /*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
27 /*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
28 /*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
29 /*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
30 /*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
31 /*    POSSIBILITY OF SUCH DAMAGE.                                    */
32 /*                                                                   */
33 /* The views and conclusions contained in the software and           */
34 /* documentation are those of the authors and should not be          */
35 /* interpreted as representing official policies, either expressed   */
36 /* or implied, of The University of Texas at Austin.                 */
37 /*********************************************************************/
38
39 #ifndef COMMON_THREAD
40 #define COMMON_THREAD
41
42 #ifdef USE_OPENMP
43 #include <omp.h>
44 extern void goto_set_num_threads(int nthreads);
45 #endif
46
47 /* Basic Thread Debugging */
48 #undef SMP_DEBUG
49
50 /* Thread Timing Debugging */
51 #undef TIMING_DEBUG
52
53 /* Global Parameter */
54 extern int blas_cpu_number;
55 extern int blas_num_threads;
56 extern int blas_omp_linked;
57
58 #define BLAS_LEGACY     0x8000U
59 #define BLAS_PTHREAD    0x4000U
60 #define BLAS_NODE       0x2000U
61
62 #define BLAS_PREC       0x0003U
63 #define BLAS_SINGLE     0x0000U
64 #define BLAS_DOUBLE     0x0001U
65 #define BLAS_XDOUBLE    0x0002U
66 #define BLAS_REAL       0x0000U
67 #define BLAS_COMPLEX    0x0004U
68
69 #define BLAS_TRANSA     0x0030U /* 2bit */
70 #define BLAS_TRANSA_N   0x0000U
71 #define BLAS_TRANSA_T   0x0010U
72 #define BLAS_TRANSA_R   0x0020U
73 #define BLAS_TRANSA_C   0x0030U
74 #define BLAS_TRANSA_SHIFT     4
75
76 #define BLAS_TRANSB     0x0300U /* 2bit */
77 #define BLAS_TRANSB_N   0x0000U
78 #define BLAS_TRANSB_T   0x0100U
79 #define BLAS_TRANSB_R   0x0200U
80 #define BLAS_TRANSB_C   0x0300U
81 #define BLAS_TRANSB_SHIFT     8
82
83 #define BLAS_RSIDE      0x0400U
84 #define BLAS_RSIDE_SHIFT     10
85 #define BLAS_UPLO       0x0800U
86 #define BLAS_UPLO_SHIFT      11
87
88 #define BLAS_STATUS_NOTYET      0
89 #define BLAS_STATUS_QUEUED      1
90 #define BLAS_STATUS_RUNNING     2
91 #define BLAS_STATUS_FINISHED    4
92
93 typedef struct blas_queue {
94
95   void *routine;
96   BLASLONG position;
97   BLASLONG assigned;
98
99   blas_arg_t *args;
100   void *range_m;
101   void *range_n;
102   void *sa, *sb;
103
104   struct blas_queue *next;
105
106 #if defined( __WIN32__) || defined(__CYGWIN32__) || defined(_WIN32) || defined(__CYGWIN__)
107   CRITICAL_SECTION lock;
108   HANDLE finish;
109 #else
110   pthread_mutex_t        lock;
111   pthread_cond_t         finished;
112 #endif
113
114   int mode, status;
115
116 #ifdef CONSISTENT_FPCSR
117   unsigned int sse_mode, x87_mode;
118 #endif
119
120 #ifdef SMP_DEBUG
121   int    num;
122 #endif
123 #ifdef TIMING_DEBUG
124   unsigned int clocks;
125 #endif
126 } blas_queue_t;
127
128 #ifdef SMP_SERVER
129
130 extern int blas_server_avail;
131
132 static __inline int num_cpu_avail(int level) {
133
134 #ifdef USE_OPENMP
135         int openmp_nthreads=0;
136 #endif
137
138   if (blas_cpu_number == 1
139
140 #ifdef USE_OPENMP
141       || omp_in_parallel()
142 #endif
143       ) return 1;
144
145 #ifdef USE_OPENMP
146   openmp_nthreads=omp_get_max_threads();
147   if (blas_cpu_number != openmp_nthreads) {
148           goto_set_num_threads(openmp_nthreads);
149   }
150 #endif
151
152   return blas_cpu_number;
153
154 }
155
156 static __inline void blas_queue_init(blas_queue_t *queue){
157
158   queue -> sa    = NULL;
159   queue -> sb    = NULL;
160   queue-> next  = NULL;
161 }
162
163 int blas_thread_init(void);
164 int BLASFUNC(blas_thread_shutdown)(void);
165 int exec_blas(BLASLONG, blas_queue_t *);
166 int exec_blas_async(BLASLONG, blas_queue_t *);
167 int exec_blas_async_wait(BLASLONG, blas_queue_t *);
168
169 #else
170 int exec_blas_async(BLASLONG num_cpu, blas_param_t *param, pthread_t *);
171 int exec_blas_async_wait(BLASLONG num_cpu, pthread_t *blas_threads);
172 int exec_blas(BLASLONG num_cpu, blas_param_t *param, void *buffer);
173 #endif
174
175 #ifndef ASSEMBLER
176
177 int blas_level1_thread(int mode, BLASLONG m, BLASLONG n, BLASLONG k, void *alpha,
178                        void *a, BLASLONG lda,
179                        void *b, BLASLONG ldb,
180                        void *c, BLASLONG ldc, int (*function)(), int threads);
181
182 int gemm_thread_m (int mode, blas_arg_t *, BLASLONG *, BLASLONG *, int (*function)(), void *, void *, BLASLONG);
183
184 int gemm_thread_n (int mode, blas_arg_t *, BLASLONG *, BLASLONG *, int (*function)(), void *, void *, BLASLONG);
185
186 int gemm_thread_mn(int mode, blas_arg_t *, BLASLONG *, BLASLONG *, int (*function)(), void *, void *, BLASLONG);
187
188 int gemm_thread_variable(int mode, blas_arg_t *, BLASLONG *, BLASLONG *, int (*function)(), void *, void *, BLASLONG, BLASLONG);
189
190 int trsm_thread(int mode, BLASLONG m, BLASLONG n,
191                 double alpha_r, double alpha_i,
192                 void *a, BLASLONG lda,
193                 void *c, BLASLONG ldc, int (*function)(), void *buffer);
194
195 int syrk_thread(int mode, blas_arg_t *, BLASLONG *, BLASLONG *, int (*function)(), void *, void *, BLASLONG);
196
197 int beta_thread(int mode, BLASLONG m, BLASLONG n,
198                 double alpha_r, double alpha_i,
199                 void *c, BLASLONG ldc, int (*fuction)());
200
201 int getrf_thread(int mode, BLASLONG m, BLASLONG n, BLASLONG k,
202                  void *offsetA, BLASLONG lda,
203                  void *offsetB, BLASLONG jb,
204                  void *ipiv, BLASLONG offset, int (*function)(), void *buffer);
205
206 #endif  /* ENDIF ASSEMBLER */
207
208 #endif