warp-lang 1.8.0__py3-none-macosx_10_13_universal2.whl → 1.9.0__py3-none-macosx_10_13_universal2.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 +282 -103
- warp/__init__.pyi +482 -110
- warp/bin/libwarp-clang.dylib +0 -0
- warp/bin/libwarp.dylib +0 -0
- warp/build.py +93 -30
- warp/build_dll.py +48 -63
- warp/builtins.py +955 -137
- warp/codegen.py +327 -209
- warp/config.py +1 -1
- warp/context.py +1363 -800
- warp/examples/core/example_marching_cubes.py +1 -0
- warp/examples/core/example_render_opengl.py +100 -3
- warp/examples/fem/example_apic_fluid.py +98 -52
- warp/examples/fem/example_convection_diffusion_dg.py +25 -4
- warp/examples/fem/example_diffusion_mgpu.py +8 -3
- warp/examples/fem/utils.py +68 -22
- warp/examples/interop/example_jax_callable.py +34 -4
- warp/examples/interop/example_jax_kernel.py +27 -1
- warp/fabric.py +1 -1
- warp/fem/cache.py +27 -19
- warp/fem/domain.py +2 -2
- warp/fem/field/nodal_field.py +2 -2
- warp/fem/field/virtual.py +266 -166
- warp/fem/geometry/geometry.py +5 -5
- warp/fem/integrate.py +200 -91
- warp/fem/space/restriction.py +4 -0
- warp/fem/space/shape/tet_shape_function.py +3 -10
- warp/jax_experimental/custom_call.py +1 -1
- warp/jax_experimental/ffi.py +203 -54
- warp/marching_cubes.py +708 -0
- warp/native/array.h +103 -8
- warp/native/builtin.h +90 -9
- warp/native/bvh.cpp +64 -28
- warp/native/bvh.cu +58 -58
- warp/native/bvh.h +2 -2
- warp/native/clang/clang.cpp +7 -7
- warp/native/coloring.cpp +13 -3
- warp/native/crt.cpp +2 -2
- warp/native/crt.h +3 -5
- warp/native/cuda_util.cpp +42 -11
- warp/native/cuda_util.h +10 -4
- warp/native/exports.h +1842 -1908
- warp/native/fabric.h +2 -1
- warp/native/hashgrid.cpp +37 -37
- warp/native/hashgrid.cu +2 -2
- warp/native/initializer_array.h +1 -1
- warp/native/intersect.h +4 -4
- warp/native/mat.h +1913 -119
- warp/native/mathdx.cpp +43 -43
- warp/native/mesh.cpp +24 -24
- warp/native/mesh.cu +26 -26
- warp/native/mesh.h +5 -3
- warp/native/nanovdb/GridHandle.h +179 -12
- warp/native/nanovdb/HostBuffer.h +8 -7
- warp/native/nanovdb/NanoVDB.h +517 -895
- warp/native/nanovdb/NodeManager.h +323 -0
- warp/native/nanovdb/PNanoVDB.h +2 -2
- warp/native/quat.h +337 -16
- warp/native/rand.h +7 -7
- warp/native/range.h +7 -1
- warp/native/reduce.cpp +10 -10
- warp/native/reduce.cu +13 -14
- warp/native/runlength_encode.cpp +2 -2
- warp/native/runlength_encode.cu +5 -5
- warp/native/scan.cpp +3 -3
- warp/native/scan.cu +4 -4
- warp/native/sort.cpp +10 -10
- warp/native/sort.cu +22 -22
- warp/native/sparse.cpp +8 -8
- warp/native/sparse.cu +14 -14
- warp/native/spatial.h +366 -17
- warp/native/svd.h +23 -8
- warp/native/temp_buffer.h +2 -2
- warp/native/tile.h +303 -70
- warp/native/tile_radix_sort.h +5 -1
- warp/native/tile_reduce.h +16 -25
- warp/native/tuple.h +2 -2
- warp/native/vec.h +385 -18
- warp/native/volume.cpp +54 -54
- warp/native/volume.cu +1 -1
- warp/native/volume.h +2 -1
- warp/native/volume_builder.cu +30 -37
- warp/native/warp.cpp +150 -149
- warp/native/warp.cu +337 -193
- warp/native/warp.h +227 -226
- warp/optim/linear.py +736 -271
- warp/render/imgui_manager.py +289 -0
- warp/render/render_opengl.py +137 -57
- warp/render/render_usd.py +0 -1
- warp/sim/collide.py +1 -2
- warp/sim/graph_coloring.py +2 -2
- warp/sim/integrator_vbd.py +10 -2
- warp/sparse.py +559 -176
- warp/tape.py +2 -0
- warp/tests/aux_test_module_aot.py +7 -0
- warp/tests/cuda/test_async.py +3 -3
- warp/tests/cuda/test_conditional_captures.py +101 -0
- warp/tests/geometry/test_marching_cubes.py +233 -12
- warp/tests/sim/test_cloth.py +89 -6
- warp/tests/sim/test_coloring.py +82 -7
- warp/tests/test_array.py +56 -5
- warp/tests/test_assert.py +53 -0
- warp/tests/test_atomic_cas.py +127 -114
- warp/tests/test_codegen.py +3 -2
- warp/tests/test_context.py +8 -15
- warp/tests/test_enum.py +136 -0
- warp/tests/test_examples.py +2 -2
- warp/tests/test_fem.py +45 -2
- warp/tests/test_fixedarray.py +229 -0
- warp/tests/test_func.py +18 -15
- warp/tests/test_future_annotations.py +7 -5
- warp/tests/test_linear_solvers.py +30 -0
- warp/tests/test_map.py +1 -1
- warp/tests/test_mat.py +1540 -378
- warp/tests/test_mat_assign_copy.py +178 -0
- warp/tests/test_mat_constructors.py +574 -0
- warp/tests/test_module_aot.py +287 -0
- warp/tests/test_print.py +69 -0
- warp/tests/test_quat.py +162 -34
- warp/tests/test_quat_assign_copy.py +145 -0
- warp/tests/test_reload.py +2 -1
- warp/tests/test_sparse.py +103 -0
- warp/tests/test_spatial.py +140 -34
- warp/tests/test_spatial_assign_copy.py +160 -0
- warp/tests/test_static.py +48 -0
- warp/tests/test_struct.py +43 -3
- warp/tests/test_tape.py +38 -0
- warp/tests/test_types.py +0 -20
- warp/tests/test_vec.py +216 -441
- warp/tests/test_vec_assign_copy.py +143 -0
- warp/tests/test_vec_constructors.py +325 -0
- warp/tests/tile/test_tile.py +206 -152
- warp/tests/tile/test_tile_cholesky.py +605 -0
- warp/tests/tile/test_tile_load.py +169 -0
- warp/tests/tile/test_tile_mathdx.py +2 -558
- warp/tests/tile/test_tile_matmul.py +179 -0
- warp/tests/tile/test_tile_mlp.py +1 -1
- warp/tests/tile/test_tile_reduce.py +100 -11
- warp/tests/tile/test_tile_shared_memory.py +16 -16
- warp/tests/tile/test_tile_sort.py +59 -55
- warp/tests/unittest_suites.py +16 -0
- warp/tests/walkthrough_debug.py +1 -1
- warp/thirdparty/unittest_parallel.py +108 -9
- warp/types.py +554 -264
- warp/utils.py +68 -86
- {warp_lang-1.8.0.dist-info → warp_lang-1.9.0.dist-info}/METADATA +28 -65
- {warp_lang-1.8.0.dist-info → warp_lang-1.9.0.dist-info}/RECORD +150 -138
- warp/native/marching.cpp +0 -19
- warp/native/marching.cu +0 -514
- warp/native/marching.h +0 -19
- {warp_lang-1.8.0.dist-info → warp_lang-1.9.0.dist-info}/WHEEL +0 -0
- {warp_lang-1.8.0.dist-info → warp_lang-1.9.0.dist-info}/licenses/LICENSE.md +0 -0
- {warp_lang-1.8.0.dist-info → warp_lang-1.9.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
import unittest
|
|
17
|
+
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
import warp as wp
|
|
21
|
+
from warp.tests.unittest_utils import *
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def setUpModule():
|
|
25
|
+
wp.config.enable_vector_component_overwrites = True
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def tearDownModule():
|
|
29
|
+
wp.config.enable_vector_component_overwrites = False
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@wp.kernel
|
|
33
|
+
def vec_assign_subscript(x: wp.array(dtype=float), y: wp.array(dtype=wp.vec3)):
|
|
34
|
+
i = wp.tid()
|
|
35
|
+
|
|
36
|
+
a = wp.vec3()
|
|
37
|
+
a[0] = 1.0 * x[i]
|
|
38
|
+
a[1] = 2.0 * x[i]
|
|
39
|
+
a[2] = 3.0 * x[i]
|
|
40
|
+
y[i] = a
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@wp.kernel
|
|
44
|
+
def vec_assign_attribute(x: wp.array(dtype=float), y: wp.array(dtype=wp.vec3)):
|
|
45
|
+
i = wp.tid()
|
|
46
|
+
|
|
47
|
+
a = wp.vec3()
|
|
48
|
+
a.x = 1.0 * x[i]
|
|
49
|
+
a.y = 2.0 * x[i]
|
|
50
|
+
a.z = 3.0 * x[i]
|
|
51
|
+
y[i] = a
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_vec_assign(test, device):
|
|
55
|
+
def run(kernel):
|
|
56
|
+
x = wp.ones(1, dtype=float, requires_grad=True, device=device)
|
|
57
|
+
y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
58
|
+
|
|
59
|
+
tape = wp.Tape()
|
|
60
|
+
with tape:
|
|
61
|
+
wp.launch(kernel, 1, inputs=[x], outputs=[y], device=device)
|
|
62
|
+
|
|
63
|
+
y.grad = wp.ones_like(y)
|
|
64
|
+
tape.backward()
|
|
65
|
+
|
|
66
|
+
assert_np_equal(y.numpy(), np.array([[1.0, 2.0, 3.0]], dtype=float))
|
|
67
|
+
assert_np_equal(x.grad.numpy(), np.array([6.0], dtype=float))
|
|
68
|
+
|
|
69
|
+
run(vec_assign_subscript)
|
|
70
|
+
run(vec_assign_attribute)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_vec_assign_copy(test, device):
|
|
74
|
+
@wp.kernel(module="unique")
|
|
75
|
+
def vec_assign_overwrite(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
76
|
+
tid = wp.tid()
|
|
77
|
+
|
|
78
|
+
a = wp.vec3()
|
|
79
|
+
b = x[tid]
|
|
80
|
+
a = b
|
|
81
|
+
a[1] = 3.0
|
|
82
|
+
|
|
83
|
+
y[tid] = a
|
|
84
|
+
|
|
85
|
+
x = wp.ones(1, dtype=wp.vec3, device=device, requires_grad=True)
|
|
86
|
+
y = wp.zeros(1, dtype=wp.vec3, device=device, requires_grad=True)
|
|
87
|
+
|
|
88
|
+
tape = wp.Tape()
|
|
89
|
+
with tape:
|
|
90
|
+
wp.launch(vec_assign_overwrite, dim=1, inputs=[x, y], device=device)
|
|
91
|
+
|
|
92
|
+
y.grad = wp.ones_like(y, requires_grad=False)
|
|
93
|
+
tape.backward()
|
|
94
|
+
|
|
95
|
+
assert_np_equal(y.numpy(), np.array([[1.0, 3.0, 1.0]], dtype=float))
|
|
96
|
+
assert_np_equal(x.grad.numpy(), np.array([[1.0, 0.0, 1.0]], dtype=float))
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_vec_slicing_assign_backward(test, device):
|
|
100
|
+
@wp.kernel(module="unique")
|
|
101
|
+
def kernel(arr_x: wp.array(dtype=wp.vec2), arr_y: wp.array(dtype=wp.vec4)):
|
|
102
|
+
i = wp.tid()
|
|
103
|
+
|
|
104
|
+
x = arr_x[i]
|
|
105
|
+
y = arr_y[i]
|
|
106
|
+
|
|
107
|
+
y[:2] = x
|
|
108
|
+
y[1:-1] += x[:2]
|
|
109
|
+
y[3:1:-1] -= x[0:]
|
|
110
|
+
|
|
111
|
+
arr_y[i] = y
|
|
112
|
+
|
|
113
|
+
x = wp.ones(1, dtype=wp.vec2, requires_grad=True, device=device)
|
|
114
|
+
y = wp.zeros(1, dtype=wp.vec4, requires_grad=True, device=device)
|
|
115
|
+
|
|
116
|
+
tape = wp.Tape()
|
|
117
|
+
with tape:
|
|
118
|
+
wp.launch(kernel, 1, inputs=(x,), outputs=(y,), device=device)
|
|
119
|
+
|
|
120
|
+
y.grad = wp.ones_like(y)
|
|
121
|
+
tape.backward()
|
|
122
|
+
|
|
123
|
+
assert_np_equal(y.numpy(), np.array(((1.0, 2.0, 0.0, -1.0),), dtype=float))
|
|
124
|
+
assert_np_equal(x.grad.numpy(), np.array(((1.0, 1.0),), dtype=float))
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
devices = get_test_devices()
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class TestVecAssignCopy(unittest.TestCase):
|
|
131
|
+
pass
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
add_function_test(TestVecAssignCopy, "test_vec_assign", test_vec_assign, devices=devices)
|
|
135
|
+
add_function_test(TestVecAssignCopy, "test_vec_assign_copy", test_vec_assign_copy, devices=devices)
|
|
136
|
+
add_function_test(
|
|
137
|
+
TestVecAssignCopy, "test_vec_slicing_assign_backward", test_vec_slicing_assign_backward, devices=devices
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
if __name__ == "__main__":
|
|
142
|
+
wp.clear_kernel_cache()
|
|
143
|
+
unittest.main(verbosity=2, failfast=True)
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
import unittest
|
|
17
|
+
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
import warp as wp
|
|
21
|
+
from warp.tests.unittest_utils import *
|
|
22
|
+
|
|
23
|
+
np_float_types = [np.float16, np.float32, np.float64]
|
|
24
|
+
|
|
25
|
+
kernel_cache = {}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def getkernel(func, suffix=""):
|
|
29
|
+
key = func.__name__ + "_" + suffix
|
|
30
|
+
if key not in kernel_cache:
|
|
31
|
+
kernel_cache[key] = wp.Kernel(func=func, key=key)
|
|
32
|
+
return kernel_cache[key]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_anon_constructor_error_length_mismatch(test, device):
|
|
36
|
+
@wp.kernel
|
|
37
|
+
def kernel():
|
|
38
|
+
wp.vector(wp.vector(length=2, dtype=float), length=3, dtype=float)
|
|
39
|
+
|
|
40
|
+
with test.assertRaisesRegex(
|
|
41
|
+
RuntimeError,
|
|
42
|
+
r"incompatible vector of length 3 given when copy constructing a vector of length 2$",
|
|
43
|
+
):
|
|
44
|
+
wp.launch(kernel, dim=1, inputs=[], device=device)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_anon_constructor_error_numeric_arg_missing(test, device):
|
|
48
|
+
@wp.kernel
|
|
49
|
+
def kernel():
|
|
50
|
+
wp.vector(1.0, 2.0, length=12345)
|
|
51
|
+
|
|
52
|
+
with test.assertRaisesRegex(
|
|
53
|
+
RuntimeError,
|
|
54
|
+
r"incompatible number of values given \(2\) when constructing a vector of length 12345$",
|
|
55
|
+
):
|
|
56
|
+
wp.launch(kernel, dim=1, inputs=[], device=device)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_anon_constructor_error_length_arg_missing(test, device):
|
|
60
|
+
@wp.kernel
|
|
61
|
+
def kernel():
|
|
62
|
+
wp.vector()
|
|
63
|
+
|
|
64
|
+
with test.assertRaisesRegex(
|
|
65
|
+
RuntimeError,
|
|
66
|
+
r"the `length` argument must be specified when zero-initializing a vector$",
|
|
67
|
+
):
|
|
68
|
+
wp.launch(kernel, dim=1, inputs=[], device=device)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_anon_constructor_error_numeric_args_mismatch(test, device):
|
|
72
|
+
@wp.kernel
|
|
73
|
+
def kernel():
|
|
74
|
+
wp.vector(1.0, 2)
|
|
75
|
+
|
|
76
|
+
with test.assertRaisesRegex(
|
|
77
|
+
RuntimeError,
|
|
78
|
+
r"all values given when constructing a vector must have the same type$",
|
|
79
|
+
):
|
|
80
|
+
wp.launch(kernel, dim=1, inputs=[], device=device)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_tpl_constructor_error_incompatible_sizes(test, device):
|
|
84
|
+
@wp.kernel
|
|
85
|
+
def kernel():
|
|
86
|
+
wp.vec3(wp.vec2(1.0, 2.0))
|
|
87
|
+
|
|
88
|
+
with test.assertRaisesRegex(
|
|
89
|
+
RuntimeError, "incompatible vector of length 3 given when copy constructing a vector of length 2"
|
|
90
|
+
):
|
|
91
|
+
wp.launch(kernel, dim=1, inputs=[], device=device)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_tpl_constructor_error_numeric_args_mismatch(test, device):
|
|
95
|
+
@wp.kernel
|
|
96
|
+
def kernel():
|
|
97
|
+
wp.vec2(1.0, 2)
|
|
98
|
+
|
|
99
|
+
with test.assertRaisesRegex(
|
|
100
|
+
RuntimeError,
|
|
101
|
+
r"all values given when constructing a vector must have the same type$",
|
|
102
|
+
):
|
|
103
|
+
wp.launch(kernel, dim=1, inputs=[], device=device)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_casting_constructors(test, device, dtype, register_kernels=False):
|
|
107
|
+
np_type = np.dtype(dtype)
|
|
108
|
+
wp_type = wp.types.np_dtype_to_warp_type[np_type]
|
|
109
|
+
vec3 = wp.types.vector(length=3, dtype=wp_type)
|
|
110
|
+
|
|
111
|
+
np16 = np.dtype(np.float16)
|
|
112
|
+
wp16 = wp.types.np_dtype_to_warp_type[np16]
|
|
113
|
+
|
|
114
|
+
np32 = np.dtype(np.float32)
|
|
115
|
+
wp32 = wp.types.np_dtype_to_warp_type[np32]
|
|
116
|
+
|
|
117
|
+
np64 = np.dtype(np.float64)
|
|
118
|
+
wp64 = wp.types.np_dtype_to_warp_type[np64]
|
|
119
|
+
|
|
120
|
+
def cast_float16(a: wp.array(dtype=wp_type, ndim=2), b: wp.array(dtype=wp16, ndim=2)):
|
|
121
|
+
tid = wp.tid()
|
|
122
|
+
|
|
123
|
+
v1 = vec3(a[tid, 0], a[tid, 1], a[tid, 2])
|
|
124
|
+
v2 = wp.vector(v1, dtype=wp16)
|
|
125
|
+
|
|
126
|
+
b[tid, 0] = v2[0]
|
|
127
|
+
b[tid, 1] = v2[1]
|
|
128
|
+
b[tid, 2] = v2[2]
|
|
129
|
+
|
|
130
|
+
def cast_float32(a: wp.array(dtype=wp_type, ndim=2), b: wp.array(dtype=wp32, ndim=2)):
|
|
131
|
+
tid = wp.tid()
|
|
132
|
+
|
|
133
|
+
v1 = vec3(a[tid, 0], a[tid, 1], a[tid, 2])
|
|
134
|
+
v2 = wp.vector(v1, dtype=wp32)
|
|
135
|
+
|
|
136
|
+
b[tid, 0] = v2[0]
|
|
137
|
+
b[tid, 1] = v2[1]
|
|
138
|
+
b[tid, 2] = v2[2]
|
|
139
|
+
|
|
140
|
+
def cast_float64(a: wp.array(dtype=wp_type, ndim=2), b: wp.array(dtype=wp64, ndim=2)):
|
|
141
|
+
tid = wp.tid()
|
|
142
|
+
|
|
143
|
+
v1 = vec3(a[tid, 0], a[tid, 1], a[tid, 2])
|
|
144
|
+
v2 = wp.vector(v1, dtype=wp64)
|
|
145
|
+
|
|
146
|
+
b[tid, 0] = v2[0]
|
|
147
|
+
b[tid, 1] = v2[1]
|
|
148
|
+
b[tid, 2] = v2[2]
|
|
149
|
+
|
|
150
|
+
kernel_16 = getkernel(cast_float16, suffix=dtype.__name__)
|
|
151
|
+
kernel_32 = getkernel(cast_float32, suffix=dtype.__name__)
|
|
152
|
+
kernel_64 = getkernel(cast_float64, suffix=dtype.__name__)
|
|
153
|
+
|
|
154
|
+
if register_kernels:
|
|
155
|
+
return
|
|
156
|
+
|
|
157
|
+
# check casting to float 16
|
|
158
|
+
a = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, requires_grad=True, device=device)
|
|
159
|
+
b = wp.array(np.zeros((1, 3), dtype=np16), dtype=wp16, requires_grad=True, device=device)
|
|
160
|
+
b_result = np.ones((1, 3), dtype=np16)
|
|
161
|
+
b_grad = wp.array(np.ones((1, 3), dtype=np16), dtype=wp16, device=device)
|
|
162
|
+
a_grad = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, device=device)
|
|
163
|
+
|
|
164
|
+
tape = wp.Tape()
|
|
165
|
+
with tape:
|
|
166
|
+
wp.launch(kernel=kernel_16, dim=1, inputs=[a, b], device=device)
|
|
167
|
+
|
|
168
|
+
tape.backward(grads={b: b_grad})
|
|
169
|
+
out = tape.gradients[a].numpy()
|
|
170
|
+
|
|
171
|
+
assert_np_equal(b.numpy(), b_result)
|
|
172
|
+
assert_np_equal(out, a_grad.numpy())
|
|
173
|
+
|
|
174
|
+
# check casting to float 32
|
|
175
|
+
a = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, requires_grad=True, device=device)
|
|
176
|
+
b = wp.array(np.zeros((1, 3), dtype=np32), dtype=wp32, requires_grad=True, device=device)
|
|
177
|
+
b_result = np.ones((1, 3), dtype=np32)
|
|
178
|
+
b_grad = wp.array(np.ones((1, 3), dtype=np32), dtype=wp32, device=device)
|
|
179
|
+
a_grad = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, device=device)
|
|
180
|
+
|
|
181
|
+
tape = wp.Tape()
|
|
182
|
+
with tape:
|
|
183
|
+
wp.launch(kernel=kernel_32, dim=1, inputs=[a, b], device=device)
|
|
184
|
+
|
|
185
|
+
tape.backward(grads={b: b_grad})
|
|
186
|
+
out = tape.gradients[a].numpy()
|
|
187
|
+
|
|
188
|
+
assert_np_equal(b.numpy(), b_result)
|
|
189
|
+
assert_np_equal(out, a_grad.numpy())
|
|
190
|
+
|
|
191
|
+
# check casting to float 64
|
|
192
|
+
a = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, requires_grad=True, device=device)
|
|
193
|
+
b = wp.array(np.zeros((1, 3), dtype=np64), dtype=wp64, requires_grad=True, device=device)
|
|
194
|
+
b_result = np.ones((1, 3), dtype=np64)
|
|
195
|
+
b_grad = wp.array(np.ones((1, 3), dtype=np64), dtype=wp64, device=device)
|
|
196
|
+
a_grad = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, device=device)
|
|
197
|
+
|
|
198
|
+
tape = wp.Tape()
|
|
199
|
+
with tape:
|
|
200
|
+
wp.launch(kernel=kernel_64, dim=1, inputs=[a, b], device=device)
|
|
201
|
+
|
|
202
|
+
tape.backward(grads={b: b_grad})
|
|
203
|
+
out = tape.gradients[a].numpy()
|
|
204
|
+
|
|
205
|
+
assert_np_equal(b.numpy(), b_result)
|
|
206
|
+
assert_np_equal(out, a_grad.numpy())
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
@wp.kernel
|
|
210
|
+
def test_vector_constructors_value_func():
|
|
211
|
+
a = wp.vec2()
|
|
212
|
+
b = wp.vector(a, dtype=wp.float16)
|
|
213
|
+
c = wp.vector(a)
|
|
214
|
+
d = wp.vector(a, length=2)
|
|
215
|
+
e = wp.vector(1.0, 2.0, 3.0, dtype=float)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
# Test matrix constructors using explicit type (float16)
|
|
219
|
+
# note that these tests are specifically not using generics / closure
|
|
220
|
+
# args to create kernels dynamically (like the rest of this file)
|
|
221
|
+
# as those use different code paths to resolve arg types which
|
|
222
|
+
# has lead to regressions.
|
|
223
|
+
@wp.kernel
|
|
224
|
+
def test_vector_constructors_explicit_precision():
|
|
225
|
+
# construction for custom matrix types
|
|
226
|
+
ones = wp.vector(wp.float16(1.0), length=2)
|
|
227
|
+
zeros = wp.vector(length=2, dtype=wp.float16)
|
|
228
|
+
custom = wp.vector(wp.float16(0.0), wp.float16(1.0))
|
|
229
|
+
|
|
230
|
+
for i in range(2):
|
|
231
|
+
wp.expect_eq(ones[i], wp.float16(1.0))
|
|
232
|
+
wp.expect_eq(zeros[i], wp.float16(0.0))
|
|
233
|
+
wp.expect_eq(custom[i], wp.float16(i))
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
# Same as above but with a default (float/int) type
|
|
237
|
+
# which tests some different code paths that
|
|
238
|
+
# need to ensure types are correctly canonicalized
|
|
239
|
+
# during codegen
|
|
240
|
+
@wp.kernel
|
|
241
|
+
def test_vector_constructors_default_precision():
|
|
242
|
+
# construction for custom matrix types
|
|
243
|
+
ones = wp.vector(1.0, length=2)
|
|
244
|
+
zeros = wp.vector(length=2, dtype=float)
|
|
245
|
+
custom = wp.vector(0.0, 1.0)
|
|
246
|
+
|
|
247
|
+
for i in range(2):
|
|
248
|
+
wp.expect_eq(ones[i], 1.0)
|
|
249
|
+
wp.expect_eq(zeros[i], 0.0)
|
|
250
|
+
wp.expect_eq(custom[i], float(i))
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
CONSTANT_LENGTH = wp.constant(10)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
# tests that we can use global constants in length keyword argument
|
|
257
|
+
# for vector constructor
|
|
258
|
+
@wp.kernel
|
|
259
|
+
def test_vector_constructors_constant_length():
|
|
260
|
+
v = wp.vector(length=(CONSTANT_LENGTH), dtype=float)
|
|
261
|
+
|
|
262
|
+
for i in range(CONSTANT_LENGTH):
|
|
263
|
+
v[i] = float(i)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
devices = get_test_devices()
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
class TestVecConstructors(unittest.TestCase):
|
|
270
|
+
pass
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
add_function_test(
|
|
274
|
+
TestVecConstructors,
|
|
275
|
+
"test_anon_constructor_error_length_mismatch",
|
|
276
|
+
test_anon_constructor_error_length_mismatch,
|
|
277
|
+
devices=devices,
|
|
278
|
+
)
|
|
279
|
+
add_function_test(
|
|
280
|
+
TestVecConstructors,
|
|
281
|
+
"test_anon_constructor_error_numeric_arg_missing",
|
|
282
|
+
test_anon_constructor_error_numeric_arg_missing,
|
|
283
|
+
devices=devices,
|
|
284
|
+
)
|
|
285
|
+
add_function_test(
|
|
286
|
+
TestVecConstructors,
|
|
287
|
+
"test_anon_constructor_error_length_arg_missing",
|
|
288
|
+
test_anon_constructor_error_length_arg_missing,
|
|
289
|
+
devices=devices,
|
|
290
|
+
)
|
|
291
|
+
add_function_test(
|
|
292
|
+
TestVecConstructors,
|
|
293
|
+
"test_anon_constructor_error_numeric_args_mismatch",
|
|
294
|
+
test_anon_constructor_error_numeric_args_mismatch,
|
|
295
|
+
devices=devices,
|
|
296
|
+
)
|
|
297
|
+
add_function_test(
|
|
298
|
+
TestVecConstructors,
|
|
299
|
+
"test_tpl_constructor_error_incompatible_sizes",
|
|
300
|
+
test_tpl_constructor_error_incompatible_sizes,
|
|
301
|
+
devices=devices,
|
|
302
|
+
)
|
|
303
|
+
add_function_test(
|
|
304
|
+
TestVecConstructors,
|
|
305
|
+
"test_tpl_constructor_error_numeric_args_mismatch",
|
|
306
|
+
test_tpl_constructor_error_numeric_args_mismatch,
|
|
307
|
+
devices=devices,
|
|
308
|
+
)
|
|
309
|
+
add_kernel_test(TestVecConstructors, test_vector_constructors_value_func, dim=1, devices=devices)
|
|
310
|
+
add_kernel_test(TestVecConstructors, test_vector_constructors_explicit_precision, dim=1, devices=devices)
|
|
311
|
+
add_kernel_test(TestVecConstructors, test_vector_constructors_default_precision, dim=1, devices=devices)
|
|
312
|
+
add_kernel_test(TestVecConstructors, test_vector_constructors_constant_length, dim=1, devices=devices)
|
|
313
|
+
|
|
314
|
+
for dtype in np_float_types:
|
|
315
|
+
add_function_test_register_kernel(
|
|
316
|
+
TestVecConstructors,
|
|
317
|
+
f"test_casting_constructors_{dtype.__name__}",
|
|
318
|
+
test_casting_constructors,
|
|
319
|
+
devices=devices,
|
|
320
|
+
dtype=dtype,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
if __name__ == "__main__":
|
|
324
|
+
wp.clear_kernel_cache()
|
|
325
|
+
unittest.main(verbosity=2, failfast=True)
|