20 #ifndef NANOVDB_NODEMANAGER_H_HAS_BEEN_INCLUDED 21 #define NANOVDB_NODEMANAGER_H_HAS_BEEN_INCLUDED 26 template <
typename BuildT>
30 template<
typename BufferT = HostBuffer>
40 template <
typename BuildT,
typename BufferT = HostBuffer>
42 const BufferT& buffer = BufferT());
53 template<
typename BufferT>
59 template<
typename BuildT>
61 return mGridType == toGridType<BuildT>() ? (
const NodeManager<BuildT>*)mBuffer.data() :
nullptr;
64 template<
typename BuildT,
typename U = BufferT>
66 getDeviceMgr()
const {
67 return mGridType == toGridType<BuildT>() ? (
const NodeManager<BuildT>*)mBuffer.deviceData() :
nullptr;
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>
149 typename util::enable_if<BufferTraits<U>::hasDeviceDual,
void>::type
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>
164 typename util::enable_if<BufferTraits<U>::hasDeviceDual,
void>::type
168 void *tmp = data->
mGrid;
169 mBuffer.deviceDownload(stream, sync);
178 template<
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;
246 if (DataT::mLinear) {
247 ptr = util::PtrAdd<const NodeT<LEVEL>>(DataT::mGrid, DataT::mOff[LEVEL]) + i;
249 ptr = util::PtrAdd<const NodeT<LEVEL>>(DataT::mGrid, DataT::mPtr[LEVEL][i]);
259 NodeT<LEVEL>* ptr =
nullptr;
260 if (DataT::mLinear) {
261 ptr = util::PtrAdd<NodeT<LEVEL>>(DataT::mGrid, DataT::mOff[LEVEL]) + i;
263 ptr = util::PtrAdd<NodeT<LEVEL>>(DataT::mGrid, DataT::mPtr[LEVEL][i]);
283 template <
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> 325 #endif// defined(__CUDACC__) 327 #endif // NANOVDB_NODEMANAGER_H_HAS_BEEN_INCLUDED __hostdev__ const GridType & gridType() const
Definition: NanoVDB.h:2140
C++11 implementation of std::enable_if.
Definition: Util.h:335
NodeManagerHandle manages the memory of a NodeManager.
Definition: NodeManager.h:31
NodeManager< BuildT > * mgr()
Returns a pointer to the NodeManager encoded in this NodeManagerHandle.
Definition: NodeManager.h:129
Highest level of the data structure. Contains a tree and a world->index transform (that currently onl...
Definition: NanoVDB.h:2011
__hostdev__ NodeT< LEVEL > & node(uint32_t i)
Return the i'th node with respect to breadth-first ordering.
Definition: NodeManager.h:257
void * data()
Returns a non-const pointer to the data.
Definition: NodeManager.h:109
__hostdev__ uint64_t nodeCount(int level) const
Return the number of tree nodes at the specified level.
Definition: NodeManager.h:235
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
#define NANOVDB_MAGIC_NUMB
Definition: NanoVDB.h:134
HostBuffer - a buffer that contains a shared or private bump pool to either externally or internally ...
static __hostdev__ bool isAligned(const void *p)
return true if the specified pointer is 32 byte aligned
Definition: NanoVDB.h:547
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
__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__ uint64_t lowerCount() const
Definition: NodeManager.h:238
int64_t mOff[3]
Definition: NodeManager.h:49
__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
__hostdev__ bool isLinear() const
return true if the nodes have both fixed size and are arranged breadth-first in memory. This allows for direct and memory-efficient linear access to nodes.
Definition: NodeManager.h:206
__hostdev__ bool isBreadthFirst() const
Definition: NanoVDB.h:2155
#define __hostdev__
Definition: Util.h:73
uint64_t mMagic
Definition: NodeManager.h:46
int64_t * mPtr[3]
Definition: NodeManager.h:49
static __hostdev__ bool isLinear(const GridT &grid)
return true if the nodes have both fixed size and are arranged breadth-first in memory. This allows for direct and memory-efficient linear access to nodes.
Definition: NodeManager.h:202
__hostdev__ TreeT & tree()
Return a reference to the tree.
Definition: NodeManager.h:226
__hostdev__ uint64_t memUsage() const
Return the memory footprint in bytes of this instance.
Definition: NodeManager.h:219
Implements a light-weight self-contained VDB data-structure in a single file! In other words...
Definition: GridHandle.h:27
const NodeManager< BuildT > * mgr() const
Returns a const pointer to the NodeManager encoded in this NodeManagerHandle.
Definition: NodeManager.h:123
Struct to derive node type from its level in a given grid, tree or root while preserving constness...
Definition: NanoVDB.h:1596
typename GridT::TreeType type
Definition: NanoVDB.h:2294
const BufferT & buffer() const
Return a const reference to the buffer.
Definition: NodeManager.h:104
NodeManagerHandle & operator=(NodeManagerHandle &&other) noexcept
Move copy assignment operation.
Definition: NodeManager.h:83
Definition: NodeManager.h:44
BufferT & buffer()
Return a reference to the buffer.
Definition: NodeManager.h:101
#define NANOVDB_MAGIC_NODE
Definition: NanoVDB.h:137
int64_t mPadding
Definition: NodeManager.h:47
__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__ GridT & grid()
Return a reference to the grid.
Definition: NodeManager.h:222
__hostdev__ uint64_t leafCount() const
Definition: NodeManager.h:237
NodeManagerHandle(NodeManagerHandle &&other) noexcept
Move copy-constructor.
Definition: NodeManager.h:90
__hostdev__ const RootT & root() const
Definition: NodeManager.h:231
void reset()
clear the buffer
Definition: NodeManager.h:98
__hostdev__ uint64_t upperCount() const
Definition: NodeManager.h:239
__hostdev__ const TreeT & tree() const
Return a const reference to the tree.
Definition: NanoVDB.h:2066
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
__hostdev__ RootT & root()
Return a reference to the root.
Definition: NodeManager.h:230
#define NANOVDB_ASSERT(x)
Definition: Util.h:50
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:219
NodeManager allows for sequential access to nodes.
Definition: NodeManager.h:27
__hostdev__ const TreeT & tree() const
Definition: NodeManager.h:227
uint64_t size() const
Returns the size in bytes of the raw memory buffer managed by this NodeManagerHandle's allocator...
Definition: NodeManager.h:117
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
void * mGrid
Definition: NodeManager.h:48
uint8_t mLinear
Definition: NodeManager.h:47
NodeManagerHandle< BufferT > createNodeManager(const NanoGrid< BuildT > &grid, const BufferT &buffer=BufferT())
brief Construct a NodeManager and return its handle
Definition: NodeManager.h:284
__hostdev__ Node1 & lower(uint32_t i)
Definition: NodeManager.h:275
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
util::enable_if< BufferTraits< U >::hasDeviceDual, const NodeManager< BuildT > * >::type deviceMgr() const
Return a const pointer to the NodeManager encoded in this NodeManagerHandle on the device...
Definition: NodeManager.h:136
const void * data() const
Returns a const pointer to the data.
Definition: NodeManager.h:114
__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__ Node2 & upper(uint32_t i)
Definition: NodeManager.h:279
__hostdev__ const GridT & grid() const
Definition: NodeManager.h:223
__hostdev__ Node0 & leaf(uint32_t i)
Definition: NodeManager.h:271
NodeManagerHandle(GridType gridType, BufferT &&buffer)
Move constructor from a buffer.
Definition: NodeManager.h:75
~NodeManagerHandle()
Default destructor.
Definition: NodeManager.h:96