GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
util.h File Reference

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>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#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)
 

Functions

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...
 

Detailed Description

General utility functions.

Author
Moritz Kreutzer morit.nosp@m.z.kr.nosp@m.eutze.nosp@m.r@fa.nosp@m.u.de

Macro Definition Documentation

#define CEILDIV (   a,
 
)    ((int)(ceil(((double)(a))/((double)(b)))))
#define GHOST_PAD_MAX   1024
#define GHOST_SINGLETHREAD (   code)
Value:
{\
int nthread;\
_Pragma("omp parallel") {\
_Pragma("omp single") {\
nthread = ghost_omp_nthread(); \
}\
}\
code;\
}
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,
 
)    ((x)<(y)?(y):(x))
#define MIN (   x,
 
)    ((x)<(y)?(x):(y))
#define PAD (   n,
 
)    (((n)<1 || (p)<1)?(n):(((n) % (p)) ? ((n) + (p) - (n) % (p)) : (n)))

Pad a number to a multiple of a second number.

Parameters
nThe number to be padded.
pThe 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.

Function Documentation

ghost_error ghost_footer_string ( char **  str)
int ghost_hash ( int  a,
int  b,
int  c 
)
inline

Computes a hash from three integral input values.

Parameters
aFirst parameter.
bSecond parameter.
cThird parameter.
Returns
Hash value.

The function has been taken from http://burtleburtle.net/bob/hash/doobs.html

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,
  ... 
)

Here is the call graph for this function:

ghost_error ghost_malloc ( void **  mem,
const size_t  size 
)

Allocate memory.

Parameters
memWhere to store the allocated memory.
sizeThe 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
memWhere to store the allocated memory.
sizeThe size (in bytes) to allocate.
alignThe 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
memWhere to store the allocated memory.
sizeThe size (in bytes) to allocate.
Returns
GHOST_SUCCESS on success or an error indicator.

If CUDA is not enabled, a normal malloc is done.

Here is the call graph for this function: