GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
math.h
Go to the documentation of this file.
1 
6 #ifndef GHOST_MATH_H
7 #define GHOST_MATH_H
8 
9 #include "config.h"
10 #include "types.h"
11 #include "context.h"
12 #include "sparsemat.h"
13 #include "densemat.h"
14 #include "error.h"
15 #include "tsmm.h"
16 #include "tsmm_inplace.h"
17 #include "dot.h"
18 
19 #include <stdarg.h>
20 
21 #define SELECT_BLAS1_KERNEL(kernels,commonlocation,compute_at,storage,ret,...) \
22  if (commonlocation == (GHOST_LOCATION_HOST | GHOST_LOCATION_DEVICE)) {\
23  if (compute_at == GHOST_LOCATION_HOST) {\
24  if (storage == GHOST_DENSEMAT_COLMAJOR) {\
25  ret = kernels[GHOST_HOST_IDX][GHOST_CM_IDX](__VA_ARGS__);\
26  } else {\
27  ret = kernels[GHOST_HOST_IDX][GHOST_RM_IDX](__VA_ARGS__);\
28  }\
29  } else {\
30  if (storage == GHOST_DENSEMAT_COLMAJOR) {\
31  ret = kernels[GHOST_DEVICE_IDX][GHOST_CM_IDX](__VA_ARGS__);\
32  } else {\
33  ret = kernels[GHOST_DEVICE_IDX][GHOST_RM_IDX](__VA_ARGS__);\
34  }\
35  }\
36  } else {\
37  if (!kernels[ghost_idx_of_location(commonlocation)][ghost_idx_of_densemat_storage(storage)]) {\
38  GHOST_ERROR_LOG("No kernel found!");\
39  ret = GHOST_ERR_INVALID_ARG;\
40  } else {\
41  ret = kernels[ghost_idx_of_location(commonlocation)][ghost_idx_of_densemat_storage(storage)](__VA_ARGS__);\
42  }\
43  }
44 
45 typedef enum {
54 
55 #ifdef __cplusplus
56 inline ghost_gemm_flags operator&=(ghost_gemm_flags &a, const ghost_gemm_flags &b) {
57  a = static_cast<ghost_gemm_flags>(static_cast<int>(a) & static_cast<int>(b));
58  return a;
59 }
60 inline ghost_gemm_flags operator~(const ghost_gemm_flags &a) {
61  return static_cast<ghost_gemm_flags>(~static_cast<int>(a));
62 }
63 #endif
64 
65 typedef struct {
66  /* C = alpha(A*B) + beta(C)
67  * C is mxn
68  * A is mxk
69  * B is kxn
70  */
72  bool alphaisone;
73  bool betaiszero;
77  bool aisc;
79 }
81 
82 #define GHOST_GEMM_ALL_REDUCE GHOST_ALLREDUCE
83 #define GHOST_GEMM_NO_REDUCE -2
84 
85 typedef struct {
90 }
92 #define GHOST_KACZ_PERF_UNIT "GF/s"
93 #define GHOST_KACZ_PERF_TAG "kacz"
94 
95 typedef struct {
101 }
103 #define GHOST_SPMV_PERF_UNIT "GF/s"
104 #define GHOST_SPMV_PERF_TAG "spmv"
105 
106 typedef struct {
110 }
112 #define GHOST_AXPY_PERF_UNIT "GB/s"
113 #define GHOST_AXPY_PERF_TAG "axpy"
114 
115 typedef struct {
119 }
121 #define GHOST_AXPBY_PERF_UNIT "GB/s"
122 #define GHOST_AXPBY_PERF_TAG "axpby"
123 
124 typedef struct {
128 }
130 #define GHOST_AXPBYPCZ_PERF_UNIT "GB/s"
131 #define GHOST_AXPBYPCZ_PERF_TAG "axpbypcz"
132 
133 typedef struct {
137  bool samevec;
138 }
140 #define GHOST_DOT_PERF_UNIT "GB/s"
141 #define GHOST_DOT_PERF_TAG "dot"
142 
143 typedef struct {
147 }
149 #define GHOST_SCALE_PERF_UNIT "GB/s"
150 #define GHOST_SCALE_PERF_TAG "scale"
151 
152 
153 #ifdef __cplusplus
154 extern "C" {
155 #endif
156 
189  ghost_error ghost_gemm_valid(ghost_densemat *x, ghost_densemat *v, const char * transv,
190  ghost_densemat *w, const char *transw, void *alpha, void *beta, int reduce,ghost_gemm_flags flags, int printerror);
208  ghost_error ghost_gemm(ghost_densemat *x, ghost_densemat *v, const char *transv, ghost_densemat *w, const char * transw, void *alpha, void *beta, int reduce,ghost_gemm_flags flags);
213 
215 
216 
244  ghost_error ghost_axpby(ghost_densemat *y, ghost_densemat *x, void *a, void *b);
254  ghost_error ghost_vaxpby(ghost_densemat *y, ghost_densemat *x, void *a, void *b);
266  ghost_error ghost_axpbypcz(ghost_densemat *y, ghost_densemat *x, void *a, void *b, ghost_densemat *z, void *c);
278  ghost_error ghost_vaxpbypcz(ghost_densemat *y, ghost_densemat *x, void *a, void *b, ghost_densemat *z, void *c);
279 
314 
324  ghost_error ghost_norm(void *norm, ghost_densemat *vec, void *pow);
325 
334  ghost_error ghost_nrm2(void *norm, ghost_densemat *vec);
344 
345  int ghost_kacz_perf(double *perf, double time, void *arg);
346  int ghost_spmv_perf(double *perf, double time, void *arg);
347  int ghost_axpy_perf(double *perf, double time, void *arg);
348  int ghost_axpby_perf(double *perf, double time, void *arg);
349  int ghost_scale_perf(double *perf, double time, void *arg);
350  int ghost_dot_perf(double *perf, double time, void *arg);
351  int ghost_axpbypcz_perf(double *perf, double time, void *arg);
352  int ghost_gemm_perf_GFs(double *perf, double time, void *arg);
353  int ghost_gemm_perf_GBs(double *perf, double time, void *arg);
354 
355  bool ghost_iszero(void *number, ghost_datatype dt);
356  bool ghost_isone(void *vnumber, ghost_datatype dt);
357 
358 #ifdef __cplusplus
359 } //extern "C"
360 
361 #endif
362 
363 #endif
364 
ghost_error ghost_nrm2(void *norm, ghost_densemat *vec)
Compute the norm of a densemat: sum_i [conj(vec_i) * vec_i]^2.
Definition: math.c:791
ghost_error ghost_vaxpby(ghost_densemat *y, ghost_densemat *x, void *a, void *b)
Computes column-wise y := a_i*x + b_i*y with separate scalar a_i and b_i.
Definition: math.c:633
Header file for type definitions.
ghost_error ghost_mult(ghost_densemat *y, ghost_densemat *x, void *a)
Computes y(i,j) := a*x(i,j)*y(i,j) or y(i,j) := a*x(i) (if x has 1 column), with scalar a...
Definition: math.c:811
ghost_datatype dt
Definition: math.h:118
bool aisc
True if A is equal to C.
Definition: math.h:77
Types and functions related to GHOST contexts.
bool samevec
Definition: math.h:137
ghost_error ghost_vaxpy(ghost_densemat *y, ghost_densemat *x, void *a)
Computes column-wise y := a_i*x + y with separate scalar a_i.
Definition: math.c:587
Definition: math.h:85
int32_t ghost_gidx
Type for global indices.
Definition: types.h:443
int ghost_gemm_perf_GBs(double *perf, double time, void *arg)
Definition: gemm.c:592
ghost_gemm_flags
Definition: math.h:45
ghost_lidx globalrows
Definition: math.h:97
bool ghost_iszero(void *number, ghost_datatype dt)
Definition: math.c:509
ghost_lidx ncols
Definition: math.h:125
ghost_error ghost_gemm_valid(ghost_densemat *x, ghost_densemat *v, const char *transv, ghost_densemat *w, const char *transw, void *alpha, void *beta, int reduce, ghost_gemm_flags flags, int printerror)
Definition: gemm.c:17
ghost_datatype dt
Definition: math.h:146
int32_t ghost_lidx
Definition: types.h:503
ghost_gidx globnrows
Definition: math.h:135
ghost_datatype dt
Definition: math.h:78
ghost_error ghost_vscale(ghost_densemat *x, void *s)
Computes column-wise x := s_i*x with separate scalars s_i.
Definition: math.c:722
ghost_lidx vecncols
Definition: math.h:86
bool ghost_isone(void *vnumber, ghost_datatype dt)
Definition: math.c:536
ghost_gidx globalnnz
Definition: math.h:98
ghost_gidx globnrows
Definition: math.h:117
ghost_datatype dt
Definition: math.h:109
ghost_lidx vecncols
Definition: math.h:96
Types, functions and macros for error handling.
int ghost_axpby_perf(double *perf, double time, void *arg)
Definition: math.c:437
The specialized GEMM function tsmm.
ghost_spmv_flags flags
Definition: math.h:100
ghost_error ghost_normalize(ghost_densemat *x)
Normalizes a densemat (interpreted as a block vector).
Definition: math.c:740
ghost_error
Error return type.
Definition: error.h:23
Definition: math.h:95
ghost_error ghost_scale(ghost_densemat *x, void *s)
Computes x := s*x with scalar s.
Definition: math.c:704
The (block vector) dot product.
ghost_lidx ncols
Definition: math.h:107
ghost_gidx globnrows
Definition: math.h:108
int ghost_axpy_perf(double *perf, double time, void *arg)
Definition: math.c:454
Definition: math.h:65
ghost_spmv_flags
Flags to be passed to sparse matrix-vector multiplication.
Definition: spmv.h:15
int ghost_kacz_perf(double *perf, double time, void *arg)
Definition: math.c:347
static T norm(const T &a)
Definition: cpp11_fixes.h:29
ghost_gidx globnrows
Definition: math.h:145
ghost_lidx ncols
Definition: math.h:144
ghost_datatype
Available primitive data types.
Definition: types.h:248
ghost_error ghost_mpi_op_sum(ghost_mpi_op *op, ghost_datatype datatype)
Definition: math.c:214
bool alphaisone
Definition: math.h:72
int ghost_scale_perf(double *perf, double time, void *arg)
Definition: math.c:492
ghost_lidx ncols
Definition: math.h:134
ghost_error ghost_spmv(ghost_densemat *res, ghost_sparsemat *mat, ghost_densemat *invec, ghost_spmv_opts opts)
Multiply a sparse matrix with a dense vector.
Definition: spmv.c:9
int ghost_axpbypcz_perf(double *perf, double time, void *arg)
Definition: math.c:420
int ghost_spmv_perf(double *perf, double time, void *arg)
Definition: math.c:361
Definition: math.h:52
ghost_error ghost_mpi_op_densemat_sum(ghost_mpi_op *op, ghost_datatype datatype)
Definition: math.c:245
The specialized GEMM function tsmm (in-place).
int ghost_mpi_op
Definition: types.h:20
ghost_error ghost_gemm(ghost_densemat *x, ghost_densemat *v, const char *transv, ghost_densemat *w, const char *transw, void *alpha, void *beta, int reduce, ghost_gemm_flags flags)
Compute the general (dense) matrix-matrix product x = v*w.
Definition: gemm.c:431
ghost_error ghost_vaxpbypcz(ghost_densemat *y, ghost_densemat *x, void *a, void *b, ghost_densemat *z, void *c)
Computes column-wise y := a_i*x + b_i*y + c_i*z with separate scalars a_i, b_i, and c_i...
Definition: math.c:680
A sparse matrix.
Definition: sparsemat.h:476
ghost_error ghost_conj(ghost_densemat *x)
Conjugates a densemat.
Definition: math.c:758
ghost_datatype dt
Definition: math.h:99
int ghost_gemm_perf_GFs(double *perf, double time, void *arg)
Definition: gemm.c:564
int ghost_dot_perf(double *perf, double time, void *arg)
Definition: math.c:471
ghost_gidx globalnnz
Definition: math.h:88
Definition: math.h:143
ghost_lidx globalrows
Definition: math.h:87
ghost_gidx n
Definition: math.h:71
ghost_error ghost_axpbypcz(ghost_densemat *y, ghost_densemat *x, void *a, void *b, ghost_densemat *z, void *c)
Computes y := a*x + b*y + c*z with scalar a, b, and c.
Definition: math.c:656
ghost_datatype dt
Definition: math.h:89
Definition: math.h:115
ghost_error ghost_axpby(ghost_densemat *y, ghost_densemat *x, void *a, void *b)
Computes y := a*x + b*y with scalar a and b.
Definition: math.c:610
ghost_error ghost_axpy(ghost_densemat *y, ghost_densemat *x, void *a)
Computes y := a*x + y with scalar a.
Definition: math.c:564
Definition: math.h:106
Definition: sparsemat.h:71
Definition: math.h:51
ghost_error ghost_norm(void *norm, ghost_densemat *vec, void *pow)
Compute the norm of a densemat: sum_i [conj(vec_i) * vec_i]^pow.
Definition: math.c:776
Definition: math.h:46
Types and functions related to sparse matrices.
ghost_error ghost_mpi_operations_create()
Definition: math.c:276
ghost_error ghost_mpi_operations_destroy()
Definition: math.c:299
ghost_error ghost_spmv_nflops(int *nFlops, ghost_datatype m_t, ghost_datatype v_t)
Definition: math.c:315
ghost_datatype dt
Definition: math.h:127
Definition: math.h:133
ghost_lidx ncols
Definition: math.h:116
Do not look for special implementations!
Definition: math.h:50
bool betaiszero
Definition: math.h:73
Definition: math.h:124
A dense vector/matrix.
Definition: densemat.h:226
ghost_datatype dt
Definition: math.h:136
ghost_gidx globnrows
Definition: math.h:126
ghost_error ghost_spmv_nocomm(ghost_densemat *res, ghost_sparsemat *mat, ghost_densemat *invec, ghost_spmv_opts opts)
Definition: spmv.c:138