General utility functions.
More...
#include "config.h"
#include "types.h"
#include "instr.h"
#include "func_util.h"
#include "cu_util.h"
#include <stdio.h>
#include <math.h>
Go to the source code of this file.
|
#define | MIN(x, y) ((x)<(y)?(x):(y)) |
|
#define | MAX(x, y) ((x)<(y)?(y):(x)) |
|
#define | PAD(n, p) (((n)<1 || (p)<1)?(n):(((n) % (p)) ? ((n) + (p) - (n) % (p)) : (n))) |
| Pad a number to a multiple of a second number. More...
|
|
#define | CEILDIV(a, b) ((int)(ceil(((double)(a))/((double)(b))))) |
|
#define | GHOST_PAD_MAX 1024 |
|
#define | IS_ALIGNED(PTR, BYTES) (((uintptr_t)(const void *)(PTR)) % (BYTES) == 0) |
|
#define | ISPOWEROFTWO(x) (((x) & ((x)-1)) == 0) |
|
#define | UNUSED(x) (void)(x) |
| Avoid unused variable/function warnings. More...
|
|
#define | GHOST_SINGLETHREAD(code) |
|
|
ghost_error | ghost_header_string (char **str, const char *fmt,...) |
|
ghost_error | ghost_footer_string (char **str) |
|
ghost_error | ghost_line_string (char **str, const char *label, const char *unit, const char *format,...) |
|
ghost_error | ghost_malloc (void **mem, const size_t size) |
| Allocate memory. More...
|
|
ghost_error | ghost_malloc_align (void **mem, const size_t size, const size_t align) |
| Allocate aligned memory. More...
|
|
ghost_error | ghost_malloc_pinned (void **mem, const size_t size) |
| Allocate pinned memory to enable fast CPU-GPU transfers. More...
|
|
int | ghost_hash (int a, int b, int c) |
| Computes a hash from three integral input values. More...
|
|
#define CEILDIV |
( |
|
a, |
|
|
|
b |
|
) |
| ((int)(ceil(((double)(a))/((double)(b))))) |
#define GHOST_PAD_MAX 1024 |
#define GHOST_SINGLETHREAD |
( |
|
code | ) |
|
Value:{\
int nthread;\
_Pragma("omp parallel") {\
_Pragma("omp single") {\
}\
}
int ghost_omp_nthread()
Get the number of OpenMP threads.
Definition: omp.c:21
void ghost_omp_nthread_set(int nthreads)
Set the number of threads.
Definition: omp.c:9
#define IS_ALIGNED |
( |
|
PTR, |
|
|
|
BYTES |
|
) |
| (((uintptr_t)(const void *)(PTR)) % (BYTES) == 0) |
#define ISPOWEROFTWO |
( |
|
x | ) |
(((x) & ((x)-1)) == 0) |
#define MAX |
( |
|
x, |
|
|
|
y |
|
) |
| ((x)<(y)?(y):(x)) |
#define MIN |
( |
|
x, |
|
|
|
y |
|
) |
| ((x)<(y)?(x):(y)) |
#define PAD |
( |
|
n, |
|
|
|
p |
|
) |
| (((n)<1 || (p)<1)?(n):(((n) % (p)) ? ((n) + (p) - (n) % (p)) : (n))) |
Pad a number to a multiple of a second number.
- Parameters
-
n | The number to be padded. |
p | The desired padding. |
- Returns
- n padded to a multiple of p or n if p or n smaller than 1.
#define UNUSED |
( |
|
x | ) |
(void)(x) |
Avoid unused variable/function warnings.
int ghost_hash |
( |
int |
a, |
|
|
int |
b, |
|
|
int |
c |
|
) |
| |
|
inline |
ghost_error ghost_header_string |
( |
char ** |
str, |
|
|
const char * |
fmt, |
|
|
|
... |
|
) |
| |
ghost_error ghost_line_string |
( |
char ** |
str, |
|
|
const char * |
label, |
|
|
const char * |
unit, |
|
|
const char * |
format, |
|
|
|
... |
|
) |
| |
ghost_error ghost_malloc |
( |
void ** |
mem, |
|
|
const size_t |
size |
|
) |
| |
Allocate memory.
- Parameters
-
mem | Where to store the allocated memory. |
size | The size (in bytes) to allocate. |
- Returns
- GHOST_SUCCESS on success or an error indicator.
ghost_error ghost_malloc_align |
( |
void ** |
mem, |
|
|
const size_t |
size, |
|
|
const size_t |
align |
|
) |
| |
Allocate aligned memory.
- Parameters
-
mem | Where to store the allocated memory. |
size | The size (in bytes) to allocate. |
align | The alignment size. |
- Returns
- GHOST_SUCCESS on success or an error indicator.
ghost_error ghost_malloc_pinned |
( |
void ** |
mem, |
|
|
const size_t |
size |
|
) |
| |
Allocate pinned memory to enable fast CPU-GPU transfers.
- Parameters
-
mem | Where to store the allocated memory. |
size | The size (in bytes) to allocate. |
- Returns
- GHOST_SUCCESS on success or an error indicator.
If CUDA is not enabled, a normal malloc is done.