OpenVDB  12.0.0
Namespaces | Classes | Typedefs | Functions
nanovdb::util Namespace Reference

Namespaces

 impl
 

Classes

struct  conditional
 C++11 implementation of std::conditional. More...
 
struct  conditional< false, TrueT, FalseT >
 Template specialization of conditional. More...
 
struct  disable_if
 
struct  disable_if< true, T >
 
struct  enable_if
 C++11 implementation of std::enable_if. More...
 
struct  enable_if< true, T >
 
struct  is_const
 
struct  is_const< const T >
 
struct  is_floating_point
 C++11 implementation of std::is_floating_point. More...
 
struct  is_pointer
 Trait used to identify template parameter that are pointers. More...
 
struct  is_pointer< T * >
 Template specialization of pointers. More...
 
struct  is_same
 C++11 implementation of std::is_same. More...
 
struct  is_same< T, T >
 
struct  is_same< T0, T1 >
 
struct  is_specialization
 Metafunction used to determine if the first template parameter is a specialization of the class template given in the second template parameter. More...
 
struct  is_specialization< TemplateType< Args... >, TemplateType >
 
struct  match_const
 Trait used to transfer the const-ness of a reference type to another type. More...
 
struct  match_const< T, const ReferenceT >
 Template specialization used to transfer the const-ness of a reference type to another type. More...
 
class  Range
 
class  Range< 1, T >
 
class  Range< 2, T >
 
class  Range< 3, T >
 
struct  remove_const
 Trait use to const from type. Default implementation is just a pass-through. More...
 
struct  remove_const< const T >
 Template specialization of trait class use to remove const qualifier type from a type. More...
 
struct  remove_pointer
 Trait use to remove pointer, i.e. "*", qualifier from a type. Default implementation is just a pass-through. More...
 
struct  remove_pointer< T * >
 Template specialization of trait class use to to remove pointer, i.e. "*", qualifier from a type. More...
 
struct  remove_reference
 Trait use to remove reference, i.e. "&", qualifier from a type. Default implementation is just a pass-through. More...
 
struct  remove_reference< T & >
 Template specialization of trait class use to remove reference, i.e. "&", qualifier from a type. More...
 
class  Split
 
class  Timer
 

Typedefs

using Range1D = Range< 1, size_t >
 
using Range2D = Range< 2, size_t >
 
using Range3D = Range< 3, size_t >
 

Functions

template<typename RangeT , typename FuncT >
void forEach (RangeT range, const FuncT &func)
 simple wrapper for tbb::parallel_for with a naive std fallback More...
 
template<typename FuncT >
void forEach (size_t begin, size_t end, size_t grainSize, const FuncT &func)
 Simple wrapper for the function defined above. More...
 
template<template< typename... > class ContainerT, typename... T, typename FuncT >
void forEach (const ContainerT< T... > &c, const FuncT &func)
 Simple wrapper for the function defined above, which works with std::containers. More...
 
template<template< typename... > class ContainerT, typename... T, typename FuncT >
void forEach (const ContainerT< T... > &c, size_t grainSize, const FuncT &func)
 Simple wrapper for the function defined above, which works with std::containers. More...
 
template<typename Func , typename... Rest>
int invoke (const Func &taskFunc1, Rest...taskFuncN)
 
template<typename T , typename OpT = std::plus<T>>
prefixSum (std::vector< T > &vec, bool threaded=true, OpT op=OpT())
 Computes inclusive prefix sum of a vector. More...
 
template<typename T , typename Op >
void inclusiveScan (T *array, size_t size, const T &identity, bool threaded, Op op)
 An inclusive scan includes in[i] when computing out[i]. More...
 
template<typename RangeT , typename T , typename FuncT , typename JoinT >
reduce (RangeT range, const T &identity, const FuncT &func, const JoinT &join)
 
template<typename T , typename FuncT , typename JoinT >
reduce (size_t begin, size_t end, size_t grainSize, const T &identity, const FuncT &func, const JoinT &join)
 Simple wrapper to the function defined above. More...
 
template<template< typename... > class ContainerT, typename... ArgT, typename T , typename FuncT , typename JoinT >
reduce (const ContainerT< ArgT... > &c, const T &identity, const FuncT &func, const JoinT &join)
 Simple wrapper that works with std::containers. More...
 
template<template< typename... > class ContainerT, typename... ArgT, typename T , typename FuncT , typename JoinT >
reduce (const ContainerT< ArgT... > &c, size_t grainSize, const T &identity, const FuncT &func, const JoinT &join)
 Simple wrapper that works with std::containers. More...
 
template<typename T >
T && declval () noexcept
 Minimal implementation of std::declval, which converts any type T to. More...
 
bool empty (const char *str)
 tests if a c-string str is empty, that is its first value is '\0' More...
 
size_t strlen (const char *str)
 length of a c-sting, excluding '\0'. More...
 
char * strcpy (char *dst, const char *src)
 Copy characters from src to dst. More...
 
char * strncpy (char *dst, const char *src, size_t max)
 Copies the first num characters of src to dst. If the end of the source C string (which is signaled by a null-character) is found before max characters have been copied, dst is padded with zeros until a total of max characters have been written to it. More...
 
char * strcpy (char *dst, int num, int bas=10)
 converts a number to a string using a specific base More...
 
char * strcat (char *dst, const char *src)
 Appends a copy of the character string pointed to by src to the end of the character string pointed to by dst on the device. More...
 
char * strcat (char *dst, int num, int bas=10)
 concatenates a number after a string using a specific base More...
 
int strcmp (const char *lhs, const char *rhs)
 Compares two null-terminated byte strings lexicographically. More...
 
bool streq (const char *lhs, const char *rhs)
 Test if two null-terminated byte strings are the same. More...
 
template<typename T , typename... Types>
char * sprint (char *dst, T var1, Types...var2)
 prints a variable number of string and/or numbers to a destination string More...
 
static void * memzero (void *dst, size_t byteCount)
 Zero initialization of memory. More...
 
static int64_t PtrDiff (const void *p, const void *q)
 Compute the distance, in bytes, between two pointers, dist = p - q. More...
 
template<typename DstT = void>
static DstT * PtrAdd (void *p, int64_t offset)
 Adds a byte offset to a non-const pointer to produce another non-const pointer. More...
 
template<typename DstT = void>
static const DstT * PtrAdd (const void *p, int64_t offset)
 Adds a byte offset to a const pointer to produce another const pointer. More...
 
uint32_t findLowestOn (uint32_t v)
 Returns the index of the lowest, i.e. least significant, on bit in the specified 32 bit word. More...
 
uint32_t findLowestOn (uint64_t v)
 Returns the index of the lowest, i.e. least significant, on bit in the specified 64 bit word. More...
 
uint32_t findHighestOn (uint32_t v)
 Returns the index of the highest, i.e. most significant, on bit in the specified 32 bit word. More...
 
uint32_t findHighestOn (uint64_t v)
 Returns the index of the highest, i.e. most significant, on bit in the specified 64 bit word. More...
 
uint32_t countOn (uint64_t v)
 

Typedef Documentation

using Range1D = Range<1, size_t>
using Range2D = Range<2, size_t>
using Range3D = Range<3, size_t>

Function Documentation

uint32_t nanovdb::util::countOn ( uint64_t  v)
inline
Returns
Number of bits that are on in the specified 64-bit word
T&& nanovdb::util::declval ( )
noexcept

Minimal implementation of std::declval, which converts any type T to.

a reference type, making it possible to use member functions in the operand of the decltype specifier without the need to go through constructors.

Template Parameters
TTemplate type to be converted to T&&
Returns
T&&
Warning
Unlike std::declval, this version does not work when T = void! However, NVRTC does not like std::declval, so we provide our own implementation.
bool nanovdb::util::empty ( const char *  str)
inline

tests if a c-string str is empty, that is its first value is '\0'

Parameters
strc-string to be tested for null termination
Returns
true if str[0] = '\0'
uint32_t nanovdb::util::findHighestOn ( uint32_t  v)
inline

Returns the index of the highest, i.e. most significant, on bit in the specified 32 bit word.

Warning
Assumes that at least one bit is set in the word, i.e. v != uint32_t(0)!
uint32_t nanovdb::util::findHighestOn ( uint64_t  v)
inline

Returns the index of the highest, i.e. most significant, on bit in the specified 64 bit word.

Warning
Assumes that at least one bit is set in the word, i.e. v != uint32_t(0)!
uint32_t nanovdb::util::findLowestOn ( uint32_t  v)
inline

Returns the index of the lowest, i.e. least significant, on bit in the specified 32 bit word.

Warning
Assumes that at least one bit is set in the word, i.e. v != uint32_t(0)!
uint32_t nanovdb::util::findLowestOn ( uint64_t  v)
inline

Returns the index of the lowest, i.e. least significant, on bit in the specified 64 bit word.

Warning
Assumes that at least one bit is set in the word, i.e. v != uint32_t(0)!
void nanovdb::util::forEach ( RangeT  range,
const FuncT &  func 
)
inline

simple wrapper for tbb::parallel_for with a naive std fallback

Parameters
rangeRange, CoordBBox, tbb::blocked_range, blocked_range2D, or blocked_range3D.
funcfunctor with the signature [](const RangeT&){...},
std::vector<int> array(100);
auto func = [&array](auto &r){for (auto i=r.begin(); i!=r.end(); ++i) array[i]=i;};
forEach(array, func);
void nanovdb::util::forEach ( size_t  begin,
size_t  end,
size_t  grainSize,
const FuncT &  func 
)
inline

Simple wrapper for the function defined above.

void nanovdb::util::forEach ( const ContainerT< T... > &  c,
const FuncT &  func 
)
inline

Simple wrapper for the function defined above, which works with std::containers.

void nanovdb::util::forEach ( const ContainerT< T... > &  c,
size_t  grainSize,
const FuncT &  func 
)
inline

Simple wrapper for the function defined above, which works with std::containers.

void nanovdb::util::inclusiveScan ( T *  array,
size_t  size,
const T &  identity,
bool  threaded,
Op  op 
)

An inclusive scan includes in[i] when computing out[i].

Note
Inclusive prefix operation: for (i=1; i<N; ++i) vec[i] = Op(vec[i],vec[i-1])
int nanovdb::util::invoke ( const Func &  taskFunc1,
Rest...  taskFuncN 
)
Returns
1 for serial, 2 for tbb multi-threading, and 3 for std multi-threading
static void* nanovdb::util::memzero ( void *  dst,
size_t  byteCount 
)
inlinestatic

Zero initialization of memory.

Parameters
dstpointer to destination
byteCountnumber of bytes to be initialized to zero
Returns
destination pointer dst
T prefixSum ( std::vector< T > &  vec,
bool  threaded = true,
OpT  op = OpT() 
)

Computes inclusive prefix sum of a vector.

Template Parameters
TType of the elements in the input/out vector
OpTType of operation performed on each element (defaults to sum)
Parameters
vecinput and output vector
threadedif true multi-threading is used
Note
Inclusive prefix sum: for (i=1; i<N; ++i) vec[i] += vec[i-1]
Returns
sum of all input elements, which is also the last element of the inclusive prefix sum
static DstT* nanovdb::util::PtrAdd ( void *  p,
int64_t  offset 
)
inlinestatic

Adds a byte offset to a non-const pointer to produce another non-const pointer.

Template Parameters
DstTType of the return pointer (defaults to void)
Parameters
pnon-const input pointer, assumed to NOT be NULL
offsetsigned byte offset
Returns
a non-const pointer defined as the offset of an input pointer
static const DstT* nanovdb::util::PtrAdd ( const void *  p,
int64_t  offset 
)
inlinestatic

Adds a byte offset to a const pointer to produce another const pointer.

Template Parameters
DstTType of the return pointer (defaults to void)
Parameters
pconst input pointer, assumed to NOT be NULL
offsetsigned byte offset
Returns
a const pointer defined as the offset of a const input pointer
static int64_t nanovdb::util::PtrDiff ( const void *  p,
const void *  q 
)
inlinestatic

Compute the distance, in bytes, between two pointers, dist = p - q.

Parameters
pfist pointer, assumed to NOT be NULL
qsecond pointer, assumed to NOT be NULL
Returns
signed distance between pointer, p - q, addresses in units of bytes
T nanovdb::util::reduce ( RangeT  range,
const T &  identity,
const FuncT &  func,
const JoinT &  join 
)
inline
Returns
reduction
Parameters
rangeRangeT can be Range<dim,T>, CoordBBox, tbb::blocked_range, blocked_range2D, or blocked_range3D.
identityinitial value
funcfunctor with signature T FuncT::operator()(const RangeT& range, const T& a) const
joinfunctor with the signature T JoinT::operator()(const T& a, const T& b) const
std::vector<int> array(100, 1);
auto func = [&array](auto &r, int a){for (auto i=r.begin(); i!=r.end(); ++i) a+=array[i]; return a;};
int sum = reduce(array, 0, func, [](int a, int b){return a + b;});
T nanovdb::util::reduce ( size_t  begin,
size_t  end,
size_t  grainSize,
const T &  identity,
const FuncT &  func,
const JoinT &  join 
)
inline

Simple wrapper to the function defined above.

T nanovdb::util::reduce ( const ContainerT< ArgT... > &  c,
const T &  identity,
const FuncT &  func,
const JoinT &  join 
)
inline

Simple wrapper that works with std::containers.

T nanovdb::util::reduce ( const ContainerT< ArgT... > &  c,
size_t  grainSize,
const T &  identity,
const FuncT &  func,
const JoinT &  join 
)
inline

Simple wrapper that works with std::containers.

char* nanovdb::util::sprint ( char *  dst,
var1,
Types...  var2 
)
inline

prints a variable number of string and/or numbers to a destination string

char* nanovdb::util::strcat ( char *  dst,
const char *  src 
)
inline

Appends a copy of the character string pointed to by src to the end of the character string pointed to by dst on the device.

Parameters
dstpointer to the null-terminated byte string to append to.
srcpointer to the null-terminated byte string to copy from.
Returns
pointer to the character array being appended to.
Note
Emulates the behaviour of std::strcat, except this version also runs on the GPU.
char* nanovdb::util::strcat ( char *  dst,
int  num,
int  bas = 10 
)
inline

concatenates a number after a string using a specific base

Parameters
dstnull terminated destination string
numsigned number to be concatenated after dst
basbase used when converting num to a string
Returns
destination string dst
int nanovdb::util::strcmp ( const char *  lhs,
const char *  rhs 
)
inline

Compares two null-terminated byte strings lexicographically.

Parameters
lhspointer to the null-terminated byte strings to compare
rhspointer to the null-terminated byte strings to compare
Returns
Negative value if lhs appears before rhs in lexicographical order. Zero if lhs and rhs compare equal. Positive value if lhs appears after rhs in lexicographical order.
Note
Emulates the behaviour of std::strcmp, except this version also runs on the GPU.
char* nanovdb::util::strcpy ( char *  dst,
const char *  src 
)
inline

Copy characters from src to dst.

Parameters
dstpointer to the destination string.
srcpointer to the null-terminated source string.
Returns
destination string dst.
Note
Emulates the behaviour of std::strcpy, except this version also runs on the GPU.
char* nanovdb::util::strcpy ( char *  dst,
int  num,
int  bas = 10 
)
inline

converts a number to a string using a specific base

Parameters
dstdestination string
numsigned number to be concatenated after dst
basbase used when converting num to a string
Returns
destination string dst
Note
Emulates the behaviour of itoa, except this verion also works on the GPU.
bool nanovdb::util::streq ( const char *  lhs,
const char *  rhs 
)
inline

Test if two null-terminated byte strings are the same.

Parameters
lhspointer to the null-terminated byte strings to compare
rhspointer to the null-terminated byte strings to compare
Returns
true if the two c-strings are identical
size_t nanovdb::util::strlen ( const char *  str)
inline

length of a c-sting, excluding '\0'.

Parameters
strc-string
Returns
the number of characters that precede the terminating null character.
char* nanovdb::util::strncpy ( char *  dst,
const char *  src,
size_t  max 
)
inline

Copies the first num characters of src to dst. If the end of the source C string (which is signaled by a null-character) is found before max characters have been copied, dst is padded with zeros until a total of max characters have been written to it.

Parameters
dstdestination string
srcsource string
maxmaximum number of character in destination string
Returns
destination string dst
Warning
if strncpy(dst, src, max)[max-1]!='\0' then src has more characters than max and the return string needs to be manually null-terminated, i.e. strncpy(dst, src, max)[max-1]='\0'