MAGMA  magma-1.4.0
Matrix Algebra on GPU and Multicore Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
magma.h
Go to the documentation of this file.
1 /*
2  -- MAGMA (version 1.4.0) --
3  Univ. of Tennessee, Knoxville
4  Univ. of California, Berkeley
5  Univ. of Colorado, Denver
6  August 2013
7 */
8 
9 #include <quark.h>
10 
11 #ifndef _MAGMA_
12 #define _MAGMA_
13 
14 /* ------------------------------------------------------------
15  * MAGMA Blas Functions
16  * --------------------------------------------------------- */
17 #include "magmablas.h"
18 
19 #include "auxiliary.h"
20 
21 /* ------------------------------------------------------------
22  * MAGMA Context
23  * --------------------------------------------------------- */
24 
25 typedef struct context
26 {
27  /* Number of CPU core in this context */
29 
30  /* Number of GPUs in this context */
32 
33  /* GPU contexts */
34  CUcontext *gpu_context;
35 
36  /* QUARK scheduler */
38 
39  /* Block size, internally used for some algorithms */
41 
42  /* Pointer to other global algorithm-dependent parameters */
43  void *params;
44 
46 
47 /* ------------------------------------------------------------
48  * MAGMA functions
49  * --------------------------------------------------------- */
50 #include "magma_z.h"
51 #include "magma_c.h"
52 #include "magma_d.h"
53 #include "magma_s.h"
54 #include "magma_zc.h"
55 #include "magma_ds.h"
56 
57 #define MagmaNoTrans 'N'
58 #define MagmaTrans 'T'
59 #define MagmaConjTrans 'C'
60 
61 #define MagmaUpper 'U'
62 #define MagmaLower 'L'
63 #define MagmaUpperLower 'A'
64 
65 #define MagmaNonUnit 'N'
66 #define MagmaUnit 'U'
67 
68 #define MagmaLeft 'L'
69 #define MagmaRight 'R'
70 
71 #define MagmaForward 'F'
72 #define MagmaBackward 'B'
73 
74 #define MagmaColumnwise 'C'
75 #define MagmaRowwise 'R'
76 
77 #define MagmaNoVectors 'N'
78 #define MagmaVectors 'V'
79 
80 #define MagmaNoTransStr "NonTrans"
81 #define MagmaTransStr "Trans"
82 #define MagmaConjTransStr "Conj"
83 
84 #define MagmaUpperStr "Upper"
85 #define MagmaLowerStr "Lower"
86 #define MagmaUpperLowerStr "All"
87 
88 #define MagmaNonUnitStr "NonUnit"
89 #define MagmaUnitStr "Unit"
90 
91 #define MagmaLeftStr "Left"
92 #define MagmaRightStr "Right"
93 
94 #define MagmaForwardStr "Forward"
95 #define MagmaBackwardStr "Backward"
96 
97 #define MagmaColumnwiseStr "Columnwise"
98 #define MagmaRowwiseStr "Rowwise"
99 
100 #define MagmaNoVectorsStr "NoVectors"
101 #define MagmaVectorsStr "Vectors"
102 
103 /* ------------------------------------------------------------
104  * Return codes
105  * --------------------------------------------------------- */
106 #define MAGMA_SUCCESS 0
107 #define MAGMA_ERR_ILLEGAL_VALUE -4
108 #define MAGMA_ERR_ALLOCATION -5
109 #define MAGMA_ERR_HOSTALLOC -6
110 #define MAGMA_ERR_CUBLASALLOC -7
111 
112 /* ------------------------------------------------------------
113  * Macros to deal with cuda complex
114  * --------------------------------------------------------- */
115 #define MAGMA_Z_SET2REAL(v, t) (v).x = (t); (v).y = 0.0
116 #define MAGMA_Z_OP_NEG_ASGN(t, z) (t).x = -(z).x; (t).y = -(z).y
117 #define MAGMA_Z_EQUAL(u,v) (((u).x == (v).x) && ((u).y == (v).y))
118 #define MAGMA_Z_GET_X(u) ((u).x)
119 #define MAGMA_Z_ASSIGN(v, t) (v).x = (t).x; (v).y = (t).y
120 #define MAGMA_Z_CNJG(v, t) (v).x = (t).x; (v).y = -(t).y
121 #define MAGMA_Z_DSCALE(v, t, s) (v).x = (t).x/(s); (v).y = (t).y/(s)
122 #define MAGMA_Z_OP_NEG(a, b, c) (a).x = (b).x-(c).x; (a).y = (b).y-(c).y
123 #define MAGMA_Z_MAKE(r, i) make_cuDoubleComplex((r), (i))
124 #define MAGMA_Z_REAL(a) cuCreal(a)
125 #define MAGMA_Z_IMAG(a) cuCimag(a)
126 #define MAGMA_Z_ADD(a, b) cuCadd((a), (b))
127 #define MAGMA_Z_SUB(a, b) cuCsub((a), (b))
128 #define MAGMA_Z_MUL(a, b) cuCmul((a), (b))
129 #define MAGMA_Z_DIV(a, b) cuCdiv((a), (b))
130 #define MAGMA_Z_ABS(a) cuCabs((a))
131 #define MAGMA_Z_ZERO make_cuDoubleComplex(0.0, 0.0)
132 #define MAGMA_Z_ONE make_cuDoubleComplex(1.0, 0.0)
133 #define MAGMA_Z_HALF make_cuDoubleComplex(0.5, 0.0)
134 #define MAGMA_Z_NEG_ONE make_cuDoubleComplex(-1.0, 0.0)
135 #define MAGMA_Z_NEG_HALF make_cuDoubleComplex(-0.5, 0.0)
136 
137 #define MAGMA_C_SET2REAL(v, t) (v).x = (t); (v).y = 0.0
138 #define MAGMA_C_OP_NEG_ASGN(t, z) (t).x = -(z).x; (t).y = -(z).y
139 #define MAGMA_C_EQUAL(u,v) (((u).x == (v).x) && ((u).y == (v).y))
140 #define MAGMA_C_GET_X(u) ((u).x)
141 #define MAGMA_C_ASSIGN(v, t) (v).x = (t).x; (v).y = (t).y
142 #define MAGMA_C_CNJG(v, t) (v).x= (t).x; (v).y = -(t).y
143 #define MAGMA_C_DSCALE(v, t, s) (v).x = (t).x/(s); (v).y = (t).y/(s)
144 #define MAGMA_C_OP_NEG(a, b, c) (a).x = (b).x-(c).x; (a).y = (b).y-(c).y
145 #define MAGMA_C_MAKE(r, i) make_cuFloatComplex((r), (i))
146 #define MAGMA_C_REAL(a) cuCrealf(a)
147 #define MAGMA_C_IMAG(a) cuCimagf(a)
148 #define MAGMA_C_ADD(a, b) cuCaddf((a), (b))
149 #define MAGMA_C_SUB(a, b) cuCsubf((a), (b))
150 #define MAGMA_C_MUL(a, b) cuCmulf((a), (b))
151 #define MAGMA_C_DIV(a, b) cuCdivf((a), (b))
152 #define MAGMA_C_ABS(a) cuCabsf((a))
153 #define MAGMA_C_ZERO make_cuFloatComplex(0.0, 0.0)
154 #define MAGMA_C_ONE make_cuFloatComplex(1.0, 0.0)
155 #define MAGMA_C_HALF make_cuFloatComplex(0.5, 0.0)
156 #define MAGMA_C_NEG_ONE make_cuFloatComplex(-1.0, 0.0)
157 #define MAGMA_C_NEG_HALF make_cuFloatComplex(-0.5, 0.0)
158 
159 #define MAGMA_D_SET2REAL(v, t) (v) = (t);
160 #define MAGMA_D_OP_NEG_ASGN(t, z) (t) = -(z)
161 #define MAGMA_D_EQUAL(u,v) ((u) == (v))
162 #define MAGMA_D_GET_X(u) (u)
163 #define MAGMA_D_ASSIGN(v, t) (v) = (t)
164 #define MAGMA_D_CNJG(v, t) (v) = (t)
165 #define MAGMA_D_DSCALE(v, t, s) (v) = (t)/(s)
166 #define MAGMA_D_OP_NEG(a, b, c) (a) = (b) - (c)
167 #define MAGMA_D_MAKE(r, i) (r)
168 #define MAGMA_D_REAL(a) (a)
169 #define MAGMA_D_IMAG(a) (a)
170 #define MAGMA_D_ADD(a, b) ( (a) + (b) )
171 #define MAGMA_D_SUB(a, b) ( (a) - (b) )
172 #define MAGMA_D_MUL(a, b) ( (a) * (b) )
173 #define MAGMA_D_DIV(a, b) ( (a) / (b) )
174 #define MAGMA_D_ABS(a) ((a)>0?(a):-(a))
175 #define MAGMA_D_ZERO (0.0)
176 #define MAGMA_D_ONE (1.0)
177 #define MAGMA_D_HALF (0.5)
178 #define MAGMA_D_NEG_ONE (-1.0)
179 #define MAGMA_D_NEG_HALF (-0.5)
180 
181 #define MAGMA_S_SET2REAL(v, t) (v) = (t);
182 #define MAGMA_S_OP_NEG_ASGN(t, z) (t) = -(z)
183 #define MAGMA_S_EQUAL(u,v) ((u) == (v))
184 #define MAGMA_S_GET_X(u) (u)
185 #define MAGMA_S_ASSIGN(v, t) (v) = (t)
186 #define MAGMA_S_CNJG(v, t) (v) = (t)
187 #define MAGMA_S_DSCALE(v, t, s) (v) = (t)/(s)
188 #define MAGMA_S_OP_NEG(a, b, c) (a) = (b) - (c)
189 #define MAGMA_S_MAKE(r, i) (r)
190 #define MAGMA_S_REAL(a) (a)
191 #define MAGMA_S_IMAG(a) (a)
192 #define MAGMA_S_ADD(a, b) ( (a) + (b) )
193 #define MAGMA_S_SUB(a, b) ( (a) - (b) )
194 #define MAGMA_S_MUL(a, b) ( (a) * (b) )
195 #define MAGMA_S_DIV(a, b) ( (a) / (b) )
196 #define MAGMA_S_ABS(a) ((a)>0?(a):-(a))
197 #define MAGMA_S_ZERO (0.0)
198 #define MAGMA_S_ONE (1.0)
199 #define MAGMA_S_HALF (0.5)
200 #define MAGMA_S_NEG_ONE (-1.0)
201 #define MAGMA_S_NEG_HALF (-0.5)
202 
203 #ifndef CBLAS_SADDR
204 #define CBLAS_SADDR(a) &(a)
205 #endif
206 
207 #ifdef __cplusplus
208 extern "C" {
209 #endif
210 
211 /* ------------------------------------------------------------
212  * -- MAGMA function definitions
213  * --------------------------------------------------------- */
214 void magma_xerbla( const char *name, magma_int_t info );
215 magma_context *magma_init(void *, void* (*func)(void *a), magma_int_t nthread, magma_int_t ncpu,
216  magma_int_t ngpu, magma_int_t argc, char **argv);
217 void magma_finalize(magma_context *cntxt);
218 void auto_tune(char algorithm, char precision, magma_int_t ncores, magma_int_t ncorespsocket,
220  magma_int_t *nthreads, magma_int_t *nquarkthreads);
221 
222 
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 
228 #endif
229 
Definition: quark.c:96
magma_int_t nb
Definition: magma.h:40
Definition: magma.h:25
magma_int_t num_gpus
Definition: magma.h:31
Quark * quark
Definition: magma.h:37
void auto_tune(char algorithm, char precision, magma_int_t ncores, magma_int_t ncorespsocket, magma_int_t m, magma_int_t n, magma_int_t *nb, magma_int_t *ob, magma_int_t *ib, magma_int_t *nthreads, magma_int_t *nquarkthreads)
Definition: auto_tune.cpp:15
int magma_int_t
Definition: magmablas.h:12
void magma_xerbla(const char *srname, magma_int_t info)
Definition: xerbla.cpp:8
void magma_finalize(magma_context_t *cntxt)
void * params
Definition: magma.h:43
magma_int_t num_cores
Definition: magma.h:28
magma_context_t * magma_init(void *, void *(*func)(void *a), magma_int_t nthread, magma_int_t ncpu, magma_int_t ngpu, magma_int_t argc, char **argv)
Definition: init.cpp:27
CUcontext * gpu_context
Definition: magma.h:34
struct context magma_context