warp-lang 0.9.0__py3-none-win_amd64.whl → 0.11.0__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of warp-lang might be problematic. Click here for more details.
- warp/__init__.py +15 -7
- warp/__init__.pyi +1 -0
- warp/bin/warp-clang.dll +0 -0
- warp/bin/warp.dll +0 -0
- warp/build.py +22 -443
- warp/build_dll.py +384 -0
- warp/builtins.py +998 -488
- warp/codegen.py +1307 -739
- warp/config.py +5 -3
- warp/constants.py +6 -0
- warp/context.py +1291 -548
- warp/dlpack.py +31 -31
- warp/fabric.py +326 -0
- warp/fem/__init__.py +27 -0
- warp/fem/cache.py +389 -0
- warp/fem/dirichlet.py +181 -0
- warp/fem/domain.py +263 -0
- warp/fem/field/__init__.py +101 -0
- warp/fem/field/field.py +149 -0
- warp/fem/field/nodal_field.py +299 -0
- warp/fem/field/restriction.py +21 -0
- warp/fem/field/test.py +181 -0
- warp/fem/field/trial.py +183 -0
- warp/fem/geometry/__init__.py +19 -0
- warp/fem/geometry/closest_point.py +70 -0
- warp/fem/geometry/deformed_geometry.py +271 -0
- warp/fem/geometry/element.py +744 -0
- warp/fem/geometry/geometry.py +186 -0
- warp/fem/geometry/grid_2d.py +373 -0
- warp/fem/geometry/grid_3d.py +435 -0
- warp/fem/geometry/hexmesh.py +953 -0
- warp/fem/geometry/partition.py +376 -0
- warp/fem/geometry/quadmesh_2d.py +532 -0
- warp/fem/geometry/tetmesh.py +840 -0
- warp/fem/geometry/trimesh_2d.py +577 -0
- warp/fem/integrate.py +1616 -0
- warp/fem/operator.py +191 -0
- warp/fem/polynomial.py +213 -0
- warp/fem/quadrature/__init__.py +2 -0
- warp/fem/quadrature/pic_quadrature.py +245 -0
- warp/fem/quadrature/quadrature.py +294 -0
- warp/fem/space/__init__.py +292 -0
- warp/fem/space/basis_space.py +489 -0
- warp/fem/space/collocated_function_space.py +105 -0
- warp/fem/space/dof_mapper.py +236 -0
- warp/fem/space/function_space.py +145 -0
- warp/fem/space/grid_2d_function_space.py +267 -0
- warp/fem/space/grid_3d_function_space.py +306 -0
- warp/fem/space/hexmesh_function_space.py +352 -0
- warp/fem/space/partition.py +350 -0
- warp/fem/space/quadmesh_2d_function_space.py +369 -0
- warp/fem/space/restriction.py +160 -0
- warp/fem/space/shape/__init__.py +15 -0
- warp/fem/space/shape/cube_shape_function.py +738 -0
- warp/fem/space/shape/shape_function.py +103 -0
- warp/fem/space/shape/square_shape_function.py +611 -0
- warp/fem/space/shape/tet_shape_function.py +567 -0
- warp/fem/space/shape/triangle_shape_function.py +429 -0
- warp/fem/space/tetmesh_function_space.py +292 -0
- warp/fem/space/topology.py +295 -0
- warp/fem/space/trimesh_2d_function_space.py +221 -0
- warp/fem/types.py +77 -0
- warp/fem/utils.py +495 -0
- warp/native/array.h +164 -55
- warp/native/builtin.h +150 -174
- warp/native/bvh.cpp +75 -328
- warp/native/bvh.cu +406 -23
- warp/native/bvh.h +37 -45
- warp/native/clang/clang.cpp +136 -24
- warp/native/crt.cpp +1 -76
- warp/native/crt.h +111 -104
- warp/native/cuda_crt.h +1049 -0
- warp/native/cuda_util.cpp +15 -3
- warp/native/cuda_util.h +3 -1
- warp/native/cutlass/tools/library/scripts/conv2d_operation.py +463 -0
- warp/native/cutlass/tools/library/scripts/conv3d_operation.py +321 -0
- warp/native/cutlass/tools/library/scripts/gemm_operation.py +988 -0
- warp/native/cutlass/tools/library/scripts/generator.py +4625 -0
- warp/native/cutlass/tools/library/scripts/library.py +799 -0
- warp/native/cutlass/tools/library/scripts/manifest.py +402 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/docs/source/conf.py +96 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/profile/conv/conv2d_f16_sm80.py +106 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/profile/gemm/gemm_f32_sm80.py +91 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/setup.py +80 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/__init__.py +48 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/arguments.py +118 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/c_types.py +241 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/compiler.py +432 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/conv2d_operation.py +631 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/epilogue.py +1026 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/frontend.py +104 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/gemm_operation.py +1276 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/library.py +744 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/memory_manager.py +74 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/operation.py +110 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/parser.py +619 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/reduction_operation.py +398 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/tensor_ref.py +70 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/__init__.py +4 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/conv2d_testbed.py +646 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/gemm_grouped_testbed.py +235 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/gemm_testbed.py +557 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/profiler.py +70 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/type_hint.py +39 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/__init__.py +1 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/device.py +76 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/reference_model.py +255 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/__init__.py +0 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +201 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +177 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +98 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +95 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_few_channels_f16nhwc_f16nhwc_f16nhwc_tensor_op_f32_sm80.py +163 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_fixed_channels_f16nhwc_f16nhwc_f16nhwc_tensor_op_f32_sm80.py +187 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +309 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +54 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +96 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +107 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_strided_dgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +253 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +97 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +242 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +96 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +107 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/run_all_tests.py +10 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/frontend/test_frontend.py +146 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/__init__.py +0 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_bf16_sm80.py +96 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f16_sm80.py +447 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f32_sm80.py +146 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f64_sm80.py +102 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_grouped_sm80.py +203 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_s8_sm80.py +229 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/run_all_tests.py +9 -0
- warp/native/cutlass/tools/library/scripts/pycutlass/test/unit/test_sm80.py +453 -0
- warp/native/cutlass/tools/library/scripts/rank_2k_operation.py +398 -0
- warp/native/cutlass/tools/library/scripts/rank_k_operation.py +387 -0
- warp/native/cutlass/tools/library/scripts/rt.py +796 -0
- warp/native/cutlass/tools/library/scripts/symm_operation.py +400 -0
- warp/native/cutlass/tools/library/scripts/trmm_operation.py +407 -0
- warp/native/cutlass_gemm.cu +5 -3
- warp/native/exports.h +1240 -949
- warp/native/fabric.h +228 -0
- warp/native/hashgrid.cpp +4 -4
- warp/native/hashgrid.h +22 -2
- warp/native/initializer_array.h +2 -2
- warp/native/intersect.h +22 -7
- warp/native/intersect_adj.h +8 -8
- warp/native/intersect_tri.h +13 -16
- warp/native/marching.cu +157 -161
- warp/native/mat.h +119 -19
- warp/native/matnn.h +2 -2
- warp/native/mesh.cpp +108 -83
- warp/native/mesh.cu +243 -6
- warp/native/mesh.h +1547 -458
- warp/native/nanovdb/NanoVDB.h +1 -1
- warp/native/noise.h +272 -329
- warp/native/quat.h +51 -8
- warp/native/rand.h +45 -35
- warp/native/range.h +6 -2
- warp/native/reduce.cpp +157 -0
- warp/native/reduce.cu +348 -0
- warp/native/runlength_encode.cpp +62 -0
- warp/native/runlength_encode.cu +46 -0
- warp/native/scan.cu +11 -13
- warp/native/scan.h +1 -0
- warp/native/solid_angle.h +442 -0
- warp/native/sort.cpp +13 -0
- warp/native/sort.cu +9 -1
- warp/native/sparse.cpp +338 -0
- warp/native/sparse.cu +545 -0
- warp/native/spatial.h +2 -2
- warp/native/temp_buffer.h +30 -0
- warp/native/vec.h +126 -24
- warp/native/volume.h +120 -0
- warp/native/warp.cpp +658 -53
- warp/native/warp.cu +660 -68
- warp/native/warp.h +112 -12
- warp/optim/__init__.py +1 -0
- warp/optim/linear.py +922 -0
- warp/optim/sgd.py +92 -0
- warp/render/render_opengl.py +392 -152
- warp/render/render_usd.py +11 -11
- warp/sim/__init__.py +2 -2
- warp/sim/articulation.py +385 -185
- warp/sim/collide.py +21 -8
- warp/sim/import_mjcf.py +297 -106
- warp/sim/import_urdf.py +389 -210
- warp/sim/import_usd.py +198 -97
- warp/sim/inertia.py +17 -18
- warp/sim/integrator_euler.py +14 -8
- warp/sim/integrator_xpbd.py +161 -19
- warp/sim/model.py +795 -291
- warp/sim/optimizer.py +2 -6
- warp/sim/render.py +65 -3
- warp/sim/utils.py +3 -0
- warp/sparse.py +1227 -0
- warp/stubs.py +665 -223
- warp/tape.py +66 -15
- warp/tests/__main__.py +3 -6
- warp/tests/assets/curlnoise_golden.npy +0 -0
- warp/tests/assets/pnoise_golden.npy +0 -0
- warp/tests/assets/torus.usda +105 -105
- warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
- warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
- warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
- warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
- warp/tests/aux_test_unresolved_func.py +14 -0
- warp/tests/aux_test_unresolved_symbol.py +14 -0
- warp/tests/disabled_kinematics.py +239 -0
- warp/tests/run_coverage_serial.py +31 -0
- warp/tests/test_adam.py +103 -106
- warp/tests/test_arithmetic.py +128 -74
- warp/tests/test_array.py +1497 -211
- warp/tests/test_array_reduce.py +150 -0
- warp/tests/test_atomic.py +64 -28
- warp/tests/test_bool.py +99 -0
- warp/tests/test_builtins_resolution.py +1292 -0
- warp/tests/test_bvh.py +75 -43
- warp/tests/test_closest_point_edge_edge.py +54 -57
- warp/tests/test_codegen.py +233 -128
- warp/tests/test_compile_consts.py +28 -20
- warp/tests/test_conditional.py +108 -24
- warp/tests/test_copy.py +10 -12
- warp/tests/test_ctypes.py +112 -88
- warp/tests/test_dense.py +21 -14
- warp/tests/test_devices.py +98 -0
- warp/tests/test_dlpack.py +136 -108
- warp/tests/test_examples.py +277 -0
- warp/tests/test_fabricarray.py +955 -0
- warp/tests/test_fast_math.py +15 -11
- warp/tests/test_fem.py +1271 -0
- warp/tests/test_fp16.py +53 -19
- warp/tests/test_func.py +187 -74
- warp/tests/test_generics.py +194 -49
- warp/tests/test_grad.py +180 -116
- warp/tests/test_grad_customs.py +176 -0
- warp/tests/test_hash_grid.py +52 -37
- warp/tests/test_import.py +10 -23
- warp/tests/test_indexedarray.py +577 -24
- warp/tests/test_intersect.py +18 -9
- warp/tests/test_large.py +141 -0
- warp/tests/test_launch.py +251 -15
- warp/tests/test_lerp.py +64 -65
- warp/tests/test_linear_solvers.py +154 -0
- warp/tests/test_lvalue.py +493 -0
- warp/tests/test_marching_cubes.py +12 -13
- warp/tests/test_mat.py +508 -2778
- warp/tests/test_mat_lite.py +115 -0
- warp/tests/test_mat_scalar_ops.py +2889 -0
- warp/tests/test_math.py +103 -9
- warp/tests/test_matmul.py +305 -69
- warp/tests/test_matmul_lite.py +410 -0
- warp/tests/test_mesh.py +71 -14
- warp/tests/test_mesh_query_aabb.py +41 -25
- warp/tests/test_mesh_query_point.py +325 -34
- warp/tests/test_mesh_query_ray.py +39 -22
- warp/tests/test_mlp.py +30 -22
- warp/tests/test_model.py +92 -89
- warp/tests/test_modules_lite.py +39 -0
- warp/tests/test_multigpu.py +88 -114
- warp/tests/test_noise.py +12 -11
- warp/tests/test_operators.py +16 -20
- warp/tests/test_options.py +11 -11
- warp/tests/test_pinned.py +17 -18
- warp/tests/test_print.py +32 -11
- warp/tests/test_quat.py +275 -129
- warp/tests/test_rand.py +18 -16
- warp/tests/test_reload.py +38 -34
- warp/tests/test_rounding.py +50 -43
- warp/tests/test_runlength_encode.py +190 -0
- warp/tests/test_smoothstep.py +9 -11
- warp/tests/test_snippet.py +143 -0
- warp/tests/test_sparse.py +460 -0
- warp/tests/test_spatial.py +276 -243
- warp/tests/test_streams.py +110 -85
- warp/tests/test_struct.py +331 -85
- warp/tests/test_tape.py +39 -21
- warp/tests/test_torch.py +118 -89
- warp/tests/test_transient_module.py +12 -13
- warp/tests/test_types.py +614 -0
- warp/tests/test_utils.py +494 -0
- warp/tests/test_vec.py +354 -1987
- warp/tests/test_vec_lite.py +73 -0
- warp/tests/test_vec_scalar_ops.py +2099 -0
- warp/tests/test_volume.py +457 -293
- warp/tests/test_volume_write.py +124 -134
- warp/tests/unittest_serial.py +35 -0
- warp/tests/unittest_suites.py +341 -0
- warp/tests/unittest_utils.py +568 -0
- warp/tests/unused_test_misc.py +71 -0
- warp/tests/{test_debug.py → walkthough_debug.py} +3 -17
- warp/thirdparty/appdirs.py +36 -45
- warp/thirdparty/unittest_parallel.py +549 -0
- warp/torch.py +72 -30
- warp/types.py +1744 -713
- warp/utils.py +360 -350
- warp_lang-0.11.0.dist-info/LICENSE.md +36 -0
- warp_lang-0.11.0.dist-info/METADATA +238 -0
- warp_lang-0.11.0.dist-info/RECORD +332 -0
- {warp_lang-0.9.0.dist-info → warp_lang-0.11.0.dist-info}/WHEEL +1 -1
- warp/bin/warp-clang.exp +0 -0
- warp/bin/warp-clang.lib +0 -0
- warp/bin/warp.exp +0 -0
- warp/bin/warp.lib +0 -0
- warp/tests/test_all.py +0 -215
- warp/tests/test_array_scan.py +0 -60
- warp/tests/test_base.py +0 -208
- warp/tests/test_unresolved_func.py +0 -7
- warp/tests/test_unresolved_symbol.py +0 -7
- warp_lang-0.9.0.dist-info/METADATA +0 -20
- warp_lang-0.9.0.dist-info/RECORD +0 -177
- /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
- /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
- /warp/tests/{test_square.py → aux_test_square.py} +0 -0
- {warp_lang-0.9.0.dist-info → warp_lang-0.11.0.dist-info}/top_level.txt +0 -0
warp/tests/test_volume.py
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
# distribution of this software and related documentation without an express
|
|
6
6
|
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
from warp.tests.test_base import *
|
|
8
|
+
import unittest
|
|
10
9
|
|
|
11
10
|
import numpy as np
|
|
12
11
|
|
|
12
|
+
import warp as wp
|
|
13
|
+
from warp.tests.unittest_utils import *
|
|
14
|
+
|
|
13
15
|
wp.init()
|
|
14
16
|
|
|
15
17
|
|
|
@@ -62,6 +64,29 @@ def test_volume_sample_linear_f(volume: wp.uint64, points: wp.array(dtype=wp.vec
|
|
|
62
64
|
expect_near(wp.volume_sample_f(volume, p, wp.Volume.LINEAR), expected, 2.0e-4)
|
|
63
65
|
|
|
64
66
|
|
|
67
|
+
@wp.kernel
|
|
68
|
+
def test_volume_sample_grad_linear_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
69
|
+
tid = wp.tid()
|
|
70
|
+
|
|
71
|
+
p = points[tid]
|
|
72
|
+
|
|
73
|
+
expected_val = p[0] * p[1] * p[2]
|
|
74
|
+
expected_gx = p[1] * p[2]
|
|
75
|
+
expected_gy = p[0] * p[2]
|
|
76
|
+
expected_gz = p[0] * p[1]
|
|
77
|
+
|
|
78
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
79
|
+
return # not testing against background values
|
|
80
|
+
|
|
81
|
+
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
82
|
+
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
83
|
+
|
|
84
|
+
expect_near(val, expected_val, 2.0e-4)
|
|
85
|
+
expect_near(grad[0], expected_gx, 2.0e-4)
|
|
86
|
+
expect_near(grad[1], expected_gy, 2.0e-4)
|
|
87
|
+
expect_near(grad[2], expected_gz, 2.0e-4)
|
|
88
|
+
|
|
89
|
+
|
|
65
90
|
@wp.kernel
|
|
66
91
|
def test_volume_sample_local_f_linear_values(
|
|
67
92
|
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
@@ -71,6 +96,25 @@ def test_volume_sample_local_f_linear_values(
|
|
|
71
96
|
values[tid] = wp.volume_sample_f(volume, p, wp.Volume.LINEAR)
|
|
72
97
|
|
|
73
98
|
|
|
99
|
+
@wp.kernel
|
|
100
|
+
def test_volume_sample_grad_local_f_linear_values(
|
|
101
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num: int
|
|
102
|
+
):
|
|
103
|
+
tid = wp.tid()
|
|
104
|
+
p = points[tid]
|
|
105
|
+
|
|
106
|
+
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
107
|
+
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
108
|
+
|
|
109
|
+
if case_num == 1:
|
|
110
|
+
val = grad[0]
|
|
111
|
+
elif case_num == 2:
|
|
112
|
+
val = grad[1]
|
|
113
|
+
elif case_num == 3:
|
|
114
|
+
val = grad[2]
|
|
115
|
+
values[tid] = val
|
|
116
|
+
|
|
117
|
+
|
|
74
118
|
@wp.kernel
|
|
75
119
|
def test_volume_sample_world_f_linear_values(
|
|
76
120
|
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
@@ -81,6 +125,27 @@ def test_volume_sample_world_f_linear_values(
|
|
|
81
125
|
values[tid] = wp.volume_sample_f(volume, p, wp.Volume.LINEAR)
|
|
82
126
|
|
|
83
127
|
|
|
128
|
+
@wp.kernel
|
|
129
|
+
def test_volume_sample_grad_world_f_linear_values(
|
|
130
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num: int
|
|
131
|
+
):
|
|
132
|
+
tid = wp.tid()
|
|
133
|
+
q = points[tid]
|
|
134
|
+
p = wp.volume_world_to_index(volume, q)
|
|
135
|
+
|
|
136
|
+
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
137
|
+
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
138
|
+
|
|
139
|
+
if case_num == 1:
|
|
140
|
+
val = grad[0]
|
|
141
|
+
elif case_num == 2:
|
|
142
|
+
val = grad[1]
|
|
143
|
+
elif case_num == 3:
|
|
144
|
+
val = grad[2]
|
|
145
|
+
|
|
146
|
+
values[tid] = val
|
|
147
|
+
|
|
148
|
+
|
|
84
149
|
# vec3f volume tests
|
|
85
150
|
@wp.kernel
|
|
86
151
|
def test_volume_lookup_v(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
@@ -265,308 +330,407 @@ def test_volume_store_i(volume: wp.uint64, points: wp.array(dtype=wp.vec3), valu
|
|
|
265
330
|
values[tid] = wp.volume_lookup_i(volume, i, j, k)
|
|
266
331
|
|
|
267
332
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
333
|
+
devices = get_test_devices()
|
|
334
|
+
rng = np.random.default_rng(101215)
|
|
335
|
+
|
|
336
|
+
# Note about the test grids:
|
|
337
|
+
# test_grid and test_int32_grid
|
|
338
|
+
# active region: [-10,10]^3
|
|
339
|
+
# values: v[i,j,k] = i * j * k
|
|
340
|
+
# voxel size: 0.25
|
|
341
|
+
#
|
|
342
|
+
# test_vec_grid
|
|
343
|
+
# active region: [-10,10]^3
|
|
344
|
+
# values: v[i,j,k] = (i + 2*j + 3*k, 4*i + 5*j + 6*k, 7*i + 8*j + 9*k)
|
|
345
|
+
# voxel size: 0.25
|
|
346
|
+
#
|
|
347
|
+
# torus
|
|
348
|
+
# index to world transformation:
|
|
349
|
+
# [0.1, 0, 0, 0]
|
|
350
|
+
# [0, 0, 0.1, 0]
|
|
351
|
+
# [0, 0.1, 0, 0]
|
|
352
|
+
# [1, 2, 3, 1]
|
|
353
|
+
# (-90 degrees rotation along X)
|
|
354
|
+
# voxel size: 0.1
|
|
355
|
+
volume_paths = {
|
|
356
|
+
"float": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_grid.nvdb")),
|
|
357
|
+
"int32": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_int32_grid.nvdb")),
|
|
358
|
+
"vec3f": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_vec_grid.nvdb")),
|
|
359
|
+
"torus": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/torus.nvdb")),
|
|
360
|
+
"float_write": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_grid.nvdb")),
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
test_volume_tiles = (
|
|
364
|
+
np.array([[i, j, k] for i in range(-2, 2) for j in range(-2, 2) for k in range(-2, 2)], dtype=np.int32) * 8
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
volumes = {}
|
|
368
|
+
for value_type, path in volume_paths.items():
|
|
369
|
+
volumes[value_type] = {}
|
|
370
|
+
volume_data = open(path, "rb").read()
|
|
371
|
+
for device in devices:
|
|
372
|
+
try:
|
|
373
|
+
volume = wp.Volume.load_from_nvdb(volume_data, device)
|
|
374
|
+
except RuntimeError as e:
|
|
375
|
+
raise RuntimeError(f'Failed to load volume from "{path}" to {device} memory:\n{e}')
|
|
376
|
+
|
|
377
|
+
volumes[value_type][device.alias] = volume
|
|
378
|
+
|
|
379
|
+
axis = np.linspace(-1, 1, 3)
|
|
380
|
+
point_grid = np.array([[x, y, z] for x in axis for y in axis for z in axis], dtype=np.float32)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def test_volume_sample_linear_f_gradient(test, device):
|
|
384
|
+
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
385
|
+
values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
|
|
386
|
+
for test_case in points:
|
|
387
|
+
uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
388
|
+
xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
389
|
+
|
|
390
|
+
tape = wp.Tape()
|
|
391
|
+
with tape:
|
|
392
|
+
wp.launch(
|
|
393
|
+
test_volume_sample_local_f_linear_values,
|
|
394
|
+
dim=1,
|
|
395
|
+
inputs=[volumes["float"][device.alias].id, uvws, values],
|
|
396
|
+
device=device,
|
|
397
|
+
)
|
|
398
|
+
tape.backward(values)
|
|
399
|
+
|
|
400
|
+
x, y, z = test_case
|
|
401
|
+
grad_expected = np.array([y * z, x * z, x * y])
|
|
402
|
+
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
403
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
404
|
+
|
|
405
|
+
tape = wp.Tape()
|
|
406
|
+
with tape:
|
|
407
|
+
wp.launch(
|
|
408
|
+
test_volume_sample_world_f_linear_values,
|
|
409
|
+
dim=1,
|
|
410
|
+
inputs=[volumes["float"][device.alias].id, xyzs, values],
|
|
411
|
+
device=device,
|
|
412
|
+
)
|
|
413
|
+
tape.backward(values)
|
|
302
414
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
volumes[value_type] = {}
|
|
308
|
-
volume_data = open(path, "rb").read()
|
|
309
|
-
for device in devices:
|
|
310
|
-
try:
|
|
311
|
-
volume = wp.Volume.load_from_nvdb(volume_data, device)
|
|
312
|
-
except RuntimeError as e:
|
|
313
|
-
raise RuntimeError(f'Failed to load volume from "{path}" to {device} memory:\n{e}')
|
|
314
|
-
|
|
315
|
-
volumes[value_type][device.alias] = volume
|
|
316
|
-
|
|
317
|
-
axis = np.linspace(-1, 1, 3)
|
|
318
|
-
point_grid = np.array([[x, y, z] for x in axis for y in axis for z in axis], dtype=np.float32)
|
|
319
|
-
|
|
320
|
-
class TestVolumes(parent):
|
|
321
|
-
def test_volume_sample_linear_f_gradient(self):
|
|
322
|
-
for device in devices:
|
|
323
|
-
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
324
|
-
values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
|
|
325
|
-
for case in points:
|
|
326
|
-
uvws = wp.array(case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
327
|
-
xyzs = wp.array(case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
328
|
-
|
|
329
|
-
tape = wp.Tape()
|
|
330
|
-
with tape:
|
|
331
|
-
wp.launch(
|
|
332
|
-
test_volume_sample_local_f_linear_values,
|
|
333
|
-
dim=1,
|
|
334
|
-
inputs=[volumes["float"][device.alias].id, uvws, values],
|
|
335
|
-
device=device,
|
|
336
|
-
)
|
|
337
|
-
tape.backward(values)
|
|
338
|
-
|
|
339
|
-
x, y, z = case
|
|
340
|
-
grad_expected = np.array([y * z, x * z, x * y])
|
|
341
|
-
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
342
|
-
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
343
|
-
|
|
344
|
-
tape = wp.Tape()
|
|
345
|
-
with tape:
|
|
346
|
-
wp.launch(
|
|
347
|
-
test_volume_sample_world_f_linear_values,
|
|
348
|
-
dim=1,
|
|
349
|
-
inputs=[volumes["float"][device.alias].id, xyzs, values],
|
|
350
|
-
device=device,
|
|
351
|
-
)
|
|
352
|
-
tape.backward(values)
|
|
353
|
-
|
|
354
|
-
x, y, z = case
|
|
355
|
-
grad_expected = np.array([y * z, x * z, x * y]) / 0.25
|
|
356
|
-
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
357
|
-
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
358
|
-
|
|
359
|
-
def test_volume_sample_linear_v_gradient(self):
|
|
360
|
-
for device in devices:
|
|
361
|
-
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
362
|
-
values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
|
|
363
|
-
for case in points:
|
|
364
|
-
uvws = wp.array(case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
365
|
-
xyzs = wp.array(case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
366
|
-
|
|
367
|
-
tape = wp.Tape()
|
|
368
|
-
with tape:
|
|
369
|
-
wp.launch(
|
|
370
|
-
test_volume_sample_local_v_linear_values,
|
|
371
|
-
dim=1,
|
|
372
|
-
inputs=[volumes["vec3f"][device.alias].id, uvws, values],
|
|
373
|
-
device=device,
|
|
374
|
-
)
|
|
375
|
-
tape.backward(values)
|
|
376
|
-
|
|
377
|
-
grad_expected = np.array([6.0, 15.0, 24.0])
|
|
378
|
-
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
379
|
-
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
380
|
-
|
|
381
|
-
tape = wp.Tape()
|
|
382
|
-
with tape:
|
|
383
|
-
wp.launch(
|
|
384
|
-
test_volume_sample_world_v_linear_values,
|
|
385
|
-
dim=1,
|
|
386
|
-
inputs=[volumes["vec3f"][device.alias].id, xyzs, values],
|
|
387
|
-
device=device,
|
|
388
|
-
)
|
|
389
|
-
tape.backward(values)
|
|
390
|
-
|
|
391
|
-
grad_expected = np.array([6.0, 15.0, 24.0]) / 0.25
|
|
392
|
-
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
393
|
-
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
394
|
-
|
|
395
|
-
def test_volume_transform_gradient(self):
|
|
396
|
-
for device in devices:
|
|
397
|
-
values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
|
|
398
|
-
grad_values = wp.zeros(1, dtype=wp.vec3, device=device)
|
|
399
|
-
points = rng.uniform(-10.0, 10.0, size=(10, 3))
|
|
400
|
-
for case in points:
|
|
401
|
-
points = wp.array(case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
402
|
-
tape = wp.Tape()
|
|
403
|
-
with tape:
|
|
404
|
-
wp.launch(
|
|
405
|
-
test_volume_index_to_world,
|
|
406
|
-
dim=1,
|
|
407
|
-
inputs=[volumes["torus"][device.alias].id, points, values, grad_values],
|
|
408
|
-
device=device,
|
|
409
|
-
)
|
|
410
|
-
tape.backward(values)
|
|
411
|
-
|
|
412
|
-
grad_computed = tape.gradients[points].numpy()
|
|
413
|
-
grad_expected = grad_values.numpy()
|
|
414
|
-
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
415
|
-
|
|
416
|
-
grad_computed = tape.gradients[points].numpy()
|
|
417
|
-
grad_expected = grad_values.numpy()
|
|
418
|
-
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
419
|
-
|
|
420
|
-
def test_volume_store(self):
|
|
421
|
-
values_ref = np.array([x + 100 * y + 10000 * z for x, y, z in point_grid])
|
|
422
|
-
for device in devices:
|
|
423
|
-
points = wp.array(point_grid, dtype=wp.vec3, device=device)
|
|
424
|
-
values = wp.empty(len(point_grid), dtype=wp.float32, device=device)
|
|
425
|
-
wp.launch(
|
|
426
|
-
test_volume_store_f,
|
|
427
|
-
dim=len(point_grid),
|
|
428
|
-
inputs=[volumes["float_write"][device.alias].id, points, values],
|
|
429
|
-
device=device,
|
|
430
|
-
)
|
|
415
|
+
x, y, z = test_case
|
|
416
|
+
grad_expected = np.array([y * z, x * z, x * y]) / 0.25
|
|
417
|
+
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
418
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
431
419
|
|
|
432
|
-
values_res = values.numpy()
|
|
433
|
-
np.testing.assert_equal(values_res, values_ref)
|
|
434
420
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
continue
|
|
421
|
+
def test_volume_sample_grad_linear_f_gradient(test, device):
|
|
422
|
+
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
423
|
+
values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
|
|
424
|
+
for test_case in points:
|
|
425
|
+
uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
426
|
+
xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
442
427
|
|
|
443
|
-
|
|
444
|
-
|
|
428
|
+
for case_num in range(4):
|
|
429
|
+
tape = wp.Tape()
|
|
430
|
+
with tape:
|
|
431
|
+
wp.launch(
|
|
432
|
+
test_volume_sample_grad_local_f_linear_values,
|
|
433
|
+
dim=1,
|
|
434
|
+
inputs=[volumes["float"][device.alias].id, uvws, values, case_num],
|
|
435
|
+
device=device,
|
|
445
436
|
)
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
np.
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
437
|
+
tape.backward(values)
|
|
438
|
+
|
|
439
|
+
x, y, z = test_case
|
|
440
|
+
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
441
|
+
if case_num == 0:
|
|
442
|
+
grad_expected = np.array([y * z, x * z, x * y])
|
|
443
|
+
elif case_num == 1:
|
|
444
|
+
grad_expected = np.array([0.0, z, y])
|
|
445
|
+
elif case_num == 2:
|
|
446
|
+
grad_expected = np.array([z, 0.0, x])
|
|
447
|
+
elif case_num == 3:
|
|
448
|
+
grad_expected = np.array([y, x, 0.0])
|
|
449
|
+
|
|
450
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
451
|
+
tape.zero()
|
|
452
|
+
|
|
453
|
+
for case_num in range(4):
|
|
454
|
+
tape = wp.Tape()
|
|
455
|
+
with tape:
|
|
456
|
+
wp.launch(
|
|
457
|
+
test_volume_sample_grad_world_f_linear_values,
|
|
458
|
+
dim=1,
|
|
459
|
+
inputs=[volumes["float"][device.alias].id, xyzs, values, case_num],
|
|
460
|
+
device=device,
|
|
463
461
|
)
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
np.
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
np.array([
|
|
462
|
+
tape.backward(values)
|
|
463
|
+
|
|
464
|
+
x, y, z = test_case
|
|
465
|
+
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
466
|
+
if case_num == 0:
|
|
467
|
+
grad_expected = np.array([y * z, x * z, x * y]) / 0.25
|
|
468
|
+
elif case_num == 1:
|
|
469
|
+
grad_expected = np.array([0.0, z, y]) / 0.25
|
|
470
|
+
elif case_num == 2:
|
|
471
|
+
grad_expected = np.array([z, 0.0, x]) / 0.25
|
|
472
|
+
elif case_num == 3:
|
|
473
|
+
grad_expected = np.array([y, x, 0.0]) / 0.25
|
|
474
|
+
|
|
475
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
476
|
+
tape.zero()
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def test_volume_sample_linear_v_gradient(test, device):
|
|
480
|
+
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
481
|
+
values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
|
|
482
|
+
for test_case in points:
|
|
483
|
+
uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
484
|
+
xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
485
|
+
|
|
486
|
+
tape = wp.Tape()
|
|
487
|
+
with tape:
|
|
488
|
+
wp.launch(
|
|
489
|
+
test_volume_sample_local_v_linear_values,
|
|
490
|
+
dim=1,
|
|
491
|
+
inputs=[volumes["vec3f"][device.alias].id, uvws, values],
|
|
492
|
+
device=device,
|
|
476
493
|
)
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
494
|
+
tape.backward(values)
|
|
495
|
+
|
|
496
|
+
grad_expected = np.array([6.0, 15.0, 24.0])
|
|
497
|
+
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
498
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
499
|
+
|
|
500
|
+
tape = wp.Tape()
|
|
501
|
+
with tape:
|
|
502
|
+
wp.launch(
|
|
503
|
+
test_volume_sample_world_v_linear_values,
|
|
504
|
+
dim=1,
|
|
505
|
+
inputs=[volumes["vec3f"][device.alias].id, xyzs, values],
|
|
506
|
+
device=device,
|
|
507
|
+
)
|
|
508
|
+
tape.backward(values)
|
|
509
|
+
|
|
510
|
+
grad_expected = np.array([6.0, 15.0, 24.0]) / 0.25
|
|
511
|
+
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
512
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
def test_volume_transform_gradient(test, device):
|
|
516
|
+
values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
|
|
517
|
+
grad_values = wp.zeros(1, dtype=wp.vec3, device=device)
|
|
518
|
+
test_points = rng.uniform(-10.0, 10.0, size=(10, 3))
|
|
519
|
+
for test_case in test_points:
|
|
520
|
+
points = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
521
|
+
tape = wp.Tape()
|
|
522
|
+
with tape:
|
|
523
|
+
wp.launch(
|
|
524
|
+
test_volume_index_to_world,
|
|
525
|
+
dim=1,
|
|
526
|
+
inputs=[volumes["torus"][device.alias].id, points, values, grad_values],
|
|
527
|
+
device=device,
|
|
528
|
+
)
|
|
529
|
+
tape.backward(values)
|
|
530
|
+
|
|
531
|
+
grad_computed = tape.gradients[points].numpy()
|
|
532
|
+
grad_expected = grad_values.numpy()
|
|
533
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
534
|
+
|
|
535
|
+
grad_computed = tape.gradients[points].numpy()
|
|
536
|
+
grad_expected = grad_values.numpy()
|
|
537
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
def test_volume_store(test, device):
|
|
541
|
+
values_ref = np.array([x + 100 * y + 10000 * z for x, y, z in point_grid])
|
|
542
|
+
points = wp.array(point_grid, dtype=wp.vec3, device=device)
|
|
543
|
+
values = wp.empty(len(point_grid), dtype=wp.float32, device=device)
|
|
544
|
+
wp.launch(
|
|
545
|
+
test_volume_store_f,
|
|
546
|
+
dim=len(point_grid),
|
|
547
|
+
inputs=[volumes["float_write"][device.alias].id, points, values],
|
|
548
|
+
device=device,
|
|
549
|
+
)
|
|
490
550
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
551
|
+
values_res = values.numpy()
|
|
552
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def test_volume_allocation_f(test, device):
|
|
556
|
+
bg_value = -123.0
|
|
557
|
+
points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
|
|
558
|
+
values_ref = np.append(np.array([x + 100 * y + 10000 * z for x, y, z in point_grid]), bg_value)
|
|
559
|
+
|
|
560
|
+
volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
|
|
561
|
+
points = wp.array(points_np, dtype=wp.vec3, device=device)
|
|
562
|
+
values = wp.empty(len(points_np), dtype=wp.float32, device=device)
|
|
563
|
+
wp.launch(test_volume_store_f, dim=len(points_np), inputs=[volume.id, points, values], device=device)
|
|
564
|
+
|
|
565
|
+
values_res = values.numpy()
|
|
566
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
def test_volume_allocation_v(test, device):
|
|
570
|
+
bg_value = (-1, 2.0, -3)
|
|
571
|
+
points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
|
|
572
|
+
values_ref = np.append(point_grid, [bg_value], axis=0)
|
|
573
|
+
|
|
574
|
+
volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
|
|
575
|
+
points = wp.array(points_np, dtype=wp.vec3, device=device)
|
|
576
|
+
values = wp.empty(len(points_np), dtype=wp.vec3, device=device)
|
|
577
|
+
wp.launch(test_volume_store_v, dim=len(points_np), inputs=[volume.id, points, values], device=device)
|
|
578
|
+
|
|
579
|
+
values_res = values.numpy()
|
|
580
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
def test_volume_allocation_i(test, device):
|
|
584
|
+
bg_value = -123
|
|
585
|
+
points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
|
|
586
|
+
values_ref = np.append(np.array([x + 100 * y + 10000 * z for x, y, z in point_grid], dtype=np.int32), bg_value)
|
|
587
|
+
|
|
588
|
+
volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
|
|
589
|
+
points = wp.array(points_np, dtype=wp.vec3, device=device)
|
|
590
|
+
values = wp.empty(len(points_np), dtype=wp.int32, device=device)
|
|
591
|
+
wp.launch(test_volume_store_i, dim=len(points_np), inputs=[volume.id, points, values], device=device)
|
|
592
|
+
|
|
593
|
+
values_res = values.numpy()
|
|
594
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
def test_volume_introspection(test, device):
|
|
598
|
+
for volume_names in ("float", "vec3f"):
|
|
599
|
+
with test.subTest(volume_names=volume_names):
|
|
600
|
+
volume = volumes[volume_names][device.alias]
|
|
601
|
+
tiles_actual = volume.get_tiles().numpy()
|
|
602
|
+
tiles_sorted = tiles_actual[np.lexsort(tiles_actual.T[::-1])]
|
|
603
|
+
voxel_size = np.array(volume.get_voxel_size())
|
|
604
|
+
|
|
605
|
+
np.testing.assert_equal(test_volume_tiles, tiles_sorted)
|
|
606
|
+
np.testing.assert_equal([0.25] * 3, voxel_size)
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
def test_volume_from_numpy(test, device):
|
|
610
|
+
# Volume.allocate_from_tiles() is only available with CUDA
|
|
611
|
+
mins = np.array([-3.0, -3.0, -3.0])
|
|
612
|
+
voxel_size = 0.2
|
|
613
|
+
maxs = np.array([3.0, 3.0, 3.0])
|
|
614
|
+
nums = np.ceil((maxs - mins) / (voxel_size)).astype(dtype=int)
|
|
615
|
+
center = np.array([0.0, 0.0, 0.0])
|
|
616
|
+
rad = 2.5
|
|
617
|
+
sphere_sdf_np = np.zeros(tuple(nums))
|
|
618
|
+
for x in range(nums[0]):
|
|
619
|
+
for y in range(nums[1]):
|
|
620
|
+
for z in range(nums[2]):
|
|
621
|
+
pos = mins + voxel_size * np.array([x, y, z])
|
|
622
|
+
dis = np.linalg.norm(pos - center)
|
|
623
|
+
sphere_sdf_np[x, y, z] = dis - rad
|
|
624
|
+
sphere_vdb = wp.Volume.load_from_numpy(sphere_sdf_np, mins, voxel_size, rad + 3.0 * voxel_size, device=device)
|
|
625
|
+
|
|
626
|
+
test.assertNotEqual(sphere_vdb.id, 0)
|
|
627
|
+
|
|
628
|
+
sphere_vdb_array = sphere_vdb.array()
|
|
629
|
+
test.assertEqual(sphere_vdb_array.dtype, wp.uint8)
|
|
630
|
+
test.assertFalse(sphere_vdb_array.owner)
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
class TestVolume(unittest.TestCase):
|
|
634
|
+
pass
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
add_function_test(
|
|
638
|
+
TestVolume, "test_volume_sample_linear_f_gradient", test_volume_sample_linear_f_gradient, devices=devices
|
|
639
|
+
)
|
|
640
|
+
add_function_test(
|
|
641
|
+
TestVolume, "test_volume_sample_grad_linear_f_gradient", test_volume_sample_grad_linear_f_gradient, devices=devices
|
|
642
|
+
)
|
|
643
|
+
add_function_test(
|
|
644
|
+
TestVolume, "test_volume_sample_linear_v_gradient", test_volume_sample_linear_v_gradient, devices=devices
|
|
645
|
+
)
|
|
646
|
+
add_function_test(TestVolume, "test_volume_transform_gradient", test_volume_transform_gradient, devices=devices)
|
|
647
|
+
add_function_test(TestVolume, "test_volume_store", test_volume_store, devices=devices)
|
|
648
|
+
add_function_test(
|
|
649
|
+
TestVolume, "test_volume_allocation_f", test_volume_allocation_f, devices=get_unique_cuda_test_devices()
|
|
650
|
+
)
|
|
651
|
+
add_function_test(
|
|
652
|
+
TestVolume, "test_volume_allocation_v", test_volume_allocation_v, devices=get_unique_cuda_test_devices()
|
|
653
|
+
)
|
|
654
|
+
add_function_test(
|
|
655
|
+
TestVolume, "test_volume_allocation_i", test_volume_allocation_i, devices=get_unique_cuda_test_devices()
|
|
656
|
+
)
|
|
657
|
+
add_function_test(TestVolume, "test_volume_introspection", test_volume_introspection, devices=devices)
|
|
658
|
+
add_function_test(TestVolume, "test_volume_from_numpy", test_volume_from_numpy, devices=get_unique_cuda_test_devices())
|
|
659
|
+
|
|
660
|
+
points = {}
|
|
661
|
+
points_jittered = {}
|
|
662
|
+
for device in devices:
|
|
663
|
+
points_jittered_np = point_grid + rng.uniform(-0.5, 0.5, size=point_grid.shape)
|
|
664
|
+
points[device.alias] = wp.array(point_grid, dtype=wp.vec3, device=device)
|
|
665
|
+
points_jittered[device.alias] = wp.array(points_jittered_np, dtype=wp.vec3, device=device)
|
|
666
|
+
|
|
667
|
+
add_kernel_test(
|
|
668
|
+
TestVolume,
|
|
669
|
+
test_volume_lookup_f,
|
|
670
|
+
dim=len(point_grid),
|
|
671
|
+
inputs=[volumes["float"][device.alias].id, points[device.alias]],
|
|
672
|
+
devices=[device],
|
|
673
|
+
)
|
|
674
|
+
add_kernel_test(
|
|
675
|
+
TestVolume,
|
|
676
|
+
test_volume_sample_closest_f,
|
|
677
|
+
dim=len(point_grid),
|
|
678
|
+
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
679
|
+
devices=[device.alias],
|
|
680
|
+
)
|
|
681
|
+
add_kernel_test(
|
|
682
|
+
TestVolume,
|
|
683
|
+
test_volume_sample_linear_f,
|
|
684
|
+
dim=len(point_grid),
|
|
685
|
+
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
686
|
+
devices=[device.alias],
|
|
687
|
+
)
|
|
688
|
+
add_kernel_test(
|
|
689
|
+
TestVolume,
|
|
690
|
+
test_volume_sample_grad_linear_f,
|
|
691
|
+
dim=len(point_grid),
|
|
692
|
+
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
693
|
+
devices=[device.alias],
|
|
694
|
+
)
|
|
498
695
|
|
|
499
|
-
|
|
500
|
-
|
|
696
|
+
add_kernel_test(
|
|
697
|
+
TestVolume,
|
|
698
|
+
test_volume_lookup_v,
|
|
699
|
+
dim=len(point_grid),
|
|
700
|
+
inputs=[volumes["vec3f"][device.alias].id, points[device.alias]],
|
|
701
|
+
devices=[device.alias],
|
|
702
|
+
)
|
|
703
|
+
add_kernel_test(
|
|
704
|
+
TestVolume,
|
|
705
|
+
test_volume_sample_closest_v,
|
|
706
|
+
dim=len(point_grid),
|
|
707
|
+
inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
|
|
708
|
+
devices=[device.alias],
|
|
709
|
+
)
|
|
710
|
+
add_kernel_test(
|
|
711
|
+
TestVolume,
|
|
712
|
+
test_volume_sample_linear_v,
|
|
713
|
+
dim=len(point_grid),
|
|
714
|
+
inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
|
|
715
|
+
devices=[device.alias],
|
|
716
|
+
)
|
|
501
717
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
test_volume_sample_closest_f,
|
|
517
|
-
dim=len(point_grid),
|
|
518
|
-
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
519
|
-
devices=[device.alias],
|
|
520
|
-
)
|
|
521
|
-
add_kernel_test(
|
|
522
|
-
TestVolumes,
|
|
523
|
-
test_volume_sample_linear_f,
|
|
524
|
-
dim=len(point_grid),
|
|
525
|
-
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
526
|
-
devices=[device.alias],
|
|
527
|
-
)
|
|
528
|
-
|
|
529
|
-
add_kernel_test(
|
|
530
|
-
TestVolumes,
|
|
531
|
-
test_volume_lookup_v,
|
|
532
|
-
dim=len(point_grid),
|
|
533
|
-
inputs=[volumes["vec3f"][device.alias].id, points[device.alias]],
|
|
534
|
-
devices=[device.alias],
|
|
535
|
-
)
|
|
536
|
-
add_kernel_test(
|
|
537
|
-
TestVolumes,
|
|
538
|
-
test_volume_sample_closest_v,
|
|
539
|
-
dim=len(point_grid),
|
|
540
|
-
inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
|
|
541
|
-
devices=[device.alias],
|
|
542
|
-
)
|
|
543
|
-
add_kernel_test(
|
|
544
|
-
TestVolumes,
|
|
545
|
-
test_volume_sample_linear_v,
|
|
546
|
-
dim=len(point_grid),
|
|
547
|
-
inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
|
|
548
|
-
devices=[device.alias],
|
|
549
|
-
)
|
|
550
|
-
|
|
551
|
-
add_kernel_test(
|
|
552
|
-
TestVolumes,
|
|
553
|
-
test_volume_lookup_i,
|
|
554
|
-
dim=len(point_grid),
|
|
555
|
-
inputs=[volumes["int32"][device.alias].id, points[device.alias]],
|
|
556
|
-
devices=[device.alias],
|
|
557
|
-
)
|
|
558
|
-
add_kernel_test(
|
|
559
|
-
TestVolumes,
|
|
560
|
-
test_volume_sample_i,
|
|
561
|
-
dim=len(point_grid),
|
|
562
|
-
inputs=[volumes["int32"][device.alias].id, points_jittered[device.alias]],
|
|
563
|
-
devices=[device.alias],
|
|
564
|
-
)
|
|
565
|
-
|
|
566
|
-
return TestVolumes
|
|
718
|
+
add_kernel_test(
|
|
719
|
+
TestVolume,
|
|
720
|
+
test_volume_lookup_i,
|
|
721
|
+
dim=len(point_grid),
|
|
722
|
+
inputs=[volumes["int32"][device.alias].id, points[device.alias]],
|
|
723
|
+
devices=[device.alias],
|
|
724
|
+
)
|
|
725
|
+
add_kernel_test(
|
|
726
|
+
TestVolume,
|
|
727
|
+
test_volume_sample_i,
|
|
728
|
+
dim=len(point_grid),
|
|
729
|
+
inputs=[volumes["int32"][device.alias].id, points_jittered[device.alias]],
|
|
730
|
+
devices=[device.alias],
|
|
731
|
+
)
|
|
567
732
|
|
|
568
733
|
|
|
569
734
|
if __name__ == "__main__":
|
|
570
|
-
wp.
|
|
571
|
-
c = register(unittest.TestCase)
|
|
735
|
+
wp.build.clear_kernel_cache()
|
|
572
736
|
unittest.main(verbosity=2)
|