warp-lang 1.1.0__py3-none-manylinux2014_x86_64.whl → 1.2.1__py3-none-manylinux2014_x86_64.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.

Files changed (218) hide show
  1. warp/bin/warp-clang.so +0 -0
  2. warp/bin/warp.so +0 -0
  3. warp/build.py +10 -37
  4. warp/build_dll.py +2 -2
  5. warp/builtins.py +274 -6
  6. warp/codegen.py +51 -4
  7. warp/config.py +2 -2
  8. warp/constants.py +4 -0
  9. warp/context.py +422 -203
  10. warp/examples/benchmarks/benchmark_api.py +0 -2
  11. warp/examples/benchmarks/benchmark_cloth_warp.py +0 -1
  12. warp/examples/benchmarks/benchmark_launches.py +0 -2
  13. warp/examples/core/example_dem.py +0 -2
  14. warp/examples/core/example_fluid.py +0 -2
  15. warp/examples/core/example_graph_capture.py +0 -2
  16. warp/examples/core/example_marching_cubes.py +0 -2
  17. warp/examples/core/example_mesh.py +0 -2
  18. warp/examples/core/example_mesh_intersect.py +0 -2
  19. warp/examples/core/example_nvdb.py +0 -2
  20. warp/examples/core/example_raycast.py +0 -2
  21. warp/examples/core/example_raymarch.py +0 -2
  22. warp/examples/core/example_render_opengl.py +0 -2
  23. warp/examples/core/example_sph.py +0 -2
  24. warp/examples/core/example_torch.py +0 -3
  25. warp/examples/core/example_wave.py +0 -2
  26. warp/examples/fem/example_apic_fluid.py +140 -115
  27. warp/examples/fem/example_burgers.py +262 -0
  28. warp/examples/fem/example_convection_diffusion.py +0 -2
  29. warp/examples/fem/example_convection_diffusion_dg.py +0 -2
  30. warp/examples/fem/example_deformed_geometry.py +0 -2
  31. warp/examples/fem/example_diffusion.py +0 -2
  32. warp/examples/fem/example_diffusion_3d.py +5 -4
  33. warp/examples/fem/example_diffusion_mgpu.py +0 -2
  34. warp/examples/fem/example_mixed_elasticity.py +0 -2
  35. warp/examples/fem/example_navier_stokes.py +0 -2
  36. warp/examples/fem/example_stokes.py +0 -2
  37. warp/examples/fem/example_stokes_transfer.py +0 -2
  38. warp/examples/optim/example_bounce.py +0 -2
  39. warp/examples/optim/example_cloth_throw.py +0 -2
  40. warp/examples/optim/example_diffray.py +0 -2
  41. warp/examples/optim/example_drone.py +0 -2
  42. warp/examples/optim/example_inverse_kinematics.py +0 -2
  43. warp/examples/optim/example_inverse_kinematics_torch.py +0 -2
  44. warp/examples/optim/example_spring_cage.py +0 -2
  45. warp/examples/optim/example_trajectory.py +0 -2
  46. warp/examples/optim/example_walker.py +0 -2
  47. warp/examples/sim/example_cartpole.py +0 -2
  48. warp/examples/sim/example_cloth.py +0 -2
  49. warp/examples/sim/example_granular.py +0 -2
  50. warp/examples/sim/example_granular_collision_sdf.py +0 -2
  51. warp/examples/sim/example_jacobian_ik.py +0 -2
  52. warp/examples/sim/example_particle_chain.py +0 -2
  53. warp/examples/sim/example_quadruped.py +0 -2
  54. warp/examples/sim/example_rigid_chain.py +0 -2
  55. warp/examples/sim/example_rigid_contact.py +0 -2
  56. warp/examples/sim/example_rigid_force.py +0 -2
  57. warp/examples/sim/example_rigid_gyroscopic.py +0 -2
  58. warp/examples/sim/example_rigid_soft_contact.py +0 -2
  59. warp/examples/sim/example_soft_body.py +0 -2
  60. warp/fem/__init__.py +1 -0
  61. warp/fem/cache.py +3 -1
  62. warp/fem/geometry/__init__.py +1 -0
  63. warp/fem/geometry/element.py +4 -0
  64. warp/fem/geometry/grid_3d.py +0 -4
  65. warp/fem/geometry/nanogrid.py +455 -0
  66. warp/fem/integrate.py +63 -9
  67. warp/fem/space/__init__.py +43 -158
  68. warp/fem/space/basis_space.py +34 -0
  69. warp/fem/space/collocated_function_space.py +1 -1
  70. warp/fem/space/grid_2d_function_space.py +13 -132
  71. warp/fem/space/grid_3d_function_space.py +16 -154
  72. warp/fem/space/hexmesh_function_space.py +37 -134
  73. warp/fem/space/nanogrid_function_space.py +202 -0
  74. warp/fem/space/quadmesh_2d_function_space.py +12 -119
  75. warp/fem/space/restriction.py +4 -1
  76. warp/fem/space/shape/__init__.py +77 -0
  77. warp/fem/space/shape/cube_shape_function.py +5 -15
  78. warp/fem/space/tetmesh_function_space.py +6 -76
  79. warp/fem/space/trimesh_2d_function_space.py +6 -76
  80. warp/native/array.h +12 -3
  81. warp/native/builtin.h +48 -5
  82. warp/native/bvh.cpp +14 -10
  83. warp/native/bvh.cu +23 -15
  84. warp/native/bvh.h +1 -0
  85. warp/native/clang/clang.cpp +2 -1
  86. warp/native/crt.cpp +11 -1
  87. warp/native/crt.h +18 -1
  88. warp/native/exports.h +187 -0
  89. warp/native/mat.h +47 -0
  90. warp/native/mesh.cpp +1 -1
  91. warp/native/mesh.cu +1 -2
  92. warp/native/nanovdb/GridHandle.h +366 -0
  93. warp/native/nanovdb/HostBuffer.h +590 -0
  94. warp/native/nanovdb/NanoVDB.h +3999 -2157
  95. warp/native/nanovdb/PNanoVDB.h +936 -99
  96. warp/native/quat.h +28 -1
  97. warp/native/rand.h +5 -1
  98. warp/native/vec.h +45 -1
  99. warp/native/volume.cpp +335 -103
  100. warp/native/volume.cu +39 -13
  101. warp/native/volume.h +725 -303
  102. warp/native/volume_builder.cu +381 -360
  103. warp/native/volume_builder.h +16 -1
  104. warp/native/volume_impl.h +61 -0
  105. warp/native/warp.cu +8 -2
  106. warp/native/warp.h +15 -7
  107. warp/render/render_opengl.py +191 -52
  108. warp/sim/integrator_featherstone.py +10 -3
  109. warp/sim/integrator_xpbd.py +16 -22
  110. warp/sparse.py +89 -27
  111. warp/stubs.py +83 -0
  112. warp/tests/assets/test_index_grid.nvdb +0 -0
  113. warp/tests/aux_test_dependent.py +0 -2
  114. warp/tests/aux_test_grad_customs.py +0 -2
  115. warp/tests/aux_test_reference.py +0 -2
  116. warp/tests/aux_test_reference_reference.py +0 -2
  117. warp/tests/aux_test_square.py +0 -2
  118. warp/tests/disabled_kinematics.py +0 -2
  119. warp/tests/test_adam.py +0 -2
  120. warp/tests/test_arithmetic.py +0 -36
  121. warp/tests/test_array.py +9 -11
  122. warp/tests/test_array_reduce.py +0 -2
  123. warp/tests/test_async.py +0 -2
  124. warp/tests/test_atomic.py +0 -2
  125. warp/tests/test_bool.py +58 -50
  126. warp/tests/test_builtins_resolution.py +0 -2
  127. warp/tests/test_bvh.py +0 -2
  128. warp/tests/test_closest_point_edge_edge.py +0 -1
  129. warp/tests/test_codegen.py +0 -4
  130. warp/tests/test_compile_consts.py +130 -10
  131. warp/tests/test_conditional.py +0 -2
  132. warp/tests/test_copy.py +0 -2
  133. warp/tests/test_ctypes.py +6 -8
  134. warp/tests/test_dense.py +0 -2
  135. warp/tests/test_devices.py +0 -2
  136. warp/tests/test_dlpack.py +9 -11
  137. warp/tests/test_examples.py +42 -39
  138. warp/tests/test_fabricarray.py +0 -3
  139. warp/tests/test_fast_math.py +0 -2
  140. warp/tests/test_fem.py +75 -54
  141. warp/tests/test_fp16.py +0 -2
  142. warp/tests/test_func.py +0 -2
  143. warp/tests/test_generics.py +27 -2
  144. warp/tests/test_grad.py +147 -8
  145. warp/tests/test_grad_customs.py +0 -2
  146. warp/tests/test_hash_grid.py +1 -3
  147. warp/tests/test_import.py +0 -2
  148. warp/tests/test_indexedarray.py +0 -2
  149. warp/tests/test_intersect.py +0 -2
  150. warp/tests/test_jax.py +0 -2
  151. warp/tests/test_large.py +11 -9
  152. warp/tests/test_launch.py +0 -2
  153. warp/tests/test_lerp.py +10 -54
  154. warp/tests/test_linear_solvers.py +3 -5
  155. warp/tests/test_lvalue.py +0 -2
  156. warp/tests/test_marching_cubes.py +0 -2
  157. warp/tests/test_mat.py +0 -2
  158. warp/tests/test_mat_lite.py +0 -2
  159. warp/tests/test_mat_scalar_ops.py +0 -2
  160. warp/tests/test_math.py +0 -2
  161. warp/tests/test_matmul.py +35 -37
  162. warp/tests/test_matmul_lite.py +29 -31
  163. warp/tests/test_mempool.py +0 -2
  164. warp/tests/test_mesh.py +0 -3
  165. warp/tests/test_mesh_query_aabb.py +0 -2
  166. warp/tests/test_mesh_query_point.py +0 -2
  167. warp/tests/test_mesh_query_ray.py +0 -2
  168. warp/tests/test_mlp.py +0 -2
  169. warp/tests/test_model.py +0 -2
  170. warp/tests/test_module_hashing.py +111 -0
  171. warp/tests/test_modules_lite.py +0 -3
  172. warp/tests/test_multigpu.py +0 -2
  173. warp/tests/test_noise.py +0 -4
  174. warp/tests/test_operators.py +0 -2
  175. warp/tests/test_options.py +0 -2
  176. warp/tests/test_peer.py +0 -2
  177. warp/tests/test_pinned.py +0 -2
  178. warp/tests/test_print.py +0 -2
  179. warp/tests/test_quat.py +0 -2
  180. warp/tests/test_rand.py +41 -5
  181. warp/tests/test_reload.py +0 -10
  182. warp/tests/test_rounding.py +0 -2
  183. warp/tests/test_runlength_encode.py +0 -2
  184. warp/tests/test_sim_grad.py +0 -2
  185. warp/tests/test_sim_kinematics.py +0 -2
  186. warp/tests/test_smoothstep.py +0 -2
  187. warp/tests/test_snippet.py +0 -2
  188. warp/tests/test_sparse.py +0 -2
  189. warp/tests/test_spatial.py +0 -2
  190. warp/tests/test_special_values.py +362 -0
  191. warp/tests/test_streams.py +0 -2
  192. warp/tests/test_struct.py +0 -2
  193. warp/tests/test_tape.py +0 -2
  194. warp/tests/test_torch.py +0 -2
  195. warp/tests/test_transient_module.py +0 -2
  196. warp/tests/test_types.py +0 -2
  197. warp/tests/test_utils.py +0 -2
  198. warp/tests/test_vec.py +0 -2
  199. warp/tests/test_vec_lite.py +0 -2
  200. warp/tests/test_vec_scalar_ops.py +0 -2
  201. warp/tests/test_verify_fp.py +0 -2
  202. warp/tests/test_volume.py +237 -13
  203. warp/tests/test_volume_write.py +86 -3
  204. warp/tests/unittest_serial.py +10 -9
  205. warp/tests/unittest_suites.py +6 -2
  206. warp/tests/unittest_utils.py +2 -171
  207. warp/tests/unused_test_misc.py +0 -2
  208. warp/tests/walkthrough_debug.py +1 -1
  209. warp/thirdparty/unittest_parallel.py +37 -40
  210. warp/types.py +526 -85
  211. {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/METADATA +61 -31
  212. warp_lang-1.2.1.dist-info/RECORD +359 -0
  213. warp/examples/fem/example_convection_diffusion_dg0.py +0 -204
  214. warp/native/nanovdb/PNanoVDBWrite.h +0 -295
  215. warp_lang-1.1.0.dist-info/RECORD +0 -352
  216. {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/LICENSE.md +0 -0
  217. {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/WHEEL +0 -0
  218. {warp_lang-1.1.0.dist-info → warp_lang-1.2.1.dist-info}/top_level.txt +0 -0
warp/tests/test_async.py CHANGED
@@ -13,8 +13,6 @@ import warp as wp
13
13
  from warp.tests.unittest_utils import *
14
14
  from warp.utils import check_iommu
15
15
 
16
- wp.init()
17
-
18
16
 
19
17
  class Capturable:
20
18
  def __init__(self, use_graph=True, stream=None):
warp/tests/test_atomic.py CHANGED
@@ -12,8 +12,6 @@ import numpy as np
12
12
  import warp as wp
13
13
  from warp.tests.unittest_utils import *
14
14
 
15
- wp.init()
16
-
17
15
 
18
16
  # construct kernel + test function for atomic ops on each vec/matrix type
19
17
  def make_atomic_test(type):
warp/tests/test_bool.py CHANGED
@@ -12,8 +12,6 @@ import numpy as np
12
12
  import warp as wp
13
13
  from warp.tests.unittest_utils import *
14
14
 
15
- wp.init()
16
-
17
15
  TRUE_CONSTANT = wp.constant(True)
18
16
 
19
17
 
@@ -90,21 +88,23 @@ def test_bool_constant(test, device):
90
88
  test.assertTrue(compile_constant_value.numpy()[0])
91
89
 
92
90
 
93
- def test_bool_constant_vec(test, device):
94
- vec3bool = wp.vec(length=3, dtype=wp.bool)
95
- bool_selector_vec = wp.constant(vec3bool([True, False, True]))
91
+ vec3bool = wp.vec(length=3, dtype=wp.bool)
92
+ bool_selector_vec = wp.constant(vec3bool([True, False, True]))
93
+
96
94
 
97
- @wp.kernel
98
- def sum_from_bool_vec(sum_array: wp.array(dtype=wp.int32)):
99
- i = wp.tid()
95
+ @wp.kernel
96
+ def sum_from_bool_vec(sum_array: wp.array(dtype=wp.int32)):
97
+ i = wp.tid()
100
98
 
101
- if bool_selector_vec[0]:
102
- sum_array[i] = sum_array[i] + 1
103
- if bool_selector_vec[1]:
104
- sum_array[i] = sum_array[i] + 2
105
- if bool_selector_vec[2]:
106
- sum_array[i] = sum_array[i] + 4
99
+ if bool_selector_vec[0]:
100
+ sum_array[i] = sum_array[i] + 1
101
+ if bool_selector_vec[1]:
102
+ sum_array[i] = sum_array[i] + 2
103
+ if bool_selector_vec[2]:
104
+ sum_array[i] = sum_array[i] + 4
107
105
 
106
+
107
+ def test_bool_constant_vec(test, device):
108
108
  result_array = wp.zeros(10, dtype=wp.int32, device=device)
109
109
 
110
110
  wp.launch(sum_from_bool_vec, result_array.shape, inputs=[result_array], device=device)
@@ -112,23 +112,25 @@ def test_bool_constant_vec(test, device):
112
112
  assert_np_equal(result_array.numpy(), np.full(result_array.shape, 5))
113
113
 
114
114
 
115
- def test_bool_constant_mat(test, device):
116
- mat22bool = wp.mat((2, 2), dtype=wp.bool)
117
- bool_selector_mat = wp.constant(mat22bool([True, False, False, True]))
118
-
119
- @wp.kernel
120
- def sum_from_bool_mat(sum_array: wp.array(dtype=wp.int32)):
121
- i = wp.tid()
122
-
123
- if bool_selector_mat[0, 0]:
124
- sum_array[i] = sum_array[i] + 1
125
- if bool_selector_mat[0, 1]:
126
- sum_array[i] = sum_array[i] + 2
127
- if bool_selector_mat[1, 0]:
128
- sum_array[i] = sum_array[i] + 4
129
- if bool_selector_mat[1, 1]:
130
- sum_array[i] = sum_array[i] + 8
115
+ mat22bool = wp.mat((2, 2), dtype=wp.bool)
116
+ bool_selector_mat = wp.constant(mat22bool([True, False, False, True]))
117
+
131
118
 
119
+ @wp.kernel
120
+ def sum_from_bool_mat(sum_array: wp.array(dtype=wp.int32)):
121
+ i = wp.tid()
122
+
123
+ if bool_selector_mat[0, 0]:
124
+ sum_array[i] = sum_array[i] + 1
125
+ if bool_selector_mat[0, 1]:
126
+ sum_array[i] = sum_array[i] + 2
127
+ if bool_selector_mat[1, 0]:
128
+ sum_array[i] = sum_array[i] + 4
129
+ if bool_selector_mat[1, 1]:
130
+ sum_array[i] = sum_array[i] + 8
131
+
132
+
133
+ def test_bool_constant_mat(test, device):
132
134
  result_array = wp.zeros(10, dtype=wp.int32, device=device)
133
135
 
134
136
  wp.launch(sum_from_bool_mat, result_array.shape, inputs=[result_array], device=device)
@@ -136,8 +138,20 @@ def test_bool_constant_mat(test, device):
136
138
  assert_np_equal(result_array.numpy(), np.full(result_array.shape, 9))
137
139
 
138
140
 
141
+ vec3bool_type = wp.types.vector(length=3, dtype=bool)
142
+
143
+
144
+ @wp.kernel
145
+ def test_bool_vec_anonymous_typing():
146
+ # Zero initialize
147
+ wp.expect_eq(vec3bool_type(), wp.vector(False, False, False))
148
+ # Scalar initialize
149
+ wp.expect_eq(vec3bool_type(True), wp.vector(True, True, True))
150
+ # Component-wise initialize
151
+ wp.expect_eq(vec3bool_type(True, False, True), wp.vector(True, False, True))
152
+
153
+
139
154
  def test_bool_vec_typing(test, device):
140
- vec3bool_type = wp.types.vector(length=3, dtype=bool)
141
155
  # Zero initialize
142
156
  vec3bool_z = vec3bool_type()
143
157
  test.assertEqual(tuple(vec3bool_z), (False, False, False))
@@ -148,20 +162,23 @@ def test_bool_vec_typing(test, device):
148
162
  vec3bool_c = vec3bool_type(True, False, True)
149
163
  test.assertEqual(tuple(vec3bool_c), (True, False, True))
150
164
 
151
- @wp.kernel
152
- def test_bool_vec_anonymous_typing():
153
- # Zero initialize
154
- wp.expect_eq(vec3bool_type(), wp.vector(False, False, False))
155
- # Scalar initialize
156
- wp.expect_eq(vec3bool_type(True), wp.vector(True, True, True))
157
- # Component-wise initialize
158
- wp.expect_eq(vec3bool_type(True, False, True), wp.vector(True, False, True))
159
-
160
165
  wp.launch(test_bool_vec_anonymous_typing, (1,), inputs=[], device=device)
161
166
 
162
167
 
168
+ mat22bool_type = wp.types.matrix((2, 2), dtype=bool)
169
+
170
+
171
+ @wp.kernel
172
+ def test_bool_mat_anonymous_typing():
173
+ # Zero initialize
174
+ wp.expect_eq(mat22bool_type(), wp.matrix(False, False, False, False, shape=(2, 2)))
175
+ # Scalar initialize
176
+ wp.expect_eq(mat22bool_type(True), wp.matrix(True, True, True, True, shape=(2, 2)))
177
+ # Component-wise initialize
178
+ wp.expect_eq(mat22bool_type(True, False, True, False), wp.matrix(True, False, True, False, shape=(2, 2)))
179
+
180
+
163
181
  def test_bool_mat_typing(test, device):
164
- mat22bool_type = wp.types.matrix((2, 2), dtype=bool)
165
182
  # Zero initialize
166
183
  mat22bool_z = mat22bool_type()
167
184
  test.assertEqual(tuple(mat22bool_z), ((False, False), (False, False)))
@@ -172,15 +189,6 @@ def test_bool_mat_typing(test, device):
172
189
  mat22bool_c = mat22bool_type(True, False, True, False)
173
190
  test.assertEqual(tuple(mat22bool_c), ((True, False), (True, False)))
174
191
 
175
- @wp.kernel
176
- def test_bool_mat_anonymous_typing():
177
- # Zero initialize
178
- wp.expect_eq(mat22bool_type(), wp.matrix(False, False, False, False, shape=(2, 2)))
179
- # Scalar initialize
180
- wp.expect_eq(mat22bool_type(True), wp.matrix(True, True, True, True, shape=(2, 2)))
181
- # Component-wise initialize
182
- wp.expect_eq(mat22bool_type(True, False, True, False), wp.matrix(True, False, True, False, shape=(2, 2)))
183
-
184
192
  wp.launch(test_bool_mat_anonymous_typing, (1,), inputs=[], device=device)
185
193
 
186
194
 
@@ -12,8 +12,6 @@ import numpy as np
12
12
 
13
13
  from warp.tests.unittest_utils import *
14
14
 
15
- wp.init()
16
-
17
15
 
18
16
  def nps(dtype, value):
19
17
  """Creates a NumPy scalar value based on the given data type."""
warp/tests/test_bvh.py CHANGED
@@ -12,8 +12,6 @@ import numpy as np
12
12
  import warp as wp
13
13
  from warp.tests.unittest_utils import *
14
14
 
15
- wp.init()
16
-
17
15
 
18
16
  @wp.kernel
19
17
  def bvh_query_aabb(bvh_id: wp.uint64, lower: wp.vec3, upper: wp.vec3, bounds_intersected: wp.array(dtype=int)):
@@ -12,7 +12,6 @@ import numpy as np
12
12
  import warp as wp
13
13
  from warp.tests.unittest_utils import *
14
14
 
15
- wp.init()
16
15
  epsilon = 0.00001
17
16
 
18
17
 
@@ -11,10 +11,6 @@ import unittest
11
11
  import warp as wp
12
12
  from warp.tests.unittest_utils import *
13
13
 
14
- # wp.config.mode = "debug"
15
-
16
- wp.init()
17
-
18
14
 
19
15
  @wp.kernel
20
16
  def test_rename():
@@ -11,8 +11,6 @@ import warp as wp
11
11
  import warp.tests.aux_test_compile_consts_dummy
12
12
  from warp.tests.unittest_utils import *
13
13
 
14
- wp.init()
15
-
16
14
  LOCAL_ONE = wp.constant(1)
17
15
 
18
16
  SQRT3_OVER_3 = wp.constant(0.57735026919)
@@ -27,7 +25,7 @@ class Foobar:
27
25
 
28
26
 
29
27
  @wp.kernel
30
- def test_constants_bool():
28
+ def test_bool():
31
29
  if TEST_BOOL:
32
30
  expect_eq(1.0, 1.0)
33
31
  else:
@@ -35,7 +33,7 @@ def test_constants_bool():
35
33
 
36
34
 
37
35
  @wp.kernel
38
- def test_constants_int(a: int):
36
+ def test_int(a: int):
39
37
  if Foobar.ONE > 0:
40
38
  a = 123 + Foobar.TWO + warp.tests.aux_test_compile_consts_dummy.MINUS_ONE
41
39
  else:
@@ -44,7 +42,7 @@ def test_constants_int(a: int):
44
42
 
45
43
 
46
44
  @wp.kernel
47
- def test_constants_float(x: float):
45
+ def test_float(x: float):
48
46
  x = SQRT3_OVER_3
49
47
  for i in range(3):
50
48
  expect_eq(UNIT_VEC[i], x)
@@ -56,7 +54,7 @@ def test_constants_float(x: float):
56
54
  expect_near(wp.float32(ONE_FP16), 1.0, 1e-6)
57
55
 
58
56
 
59
- def test_constant_closure_capture(test, device):
57
+ def test_closure_capture(test, device):
60
58
  def make_closure_kernel(cst):
61
59
  def closure_kernel_fn(expected: int):
62
60
  wp.expect_eq(cst, expected)
@@ -70,6 +68,124 @@ def test_constant_closure_capture(test, device):
70
68
  wp.launch(two_closure, dim=(1), inputs=[2], device=device)
71
69
 
72
70
 
71
+ def test_hash_global_capture(test, device):
72
+ """Verifies that global variables are included in the module hash"""
73
+
74
+ a = 0
75
+ wp.launch(test_int, (1,), inputs=[a], device=device)
76
+
77
+ module_constants = wp.get_module(test_int.__module__).constants
78
+
79
+ # Ensure the expected constants and values are in the dictionary used in hashing
80
+ # Depending on what's been launched already, there might be additional constants present
81
+ test.assertEqual(module_constants["Foobar.ONE"], 1)
82
+ test.assertEqual(module_constants["Foobar.TWO"], 2)
83
+ test.assertEqual(module_constants["warp.tests.aux_test_compile_consts_dummy.MINUS_ONE"], -1)
84
+ test.assertEqual(module_constants["LOCAL_ONE"], 1)
85
+
86
+
87
+ def test_hash_redefine_kernel(test, device):
88
+ """This test defines a second ``test_function`` so that the second launch returns the correct result."""
89
+
90
+ @wp.kernel
91
+ def test_function(data: wp.array(dtype=wp.float32)):
92
+ i = wp.tid()
93
+ data[i] = TEST_CONSTANT
94
+
95
+ TEST_CONSTANT = wp.constant(1.0)
96
+
97
+ test_array = wp.empty(1, dtype=wp.float32, device=device)
98
+ wp.launch(test_function, (1,), inputs=[test_array], device=device)
99
+ test.assertEqual(test_array.numpy()[0], 1.0)
100
+
101
+ module_hash_0 = wp.get_module(test_function.__module__).hash_module()
102
+ module_constants = wp.get_module(test_function.__module__).constants
103
+ test.assertEqual(module_constants["TEST_CONSTANT"], 1.0)
104
+
105
+ @wp.kernel
106
+ def test_function(data: wp.array(dtype=wp.float32)):
107
+ i = wp.tid()
108
+ data[i] = TEST_CONSTANT
109
+
110
+ TEST_CONSTANT = wp.constant(2.0)
111
+
112
+ wp.launch(test_function, (1,), inputs=[test_array], device=device)
113
+ test.assertEqual(test_array.numpy()[0], 2.0)
114
+
115
+ module_hash_1 = wp.get_module(test_function.__module__).hash_module()
116
+ module_constants = wp.get_module(test_function.__module__).constants
117
+
118
+ test.assertEqual(module_constants["TEST_CONSTANT"], 2.0)
119
+ test.assertNotEqual(module_hash_0, module_hash_1)
120
+
121
+
122
+ def test_hash_redefine_constant_only(test, device):
123
+ """This test does not define a second ``test_function``, so the second launch does not invalidate the cache.
124
+
125
+ For now this is expected behavior, but we can verify that the content has is different.
126
+ """
127
+
128
+ @wp.kernel
129
+ def test_function(data: wp.array(dtype=wp.float32)):
130
+ i = wp.tid()
131
+ data[i] = TEST_CONSTANT
132
+
133
+ TEST_CONSTANT = wp.constant(1.0)
134
+
135
+ test_array = wp.empty(1, dtype=wp.float32, device=device)
136
+ wp.launch(test_function, (1,), inputs=[test_array], device=device)
137
+ test.assertEqual(test_array.numpy()[0], 1.0)
138
+
139
+ module_hash_0 = wp.get_module(test_function.__module__).hash_module()
140
+
141
+ module_constants = wp.get_module(test_function.__module__).constants
142
+ test.assertEqual(module_constants["TEST_CONSTANT"], 1.0)
143
+
144
+ TEST_CONSTANT = wp.constant(2.0)
145
+ module_hash_1 = wp.get_module(test_function.__module__).hash_module(recompute_content_hash=True)
146
+ module_constants = wp.get_module(test_function.__module__).constants
147
+ test.assertEqual(module_constants["TEST_CONSTANT"], 2.0)
148
+ test.assertNotEqual(module_hash_0, module_hash_1, "Module hashes should be different if TEST_CONSTANT is changed.")
149
+
150
+ TEST_CONSTANT = wp.constant(1.0)
151
+ module_hash_2 = wp.get_module(test_function.__module__).hash_module(recompute_content_hash=True)
152
+ module_constants = wp.get_module(test_function.__module__).constants
153
+ test.assertEqual(module_constants["TEST_CONSTANT"], 1.0)
154
+ test.assertEqual(module_hash_0, module_hash_2, "Module hashes should be the same if TEST_CONSTANT is the same.")
155
+
156
+
157
+ def test_hash_shadowed_var(test, device):
158
+ """Tests to ensure shadowed variables are not mistakenly added to the module hash"""
159
+
160
+ TEST_CONSTANT_SHADOW_0 = wp.constant(1.0)
161
+ TEST_CONSTANT_SHADOW_1 = wp.constant(1.0)
162
+ TEST_CONSTANT_SHADOW_2 = wp.constant(1.0)
163
+
164
+ @wp.kernel
165
+ def test_function(data: wp.array(dtype=wp.float32)):
166
+ i = wp.tid()
167
+ TEST_CONSTANT_SHADOW_0 = 2.0
168
+ TEST_CONSTANT_SHADOW_1, TEST_CONSTANT_SHADOW_2 = 4.0, 8.0
169
+ data[i] = TEST_CONSTANT_SHADOW_0 + TEST_CONSTANT_SHADOW_1 + TEST_CONSTANT_SHADOW_2
170
+
171
+ test_array = wp.empty(1, dtype=wp.float32, device=device)
172
+ wp.launch(test_function, (1,), inputs=[test_array], device=device)
173
+ test.assertEqual(test_array.numpy()[0], 14.0)
174
+
175
+ module_hash_0 = wp.get_module(test_function.__module__).hash_module()
176
+ module_constants = wp.get_module(test_function.__module__).constants
177
+
178
+ test.assertFalse("TEST_CONSTANT_SHADOW_0" in module_constants, "Constant should not be in dictionary.")
179
+ test.assertFalse("TEST_CONSTANT_SHADOW_1" in module_constants, "Constant should not be in dictionary.")
180
+ test.assertFalse("TEST_CONSTANT_SHADOW_2" in module_constants, "Constant should not be in dictionary.")
181
+
182
+ TEST_CONSTANT_SHADOW_0 = wp.constant(0.0)
183
+ TEST_CONSTANT_SHADOW_1 = wp.constant(0.0)
184
+ TEST_CONSTANT_SHADOW_2 = wp.constant(0.0)
185
+ module_hash_1 = wp.get_module(test_function.__module__).hash_module(recompute_content_hash=True)
186
+ test.assertEqual(module_hash_0, module_hash_1, "Module hashes should be the same since all constants are shadowed.")
187
+
188
+
73
189
  class TestConstants(unittest.TestCase):
74
190
  def test_constant_math(self):
75
191
  # test doing math with python defined constants in *python* scope
@@ -85,11 +201,15 @@ x = 0.0
85
201
 
86
202
  devices = get_test_devices()
87
203
 
88
- add_kernel_test(TestConstants, test_constants_bool, dim=1, inputs=[], devices=devices)
89
- add_kernel_test(TestConstants, test_constants_int, dim=1, inputs=[a], devices=devices)
90
- add_kernel_test(TestConstants, test_constants_float, dim=1, inputs=[x], devices=devices)
204
+ add_kernel_test(TestConstants, test_bool, dim=1, inputs=[], devices=devices)
205
+ add_kernel_test(TestConstants, test_int, dim=1, inputs=[a], devices=devices)
206
+ add_kernel_test(TestConstants, test_float, dim=1, inputs=[x], devices=devices)
91
207
 
92
- add_function_test(TestConstants, "test_constant_closure_capture", test_constant_closure_capture, devices=devices)
208
+ add_function_test(TestConstants, "test_closure_capture", test_closure_capture, devices=devices)
209
+ add_function_test(TestConstants, "test_hash_global_capture", test_hash_global_capture, devices=devices)
210
+ add_function_test(TestConstants, "test_hash_redefine_kernel", test_hash_redefine_kernel, devices=devices)
211
+ add_function_test(TestConstants, "test_hash_redefine_constant_only", test_hash_redefine_constant_only, devices=devices)
212
+ add_function_test(TestConstants, "test_hash_shadowed_var", test_hash_shadowed_var, devices=devices)
93
213
 
94
214
 
95
215
  if __name__ == "__main__":
@@ -10,8 +10,6 @@ import unittest
10
10
  import warp as wp
11
11
  from warp.tests.unittest_utils import *
12
12
 
13
- wp.init()
14
-
15
13
 
16
14
  @wp.kernel
17
15
  def test_conditional_if_else():
warp/tests/test_copy.py CHANGED
@@ -12,8 +12,6 @@ import numpy as np
12
12
  import warp as wp
13
13
  from warp.tests.unittest_utils import *
14
14
 
15
- wp.init()
16
-
17
15
 
18
16
  @wp.kernel
19
17
  def mul_1d(a: wp.array1d(dtype=float), s: float):
warp/tests/test_ctypes.py CHANGED
@@ -12,8 +12,6 @@ import numpy as np
12
12
  import warp as wp
13
13
  from warp.tests.unittest_utils import *
14
14
 
15
- wp.init()
16
-
17
15
 
18
16
  @wp.kernel
19
17
  def add_vec2(dest: wp.array(dtype=wp.vec2), c: wp.vec2):
@@ -57,7 +55,7 @@ def test_vec2_arg(test, device, n):
57
55
  wp.launch(add_vec2, dim=n, inputs=[dest, c], device=device)
58
56
 
59
57
  # ensure type can round-trip from Python->GPU->Python
60
- test.assertTrue(np.array_equal(dest.numpy(), np.tile(c, (n, 1))))
58
+ assert_np_equal(dest.numpy(), np.tile(c, (n, 1)))
61
59
 
62
60
 
63
61
  def test_vec2_transform(test, device, n):
@@ -67,8 +65,8 @@ def test_vec2_transform(test, device, n):
67
65
  m = np.array(((3.0, -1.0), (2.5, 4.0)))
68
66
 
69
67
  wp.launch(transform_vec2, dim=n, inputs=[dest_right, dest_left, m, c], device=device)
70
- test.assertTrue(np.array_equal(dest_right.numpy(), np.tile(m @ c, (n, 1))))
71
- test.assertTrue(np.array_equal(dest_left.numpy(), np.tile(c @ m, (n, 1))))
68
+ assert_np_equal(dest_right.numpy(), np.tile(m @ c, (n, 1)))
69
+ assert_np_equal(dest_left.numpy(), np.tile(c @ m, (n, 1)))
72
70
 
73
71
 
74
72
  def test_vec3_arg(test, device, n):
@@ -76,7 +74,7 @@ def test_vec3_arg(test, device, n):
76
74
  c = np.array((1.0, 2.0, 3.0))
77
75
 
78
76
  wp.launch(add_vec3, dim=n, inputs=[dest, c], device=device)
79
- test.assertTrue(np.array_equal(dest.numpy(), np.tile(c, (n, 1))))
77
+ assert_np_equal(dest.numpy(), np.tile(c, (n, 1)))
80
78
 
81
79
 
82
80
  def test_vec3_transform(test, device, n):
@@ -86,8 +84,8 @@ def test_vec3_transform(test, device, n):
86
84
  m = np.array(((1.0, 2.0, 3.0), (4.0, 5.0, 6.0), (7.0, 8.0, 9.0)))
87
85
 
88
86
  wp.launch(transform_vec3, dim=n, inputs=[dest_right, dest_left, m, c], device=device)
89
- test.assertTrue(np.array_equal(dest_right.numpy(), np.tile(m @ c, (n, 1))))
90
- test.assertTrue(np.array_equal(dest_left.numpy(), np.tile(c @ m, (n, 1))))
87
+ assert_np_equal(dest_right.numpy(), np.tile(m @ c, (n, 1)))
88
+ assert_np_equal(dest_left.numpy(), np.tile(c @ m, (n, 1)))
91
89
 
92
90
 
93
91
  def test_transform_multiply(test, device, n):
warp/tests/test_dense.py CHANGED
@@ -10,8 +10,6 @@ import unittest
10
10
  import warp as wp
11
11
  from warp.tests.unittest_utils import *
12
12
 
13
- wp.init()
14
-
15
13
 
16
14
  @wp.kernel
17
15
  def eval_dense_gemm(
@@ -10,8 +10,6 @@ import unittest
10
10
  import warp as wp
11
11
  from warp.tests.unittest_utils import *
12
12
 
13
- wp.init()
14
-
15
13
 
16
14
  def test_devices_get_cuda_device_functions(test, device):
17
15
  test.assertTrue(device.is_cuda)
warp/tests/test_dlpack.py CHANGED
@@ -16,15 +16,13 @@ from warp.tests.unittest_utils import *
16
16
 
17
17
  N = 1024 * 1024
18
18
 
19
- wp.init()
20
-
21
19
 
22
20
  def _jax_version():
23
21
  try:
24
22
  import jax
25
23
 
26
24
  return jax.__version_info__
27
- except ImportError:
25
+ except (ImportError, AttributeError):
28
26
  return (0, 0, 0)
29
27
 
30
28
 
@@ -315,8 +313,8 @@ def test_dlpack_warp_to_jax(test, device):
315
313
 
316
314
  test.assertEqual(a.ptr, j1.unsafe_buffer_pointer())
317
315
  test.assertEqual(a.ptr, j2.unsafe_buffer_pointer())
318
- test.assertEqual(a.device, wp.device_from_jax(j1.device()))
319
- test.assertEqual(a.device, wp.device_from_jax(j2.device()))
316
+ test.assertEqual(a.device, wp.device_from_jax(list(j1.devices())[0]))
317
+ test.assertEqual(a.device, wp.device_from_jax(list(j2.devices())[0]))
320
318
  test.assertEqual(a.shape, j1.shape)
321
319
  test.assertEqual(a.shape, j2.shape)
322
320
 
@@ -352,8 +350,8 @@ def test_dlpack_warp_to_jax_v2(test, device):
352
350
 
353
351
  test.assertEqual(a.ptr, j1.unsafe_buffer_pointer())
354
352
  test.assertEqual(a.ptr, j2.unsafe_buffer_pointer())
355
- test.assertEqual(a.device, wp.device_from_jax(j1.device()))
356
- test.assertEqual(a.device, wp.device_from_jax(j2.device()))
353
+ test.assertEqual(a.device, wp.device_from_jax(list(j1.devices())[0]))
354
+ test.assertEqual(a.device, wp.device_from_jax(list(j2.devices())[0]))
357
355
  test.assertEqual(a.shape, j1.shape)
358
356
  test.assertEqual(a.shape, j2.shape)
359
357
 
@@ -387,8 +385,8 @@ def test_dlpack_jax_to_warp(test, device):
387
385
 
388
386
  test.assertEqual(a1.ptr, j.unsafe_buffer_pointer())
389
387
  test.assertEqual(a2.ptr, j.unsafe_buffer_pointer())
390
- test.assertEqual(a1.device, wp.device_from_jax(j.device()))
391
- test.assertEqual(a2.device, wp.device_from_jax(j.device()))
388
+ test.assertEqual(a1.device, wp.device_from_jax(list(j.devices())[0]))
389
+ test.assertEqual(a2.device, wp.device_from_jax(list(j.devices())[0]))
392
390
  test.assertEqual(a1.shape, j.shape)
393
391
  test.assertEqual(a2.shape, j.shape)
394
392
 
@@ -423,8 +421,8 @@ def test_dlpack_jax_to_warp_v2(test, device):
423
421
 
424
422
  test.assertEqual(a1.ptr, j.unsafe_buffer_pointer())
425
423
  test.assertEqual(a2.ptr, j.unsafe_buffer_pointer())
426
- test.assertEqual(a1.device, wp.device_from_jax(j.device()))
427
- test.assertEqual(a2.device, wp.device_from_jax(j.device()))
424
+ test.assertEqual(a1.device, wp.device_from_jax(list(j.devices())[0]))
425
+ test.assertEqual(a2.device, wp.device_from_jax(list(j.devices())[0]))
428
426
  test.assertEqual(a1.shape, j.shape)
429
427
  test.assertEqual(a2.shape, j.shape)
430
428