1 /*
2 
3     Copyright (C) 2014, The University of Texas at Austin
4 
5     This file is part of libflame and is available under the 3-Clause
6     BSD license, which can be found in the LICENSE file at the top-level
7     directory, or at http://opensource.org/licenses/BSD-3-Clause
8 
9 */
10 
11 #ifndef FLA_TYPE_DEFS_H
12 #define FLA_TYPE_DEFS_H
13 
14 #if   FLA_MULTITHREADING_MODEL == FLA_OPENMP
15 #ifdef FLA_ENABLE_TIDSP
16 #include <ti/omp/omp.h>
17 #else
18 #include <omp.h>
19 #endif
20 #elif FLA_MULTITHREADING_MODEL == FLA_PTHREADS
21 #include <pthread.h>
22 #endif
23 
24 
25 // --- Complex type definitions -----------------------------------------------
26 
27 #ifndef _DEFINED_SCOMPLEX
28 #define _DEFINED_SCOMPLEX
29 typedef struct scomplex
30 {
31   float real, imag;
32 } scomplex;
33 #endif
34 
35 #ifndef _DEFINED_DCOMPLEX
36 #define _DEFINED_DCOMPLEX
37 typedef struct dcomplex
38 {
39   double real, imag;
40 } dcomplex;
41 #endif
42 
43 
44 // --- Parameter and return type definitions ----------------------------------
45 
46 typedef int FLA_Bool;
47 typedef int FLA_Error;
48 typedef int FLA_Quadrant;
49 typedef int FLA_Datatype;
50 typedef int FLA_Elemtype;
51 typedef int FLA_Side;
52 typedef int FLA_Uplo;
53 typedef int FLA_Trans;
54 typedef int FLA_Conj;
55 typedef int FLA_Diag;
56 typedef int FLA_Dimension;
57 typedef int FLA_Pivot_type;
58 typedef int FLA_Direct;
59 typedef int FLA_Store;
60 typedef int FLA_Matrix_type;
61 typedef int FLA_Precision;
62 typedef int FLA_Domain;
63 typedef int FLA_Inv;
64 typedef int FLA_Evd_type;
65 typedef int FLA_Svd_type;
66 typedef int FLA_Machval;
67 typedef int FLA_Diag_off;
68 
69 #ifndef _DEFINED_DIM_T
70 #define _DEFINED_DIM_T
71 typedef unsigned long dim_t;
72 #endif
73 
74 // --- Intrinsic/assembly definitions ----------------------------------------
75 
76 #if FLA_VECTOR_INTRINSIC_TYPE == FLA_SSE_INTRINSICS
77 
78 #include "pmmintrin.h"
79 
80 //typedef double v2df __attribute__ ((vector_size (16)));
81 
82 typedef union
83 {
84     __m128  v;
85     float   f[4];
86 } v4sf_t;
87 
88 typedef union
89 {
90     __m128d v;
91     double  d[2];
92 } v2df_t;
93 
94 #endif
95 
96 // --- FLAME object definitions -----------------------------------------------
97 
98 typedef struct FLA_Lock_s     FLA_Lock;
99 
100 //#ifdef FLA_ENABLE_MULTITHREADING
101 struct FLA_Lock_s
102 {
103   // Implementation-specific lock object
104 #if   FLA_MULTITHREADING_MODEL == FLA_OPENMP
105   omp_lock_t       lock;
106 #elif FLA_MULTITHREADING_MODEL == FLA_PTHREADS
107   pthread_mutex_t  lock;
108 #endif
109 };
110 //#endif
111 
112 #ifdef FLA_ENABLE_SUPERMATRIX
113 typedef int                   FLASH_Verbose;
114 typedef int                   FLASH_Data_aff;
115 
116 typedef struct FLASH_Queue_s  FLASH_Queue;
117 typedef struct FLASH_Task_s   FLASH_Task;
118 typedef struct FLASH_Dep_s    FLASH_Dep;
119 #endif
120 typedef struct FLASH_Thread_s FLASH_Thread;
121 
122 typedef struct FLA_Obj_struct
123 {
124   // Basic object description fields
125   FLA_Datatype  datatype;
126   FLA_Elemtype  elemtype;
127   dim_t         m;
128   dim_t         n;
129   dim_t         rs;
130   dim_t         cs;
131   dim_t         m_inner;
132   dim_t         n_inner;
133   unsigned long id;
134   dim_t         m_index;
135   dim_t         n_index;
136 
137   dim_t         n_elem_alloc;
138   void*         buffer;
139   int           buffer_info;
140 
141   FLA_Uplo      uplo;
142 
143 #ifdef FLA_ENABLE_SUPERMATRIX
144   // Fields for supermatrix
145   int           n_read_blocks;
146   int           n_write_blocks;
147 
148   // All the tasks that previously read this block, anti-dependency
149   int           n_read_tasks;
150   FLASH_Dep*    read_task_head;
151   FLASH_Dep*    read_task_tail;
152 
153   // Task that last overwrote this block, flow dependency
154   FLASH_Task*   write_task;
155 #endif
156 } FLA_Base_obj;
157 
158 typedef struct FLA_Obj_view
159 {
160   // Basic object view description fields
161   dim_t         offm;
162   dim_t         offn;
163   dim_t         m;
164   dim_t         n;
165   dim_t         m_inner;
166   dim_t         n_inner;
167 
168   FLA_Base_obj* base;
169 
170 } FLA_Obj;
171 
172 #ifdef FLA_ENABLE_SUPERMATRIX
173 struct FLASH_Queue_s
174 {
175   // Number of tasks currently in queue
176   unsigned int  n_tasks;
177 
178   // Pointers to head (front) and tail (back) of queue
179   FLASH_Task*   head;
180   FLASH_Task*   tail;
181 };
182 
183 struct FLASH_Task_s
184 {
185   // Execution information
186   int           n_ready;
187 
188   // Labels
189   int           order;
190   int           queue;
191   int           height;
192   int           thread;
193   int           cache;
194   FLA_Bool      hit;
195 
196   // Function pointer
197   void*         func;
198 
199   // Control tree pointer
200   void*         cntl;
201 
202   // Name of task
203   char*         name;
204 
205   // GPU enabled task
206   FLA_Bool      enabled_gpu;
207 
208   // Integer arguments
209   int           n_int_args;
210   int*          int_arg;
211 
212   // Constant FLA_Obj arguments
213   int           n_fla_args;
214   FLA_Obj*      fla_arg;
215 
216   // Input FLA_Obj arguments
217   int           n_input_args;
218   FLA_Obj*      input_arg;
219 
220   // Output FLA_Obj argument
221   int           n_output_args;
222   FLA_Obj*      output_arg;
223 
224   // Number of blocks within all macroblocks
225   int           n_macro_args;
226 
227   // Number of write after read dependencies
228   int           n_war_args;
229 
230   // Dependence information
231   int           n_dep_args;
232   FLASH_Dep*    dep_arg_head;
233   FLASH_Dep*    dep_arg_tail;
234 
235   // Support for a doubly linked list of tasks
236   FLASH_Task*   prev_task;
237   FLASH_Task*   next_task;
238 
239   // Support for a doubly linked list for wait queue
240   FLASH_Task*   prev_wait;
241   FLASH_Task*   next_wait;
242 };
243 
244 struct FLASH_Dep_s
245 {
246   // Task yielding dependency
247   FLASH_Task*   task;
248 
249   // Support for linked list of FLASH_Deps
250   FLASH_Dep*    next_dep;
251 };
252 #endif // FLA_ENABLE_SUPERMATRIX
253 
254 struct FLASH_Thread_s
255 {
256   // The thread's unique identifier
257   int       id;
258 
259   // Pointer to variables needed to execute SuperMatrix mechanism
260   void*     args;
261 
262 #if FLA_MULTITHREADING_MODEL == FLA_PTHREADS
263   // The thread object. Only needed for the POSIX threads implementation.
264   pthread_t pthread_obj;
265 #endif
266 };
267 
268 #endif // FLA_TYPE_DEFS_H
269