warp-lang 1.7.0__py3-none-manylinux_2_34_aarch64.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 (429) hide show
  1. warp/__init__.py +139 -0
  2. warp/__init__.pyi +1 -0
  3. warp/autograd.py +1142 -0
  4. warp/bin/warp-clang.so +0 -0
  5. warp/bin/warp.so +0 -0
  6. warp/build.py +557 -0
  7. warp/build_dll.py +405 -0
  8. warp/builtins.py +6855 -0
  9. warp/codegen.py +3969 -0
  10. warp/config.py +158 -0
  11. warp/constants.py +57 -0
  12. warp/context.py +6812 -0
  13. warp/dlpack.py +462 -0
  14. warp/examples/__init__.py +24 -0
  15. warp/examples/assets/bear.usd +0 -0
  16. warp/examples/assets/bunny.usd +0 -0
  17. warp/examples/assets/cartpole.urdf +110 -0
  18. warp/examples/assets/crazyflie.usd +0 -0
  19. warp/examples/assets/cube.usd +0 -0
  20. warp/examples/assets/nonuniform.usd +0 -0
  21. warp/examples/assets/nv_ant.xml +92 -0
  22. warp/examples/assets/nv_humanoid.xml +183 -0
  23. warp/examples/assets/nvidia_logo.png +0 -0
  24. warp/examples/assets/pixel.jpg +0 -0
  25. warp/examples/assets/quadruped.urdf +268 -0
  26. warp/examples/assets/rocks.nvdb +0 -0
  27. warp/examples/assets/rocks.usd +0 -0
  28. warp/examples/assets/sphere.usd +0 -0
  29. warp/examples/assets/square_cloth.usd +0 -0
  30. warp/examples/benchmarks/benchmark_api.py +389 -0
  31. warp/examples/benchmarks/benchmark_cloth.py +296 -0
  32. warp/examples/benchmarks/benchmark_cloth_cupy.py +96 -0
  33. warp/examples/benchmarks/benchmark_cloth_jax.py +105 -0
  34. warp/examples/benchmarks/benchmark_cloth_numba.py +161 -0
  35. warp/examples/benchmarks/benchmark_cloth_numpy.py +85 -0
  36. warp/examples/benchmarks/benchmark_cloth_paddle.py +94 -0
  37. warp/examples/benchmarks/benchmark_cloth_pytorch.py +94 -0
  38. warp/examples/benchmarks/benchmark_cloth_taichi.py +120 -0
  39. warp/examples/benchmarks/benchmark_cloth_warp.py +153 -0
  40. warp/examples/benchmarks/benchmark_gemm.py +164 -0
  41. warp/examples/benchmarks/benchmark_interop_paddle.py +166 -0
  42. warp/examples/benchmarks/benchmark_interop_torch.py +166 -0
  43. warp/examples/benchmarks/benchmark_launches.py +301 -0
  44. warp/examples/benchmarks/benchmark_tile_load_store.py +103 -0
  45. warp/examples/browse.py +37 -0
  46. warp/examples/core/example_cupy.py +86 -0
  47. warp/examples/core/example_dem.py +241 -0
  48. warp/examples/core/example_fluid.py +299 -0
  49. warp/examples/core/example_graph_capture.py +150 -0
  50. warp/examples/core/example_marching_cubes.py +194 -0
  51. warp/examples/core/example_mesh.py +180 -0
  52. warp/examples/core/example_mesh_intersect.py +211 -0
  53. warp/examples/core/example_nvdb.py +182 -0
  54. warp/examples/core/example_raycast.py +111 -0
  55. warp/examples/core/example_raymarch.py +205 -0
  56. warp/examples/core/example_render_opengl.py +193 -0
  57. warp/examples/core/example_sample_mesh.py +300 -0
  58. warp/examples/core/example_sph.py +411 -0
  59. warp/examples/core/example_torch.py +211 -0
  60. warp/examples/core/example_wave.py +269 -0
  61. warp/examples/fem/example_adaptive_grid.py +286 -0
  62. warp/examples/fem/example_apic_fluid.py +423 -0
  63. warp/examples/fem/example_burgers.py +261 -0
  64. warp/examples/fem/example_convection_diffusion.py +178 -0
  65. warp/examples/fem/example_convection_diffusion_dg.py +204 -0
  66. warp/examples/fem/example_deformed_geometry.py +172 -0
  67. warp/examples/fem/example_diffusion.py +196 -0
  68. warp/examples/fem/example_diffusion_3d.py +225 -0
  69. warp/examples/fem/example_diffusion_mgpu.py +220 -0
  70. warp/examples/fem/example_distortion_energy.py +228 -0
  71. warp/examples/fem/example_magnetostatics.py +240 -0
  72. warp/examples/fem/example_mixed_elasticity.py +291 -0
  73. warp/examples/fem/example_navier_stokes.py +261 -0
  74. warp/examples/fem/example_nonconforming_contact.py +298 -0
  75. warp/examples/fem/example_stokes.py +213 -0
  76. warp/examples/fem/example_stokes_transfer.py +262 -0
  77. warp/examples/fem/example_streamlines.py +352 -0
  78. warp/examples/fem/utils.py +1000 -0
  79. warp/examples/interop/example_jax_callable.py +116 -0
  80. warp/examples/interop/example_jax_ffi_callback.py +132 -0
  81. warp/examples/interop/example_jax_kernel.py +205 -0
  82. warp/examples/optim/example_bounce.py +266 -0
  83. warp/examples/optim/example_cloth_throw.py +228 -0
  84. warp/examples/optim/example_diffray.py +561 -0
  85. warp/examples/optim/example_drone.py +870 -0
  86. warp/examples/optim/example_fluid_checkpoint.py +497 -0
  87. warp/examples/optim/example_inverse_kinematics.py +182 -0
  88. warp/examples/optim/example_inverse_kinematics_torch.py +191 -0
  89. warp/examples/optim/example_softbody_properties.py +400 -0
  90. warp/examples/optim/example_spring_cage.py +245 -0
  91. warp/examples/optim/example_trajectory.py +227 -0
  92. warp/examples/sim/example_cartpole.py +143 -0
  93. warp/examples/sim/example_cloth.py +225 -0
  94. warp/examples/sim/example_cloth_self_contact.py +322 -0
  95. warp/examples/sim/example_granular.py +130 -0
  96. warp/examples/sim/example_granular_collision_sdf.py +202 -0
  97. warp/examples/sim/example_jacobian_ik.py +244 -0
  98. warp/examples/sim/example_particle_chain.py +124 -0
  99. warp/examples/sim/example_quadruped.py +203 -0
  100. warp/examples/sim/example_rigid_chain.py +203 -0
  101. warp/examples/sim/example_rigid_contact.py +195 -0
  102. warp/examples/sim/example_rigid_force.py +133 -0
  103. warp/examples/sim/example_rigid_gyroscopic.py +115 -0
  104. warp/examples/sim/example_rigid_soft_contact.py +140 -0
  105. warp/examples/sim/example_soft_body.py +196 -0
  106. warp/examples/tile/example_tile_cholesky.py +87 -0
  107. warp/examples/tile/example_tile_convolution.py +66 -0
  108. warp/examples/tile/example_tile_fft.py +55 -0
  109. warp/examples/tile/example_tile_filtering.py +113 -0
  110. warp/examples/tile/example_tile_matmul.py +85 -0
  111. warp/examples/tile/example_tile_mlp.py +383 -0
  112. warp/examples/tile/example_tile_nbody.py +199 -0
  113. warp/examples/tile/example_tile_walker.py +327 -0
  114. warp/fabric.py +355 -0
  115. warp/fem/__init__.py +106 -0
  116. warp/fem/adaptivity.py +508 -0
  117. warp/fem/cache.py +572 -0
  118. warp/fem/dirichlet.py +202 -0
  119. warp/fem/domain.py +411 -0
  120. warp/fem/field/__init__.py +125 -0
  121. warp/fem/field/field.py +619 -0
  122. warp/fem/field/nodal_field.py +326 -0
  123. warp/fem/field/restriction.py +37 -0
  124. warp/fem/field/virtual.py +848 -0
  125. warp/fem/geometry/__init__.py +32 -0
  126. warp/fem/geometry/adaptive_nanogrid.py +857 -0
  127. warp/fem/geometry/closest_point.py +84 -0
  128. warp/fem/geometry/deformed_geometry.py +221 -0
  129. warp/fem/geometry/element.py +776 -0
  130. warp/fem/geometry/geometry.py +362 -0
  131. warp/fem/geometry/grid_2d.py +392 -0
  132. warp/fem/geometry/grid_3d.py +452 -0
  133. warp/fem/geometry/hexmesh.py +911 -0
  134. warp/fem/geometry/nanogrid.py +571 -0
  135. warp/fem/geometry/partition.py +389 -0
  136. warp/fem/geometry/quadmesh.py +663 -0
  137. warp/fem/geometry/tetmesh.py +855 -0
  138. warp/fem/geometry/trimesh.py +806 -0
  139. warp/fem/integrate.py +2335 -0
  140. warp/fem/linalg.py +419 -0
  141. warp/fem/operator.py +293 -0
  142. warp/fem/polynomial.py +229 -0
  143. warp/fem/quadrature/__init__.py +17 -0
  144. warp/fem/quadrature/pic_quadrature.py +299 -0
  145. warp/fem/quadrature/quadrature.py +591 -0
  146. warp/fem/space/__init__.py +228 -0
  147. warp/fem/space/basis_function_space.py +468 -0
  148. warp/fem/space/basis_space.py +667 -0
  149. warp/fem/space/dof_mapper.py +251 -0
  150. warp/fem/space/function_space.py +309 -0
  151. warp/fem/space/grid_2d_function_space.py +177 -0
  152. warp/fem/space/grid_3d_function_space.py +227 -0
  153. warp/fem/space/hexmesh_function_space.py +257 -0
  154. warp/fem/space/nanogrid_function_space.py +201 -0
  155. warp/fem/space/partition.py +367 -0
  156. warp/fem/space/quadmesh_function_space.py +223 -0
  157. warp/fem/space/restriction.py +179 -0
  158. warp/fem/space/shape/__init__.py +143 -0
  159. warp/fem/space/shape/cube_shape_function.py +1105 -0
  160. warp/fem/space/shape/shape_function.py +133 -0
  161. warp/fem/space/shape/square_shape_function.py +926 -0
  162. warp/fem/space/shape/tet_shape_function.py +834 -0
  163. warp/fem/space/shape/triangle_shape_function.py +672 -0
  164. warp/fem/space/tetmesh_function_space.py +271 -0
  165. warp/fem/space/topology.py +424 -0
  166. warp/fem/space/trimesh_function_space.py +194 -0
  167. warp/fem/types.py +99 -0
  168. warp/fem/utils.py +420 -0
  169. warp/jax.py +187 -0
  170. warp/jax_experimental/__init__.py +16 -0
  171. warp/jax_experimental/custom_call.py +351 -0
  172. warp/jax_experimental/ffi.py +698 -0
  173. warp/jax_experimental/xla_ffi.py +602 -0
  174. warp/math.py +244 -0
  175. warp/native/array.h +1145 -0
  176. warp/native/builtin.h +1800 -0
  177. warp/native/bvh.cpp +492 -0
  178. warp/native/bvh.cu +791 -0
  179. warp/native/bvh.h +554 -0
  180. warp/native/clang/clang.cpp +536 -0
  181. warp/native/coloring.cpp +613 -0
  182. warp/native/crt.cpp +51 -0
  183. warp/native/crt.h +362 -0
  184. warp/native/cuda_crt.h +1058 -0
  185. warp/native/cuda_util.cpp +646 -0
  186. warp/native/cuda_util.h +307 -0
  187. warp/native/error.cpp +77 -0
  188. warp/native/error.h +36 -0
  189. warp/native/exports.h +1878 -0
  190. warp/native/fabric.h +245 -0
  191. warp/native/hashgrid.cpp +311 -0
  192. warp/native/hashgrid.cu +87 -0
  193. warp/native/hashgrid.h +240 -0
  194. warp/native/initializer_array.h +41 -0
  195. warp/native/intersect.h +1230 -0
  196. warp/native/intersect_adj.h +375 -0
  197. warp/native/intersect_tri.h +339 -0
  198. warp/native/marching.cpp +19 -0
  199. warp/native/marching.cu +514 -0
  200. warp/native/marching.h +19 -0
  201. warp/native/mat.h +2220 -0
  202. warp/native/mathdx.cpp +87 -0
  203. warp/native/matnn.h +343 -0
  204. warp/native/mesh.cpp +266 -0
  205. warp/native/mesh.cu +404 -0
  206. warp/native/mesh.h +1980 -0
  207. warp/native/nanovdb/GridHandle.h +366 -0
  208. warp/native/nanovdb/HostBuffer.h +590 -0
  209. warp/native/nanovdb/NanoVDB.h +6624 -0
  210. warp/native/nanovdb/PNanoVDB.h +3390 -0
  211. warp/native/noise.h +859 -0
  212. warp/native/quat.h +1371 -0
  213. warp/native/rand.h +342 -0
  214. warp/native/range.h +139 -0
  215. warp/native/reduce.cpp +174 -0
  216. warp/native/reduce.cu +364 -0
  217. warp/native/runlength_encode.cpp +79 -0
  218. warp/native/runlength_encode.cu +61 -0
  219. warp/native/scan.cpp +47 -0
  220. warp/native/scan.cu +53 -0
  221. warp/native/scan.h +23 -0
  222. warp/native/solid_angle.h +466 -0
  223. warp/native/sort.cpp +251 -0
  224. warp/native/sort.cu +277 -0
  225. warp/native/sort.h +33 -0
  226. warp/native/sparse.cpp +378 -0
  227. warp/native/sparse.cu +524 -0
  228. warp/native/spatial.h +657 -0
  229. warp/native/svd.h +702 -0
  230. warp/native/temp_buffer.h +46 -0
  231. warp/native/tile.h +2584 -0
  232. warp/native/tile_reduce.h +264 -0
  233. warp/native/vec.h +1426 -0
  234. warp/native/volume.cpp +501 -0
  235. warp/native/volume.cu +67 -0
  236. warp/native/volume.h +969 -0
  237. warp/native/volume_builder.cu +477 -0
  238. warp/native/volume_builder.h +52 -0
  239. warp/native/volume_impl.h +70 -0
  240. warp/native/warp.cpp +1082 -0
  241. warp/native/warp.cu +3636 -0
  242. warp/native/warp.h +381 -0
  243. warp/optim/__init__.py +17 -0
  244. warp/optim/adam.py +163 -0
  245. warp/optim/linear.py +1137 -0
  246. warp/optim/sgd.py +112 -0
  247. warp/paddle.py +407 -0
  248. warp/render/__init__.py +18 -0
  249. warp/render/render_opengl.py +3518 -0
  250. warp/render/render_usd.py +784 -0
  251. warp/render/utils.py +160 -0
  252. warp/sim/__init__.py +65 -0
  253. warp/sim/articulation.py +793 -0
  254. warp/sim/collide.py +2395 -0
  255. warp/sim/graph_coloring.py +300 -0
  256. warp/sim/import_mjcf.py +790 -0
  257. warp/sim/import_snu.py +227 -0
  258. warp/sim/import_urdf.py +579 -0
  259. warp/sim/import_usd.py +894 -0
  260. warp/sim/inertia.py +324 -0
  261. warp/sim/integrator.py +242 -0
  262. warp/sim/integrator_euler.py +1997 -0
  263. warp/sim/integrator_featherstone.py +2101 -0
  264. warp/sim/integrator_vbd.py +2048 -0
  265. warp/sim/integrator_xpbd.py +3292 -0
  266. warp/sim/model.py +4791 -0
  267. warp/sim/particles.py +121 -0
  268. warp/sim/render.py +427 -0
  269. warp/sim/utils.py +428 -0
  270. warp/sparse.py +2057 -0
  271. warp/stubs.py +3333 -0
  272. warp/tape.py +1203 -0
  273. warp/tests/__init__.py +1 -0
  274. warp/tests/__main__.py +4 -0
  275. warp/tests/assets/curlnoise_golden.npy +0 -0
  276. warp/tests/assets/mlp_golden.npy +0 -0
  277. warp/tests/assets/pixel.npy +0 -0
  278. warp/tests/assets/pnoise_golden.npy +0 -0
  279. warp/tests/assets/spiky.usd +0 -0
  280. warp/tests/assets/test_grid.nvdb +0 -0
  281. warp/tests/assets/test_index_grid.nvdb +0 -0
  282. warp/tests/assets/test_int32_grid.nvdb +0 -0
  283. warp/tests/assets/test_vec_grid.nvdb +0 -0
  284. warp/tests/assets/torus.nvdb +0 -0
  285. warp/tests/assets/torus.usda +105 -0
  286. warp/tests/aux_test_class_kernel.py +34 -0
  287. warp/tests/aux_test_compile_consts_dummy.py +18 -0
  288. warp/tests/aux_test_conditional_unequal_types_kernels.py +29 -0
  289. warp/tests/aux_test_dependent.py +29 -0
  290. warp/tests/aux_test_grad_customs.py +29 -0
  291. warp/tests/aux_test_instancing_gc.py +26 -0
  292. warp/tests/aux_test_module_unload.py +23 -0
  293. warp/tests/aux_test_name_clash1.py +40 -0
  294. warp/tests/aux_test_name_clash2.py +40 -0
  295. warp/tests/aux_test_reference.py +9 -0
  296. warp/tests/aux_test_reference_reference.py +8 -0
  297. warp/tests/aux_test_square.py +16 -0
  298. warp/tests/aux_test_unresolved_func.py +22 -0
  299. warp/tests/aux_test_unresolved_symbol.py +22 -0
  300. warp/tests/cuda/__init__.py +0 -0
  301. warp/tests/cuda/test_async.py +676 -0
  302. warp/tests/cuda/test_ipc.py +124 -0
  303. warp/tests/cuda/test_mempool.py +233 -0
  304. warp/tests/cuda/test_multigpu.py +169 -0
  305. warp/tests/cuda/test_peer.py +139 -0
  306. warp/tests/cuda/test_pinned.py +84 -0
  307. warp/tests/cuda/test_streams.py +634 -0
  308. warp/tests/geometry/__init__.py +0 -0
  309. warp/tests/geometry/test_bvh.py +200 -0
  310. warp/tests/geometry/test_hash_grid.py +221 -0
  311. warp/tests/geometry/test_marching_cubes.py +74 -0
  312. warp/tests/geometry/test_mesh.py +316 -0
  313. warp/tests/geometry/test_mesh_query_aabb.py +399 -0
  314. warp/tests/geometry/test_mesh_query_point.py +932 -0
  315. warp/tests/geometry/test_mesh_query_ray.py +311 -0
  316. warp/tests/geometry/test_volume.py +1103 -0
  317. warp/tests/geometry/test_volume_write.py +346 -0
  318. warp/tests/interop/__init__.py +0 -0
  319. warp/tests/interop/test_dlpack.py +729 -0
  320. warp/tests/interop/test_jax.py +371 -0
  321. warp/tests/interop/test_paddle.py +800 -0
  322. warp/tests/interop/test_torch.py +1001 -0
  323. warp/tests/run_coverage_serial.py +39 -0
  324. warp/tests/sim/__init__.py +0 -0
  325. warp/tests/sim/disabled_kinematics.py +244 -0
  326. warp/tests/sim/flaky_test_sim_grad.py +290 -0
  327. warp/tests/sim/test_collision.py +604 -0
  328. warp/tests/sim/test_coloring.py +258 -0
  329. warp/tests/sim/test_model.py +224 -0
  330. warp/tests/sim/test_sim_grad_bounce_linear.py +212 -0
  331. warp/tests/sim/test_sim_kinematics.py +98 -0
  332. warp/tests/sim/test_vbd.py +597 -0
  333. warp/tests/test_adam.py +163 -0
  334. warp/tests/test_arithmetic.py +1096 -0
  335. warp/tests/test_array.py +2972 -0
  336. warp/tests/test_array_reduce.py +156 -0
  337. warp/tests/test_assert.py +250 -0
  338. warp/tests/test_atomic.py +153 -0
  339. warp/tests/test_bool.py +220 -0
  340. warp/tests/test_builtins_resolution.py +1298 -0
  341. warp/tests/test_closest_point_edge_edge.py +327 -0
  342. warp/tests/test_codegen.py +810 -0
  343. warp/tests/test_codegen_instancing.py +1495 -0
  344. warp/tests/test_compile_consts.py +215 -0
  345. warp/tests/test_conditional.py +252 -0
  346. warp/tests/test_context.py +42 -0
  347. warp/tests/test_copy.py +238 -0
  348. warp/tests/test_ctypes.py +638 -0
  349. warp/tests/test_dense.py +73 -0
  350. warp/tests/test_devices.py +97 -0
  351. warp/tests/test_examples.py +482 -0
  352. warp/tests/test_fabricarray.py +996 -0
  353. warp/tests/test_fast_math.py +74 -0
  354. warp/tests/test_fem.py +2003 -0
  355. warp/tests/test_fp16.py +136 -0
  356. warp/tests/test_func.py +454 -0
  357. warp/tests/test_future_annotations.py +98 -0
  358. warp/tests/test_generics.py +656 -0
  359. warp/tests/test_grad.py +893 -0
  360. warp/tests/test_grad_customs.py +339 -0
  361. warp/tests/test_grad_debug.py +341 -0
  362. warp/tests/test_implicit_init.py +411 -0
  363. warp/tests/test_import.py +45 -0
  364. warp/tests/test_indexedarray.py +1140 -0
  365. warp/tests/test_intersect.py +73 -0
  366. warp/tests/test_iter.py +76 -0
  367. warp/tests/test_large.py +177 -0
  368. warp/tests/test_launch.py +411 -0
  369. warp/tests/test_lerp.py +151 -0
  370. warp/tests/test_linear_solvers.py +193 -0
  371. warp/tests/test_lvalue.py +427 -0
  372. warp/tests/test_mat.py +2089 -0
  373. warp/tests/test_mat_lite.py +122 -0
  374. warp/tests/test_mat_scalar_ops.py +2913 -0
  375. warp/tests/test_math.py +178 -0
  376. warp/tests/test_mlp.py +282 -0
  377. warp/tests/test_module_hashing.py +258 -0
  378. warp/tests/test_modules_lite.py +44 -0
  379. warp/tests/test_noise.py +252 -0
  380. warp/tests/test_operators.py +299 -0
  381. warp/tests/test_options.py +129 -0
  382. warp/tests/test_overwrite.py +551 -0
  383. warp/tests/test_print.py +339 -0
  384. warp/tests/test_quat.py +2315 -0
  385. warp/tests/test_rand.py +339 -0
  386. warp/tests/test_reload.py +302 -0
  387. warp/tests/test_rounding.py +185 -0
  388. warp/tests/test_runlength_encode.py +196 -0
  389. warp/tests/test_scalar_ops.py +105 -0
  390. warp/tests/test_smoothstep.py +108 -0
  391. warp/tests/test_snippet.py +318 -0
  392. warp/tests/test_sparse.py +582 -0
  393. warp/tests/test_spatial.py +2229 -0
  394. warp/tests/test_special_values.py +361 -0
  395. warp/tests/test_static.py +592 -0
  396. warp/tests/test_struct.py +734 -0
  397. warp/tests/test_tape.py +204 -0
  398. warp/tests/test_transient_module.py +93 -0
  399. warp/tests/test_triangle_closest_point.py +145 -0
  400. warp/tests/test_types.py +562 -0
  401. warp/tests/test_utils.py +588 -0
  402. warp/tests/test_vec.py +1487 -0
  403. warp/tests/test_vec_lite.py +80 -0
  404. warp/tests/test_vec_scalar_ops.py +2327 -0
  405. warp/tests/test_verify_fp.py +100 -0
  406. warp/tests/tile/__init__.py +0 -0
  407. warp/tests/tile/test_tile.py +780 -0
  408. warp/tests/tile/test_tile_load.py +407 -0
  409. warp/tests/tile/test_tile_mathdx.py +208 -0
  410. warp/tests/tile/test_tile_mlp.py +402 -0
  411. warp/tests/tile/test_tile_reduce.py +447 -0
  412. warp/tests/tile/test_tile_shared_memory.py +247 -0
  413. warp/tests/tile/test_tile_view.py +173 -0
  414. warp/tests/unittest_serial.py +47 -0
  415. warp/tests/unittest_suites.py +427 -0
  416. warp/tests/unittest_utils.py +468 -0
  417. warp/tests/walkthrough_debug.py +93 -0
  418. warp/thirdparty/__init__.py +0 -0
  419. warp/thirdparty/appdirs.py +598 -0
  420. warp/thirdparty/dlpack.py +145 -0
  421. warp/thirdparty/unittest_parallel.py +570 -0
  422. warp/torch.py +391 -0
  423. warp/types.py +5230 -0
  424. warp/utils.py +1137 -0
  425. warp_lang-1.7.0.dist-info/METADATA +516 -0
  426. warp_lang-1.7.0.dist-info/RECORD +429 -0
  427. warp_lang-1.7.0.dist-info/WHEEL +5 -0
  428. warp_lang-1.7.0.dist-info/licenses/LICENSE.md +202 -0
  429. warp_lang-1.7.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,780 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2024 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
+ TILE_M = wp.constant(8)
24
+ TILE_N = wp.constant(4)
25
+ TILE_K = wp.constant(8)
26
+
27
+ # num threads per-tile
28
+ TILE_DIM = 64
29
+
30
+
31
+ @wp.kernel
32
+ def tile_copy_1d_kernel(A: wp.array(dtype=float), B: wp.array(dtype=float)):
33
+ # tile index
34
+ i = wp.tid()
35
+
36
+ a = wp.tile_load(A, shape=TILE_N, offset=i * TILE_N)
37
+ wp.tile_store(B, a, offset=i * TILE_N)
38
+
39
+
40
+ def test_tile_copy_1d(test, device):
41
+ rng = np.random.default_rng(42)
42
+
43
+ N = TILE_N * 5
44
+
45
+ A = rng.random((N), dtype=np.float32)
46
+ B = rng.random((N), dtype=np.float32)
47
+
48
+ A_wp = wp.array(A, requires_grad=True, device=device)
49
+ B_wp = wp.array(B, requires_grad=True, device=device)
50
+
51
+ with wp.Tape() as tape:
52
+ wp.launch_tiled(
53
+ tile_copy_1d_kernel,
54
+ dim=[int(N / TILE_N)],
55
+ inputs=[A_wp, B_wp],
56
+ block_dim=TILE_DIM,
57
+ device=device,
58
+ )
59
+
60
+ # verify forward pass
61
+ assert_array_equal(B_wp, A_wp)
62
+
63
+ # verify backward pass
64
+ B_wp.grad = wp.ones_like(B_wp, device=device)
65
+ tape.backward()
66
+
67
+ assert_array_equal(B_wp.grad, A_wp.grad)
68
+
69
+
70
+ @wp.kernel
71
+ def tile_copy_2d_kernel(A: wp.array2d(dtype=float), B: wp.array2d(dtype=float)):
72
+ # tile index
73
+ i, j = wp.tid()
74
+
75
+ a = wp.tile_load(A, shape=(TILE_M, TILE_N), offset=(i * TILE_M, j * TILE_N))
76
+ wp.tile_store(B, a, offset=(i * TILE_M, j * TILE_N))
77
+
78
+
79
+ def test_tile_copy_2d(test, device):
80
+ rng = np.random.default_rng(42)
81
+
82
+ M = TILE_M * 7
83
+ N = TILE_N * 5
84
+
85
+ A = rng.random((M, N), dtype=np.float32)
86
+ B = rng.random((M, N), dtype=np.float32)
87
+
88
+ A_wp = wp.array(A, requires_grad=True, device=device)
89
+ B_wp = wp.array(B, requires_grad=True, device=device)
90
+
91
+ with wp.Tape() as tape:
92
+ wp.launch_tiled(
93
+ tile_copy_2d_kernel,
94
+ dim=[int(M / TILE_M), int(N / TILE_N)],
95
+ inputs=[A_wp, B_wp],
96
+ block_dim=TILE_DIM,
97
+ device=device,
98
+ )
99
+
100
+ # verify forward pass
101
+ assert_array_equal(B_wp, A_wp)
102
+
103
+ # verify backward pass
104
+ B_wp.grad = wp.ones_like(B_wp, device=device)
105
+ tape.backward()
106
+
107
+ assert_array_equal(B_wp.grad, A_wp.grad)
108
+
109
+
110
+ @wp.func
111
+ def unary_func(x: float):
112
+ return wp.sin(x)
113
+
114
+
115
+ @wp.kernel
116
+ def tile_unary_map(input: wp.array2d(dtype=float), output: wp.array2d(dtype=float)):
117
+ # tile index
118
+ i, j = wp.tid()
119
+
120
+ a = wp.tile_load(input, shape=(TILE_M, TILE_N), offset=(i * TILE_M, j * TILE_N))
121
+
122
+ sa = wp.tile_map(wp.sin, a)
123
+
124
+ wp.tile_store(output, sa, offset=(i * TILE_M, j * TILE_N))
125
+
126
+
127
+ def test_tile_unary_map(test, device):
128
+ rng = np.random.default_rng(42)
129
+
130
+ M = TILE_M * 7
131
+ N = TILE_N * 5
132
+
133
+ A = rng.random((M, N), dtype=np.float32)
134
+ B = np.sin(A)
135
+
136
+ A_grad = np.cos(A)
137
+
138
+ A_wp = wp.array(A, requires_grad=True, device=device)
139
+ B_wp = wp.zeros_like(A_wp, requires_grad=True, device=device)
140
+
141
+ with wp.Tape() as tape:
142
+ wp.launch_tiled(
143
+ tile_unary_map,
144
+ dim=[int(M / TILE_M), int(N / TILE_N)],
145
+ inputs=[A_wp, B_wp],
146
+ block_dim=TILE_DIM,
147
+ device=device,
148
+ )
149
+
150
+ # verify forward pass
151
+ assert_np_equal(B_wp.numpy(), B, tol=1.0e-4)
152
+
153
+ # verify backward pass
154
+ B_wp.grad = wp.ones_like(B_wp, device=device)
155
+ tape.backward()
156
+
157
+ assert_np_equal(A_wp.grad.numpy(), A_grad, tol=1.0e-6)
158
+
159
+
160
+ @wp.func
161
+ def binary_func(x: float, y: float):
162
+ return wp.sin(x) + y
163
+
164
+
165
+ @wp.kernel
166
+ def tile_binary_map(
167
+ input_a: wp.array2d(dtype=float), input_b: wp.array2d(dtype=float), output: wp.array2d(dtype=float)
168
+ ):
169
+ # tile index
170
+ i, j = wp.tid()
171
+
172
+ a = wp.tile_load(input_a, shape=(TILE_M, TILE_N), offset=(i * TILE_M, j * TILE_N))
173
+ b = wp.tile_load(input_b, shape=(TILE_M, TILE_N), offset=(i * TILE_M, j * TILE_N))
174
+
175
+ sa = wp.tile_map(binary_func, a, b)
176
+
177
+ wp.tile_store(output, sa, offset=(i * TILE_M, j * TILE_N))
178
+
179
+
180
+ def test_tile_binary_map(test, device):
181
+ rng = np.random.default_rng(42)
182
+
183
+ M = TILE_M * 7
184
+ N = TILE_N * 5
185
+
186
+ A = rng.random((M, N), dtype=np.float32)
187
+ B = rng.random((M, N), dtype=np.float32)
188
+ C = np.sin(A) + B
189
+
190
+ A_grad = np.cos(A)
191
+ B_grad = np.ones_like(B)
192
+
193
+ A_wp = wp.array(A, requires_grad=True, device=device)
194
+ B_wp = wp.array(B, requires_grad=True, device=device)
195
+ C_wp = wp.zeros_like(A_wp, requires_grad=True, device=device)
196
+
197
+ with wp.Tape() as tape:
198
+ wp.launch_tiled(
199
+ tile_binary_map,
200
+ dim=[int(M / TILE_M), int(N / TILE_N)],
201
+ inputs=[A_wp, B_wp, C_wp],
202
+ block_dim=TILE_DIM,
203
+ device=device,
204
+ )
205
+
206
+ # verify forward pass
207
+ assert_np_equal(C_wp.numpy(), C, tol=1.0e-6)
208
+
209
+ # verify backward pass
210
+ C_wp.grad = wp.ones_like(C_wp, device=device)
211
+ tape.backward()
212
+
213
+ assert_np_equal(A_wp.grad.numpy(), A_grad, tol=1.0e-6)
214
+ assert_np_equal(B_wp.grad.numpy(), B_grad)
215
+
216
+
217
+ def test_tile_grouped_gemm(test, device):
218
+ @wp.kernel
219
+ def tile_grouped_gemm(A: wp.array3d(dtype=float), B: wp.array3d(dtype=float), C: wp.array3d(dtype=float)):
220
+ # output tile index
221
+ i = wp.tid()
222
+
223
+ a = wp.tile_load(A[i], shape=(TILE_M, TILE_K))
224
+ b = wp.tile_load(B[i], shape=(TILE_K, TILE_N))
225
+
226
+ sum = wp.tile_zeros(shape=(TILE_M, TILE_N), dtype=wp.float32)
227
+
228
+ wp.tile_matmul(a, b, sum)
229
+
230
+ wp.tile_store(C[i], sum)
231
+
232
+ batch_count = 56
233
+
234
+ M = TILE_M
235
+ N = TILE_N
236
+ K = TILE_K
237
+
238
+ rng = np.random.default_rng(42)
239
+ A = rng.random((batch_count, M, K), dtype=np.float32)
240
+ B = rng.random((batch_count, K, N), dtype=np.float32)
241
+ C = A @ B
242
+
243
+ A_wp = wp.array(A, requires_grad=True, device=device)
244
+ B_wp = wp.array(B, requires_grad=True, device=device)
245
+ C_wp = wp.zeros((batch_count, TILE_M, TILE_N), requires_grad=True, device=device)
246
+
247
+ with wp.Tape() as tape:
248
+ wp.launch_tiled(
249
+ tile_grouped_gemm, dim=[batch_count], inputs=[A_wp, B_wp, C_wp], block_dim=TILE_DIM, device=device
250
+ )
251
+
252
+ # TODO: 32 mismatched elements
253
+ assert_np_equal(C_wp.numpy(), C, 1e-6)
254
+
255
+
256
+ def test_tile_gemm(dtype):
257
+ def test(test, device):
258
+ @wp.kernel
259
+ def tile_gemm(A: wp.array2d(dtype=dtype), B: wp.array2d(dtype=dtype), C: wp.array2d(dtype=dtype)):
260
+ # output tile index
261
+ i, j = wp.tid()
262
+
263
+ sum = wp.tile_zeros(shape=(TILE_M, TILE_N), dtype=dtype)
264
+
265
+ M = A.shape[0]
266
+ N = B.shape[1]
267
+ K = A.shape[1]
268
+
269
+ count = int(K / TILE_K)
270
+
271
+ for k in range(0, count):
272
+ a = wp.tile_load(A, shape=(TILE_M, TILE_K), offset=(i * TILE_M, k * TILE_K))
273
+ b = wp.tile_load(B, shape=(TILE_K, TILE_N), offset=(k * TILE_K, j * TILE_N))
274
+
275
+ # sum += a*b
276
+ wp.tile_matmul(a, b, sum)
277
+
278
+ wp.tile_store(C, sum, offset=(i * TILE_M, j * TILE_N))
279
+
280
+ M = TILE_M * 7
281
+ K = TILE_K * 6
282
+ N = TILE_N * 5
283
+
284
+ rng = np.random.default_rng(42)
285
+ A = rng.random((M, K), dtype=float).astype(wp.dtype_to_numpy(dtype))
286
+ B = rng.random((K, N), dtype=float).astype(wp.dtype_to_numpy(dtype))
287
+ C = np.zeros((M, N), dtype=float).astype(wp.dtype_to_numpy(dtype))
288
+
289
+ A_wp = wp.array(A, requires_grad=True, device=device)
290
+ B_wp = wp.array(B, requires_grad=True, device=device)
291
+ C_wp = wp.array(C, requires_grad=True, device=device)
292
+
293
+ with wp.Tape() as tape:
294
+ wp.launch_tiled(
295
+ tile_gemm,
296
+ dim=(int(M / TILE_M), int(N / TILE_N)),
297
+ inputs=[A_wp, B_wp, C_wp],
298
+ block_dim=TILE_DIM,
299
+ device=device,
300
+ )
301
+
302
+ assert_np_equal(C_wp.numpy(), A @ B, tol=1.0e-1)
303
+
304
+ adj_C = np.ones_like(C)
305
+
306
+ tape.backward(grads={C_wp: wp.array(adj_C, device=device)})
307
+
308
+ assert_np_equal(A_wp.grad.numpy(), adj_C @ B.T, tol=1.0e-1)
309
+ assert_np_equal(B_wp.grad.numpy(), A.T @ adj_C, 1.0e-1)
310
+
311
+ return test
312
+
313
+
314
+ @wp.kernel
315
+ def tile_operators(input: wp.array3d(dtype=float), output: wp.array3d(dtype=float)):
316
+ # output tile index
317
+ i = wp.tid()
318
+
319
+ a = wp.tile_load(input[i], shape=(TILE_M, TILE_N))
320
+
321
+ # neg
322
+ b = -a
323
+
324
+ # right scalar multiply
325
+ c = b * 0.5
326
+
327
+ # left scalar multiply
328
+ d = 0.5 * c
329
+
330
+ # add tiles
331
+ e = a + d
332
+
333
+ wp.tile_store(output[i], e)
334
+
335
+
336
+ def test_tile_operators(test, device):
337
+ batch_count = 56
338
+
339
+ M = TILE_M
340
+ N = TILE_N
341
+
342
+ rng = np.random.default_rng(42)
343
+ input = rng.random((batch_count, M, N), dtype=np.float32)
344
+ output = input * 0.75
345
+
346
+ input_wp = wp.array(input, requires_grad=True, device=device)
347
+ output_wp = wp.zeros_like(input_wp, requires_grad=True, device=device)
348
+
349
+ with wp.Tape() as tape:
350
+ wp.launch_tiled(
351
+ tile_operators, dim=[batch_count], inputs=[input_wp, output_wp], block_dim=TILE_DIM, device=device
352
+ )
353
+
354
+ assert_np_equal(output_wp.numpy(), output)
355
+
356
+ output_wp.grad.fill_(1.0)
357
+
358
+ tape.backward()
359
+
360
+ assert_np_equal(input_wp.grad.numpy(), np.ones_like(input) * 0.75)
361
+
362
+
363
+ @wp.kernel
364
+ def tile_sum_kernel(input: wp.array3d(dtype=float), output: wp.array(dtype=float)):
365
+ # output tile index
366
+ i = wp.tid()
367
+
368
+ a = wp.tile_load(input[i], shape=(TILE_M, TILE_N))
369
+ s = wp.tile_sum(a) * 0.5
370
+
371
+ wp.tile_store(output, s, offset=i)
372
+
373
+
374
+ def test_tile_sum(test, device):
375
+ batch_count = 56
376
+
377
+ M = TILE_M
378
+ N = TILE_N
379
+
380
+ rng = np.random.default_rng(42)
381
+ input = rng.random((batch_count, M, N), dtype=np.float32)
382
+
383
+ input_wp = wp.array(input, requires_grad=True, device=device)
384
+ output_wp = wp.zeros(batch_count, requires_grad=True, device=device)
385
+
386
+ with wp.Tape() as tape:
387
+ wp.launch_tiled(
388
+ tile_sum_kernel,
389
+ dim=[batch_count],
390
+ inputs=[input_wp, output_wp],
391
+ block_dim=TILE_DIM,
392
+ device=device,
393
+ )
394
+
395
+ sum_wp = output_wp.numpy()
396
+
397
+ for i in range(batch_count):
398
+ sum_np = np.sum(input[i]) * 0.5
399
+ test.assertAlmostEqual(sum_wp[i], sum_np, places=5)
400
+
401
+ output_wp.grad.fill_(1.0)
402
+
403
+ tape.backward()
404
+
405
+ assert_np_equal(input_wp.grad.numpy(), np.ones_like(input) * 0.5)
406
+
407
+
408
+ def test_tile_sum_launch(test, device):
409
+ batch_count = 56
410
+
411
+ M = TILE_M
412
+ N = TILE_N
413
+
414
+ rng = np.random.default_rng(42)
415
+ input = rng.random((batch_count, M, N), dtype=np.float32)
416
+
417
+ input_wp = wp.array(input, requires_grad=True, device=device)
418
+ output_wp = wp.zeros(batch_count, requires_grad=True, device=device)
419
+
420
+ cmd = wp.launch_tiled(
421
+ tile_sum_kernel,
422
+ dim=[batch_count],
423
+ inputs=[input_wp, output_wp],
424
+ block_dim=TILE_DIM,
425
+ device=device,
426
+ record_cmd=True,
427
+ )
428
+ cmd.launch()
429
+
430
+ sum_wp = output_wp.numpy()
431
+
432
+ for i in range(batch_count):
433
+ sum_np = np.sum(input[i]) * 0.5
434
+ test.assertAlmostEqual(sum_wp[i], sum_np, places=5)
435
+
436
+ output_wp.grad.fill_(1.0)
437
+
438
+ wp.launch_tiled(
439
+ tile_sum_kernel,
440
+ dim=[batch_count],
441
+ inputs=[input_wp, output_wp],
442
+ adj_inputs=[input_wp.grad, output_wp.grad],
443
+ block_dim=TILE_DIM,
444
+ device=device,
445
+ adjoint=True,
446
+ )
447
+
448
+ assert_np_equal(input_wp.grad.numpy(), np.ones_like(input) * 0.5)
449
+
450
+
451
+ @wp.kernel
452
+ def test_tile_extract_kernel(a: wp.array2d(dtype=float), b: wp.array2d(dtype=float)):
453
+ i, j, x, y = wp.tid()
454
+
455
+ tile = wp.tile_load(a, shape=(TILE_M, TILE_N), offset=(i * TILE_M, j * TILE_N))
456
+
457
+ # compute sum of array sub tile
458
+ wp.atomic_add(b, i, j, wp.tile_extract(tile, x, y))
459
+
460
+
461
+ def test_tile_extract(test, device):
462
+ block_dim = 16
463
+
464
+ input = np.arange(TILE_M * TILE_N * 4).reshape((TILE_M * 2, TILE_N * 2))
465
+
466
+ a = wp.array(input, dtype=float, requires_grad=True, device=device)
467
+ b = wp.zeros((2, 2), dtype=float, requires_grad=True, device=device)
468
+
469
+ with wp.Tape() as tape:
470
+ wp.launch(
471
+ test_tile_extract_kernel, dim=[2, 2, TILE_M, TILE_N], inputs=[a, b], block_dim=block_dim, device=device
472
+ )
473
+
474
+ # compute sum of each sub-block
475
+ sums = input.reshape(2, input.shape[0] // 2, 2, input.shape[1] // 2).sum(axis=(1, 3))
476
+
477
+ assert_np_equal(b.numpy(), sums)
478
+
479
+ b.grad.fill_(1.0)
480
+
481
+ tape.backward()
482
+
483
+ expected_grad = np.ones_like(input)
484
+ assert_np_equal(a.grad.numpy(), expected_grad)
485
+
486
+
487
+ @wp.kernel
488
+ def test_tile_extract_repeated_kernel(a: wp.array2d(dtype=float), b: wp.array2d(dtype=float)):
489
+ i, j, x, y = wp.tid()
490
+
491
+ tile = wp.tile_load(a, shape=(TILE_M, TILE_N), offset=(i * TILE_M, j * TILE_N))
492
+
493
+ # each thread extracts the first element of the sub-tile
494
+ # and accumulates the value onto the output
495
+ wp.atomic_add(b, i, j, wp.tile_extract(tile, 0, 0))
496
+
497
+
498
+ def test_tile_extract_repeated(test, device):
499
+ block_dim = 16
500
+
501
+ input = np.arange(TILE_M * TILE_N * 4).reshape((TILE_M * 2, TILE_N * 2))
502
+
503
+ a = wp.array(input, dtype=float, requires_grad=True, device=device)
504
+ b = wp.zeros((2, 2), dtype=float, requires_grad=True, device=device)
505
+
506
+ with wp.Tape() as tape:
507
+ wp.launch(
508
+ test_tile_extract_repeated_kernel,
509
+ dim=[2, 2, TILE_M, TILE_N],
510
+ inputs=[a, b],
511
+ block_dim=block_dim,
512
+ device=device,
513
+ )
514
+
515
+ # each thread adds the first element to the output
516
+ scale = TILE_M * TILE_N
517
+ sums = np.array([[input[0, 0], input[0, TILE_N]], [input[TILE_M, 0], input[TILE_M, TILE_N]]]) * scale
518
+
519
+ assert_np_equal(b.numpy(), sums)
520
+
521
+ b.grad.fill_(1.0)
522
+
523
+ tape.backward()
524
+
525
+ expected_grad = np.zeros_like(input)
526
+ expected_grad[0, 0] = scale
527
+ expected_grad[0, TILE_N] = scale
528
+ expected_grad[TILE_M, 0] = scale
529
+ expected_grad[TILE_M, TILE_N] = scale
530
+
531
+ assert_np_equal(a.grad.numpy(), expected_grad)
532
+
533
+
534
+ @wp.kernel
535
+ def test_tile_transpose_kernel(input: wp.array2d(dtype=float), output: wp.array2d(dtype=float)):
536
+ x = wp.tile_load(input, shape=(TILE_M, TILE_N))
537
+ y = wp.tile_transpose(x)
538
+
539
+ wp.tile_store(output, y)
540
+
541
+
542
+ def test_tile_transpose(test, device):
543
+ rng = np.random.default_rng(42)
544
+ input = wp.array(rng.random((TILE_M, TILE_N), dtype=np.float32), device=device)
545
+ output = wp.zeros_like(input.transpose(), device=device)
546
+
547
+ wp.launch_tiled(test_tile_transpose_kernel, dim=[1], inputs=[input, output], block_dim=32, device=device)
548
+
549
+ assert_np_equal(output.numpy(), input.numpy().T)
550
+
551
+
552
+ def test_tile_transpose_matmul(test, device):
553
+ @wp.kernel
554
+ def test_tile_transpose_matmul_kernel(input: wp.array2d(dtype=float), output: wp.array2d(dtype=float)):
555
+ x = wp.tile_load(input, shape=(TILE_M, TILE_N))
556
+ y = wp.tile_transpose(x)
557
+
558
+ z = wp.tile_zeros(dtype=float, shape=(TILE_N, TILE_N))
559
+ wp.tile_matmul(y, x, z)
560
+
561
+ wp.tile_store(output, z)
562
+
563
+ rng = np.random.default_rng(42)
564
+ input = wp.array(rng.random((TILE_M, TILE_N), dtype=np.float32), device=device)
565
+ output = wp.zeros((TILE_N, TILE_N), dtype=float, device=device)
566
+
567
+ wp.launch_tiled(test_tile_transpose_matmul_kernel, dim=[1], inputs=[input, output], block_dim=32, device=device)
568
+
569
+ assert_np_equal(output.numpy(), input.numpy().T @ input.numpy())
570
+
571
+
572
+ @wp.kernel
573
+ def test_tile_broadcast_add_1d_kernel(
574
+ input_a: wp.array(dtype=float), input_b: wp.array(dtype=float), output: wp.array(dtype=float)
575
+ ):
576
+ a = wp.tile_load(input_a, shape=(10,))
577
+ b = wp.tile_load(input_b, shape=(1,))
578
+
579
+ c = wp.tile_broadcast(b, shape=(10,))
580
+ d = a + c
581
+
582
+ wp.tile_store(output, d)
583
+
584
+
585
+ def test_tile_broadcast_add_1d(test, device):
586
+ N = 10
587
+
588
+ # implicit 1-dim ([1], 1)
589
+ a = wp.array(np.arange(0, N, dtype=np.float32), device=device)
590
+ b = wp.array(np.ones(1, dtype=np.float32), device=device)
591
+ out = wp.zeros((N,), dtype=float, device=device)
592
+
593
+ wp.launch_tiled(test_tile_broadcast_add_1d_kernel, dim=[1], inputs=[a, b, out], block_dim=32, device=device)
594
+
595
+ assert_np_equal(out.numpy(), a.numpy() + b.numpy())
596
+
597
+
598
+ @wp.kernel
599
+ def test_tile_broadcast_add_2d_kernel(
600
+ input_a: wp.array2d(dtype=float), input_b: wp.array(dtype=float), output: wp.array2d(dtype=float)
601
+ ):
602
+ # implicit 1-dim ([1], 10)
603
+ a = wp.tile_load(input_a, shape=(10, 10))
604
+ b = wp.tile_load(input_b, shape=10)
605
+
606
+ c = wp.tile_broadcast(b, shape=(10, 10))
607
+ d = a + c
608
+
609
+ wp.tile_store(output, d)
610
+
611
+
612
+ def test_tile_broadcast_add_2d(test, device):
613
+ M = 10
614
+ N = 10
615
+
616
+ a = wp.array(np.ones((M, N), dtype=np.float32), device=device)
617
+ b = wp.array(np.arange(0, N, dtype=np.float32), device=device)
618
+ out = wp.zeros((M, N), dtype=float, device=device)
619
+
620
+ wp.launch_tiled(test_tile_broadcast_add_2d_kernel, dim=[1], inputs=[a, b, out], block_dim=32, device=device)
621
+
622
+ assert_np_equal(out.numpy(), a.numpy() + b.numpy())
623
+
624
+
625
+ @wp.kernel
626
+ def test_tile_broadcast_add_3d_kernel(
627
+ input_a: wp.array3d(dtype=float), input_b: wp.array3d(dtype=float), output: wp.array3d(dtype=float)
628
+ ):
629
+ a = wp.tile_load(input_a, shape=(4, 10, 12))
630
+ b = wp.tile_load(input_b, shape=(4, 10, 1))
631
+
632
+ c = wp.tile_broadcast(b, shape=(4, 10, 12))
633
+ d = a + c
634
+
635
+ wp.tile_store(output, d)
636
+
637
+
638
+ def test_tile_broadcast_add_3d(test, device):
639
+ M = 4
640
+ N = 10
641
+ O = 12
642
+
643
+ # explicit 1-dim (M, N, 1) to (M, N, O)
644
+ a = wp.array(np.ones((M, N, O), dtype=np.float32), device=device)
645
+ b = wp.array(np.arange(0, M * N, dtype=np.float32).reshape((M, N, 1)), device=device)
646
+ out = wp.zeros((M, N, O), dtype=float, device=device)
647
+
648
+ wp.launch_tiled(test_tile_broadcast_add_3d_kernel, dim=[1], inputs=[a, b, out], block_dim=32, device=device)
649
+ assert_np_equal(out.numpy(), a.numpy() + b.numpy())
650
+
651
+
652
+ @wp.kernel
653
+ def test_tile_broadcast_add_4d_kernel(
654
+ input_a: wp.array4d(dtype=float), input_b: wp.array4d(dtype=float), output: wp.array4d(dtype=float)
655
+ ):
656
+ a = wp.tile_load(input_a, shape=(4, 10, 5, 6))
657
+ b = wp.tile_load(input_b, shape=(4, 1, 5, 1))
658
+ c = wp.tile_broadcast(b, shape=(4, 10, 5, 6))
659
+ d = a + c
660
+
661
+ wp.tile_store(output, d)
662
+
663
+
664
+ def test_tile_broadcast_add_4d(test, device):
665
+ M = 4
666
+ N = 10
667
+ O = 5
668
+ P = 6
669
+
670
+ # explicit 1-dims (M, 1, O, 1) to (M, N, O, P)
671
+ a = wp.array(np.ones((M, N, O, P), dtype=np.float32), device=device)
672
+ b = wp.array(np.arange(0, M * O, dtype=np.float32).reshape((M, 1, O, 1)), device=device)
673
+ out = wp.zeros((M, N, O, P), dtype=float, device=device)
674
+
675
+ wp.launch_tiled(test_tile_broadcast_add_4d_kernel, dim=[1], inputs=[a, b, out], block_dim=32, device=device)
676
+
677
+ assert_np_equal(out.numpy(), a.numpy() + b.numpy())
678
+
679
+
680
+ @wp.kernel
681
+ def test_tile_broadcast_grad_kernel(a: wp.array(dtype=float), b: wp.array2d(dtype=float)):
682
+ x = wp.tile_load(a, shape=5)
683
+ y = wp.tile_broadcast(x, shape=(5, 5))
684
+
685
+ w = wp.tile_ones(dtype=float, shape=(5, 5))
686
+ z = w + y
687
+
688
+ wp.tile_store(b, z)
689
+
690
+
691
+ def test_tile_broadcast_grad(test, device):
692
+ a = wp.array(np.arange(0, 5, dtype=np.float32), requires_grad=True, device=device)
693
+ b = wp.array(np.ones((5, 5), dtype=np.float32), requires_grad=True, device=device)
694
+
695
+ with wp.Tape() as tape:
696
+ wp.launch_tiled(test_tile_broadcast_grad_kernel, dim=[1], inputs=[a, b], block_dim=32, device=device)
697
+
698
+ b.grad = wp.ones_like(b, device=device)
699
+ tape.backward()
700
+
701
+ assert_np_equal(b.numpy(), a.numpy() + np.ones((5, 5)))
702
+ assert_np_equal(a.grad.numpy(), np.ones(5) * 5.0)
703
+
704
+
705
+ @wp.kernel
706
+ def tile_len_kernel(
707
+ a: wp.array(dtype=float, ndim=2),
708
+ out: wp.array(dtype=int),
709
+ ):
710
+ x = wp.tile_load(a, shape=(TILE_M, TILE_N))
711
+
712
+ length = wp.static(len(x))
713
+ wp.expect_eq(wp.static(len(x)), TILE_M)
714
+ out[0] = wp.static(len(x))
715
+
716
+
717
+ def test_tile_len(test, device):
718
+ a = wp.zeros((TILE_M, TILE_N), dtype=float, device=device)
719
+ out = wp.empty(1, dtype=int, device=device)
720
+ wp.launch_tiled(
721
+ tile_len_kernel,
722
+ dim=(1,),
723
+ inputs=(a,),
724
+ outputs=(out,),
725
+ block_dim=32,
726
+ device=device,
727
+ )
728
+
729
+ test.assertEqual(out.numpy()[0], TILE_M)
730
+
731
+
732
+ @wp.kernel
733
+ def test_tile_print_kernel():
734
+ # shared tile
735
+ a = wp.tile_ones(shape=(4, 3), dtype=float, storage="shared")
736
+ # register tile
737
+ b = wp.tile_ones(shape=(4, 3), dtype=float)
738
+
739
+ print(a)
740
+ print(b)
741
+
742
+
743
+ def test_tile_print(test, device):
744
+ wp.launch_tiled(test_tile_print_kernel, dim=1, inputs=[], block_dim=64, device=device)
745
+ wp.synchronize()
746
+
747
+
748
+ devices = get_test_devices()
749
+
750
+
751
+ class TestTile(unittest.TestCase):
752
+ pass
753
+
754
+
755
+ add_function_test(TestTile, "test_tile_copy_1d", test_tile_copy_1d, devices=devices)
756
+ add_function_test(TestTile, "test_tile_copy_2d", test_tile_copy_2d, devices=devices)
757
+ add_function_test(TestTile, "test_tile_unary_map", test_tile_unary_map, devices=devices)
758
+ add_function_test(TestTile, "test_tile_binary_map", test_tile_binary_map, devices=devices)
759
+ add_function_test(TestTile, "test_tile_grouped_gemm", test_tile_grouped_gemm, devices=devices)
760
+ add_function_test(TestTile, "test_tile_gemm_fp16", test_tile_gemm(wp.float16), devices=devices)
761
+ add_function_test(TestTile, "test_tile_gemm_fp32", test_tile_gemm(wp.float32), devices=devices)
762
+ add_function_test(TestTile, "test_tile_gemm_fp64", test_tile_gemm(wp.float64), devices=devices)
763
+ add_function_test(TestTile, "test_tile_transpose", test_tile_transpose, devices=devices)
764
+ add_function_test(TestTile, "test_tile_transpose_matmul", test_tile_transpose_matmul, devices=devices)
765
+ add_function_test(TestTile, "test_tile_operators", test_tile_operators, devices=devices)
766
+ add_function_test(TestTile, "test_tile_sum", test_tile_sum, devices=devices, check_output=False)
767
+ add_function_test(TestTile, "test_tile_sum_launch", test_tile_sum_launch, devices=devices)
768
+ add_function_test(TestTile, "test_tile_extract", test_tile_extract, devices=devices)
769
+ add_function_test(TestTile, "test_tile_extract_repeated", test_tile_extract_repeated, devices=devices)
770
+ add_function_test(TestTile, "test_tile_broadcast_add_1d", test_tile_broadcast_add_1d, devices=devices)
771
+ add_function_test(TestTile, "test_tile_broadcast_add_2d", test_tile_broadcast_add_2d, devices=devices)
772
+ add_function_test(TestTile, "test_tile_broadcast_add_3d", test_tile_broadcast_add_3d, devices=devices)
773
+ add_function_test(TestTile, "test_tile_broadcast_add_4d", test_tile_broadcast_add_4d, devices=devices)
774
+ add_function_test(TestTile, "test_tile_broadcast_grad", test_tile_broadcast_grad, devices=devices)
775
+ add_function_test(TestTile, "test_tile_len", test_tile_len, devices=devices)
776
+ add_function_test(TestTile, "test_tile_print", test_tile_print, devices=devices, check_output=False)
777
+
778
+ if __name__ == "__main__":
779
+ wp.clear_kernel_cache()
780
+ unittest.main(verbosity=2, failfast=True)