warp-lang 1.0.2__py3-none-win_amd64.whl → 1.2.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 (356) hide show
  1. warp/__init__.py +108 -97
  2. warp/__init__.pyi +1 -1
  3. warp/bin/warp-clang.dll +0 -0
  4. warp/bin/warp.dll +0 -0
  5. warp/build.py +88 -113
  6. warp/build_dll.py +383 -375
  7. warp/builtins.py +3693 -3354
  8. warp/codegen.py +2925 -2792
  9. warp/config.py +40 -36
  10. warp/constants.py +49 -45
  11. warp/context.py +5409 -5102
  12. warp/dlpack.py +442 -442
  13. warp/examples/__init__.py +16 -16
  14. warp/examples/assets/bear.usd +0 -0
  15. warp/examples/assets/bunny.usd +0 -0
  16. warp/examples/assets/cartpole.urdf +110 -110
  17. warp/examples/assets/crazyflie.usd +0 -0
  18. warp/examples/assets/cube.usd +0 -0
  19. warp/examples/assets/nv_ant.xml +92 -92
  20. warp/examples/assets/nv_humanoid.xml +183 -183
  21. warp/examples/assets/quadruped.urdf +267 -267
  22. warp/examples/assets/rocks.nvdb +0 -0
  23. warp/examples/assets/rocks.usd +0 -0
  24. warp/examples/assets/sphere.usd +0 -0
  25. warp/examples/benchmarks/benchmark_api.py +381 -383
  26. warp/examples/benchmarks/benchmark_cloth.py +278 -277
  27. warp/examples/benchmarks/benchmark_cloth_cupy.py +88 -88
  28. warp/examples/benchmarks/benchmark_cloth_jax.py +97 -100
  29. warp/examples/benchmarks/benchmark_cloth_numba.py +146 -142
  30. warp/examples/benchmarks/benchmark_cloth_numpy.py +77 -77
  31. warp/examples/benchmarks/benchmark_cloth_pytorch.py +86 -86
  32. warp/examples/benchmarks/benchmark_cloth_taichi.py +112 -112
  33. warp/examples/benchmarks/benchmark_cloth_warp.py +145 -146
  34. warp/examples/benchmarks/benchmark_launches.py +293 -295
  35. warp/examples/browse.py +29 -29
  36. warp/examples/core/example_dem.py +232 -219
  37. warp/examples/core/example_fluid.py +291 -267
  38. warp/examples/core/example_graph_capture.py +142 -126
  39. warp/examples/core/example_marching_cubes.py +186 -174
  40. warp/examples/core/example_mesh.py +172 -155
  41. warp/examples/core/example_mesh_intersect.py +203 -193
  42. warp/examples/core/example_nvdb.py +174 -170
  43. warp/examples/core/example_raycast.py +103 -90
  44. warp/examples/core/example_raymarch.py +197 -178
  45. warp/examples/core/example_render_opengl.py +183 -141
  46. warp/examples/core/example_sph.py +403 -387
  47. warp/examples/core/example_torch.py +219 -181
  48. warp/examples/core/example_wave.py +261 -248
  49. warp/examples/fem/bsr_utils.py +378 -380
  50. warp/examples/fem/example_apic_fluid.py +432 -389
  51. warp/examples/fem/example_burgers.py +262 -0
  52. warp/examples/fem/example_convection_diffusion.py +180 -168
  53. warp/examples/fem/example_convection_diffusion_dg.py +217 -209
  54. warp/examples/fem/example_deformed_geometry.py +175 -159
  55. warp/examples/fem/example_diffusion.py +199 -173
  56. warp/examples/fem/example_diffusion_3d.py +178 -152
  57. warp/examples/fem/example_diffusion_mgpu.py +219 -214
  58. warp/examples/fem/example_mixed_elasticity.py +242 -222
  59. warp/examples/fem/example_navier_stokes.py +257 -243
  60. warp/examples/fem/example_stokes.py +218 -192
  61. warp/examples/fem/example_stokes_transfer.py +263 -249
  62. warp/examples/fem/mesh_utils.py +133 -109
  63. warp/examples/fem/plot_utils.py +292 -287
  64. warp/examples/optim/example_bounce.py +258 -246
  65. warp/examples/optim/example_cloth_throw.py +220 -209
  66. warp/examples/optim/example_diffray.py +564 -536
  67. warp/examples/optim/example_drone.py +862 -835
  68. warp/examples/optim/example_inverse_kinematics.py +174 -168
  69. warp/examples/optim/example_inverse_kinematics_torch.py +183 -169
  70. warp/examples/optim/example_spring_cage.py +237 -231
  71. warp/examples/optim/example_trajectory.py +221 -199
  72. warp/examples/optim/example_walker.py +304 -293
  73. warp/examples/sim/example_cartpole.py +137 -129
  74. warp/examples/sim/example_cloth.py +194 -186
  75. warp/examples/sim/example_granular.py +122 -111
  76. warp/examples/sim/example_granular_collision_sdf.py +195 -186
  77. warp/examples/sim/example_jacobian_ik.py +234 -214
  78. warp/examples/sim/example_particle_chain.py +116 -105
  79. warp/examples/sim/example_quadruped.py +191 -180
  80. warp/examples/sim/example_rigid_chain.py +195 -187
  81. warp/examples/sim/example_rigid_contact.py +187 -177
  82. warp/examples/sim/example_rigid_force.py +125 -125
  83. warp/examples/sim/example_rigid_gyroscopic.py +107 -95
  84. warp/examples/sim/example_rigid_soft_contact.py +132 -122
  85. warp/examples/sim/example_soft_body.py +188 -177
  86. warp/fabric.py +337 -335
  87. warp/fem/__init__.py +61 -27
  88. warp/fem/cache.py +403 -388
  89. warp/fem/dirichlet.py +178 -179
  90. warp/fem/domain.py +262 -263
  91. warp/fem/field/__init__.py +100 -101
  92. warp/fem/field/field.py +148 -149
  93. warp/fem/field/nodal_field.py +298 -299
  94. warp/fem/field/restriction.py +22 -21
  95. warp/fem/field/test.py +180 -181
  96. warp/fem/field/trial.py +183 -183
  97. warp/fem/geometry/__init__.py +16 -19
  98. warp/fem/geometry/closest_point.py +69 -70
  99. warp/fem/geometry/deformed_geometry.py +270 -271
  100. warp/fem/geometry/element.py +748 -744
  101. warp/fem/geometry/geometry.py +184 -186
  102. warp/fem/geometry/grid_2d.py +380 -373
  103. warp/fem/geometry/grid_3d.py +437 -435
  104. warp/fem/geometry/hexmesh.py +953 -953
  105. warp/fem/geometry/nanogrid.py +455 -0
  106. warp/fem/geometry/partition.py +374 -376
  107. warp/fem/geometry/quadmesh_2d.py +532 -532
  108. warp/fem/geometry/tetmesh.py +840 -840
  109. warp/fem/geometry/trimesh_2d.py +577 -577
  110. warp/fem/integrate.py +1684 -1615
  111. warp/fem/operator.py +190 -191
  112. warp/fem/polynomial.py +214 -213
  113. warp/fem/quadrature/__init__.py +2 -2
  114. warp/fem/quadrature/pic_quadrature.py +243 -245
  115. warp/fem/quadrature/quadrature.py +295 -294
  116. warp/fem/space/__init__.py +179 -292
  117. warp/fem/space/basis_space.py +522 -489
  118. warp/fem/space/collocated_function_space.py +100 -105
  119. warp/fem/space/dof_mapper.py +236 -236
  120. warp/fem/space/function_space.py +148 -145
  121. warp/fem/space/grid_2d_function_space.py +148 -267
  122. warp/fem/space/grid_3d_function_space.py +167 -306
  123. warp/fem/space/hexmesh_function_space.py +253 -352
  124. warp/fem/space/nanogrid_function_space.py +202 -0
  125. warp/fem/space/partition.py +350 -350
  126. warp/fem/space/quadmesh_2d_function_space.py +261 -369
  127. warp/fem/space/restriction.py +161 -160
  128. warp/fem/space/shape/__init__.py +90 -15
  129. warp/fem/space/shape/cube_shape_function.py +728 -738
  130. warp/fem/space/shape/shape_function.py +102 -103
  131. warp/fem/space/shape/square_shape_function.py +611 -611
  132. warp/fem/space/shape/tet_shape_function.py +565 -567
  133. warp/fem/space/shape/triangle_shape_function.py +429 -429
  134. warp/fem/space/tetmesh_function_space.py +224 -292
  135. warp/fem/space/topology.py +297 -295
  136. warp/fem/space/trimesh_2d_function_space.py +153 -221
  137. warp/fem/types.py +77 -77
  138. warp/fem/utils.py +495 -495
  139. warp/jax.py +166 -141
  140. warp/jax_experimental.py +341 -339
  141. warp/native/array.h +1081 -1025
  142. warp/native/builtin.h +1603 -1560
  143. warp/native/bvh.cpp +402 -398
  144. warp/native/bvh.cu +533 -525
  145. warp/native/bvh.h +430 -429
  146. warp/native/clang/clang.cpp +496 -464
  147. warp/native/crt.cpp +42 -32
  148. warp/native/crt.h +352 -335
  149. warp/native/cuda_crt.h +1049 -1049
  150. warp/native/cuda_util.cpp +549 -540
  151. warp/native/cuda_util.h +288 -203
  152. warp/native/cutlass_gemm.cpp +34 -34
  153. warp/native/cutlass_gemm.cu +372 -372
  154. warp/native/error.cpp +66 -66
  155. warp/native/error.h +27 -27
  156. warp/native/exports.h +187 -0
  157. warp/native/fabric.h +228 -228
  158. warp/native/hashgrid.cpp +301 -278
  159. warp/native/hashgrid.cu +78 -77
  160. warp/native/hashgrid.h +227 -227
  161. warp/native/initializer_array.h +32 -32
  162. warp/native/intersect.h +1204 -1204
  163. warp/native/intersect_adj.h +365 -365
  164. warp/native/intersect_tri.h +322 -322
  165. warp/native/marching.cpp +2 -2
  166. warp/native/marching.cu +497 -497
  167. warp/native/marching.h +2 -2
  168. warp/native/mat.h +1545 -1498
  169. warp/native/matnn.h +333 -333
  170. warp/native/mesh.cpp +203 -203
  171. warp/native/mesh.cu +292 -293
  172. warp/native/mesh.h +1887 -1887
  173. warp/native/nanovdb/GridHandle.h +366 -0
  174. warp/native/nanovdb/HostBuffer.h +590 -0
  175. warp/native/nanovdb/NanoVDB.h +6624 -4782
  176. warp/native/nanovdb/PNanoVDB.h +3390 -2553
  177. warp/native/noise.h +850 -850
  178. warp/native/quat.h +1112 -1085
  179. warp/native/rand.h +303 -299
  180. warp/native/range.h +108 -108
  181. warp/native/reduce.cpp +156 -156
  182. warp/native/reduce.cu +348 -348
  183. warp/native/runlength_encode.cpp +61 -61
  184. warp/native/runlength_encode.cu +46 -46
  185. warp/native/scan.cpp +30 -30
  186. warp/native/scan.cu +36 -36
  187. warp/native/scan.h +7 -7
  188. warp/native/solid_angle.h +442 -442
  189. warp/native/sort.cpp +94 -94
  190. warp/native/sort.cu +97 -97
  191. warp/native/sort.h +14 -14
  192. warp/native/sparse.cpp +337 -337
  193. warp/native/sparse.cu +544 -544
  194. warp/native/spatial.h +630 -630
  195. warp/native/svd.h +562 -562
  196. warp/native/temp_buffer.h +30 -30
  197. warp/native/vec.h +1177 -1133
  198. warp/native/volume.cpp +529 -297
  199. warp/native/volume.cu +58 -32
  200. warp/native/volume.h +960 -538
  201. warp/native/volume_builder.cu +446 -425
  202. warp/native/volume_builder.h +34 -19
  203. warp/native/volume_impl.h +61 -0
  204. warp/native/warp.cpp +1057 -1052
  205. warp/native/warp.cu +2949 -2828
  206. warp/native/warp.h +321 -305
  207. warp/optim/__init__.py +9 -9
  208. warp/optim/adam.py +120 -120
  209. warp/optim/linear.py +1104 -939
  210. warp/optim/sgd.py +104 -92
  211. warp/render/__init__.py +10 -10
  212. warp/render/render_opengl.py +3356 -3204
  213. warp/render/render_usd.py +768 -749
  214. warp/render/utils.py +152 -150
  215. warp/sim/__init__.py +52 -59
  216. warp/sim/articulation.py +685 -685
  217. warp/sim/collide.py +1594 -1590
  218. warp/sim/import_mjcf.py +489 -481
  219. warp/sim/import_snu.py +220 -221
  220. warp/sim/import_urdf.py +536 -516
  221. warp/sim/import_usd.py +887 -881
  222. warp/sim/inertia.py +316 -317
  223. warp/sim/integrator.py +234 -233
  224. warp/sim/integrator_euler.py +1956 -1956
  225. warp/sim/integrator_featherstone.py +1917 -1991
  226. warp/sim/integrator_xpbd.py +3288 -3312
  227. warp/sim/model.py +4473 -4314
  228. warp/sim/particles.py +113 -112
  229. warp/sim/render.py +417 -403
  230. warp/sim/utils.py +413 -410
  231. warp/sparse.py +1289 -1227
  232. warp/stubs.py +2192 -2469
  233. warp/tape.py +1162 -225
  234. warp/tests/__init__.py +1 -1
  235. warp/tests/__main__.py +4 -4
  236. warp/tests/assets/test_index_grid.nvdb +0 -0
  237. warp/tests/assets/torus.usda +105 -105
  238. warp/tests/aux_test_class_kernel.py +26 -26
  239. warp/tests/aux_test_compile_consts_dummy.py +10 -10
  240. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -21
  241. warp/tests/aux_test_dependent.py +20 -22
  242. warp/tests/aux_test_grad_customs.py +21 -23
  243. warp/tests/aux_test_reference.py +9 -11
  244. warp/tests/aux_test_reference_reference.py +8 -10
  245. warp/tests/aux_test_square.py +15 -17
  246. warp/tests/aux_test_unresolved_func.py +14 -14
  247. warp/tests/aux_test_unresolved_symbol.py +14 -14
  248. warp/tests/disabled_kinematics.py +237 -239
  249. warp/tests/run_coverage_serial.py +31 -31
  250. warp/tests/test_adam.py +155 -157
  251. warp/tests/test_arithmetic.py +1088 -1124
  252. warp/tests/test_array.py +2415 -2326
  253. warp/tests/test_array_reduce.py +148 -150
  254. warp/tests/test_async.py +666 -656
  255. warp/tests/test_atomic.py +139 -141
  256. warp/tests/test_bool.py +212 -149
  257. warp/tests/test_builtins_resolution.py +1290 -1292
  258. warp/tests/test_bvh.py +162 -171
  259. warp/tests/test_closest_point_edge_edge.py +227 -228
  260. warp/tests/test_codegen.py +562 -553
  261. warp/tests/test_compile_consts.py +217 -101
  262. warp/tests/test_conditional.py +244 -246
  263. warp/tests/test_copy.py +230 -215
  264. warp/tests/test_ctypes.py +630 -632
  265. warp/tests/test_dense.py +65 -67
  266. warp/tests/test_devices.py +89 -98
  267. warp/tests/test_dlpack.py +528 -529
  268. warp/tests/test_examples.py +403 -378
  269. warp/tests/test_fabricarray.py +952 -955
  270. warp/tests/test_fast_math.py +60 -54
  271. warp/tests/test_fem.py +1298 -1278
  272. warp/tests/test_fp16.py +128 -130
  273. warp/tests/test_func.py +336 -337
  274. warp/tests/test_generics.py +596 -571
  275. warp/tests/test_grad.py +885 -640
  276. warp/tests/test_grad_customs.py +331 -336
  277. warp/tests/test_hash_grid.py +208 -164
  278. warp/tests/test_import.py +37 -39
  279. warp/tests/test_indexedarray.py +1132 -1134
  280. warp/tests/test_intersect.py +65 -67
  281. warp/tests/test_jax.py +305 -307
  282. warp/tests/test_large.py +169 -164
  283. warp/tests/test_launch.py +352 -354
  284. warp/tests/test_lerp.py +217 -261
  285. warp/tests/test_linear_solvers.py +189 -171
  286. warp/tests/test_lvalue.py +419 -493
  287. warp/tests/test_marching_cubes.py +63 -65
  288. warp/tests/test_mat.py +1799 -1827
  289. warp/tests/test_mat_lite.py +113 -115
  290. warp/tests/test_mat_scalar_ops.py +2905 -2889
  291. warp/tests/test_math.py +124 -193
  292. warp/tests/test_matmul.py +498 -499
  293. warp/tests/test_matmul_lite.py +408 -410
  294. warp/tests/test_mempool.py +186 -190
  295. warp/tests/test_mesh.py +281 -324
  296. warp/tests/test_mesh_query_aabb.py +226 -241
  297. warp/tests/test_mesh_query_point.py +690 -702
  298. warp/tests/test_mesh_query_ray.py +290 -303
  299. warp/tests/test_mlp.py +274 -276
  300. warp/tests/test_model.py +108 -110
  301. warp/tests/test_module_hashing.py +111 -0
  302. warp/tests/test_modules_lite.py +36 -39
  303. warp/tests/test_multigpu.py +161 -163
  304. warp/tests/test_noise.py +244 -248
  305. warp/tests/test_operators.py +248 -250
  306. warp/tests/test_options.py +121 -125
  307. warp/tests/test_peer.py +131 -137
  308. warp/tests/test_pinned.py +76 -78
  309. warp/tests/test_print.py +52 -54
  310. warp/tests/test_quat.py +2084 -2086
  311. warp/tests/test_rand.py +324 -288
  312. warp/tests/test_reload.py +207 -217
  313. warp/tests/test_rounding.py +177 -179
  314. warp/tests/test_runlength_encode.py +188 -190
  315. warp/tests/test_sim_grad.py +241 -0
  316. warp/tests/test_sim_kinematics.py +89 -97
  317. warp/tests/test_smoothstep.py +166 -168
  318. warp/tests/test_snippet.py +303 -266
  319. warp/tests/test_sparse.py +466 -460
  320. warp/tests/test_spatial.py +2146 -2148
  321. warp/tests/test_special_values.py +362 -0
  322. warp/tests/test_streams.py +484 -473
  323. warp/tests/test_struct.py +708 -675
  324. warp/tests/test_tape.py +171 -148
  325. warp/tests/test_torch.py +741 -743
  326. warp/tests/test_transient_module.py +85 -87
  327. warp/tests/test_types.py +554 -659
  328. warp/tests/test_utils.py +488 -499
  329. warp/tests/test_vec.py +1262 -1268
  330. warp/tests/test_vec_lite.py +71 -73
  331. warp/tests/test_vec_scalar_ops.py +2097 -2099
  332. warp/tests/test_verify_fp.py +92 -94
  333. warp/tests/test_volume.py +961 -736
  334. warp/tests/test_volume_write.py +338 -265
  335. warp/tests/unittest_serial.py +38 -37
  336. warp/tests/unittest_suites.py +367 -359
  337. warp/tests/unittest_utils.py +434 -578
  338. warp/tests/unused_test_misc.py +69 -71
  339. warp/tests/walkthrough_debug.py +85 -85
  340. warp/thirdparty/appdirs.py +598 -598
  341. warp/thirdparty/dlpack.py +143 -143
  342. warp/thirdparty/unittest_parallel.py +563 -561
  343. warp/torch.py +321 -295
  344. warp/types.py +4941 -4450
  345. warp/utils.py +1008 -821
  346. {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/LICENSE.md +126 -126
  347. {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/METADATA +365 -400
  348. warp_lang-1.2.0.dist-info/RECORD +359 -0
  349. warp/examples/assets/cube.usda +0 -42
  350. warp/examples/assets/sphere.usda +0 -56
  351. warp/examples/assets/torus.usda +0 -105
  352. warp/examples/fem/example_convection_diffusion_dg0.py +0 -194
  353. warp/native/nanovdb/PNanoVDBWrite.h +0 -295
  354. warp_lang-1.0.2.dist-info/RECORD +0 -352
  355. {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/WHEEL +0 -0
  356. {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/top_level.txt +0 -0
@@ -1,561 +1,563 @@
1
- # Licensed under the MIT License
2
- # https://github.com/craigahobbs/unittest-parallel/blob/main/LICENSE
3
-
4
- # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5
- # SPDX-License-Identifier: LicenseRef-NvidiaProprietary
6
- #
7
- # NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
8
- # property and proprietary rights in and to this material, related
9
- # documentation and any modifications thereto. Any use, reproduction,
10
- # disclosure or distribution of this material and related documentation
11
- # without an express license agreement from NVIDIA CORPORATION or
12
- # its affiliates is strictly prohibited.
13
-
14
- """
15
- unittest-parallel command-line script main module
16
- """
17
-
18
- import argparse
19
- import concurrent.futures # NVIDIA Modification
20
- import multiprocessing
21
- import os
22
- import sys
23
- import tempfile
24
- import time
25
- import unittest
26
- from contextlib import contextmanager
27
- from io import StringIO
28
-
29
- import warp.tests.unittest_suites # NVIDIA Modification
30
- from warp.tests.unittest_utils import ( # NVIDIA modification
31
- ParallelJunitTestResult,
32
- ParallelTeamCityTestResult,
33
- write_junit_results,
34
- )
35
-
36
- try:
37
- import coverage
38
-
39
- COVERAGE_AVAILABLE = True # NVIDIA Modification
40
- except ImportError:
41
- COVERAGE_AVAILABLE = False # NVIDIA Modification
42
-
43
-
44
- # The following variables are NVIDIA Modifications
45
- RUNNING_IN_TEAMCITY = os.environ.get("TEAMCITY_VERSION") is not None
46
- TEST_SUITE_NAME = "WarpTests"
47
- START_DIRECTORY = os.path.dirname(__file__) # The directory to start test discovery
48
-
49
-
50
- def main(argv=None):
51
- """
52
- unittest-parallel command-line script main entry point
53
- """
54
-
55
- # Command line arguments
56
- parser = argparse.ArgumentParser(
57
- prog="unittest-parallel",
58
- # NVIDIA Modifications follow:
59
- formatter_class=argparse.RawTextHelpFormatter,
60
- epilog="""Example usage:
61
- python -m warp.tests -s autodetect -p 'test_a*.py'
62
- python -m warp.tests -s kit
63
- python -m warp.tests -k 'mgpu' -k 'cuda'
64
- """,
65
- )
66
- # parser.add_argument("-v", "--verbose", action="store_const", const=2, default=1, help="Verbose output")
67
- parser.add_argument("-q", "--quiet", dest="verbose", action="store_const", const=0, default=2, help="Quiet output")
68
- parser.add_argument("-f", "--failfast", action="store_true", default=False, help="Stop on first fail or error")
69
- parser.add_argument(
70
- "-b", "--buffer", action="store_true", default=False, help="Buffer stdout and stderr during tests"
71
- )
72
- parser.add_argument(
73
- "-k",
74
- dest="testNamePatterns",
75
- action="append",
76
- type=_convert_select_pattern,
77
- help="Only run tests which match the given substring",
78
- )
79
- parser.add_argument(
80
- "-p",
81
- "--pattern",
82
- metavar="PATTERN",
83
- default="test*.py",
84
- help="'autodetect' suite only: Pattern to match tests ('test*.py' default)", # NVIDIA Modification
85
- )
86
- parser.add_argument(
87
- "-t",
88
- "--top-level-directory",
89
- metavar="TOP",
90
- help="Top level directory of project (defaults to start directory)",
91
- )
92
- parser.add_argument(
93
- "--junit-report-xml", metavar="FILE", help="Generate JUnit report format XML file"
94
- ) # NVIDIA Modification
95
- parser.add_argument(
96
- "-s",
97
- "--suite",
98
- type=str,
99
- default="default",
100
- choices=["autodetect", "default", "kit"],
101
- help="Name of the test suite to run (default is 'default').",
102
- ) # NVIDIA Modification
103
- group_parallel = parser.add_argument_group("parallelization options")
104
- group_parallel.add_argument(
105
- "-j",
106
- "--jobs",
107
- metavar="COUNT",
108
- type=int,
109
- default=0,
110
- help="The number of test processes (default is 0, all cores)",
111
- )
112
- group_parallel.add_argument(
113
- "-m",
114
- "--maxjobs",
115
- metavar="MAXCOUNT",
116
- type=int,
117
- default=8,
118
- help="The maximum number of test processes (default is 8)",
119
- ) # NVIDIA Modification
120
- group_parallel.add_argument(
121
- "--level",
122
- choices=["module", "class", "test"],
123
- default="class",
124
- help="Set the test parallelism level (default is 'class')",
125
- )
126
- group_parallel.add_argument(
127
- "--disable-process-pooling",
128
- action="store_true",
129
- default=False,
130
- help="Do not reuse processes used to run test suites",
131
- )
132
- group_parallel.add_argument(
133
- "--disable-concurrent-futures",
134
- action="store_true",
135
- default=False,
136
- help="Use multiprocessing instead of concurrent.futures.",
137
- ) # NVIDIA Modification
138
- group_parallel.add_argument(
139
- "--serial-fallback",
140
- action="store_true",
141
- default=False,
142
- help="Run in a single-process (no spawning) mode without multiprocessing or concurrent.futures.",
143
- ) # NVIDIA Modification
144
- group_coverage = parser.add_argument_group("coverage options")
145
- group_coverage.add_argument("--coverage", action="store_true", help="Run tests with coverage")
146
- group_coverage.add_argument("--coverage-branch", action="store_true", help="Run tests with branch coverage")
147
- group_coverage.add_argument(
148
- "--coverage-html",
149
- metavar="DIR",
150
- help="Generate coverage HTML report",
151
- default=os.path.join(START_DIRECTORY, "..", "..", "htmlcov"),
152
- )
153
- group_coverage.add_argument("--coverage-xml", metavar="FILE", help="Generate coverage XML report")
154
- group_coverage.add_argument(
155
- "--coverage-fail-under", metavar="MIN", type=float, help="Fail if coverage percentage under min"
156
- )
157
- args = parser.parse_args(args=argv)
158
-
159
- if args.coverage_branch:
160
- args.coverage = args.coverage_branch
161
-
162
- if args.coverage and not COVERAGE_AVAILABLE:
163
- parser.exit(
164
- status=2, message="--coverage was used, but coverage was not found. Is it installed?\n"
165
- ) # NVIDIA Modification
166
-
167
- process_count = max(0, args.jobs)
168
- if process_count == 0:
169
- process_count = multiprocessing.cpu_count()
170
- process_count = min(process_count, args.maxjobs) # NVIDIA Modification
171
-
172
- # Create the temporary directory (for coverage files)
173
- with tempfile.TemporaryDirectory() as temp_dir:
174
- # Discover tests
175
- with _coverage(args, temp_dir):
176
- test_loader = unittest.TestLoader()
177
- if args.testNamePatterns:
178
- test_loader.testNamePatterns = args.testNamePatterns
179
-
180
- auto_discover_suite = warp.tests.unittest_suites.auto_discover_suite(
181
- test_loader, args.pattern
182
- ) # NVIDIA Modification
183
-
184
- # NVIDIA Modification
185
- if args.suite != "autodetect":
186
- # Print notices for test classes missing from the suite when compared to auto-discovered tests
187
- discover_suite = warp.tests.unittest_suites.compare_unittest_suites(
188
- test_loader, args.suite, auto_discover_suite
189
- )
190
- else:
191
- discover_suite = auto_discover_suite
192
-
193
- # Get the parallelizable test suites
194
- if args.level == "test":
195
- test_suites = list(_iter_test_cases(discover_suite))
196
- elif args.level == "class":
197
- test_suites = list(_iter_class_suites(discover_suite))
198
- else: # args.level == 'module'
199
- test_suites = list(_iter_module_suites(discover_suite))
200
-
201
- # Don't use more processes than test suites
202
- process_count = max(1, min(len(test_suites), process_count))
203
-
204
- if RUNNING_IN_TEAMCITY:
205
- print(f"##teamcity[testSuiteStarted name='{TEST_SUITE_NAME}']") # NVIDIA Modification for TC
206
-
207
- if not args.serial_fallback:
208
- # Report test suites and processes
209
- print(
210
- f"Running {len(test_suites)} test suites ({discover_suite.countTestCases()} total tests) across {process_count} processes",
211
- file=sys.stderr,
212
- )
213
- if args.verbose > 1:
214
- print(file=sys.stderr)
215
-
216
- # Run the tests in parallel
217
- start_time = time.perf_counter()
218
-
219
- if args.disable_concurrent_futures:
220
- multiprocessing_context = multiprocessing.get_context(method="spawn")
221
- maxtasksperchild = 1 if args.disable_process_pooling else None
222
- with multiprocessing_context.Pool(
223
- process_count,
224
- maxtasksperchild=maxtasksperchild,
225
- initializer=set_worker_cache,
226
- initargs=(args, temp_dir),
227
- ) as pool, multiprocessing.Manager() as manager:
228
- test_manager = ParallelTestManager(manager, args, temp_dir)
229
- results = pool.map(test_manager.run_tests, test_suites)
230
- else:
231
- # NVIDIA Modification added concurrent.futures
232
- with concurrent.futures.ProcessPoolExecutor(
233
- max_workers=process_count,
234
- mp_context=multiprocessing.get_context(method="spawn"),
235
- initializer=set_worker_cache,
236
- initargs=(args, temp_dir),
237
- ) as executor, multiprocessing.Manager() as manager:
238
- test_manager = ParallelTestManager(manager, args, temp_dir)
239
- results = list(executor.map(test_manager.run_tests, test_suites, timeout=3600))
240
- else:
241
- # This entire path is an NVIDIA Modification
242
-
243
- # Report test suites and processes
244
- print(f"Running {discover_suite.countTestCases()} total tests (serial fallback)", file=sys.stderr)
245
- if args.verbose > 1:
246
- print(file=sys.stderr)
247
-
248
- import warp as wp
249
-
250
- wp.init()
251
-
252
- # force rebuild of all kernels
253
- wp.build.clear_kernel_cache()
254
- print("Cleared Warp kernel cache")
255
-
256
- # Run the tests in serial
257
- start_time = time.perf_counter()
258
-
259
- with multiprocessing.Manager() as manager:
260
- test_manager = ParallelTestManager(manager, args, temp_dir)
261
- results = [test_manager.run_tests(discover_suite)]
262
-
263
- stop_time = time.perf_counter()
264
- test_duration = stop_time - start_time
265
-
266
- if RUNNING_IN_TEAMCITY:
267
- print(f"##teamcity[testSuiteFinished name='{TEST_SUITE_NAME}']") # NVIDIA Modification for TC
268
-
269
- # Aggregate parallel test run results
270
- tests_run = 0
271
- errors = []
272
- failures = []
273
- skipped = 0
274
- expected_failures = 0
275
- unexpected_successes = 0
276
- test_records = [] # NVIDIA Modification
277
- for result in results:
278
- tests_run += result[0]
279
- errors.extend(result[1])
280
- failures.extend(result[2])
281
- skipped += result[3]
282
- expected_failures += result[4]
283
- unexpected_successes += result[5]
284
- test_records += result[6] # NVIDIA Modification
285
- is_success = not (errors or failures or unexpected_successes)
286
-
287
- # Compute test info
288
- infos = []
289
- if failures:
290
- infos.append(f"failures={len(failures)}")
291
- if errors:
292
- infos.append(f"errors={len(errors)}")
293
- if skipped:
294
- infos.append(f"skipped={skipped}")
295
- if expected_failures:
296
- infos.append(f"expected failures={expected_failures}")
297
- if unexpected_successes:
298
- infos.append(f"unexpected successes={unexpected_successes}")
299
-
300
- # Report test errors
301
- if errors or failures:
302
- print(file=sys.stderr)
303
- for error in errors:
304
- print(error, file=sys.stderr)
305
- for failure in failures:
306
- print(failure, file=sys.stderr)
307
- elif args.verbose > 0:
308
- print(file=sys.stderr)
309
-
310
- # Test report
311
- print(unittest.TextTestResult.separator2, file=sys.stderr)
312
- print(f'Ran {tests_run} {"tests" if tests_run > 1 else "test"} in {test_duration:.3f}s', file=sys.stderr)
313
- print(file=sys.stderr)
314
- print(f'{"OK" if is_success else "FAILED"}{" (" + ", ".join(infos) + ")" if infos else ""}', file=sys.stderr)
315
-
316
- if test_records and args.junit_report_xml:
317
- # NVIDIA modification to report results in Junit XML format
318
- write_junit_results(
319
- args.junit_report_xml,
320
- test_records,
321
- tests_run,
322
- len(failures) + unexpected_successes,
323
- len(errors),
324
- skipped,
325
- test_duration,
326
- )
327
-
328
- # Return an error status on failure
329
- if not is_success:
330
- if RUNNING_IN_TEAMCITY:
331
- print("##teamcity[buildStatus status='FAILURE']") # NVIDIA Modification for TC
332
- parser.exit(status=len(errors) + len(failures) + unexpected_successes)
333
-
334
- # Coverage?
335
- if args.coverage:
336
- # Combine the coverage files
337
- cov_options = {}
338
- cov_options["config_file"] = True # Grab configuration from pyproject.toml (must install coverage[toml])
339
- cov = coverage.Coverage(**cov_options)
340
- cov.combine(data_paths=[os.path.join(temp_dir, x) for x in os.listdir(temp_dir)])
341
-
342
- # Coverage report
343
- print(file=sys.stderr)
344
- percent_covered = cov.report(ignore_errors=True, file=sys.stderr)
345
- print(f"Total coverage is {percent_covered:.2f}%", file=sys.stderr)
346
-
347
- # HTML coverage report
348
- if args.coverage_html:
349
- cov.html_report(directory=args.coverage_html, ignore_errors=True)
350
-
351
- # XML coverage report
352
- if args.coverage_xml:
353
- cov.xml_report(outfile=args.coverage_xml, ignore_errors=True)
354
-
355
- # Fail under
356
- if args.coverage_fail_under and percent_covered < args.coverage_fail_under:
357
- parser.exit(status=2)
358
-
359
-
360
- def _convert_select_pattern(pattern):
361
- if "*" not in pattern:
362
- return f"*{pattern}*"
363
- return pattern
364
-
365
-
366
- @contextmanager
367
- def _coverage(args, temp_dir):
368
- # Running tests with coverage?
369
- if args.coverage:
370
- # Generate a random coverage data file name - file is deleted along with containing directory
371
- with tempfile.NamedTemporaryFile(dir=temp_dir, delete=False) as coverage_file:
372
- pass
373
-
374
- # Create the coverage object
375
- cov_options = {
376
- "branch": args.coverage_branch,
377
- "data_file": coverage_file.name,
378
- # NVIDIA Modification removed unneeded options
379
- }
380
- cov_options["config_file"] = True # Grab configuration from pyproject.toml (must install coverage[toml])
381
- cov = coverage.Coverage(**cov_options)
382
- try:
383
- # Start measuring code coverage
384
- cov.start()
385
-
386
- # Yield for unit test running
387
- yield cov
388
- finally:
389
- # Stop measuring code coverage
390
- cov.stop()
391
-
392
- # Save the collected coverage data to the data file
393
- cov.save()
394
- else:
395
- # Not running tests with coverage - yield for unit test running
396
- yield None
397
-
398
-
399
- # Iterate module-level test suites - all top-level test suites returned from TestLoader.discover
400
- def _iter_module_suites(test_suite):
401
- for module_suite in test_suite:
402
- if module_suite.countTestCases():
403
- yield module_suite
404
-
405
-
406
- # Iterate class-level test suites - test suites that contains test cases
407
- def _iter_class_suites(test_suite):
408
- has_cases = any(isinstance(suite, unittest.TestCase) for suite in test_suite)
409
- if has_cases:
410
- yield test_suite
411
- else:
412
- for suite in test_suite:
413
- yield from _iter_class_suites(suite)
414
-
415
-
416
- # Iterate test cases (methods)
417
- def _iter_test_cases(test_suite):
418
- if isinstance(test_suite, unittest.TestCase):
419
- yield test_suite
420
- else:
421
- for suite in test_suite:
422
- yield from _iter_test_cases(suite)
423
-
424
-
425
- class ParallelTestManager:
426
- def __init__(self, manager, args, temp_dir):
427
- self.args = args
428
- self.temp_dir = temp_dir
429
- self.failfast = manager.Event()
430
-
431
- def run_tests(self, test_suite):
432
- # Fail fast?
433
- if self.failfast.is_set():
434
- return [0, [], [], 0, 0, 0]
435
-
436
- # NVIDIA Modification for TeamCity and GitLab
437
-
438
- if RUNNING_IN_TEAMCITY:
439
- resultclass = ParallelTeamCityTestResult
440
- elif self.args.junit_report_xml:
441
- resultclass = ParallelJunitTestResult
442
- else:
443
- resultclass = ParallelTextTestResult
444
-
445
- # Run unit tests
446
- with _coverage(self.args, self.temp_dir):
447
- runner = unittest.TextTestRunner(
448
- stream=StringIO(),
449
- resultclass=resultclass, # NVIDIA Modification for TC
450
- verbosity=self.args.verbose,
451
- failfast=self.args.failfast,
452
- buffer=self.args.buffer,
453
- )
454
- result = runner.run(test_suite)
455
-
456
- # Set failfast, if necessary
457
- if result.shouldStop:
458
- self.failfast.set()
459
-
460
- # Clean up kernel cache (NVIDIA modification)
461
- import warp as wp
462
-
463
- wp.init()
464
- wp.build.clear_kernel_cache()
465
-
466
- # Return (test_count, errors, failures, skipped_count, expected_failure_count, unexpected_success_count)
467
- return (
468
- result.testsRun,
469
- [self._format_error(result, error) for error in result.errors],
470
- [self._format_error(result, failure) for failure in result.failures],
471
- len(result.skipped),
472
- len(result.expectedFailures),
473
- len(result.unexpectedSuccesses),
474
- result.test_record, # NVIDIA modification
475
- )
476
-
477
- @staticmethod
478
- def _format_error(result, error):
479
- return "\n".join(
480
- [
481
- unittest.TextTestResult.separator1,
482
- result.getDescription(error[0]),
483
- unittest.TextTestResult.separator2,
484
- error[1],
485
- ]
486
- )
487
-
488
-
489
- class ParallelTextTestResult(unittest.TextTestResult):
490
- def __init__(self, stream, descriptions, verbosity):
491
- stream = type(stream)(sys.stderr)
492
- super().__init__(stream, descriptions, verbosity)
493
- self.test_record = [] # NVIDIA modification
494
-
495
- def startTest(self, test):
496
- if self.showAll:
497
- self.stream.writeln(f"{self.getDescription(test)} ...")
498
- self.stream.flush()
499
- super(unittest.TextTestResult, self).startTest(test)
500
-
501
- def _add_helper(self, test, dots_message, show_all_message):
502
- if self.showAll:
503
- self.stream.writeln(f"{self.getDescription(test)} ... {show_all_message}")
504
- elif self.dots:
505
- self.stream.write(dots_message)
506
- self.stream.flush()
507
-
508
- def addSuccess(self, test):
509
- super(unittest.TextTestResult, self).addSuccess(test)
510
- self._add_helper(test, ".", "ok")
511
-
512
- def addError(self, test, err):
513
- super(unittest.TextTestResult, self).addError(test, err)
514
- self._add_helper(test, "E", "ERROR")
515
-
516
- def addFailure(self, test, err):
517
- super(unittest.TextTestResult, self).addFailure(test, err)
518
- self._add_helper(test, "F", "FAIL")
519
-
520
- def addSkip(self, test, reason):
521
- super(unittest.TextTestResult, self).addSkip(test, reason)
522
- self._add_helper(test, "s", f"skipped {reason!r}")
523
-
524
- def addExpectedFailure(self, test, err):
525
- super(unittest.TextTestResult, self).addExpectedFailure(test, err)
526
- self._add_helper(test, "x", "expected failure")
527
-
528
- def addUnexpectedSuccess(self, test):
529
- super(unittest.TextTestResult, self).addUnexpectedSuccess(test)
530
- self._add_helper(test, "u", "unexpected success")
531
-
532
- def printErrors(self):
533
- pass
534
-
535
-
536
- def set_worker_cache(args, temp_dir):
537
- """Change the Warp cache to avoid conflicts.
538
- This function is run at the start of every new process. (NVIDIA modification)
539
- If the environment variable `WARP_CACHE_ROOT` is detected, the cache will be placed in the provided path.
540
- """
541
-
542
- with _coverage(args, temp_dir):
543
- import warp as wp
544
- from warp.thirdparty import appdirs
545
-
546
- pid = os.getpid()
547
-
548
- if "WARP_CACHE_ROOT" in os.environ:
549
- cache_root_dir = os.path.join(os.getenv("WARP_CACHE_ROOT"), f"{wp.config.version}-{pid}")
550
- else:
551
- cache_root_dir = appdirs.user_cache_dir(
552
- appname="warp", appauthor="NVIDIA", version=f"{wp.config.version}-{pid}"
553
- )
554
-
555
- wp.config.kernel_cache_dir = cache_root_dir
556
- wp.init()
557
- wp.build.clear_kernel_cache()
558
-
559
-
560
- if __name__ == "__main__": # pragma: no cover
561
- main()
1
+ # Licensed under the MIT License
2
+ # https://github.com/craigahobbs/unittest-parallel/blob/main/LICENSE
3
+
4
+ # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5
+ # SPDX-License-Identifier: LicenseRef-NvidiaProprietary
6
+ #
7
+ # NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
8
+ # property and proprietary rights in and to this material, related
9
+ # documentation and any modifications thereto. Any use, reproduction,
10
+ # disclosure or distribution of this material and related documentation
11
+ # without an express license agreement from NVIDIA CORPORATION or
12
+ # its affiliates is strictly prohibited.
13
+
14
+ """
15
+ unittest-parallel command-line script main module
16
+ """
17
+
18
+ import argparse
19
+ import concurrent.futures # NVIDIA Modification
20
+ import multiprocessing
21
+ import os
22
+ import sys
23
+ import tempfile
24
+ import time
25
+ import unittest
26
+ from contextlib import contextmanager
27
+ from io import StringIO
28
+
29
+ import warp.tests.unittest_suites # NVIDIA Modification
30
+ from warp.tests.unittest_utils import ( # NVIDIA modification
31
+ ParallelJunitTestResult,
32
+ write_junit_results,
33
+ )
34
+
35
+ try:
36
+ import coverage
37
+
38
+ COVERAGE_AVAILABLE = True # NVIDIA Modification
39
+ except ImportError:
40
+ COVERAGE_AVAILABLE = False # NVIDIA Modification
41
+
42
+
43
+ # The following variables are NVIDIA Modifications
44
+ START_DIRECTORY = os.path.dirname(__file__) # The directory to start test discovery
45
+
46
+
47
+ def main(argv=None):
48
+ """
49
+ unittest-parallel command-line script main entry point
50
+ """
51
+
52
+ # Command line arguments
53
+ parser = argparse.ArgumentParser(
54
+ prog="unittest-parallel",
55
+ # NVIDIA Modifications follow:
56
+ formatter_class=argparse.RawTextHelpFormatter,
57
+ epilog="""Example usage:
58
+ python -m warp.tests -s autodetect -p 'test_a*.py'
59
+ python -m warp.tests -s kit
60
+ python -m warp.tests -k 'mgpu' -k 'cuda'
61
+ """,
62
+ )
63
+ # parser.add_argument("-v", "--verbose", action="store_const", const=2, default=1, help="Verbose output")
64
+ parser.add_argument("-q", "--quiet", dest="verbose", action="store_const", const=0, default=2, help="Quiet output")
65
+ parser.add_argument("-f", "--failfast", action="store_true", default=False, help="Stop on first fail or error")
66
+ parser.add_argument(
67
+ "-b", "--buffer", action="store_true", default=False, help="Buffer stdout and stderr during tests"
68
+ )
69
+ parser.add_argument(
70
+ "-k",
71
+ dest="testNamePatterns",
72
+ action="append",
73
+ type=_convert_select_pattern,
74
+ help="Only run tests which match the given substring",
75
+ )
76
+ parser.add_argument(
77
+ "-p",
78
+ "--pattern",
79
+ metavar="PATTERN",
80
+ default="test*.py",
81
+ help="'autodetect' suite only: Pattern to match tests ('test*.py' default)", # NVIDIA Modification
82
+ )
83
+ parser.add_argument(
84
+ "-t",
85
+ "--top-level-directory",
86
+ metavar="TOP",
87
+ help="Top level directory of project (defaults to start directory)",
88
+ )
89
+ parser.add_argument(
90
+ "--junit-report-xml", metavar="FILE", help="Generate JUnit report format XML file"
91
+ ) # NVIDIA Modification
92
+ parser.add_argument(
93
+ "-s",
94
+ "--suite",
95
+ type=str,
96
+ default="default",
97
+ choices=["autodetect", "default", "kit"],
98
+ help="Name of the test suite to run (default is 'default').",
99
+ ) # NVIDIA Modification
100
+ group_parallel = parser.add_argument_group("parallelization options")
101
+ group_parallel.add_argument(
102
+ "-j",
103
+ "--jobs",
104
+ metavar="COUNT",
105
+ type=int,
106
+ default=0,
107
+ help="The number of test processes (default is 0, all cores)",
108
+ )
109
+ group_parallel.add_argument(
110
+ "-m",
111
+ "--maxjobs",
112
+ metavar="MAXCOUNT",
113
+ type=int,
114
+ default=8,
115
+ help="The maximum number of test processes (default is 8)",
116
+ ) # NVIDIA Modification
117
+ group_parallel.add_argument(
118
+ "--level",
119
+ choices=["module", "class", "test"],
120
+ default="class",
121
+ help="Set the test parallelism level (default is 'class')",
122
+ )
123
+ group_parallel.add_argument(
124
+ "--disable-process-pooling",
125
+ action="store_true",
126
+ default=False,
127
+ help="Do not reuse processes used to run test suites",
128
+ )
129
+ group_parallel.add_argument(
130
+ "--disable-concurrent-futures",
131
+ action="store_true",
132
+ default=False,
133
+ help="Use multiprocessing instead of concurrent.futures.",
134
+ ) # NVIDIA Modification
135
+ group_parallel.add_argument(
136
+ "--serial-fallback",
137
+ action="store_true",
138
+ default=False,
139
+ help="Run in a single-process (no spawning) mode without multiprocessing or concurrent.futures.",
140
+ ) # NVIDIA Modification
141
+ group_coverage = parser.add_argument_group("coverage options")
142
+ group_coverage.add_argument("--coverage", action="store_true", help="Run tests with coverage")
143
+ group_coverage.add_argument("--coverage-branch", action="store_true", help="Run tests with branch coverage")
144
+ group_coverage.add_argument(
145
+ "--coverage-html",
146
+ metavar="DIR",
147
+ help="Generate coverage HTML report",
148
+ default=os.path.join(START_DIRECTORY, "..", "..", "htmlcov"),
149
+ )
150
+ group_coverage.add_argument("--coverage-xml", metavar="FILE", help="Generate coverage XML report")
151
+ group_coverage.add_argument(
152
+ "--coverage-fail-under", metavar="MIN", type=float, help="Fail if coverage percentage under min"
153
+ )
154
+ group_warp = parser.add_argument_group("NVIDIA Warp options") # NVIDIA Modification
155
+ group_warp.add_argument(
156
+ "--no-shared-cache", action="store_true", help="Use a separate kernel cache per test process."
157
+ )
158
+ args = parser.parse_args(args=argv)
159
+
160
+ if args.coverage_branch:
161
+ args.coverage = args.coverage_branch
162
+
163
+ if args.coverage and not COVERAGE_AVAILABLE:
164
+ parser.exit(
165
+ status=2, message="--coverage was used, but coverage was not found. Is it installed?\n"
166
+ ) # NVIDIA Modification
167
+
168
+ process_count = max(0, args.jobs)
169
+ if process_count == 0:
170
+ process_count = multiprocessing.cpu_count()
171
+ process_count = min(process_count, args.maxjobs) # NVIDIA Modification
172
+
173
+ import warp as wp # NVIDIA Modification
174
+
175
+ # Clear the Warp cache (NVIDIA Modification)
176
+ wp.build.clear_kernel_cache()
177
+ print("Cleared Warp kernel cache")
178
+
179
+ # Create the temporary directory (for coverage files)
180
+ with tempfile.TemporaryDirectory() as temp_dir:
181
+ # Discover tests
182
+ with _coverage(args, temp_dir):
183
+ test_loader = unittest.TestLoader()
184
+ if args.testNamePatterns:
185
+ test_loader.testNamePatterns = args.testNamePatterns
186
+
187
+ auto_discover_suite = warp.tests.unittest_suites.auto_discover_suite(
188
+ test_loader, args.pattern
189
+ ) # NVIDIA Modification
190
+
191
+ # NVIDIA Modification
192
+ if args.suite != "autodetect":
193
+ # Print notices for test classes missing from the suite when compared to auto-discovered tests
194
+ discover_suite = warp.tests.unittest_suites.compare_unittest_suites(
195
+ test_loader, args.suite, auto_discover_suite
196
+ )
197
+ else:
198
+ discover_suite = auto_discover_suite
199
+
200
+ # Get the parallelizable test suites
201
+ if args.level == "test":
202
+ test_suites = list(_iter_test_cases(discover_suite))
203
+ elif args.level == "class":
204
+ test_suites = list(_iter_class_suites(discover_suite))
205
+ else: # args.level == 'module'
206
+ test_suites = list(_iter_module_suites(discover_suite))
207
+
208
+ # Don't use more processes than test suites
209
+ process_count = max(1, min(len(test_suites), process_count))
210
+
211
+ if not args.serial_fallback:
212
+ # Report test suites and processes
213
+ print(
214
+ f"Running {len(test_suites)} test suites ({discover_suite.countTestCases()} total tests) across {process_count} processes",
215
+ file=sys.stderr,
216
+ )
217
+ if args.verbose > 1:
218
+ print(file=sys.stderr)
219
+
220
+ # Create the shared index object used in Warp caches (NVIDIA Modification)
221
+ manager = multiprocessing.Manager()
222
+ shared_index = manager.Value("i", -1)
223
+
224
+ # Run the tests in parallel
225
+ start_time = time.perf_counter()
226
+
227
+ if args.disable_concurrent_futures:
228
+ multiprocessing_context = multiprocessing.get_context(method="spawn")
229
+ maxtasksperchild = 1 if args.disable_process_pooling else None
230
+ with multiprocessing_context.Pool(
231
+ process_count,
232
+ maxtasksperchild=maxtasksperchild,
233
+ initializer=initialize_test_process,
234
+ initargs=(manager.Lock(), shared_index, args, temp_dir),
235
+ ) as pool:
236
+ test_manager = ParallelTestManager(manager, args, temp_dir)
237
+ results = pool.map(test_manager.run_tests, test_suites)
238
+ else:
239
+ # NVIDIA Modification added concurrent.futures
240
+ with concurrent.futures.ProcessPoolExecutor(
241
+ max_workers=process_count,
242
+ mp_context=multiprocessing.get_context(method="spawn"),
243
+ initializer=initialize_test_process,
244
+ initargs=(manager.Lock(), shared_index, args, temp_dir),
245
+ ) as executor:
246
+ test_manager = ParallelTestManager(manager, args, temp_dir)
247
+ results = list(executor.map(test_manager.run_tests, test_suites, timeout=7200))
248
+ else:
249
+ # This entire path is an NVIDIA Modification
250
+
251
+ # Report test suites and processes
252
+ print(f"Running {discover_suite.countTestCases()} total tests (serial fallback)", file=sys.stderr)
253
+ if args.verbose > 1:
254
+ print(file=sys.stderr)
255
+
256
+ # Run the tests in serial
257
+ start_time = time.perf_counter()
258
+
259
+ with multiprocessing.Manager() as manager:
260
+ test_manager = ParallelTestManager(manager, args, temp_dir)
261
+ results = [test_manager.run_tests(discover_suite)]
262
+
263
+ stop_time = time.perf_counter()
264
+ test_duration = stop_time - start_time
265
+
266
+ # Aggregate parallel test run results
267
+ tests_run = 0
268
+ errors = []
269
+ failures = []
270
+ skipped = 0
271
+ expected_failures = 0
272
+ unexpected_successes = 0
273
+ test_records = [] # NVIDIA Modification
274
+ for result in results:
275
+ tests_run += result[0]
276
+ errors.extend(result[1])
277
+ failures.extend(result[2])
278
+ skipped += result[3]
279
+ expected_failures += result[4]
280
+ unexpected_successes += result[5]
281
+ test_records += result[6] # NVIDIA Modification
282
+ is_success = not (errors or failures or unexpected_successes)
283
+
284
+ # Compute test info
285
+ infos = []
286
+ if failures:
287
+ infos.append(f"failures={len(failures)}")
288
+ if errors:
289
+ infos.append(f"errors={len(errors)}")
290
+ if skipped:
291
+ infos.append(f"skipped={skipped}")
292
+ if expected_failures:
293
+ infos.append(f"expected failures={expected_failures}")
294
+ if unexpected_successes:
295
+ infos.append(f"unexpected successes={unexpected_successes}")
296
+
297
+ # Report test errors
298
+ if errors or failures:
299
+ print(file=sys.stderr)
300
+ for error in errors:
301
+ print(error, file=sys.stderr)
302
+ for failure in failures:
303
+ print(failure, file=sys.stderr)
304
+ elif args.verbose > 0:
305
+ print(file=sys.stderr)
306
+
307
+ # Test report
308
+ print(unittest.TextTestResult.separator2, file=sys.stderr)
309
+ print(f'Ran {tests_run} {"tests" if tests_run > 1 else "test"} in {test_duration:.3f}s', file=sys.stderr)
310
+ print(file=sys.stderr)
311
+ print(f'{"OK" if is_success else "FAILED"}{" (" + ", ".join(infos) + ")" if infos else ""}', file=sys.stderr)
312
+
313
+ if test_records and args.junit_report_xml:
314
+ # NVIDIA modification to report results in Junit XML format
315
+ write_junit_results(
316
+ args.junit_report_xml,
317
+ test_records,
318
+ tests_run,
319
+ len(failures) + unexpected_successes,
320
+ len(errors),
321
+ skipped,
322
+ test_duration,
323
+ )
324
+
325
+ # Return an error status on failure
326
+ if not is_success:
327
+ parser.exit(status=len(errors) + len(failures) + unexpected_successes)
328
+
329
+ # Coverage?
330
+ if args.coverage:
331
+ # Combine the coverage files
332
+ cov_options = {}
333
+ cov_options["config_file"] = True # Grab configuration from pyproject.toml (must install coverage[toml])
334
+ cov = coverage.Coverage(**cov_options)
335
+ cov.combine(data_paths=[os.path.join(temp_dir, x) for x in os.listdir(temp_dir)])
336
+
337
+ # Coverage report
338
+ print(file=sys.stderr)
339
+ percent_covered = cov.report(ignore_errors=True, file=sys.stderr)
340
+ print(f"Total coverage is {percent_covered:.2f}%", file=sys.stderr)
341
+
342
+ # HTML coverage report
343
+ if args.coverage_html:
344
+ cov.html_report(directory=args.coverage_html, ignore_errors=True)
345
+
346
+ # XML coverage report
347
+ if args.coverage_xml:
348
+ cov.xml_report(outfile=args.coverage_xml, ignore_errors=True)
349
+
350
+ # Fail under
351
+ if args.coverage_fail_under and percent_covered < args.coverage_fail_under:
352
+ parser.exit(status=2)
353
+
354
+
355
+ def _convert_select_pattern(pattern):
356
+ if "*" not in pattern:
357
+ return f"*{pattern}*"
358
+ return pattern
359
+
360
+
361
+ @contextmanager
362
+ def _coverage(args, temp_dir):
363
+ # Running tests with coverage?
364
+ if args.coverage:
365
+ # Generate a random coverage data file name - file is deleted along with containing directory
366
+ with tempfile.NamedTemporaryFile(dir=temp_dir, delete=False) as coverage_file:
367
+ pass
368
+
369
+ # Create the coverage object
370
+ cov_options = {
371
+ "branch": args.coverage_branch,
372
+ "data_file": coverage_file.name,
373
+ # NVIDIA Modification removed unneeded options
374
+ }
375
+ cov_options["config_file"] = True # Grab configuration from pyproject.toml (must install coverage[toml])
376
+ cov = coverage.Coverage(**cov_options)
377
+ try:
378
+ # Start measuring code coverage
379
+ cov.start()
380
+
381
+ # Yield for unit test running
382
+ yield cov
383
+ finally:
384
+ # Stop measuring code coverage
385
+ cov.stop()
386
+
387
+ # Save the collected coverage data to the data file
388
+ cov.save()
389
+ else:
390
+ # Not running tests with coverage - yield for unit test running
391
+ yield None
392
+
393
+
394
+ # Iterate module-level test suites - all top-level test suites returned from TestLoader.discover
395
+ def _iter_module_suites(test_suite):
396
+ for module_suite in test_suite:
397
+ if module_suite.countTestCases():
398
+ yield module_suite
399
+
400
+
401
+ # Iterate class-level test suites - test suites that contains test cases
402
+ def _iter_class_suites(test_suite):
403
+ has_cases = any(isinstance(suite, unittest.TestCase) for suite in test_suite)
404
+ if has_cases:
405
+ yield test_suite
406
+ else:
407
+ for suite in test_suite:
408
+ yield from _iter_class_suites(suite)
409
+
410
+
411
+ # Iterate test cases (methods)
412
+ def _iter_test_cases(test_suite):
413
+ if isinstance(test_suite, unittest.TestCase):
414
+ yield test_suite
415
+ else:
416
+ for suite in test_suite:
417
+ yield from _iter_test_cases(suite)
418
+
419
+
420
+ class ParallelTestManager:
421
+ def __init__(self, manager, args, temp_dir):
422
+ self.args = args
423
+ self.temp_dir = temp_dir
424
+ self.failfast = manager.Event()
425
+
426
+ def run_tests(self, test_suite):
427
+ # Fail fast?
428
+ if self.failfast.is_set():
429
+ return [0, [], [], 0, 0, 0, []] # NVIDIA Modification
430
+
431
+ # NVIDIA Modification for GitLab
432
+ import warp.tests.unittest_utils
433
+
434
+ warp.tests.unittest_utils.coverage_enabled = self.args.coverage
435
+ warp.tests.unittest_utils.coverage_temp_dir = self.temp_dir
436
+ warp.tests.unittest_utils.coverage_branch = self.args.coverage_branch
437
+
438
+ if self.args.junit_report_xml:
439
+ resultclass = ParallelJunitTestResult
440
+ else:
441
+ resultclass = ParallelTextTestResult
442
+
443
+ # Run unit tests
444
+ with _coverage(self.args, self.temp_dir):
445
+ runner = unittest.TextTestRunner(
446
+ stream=StringIO(),
447
+ resultclass=resultclass, # NVIDIA Modification
448
+ verbosity=self.args.verbose,
449
+ failfast=self.args.failfast,
450
+ buffer=self.args.buffer,
451
+ )
452
+ result = runner.run(test_suite)
453
+
454
+ # Set failfast, if necessary
455
+ if result.shouldStop:
456
+ self.failfast.set()
457
+
458
+ # Return (test_count, errors, failures, skipped_count, expected_failure_count, unexpected_success_count)
459
+ return (
460
+ result.testsRun,
461
+ [self._format_error(result, error) for error in result.errors],
462
+ [self._format_error(result, failure) for failure in result.failures],
463
+ len(result.skipped),
464
+ len(result.expectedFailures),
465
+ len(result.unexpectedSuccesses),
466
+ result.test_record, # NVIDIA modification
467
+ )
468
+
469
+ @staticmethod
470
+ def _format_error(result, error):
471
+ return "\n".join(
472
+ [
473
+ unittest.TextTestResult.separator1,
474
+ result.getDescription(error[0]),
475
+ unittest.TextTestResult.separator2,
476
+ error[1],
477
+ ]
478
+ )
479
+
480
+
481
+ class ParallelTextTestResult(unittest.TextTestResult):
482
+ def __init__(self, stream, descriptions, verbosity):
483
+ stream = type(stream)(sys.stderr)
484
+ super().__init__(stream, descriptions, verbosity)
485
+ self.test_record = [] # NVIDIA modification
486
+
487
+ def startTest(self, test):
488
+ if self.showAll:
489
+ self.stream.writeln(f"{self.getDescription(test)} ...")
490
+ self.stream.flush()
491
+ super(unittest.TextTestResult, self).startTest(test)
492
+
493
+ def _add_helper(self, test, dots_message, show_all_message):
494
+ if self.showAll:
495
+ self.stream.writeln(f"{self.getDescription(test)} ... {show_all_message}")
496
+ elif self.dots:
497
+ self.stream.write(dots_message)
498
+ self.stream.flush()
499
+
500
+ def addSuccess(self, test):
501
+ super(unittest.TextTestResult, self).addSuccess(test)
502
+ self._add_helper(test, ".", "ok")
503
+
504
+ def addError(self, test, err):
505
+ super(unittest.TextTestResult, self).addError(test, err)
506
+ self._add_helper(test, "E", "ERROR")
507
+
508
+ def addFailure(self, test, err):
509
+ super(unittest.TextTestResult, self).addFailure(test, err)
510
+ self._add_helper(test, "F", "FAIL")
511
+
512
+ def addSkip(self, test, reason):
513
+ super(unittest.TextTestResult, self).addSkip(test, reason)
514
+ self._add_helper(test, "s", f"skipped {reason!r}")
515
+
516
+ def addExpectedFailure(self, test, err):
517
+ super(unittest.TextTestResult, self).addExpectedFailure(test, err)
518
+ self._add_helper(test, "x", "expected failure")
519
+
520
+ def addUnexpectedSuccess(self, test):
521
+ super(unittest.TextTestResult, self).addUnexpectedSuccess(test)
522
+ self._add_helper(test, "u", "unexpected success")
523
+
524
+ def printErrors(self):
525
+ pass
526
+
527
+
528
+ def initialize_test_process(lock, shared_index, args, temp_dir):
529
+ """Necessary operations to be executed at the start of every test process.
530
+
531
+ Currently this function can be used to set a separate Warp cache. (NVIDIA modification)
532
+ If the environment variable `WARP_CACHE_ROOT` is detected, the cache will be placed in the provided path.
533
+
534
+ It also ensures that Warp is initialized prior to running any tests.
535
+ """
536
+
537
+ with lock:
538
+ shared_index.value += 1
539
+ worker_index = shared_index.value
540
+
541
+ with _coverage(args, temp_dir):
542
+ import warp as wp
543
+
544
+ if args.no_shared_cache:
545
+ from warp.thirdparty import appdirs
546
+
547
+ if "WARP_CACHE_ROOT" in os.environ:
548
+ cache_root_dir = os.path.join(os.getenv("WARP_CACHE_ROOT"), f"{wp.config.version}-{worker_index:03d}")
549
+ else:
550
+ cache_root_dir = appdirs.user_cache_dir(
551
+ appname="warp", appauthor="NVIDIA", version=f"{wp.config.version}-{worker_index:03d}"
552
+ )
553
+
554
+ wp.config.kernel_cache_dir = cache_root_dir
555
+
556
+ wp.build.clear_kernel_cache()
557
+ else:
558
+ # Initialize Warp is if hasn't been initialized already
559
+ wp.init()
560
+
561
+
562
+ if __name__ == "__main__": # pragma: no cover
563
+ main()