GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
util.h
Go to the documentation of this file.
1 
6 #ifndef GHOST_UTIL_H
7 #define GHOST_UTIL_H
8 
9 #include "config.h"
10 #include "types.h"
11 #include "instr.h"
12 #include "func_util.h"
13 #include "cu_util.h"
14 
15 #include <stdio.h>
16 #include <math.h>
17 /*
18 #ifndef __cplusplus
19 #include <complex.h>
20 #include <string.h>
21 #include <float.h>
22 #else
23 #include <complex>
24 #include <cstring>
25 #include <cfloat>
26 #endif
27 */
28 
29 #ifndef MIN
30 #define MIN(x,y) ((x)<(y)?(x):(y))
31 #endif
32 #ifndef MAX
33 #define MAX(x,y) ((x)<(y)?(y):(x))
34 #endif
35 
44 #define PAD(n,p) (((n)<1 || (p)<1)?(n):(((n) % (p)) ? ((n) + (p) - (n) % (p)) : (n)))
45 
46 #define CEILDIV(a,b) ((int)(ceil(((double)(a))/((double)(b)))))
47 
48 #define GHOST_PAD_MAX 1024
49 
50 #define IS_ALIGNED(PTR,BYTES) (((uintptr_t)(const void *)(PTR)) % (BYTES) == 0)
51 
52 #define ISPOWEROFTWO(x) (((x) & ((x)-1)) == 0)
53 
57 #define UNUSED(x) (void)(x)
58 
59 #define GHOST_SINGLETHREAD(code) {\
60  int nthread;\
61 _Pragma("omp parallel") {\
62 _Pragma("omp single") {\
63  nthread = ghost_omp_nthread(); \
64  }\
65  }\
66  ghost_omp_nthread_set(1);\
67  code;\
68  ghost_omp_nthread_set(nthread);\
69 }
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
75  ghost_error ghost_header_string(char **str, const char *fmt, ...);
76  ghost_error ghost_footer_string(char **str);
77  ghost_error ghost_line_string(char **str, const char *label, const char *unit, const char *format, ...);
78 
79 
88  ghost_error ghost_malloc(void **mem, const size_t size);
98  ghost_error ghost_malloc_align(void **mem, const size_t size, const size_t align);
99 
110  ghost_error ghost_malloc_pinned(void **mem, const size_t size);
111 
123  inline int ghost_hash(int a, int b, int c)
124  {
125  //GHOST_FUNC_ENTER(GHOST_FUNCTYPE_UTIL);
126 
127  a -= b; a -= c; a ^= (c>>13);
128  b -= c; b -= a; b ^= (a<<8);
129  c -= a; c -= b; c ^= (b>>13);
130  a -= b; a -= c; a ^= (c>>12);
131  b -= c; b -= a; b ^= (a<<16);
132  c -= a; c -= b; c ^= (b>>5);
133  a -= b; a -= c; a ^= (c>>3);
134  b -= c; b -= a; b ^= (a<<10);
135  c -= a; c -= b; c ^= (b>>15);
136 
137  //GHOST_FUNC_EXIT(GHOST_FUNCTYPE_UTIL);
138  return c;
139  }
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 #endif
Functions for global mathematical operations.
Header file for type definitions.
ghost_error ghost_malloc_align(void **mem, const size_t size, const size_t align)
Allocate aligned memory.
Definition: util.c:206
ghost_error ghost_footer_string(char **str)
Definition: util.c:99
ghost_error
Error return type.
Definition: error.h:23
CUDA utility functions.
ghost_error ghost_line_string(char **str, const char *label, const char *unit, const char *format,...)
Definition: util.c:126
Macros used for code instrumentation.
ghost_error ghost_malloc(void **mem, const size_t size)
Allocate memory.
Definition: util.c:172
int ghost_hash(int a, int b, int c)
Computes a hash from three integral input values.
Definition: util.h:123
ghost_error ghost_header_string(char **str, const char *fmt,...)
Definition: util.c:27
ghost_error ghost_malloc_pinned(void **mem, const size_t size)
Allocate pinned memory to enable fast CPU-GPU transfers.
Definition: util.c:195