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.

Files changed (315) hide show
  1. warp/__init__.py +15 -7
  2. warp/__init__.pyi +1 -0
  3. warp/bin/warp-clang.dll +0 -0
  4. warp/bin/warp.dll +0 -0
  5. warp/build.py +22 -443
  6. warp/build_dll.py +384 -0
  7. warp/builtins.py +998 -488
  8. warp/codegen.py +1307 -739
  9. warp/config.py +5 -3
  10. warp/constants.py +6 -0
  11. warp/context.py +1291 -548
  12. warp/dlpack.py +31 -31
  13. warp/fabric.py +326 -0
  14. warp/fem/__init__.py +27 -0
  15. warp/fem/cache.py +389 -0
  16. warp/fem/dirichlet.py +181 -0
  17. warp/fem/domain.py +263 -0
  18. warp/fem/field/__init__.py +101 -0
  19. warp/fem/field/field.py +149 -0
  20. warp/fem/field/nodal_field.py +299 -0
  21. warp/fem/field/restriction.py +21 -0
  22. warp/fem/field/test.py +181 -0
  23. warp/fem/field/trial.py +183 -0
  24. warp/fem/geometry/__init__.py +19 -0
  25. warp/fem/geometry/closest_point.py +70 -0
  26. warp/fem/geometry/deformed_geometry.py +271 -0
  27. warp/fem/geometry/element.py +744 -0
  28. warp/fem/geometry/geometry.py +186 -0
  29. warp/fem/geometry/grid_2d.py +373 -0
  30. warp/fem/geometry/grid_3d.py +435 -0
  31. warp/fem/geometry/hexmesh.py +953 -0
  32. warp/fem/geometry/partition.py +376 -0
  33. warp/fem/geometry/quadmesh_2d.py +532 -0
  34. warp/fem/geometry/tetmesh.py +840 -0
  35. warp/fem/geometry/trimesh_2d.py +577 -0
  36. warp/fem/integrate.py +1616 -0
  37. warp/fem/operator.py +191 -0
  38. warp/fem/polynomial.py +213 -0
  39. warp/fem/quadrature/__init__.py +2 -0
  40. warp/fem/quadrature/pic_quadrature.py +245 -0
  41. warp/fem/quadrature/quadrature.py +294 -0
  42. warp/fem/space/__init__.py +292 -0
  43. warp/fem/space/basis_space.py +489 -0
  44. warp/fem/space/collocated_function_space.py +105 -0
  45. warp/fem/space/dof_mapper.py +236 -0
  46. warp/fem/space/function_space.py +145 -0
  47. warp/fem/space/grid_2d_function_space.py +267 -0
  48. warp/fem/space/grid_3d_function_space.py +306 -0
  49. warp/fem/space/hexmesh_function_space.py +352 -0
  50. warp/fem/space/partition.py +350 -0
  51. warp/fem/space/quadmesh_2d_function_space.py +369 -0
  52. warp/fem/space/restriction.py +160 -0
  53. warp/fem/space/shape/__init__.py +15 -0
  54. warp/fem/space/shape/cube_shape_function.py +738 -0
  55. warp/fem/space/shape/shape_function.py +103 -0
  56. warp/fem/space/shape/square_shape_function.py +611 -0
  57. warp/fem/space/shape/tet_shape_function.py +567 -0
  58. warp/fem/space/shape/triangle_shape_function.py +429 -0
  59. warp/fem/space/tetmesh_function_space.py +292 -0
  60. warp/fem/space/topology.py +295 -0
  61. warp/fem/space/trimesh_2d_function_space.py +221 -0
  62. warp/fem/types.py +77 -0
  63. warp/fem/utils.py +495 -0
  64. warp/native/array.h +164 -55
  65. warp/native/builtin.h +150 -174
  66. warp/native/bvh.cpp +75 -328
  67. warp/native/bvh.cu +406 -23
  68. warp/native/bvh.h +37 -45
  69. warp/native/clang/clang.cpp +136 -24
  70. warp/native/crt.cpp +1 -76
  71. warp/native/crt.h +111 -104
  72. warp/native/cuda_crt.h +1049 -0
  73. warp/native/cuda_util.cpp +15 -3
  74. warp/native/cuda_util.h +3 -1
  75. warp/native/cutlass/tools/library/scripts/conv2d_operation.py +463 -0
  76. warp/native/cutlass/tools/library/scripts/conv3d_operation.py +321 -0
  77. warp/native/cutlass/tools/library/scripts/gemm_operation.py +988 -0
  78. warp/native/cutlass/tools/library/scripts/generator.py +4625 -0
  79. warp/native/cutlass/tools/library/scripts/library.py +799 -0
  80. warp/native/cutlass/tools/library/scripts/manifest.py +402 -0
  81. warp/native/cutlass/tools/library/scripts/pycutlass/docs/source/conf.py +96 -0
  82. warp/native/cutlass/tools/library/scripts/pycutlass/profile/conv/conv2d_f16_sm80.py +106 -0
  83. warp/native/cutlass/tools/library/scripts/pycutlass/profile/gemm/gemm_f32_sm80.py +91 -0
  84. warp/native/cutlass/tools/library/scripts/pycutlass/setup.py +80 -0
  85. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/__init__.py +48 -0
  86. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/arguments.py +118 -0
  87. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/c_types.py +241 -0
  88. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/compiler.py +432 -0
  89. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/conv2d_operation.py +631 -0
  90. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/epilogue.py +1026 -0
  91. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/frontend.py +104 -0
  92. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/gemm_operation.py +1276 -0
  93. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/library.py +744 -0
  94. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/memory_manager.py +74 -0
  95. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/operation.py +110 -0
  96. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/parser.py +619 -0
  97. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/reduction_operation.py +398 -0
  98. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/tensor_ref.py +70 -0
  99. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/__init__.py +4 -0
  100. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/conv2d_testbed.py +646 -0
  101. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/gemm_grouped_testbed.py +235 -0
  102. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/gemm_testbed.py +557 -0
  103. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/test/profiler.py +70 -0
  104. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/type_hint.py +39 -0
  105. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/__init__.py +1 -0
  106. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/device.py +76 -0
  107. warp/native/cutlass/tools/library/scripts/pycutlass/src/pycutlass/utils/reference_model.py +255 -0
  108. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/__init__.py +0 -0
  109. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +201 -0
  110. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +177 -0
  111. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +98 -0
  112. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_dgrad_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +95 -0
  113. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_few_channels_f16nhwc_f16nhwc_f16nhwc_tensor_op_f32_sm80.py +163 -0
  114. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_fixed_channels_f16nhwc_f16nhwc_f16nhwc_tensor_op_f32_sm80.py +187 -0
  115. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +309 -0
  116. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +54 -0
  117. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +96 -0
  118. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_fprop_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +107 -0
  119. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_strided_dgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +253 -0
  120. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f16nhwc_f16nhwc_f16nhwc_tensor_op_f16_sm80.py +97 -0
  121. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f16nhwc_f16nhwc_f32nhwc_tensor_op_f32_sm80.py +242 -0
  122. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_f32nhwc_f32nhwc_f32nhwc_simt_f32_sm80.py +96 -0
  123. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/conv2d_wgrad_implicit_gemm_tf32nhwc_tf32nhwc_f32nhwc_tensor_op_f32_sm80.py +107 -0
  124. warp/native/cutlass/tools/library/scripts/pycutlass/test/conv/run_all_tests.py +10 -0
  125. warp/native/cutlass/tools/library/scripts/pycutlass/test/frontend/test_frontend.py +146 -0
  126. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/__init__.py +0 -0
  127. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_bf16_sm80.py +96 -0
  128. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f16_sm80.py +447 -0
  129. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f32_sm80.py +146 -0
  130. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_f64_sm80.py +102 -0
  131. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_grouped_sm80.py +203 -0
  132. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/gemm_s8_sm80.py +229 -0
  133. warp/native/cutlass/tools/library/scripts/pycutlass/test/gemm/run_all_tests.py +9 -0
  134. warp/native/cutlass/tools/library/scripts/pycutlass/test/unit/test_sm80.py +453 -0
  135. warp/native/cutlass/tools/library/scripts/rank_2k_operation.py +398 -0
  136. warp/native/cutlass/tools/library/scripts/rank_k_operation.py +387 -0
  137. warp/native/cutlass/tools/library/scripts/rt.py +796 -0
  138. warp/native/cutlass/tools/library/scripts/symm_operation.py +400 -0
  139. warp/native/cutlass/tools/library/scripts/trmm_operation.py +407 -0
  140. warp/native/cutlass_gemm.cu +5 -3
  141. warp/native/exports.h +1240 -949
  142. warp/native/fabric.h +228 -0
  143. warp/native/hashgrid.cpp +4 -4
  144. warp/native/hashgrid.h +22 -2
  145. warp/native/initializer_array.h +2 -2
  146. warp/native/intersect.h +22 -7
  147. warp/native/intersect_adj.h +8 -8
  148. warp/native/intersect_tri.h +13 -16
  149. warp/native/marching.cu +157 -161
  150. warp/native/mat.h +119 -19
  151. warp/native/matnn.h +2 -2
  152. warp/native/mesh.cpp +108 -83
  153. warp/native/mesh.cu +243 -6
  154. warp/native/mesh.h +1547 -458
  155. warp/native/nanovdb/NanoVDB.h +1 -1
  156. warp/native/noise.h +272 -329
  157. warp/native/quat.h +51 -8
  158. warp/native/rand.h +45 -35
  159. warp/native/range.h +6 -2
  160. warp/native/reduce.cpp +157 -0
  161. warp/native/reduce.cu +348 -0
  162. warp/native/runlength_encode.cpp +62 -0
  163. warp/native/runlength_encode.cu +46 -0
  164. warp/native/scan.cu +11 -13
  165. warp/native/scan.h +1 -0
  166. warp/native/solid_angle.h +442 -0
  167. warp/native/sort.cpp +13 -0
  168. warp/native/sort.cu +9 -1
  169. warp/native/sparse.cpp +338 -0
  170. warp/native/sparse.cu +545 -0
  171. warp/native/spatial.h +2 -2
  172. warp/native/temp_buffer.h +30 -0
  173. warp/native/vec.h +126 -24
  174. warp/native/volume.h +120 -0
  175. warp/native/warp.cpp +658 -53
  176. warp/native/warp.cu +660 -68
  177. warp/native/warp.h +112 -12
  178. warp/optim/__init__.py +1 -0
  179. warp/optim/linear.py +922 -0
  180. warp/optim/sgd.py +92 -0
  181. warp/render/render_opengl.py +392 -152
  182. warp/render/render_usd.py +11 -11
  183. warp/sim/__init__.py +2 -2
  184. warp/sim/articulation.py +385 -185
  185. warp/sim/collide.py +21 -8
  186. warp/sim/import_mjcf.py +297 -106
  187. warp/sim/import_urdf.py +389 -210
  188. warp/sim/import_usd.py +198 -97
  189. warp/sim/inertia.py +17 -18
  190. warp/sim/integrator_euler.py +14 -8
  191. warp/sim/integrator_xpbd.py +161 -19
  192. warp/sim/model.py +795 -291
  193. warp/sim/optimizer.py +2 -6
  194. warp/sim/render.py +65 -3
  195. warp/sim/utils.py +3 -0
  196. warp/sparse.py +1227 -0
  197. warp/stubs.py +665 -223
  198. warp/tape.py +66 -15
  199. warp/tests/__main__.py +3 -6
  200. warp/tests/assets/curlnoise_golden.npy +0 -0
  201. warp/tests/assets/pnoise_golden.npy +0 -0
  202. warp/tests/assets/torus.usda +105 -105
  203. warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
  204. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
  205. warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
  206. warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
  207. warp/tests/aux_test_unresolved_func.py +14 -0
  208. warp/tests/aux_test_unresolved_symbol.py +14 -0
  209. warp/tests/disabled_kinematics.py +239 -0
  210. warp/tests/run_coverage_serial.py +31 -0
  211. warp/tests/test_adam.py +103 -106
  212. warp/tests/test_arithmetic.py +128 -74
  213. warp/tests/test_array.py +1497 -211
  214. warp/tests/test_array_reduce.py +150 -0
  215. warp/tests/test_atomic.py +64 -28
  216. warp/tests/test_bool.py +99 -0
  217. warp/tests/test_builtins_resolution.py +1292 -0
  218. warp/tests/test_bvh.py +75 -43
  219. warp/tests/test_closest_point_edge_edge.py +54 -57
  220. warp/tests/test_codegen.py +233 -128
  221. warp/tests/test_compile_consts.py +28 -20
  222. warp/tests/test_conditional.py +108 -24
  223. warp/tests/test_copy.py +10 -12
  224. warp/tests/test_ctypes.py +112 -88
  225. warp/tests/test_dense.py +21 -14
  226. warp/tests/test_devices.py +98 -0
  227. warp/tests/test_dlpack.py +136 -108
  228. warp/tests/test_examples.py +277 -0
  229. warp/tests/test_fabricarray.py +955 -0
  230. warp/tests/test_fast_math.py +15 -11
  231. warp/tests/test_fem.py +1271 -0
  232. warp/tests/test_fp16.py +53 -19
  233. warp/tests/test_func.py +187 -74
  234. warp/tests/test_generics.py +194 -49
  235. warp/tests/test_grad.py +180 -116
  236. warp/tests/test_grad_customs.py +176 -0
  237. warp/tests/test_hash_grid.py +52 -37
  238. warp/tests/test_import.py +10 -23
  239. warp/tests/test_indexedarray.py +577 -24
  240. warp/tests/test_intersect.py +18 -9
  241. warp/tests/test_large.py +141 -0
  242. warp/tests/test_launch.py +251 -15
  243. warp/tests/test_lerp.py +64 -65
  244. warp/tests/test_linear_solvers.py +154 -0
  245. warp/tests/test_lvalue.py +493 -0
  246. warp/tests/test_marching_cubes.py +12 -13
  247. warp/tests/test_mat.py +508 -2778
  248. warp/tests/test_mat_lite.py +115 -0
  249. warp/tests/test_mat_scalar_ops.py +2889 -0
  250. warp/tests/test_math.py +103 -9
  251. warp/tests/test_matmul.py +305 -69
  252. warp/tests/test_matmul_lite.py +410 -0
  253. warp/tests/test_mesh.py +71 -14
  254. warp/tests/test_mesh_query_aabb.py +41 -25
  255. warp/tests/test_mesh_query_point.py +325 -34
  256. warp/tests/test_mesh_query_ray.py +39 -22
  257. warp/tests/test_mlp.py +30 -22
  258. warp/tests/test_model.py +92 -89
  259. warp/tests/test_modules_lite.py +39 -0
  260. warp/tests/test_multigpu.py +88 -114
  261. warp/tests/test_noise.py +12 -11
  262. warp/tests/test_operators.py +16 -20
  263. warp/tests/test_options.py +11 -11
  264. warp/tests/test_pinned.py +17 -18
  265. warp/tests/test_print.py +32 -11
  266. warp/tests/test_quat.py +275 -129
  267. warp/tests/test_rand.py +18 -16
  268. warp/tests/test_reload.py +38 -34
  269. warp/tests/test_rounding.py +50 -43
  270. warp/tests/test_runlength_encode.py +190 -0
  271. warp/tests/test_smoothstep.py +9 -11
  272. warp/tests/test_snippet.py +143 -0
  273. warp/tests/test_sparse.py +460 -0
  274. warp/tests/test_spatial.py +276 -243
  275. warp/tests/test_streams.py +110 -85
  276. warp/tests/test_struct.py +331 -85
  277. warp/tests/test_tape.py +39 -21
  278. warp/tests/test_torch.py +118 -89
  279. warp/tests/test_transient_module.py +12 -13
  280. warp/tests/test_types.py +614 -0
  281. warp/tests/test_utils.py +494 -0
  282. warp/tests/test_vec.py +354 -1987
  283. warp/tests/test_vec_lite.py +73 -0
  284. warp/tests/test_vec_scalar_ops.py +2099 -0
  285. warp/tests/test_volume.py +457 -293
  286. warp/tests/test_volume_write.py +124 -134
  287. warp/tests/unittest_serial.py +35 -0
  288. warp/tests/unittest_suites.py +341 -0
  289. warp/tests/unittest_utils.py +568 -0
  290. warp/tests/unused_test_misc.py +71 -0
  291. warp/tests/{test_debug.py → walkthough_debug.py} +3 -17
  292. warp/thirdparty/appdirs.py +36 -45
  293. warp/thirdparty/unittest_parallel.py +549 -0
  294. warp/torch.py +72 -30
  295. warp/types.py +1744 -713
  296. warp/utils.py +360 -350
  297. warp_lang-0.11.0.dist-info/LICENSE.md +36 -0
  298. warp_lang-0.11.0.dist-info/METADATA +238 -0
  299. warp_lang-0.11.0.dist-info/RECORD +332 -0
  300. {warp_lang-0.9.0.dist-info → warp_lang-0.11.0.dist-info}/WHEEL +1 -1
  301. warp/bin/warp-clang.exp +0 -0
  302. warp/bin/warp-clang.lib +0 -0
  303. warp/bin/warp.exp +0 -0
  304. warp/bin/warp.lib +0 -0
  305. warp/tests/test_all.py +0 -215
  306. warp/tests/test_array_scan.py +0 -60
  307. warp/tests/test_base.py +0 -208
  308. warp/tests/test_unresolved_func.py +0 -7
  309. warp/tests/test_unresolved_symbol.py +0 -7
  310. warp_lang-0.9.0.dist-info/METADATA +0 -20
  311. warp_lang-0.9.0.dist-info/RECORD +0 -177
  312. /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
  313. /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
  314. /warp/tests/{test_square.py → aux_test_square.py} +0 -0
  315. {warp_lang-0.9.0.dist-info → warp_lang-0.11.0.dist-info}/top_level.txt +0 -0
warp/tests/test_struct.py CHANGED
@@ -5,11 +5,15 @@
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 unittest
9
+ from typing import Any
10
+
8
11
  import numpy as np
12
+
9
13
  import warp as wp
10
- from warp.tests.test_base import *
14
+ from warp.tests.unittest_utils import *
11
15
 
12
- import unittest
16
+ from warp.fem import Sample as StructFromAnotherModule
13
17
 
14
18
  wp.init()
15
19
 
@@ -35,7 +39,20 @@ def kernel_step(state_in: State, state_out: State, model: Model):
35
39
  state_out.x[i] = state_in.x[i] + state_out.v[i] * model.dt
36
40
 
37
41
 
42
+ @wp.kernel
43
+ def kernel_step_with_copy(state_in: State, state_out: State, model: Model):
44
+ i = wp.tid()
45
+
46
+ model_rescaled = Model(1.0, model.gravity / model.m[i] * model.dt, model.m)
47
+
48
+ state_out_copy = State(state_out.x, state_out.v)
49
+ state_out_copy.v[i] = state_in.v[i] + model_rescaled.gravity
50
+ state_out_copy.x[i] = state_in.x[i] + state_out_copy.v[i] * model.dt
51
+
52
+
38
53
  def test_step(test, device):
54
+ rng = np.random.default_rng(123)
55
+
39
56
  dim = 5
40
57
 
41
58
  dt = 0.01
@@ -50,9 +67,8 @@ def test_step(test, device):
50
67
  model.dt = dt
51
68
  model.gravity = wp.vec3(0, 0, -9.81)
52
69
 
53
- np.random.seed(0)
54
- x = np.random.normal(size=(dim, 3))
55
- v = np.random.normal(size=(dim, 3))
70
+ x = rng.normal(size=(dim, 3))
71
+ v = rng.normal(size=(dim, 3))
56
72
 
57
73
  x_expected = x + (v + gravity / m[:, None] * dt) * dt
58
74
 
@@ -67,10 +83,11 @@ def test_step(test, device):
67
83
  state_out.x = wp.empty_like(x_in)
68
84
  state_out.v = wp.empty_like(v_in)
69
85
 
70
- with CheckOutput(test):
71
- wp.launch(kernel_step, dim=dim, inputs=[state_in, state_out, model], device=device)
86
+ for step_kernel in [kernel_step, kernel_step_with_copy]:
87
+ with CheckOutput(test):
88
+ wp.launch(step_kernel, dim=dim, inputs=[state_in, state_out, model], device=device)
72
89
 
73
- assert_np_equal(state_out.x.numpy(), x_expected, tol=1e-6)
90
+ assert_np_equal(state_out.x.numpy(), x_expected, tol=1e-6)
74
91
 
75
92
 
76
93
  @wp.kernel
@@ -80,13 +97,14 @@ def kernel_loss(x: wp.array(dtype=wp.vec3), loss: wp.array(dtype=float)):
80
97
 
81
98
 
82
99
  def test_step_grad(test, device):
100
+ rng = np.random.default_rng(123)
101
+
83
102
  dim = 5
84
103
 
85
104
  dt = 0.01
86
105
  gravity = np.array([0, 0, -9.81])
87
106
 
88
- np.random.seed(0)
89
- m = np.random.rand(dim) + 0.1
107
+ m = rng.random(size=dim) + 0.1
90
108
 
91
109
  m_model = wp.array(m, dtype=float, device=device, requires_grad=True)
92
110
 
@@ -95,8 +113,8 @@ def test_step_grad(test, device):
95
113
  model.dt = dt
96
114
  model.gravity = wp.vec3(0, 0, -9.81)
97
115
 
98
- x = np.random.normal(size=(dim, 3))
99
- v = np.random.normal(size=(dim, 3))
116
+ x = rng.normal(size=(dim, 3))
117
+ v = rng.normal(size=(dim, 3))
100
118
 
101
119
  x_in = wp.array(x, dtype=wp.vec3, device=device, requires_grad=True)
102
120
  v_in = wp.array(v, dtype=wp.vec3, device=device, requires_grad=True)
@@ -111,33 +129,34 @@ def test_step_grad(test, device):
111
129
 
112
130
  loss = wp.empty(1, dtype=float, device=device, requires_grad=True)
113
131
 
114
- tape = wp.Tape()
132
+ for step_kernel in [kernel_step, kernel_step_with_copy]:
133
+ tape = wp.Tape()
115
134
 
116
- with tape:
117
- wp.launch(kernel_step, dim=dim, inputs=[state_in, state_out, model], device=device)
118
- wp.launch(kernel_loss, dim=dim, inputs=[state_out.x, loss], device=device)
135
+ with tape:
136
+ wp.launch(step_kernel, dim=dim, inputs=[state_in, state_out, model], device=device)
137
+ wp.launch(kernel_loss, dim=dim, inputs=[state_out.x, loss], device=device)
119
138
 
120
- tape.backward(loss)
139
+ tape.backward(loss)
121
140
 
122
- dl_dx = 2 * state_out.x.numpy()
123
- dl_dv = dl_dx * dt
141
+ dl_dx = 2 * state_out.x.numpy()
142
+ dl_dv = dl_dx * dt
124
143
 
125
- dv_dm = -gravity * dt / m[:, None] ** 2
126
- dl_dm = (dl_dv * dv_dm).sum(-1)
144
+ dv_dm = -gravity * dt / m[:, None] ** 2
145
+ dl_dm = (dl_dv * dv_dm).sum(-1)
127
146
 
128
- assert_np_equal(state_out.x.grad.numpy(), dl_dx, tol=1e-6)
129
- assert_np_equal(state_in.x.grad.numpy(), dl_dx, tol=1e-6)
130
- assert_np_equal(state_out.v.grad.numpy(), dl_dv, tol=1e-6)
131
- assert_np_equal(state_in.v.grad.numpy(), dl_dv, tol=1e-6)
132
- assert_np_equal(model.m.grad.numpy(), dl_dm, tol=1e-6)
147
+ assert_np_equal(state_out.x.grad.numpy(), dl_dx, tol=1e-6)
148
+ assert_np_equal(state_in.x.grad.numpy(), dl_dx, tol=1e-6)
149
+ assert_np_equal(state_out.v.grad.numpy(), dl_dv, tol=1e-6)
150
+ assert_np_equal(state_in.v.grad.numpy(), dl_dv, tol=1e-6)
151
+ assert_np_equal(model.m.grad.numpy(), dl_dm, tol=1e-6)
133
152
 
134
- tape.zero()
153
+ tape.zero()
135
154
 
136
- assert state_out.x.grad.numpy().sum() == 0.0
137
- assert state_in.x.grad.numpy().sum() == 0.0
138
- assert state_out.v.grad.numpy().sum() == 0.0
139
- assert state_in.v.grad.numpy().sum() == 0.0
140
- assert model.m.grad.numpy().sum() == 0.0
155
+ assert state_out.x.grad.numpy().sum() == 0.0
156
+ assert state_in.x.grad.numpy().sum() == 0.0
157
+ assert state_out.v.grad.numpy().sum() == 0.0
158
+ assert state_in.v.grad.numpy().sum() == 0.0
159
+ assert model.m.grad.numpy().sum() == 0.0
141
160
 
142
161
 
143
162
  @wp.struct
@@ -205,6 +224,20 @@ def test_nested_struct(test, device):
205
224
  )
206
225
 
207
226
 
227
+ def test_struct_attribute_error(test, device):
228
+ @wp.kernel
229
+ def kernel(foo: Foo):
230
+ _ = foo.nonexisting
231
+
232
+ with test.assertRaisesRegex(AttributeError, r"`nonexisting` is not an attribute of 'foo' \([\w.]+\.Foo\)$"):
233
+ wp.launch(
234
+ kernel,
235
+ dim=1,
236
+ inputs=[Foo()],
237
+ device=device,
238
+ )
239
+
240
+
208
241
  @wp.kernel
209
242
  def test_struct_instantiate(data: wp.array(dtype=int)):
210
243
  baz = Baz(data, wp.vec3(0.0, 0.0, 26.0))
@@ -259,7 +292,7 @@ def test_struct_math_conversions(test, device):
259
292
  s.m5 = [10, 20, 30, 40]
260
293
  s.m6 = np.array([100, 200, 300, 400])
261
294
 
262
- wp.launch(check_math_conversions, dim=1, inputs=[s])
295
+ wp.launch(check_math_conversions, dim=1, inputs=[s], device=device)
263
296
 
264
297
 
265
298
  @wp.struct
@@ -346,14 +379,12 @@ def test_struct_default_attributes_kernel():
346
379
 
347
380
  @wp.struct
348
381
  class MutableStruct:
349
-
350
382
  param1: int
351
383
  param2: float
352
384
 
353
385
 
354
386
  @wp.kernel
355
387
  def test_struct_mutate_attributes_kernel():
356
-
357
388
  t = MutableStruct()
358
389
  t.param1 = 1
359
390
  t.param2 = 1.1
@@ -362,68 +393,283 @@ def test_struct_mutate_attributes_kernel():
362
393
  wp.expect_eq(t.param2, 1.1)
363
394
 
364
395
 
365
- def register(parent):
366
- devices = get_test_devices()
396
+ @wp.struct
397
+ class InnerStruct:
398
+ i: int
367
399
 
368
- class TestStruct(parent):
369
- pass
370
400
 
371
- add_function_test(TestStruct, "test_step", test_step, devices=devices)
372
- add_function_test(TestStruct, "test_step_grad", test_step_grad, devices=devices)
373
- add_kernel_test(TestStruct, kernel=test_empty, name="test_empty", dim=1, inputs=[Empty()], devices=devices)
374
- add_kernel_test(
375
- TestStruct,
376
- kernel=test_uninitialized,
377
- name="test_uninitialized",
378
- dim=1,
379
- inputs=[Uninitialized()],
380
- devices=devices,
381
- )
382
- add_kernel_test(TestStruct, kernel=test_return, name="test_return", dim=1, inputs=[], devices=devices)
383
- add_function_test(TestStruct, "test_nested_struct", test_nested_struct, devices=devices)
384
- add_function_test(TestStruct, "test_struct_math_conversions", test_struct_math_conversions, devices=devices)
385
- add_function_test(
386
- TestStruct, "test_struct_default_attributes_python", test_struct_default_attributes_python, devices=devices
387
- )
401
+ @wp.struct
402
+ class ArrayStruct:
403
+ array: wp.array(dtype=InnerStruct)
404
+
405
+
406
+ @wp.kernel
407
+ def struct2_reader(test: ArrayStruct):
408
+ k = wp.tid()
409
+ wp.expect_eq(k + 1, test.array[k].i)
410
+
411
+
412
+ def test_nested_array_struct(test, device):
413
+ var1 = InnerStruct()
414
+ var1.i = 1
415
+
416
+ var2 = InnerStruct()
417
+ var2.i = 2
418
+
419
+ struct = ArrayStruct()
420
+ struct.array = wp.array([var1, var2], dtype=InnerStruct, device=device)
421
+
422
+ wp.launch(struct2_reader, dim=2, inputs=[struct], device=device)
423
+
424
+
425
+ @wp.struct
426
+ class EmptyNest1:
427
+ a: Empty
428
+ z: int
429
+
430
+
431
+ @wp.struct
432
+ class EmptyNest2:
433
+ a: Empty
434
+ b: Empty
435
+ z: int
436
+
437
+
438
+ @wp.struct
439
+ class EmptyNest3:
440
+ a: Empty
441
+ b: Empty
442
+ c: Empty
443
+ z: int
444
+
445
+
446
+ @wp.struct
447
+ class EmptyNest4:
448
+ a: Empty
449
+ b: Empty
450
+ c: Empty
451
+ d: Empty
452
+ z: int
453
+
454
+
455
+ @wp.struct
456
+ class EmptyNest5:
457
+ a: Empty
458
+ b: Empty
459
+ c: Empty
460
+ d: Empty
461
+ e: Empty
462
+ z: int
463
+
464
+
465
+ @wp.struct
466
+ class EmptyNest6:
467
+ a: Empty
468
+ b: Empty
469
+ c: Empty
470
+ d: Empty
471
+ e: Empty
472
+ f: Empty
473
+ z: int
474
+
475
+
476
+ @wp.struct
477
+ class EmptyNest7:
478
+ a: Empty
479
+ b: Empty
480
+ c: Empty
481
+ d: Empty
482
+ e: Empty
483
+ f: Empty
484
+ g: Empty
485
+ z: int
486
+
487
+
488
+ @wp.struct
489
+ class EmptyNest8:
490
+ a: Empty
491
+ b: Empty
492
+ c: Empty
493
+ d: Empty
494
+ e: Empty
495
+ f: Empty
496
+ g: Empty
497
+ h: Empty
498
+ z: int
499
+
500
+
501
+ @wp.kernel
502
+ def empty_nest_kernel(s: Any):
503
+ wp.expect_eq(s.z, 42)
504
+
505
+
506
+ wp.overload(empty_nest_kernel, [EmptyNest1])
507
+ wp.overload(empty_nest_kernel, [EmptyNest2])
508
+ wp.overload(empty_nest_kernel, [EmptyNest3])
509
+ wp.overload(empty_nest_kernel, [EmptyNest4])
510
+ wp.overload(empty_nest_kernel, [EmptyNest5])
511
+ wp.overload(empty_nest_kernel, [EmptyNest6])
512
+ wp.overload(empty_nest_kernel, [EmptyNest7])
513
+ wp.overload(empty_nest_kernel, [EmptyNest8])
514
+
515
+
516
+ def test_nested_empty_struct(test, device):
517
+ with wp.ScopedDevice(device):
518
+ e1 = EmptyNest1()
519
+ e1.z = 42
520
+ e2 = EmptyNest2()
521
+ e2.z = 42
522
+ e3 = EmptyNest3()
523
+ e3.z = 42
524
+ e4 = EmptyNest4()
525
+ e4.z = 42
526
+ e5 = EmptyNest5()
527
+ e5.z = 42
528
+ e6 = EmptyNest6()
529
+ e6.z = 42
530
+ e7 = EmptyNest7()
531
+ e7.z = 42
532
+ e8 = EmptyNest8()
533
+ e8.z = 42
534
+
535
+ wp.launch(empty_nest_kernel, dim=1, inputs=[e1])
536
+ wp.launch(empty_nest_kernel, dim=1, inputs=[e2])
537
+ wp.launch(empty_nest_kernel, dim=1, inputs=[e3])
538
+ wp.launch(empty_nest_kernel, dim=1, inputs=[e4])
539
+ wp.launch(empty_nest_kernel, dim=1, inputs=[e5])
540
+ wp.launch(empty_nest_kernel, dim=1, inputs=[e6])
541
+ wp.launch(empty_nest_kernel, dim=1, inputs=[e7])
542
+ wp.launch(empty_nest_kernel, dim=1, inputs=[e8])
543
+
544
+ wp.synchronize_device()
545
+
546
+
547
+ @wp.struct
548
+ class DependentModuleImport_A:
549
+ s: StructFromAnotherModule
550
+
551
+
552
+ @wp.struct
553
+ class DependentModuleImport_B:
554
+ s: StructFromAnotherModule
555
+
556
+
557
+ @wp.struct
558
+ class DependentModuleImport_C:
559
+ a: DependentModuleImport_A
560
+ b: DependentModuleImport_B
561
+
562
+
563
+ @wp.kernel
564
+ def test_dependent_module_import(c: DependentModuleImport_C):
565
+ wp.tid() # nop, we're just testing codegen
566
+
567
+
568
+ devices = get_test_devices()
569
+
570
+
571
+ class TestStruct(unittest.TestCase):
572
+ pass
573
+
574
+
575
+ add_function_test(TestStruct, "test_step", test_step, devices=devices)
576
+ add_function_test(TestStruct, "test_step_grad", test_step_grad, devices=devices)
577
+ add_kernel_test(TestStruct, kernel=test_empty, name="test_empty", dim=1, inputs=[Empty()], devices=devices)
578
+ add_kernel_test(
579
+ TestStruct,
580
+ kernel=test_uninitialized,
581
+ name="test_uninitialized",
582
+ dim=1,
583
+ inputs=[Uninitialized()],
584
+ devices=devices,
585
+ )
586
+ add_kernel_test(TestStruct, kernel=test_return, name="test_return", dim=1, inputs=[], devices=devices)
587
+ add_function_test(TestStruct, "test_nested_struct", test_nested_struct, devices=devices)
588
+ add_function_test(TestStruct, "test_nested_array_struct", test_nested_array_struct, devices=devices)
589
+ add_function_test(TestStruct, "test_nested_empty_struct", test_nested_empty_struct, devices=devices)
590
+ add_function_test(TestStruct, "test_struct_math_conversions", test_struct_math_conversions, devices=devices)
591
+ add_function_test(
592
+ TestStruct, "test_struct_default_attributes_python", test_struct_default_attributes_python, devices=devices
593
+ )
594
+ add_kernel_test(
595
+ TestStruct,
596
+ name="test_struct_default_attributes",
597
+ kernel=test_struct_default_attributes_kernel,
598
+ dim=1,
599
+ inputs=[],
600
+ devices=devices,
601
+ )
602
+
603
+ add_kernel_test(
604
+ TestStruct,
605
+ name="test_struct_mutate_attributes",
606
+ kernel=test_struct_mutate_attributes_kernel,
607
+ dim=1,
608
+ inputs=[],
609
+ devices=devices,
610
+ )
611
+ add_kernel_test(
612
+ TestStruct,
613
+ kernel=test_uninitialized,
614
+ name="test_uninitialized",
615
+ dim=1,
616
+ inputs=[Uninitialized()],
617
+ devices=devices,
618
+ )
619
+ add_kernel_test(TestStruct, kernel=test_return, name="test_return", dim=1, inputs=[], devices=devices)
620
+ add_function_test(TestStruct, "test_nested_struct", test_nested_struct, devices=devices)
621
+ add_function_test(TestStruct, "test_nested_array_struct", test_nested_array_struct, devices=devices)
622
+ add_function_test(TestStruct, "test_nested_empty_struct", test_nested_empty_struct, devices=devices)
623
+ add_function_test(TestStruct, "test_struct_math_conversions", test_struct_math_conversions, devices=devices)
624
+ add_function_test(
625
+ TestStruct, "test_struct_default_attributes_python", test_struct_default_attributes_python, devices=devices
626
+ )
627
+ add_kernel_test(
628
+ TestStruct,
629
+ name="test_struct_default_attributes",
630
+ kernel=test_struct_default_attributes_kernel,
631
+ dim=1,
632
+ inputs=[],
633
+ devices=devices,
634
+ )
635
+
636
+ add_kernel_test(
637
+ TestStruct,
638
+ name="test_struct_mutate_attributes",
639
+ kernel=test_struct_mutate_attributes_kernel,
640
+ dim=1,
641
+ inputs=[],
642
+ devices=devices,
643
+ )
644
+
645
+ for device in devices:
388
646
  add_kernel_test(
389
647
  TestStruct,
390
- name="test_struct_default_attributes",
391
- kernel=test_struct_default_attributes_kernel,
648
+ kernel=test_struct_instantiate,
649
+ name="test_struct_instantiate",
392
650
  dim=1,
393
- inputs=[],
394
- devices=devices,
651
+ inputs=[wp.array([1], dtype=int, device=device)],
652
+ devices=[device],
395
653
  )
396
-
397
654
  add_kernel_test(
398
655
  TestStruct,
399
- name="test_struct_mutate_attributes",
400
- kernel=test_struct_mutate_attributes_kernel,
656
+ kernel=test_return_struct,
657
+ name="test_return_struct",
401
658
  dim=1,
402
- inputs=[],
403
- devices=devices,
659
+ inputs=[wp.zeros(10, dtype=int, device=device)],
660
+ devices=[device],
404
661
  )
405
662
 
406
- for device in devices:
407
- add_kernel_test(
408
- TestStruct,
409
- kernel=test_struct_instantiate,
410
- name="test_struct_instantiate",
411
- dim=1,
412
- inputs=[wp.array([1], dtype=int, device=device)],
413
- devices=[device],
414
- )
415
- add_kernel_test(
416
- TestStruct,
417
- kernel=test_return_struct,
418
- name="test_return_struct",
419
- dim=1,
420
- inputs=[wp.zeros(10, dtype=int, device=device)],
421
- devices=[device],
422
- )
423
-
424
- return TestStruct
663
+ add_kernel_test(
664
+ TestStruct,
665
+ kernel=test_dependent_module_import,
666
+ name="test_dependent_module_import",
667
+ dim=1,
668
+ inputs=[DependentModuleImport_C()],
669
+ devices=devices,
670
+ )
425
671
 
426
672
 
427
673
  if __name__ == "__main__":
428
- c = register(unittest.TestCase)
674
+ wp.build.clear_kernel_cache()
429
675
  unittest.main(verbosity=2)
warp/tests/test_tape.py CHANGED
@@ -5,9 +5,12 @@
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 unittest
9
+
8
10
  import numpy as np
11
+
9
12
  import warp as wp
10
- from warp.tests.test_base import *
13
+ from warp.tests.unittest_utils import *
11
14
 
12
15
  wp.init()
13
16
 
@@ -19,11 +22,17 @@ def mul_constant(x: wp.array(dtype=float), y: wp.array(dtype=float)):
19
22
  y[tid] = x[tid] * 2.0
20
23
 
21
24
 
25
+ @wp.struct
26
+ class Multiplicands:
27
+ x: wp.array(dtype=float)
28
+ y: wp.array(dtype=float)
29
+
30
+
22
31
  @wp.kernel
23
- def mul_variable(x: wp.array(dtype=float), y: wp.array(dtype=float), z: wp.array(dtype=float)):
32
+ def mul_variable(mutiplicands: Multiplicands, z: wp.array(dtype=float)):
24
33
  tid = wp.tid()
25
34
 
26
- z[tid] = x[tid] * y[tid]
35
+ z[tid] = mutiplicands.x[tid] * mutiplicands.y[tid]
27
36
 
28
37
 
29
38
  @wp.kernel
@@ -65,12 +74,13 @@ def test_tape_mul_variable(test, device):
65
74
 
66
75
  # record onto tape
67
76
  with tape:
68
- # input data
69
- x = wp.array(np.ones(dim) * 16.0, dtype=wp.float32, device=device, requires_grad=True)
70
- y = wp.array(np.ones(dim) * 32.0, dtype=wp.float32, device=device, requires_grad=True)
71
- z = wp.zeros_like(x)
77
+ # input data (Note: We're intentionally testing structs in tapes here)
78
+ multiplicands = Multiplicands()
79
+ multiplicands.x = wp.array(np.ones(dim) * 16.0, dtype=wp.float32, device=device, requires_grad=True)
80
+ multiplicands.y = wp.array(np.ones(dim) * 32.0, dtype=wp.float32, device=device, requires_grad=True)
81
+ z = wp.zeros_like(multiplicands.x)
72
82
 
73
- wp.launch(kernel=mul_variable, dim=dim, inputs=[x, y], outputs=[z], device=device)
83
+ wp.launch(kernel=mul_variable, dim=dim, inputs=[multiplicands], outputs=[z], device=device)
74
84
 
75
85
  # loss = wp.sum(x)
76
86
  z.grad = wp.array(np.ones(dim), device=device, dtype=wp.float32)
@@ -79,16 +89,21 @@ def test_tape_mul_variable(test, device):
79
89
  tape.backward()
80
90
 
81
91
  # grad_x=y, grad_y=x
82
- assert_np_equal(tape.gradients[x].numpy(), y.numpy())
83
- assert_np_equal(tape.gradients[y].numpy(), x.numpy())
92
+ assert_np_equal(tape.gradients[multiplicands].x.numpy(), multiplicands.y.numpy())
93
+ assert_np_equal(tape.gradients[multiplicands].y.numpy(), multiplicands.x.numpy())
84
94
 
85
95
  # run backward again with different incoming gradient
86
96
  # should accumulate the same gradients again onto output
87
97
  # so gradients = 2.0*prev
88
98
  tape.backward()
89
99
 
90
- assert_np_equal(tape.gradients[x].numpy(), y.numpy() * 2.0)
91
- assert_np_equal(tape.gradients[y].numpy(), x.numpy() * 2.0)
100
+ assert_np_equal(tape.gradients[multiplicands].x.numpy(), multiplicands.y.numpy() * 2.0)
101
+ assert_np_equal(tape.gradients[multiplicands].y.numpy(), multiplicands.x.numpy() * 2.0)
102
+
103
+ # Clear launches and zero out the gradients
104
+ tape.reset()
105
+ assert_np_equal(tape.gradients[multiplicands].x.numpy(), np.zeros_like(tape.gradients[multiplicands].x.numpy()))
106
+ test.assertFalse(tape.launches)
92
107
 
93
108
 
94
109
  def test_tape_dot_product(test, device):
@@ -112,19 +127,22 @@ def test_tape_dot_product(test, device):
112
127
  assert_np_equal(tape.gradients[y].numpy(), x.numpy())
113
128
 
114
129
 
115
- def register(parent):
116
- devices = get_test_devices()
130
+ devices = get_test_devices()
131
+
117
132
 
118
- class TestTape(parent):
119
- pass
133
+ class TestTape(unittest.TestCase):
134
+ def test_tape_no_nested_tapes(self):
135
+ with self.assertRaises(RuntimeError):
136
+ with wp.Tape():
137
+ with wp.Tape():
138
+ pass
120
139
 
121
- add_function_test(TestTape, "test_tape_mul_constant", test_tape_mul_constant, devices=devices)
122
- add_function_test(TestTape, "test_tape_mul_variable", test_tape_mul_variable, devices=devices)
123
- add_function_test(TestTape, "test_tape_dot_product", test_tape_dot_product, devices=devices)
124
140
 
125
- return TestTape
141
+ add_function_test(TestTape, "test_tape_mul_constant", test_tape_mul_constant, devices=devices)
142
+ add_function_test(TestTape, "test_tape_mul_variable", test_tape_mul_variable, devices=devices)
143
+ add_function_test(TestTape, "test_tape_dot_product", test_tape_dot_product, devices=devices)
126
144
 
127
145
 
128
146
  if __name__ == "__main__":
129
- c = register(unittest.TestCase)
147
+ wp.build.clear_kernel_cache()
130
148
  unittest.main(verbosity=2)