warp-lang 1.9.0__py3-none-manylinux_2_34_aarch64.whl → 1.10.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 (350) hide show
  1. warp/__init__.py +301 -287
  2. warp/__init__.pyi +2302 -307
  3. warp/_src/__init__.py +14 -0
  4. warp/_src/autograd.py +1077 -0
  5. warp/_src/build.py +620 -0
  6. warp/_src/build_dll.py +642 -0
  7. warp/{builtins.py → _src/builtins.py} +1546 -224
  8. warp/_src/codegen.py +4361 -0
  9. warp/{config.py → _src/config.py} +178 -169
  10. warp/_src/constants.py +59 -0
  11. warp/_src/context.py +8352 -0
  12. warp/_src/dlpack.py +464 -0
  13. warp/_src/fabric.py +362 -0
  14. warp/_src/fem/__init__.py +14 -0
  15. warp/_src/fem/adaptivity.py +510 -0
  16. warp/_src/fem/cache.py +689 -0
  17. warp/_src/fem/dirichlet.py +190 -0
  18. warp/{fem → _src/fem}/domain.py +42 -30
  19. warp/_src/fem/field/__init__.py +131 -0
  20. warp/_src/fem/field/field.py +703 -0
  21. warp/{fem → _src/fem}/field/nodal_field.py +32 -15
  22. warp/{fem → _src/fem}/field/restriction.py +3 -1
  23. warp/{fem → _src/fem}/field/virtual.py +55 -27
  24. warp/_src/fem/geometry/__init__.py +32 -0
  25. warp/{fem → _src/fem}/geometry/adaptive_nanogrid.py +79 -163
  26. warp/_src/fem/geometry/closest_point.py +99 -0
  27. warp/{fem → _src/fem}/geometry/deformed_geometry.py +16 -22
  28. warp/{fem → _src/fem}/geometry/element.py +34 -10
  29. warp/{fem → _src/fem}/geometry/geometry.py +50 -20
  30. warp/{fem → _src/fem}/geometry/grid_2d.py +14 -23
  31. warp/{fem → _src/fem}/geometry/grid_3d.py +14 -23
  32. warp/{fem → _src/fem}/geometry/hexmesh.py +42 -63
  33. warp/{fem → _src/fem}/geometry/nanogrid.py +256 -247
  34. warp/{fem → _src/fem}/geometry/partition.py +123 -63
  35. warp/{fem → _src/fem}/geometry/quadmesh.py +28 -45
  36. warp/{fem → _src/fem}/geometry/tetmesh.py +42 -63
  37. warp/{fem → _src/fem}/geometry/trimesh.py +28 -45
  38. warp/{fem → _src/fem}/integrate.py +166 -158
  39. warp/_src/fem/linalg.py +385 -0
  40. warp/_src/fem/operator.py +398 -0
  41. warp/_src/fem/polynomial.py +231 -0
  42. warp/{fem → _src/fem}/quadrature/pic_quadrature.py +17 -20
  43. warp/{fem → _src/fem}/quadrature/quadrature.py +97 -47
  44. warp/_src/fem/space/__init__.py +248 -0
  45. warp/{fem → _src/fem}/space/basis_function_space.py +22 -11
  46. warp/_src/fem/space/basis_space.py +681 -0
  47. warp/{fem → _src/fem}/space/dof_mapper.py +5 -3
  48. warp/{fem → _src/fem}/space/function_space.py +16 -13
  49. warp/{fem → _src/fem}/space/grid_2d_function_space.py +6 -7
  50. warp/{fem → _src/fem}/space/grid_3d_function_space.py +6 -4
  51. warp/{fem → _src/fem}/space/hexmesh_function_space.py +6 -10
  52. warp/{fem → _src/fem}/space/nanogrid_function_space.py +5 -9
  53. warp/{fem → _src/fem}/space/partition.py +119 -60
  54. warp/{fem → _src/fem}/space/quadmesh_function_space.py +6 -10
  55. warp/{fem → _src/fem}/space/restriction.py +68 -33
  56. warp/_src/fem/space/shape/__init__.py +152 -0
  57. warp/{fem → _src/fem}/space/shape/cube_shape_function.py +11 -9
  58. warp/{fem → _src/fem}/space/shape/shape_function.py +10 -9
  59. warp/{fem → _src/fem}/space/shape/square_shape_function.py +8 -6
  60. warp/{fem → _src/fem}/space/shape/tet_shape_function.py +5 -3
  61. warp/{fem → _src/fem}/space/shape/triangle_shape_function.py +5 -3
  62. warp/{fem → _src/fem}/space/tetmesh_function_space.py +5 -9
  63. warp/_src/fem/space/topology.py +461 -0
  64. warp/{fem → _src/fem}/space/trimesh_function_space.py +5 -9
  65. warp/_src/fem/types.py +114 -0
  66. warp/_src/fem/utils.py +488 -0
  67. warp/_src/jax.py +188 -0
  68. warp/_src/jax_experimental/__init__.py +14 -0
  69. warp/_src/jax_experimental/custom_call.py +389 -0
  70. warp/_src/jax_experimental/ffi.py +1286 -0
  71. warp/_src/jax_experimental/xla_ffi.py +658 -0
  72. warp/_src/marching_cubes.py +710 -0
  73. warp/_src/math.py +416 -0
  74. warp/_src/optim/__init__.py +14 -0
  75. warp/_src/optim/adam.py +165 -0
  76. warp/_src/optim/linear.py +1608 -0
  77. warp/_src/optim/sgd.py +114 -0
  78. warp/_src/paddle.py +408 -0
  79. warp/_src/render/__init__.py +14 -0
  80. warp/_src/render/imgui_manager.py +291 -0
  81. warp/_src/render/render_opengl.py +3638 -0
  82. warp/_src/render/render_usd.py +939 -0
  83. warp/_src/render/utils.py +162 -0
  84. warp/_src/sparse.py +2718 -0
  85. warp/_src/tape.py +1208 -0
  86. warp/{thirdparty → _src/thirdparty}/unittest_parallel.py +9 -2
  87. warp/_src/torch.py +393 -0
  88. warp/_src/types.py +5888 -0
  89. warp/_src/utils.py +1695 -0
  90. warp/autograd.py +12 -1054
  91. warp/bin/warp-clang.so +0 -0
  92. warp/bin/warp.so +0 -0
  93. warp/build.py +8 -588
  94. warp/build_dll.py +6 -471
  95. warp/codegen.py +6 -4246
  96. warp/constants.py +6 -39
  97. warp/context.py +12 -7851
  98. warp/dlpack.py +6 -444
  99. warp/examples/distributed/example_jacobi_mpi.py +4 -5
  100. warp/examples/fem/example_adaptive_grid.py +1 -1
  101. warp/examples/fem/example_apic_fluid.py +1 -1
  102. warp/examples/fem/example_burgers.py +8 -8
  103. warp/examples/fem/example_diffusion.py +1 -1
  104. warp/examples/fem/example_distortion_energy.py +1 -1
  105. warp/examples/fem/example_mixed_elasticity.py +2 -2
  106. warp/examples/fem/example_navier_stokes.py +1 -1
  107. warp/examples/fem/example_nonconforming_contact.py +7 -7
  108. warp/examples/fem/example_stokes.py +1 -1
  109. warp/examples/fem/example_stokes_transfer.py +1 -1
  110. warp/examples/fem/utils.py +2 -2
  111. warp/examples/interop/example_jax_callable.py +1 -1
  112. warp/examples/interop/example_jax_ffi_callback.py +1 -1
  113. warp/examples/interop/example_jax_kernel.py +3 -2
  114. warp/examples/tile/example_tile_mcgp.py +191 -0
  115. warp/fabric.py +6 -337
  116. warp/fem/__init__.py +159 -97
  117. warp/fem/adaptivity.py +7 -489
  118. warp/fem/cache.py +9 -648
  119. warp/fem/dirichlet.py +6 -184
  120. warp/fem/field/__init__.py +8 -109
  121. warp/fem/field/field.py +7 -652
  122. warp/fem/geometry/__init__.py +7 -18
  123. warp/fem/geometry/closest_point.py +11 -77
  124. warp/fem/linalg.py +18 -366
  125. warp/fem/operator.py +11 -369
  126. warp/fem/polynomial.py +9 -209
  127. warp/fem/space/__init__.py +5 -211
  128. warp/fem/space/basis_space.py +6 -662
  129. warp/fem/space/shape/__init__.py +41 -118
  130. warp/fem/space/topology.py +6 -437
  131. warp/fem/types.py +6 -81
  132. warp/fem/utils.py +11 -444
  133. warp/jax.py +8 -165
  134. warp/jax_experimental/__init__.py +14 -1
  135. warp/jax_experimental/custom_call.py +8 -342
  136. warp/jax_experimental/ffi.py +17 -853
  137. warp/jax_experimental/xla_ffi.py +5 -596
  138. warp/marching_cubes.py +5 -689
  139. warp/math.py +16 -393
  140. warp/native/array.h +385 -37
  141. warp/native/builtin.h +316 -39
  142. warp/native/bvh.cpp +43 -9
  143. warp/native/bvh.cu +62 -27
  144. warp/native/bvh.h +310 -309
  145. warp/native/clang/clang.cpp +102 -97
  146. warp/native/coloring.cpp +0 -1
  147. warp/native/crt.h +208 -0
  148. warp/native/exports.h +156 -0
  149. warp/native/hashgrid.cu +2 -0
  150. warp/native/intersect.h +24 -1
  151. warp/native/intersect_tri.h +44 -35
  152. warp/native/mat.h +1456 -276
  153. warp/native/mesh.cpp +4 -4
  154. warp/native/mesh.cu +4 -2
  155. warp/native/mesh.h +176 -61
  156. warp/native/quat.h +0 -52
  157. warp/native/scan.cu +2 -0
  158. warp/native/sort.cu +22 -13
  159. warp/native/sort.h +2 -0
  160. warp/native/sparse.cu +7 -3
  161. warp/native/spatial.h +12 -0
  162. warp/native/tile.h +837 -70
  163. warp/native/tile_radix_sort.h +3 -3
  164. warp/native/tile_reduce.h +394 -46
  165. warp/native/tile_scan.h +4 -4
  166. warp/native/vec.h +469 -53
  167. warp/native/version.h +23 -0
  168. warp/native/volume.cpp +1 -1
  169. warp/native/volume.cu +1 -0
  170. warp/native/volume.h +1 -1
  171. warp/native/volume_builder.cu +2 -0
  172. warp/native/warp.cpp +60 -32
  173. warp/native/warp.cu +581 -280
  174. warp/native/warp.h +14 -11
  175. warp/optim/__init__.py +6 -3
  176. warp/optim/adam.py +6 -145
  177. warp/optim/linear.py +14 -1585
  178. warp/optim/sgd.py +6 -94
  179. warp/paddle.py +6 -388
  180. warp/render/__init__.py +8 -4
  181. warp/render/imgui_manager.py +7 -267
  182. warp/render/render_opengl.py +6 -3616
  183. warp/render/render_usd.py +6 -918
  184. warp/render/utils.py +6 -142
  185. warp/sparse.py +37 -2563
  186. warp/tape.py +6 -1188
  187. warp/tests/__main__.py +1 -1
  188. warp/tests/cuda/test_async.py +4 -4
  189. warp/tests/cuda/test_conditional_captures.py +1 -1
  190. warp/tests/cuda/test_multigpu.py +1 -1
  191. warp/tests/cuda/test_streams.py +58 -1
  192. warp/tests/geometry/test_bvh.py +157 -22
  193. warp/tests/geometry/test_hash_grid.py +38 -0
  194. warp/tests/geometry/test_marching_cubes.py +0 -1
  195. warp/tests/geometry/test_mesh.py +5 -3
  196. warp/tests/geometry/test_mesh_query_aabb.py +5 -12
  197. warp/tests/geometry/test_mesh_query_point.py +5 -2
  198. warp/tests/geometry/test_mesh_query_ray.py +15 -3
  199. warp/tests/geometry/test_volume_write.py +5 -5
  200. warp/tests/interop/test_dlpack.py +18 -17
  201. warp/tests/interop/test_jax.py +1382 -79
  202. warp/tests/interop/test_paddle.py +1 -1
  203. warp/tests/test_adam.py +0 -1
  204. warp/tests/test_arithmetic.py +9 -9
  205. warp/tests/test_array.py +580 -100
  206. warp/tests/test_array_reduce.py +3 -3
  207. warp/tests/test_atomic.py +12 -8
  208. warp/tests/test_atomic_bitwise.py +209 -0
  209. warp/tests/test_atomic_cas.py +4 -4
  210. warp/tests/test_bool.py +2 -2
  211. warp/tests/test_builtins_resolution.py +5 -571
  212. warp/tests/test_codegen.py +34 -15
  213. warp/tests/test_conditional.py +1 -1
  214. warp/tests/test_context.py +6 -6
  215. warp/tests/test_copy.py +242 -161
  216. warp/tests/test_ctypes.py +3 -3
  217. warp/tests/test_devices.py +24 -2
  218. warp/tests/test_examples.py +16 -84
  219. warp/tests/test_fabricarray.py +35 -35
  220. warp/tests/test_fast_math.py +0 -2
  221. warp/tests/test_fem.py +60 -14
  222. warp/tests/test_fixedarray.py +3 -3
  223. warp/tests/test_func.py +8 -5
  224. warp/tests/test_generics.py +1 -1
  225. warp/tests/test_indexedarray.py +24 -24
  226. warp/tests/test_intersect.py +39 -9
  227. warp/tests/test_large.py +1 -1
  228. warp/tests/test_lerp.py +3 -1
  229. warp/tests/test_linear_solvers.py +1 -1
  230. warp/tests/test_map.py +49 -4
  231. warp/tests/test_mat.py +52 -62
  232. warp/tests/test_mat_constructors.py +4 -5
  233. warp/tests/test_mat_lite.py +1 -1
  234. warp/tests/test_mat_scalar_ops.py +121 -121
  235. warp/tests/test_math.py +34 -0
  236. warp/tests/test_module_aot.py +4 -4
  237. warp/tests/test_modules_lite.py +28 -2
  238. warp/tests/test_print.py +11 -11
  239. warp/tests/test_quat.py +93 -58
  240. warp/tests/test_runlength_encode.py +1 -1
  241. warp/tests/test_scalar_ops.py +38 -10
  242. warp/tests/test_smoothstep.py +1 -1
  243. warp/tests/test_sparse.py +126 -15
  244. warp/tests/test_spatial.py +105 -87
  245. warp/tests/test_special_values.py +6 -6
  246. warp/tests/test_static.py +7 -7
  247. warp/tests/test_struct.py +13 -2
  248. warp/tests/test_triangle_closest_point.py +48 -1
  249. warp/tests/test_tuple.py +96 -0
  250. warp/tests/test_types.py +82 -9
  251. warp/tests/test_utils.py +52 -52
  252. warp/tests/test_vec.py +29 -29
  253. warp/tests/test_vec_constructors.py +5 -5
  254. warp/tests/test_vec_scalar_ops.py +97 -97
  255. warp/tests/test_version.py +75 -0
  256. warp/tests/tile/test_tile.py +239 -0
  257. warp/tests/tile/test_tile_atomic_bitwise.py +403 -0
  258. warp/tests/tile/test_tile_cholesky.py +7 -4
  259. warp/tests/tile/test_tile_load.py +26 -2
  260. warp/tests/tile/test_tile_mathdx.py +3 -3
  261. warp/tests/tile/test_tile_matmul.py +1 -1
  262. warp/tests/tile/test_tile_mlp.py +2 -4
  263. warp/tests/tile/test_tile_reduce.py +214 -13
  264. warp/tests/unittest_suites.py +6 -14
  265. warp/tests/unittest_utils.py +10 -9
  266. warp/tests/walkthrough_debug.py +3 -1
  267. warp/torch.py +6 -373
  268. warp/types.py +29 -5750
  269. warp/utils.py +10 -1659
  270. {warp_lang-1.9.0.dist-info → warp_lang-1.10.0.dist-info}/METADATA +47 -103
  271. warp_lang-1.10.0.dist-info/RECORD +468 -0
  272. warp_lang-1.10.0.dist-info/licenses/licenses/Gaia-LICENSE.txt +6 -0
  273. warp_lang-1.10.0.dist-info/licenses/licenses/appdirs-LICENSE.txt +22 -0
  274. warp_lang-1.10.0.dist-info/licenses/licenses/asset_pixel_jpg-LICENSE.txt +3 -0
  275. warp_lang-1.10.0.dist-info/licenses/licenses/cuda-LICENSE.txt +1582 -0
  276. warp_lang-1.10.0.dist-info/licenses/licenses/dlpack-LICENSE.txt +201 -0
  277. warp_lang-1.10.0.dist-info/licenses/licenses/fp16-LICENSE.txt +28 -0
  278. warp_lang-1.10.0.dist-info/licenses/licenses/libmathdx-LICENSE.txt +220 -0
  279. warp_lang-1.10.0.dist-info/licenses/licenses/llvm-LICENSE.txt +279 -0
  280. warp_lang-1.10.0.dist-info/licenses/licenses/moller-LICENSE.txt +16 -0
  281. warp_lang-1.10.0.dist-info/licenses/licenses/nanovdb-LICENSE.txt +2 -0
  282. warp_lang-1.10.0.dist-info/licenses/licenses/nvrtc-LICENSE.txt +1592 -0
  283. warp_lang-1.10.0.dist-info/licenses/licenses/svd-LICENSE.txt +23 -0
  284. warp_lang-1.10.0.dist-info/licenses/licenses/unittest_parallel-LICENSE.txt +21 -0
  285. warp_lang-1.10.0.dist-info/licenses/licenses/usd-LICENSE.txt +213 -0
  286. warp_lang-1.10.0.dist-info/licenses/licenses/windingnumber-LICENSE.txt +21 -0
  287. warp/examples/assets/cartpole.urdf +0 -110
  288. warp/examples/assets/crazyflie.usd +0 -0
  289. warp/examples/assets/nv_ant.xml +0 -92
  290. warp/examples/assets/nv_humanoid.xml +0 -183
  291. warp/examples/assets/quadruped.urdf +0 -268
  292. warp/examples/optim/example_bounce.py +0 -266
  293. warp/examples/optim/example_cloth_throw.py +0 -228
  294. warp/examples/optim/example_drone.py +0 -870
  295. warp/examples/optim/example_inverse_kinematics.py +0 -182
  296. warp/examples/optim/example_inverse_kinematics_torch.py +0 -191
  297. warp/examples/optim/example_softbody_properties.py +0 -400
  298. warp/examples/optim/example_spring_cage.py +0 -245
  299. warp/examples/optim/example_trajectory.py +0 -227
  300. warp/examples/sim/example_cartpole.py +0 -143
  301. warp/examples/sim/example_cloth.py +0 -225
  302. warp/examples/sim/example_cloth_self_contact.py +0 -316
  303. warp/examples/sim/example_granular.py +0 -130
  304. warp/examples/sim/example_granular_collision_sdf.py +0 -202
  305. warp/examples/sim/example_jacobian_ik.py +0 -244
  306. warp/examples/sim/example_particle_chain.py +0 -124
  307. warp/examples/sim/example_quadruped.py +0 -203
  308. warp/examples/sim/example_rigid_chain.py +0 -203
  309. warp/examples/sim/example_rigid_contact.py +0 -195
  310. warp/examples/sim/example_rigid_force.py +0 -133
  311. warp/examples/sim/example_rigid_gyroscopic.py +0 -115
  312. warp/examples/sim/example_rigid_soft_contact.py +0 -140
  313. warp/examples/sim/example_soft_body.py +0 -196
  314. warp/examples/tile/example_tile_walker.py +0 -327
  315. warp/sim/__init__.py +0 -74
  316. warp/sim/articulation.py +0 -793
  317. warp/sim/collide.py +0 -2570
  318. warp/sim/graph_coloring.py +0 -307
  319. warp/sim/import_mjcf.py +0 -791
  320. warp/sim/import_snu.py +0 -227
  321. warp/sim/import_urdf.py +0 -579
  322. warp/sim/import_usd.py +0 -898
  323. warp/sim/inertia.py +0 -357
  324. warp/sim/integrator.py +0 -245
  325. warp/sim/integrator_euler.py +0 -2000
  326. warp/sim/integrator_featherstone.py +0 -2101
  327. warp/sim/integrator_vbd.py +0 -2487
  328. warp/sim/integrator_xpbd.py +0 -3295
  329. warp/sim/model.py +0 -4821
  330. warp/sim/particles.py +0 -121
  331. warp/sim/render.py +0 -431
  332. warp/sim/utils.py +0 -431
  333. warp/tests/sim/disabled_kinematics.py +0 -244
  334. warp/tests/sim/test_cloth.py +0 -863
  335. warp/tests/sim/test_collision.py +0 -743
  336. warp/tests/sim/test_coloring.py +0 -347
  337. warp/tests/sim/test_inertia.py +0 -161
  338. warp/tests/sim/test_model.py +0 -226
  339. warp/tests/sim/test_sim_grad.py +0 -287
  340. warp/tests/sim/test_sim_grad_bounce_linear.py +0 -212
  341. warp/tests/sim/test_sim_kinematics.py +0 -98
  342. warp/thirdparty/__init__.py +0 -0
  343. warp_lang-1.9.0.dist-info/RECORD +0 -456
  344. /warp/{fem → _src/fem}/quadrature/__init__.py +0 -0
  345. /warp/{tests/sim → _src/thirdparty}/__init__.py +0 -0
  346. /warp/{thirdparty → _src/thirdparty}/appdirs.py +0 -0
  347. /warp/{thirdparty → _src/thirdparty}/dlpack.py +0 -0
  348. {warp_lang-1.9.0.dist-info → warp_lang-1.10.0.dist-info}/WHEEL +0 -0
  349. {warp_lang-1.9.0.dist-info → warp_lang-1.10.0.dist-info}/licenses/LICENSE.md +0 -0
  350. {warp_lang-1.9.0.dist-info → warp_lang-1.10.0.dist-info}/top_level.txt +0 -0
warp/_src/build.py ADDED
@@ -0,0 +1,620 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import ctypes
17
+ import errno
18
+ import hashlib
19
+ import json
20
+ import os
21
+ import time
22
+ from pathlib import Path
23
+
24
+ import warp._src.config
25
+ from warp._src.thirdparty import appdirs
26
+ from warp._src.types import *
27
+
28
+ _wp_module_name_ = "warp.build"
29
+
30
+ # From nvJitLink.h
31
+ nvJitLink_input_type = {"cubin": 1, "ptx": 2, "ltoir": 3, "fatbin": 4, "object": 5, "library": 6}
32
+
33
+ warp_home = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
34
+
35
+
36
+ # builds cuda source to PTX or CUBIN using NVRTC (output type determined by output_path extension)
37
+ def build_cuda(
38
+ cu_path,
39
+ arch,
40
+ output_path,
41
+ config="release",
42
+ verify_fp=False,
43
+ fast_math=False,
44
+ fuse_fp=True,
45
+ lineinfo=False,
46
+ compile_time_trace=False,
47
+ ltoirs=None,
48
+ fatbins=None,
49
+ ) -> None:
50
+ with open(cu_path, "rb") as src_file:
51
+ src = src_file.read()
52
+ cu_path_bytes = cu_path.encode("utf-8")
53
+ program_name_bytes = os.path.basename(cu_path).encode("utf-8")
54
+ inc_path = os.path.join(warp_home, "native").encode("utf-8")
55
+ output_path = output_path.encode("utf-8")
56
+
57
+ if warp._src.config.llvm_cuda:
58
+ warp._src.context.runtime.llvm.wp_compile_cuda(src, cu_path_bytes, inc_path, output_path, False)
59
+
60
+ else:
61
+ if ltoirs is None:
62
+ ltoirs = []
63
+ if fatbins is None:
64
+ fatbins = []
65
+
66
+ link_data = list(ltoirs) + list(fatbins)
67
+ num_link = len(link_data)
68
+ arr_link = (ctypes.c_char_p * num_link)(*link_data)
69
+ arr_link_sizes = (ctypes.c_size_t * num_link)(*[len(l) for l in link_data])
70
+ link_input_types = [nvJitLink_input_type["ltoir"]] * len(ltoirs) + [nvJitLink_input_type["fatbin"]] * len(
71
+ fatbins
72
+ )
73
+ arr_link_input_types = (ctypes.c_int * num_link)(*link_input_types)
74
+ err = warp._src.context.runtime.core.wp_cuda_compile_program(
75
+ src,
76
+ program_name_bytes,
77
+ arch,
78
+ inc_path,
79
+ 0,
80
+ None,
81
+ config == "debug",
82
+ warp._src.config.verbose,
83
+ verify_fp,
84
+ fast_math,
85
+ fuse_fp,
86
+ lineinfo,
87
+ compile_time_trace,
88
+ output_path,
89
+ num_link,
90
+ arr_link,
91
+ arr_link_sizes,
92
+ arr_link_input_types,
93
+ )
94
+ if err != 0:
95
+ raise Exception(f"CUDA kernel build failed with error code {err}")
96
+
97
+
98
+ # load PTX or CUBIN as a CUDA runtime module (input type determined by input_path extension)
99
+ def load_cuda(input_path, device):
100
+ if not device.is_cuda:
101
+ raise RuntimeError("Not a CUDA device")
102
+
103
+ return warp._src.context.runtime.core.wp_cuda_load_module(device.context, input_path.encode("utf-8"))
104
+
105
+
106
+ def build_cpu(obj_path, cpp_path, mode="release", verify_fp=False, fast_math=False, fuse_fp=True):
107
+ with open(cpp_path, "rb") as cpp:
108
+ src = cpp.read()
109
+ cpp_path = cpp_path.encode("utf-8")
110
+ inc_path = os.path.join(warp_home, "native").encode("utf-8")
111
+ obj_path = obj_path.encode("utf-8")
112
+
113
+ err = warp._src.context.runtime.llvm.wp_compile_cpp(
114
+ src,
115
+ cpp_path,
116
+ inc_path,
117
+ obj_path,
118
+ mode == "debug",
119
+ verify_fp,
120
+ fuse_fp,
121
+ warp.config.enable_tiles_in_stack_memory,
122
+ )
123
+ if err != 0:
124
+ raise Exception(f"CPU kernel build failed with error code {err}")
125
+
126
+
127
+ def init_kernel_cache(path=None):
128
+ """Initialize kernel cache directory.
129
+
130
+ This function is used during Warp initialization, but it can also be called directly to change the cache location.
131
+ If the path is not explicitly specified, a default location will be chosen based on OS-specific conventions.
132
+
133
+ To change the default cache location, set warp.config.kernel_cache_dir before calling warp.init().
134
+ """
135
+
136
+ if path is not None:
137
+ cache_root_dir = os.path.realpath(path)
138
+ elif "WARP_CACHE_PATH" in os.environ:
139
+ cache_root_dir = os.path.realpath(os.environ.get("WARP_CACHE_PATH"))
140
+ else:
141
+ cache_root_dir = appdirs.user_cache_dir(appname="warp", appauthor="NVIDIA", version=warp._src.config.version)
142
+
143
+ if os.name == "nt" and os.path.isabs(cache_root_dir) and not cache_root_dir.startswith("\\\\?\\"):
144
+ # Add Windows long-path prefix, accounting for UNC shares.
145
+ if cache_root_dir.startswith("\\\\"):
146
+ # UNC path \\server\share\… → \\?\UNC\server\share\…
147
+ cache_root_dir = "\\\\?\\UNC\\" + cache_root_dir.lstrip("\\")
148
+ else:
149
+ # Drive-letter path C:\… → \\?\C:\…
150
+ cache_root_dir = "\\\\?\\" + cache_root_dir
151
+
152
+ warp._src.config.kernel_cache_dir = cache_root_dir
153
+
154
+ os.makedirs(warp._src.config.kernel_cache_dir, exist_ok=True)
155
+
156
+
157
+ def clear_kernel_cache() -> None:
158
+ """Clear the kernel cache directory of previously generated source code and compiler artifacts.
159
+
160
+ Only directories beginning with ``wp_`` will be deleted.
161
+ This function only clears the cache for the current Warp version.
162
+ LTO artifacts are not affected.
163
+ """
164
+
165
+ warp._src.context.init()
166
+
167
+ import shutil
168
+
169
+ is_initialized = warp._src.context.runtime is not None
170
+ assert is_initialized, "The kernel cache directory is not configured; wp.init() has not been called yet or failed."
171
+
172
+ for item in os.listdir(warp._src.config.kernel_cache_dir):
173
+ item_path = os.path.join(warp._src.config.kernel_cache_dir, item)
174
+ if os.path.isdir(item_path) and item.startswith("wp_"):
175
+ # Remove the directory and its contents
176
+ shutil.rmtree(item_path, ignore_errors=True)
177
+
178
+
179
+ def clear_lto_cache() -> None:
180
+ """Clear the LTO cache directory of previously generated LTO code.
181
+
182
+ The LTO cache is stored within a subdirectory of the kernel cache directory.
183
+ This function only clears the cache for the current Warp version.
184
+ """
185
+
186
+ warp._src.context.init()
187
+
188
+ import shutil
189
+
190
+ is_initialized = warp._src.context.runtime is not None
191
+ assert is_initialized, "The kernel cache directory is not configured; wp.init() has not been called yet or failed."
192
+
193
+ lto_path = os.path.join(warp._src.config.kernel_cache_dir, "lto")
194
+ if os.path.isdir(lto_path):
195
+ # Remove the lto directory and its contents
196
+ shutil.rmtree(lto_path, ignore_errors=True)
197
+
198
+
199
+ def safe_rename(src, dst, attempts=5, delay=0.1):
200
+ for i in range(attempts):
201
+ try:
202
+ os.rename(src, dst)
203
+ return
204
+ except FileExistsError:
205
+ return
206
+ except OSError as e:
207
+ if e.errno == errno.ENOTEMPTY:
208
+ # if directory exists we assume another process
209
+ # got there first, in which case we will copy
210
+ # our output to the directory manually in second step
211
+ return
212
+ else:
213
+ # otherwise assume directory creation failed e.g.: access denied
214
+ # on Windows we see occasional failures to rename directories due to
215
+ # some process holding a lock on a file to be moved to workaround
216
+ # this we make multiple attempts to rename with some delay
217
+ if i < attempts - 1:
218
+ time.sleep(delay)
219
+ else:
220
+ print(
221
+ f"Could not update Warp cache with compiled binaries, trying to rename {src} to {dst}, error {e}"
222
+ )
223
+ raise e
224
+
225
+
226
+ def hash_symbol(symbol):
227
+ ch = hashlib.sha256()
228
+ ch.update(symbol.encode("utf-8"))
229
+ return ch.hexdigest()
230
+
231
+
232
+ def get_lto_cache_dir():
233
+ lto_dir = os.path.join(warp._src.config.kernel_cache_dir, "lto")
234
+ return lto_dir
235
+
236
+
237
+ def get_cached_lto(path):
238
+ if os.path.exists(path):
239
+ with open(path, "rb") as f:
240
+ lto_code_data = f.read()
241
+ return lto_code_data
242
+ else:
243
+ return None
244
+
245
+
246
+ def get_cached_lto_meta(path, symbol):
247
+ if os.path.exists(path):
248
+ with open(path) as f:
249
+ keys = json.load(f)
250
+ value = keys[symbol]
251
+ return value
252
+ else:
253
+ return None
254
+
255
+
256
+ def _build_lto_base(lto_symbol, compile_func, builder, extra_files=None):
257
+ """Generic LTO build function that handles caching, file operations and process management.
258
+
259
+ Args:
260
+ lto_symbol: Unique identifier for the LTO operation
261
+ compile_func: Function to compile the specific LTO
262
+ (receives a dictionary of build paths)
263
+ builder: Builder object to store results
264
+ extra_files: Dictionary of additional file types to handle (e.g.,
265
+ {".meta": None, ".fatbin": None}). Values are the functions to get
266
+ the cached file data.
267
+
268
+ Returns:
269
+ Tuple where the first element is a success flag (``bool``). The second
270
+ element is the LTO code as bytes (or ``None`` on failure).
271
+ If ``extra_files`` is provided, additional elements follow in the same
272
+ order as the keys in ``extra_files``:
273
+ - ``".meta"``: int (shared memory bytes).
274
+ - ``"_fatbin.lto"``: bytes (universal fatbin).
275
+ """
276
+ if extra_files is None:
277
+ extra_files = {}
278
+
279
+ # Hash symbol and set up paths
280
+ h = hash_symbol(lto_symbol)
281
+ lto_dir = get_lto_cache_dir()
282
+ lto_name = f"{h[:7]}.lto"
283
+ lto_path = os.path.join(lto_dir, lto_name)
284
+
285
+ # Set up paths for extra files
286
+ file_paths = {".lto": lto_path}
287
+ temp_file_paths = {}
288
+
289
+ for ext, _ in extra_files.items():
290
+ name = f"{h[:7]}{ext}"
291
+ file_paths[ext] = os.path.join(lto_dir, name)
292
+
293
+ # Check if already built but not cached
294
+ lto_code_data = get_cached_lto(lto_path)
295
+ if lto_code_data is not None:
296
+ # Get the cached data for the extra files and early return
297
+ all_files_cached = True
298
+ for ext, getter in extra_files.items():
299
+ if getter and os.path.exists(file_paths[ext]):
300
+ cached_data = getter(file_paths[ext])
301
+ if cached_data is None:
302
+ all_files_cached = False
303
+ break
304
+ extra_files[ext] = cached_data
305
+ elif getter: # If there's a getter but file doesn't exist
306
+ all_files_cached = False
307
+ break
308
+
309
+ if all_files_cached:
310
+ if not extra_files:
311
+ return (True, lto_code_data)
312
+ else:
313
+ return (True, lto_code_data, *[extra_files[ext] for ext in extra_files.keys()])
314
+
315
+ # Create process-dependent temporary build directory
316
+ build_dir = f"{lto_dir}_p{os.getpid()}"
317
+ Path(build_dir).mkdir(parents=True, exist_ok=True)
318
+
319
+ # Set up temporary paths for the build outputs
320
+ for ext, path in file_paths.items():
321
+ temp_file_paths[ext] = os.path.join(build_dir, os.path.basename(path))
322
+
323
+ # Compile LTO with the specialized function
324
+ result, outputs = compile_func(temp_file_paths)
325
+
326
+ if not result:
327
+ # Clean up and fail
328
+ for path in temp_file_paths.values():
329
+ if Path(path).exists():
330
+ Path(path).unlink()
331
+
332
+ outputs[".lto"] = None
333
+ for ext in extra_files.keys():
334
+ outputs[ext] = None
335
+ else:
336
+ # Move outputs to cache
337
+ safe_rename(build_dir, lto_dir)
338
+
339
+ # If build_dir couldn't be moved by a rename, move the outputs one-by-one to lto_dir
340
+ if os.path.exists(lto_dir):
341
+ for ext, path in file_paths.items():
342
+ if not os.path.exists(path):
343
+ try:
344
+ # copy output file to the destination lto dir
345
+ os.rename(temp_file_paths[ext], path)
346
+ except (OSError, FileExistsError):
347
+ # another process likely updated the lto dir first
348
+ pass
349
+
350
+ # Clean up the temporary build directory
351
+ if build_dir:
352
+ import shutil
353
+
354
+ shutil.rmtree(build_dir, ignore_errors=True)
355
+
356
+ if not extra_files:
357
+ return (result, outputs[".lto"])
358
+ else:
359
+ return (result, outputs[".lto"], *[outputs[ext] for ext in extra_files.keys()])
360
+
361
+
362
+ def build_lto_dot(M, N, K, adtype, bdtype, cdtype, alayout, blayout, clayout, arch, num_threads, builder):
363
+ arch = 120 if arch > 121 else arch
364
+
365
+ # Maps Python/Warp types to C++ types and enums
366
+ def cublasdx_type_map(dtype):
367
+ if dtype == float16:
368
+ return ("wp::float16", 3, 0)
369
+ if dtype == float32:
370
+ return ("wp::float32", 5, 0)
371
+ if dtype == float64:
372
+ return ("wp::float64", 6, 0)
373
+ if dtype == vec2h:
374
+ return ("wp::vec2h", 3, 1)
375
+ if dtype == vec2f:
376
+ return ("wp::vec2f", 5, 1)
377
+ if dtype == vec2d:
378
+ return ("wp::vec2d", 6, 1)
379
+ raise TypeError("Unsupported input type in tile_matmul")
380
+
381
+ def cublasdx_arrangement_map(layout):
382
+ if layout == "colmajor":
383
+ return 0 # CUBLASDX_ARRANGEMENT_COL_MAJOR
384
+ if layout == "rowmajor":
385
+ return 1 # CUBLASDX_ARRANGEMENT_ROW_MAJOR
386
+ raise ValueError("Unsupported layout in tile_matmul")
387
+
388
+ (a_dtype, a_prec, a_type) = cublasdx_type_map(adtype)
389
+ (b_dtype, b_prec, b_type) = cublasdx_type_map(bdtype)
390
+ (c_dtype, c_prec, c_type) = cublasdx_type_map(cdtype)
391
+ a_arrangement = cublasdx_arrangement_map(alayout)
392
+ b_arrangement = cublasdx_arrangement_map(blayout)
393
+ c_arrangement = cublasdx_arrangement_map(clayout)
394
+
395
+ if a_type != b_type or a_type != c_type:
396
+ raise TypeError("tile_matmul(A, B, C) requires all inputs to be real or complex")
397
+
398
+ element_type = a_type
399
+
400
+ lto_symbol = f"dot_{M}_{N}_{K}_{arch}_{num_threads}_{a_arrangement}_{b_arrangement}_{c_arrangement}_{a_prec}_{b_prec}_{c_prec}_{element_type}"
401
+
402
+ def compile_lto_dot(temp_paths):
403
+ result = warp._src.context.runtime.core.wp_cuda_compile_dot(
404
+ temp_paths[".lto"].encode("utf-8"),
405
+ lto_symbol.encode("utf-8"),
406
+ 0,
407
+ None,
408
+ None,
409
+ arch,
410
+ M,
411
+ N,
412
+ K,
413
+ a_prec,
414
+ b_prec,
415
+ c_prec,
416
+ element_type,
417
+ a_arrangement,
418
+ b_arrangement,
419
+ c_arrangement,
420
+ num_threads,
421
+ )
422
+
423
+ if result:
424
+ with open(temp_paths[".lto"], "rb") as f:
425
+ lto_code_data = f.read()
426
+ return True, {".lto": lto_code_data}
427
+ return False, {}
428
+
429
+ # Early out if already cached in module
430
+ if lto_symbol in builder.ltoirs:
431
+ lto_code_data = builder.ltoirs[lto_symbol]
432
+ else:
433
+ (result, lto_code_data) = _build_lto_base(lto_symbol, compile_lto_dot, builder, {})
434
+
435
+ if not result:
436
+ raise RuntimeError(
437
+ f"Failed to compile LTO '{lto_symbol}'. "
438
+ "Set the environment variable LIBMATHDX_LOG_LEVEL=5 and rerun for more details."
439
+ )
440
+
441
+ # Update builder
442
+ builder.ltoirs[lto_symbol] = lto_code_data
443
+ builder.ltoirs_decl[lto_symbol] = (
444
+ f"void {lto_symbol}({c_dtype}*, {a_dtype}*, {b_dtype}*, {c_dtype}*, {c_dtype}*);"
445
+ )
446
+
447
+ return lto_symbol, lto_code_data
448
+
449
+
450
+ def build_lto_solver(
451
+ M,
452
+ N,
453
+ NRHS,
454
+ solver,
455
+ solver_enum,
456
+ side_enum,
457
+ diag_enum,
458
+ alayout,
459
+ blayout,
460
+ fill_mode,
461
+ arch,
462
+ precision_enum,
463
+ num_threads,
464
+ parameter_list,
465
+ builder,
466
+ smem_estimate_bytes=None,
467
+ ):
468
+ arch = 120 if arch > 121 else arch
469
+
470
+ def cusolverdx_arrangement_map(layout):
471
+ if layout == "colmajor":
472
+ return 0 # CUSOLVERDX_ARRANGEMENT_COL_MAJOR
473
+ if layout == "rowmajor":
474
+ return 1 # CUSOLVERDX_ARRANGEMENT_ROW_MAJOR
475
+ raise ValueError("Unsupported layout in tile_matmul")
476
+
477
+ a_arrangement = cusolverdx_arrangement_map(alayout)
478
+ b_arrangement = cusolverdx_arrangement_map(blayout)
479
+
480
+ lto_symbol = f"{solver}_{M}_{N}_{NRHS}_{arch}_{num_threads}_{a_arrangement}_{b_arrangement}_{precision_enum}_{side_enum if side_enum >= 0 else 'x'}_{diag_enum if diag_enum >= 0 else 'x'}_{fill_mode}"
481
+
482
+ def compile_lto_solver(temp_paths):
483
+ # compile LTO
484
+ result = warp._src.context.runtime.core.wp_cuda_compile_solver(
485
+ temp_paths["_fatbin.lto"].encode("utf-8"),
486
+ temp_paths[".lto"].encode("utf-8"),
487
+ lto_symbol.encode("utf-8"),
488
+ 0,
489
+ None,
490
+ None,
491
+ arch,
492
+ M,
493
+ N,
494
+ NRHS,
495
+ solver_enum,
496
+ side_enum,
497
+ diag_enum,
498
+ precision_enum,
499
+ a_arrangement,
500
+ b_arrangement,
501
+ fill_mode,
502
+ num_threads,
503
+ )
504
+
505
+ if result:
506
+ with open(temp_paths[".lto"], "rb") as f:
507
+ lto_code_data = f.read()
508
+ with open(temp_paths["_fatbin.lto"], "rb") as f:
509
+ universal_fatbin_code_data = f.read()
510
+ return True, {".lto": lto_code_data, "_fatbin.lto": universal_fatbin_code_data}
511
+ return False, {}
512
+
513
+ # Early out if already cached in module
514
+ if lto_symbol in builder.ltoirs:
515
+ lto_code_data = builder.ltoirs[lto_symbol]
516
+ else:
517
+ (result, lto_code_data, universal_fatbin_code_data) = _build_lto_base(
518
+ lto_symbol, compile_lto_solver, builder, {"_fatbin.lto": get_cached_lto}
519
+ )
520
+
521
+ if not result:
522
+ hint = ""
523
+ if smem_estimate_bytes:
524
+ max_smem_bytes = 232448
525
+ max_smem_is_estimate = True
526
+ for d in warp.get_cuda_devices():
527
+ if d.arch == arch:
528
+ # We can directly query the max shared memory for this device
529
+ queried_bytes = warp._src.context.runtime.core.wp_cuda_get_max_shared_memory(d.context)
530
+ if queried_bytes > 0:
531
+ max_smem_bytes = queried_bytes
532
+ max_smem_is_estimate = False
533
+ break
534
+ if smem_estimate_bytes > max_smem_bytes:
535
+ source = "estimated limit" if max_smem_is_estimate else "device-reported limit"
536
+ hint = (
537
+ f"Estimated shared memory requirement is {smem_estimate_bytes}B, "
538
+ f"but the {source} is {max_smem_bytes}B. "
539
+ "The tile size(s) may be too large for this device."
540
+ )
541
+
542
+ if warp._src.context.runtime.toolkit_version < (12, 6):
543
+ raise RuntimeError(
544
+ "cuSolverDx requires CUDA Toolkit 12.6.3 or later. This version of Warp was built against CUDA Toolkit "
545
+ f"{warp._src.context.runtime.toolkit_version[0]}.{warp._src.context.runtime.toolkit_version[1]}. "
546
+ "Upgrade your CUDA Toolkit and rebuild Warp, or install a Warp wheel built with CUDA >= 12.6.3."
547
+ )
548
+ else:
549
+ raise RuntimeError(
550
+ f"Failed to compile LTO '{lto_symbol}'. {hint}"
551
+ " Set the environment variable LIBMATHDX_LOG_LEVEL=5 and rerun for more details."
552
+ )
553
+
554
+ # Update builder
555
+ builder.ltoirs[lto_symbol] = lto_code_data
556
+ builder.ltoirs_decl[lto_symbol] = f"void {lto_symbol}{parameter_list};"
557
+ builder.fatbins[lto_symbol] = universal_fatbin_code_data
558
+
559
+ return lto_symbol, lto_code_data
560
+
561
+
562
+ def build_lto_fft(arch, size, ept, direction, dir, precision, builder):
563
+ arch = 120 if arch > 121 else arch
564
+
565
+ lto_symbol = f"fft_{size}_{ept}_{arch}_{direction}_{precision}"
566
+
567
+ def compile_lto_fft(temp_paths):
568
+ shared_memory_size = ctypes.c_int(0)
569
+
570
+ result = warp._src.context.runtime.core.wp_cuda_compile_fft(
571
+ temp_paths[".lto"].encode("utf-8"),
572
+ lto_symbol.encode("utf-8"),
573
+ 0,
574
+ None,
575
+ None,
576
+ arch,
577
+ size,
578
+ ept,
579
+ dir,
580
+ precision,
581
+ ctypes.byref(shared_memory_size),
582
+ )
583
+
584
+ if result:
585
+ with open(temp_paths[".lto"], "rb") as f:
586
+ lto_code_data = f.read()
587
+
588
+ shared_memory_bytes = tile.round_up(shared_memory_size.value)
589
+
590
+ # output meta file with shared memory requirements for this lto_symbol
591
+ meta = {}
592
+ meta[lto_symbol] = shared_memory_bytes
593
+
594
+ with open(temp_paths[".meta"], "w") as meta_file:
595
+ json.dump(meta, meta_file)
596
+
597
+ return True, {".lto": lto_code_data, ".meta": shared_memory_bytes}
598
+
599
+ return False, {}
600
+
601
+ # Early out if already cached in module
602
+ if lto_symbol in builder.ltoirs and lto_symbol in builder.shared_memory_bytes:
603
+ lto_code_data = builder.ltoirs[lto_symbol]
604
+ shared_memory_bytes = builder.shared_memory_bytes[lto_symbol]
605
+ else:
606
+ (result, lto_code_data, shared_memory_bytes) = _build_lto_base(
607
+ lto_symbol, compile_lto_fft, builder, {".meta": lambda path: get_cached_lto_meta(path, lto_symbol)}
608
+ )
609
+
610
+ if not result:
611
+ raise RuntimeError(
612
+ f"Failed to compile LTO '{lto_symbol}'."
613
+ "Set the environment variable LIBMATHDX_LOG_LEVEL=5 and rerun for more details."
614
+ )
615
+
616
+ # Update builder
617
+ builder.ltoirs[lto_symbol] = lto_code_data
618
+ builder.shared_memory_bytes[lto_symbol] = shared_memory_bytes
619
+
620
+ return lto_symbol, lto_code_data, shared_memory_bytes