Skip to content

Commit 569eda1

Browse files
committed
Add updateFiles.py, bug fix in updateFiles.sh, add pending changes for
NanoVDB 32.7. Signed-off-by: apradhana <[email protected]>
1 parent a836f7e commit 569eda1

File tree

3 files changed

+307
-3
lines changed

3 files changed

+307
-3
lines changed

nanovdb/nanovdb/cmd/updateFiles.py

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
import argparse
2+
import os
3+
from pathlib import Path
4+
5+
6+
def open_file(file_path):
7+
"""
8+
Opens a file. If utf-8 decoding fails, try windows-1252.
9+
10+
Args:
11+
file_path: Path of the file to open.
12+
13+
Returns:
14+
The content of the file in an arbitrary format.
15+
"""
16+
try:
17+
with open(file_path, "r", encoding="utf-8", errors="replace") as file:
18+
return file.read()
19+
except UnicodeDecodeError:
20+
with open(file_path, "r", encoding="windows-1252", errors="replace") as file:
21+
return file.read()
22+
23+
24+
def write_file(file_path, content):
25+
"""
26+
Writes a file. If utf-8 decoding fails, try windows-1252.
27+
28+
Args:
29+
file_path: Path of the file to open.
30+
31+
Returns:
32+
None.
33+
"""
34+
try:
35+
with open(file_path, "w", encoding="utf-8", errors="replace") as file:
36+
file.write(content)
37+
except UnicodeDecodeError:
38+
with open(file_path, "w", encoding="windows-1252", errors="replace") as file:
39+
file.write(content)
40+
41+
42+
def update_files(dir_path):
43+
"""
44+
Updates the content of files ending in .h, .cuh, .cc, .cu, and .cpp
45+
to call the appropriate API as we update NanoVDB from version 32.6 to
46+
version 32.7. This includes changes in namespaces, function names, and
47+
include directories.
48+
49+
Args:
50+
Directory path: will include files in downstream directories.
51+
52+
Returns:
53+
None. Writes the contents of the file.
54+
"""
55+
56+
# List of file extensions to search for
57+
file_extensions = [".h", ".cuh", ".cc", ".cu", ".cpp"]
58+
59+
nspace_dic = {
60+
"math": [
61+
"Ray",
62+
"DDA<",
63+
"HDDA",
64+
"Vec3<",
65+
"Vec4<",
66+
"BBox<",
67+
"ZeroCrossing",
68+
"TreeMarcher",
69+
"PointTreeMarcher",
70+
"BoxStencil<",
71+
"CurvatureStencil<",
72+
"GradStencil<",
73+
"WenoStencil<",
74+
"AlignUp",
75+
"Min",
76+
"Max",
77+
"Abs",
78+
"Clamp",
79+
"Sqrt",
80+
"Sign",
81+
"Maximum<",
82+
"Delta<",
83+
"RoundDown<",
84+
"pi<",
85+
"isApproxZero<",
86+
"Round<",
87+
"createSampler",
88+
"SampleFromVoxels<",
89+
],
90+
"tools": [
91+
"createNanoGrid",
92+
"StatsMode",
93+
"createLevelSetSphere",
94+
"createFogVolumeSphere",
95+
"createFogVolumeSphere createFogVolumeSphere",
96+
"createFogVolumeTorus",
97+
"createLevelSetBox",
98+
"CreateNanoGrid",
99+
"updateGridStats",
100+
"evalChecksum",
101+
"validateChecksum",
102+
"checkGrid",
103+
"Extrema",
104+
],
105+
"util": [
106+
"is_floating_point",
107+
"findLowestOn",
108+
"findHighestOn",
109+
"Range",
110+
"streq",
111+
"strcpy",
112+
"strcat",
113+
"empty(",
114+
"Split",
115+
"invoke",
116+
"forEach",
117+
"reduce",
118+
"prefixSum",
119+
"is_same",
120+
"is_specialization",
121+
"PtrAdd",
122+
"PtrDiff",
123+
],
124+
}
125+
126+
rename_dic = {
127+
# list from func4 in updateFiles.sh
128+
"nanovdb::build::": "nanovdb::tools::build::",
129+
"nanovdb::BBoxR": "nanovdb::Vec3dBBox",
130+
"nanovdb::BBox<nanovdb::Vec3d>": "nanovdb::Vec3dBbox",
131+
# scope and rename, i.e. list from func2 in updateFiles.sh
132+
"nanovdb::cudaCreateNodeManager": "nanovdb::cuda::createNodeManager",
133+
"nanovdb::cudaVoxelsToGrid": "nanovdb::cuda::voxelsToGrid",
134+
"nanovdb::cudaPointsToGrid": "nanovdb::cuda::pointsToGrid",
135+
"nanovdb::DitherLUT": "nanovdb::math::DitherLUT",
136+
"nanovdb::PackedRGBA8": "nanovdb::math::Rgba8",
137+
"nanovdb::Rgba8": "nanovdb::math::Rgba8",
138+
"nanovdb::CpuTimer": "nanovdb::util::Timer",
139+
"nanovdb::GpuTimer": "nanovdb::util::cuda::Timer",
140+
"nanovdb::CountOn": "nanovdb::util::countOn",
141+
}
142+
143+
movdir_dic = {
144+
# list comes from func3 calls on updateFiles.sh
145+
"util/GridHandle.h": "GridHandle.h",
146+
"util/BuildGrid.h": "tools/GridBuilder.h",
147+
"util/GridBuilder.h": "tools/GridBuilder.h",
148+
"util/IO.h": "io/IO.h",
149+
"util/CSampleFromVoxels.h": "math/CSampleFromVoxels.h",
150+
"util/DitherLUT.h": "math/DitherLUT.h",
151+
"util/HDDA.h": "math/HDDA.h",
152+
"util/Ray.h": "math/Ray.h",
153+
"util/SampleFromVoxels.h": "math/SampleFromVoxels.h",
154+
"util/Stencils.h": "nanovdb/math/Stencils.h",
155+
"util/CreateNanoGrid.h": "tools/CreateNanoGrid.h",
156+
"util/Primitives.h": "tools/CreatePrimitives.h",
157+
"util/GridChecksum.h": "tools/GridChecksum.h",
158+
"util/GridStats.h": "tools/GridStats.h",
159+
"util/GridChecksum.h": "tools/GridChecksum.h",
160+
"util/GridValidator.h": "tools/GridValidator.h",
161+
"util/NanoToOpenVDB.h": "tools/NanoToOpenVDB.h",
162+
"util/cuda/CudaGridChecksum.cuh": "tools/cuda/CudaGridChecksum.cuh",
163+
"util/cuda/CudaGridStats.cuh": "tools/cuda/CudaGridStats.cuh",
164+
"util/cuda/CudaGridValidator.cuh": "tools/cuda/CudaGridValidator.cuh",
165+
"util/cuda/CudaIndexToGrid.cuh": "tools/cuda/CudaIndexToGrid.cuh",
166+
"util/cuda/CudaPointsToGrid.cuh": "tools/cuda/PointsToGrid.cuh",
167+
"util/cuda/CudaSignedFloodFill.cuh": "tools/cuda/CudaSignedFloodFill.cuh",
168+
"util/cuda/CudaDeviceBuffer.h": "cuda/DeviceBuffer.h",
169+
"util/cuda/CudaGridHandle.cuh": "cuda/GridHandle.cuh",
170+
"util/cuda/CudaUtils.h": "util/cuda/Util.h",
171+
"util/cuda/GpuTimer.h": "util/cuda/Timer.h",
172+
}
173+
174+
# Iterate over files in the directory and its subdirectories
175+
for root, dirs, files in os.walk(dir_path):
176+
for file in files:
177+
if any(file.endswith(ext) for ext in file_extensions):
178+
file_path = os.path.join(root, file)
179+
print(f"Processing file: {file_path}")
180+
181+
content = open_file(file_path)
182+
183+
# Correspond to func1 $file in updateFiles.sh
184+
for key, vals in nspace_dic.items():
185+
for val in vals:
186+
old_word = "nanovdb::" + val
187+
new_word = "nanovdb::" + key + "::" + val
188+
content = content.replace(old_word, new_word)
189+
190+
# Correspond to func4 and func2 in updateFiles.sh
191+
for key, val in rename_dic.items():
192+
content = content.replace(key, val)
193+
194+
# Correspond to func3 in updateFiles.sh
195+
for key, val in movdir_dic.items():
196+
old_path = "<nanovdb/" + key + ">"
197+
new_path = "<nanovdb/" + val + ">"
198+
content = content.replace(old_path, new_path)
199+
200+
write_file(file_path, content)
201+
202+
# Example use:
203+
# To update all the files using NanoVDB in the current directory (and directories downstream):
204+
# python ./nanovdb/nanovdb/cmd/updateFiles.py
205+
# To update all the files using NanoVDB in a directory called foo (and directories downstream):
206+
# python ./nanovdb/nanovdb/cmd/updateFiles.py -d /path/to/foo
207+
if __name__ == "__main__":
208+
parser = argparse.ArgumentParser(description="Synthetic Data Generation for USD")
209+
parser.add_argument(
210+
"-d",
211+
"--directory",
212+
type=str,
213+
default=None,
214+
help="Path to directory containing .h, .cc, and .cu files using NanoVDB.",
215+
)
216+
217+
args = parser.parse_args()
218+
dir_path = os.getcwd() if args.directory is None else Path(args.directory).resolve()
219+
220+
update_files(dir_path)

nanovdb/nanovdb/cmd/updateFiles.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ for file in $(find "$dir" -name '*.h' -or -name '*.cuh' -or -name '*.cc' -or -na
6969
func2 $file util GpuTimer "cuda::Timer"
7070
func2 $file util CountOn countOn
7171
func3 $file "util/GridHandle.h" "GridHandle.h"
72-
func3 $file "util/GridHandle.h" "HostBuffer.h"
7372
func3 $file "util/BuildGrid.h" "tools/GridBuilder.h"
7473
func3 $file "util/GridBuilder.h" "tools/GridBuilder.h"
7574
func3 $file "util/IO.h" "io/IO.h"
@@ -90,11 +89,11 @@ for file in $(find "$dir" -name '*.h' -or -name '*.cuh' -or -name '*.cc' -or -na
9089
func3 $file "util/cuda/CudaGridStats.cuh" "tools/cuda/CudaGridStats.cuh"
9190
func3 $file "util/cuda/CudaGridValidator.cuh" "tools/cuda/CudaGridValidator.cuh"
9291
func3 $file "util/cuda/CudaIndexToGrid.cuh" "tools/cuda/CudaIndexToGrid.cuh"
93-
func3 $file "util/cuda/CudaPointsToGrid.cuh" "tools/GridChecksum.cuh"
92+
func3 $file "util/cuda/CudaPointsToGrid.cuh" "tools/cuda/PointsToGrid.cuh"
9493
func3 $file "util/cuda/CudaSignedFloodFill.cuh" "tools/cuda/CudaSignedFloodFill.cuh"
9594
func3 $file "util/cuda/CudaDeviceBuffer.h" "cuda/DeviceBuffer.h"
9695
func3 $file "util/cuda/CudaGridHandle.cuh" "cuda/GridHandle.cuh"
9796
func3 $file "util/cuda/CudaUtils.h" "util/cuda/Util.h"
9897
func3 $file "util/cuda/GpuTimer.h" "util/cuda/Timer.h"
9998
fi
100-
done
99+
done

pendingchanges/nanovdb_32.7.txt

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Bug fix:
2+
nanovdb::readGrids works with raw grid buffer.
3+
4+
Improvements:
5+
Restructure files location and namespace to be more align with OpenVDB. The
6+
namespaces touched by the restructuring are: io, cuda, util, tools, and math.
7+
Add two scripts updateFiles.sh and updateFiles.py to update the files using
8+
NanoVDB. The script updateFiles.py works on both Windows and Linux.
9+
For a more complete list of changes, see API Changes (details).
10+
11+
cuda::PointsToGrid supports target density.
12+
Add support for NanoVDB Grid of type UInt8.
13+
Add ability to use externally managed CUDA buffer.
14+
Add create methods for CudaDeviceBuffer and exceptions.
15+
Improve GridValidator logic, e.g. include check for grid count.
16+
Add operator > and >= for class Coord according to lexicographical order.
17+
Add toCodec to convert string to Codec enumeration type.
18+
Add nanovdb::strlen<GridType>().
19+
Add strncpy util.
20+
Add NANOVDB_DISABLE_SYNC_CUDA_MALLOC that maps cudaMallocAsync and
21+
cudaFreeAsync to cudaMalloc and cudaFree respectively.
22+
Add guard to UINT64_C.
23+
Remove use of cudaMallocAsync in PointsToGrid.cuh.
24+
Align PNanoVDB blind metadata to NanoVDB.
25+
26+
API Changes:
27+
Change mapToGridType to toGridType.
28+
Change mapToMagic to toMagic.
29+
Change CpuTimer.h to Timer.h.
30+
31+
API Changes (details):
32+
These APIs are now under the math namespace: Ray, DDA, HDDA, Vec3, Vec4, BBox,
33+
ZeroCrossing, TreeMarcher, PointTreeMarcher, BoxStencil, CurvatureStencil,
34+
GradStencil, WenoStencil, AlignUp, Min, Max, Abs, Clamp, Sqrt, Sign, Maximum,
35+
Delta, RoundDown, pi, isApproxZero, Round, createSampler, SampleFromVoxels.
36+
37+
These APIs are now under the tools namespace: createNanoGrid, StatsMode,
38+
createLevelSetSphere, createFogVolumeSphere, createFogVolumeSphere,
39+
createFogVolumeSphere, createFogVolumeTorus, createLevelSetBox, CreateNanoGrid,
40+
updateGridStats, evalChecksum, validateChecksum, checkGrid, Extrema.
41+
42+
These APIs are now under the util namespace: is_floating_point, findLowestOn,
43+
findHighestOn, Range, streq, strcpy, strcat, empty, Split, invoke, forEach,
44+
reduce, prefixSum, is_same, is_specialization, PtrAdd, PtrDiff.
45+
46+
Move nanovdb::build to nanovdb::tools::build.
47+
Rename nanovdb::BBoxR to nanovdb::Vec3dBBox.
48+
Rename nanovdb::BBox<nanovdb::Vec3d> to nanovdb::Vec3dBbox.
49+
Move nanovdb::cudaCreateNodeManager to nanovdb::cuda::createNodeManager.
50+
Move and rename nanovdb::cudaVoxelsToGrid to nanovdb::cuda::voxelsToGrid.
51+
Move and rename nanovdb::cudaPointsToGrid to nanovdb::cuda::pointsToGrid.
52+
Move nanovdb::DitherLUT to nanovdb::math::DitherLUT.
53+
Move and rename nanovdb::PackedRGBA8 to nanovdb::math::Rgba8.
54+
Move nanovdb::Rgba8 to nanovdb::math::Rgba8.
55+
Move and rename nanovdb::CpuTimer to nanovdb::util::Timer.
56+
Move nanovdb::GpuTimer to nanovdb::util::cuda::Timer.
57+
Move and rename nanovdb::CountOn to nanovdb::util::countOn.
58+
59+
Move util/GridHandle.h to GridHandle.h.
60+
Move util/BuildGrid.h to tools/GridBuilder.h.
61+
Move util/GridBuilder.h to tools/GridBuilder.h.
62+
Move util/IO.h to io/IO.h.
63+
Move util/CSampleFromVoxels.h to math/CSampleFromVoxels.h.
64+
Move util/DitherLUT.h to math/DitherLUT.h.
65+
Move util/HDDA.h to math/HDDA.h.
66+
Move util/Ray.h to math/Ray.h.
67+
Move util/SampleFromVoxels.h to math/SampleFromVoxels.h.
68+
Move util/Stencils.h to nanovdb/math/Stencils.h.
69+
Move util/CreateNanoGrid.h to tools/CreateNanoGrid.h.
70+
Move and rename util/Primitives.h to tools/CreatePrimitives.h.
71+
Move util/GridChecksum.h to tools/GridChecksum.h.
72+
Move util/GridStats.h to tools/GridStats.h.
73+
Move util/GridChecksum.h to tools/GridChecksum.h.
74+
Move util/GridValidator.h to tools/GridValidator.h.
75+
Move util/NanoToOpenVDB.h to tools/NanoToOpenVDB.h.
76+
Move util/cuda/CudaGridChecksum.cuh to tools/cuda/CudaGridChecksum.cuh.
77+
Move util/cuda/CudaGridStats.cuh to tools/cuda/CudaGridStats.cuh.
78+
Move util/cuda/CudaGridValidator.cuh to tools/cuda/CudaGridValidator.cuh.
79+
Move util/cuda/CudaIndexToGrid.cuh to tools/cuda/CudaIndexToGrid.cuh.
80+
Move and rename util/cuda/CudaPointsToGrid.cuh to tools/cuda/PointsToGrid.cuh.
81+
Move util/cuda/CudaSignedFloodFill.cuh to tools/cuda/CudaSignedFloodFill.cuh.
82+
Move and rename util/cuda/CudaDeviceBuffer.h to cuda/DeviceBuffer.h.
83+
Move and rename util/cuda/CudaGridHandle.cuh to cuda/GridHandle.cuh.
84+
Move and rename util/cuda/CudaUtils.h to util/cuda/Util.h.
85+
Move and consolidate util/cuda/GpuTimer.h to util/cuda/Timer.h.

0 commit comments

Comments
 (0)