20#ifndef NANOVDB_NODEMANAGER_H_HAS_BEEN_INCLUDED
21#define NANOVDB_NODEMANAGER_H_HAS_BEEN_INCLUDED
26template <
typename BuildT>
30template<
typename BufferT = HostBuffer>
40template <
typename BuildT,
typename BufferT = HostBuffer>
42 const BufferT& buffer = BufferT());
53template<
typename BufferT>
59 template<
typename BuildT>
64 template<
typename BuildT,
typename U = BufferT>
66 getDeviceMgr()
const {
71 static T* no_const(
const T* ptr) {
return const_cast<T*
>(ptr); }
84 mGridType = other.mGridType;
85 mBuffer = std::move(other.mBuffer);
91 mGridType = other.mGridType;
92 mBuffer = std::move(other.mBuffer);
98 void reset() { mBuffer.clear(); }
104 const BufferT&
buffer()
const {
return mBuffer; }
109 void*
data() {
return mBuffer.data(); }
114 const void*
data()
const {
return mBuffer.data(); }
117 uint64_t
size()
const {
return mBuffer.size(); }
122 template<
typename BuildT>
128 template<
typename BuildT>
134 template<
typename BuildT,
typename U = BufferT>
136 deviceMgr()
const {
return this->
template getDeviceMgr<BuildT>(); }
141 template<
typename BuildT,
typename U = BufferT>
143 deviceMgr() {
return no_const(this->
template getDeviceMgr<BuildT>()); }
148 template<
typename U = BufferT>
150 deviceUpload(
void* deviceGrid,
void* stream =
nullptr,
bool sync =
true)
154 void *tmp =
data->mGrid;
155 data->mGrid = deviceGrid;
156 mBuffer.deviceUpload(stream, sync);
163 template<
typename U = BufferT>
168 void *tmp =
data->mGrid;
169 mBuffer.deviceDownload(stream, sync);
178template<
typename BuildT>
186 using RootT = NodeT<3>;
187 using Node2 = NodeT<2>;
188 using Node1 = NodeT<1>;
189 using Node0 = NodeT<0>;
192 static constexpr bool FIXED_SIZE = Node0::FIXED_SIZE && Node1::FIXED_SIZE && Node2::FIXED_SIZE;
212 const uint32_t *p =
grid.tree().mNodeCount;
213 size +=
sizeof(int64_t)*(p[0]+p[1]+p[2]);
245 const NodeT<LEVEL>* ptr =
nullptr;
259 NodeT<LEVEL>* ptr =
nullptr;
283template <
typename BuildT,
typename BufferT>
285 const BufferT& buffer)
291#ifdef NANOVDB_USE_NEW_MAGIC_NUMBERS
298 data->mLinear = uint8_t(1u);
303 int64_t *ptr0 = data->mPtr[0] =
reinterpret_cast<int64_t*
>(data + 1);
304 int64_t *ptr1 = data->mPtr[1] = data->mPtr[0] + grid.
tree().nodeCount(0);
305 int64_t *ptr2 = data->mPtr[2] = data->mPtr[1] + grid.
tree().nodeCount(1);
307 for (
auto it2 = grid.
tree().root().cbeginChild(); it2; ++it2) {
309 for (
auto it1 = it2->cbeginChild(); it1; ++it1) {
311 for (
auto it0 = it1->cbeginChild(); it0; ++it0) {
323#if defined(__CUDACC__)
324#include <nanovdb/cuda/NodeManager.cuh>
HostBuffer - a buffer that contains a shared or private bump pool to either externally or internally ...
Implements a light-weight self-contained VDB data-structure in a single file! In other words,...
#define NANOVDB_MAGIC_NUMB
Definition NanoVDB.h:134
#define NANOVDB_MAGIC_NODE
Definition NanoVDB.h:137
__hostdev__ const TreeT & tree() const
Return a const reference to the tree.
Definition NanoVDB.h:2066
__hostdev__ const GridType & gridType() const
Definition NanoVDB.h:2140
NodeManagerHandle manages the memory of a NodeManager.
Definition NodeManager.h:55
void * data()
Returns a non-const pointer to the data.
Definition NodeManager.h:109
NodeManagerHandle & operator=(const NodeManagerHandle &)=delete
Disallow copy assignment operation.
BufferT & buffer()
Return a reference to the buffer.
Definition NodeManager.h:101
const void * data() const
Returns a const pointer to the data.
Definition NodeManager.h:114
util::enable_if< BufferTraits< U >::hasDeviceDual, void >::type deviceDownload(void *stream=nullptr, bool sync=true)
Download the NodeManager to from the device, e.g. from GPU to CPU.
Definition NodeManager.h:165
NodeManagerHandle & operator=(NodeManagerHandle &&other) noexcept
Move copy assignment operation.
Definition NodeManager.h:83
util::enable_if< BufferTraits< U >::hasDeviceDual, constNodeManager< BuildT > * >::type deviceMgr() const
Return a const pointer to the NodeManager encoded in this NodeManagerHandle on the device,...
Definition NodeManager.h:136
util::enable_if< BufferTraits< U >::hasDeviceDual, NodeManager< BuildT > * >::type deviceMgr()
Return a const pointer to the NodeManager encoded in this NodeManagerHandle on the device,...
Definition NodeManager.h:143
uint64_t size() const
Returns the size in bytes of the raw memory buffer managed by this NodeManagerHandle's allocator.
Definition NodeManager.h:117
const BufferT & buffer() const
Return a const reference to the buffer.
Definition NodeManager.h:104
util::enable_if< BufferTraits< U >::hasDeviceDual, void >::type deviceUpload(void *deviceGrid, void *stream=nullptr, bool sync=true)
Upload the NodeManager to the device, e.g. from CPU to GPU.
Definition NodeManager.h:150
NodeManager< BuildT > * mgr()
Returns a pointer to the NodeManager encoded in this NodeManagerHandle.
Definition NodeManager.h:129
const NodeManager< BuildT > * mgr() const
Returns a const pointer to the NodeManager encoded in this NodeManagerHandle.
Definition NodeManager.h:123
NodeManagerHandle()=default
Empty ctor.
NodeManagerHandle(const NodeManagerHandle &)=delete
Disallow copy-construction.
void reset()
clear the buffer
Definition NodeManager.h:98
NodeManagerHandle(NodeManagerHandle &&other) noexcept
Move copy-constructor.
Definition NodeManager.h:90
~NodeManagerHandle()
Default destructor.
Definition NodeManager.h:96
NodeManagerHandle(GridType gridType, BufferT &&buffer)
Move constructor from a buffer.
Definition NodeManager.h:75
NodeManager allows for sequential access to nodes.
Definition NodeManager.h:180
NodeManager & operator=(const NodeManager &)=delete
__hostdev__ uint64_t lowerCount() const
Definition NodeManager.h:238
NodeManager & operator=(NodeManager &&)=delete
__hostdev__ uint64_t leafCount() const
Definition NodeManager.h:237
static constexpr bool FIXED_SIZE
Definition NodeManager.h:192
__hostdev__ const TreeT & tree() const
Definition NodeManager.h:227
__hostdev__ Node2 & upper(uint32_t i)
Definition NodeManager.h:279
__hostdev__ GridT & grid()
Return a reference to the grid.
Definition NodeManager.h:222
__hostdev__ const GridT & grid() const
Definition NodeManager.h:223
__hostdev__ RootT & root()
Return a reference to the root.
Definition NodeManager.h:230
NodeManager(const NodeManager &)=delete
NodeManager(NodeManager &&)=delete
__hostdev__ const NodeT< LEVEL > & node(uint32_t i) const
Return the i'th leaf node with respect to breadth-first ordering.
Definition NodeManager.h:243
static __hostdev__ bool isLinear(const GridT &grid)
return true if the nodes have both fixed size and are arranged breadth-first in memory....
Definition NodeManager.h:202
__hostdev__ uint64_t upperCount() const
Definition NodeManager.h:239
__hostdev__ uint64_t nodeCount(int level) const
Return the number of tree nodes at the specified level.
Definition NodeManager.h:235
__hostdev__ Node0 & leaf(uint32_t i)
Definition NodeManager.h:271
__hostdev__ NodeT< LEVEL > & node(uint32_t i)
Return the i'th node with respect to breadth-first ordering.
Definition NodeManager.h:257
__hostdev__ const Node0 & leaf(uint32_t i) const
Return the i'th leaf node with respect to breadth-first ordering.
Definition NodeManager.h:270
__hostdev__ uint64_t memUsage() const
Return the memory footprint in bytes of this instance.
Definition NodeManager.h:219
static __hostdev__ uint64_t memUsage(const GridT &grid)
Return the memory footprint in bytes of the NodeManager derived from the specified grid.
Definition NodeManager.h:209
__hostdev__ bool isLinear() const
return true if the nodes have both fixed size and are arranged breadth-first in memory....
Definition NodeManager.h:206
__hostdev__ Node1 & lower(uint32_t i)
Definition NodeManager.h:275
__hostdev__ const Node2 & upper(uint32_t i) const
Return the i'th upper internal node with respect to breadth-first ordering.
Definition NodeManager.h:278
__hostdev__ const Node1 & lower(uint32_t i) const
Return the i'th lower internal node with respect to breadth-first ordering.
Definition NodeManager.h:274
__hostdev__ const RootT & root() const
Definition NodeManager.h:231
__hostdev__ TreeT & tree()
Return a reference to the tree.
Definition NodeManager.h:226
static DstT * PtrAdd(void *p, int64_t offset)
Adds a byte offset to a non-const pointer to produce another non-const pointer.
Definition Util.h:478
static int64_t PtrDiff(const void *p, const void *q)
Compute the distance, in bytes, between two pointers, dist = p - q.
Definition Util.h:464
Definition GridHandle.h:27
Grid< NanoTree< BuildT > > NanoGrid
Definition NanoVDB.h:4750
__hostdev__ GridType toGridType()
Maps from a templated build type to a GridType enum.
Definition NanoVDB.h:812
GridType
List of types that are currently supported by NanoVDB.
Definition NanoVDB.h:219
@ Unknown
Definition NanoVDB.h:219
static __hostdev__ bool isAligned(const void *p)
return true if the specified pointer is 32 byte aligned
Definition NanoVDB.h:547
NodeManagerHandle< BufferT > createNodeManager(const NanoGrid< BuildT > &grid, const BufferT &buffer=BufferT())
brief Construct a NodeManager and return its handle
Definition NodeManager.h:284
#define __hostdev__
Definition Util.h:73
#define NANOVDB_ASSERT(x)
Definition Util.h:50
typename GridT::TreeType type
Definition NanoVDB.h:2294
Definition NodeManager.h:45
int64_t * mPtr[3]
Definition NodeManager.h:49
int64_t mOff[3]
Definition NodeManager.h:49
uint64_t mMagic
Definition NodeManager.h:46
void * mGrid
Definition NodeManager.h:48
uint8_t mLinear
Definition NodeManager.h:47
int64_t mPadding
Definition NodeManager.h:47
Struct to derive node type from its level in a given grid, tree or root while preserving constness.
Definition NanoVDB.h:1596
C++11 implementation of std::enable_if.
Definition Util.h:335