warp-lang 1.7.0__py3-none-manylinux_2_34_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of warp-lang might be problematic. Click here for more details.
- warp/__init__.py +139 -0
- warp/__init__.pyi +1 -0
- warp/autograd.py +1142 -0
- warp/bin/warp-clang.so +0 -0
- warp/bin/warp.so +0 -0
- warp/build.py +557 -0
- warp/build_dll.py +405 -0
- warp/builtins.py +6855 -0
- warp/codegen.py +3969 -0
- warp/config.py +158 -0
- warp/constants.py +57 -0
- warp/context.py +6812 -0
- warp/dlpack.py +462 -0
- warp/examples/__init__.py +24 -0
- warp/examples/assets/bear.usd +0 -0
- warp/examples/assets/bunny.usd +0 -0
- warp/examples/assets/cartpole.urdf +110 -0
- warp/examples/assets/crazyflie.usd +0 -0
- warp/examples/assets/cube.usd +0 -0
- warp/examples/assets/nonuniform.usd +0 -0
- warp/examples/assets/nv_ant.xml +92 -0
- warp/examples/assets/nv_humanoid.xml +183 -0
- warp/examples/assets/nvidia_logo.png +0 -0
- warp/examples/assets/pixel.jpg +0 -0
- warp/examples/assets/quadruped.urdf +268 -0
- warp/examples/assets/rocks.nvdb +0 -0
- warp/examples/assets/rocks.usd +0 -0
- warp/examples/assets/sphere.usd +0 -0
- warp/examples/assets/square_cloth.usd +0 -0
- warp/examples/benchmarks/benchmark_api.py +389 -0
- warp/examples/benchmarks/benchmark_cloth.py +296 -0
- warp/examples/benchmarks/benchmark_cloth_cupy.py +96 -0
- warp/examples/benchmarks/benchmark_cloth_jax.py +105 -0
- warp/examples/benchmarks/benchmark_cloth_numba.py +161 -0
- warp/examples/benchmarks/benchmark_cloth_numpy.py +85 -0
- warp/examples/benchmarks/benchmark_cloth_paddle.py +94 -0
- warp/examples/benchmarks/benchmark_cloth_pytorch.py +94 -0
- warp/examples/benchmarks/benchmark_cloth_taichi.py +120 -0
- warp/examples/benchmarks/benchmark_cloth_warp.py +153 -0
- warp/examples/benchmarks/benchmark_gemm.py +164 -0
- warp/examples/benchmarks/benchmark_interop_paddle.py +166 -0
- warp/examples/benchmarks/benchmark_interop_torch.py +166 -0
- warp/examples/benchmarks/benchmark_launches.py +301 -0
- warp/examples/benchmarks/benchmark_tile_load_store.py +103 -0
- warp/examples/browse.py +37 -0
- warp/examples/core/example_cupy.py +86 -0
- warp/examples/core/example_dem.py +241 -0
- warp/examples/core/example_fluid.py +299 -0
- warp/examples/core/example_graph_capture.py +150 -0
- warp/examples/core/example_marching_cubes.py +194 -0
- warp/examples/core/example_mesh.py +180 -0
- warp/examples/core/example_mesh_intersect.py +211 -0
- warp/examples/core/example_nvdb.py +182 -0
- warp/examples/core/example_raycast.py +111 -0
- warp/examples/core/example_raymarch.py +205 -0
- warp/examples/core/example_render_opengl.py +193 -0
- warp/examples/core/example_sample_mesh.py +300 -0
- warp/examples/core/example_sph.py +411 -0
- warp/examples/core/example_torch.py +211 -0
- warp/examples/core/example_wave.py +269 -0
- warp/examples/fem/example_adaptive_grid.py +286 -0
- warp/examples/fem/example_apic_fluid.py +423 -0
- warp/examples/fem/example_burgers.py +261 -0
- warp/examples/fem/example_convection_diffusion.py +178 -0
- warp/examples/fem/example_convection_diffusion_dg.py +204 -0
- warp/examples/fem/example_deformed_geometry.py +172 -0
- warp/examples/fem/example_diffusion.py +196 -0
- warp/examples/fem/example_diffusion_3d.py +225 -0
- warp/examples/fem/example_diffusion_mgpu.py +220 -0
- warp/examples/fem/example_distortion_energy.py +228 -0
- warp/examples/fem/example_magnetostatics.py +240 -0
- warp/examples/fem/example_mixed_elasticity.py +291 -0
- warp/examples/fem/example_navier_stokes.py +261 -0
- warp/examples/fem/example_nonconforming_contact.py +298 -0
- warp/examples/fem/example_stokes.py +213 -0
- warp/examples/fem/example_stokes_transfer.py +262 -0
- warp/examples/fem/example_streamlines.py +352 -0
- warp/examples/fem/utils.py +1000 -0
- warp/examples/interop/example_jax_callable.py +116 -0
- warp/examples/interop/example_jax_ffi_callback.py +132 -0
- warp/examples/interop/example_jax_kernel.py +205 -0
- warp/examples/optim/example_bounce.py +266 -0
- warp/examples/optim/example_cloth_throw.py +228 -0
- warp/examples/optim/example_diffray.py +561 -0
- warp/examples/optim/example_drone.py +870 -0
- warp/examples/optim/example_fluid_checkpoint.py +497 -0
- warp/examples/optim/example_inverse_kinematics.py +182 -0
- warp/examples/optim/example_inverse_kinematics_torch.py +191 -0
- warp/examples/optim/example_softbody_properties.py +400 -0
- warp/examples/optim/example_spring_cage.py +245 -0
- warp/examples/optim/example_trajectory.py +227 -0
- warp/examples/sim/example_cartpole.py +143 -0
- warp/examples/sim/example_cloth.py +225 -0
- warp/examples/sim/example_cloth_self_contact.py +322 -0
- warp/examples/sim/example_granular.py +130 -0
- warp/examples/sim/example_granular_collision_sdf.py +202 -0
- warp/examples/sim/example_jacobian_ik.py +244 -0
- warp/examples/sim/example_particle_chain.py +124 -0
- warp/examples/sim/example_quadruped.py +203 -0
- warp/examples/sim/example_rigid_chain.py +203 -0
- warp/examples/sim/example_rigid_contact.py +195 -0
- warp/examples/sim/example_rigid_force.py +133 -0
- warp/examples/sim/example_rigid_gyroscopic.py +115 -0
- warp/examples/sim/example_rigid_soft_contact.py +140 -0
- warp/examples/sim/example_soft_body.py +196 -0
- warp/examples/tile/example_tile_cholesky.py +87 -0
- warp/examples/tile/example_tile_convolution.py +66 -0
- warp/examples/tile/example_tile_fft.py +55 -0
- warp/examples/tile/example_tile_filtering.py +113 -0
- warp/examples/tile/example_tile_matmul.py +85 -0
- warp/examples/tile/example_tile_mlp.py +383 -0
- warp/examples/tile/example_tile_nbody.py +199 -0
- warp/examples/tile/example_tile_walker.py +327 -0
- warp/fabric.py +355 -0
- warp/fem/__init__.py +106 -0
- warp/fem/adaptivity.py +508 -0
- warp/fem/cache.py +572 -0
- warp/fem/dirichlet.py +202 -0
- warp/fem/domain.py +411 -0
- warp/fem/field/__init__.py +125 -0
- warp/fem/field/field.py +619 -0
- warp/fem/field/nodal_field.py +326 -0
- warp/fem/field/restriction.py +37 -0
- warp/fem/field/virtual.py +848 -0
- warp/fem/geometry/__init__.py +32 -0
- warp/fem/geometry/adaptive_nanogrid.py +857 -0
- warp/fem/geometry/closest_point.py +84 -0
- warp/fem/geometry/deformed_geometry.py +221 -0
- warp/fem/geometry/element.py +776 -0
- warp/fem/geometry/geometry.py +362 -0
- warp/fem/geometry/grid_2d.py +392 -0
- warp/fem/geometry/grid_3d.py +452 -0
- warp/fem/geometry/hexmesh.py +911 -0
- warp/fem/geometry/nanogrid.py +571 -0
- warp/fem/geometry/partition.py +389 -0
- warp/fem/geometry/quadmesh.py +663 -0
- warp/fem/geometry/tetmesh.py +855 -0
- warp/fem/geometry/trimesh.py +806 -0
- warp/fem/integrate.py +2335 -0
- warp/fem/linalg.py +419 -0
- warp/fem/operator.py +293 -0
- warp/fem/polynomial.py +229 -0
- warp/fem/quadrature/__init__.py +17 -0
- warp/fem/quadrature/pic_quadrature.py +299 -0
- warp/fem/quadrature/quadrature.py +591 -0
- warp/fem/space/__init__.py +228 -0
- warp/fem/space/basis_function_space.py +468 -0
- warp/fem/space/basis_space.py +667 -0
- warp/fem/space/dof_mapper.py +251 -0
- warp/fem/space/function_space.py +309 -0
- warp/fem/space/grid_2d_function_space.py +177 -0
- warp/fem/space/grid_3d_function_space.py +227 -0
- warp/fem/space/hexmesh_function_space.py +257 -0
- warp/fem/space/nanogrid_function_space.py +201 -0
- warp/fem/space/partition.py +367 -0
- warp/fem/space/quadmesh_function_space.py +223 -0
- warp/fem/space/restriction.py +179 -0
- warp/fem/space/shape/__init__.py +143 -0
- warp/fem/space/shape/cube_shape_function.py +1105 -0
- warp/fem/space/shape/shape_function.py +133 -0
- warp/fem/space/shape/square_shape_function.py +926 -0
- warp/fem/space/shape/tet_shape_function.py +834 -0
- warp/fem/space/shape/triangle_shape_function.py +672 -0
- warp/fem/space/tetmesh_function_space.py +271 -0
- warp/fem/space/topology.py +424 -0
- warp/fem/space/trimesh_function_space.py +194 -0
- warp/fem/types.py +99 -0
- warp/fem/utils.py +420 -0
- warp/jax.py +187 -0
- warp/jax_experimental/__init__.py +16 -0
- warp/jax_experimental/custom_call.py +351 -0
- warp/jax_experimental/ffi.py +698 -0
- warp/jax_experimental/xla_ffi.py +602 -0
- warp/math.py +244 -0
- warp/native/array.h +1145 -0
- warp/native/builtin.h +1800 -0
- warp/native/bvh.cpp +492 -0
- warp/native/bvh.cu +791 -0
- warp/native/bvh.h +554 -0
- warp/native/clang/clang.cpp +536 -0
- warp/native/coloring.cpp +613 -0
- warp/native/crt.cpp +51 -0
- warp/native/crt.h +362 -0
- warp/native/cuda_crt.h +1058 -0
- warp/native/cuda_util.cpp +646 -0
- warp/native/cuda_util.h +307 -0
- warp/native/error.cpp +77 -0
- warp/native/error.h +36 -0
- warp/native/exports.h +1878 -0
- warp/native/fabric.h +245 -0
- warp/native/hashgrid.cpp +311 -0
- warp/native/hashgrid.cu +87 -0
- warp/native/hashgrid.h +240 -0
- warp/native/initializer_array.h +41 -0
- warp/native/intersect.h +1230 -0
- warp/native/intersect_adj.h +375 -0
- warp/native/intersect_tri.h +339 -0
- warp/native/marching.cpp +19 -0
- warp/native/marching.cu +514 -0
- warp/native/marching.h +19 -0
- warp/native/mat.h +2220 -0
- warp/native/mathdx.cpp +87 -0
- warp/native/matnn.h +343 -0
- warp/native/mesh.cpp +266 -0
- warp/native/mesh.cu +404 -0
- warp/native/mesh.h +1980 -0
- warp/native/nanovdb/GridHandle.h +366 -0
- warp/native/nanovdb/HostBuffer.h +590 -0
- warp/native/nanovdb/NanoVDB.h +6624 -0
- warp/native/nanovdb/PNanoVDB.h +3390 -0
- warp/native/noise.h +859 -0
- warp/native/quat.h +1371 -0
- warp/native/rand.h +342 -0
- warp/native/range.h +139 -0
- warp/native/reduce.cpp +174 -0
- warp/native/reduce.cu +364 -0
- warp/native/runlength_encode.cpp +79 -0
- warp/native/runlength_encode.cu +61 -0
- warp/native/scan.cpp +47 -0
- warp/native/scan.cu +53 -0
- warp/native/scan.h +23 -0
- warp/native/solid_angle.h +466 -0
- warp/native/sort.cpp +251 -0
- warp/native/sort.cu +277 -0
- warp/native/sort.h +33 -0
- warp/native/sparse.cpp +378 -0
- warp/native/sparse.cu +524 -0
- warp/native/spatial.h +657 -0
- warp/native/svd.h +702 -0
- warp/native/temp_buffer.h +46 -0
- warp/native/tile.h +2584 -0
- warp/native/tile_reduce.h +264 -0
- warp/native/vec.h +1426 -0
- warp/native/volume.cpp +501 -0
- warp/native/volume.cu +67 -0
- warp/native/volume.h +969 -0
- warp/native/volume_builder.cu +477 -0
- warp/native/volume_builder.h +52 -0
- warp/native/volume_impl.h +70 -0
- warp/native/warp.cpp +1082 -0
- warp/native/warp.cu +3636 -0
- warp/native/warp.h +381 -0
- warp/optim/__init__.py +17 -0
- warp/optim/adam.py +163 -0
- warp/optim/linear.py +1137 -0
- warp/optim/sgd.py +112 -0
- warp/paddle.py +407 -0
- warp/render/__init__.py +18 -0
- warp/render/render_opengl.py +3518 -0
- warp/render/render_usd.py +784 -0
- warp/render/utils.py +160 -0
- warp/sim/__init__.py +65 -0
- warp/sim/articulation.py +793 -0
- warp/sim/collide.py +2395 -0
- warp/sim/graph_coloring.py +300 -0
- warp/sim/import_mjcf.py +790 -0
- warp/sim/import_snu.py +227 -0
- warp/sim/import_urdf.py +579 -0
- warp/sim/import_usd.py +894 -0
- warp/sim/inertia.py +324 -0
- warp/sim/integrator.py +242 -0
- warp/sim/integrator_euler.py +1997 -0
- warp/sim/integrator_featherstone.py +2101 -0
- warp/sim/integrator_vbd.py +2048 -0
- warp/sim/integrator_xpbd.py +3292 -0
- warp/sim/model.py +4791 -0
- warp/sim/particles.py +121 -0
- warp/sim/render.py +427 -0
- warp/sim/utils.py +428 -0
- warp/sparse.py +2057 -0
- warp/stubs.py +3333 -0
- warp/tape.py +1203 -0
- warp/tests/__init__.py +1 -0
- warp/tests/__main__.py +4 -0
- warp/tests/assets/curlnoise_golden.npy +0 -0
- warp/tests/assets/mlp_golden.npy +0 -0
- warp/tests/assets/pixel.npy +0 -0
- warp/tests/assets/pnoise_golden.npy +0 -0
- warp/tests/assets/spiky.usd +0 -0
- warp/tests/assets/test_grid.nvdb +0 -0
- warp/tests/assets/test_index_grid.nvdb +0 -0
- warp/tests/assets/test_int32_grid.nvdb +0 -0
- warp/tests/assets/test_vec_grid.nvdb +0 -0
- warp/tests/assets/torus.nvdb +0 -0
- warp/tests/assets/torus.usda +105 -0
- warp/tests/aux_test_class_kernel.py +34 -0
- warp/tests/aux_test_compile_consts_dummy.py +18 -0
- warp/tests/aux_test_conditional_unequal_types_kernels.py +29 -0
- warp/tests/aux_test_dependent.py +29 -0
- warp/tests/aux_test_grad_customs.py +29 -0
- warp/tests/aux_test_instancing_gc.py +26 -0
- warp/tests/aux_test_module_unload.py +23 -0
- warp/tests/aux_test_name_clash1.py +40 -0
- warp/tests/aux_test_name_clash2.py +40 -0
- warp/tests/aux_test_reference.py +9 -0
- warp/tests/aux_test_reference_reference.py +8 -0
- warp/tests/aux_test_square.py +16 -0
- warp/tests/aux_test_unresolved_func.py +22 -0
- warp/tests/aux_test_unresolved_symbol.py +22 -0
- warp/tests/cuda/__init__.py +0 -0
- warp/tests/cuda/test_async.py +676 -0
- warp/tests/cuda/test_ipc.py +124 -0
- warp/tests/cuda/test_mempool.py +233 -0
- warp/tests/cuda/test_multigpu.py +169 -0
- warp/tests/cuda/test_peer.py +139 -0
- warp/tests/cuda/test_pinned.py +84 -0
- warp/tests/cuda/test_streams.py +634 -0
- warp/tests/geometry/__init__.py +0 -0
- warp/tests/geometry/test_bvh.py +200 -0
- warp/tests/geometry/test_hash_grid.py +221 -0
- warp/tests/geometry/test_marching_cubes.py +74 -0
- warp/tests/geometry/test_mesh.py +316 -0
- warp/tests/geometry/test_mesh_query_aabb.py +399 -0
- warp/tests/geometry/test_mesh_query_point.py +932 -0
- warp/tests/geometry/test_mesh_query_ray.py +311 -0
- warp/tests/geometry/test_volume.py +1103 -0
- warp/tests/geometry/test_volume_write.py +346 -0
- warp/tests/interop/__init__.py +0 -0
- warp/tests/interop/test_dlpack.py +729 -0
- warp/tests/interop/test_jax.py +371 -0
- warp/tests/interop/test_paddle.py +800 -0
- warp/tests/interop/test_torch.py +1001 -0
- warp/tests/run_coverage_serial.py +39 -0
- warp/tests/sim/__init__.py +0 -0
- warp/tests/sim/disabled_kinematics.py +244 -0
- warp/tests/sim/flaky_test_sim_grad.py +290 -0
- warp/tests/sim/test_collision.py +604 -0
- warp/tests/sim/test_coloring.py +258 -0
- warp/tests/sim/test_model.py +224 -0
- warp/tests/sim/test_sim_grad_bounce_linear.py +212 -0
- warp/tests/sim/test_sim_kinematics.py +98 -0
- warp/tests/sim/test_vbd.py +597 -0
- warp/tests/test_adam.py +163 -0
- warp/tests/test_arithmetic.py +1096 -0
- warp/tests/test_array.py +2972 -0
- warp/tests/test_array_reduce.py +156 -0
- warp/tests/test_assert.py +250 -0
- warp/tests/test_atomic.py +153 -0
- warp/tests/test_bool.py +220 -0
- warp/tests/test_builtins_resolution.py +1298 -0
- warp/tests/test_closest_point_edge_edge.py +327 -0
- warp/tests/test_codegen.py +810 -0
- warp/tests/test_codegen_instancing.py +1495 -0
- warp/tests/test_compile_consts.py +215 -0
- warp/tests/test_conditional.py +252 -0
- warp/tests/test_context.py +42 -0
- warp/tests/test_copy.py +238 -0
- warp/tests/test_ctypes.py +638 -0
- warp/tests/test_dense.py +73 -0
- warp/tests/test_devices.py +97 -0
- warp/tests/test_examples.py +482 -0
- warp/tests/test_fabricarray.py +996 -0
- warp/tests/test_fast_math.py +74 -0
- warp/tests/test_fem.py +2003 -0
- warp/tests/test_fp16.py +136 -0
- warp/tests/test_func.py +454 -0
- warp/tests/test_future_annotations.py +98 -0
- warp/tests/test_generics.py +656 -0
- warp/tests/test_grad.py +893 -0
- warp/tests/test_grad_customs.py +339 -0
- warp/tests/test_grad_debug.py +341 -0
- warp/tests/test_implicit_init.py +411 -0
- warp/tests/test_import.py +45 -0
- warp/tests/test_indexedarray.py +1140 -0
- warp/tests/test_intersect.py +73 -0
- warp/tests/test_iter.py +76 -0
- warp/tests/test_large.py +177 -0
- warp/tests/test_launch.py +411 -0
- warp/tests/test_lerp.py +151 -0
- warp/tests/test_linear_solvers.py +193 -0
- warp/tests/test_lvalue.py +427 -0
- warp/tests/test_mat.py +2089 -0
- warp/tests/test_mat_lite.py +122 -0
- warp/tests/test_mat_scalar_ops.py +2913 -0
- warp/tests/test_math.py +178 -0
- warp/tests/test_mlp.py +282 -0
- warp/tests/test_module_hashing.py +258 -0
- warp/tests/test_modules_lite.py +44 -0
- warp/tests/test_noise.py +252 -0
- warp/tests/test_operators.py +299 -0
- warp/tests/test_options.py +129 -0
- warp/tests/test_overwrite.py +551 -0
- warp/tests/test_print.py +339 -0
- warp/tests/test_quat.py +2315 -0
- warp/tests/test_rand.py +339 -0
- warp/tests/test_reload.py +302 -0
- warp/tests/test_rounding.py +185 -0
- warp/tests/test_runlength_encode.py +196 -0
- warp/tests/test_scalar_ops.py +105 -0
- warp/tests/test_smoothstep.py +108 -0
- warp/tests/test_snippet.py +318 -0
- warp/tests/test_sparse.py +582 -0
- warp/tests/test_spatial.py +2229 -0
- warp/tests/test_special_values.py +361 -0
- warp/tests/test_static.py +592 -0
- warp/tests/test_struct.py +734 -0
- warp/tests/test_tape.py +204 -0
- warp/tests/test_transient_module.py +93 -0
- warp/tests/test_triangle_closest_point.py +145 -0
- warp/tests/test_types.py +562 -0
- warp/tests/test_utils.py +588 -0
- warp/tests/test_vec.py +1487 -0
- warp/tests/test_vec_lite.py +80 -0
- warp/tests/test_vec_scalar_ops.py +2327 -0
- warp/tests/test_verify_fp.py +100 -0
- warp/tests/tile/__init__.py +0 -0
- warp/tests/tile/test_tile.py +780 -0
- warp/tests/tile/test_tile_load.py +407 -0
- warp/tests/tile/test_tile_mathdx.py +208 -0
- warp/tests/tile/test_tile_mlp.py +402 -0
- warp/tests/tile/test_tile_reduce.py +447 -0
- warp/tests/tile/test_tile_shared_memory.py +247 -0
- warp/tests/tile/test_tile_view.py +173 -0
- warp/tests/unittest_serial.py +47 -0
- warp/tests/unittest_suites.py +427 -0
- warp/tests/unittest_utils.py +468 -0
- warp/tests/walkthrough_debug.py +93 -0
- warp/thirdparty/__init__.py +0 -0
- warp/thirdparty/appdirs.py +598 -0
- warp/thirdparty/dlpack.py +145 -0
- warp/thirdparty/unittest_parallel.py +570 -0
- warp/torch.py +391 -0
- warp/types.py +5230 -0
- warp/utils.py +1137 -0
- warp_lang-1.7.0.dist-info/METADATA +516 -0
- warp_lang-1.7.0.dist-info/RECORD +429 -0
- warp_lang-1.7.0.dist-info/WHEEL +5 -0
- warp_lang-1.7.0.dist-info/licenses/LICENSE.md +202 -0
- warp_lang-1.7.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,241 @@
|
|
|
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
|
+
###########################################################################
|
|
17
|
+
# Example DEM
|
|
18
|
+
#
|
|
19
|
+
# Shows how to implement a DEM particle simulation with cohesion between
|
|
20
|
+
# particles. Neighbors are found using the wp.HashGrid class, and
|
|
21
|
+
# wp.hash_grid_query(), wp.hash_grid_query_next() kernel methods.
|
|
22
|
+
#
|
|
23
|
+
###########################################################################
|
|
24
|
+
|
|
25
|
+
import numpy as np
|
|
26
|
+
|
|
27
|
+
import warp as wp
|
|
28
|
+
import warp.render
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@wp.func
|
|
32
|
+
def contact_force(n: wp.vec3, v: wp.vec3, c: float, k_n: float, k_d: float, k_f: float, k_mu: float):
|
|
33
|
+
vn = wp.dot(n, v)
|
|
34
|
+
jn = c * k_n
|
|
35
|
+
jd = min(vn, 0.0) * k_d
|
|
36
|
+
|
|
37
|
+
# contact force
|
|
38
|
+
fn = jn + jd
|
|
39
|
+
|
|
40
|
+
# friction force
|
|
41
|
+
vt = v - n * vn
|
|
42
|
+
vs = wp.length(vt)
|
|
43
|
+
|
|
44
|
+
if vs > 0.0:
|
|
45
|
+
vt = vt / vs
|
|
46
|
+
|
|
47
|
+
# Coulomb condition
|
|
48
|
+
ft = wp.min(vs * k_f, k_mu * wp.abs(fn))
|
|
49
|
+
|
|
50
|
+
# total force
|
|
51
|
+
return -n * fn - vt * ft
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@wp.kernel
|
|
55
|
+
def apply_forces(
|
|
56
|
+
grid: wp.uint64,
|
|
57
|
+
particle_x: wp.array(dtype=wp.vec3),
|
|
58
|
+
particle_v: wp.array(dtype=wp.vec3),
|
|
59
|
+
particle_f: wp.array(dtype=wp.vec3),
|
|
60
|
+
radius: float,
|
|
61
|
+
k_contact: float,
|
|
62
|
+
k_damp: float,
|
|
63
|
+
k_friction: float,
|
|
64
|
+
k_mu: float,
|
|
65
|
+
):
|
|
66
|
+
tid = wp.tid()
|
|
67
|
+
|
|
68
|
+
# order threads by cell
|
|
69
|
+
i = wp.hash_grid_point_id(grid, tid)
|
|
70
|
+
|
|
71
|
+
x = particle_x[i]
|
|
72
|
+
v = particle_v[i]
|
|
73
|
+
|
|
74
|
+
f = wp.vec3()
|
|
75
|
+
|
|
76
|
+
# ground contact
|
|
77
|
+
n = wp.vec3(0.0, 1.0, 0.0)
|
|
78
|
+
c = wp.dot(n, x)
|
|
79
|
+
|
|
80
|
+
cohesion_ground = 0.02
|
|
81
|
+
cohesion_particle = 0.0075
|
|
82
|
+
|
|
83
|
+
if c < cohesion_ground:
|
|
84
|
+
f = f + contact_force(n, v, c, k_contact, k_damp, 100.0, 0.5)
|
|
85
|
+
|
|
86
|
+
# particle contact
|
|
87
|
+
neighbors = wp.hash_grid_query(grid, x, radius * 5.0)
|
|
88
|
+
|
|
89
|
+
for index in neighbors:
|
|
90
|
+
if index != i:
|
|
91
|
+
# compute distance to point
|
|
92
|
+
n = x - particle_x[index]
|
|
93
|
+
d = wp.length(n)
|
|
94
|
+
err = d - radius * 2.0
|
|
95
|
+
|
|
96
|
+
if err <= cohesion_particle:
|
|
97
|
+
n = n / d
|
|
98
|
+
vrel = v - particle_v[index]
|
|
99
|
+
|
|
100
|
+
f = f + contact_force(n, vrel, err, k_contact, k_damp, k_friction, k_mu)
|
|
101
|
+
|
|
102
|
+
particle_f[i] = f
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@wp.kernel
|
|
106
|
+
def integrate(
|
|
107
|
+
x: wp.array(dtype=wp.vec3),
|
|
108
|
+
v: wp.array(dtype=wp.vec3),
|
|
109
|
+
f: wp.array(dtype=wp.vec3),
|
|
110
|
+
gravity: wp.vec3,
|
|
111
|
+
dt: float,
|
|
112
|
+
inv_mass: float,
|
|
113
|
+
):
|
|
114
|
+
tid = wp.tid()
|
|
115
|
+
|
|
116
|
+
v_new = v[tid] + f[tid] * inv_mass * dt + gravity * dt
|
|
117
|
+
x_new = x[tid] + v_new * dt
|
|
118
|
+
|
|
119
|
+
v[tid] = v_new
|
|
120
|
+
x[tid] = x_new
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class Example:
|
|
124
|
+
def __init__(self, stage_path="example_dem.usd"):
|
|
125
|
+
fps = 60
|
|
126
|
+
self.frame_dt = 1.0 / fps
|
|
127
|
+
|
|
128
|
+
self.sim_substeps = 64
|
|
129
|
+
self.sim_dt = self.frame_dt / self.sim_substeps
|
|
130
|
+
self.sim_time = 0.0
|
|
131
|
+
|
|
132
|
+
self.point_radius = 0.1
|
|
133
|
+
|
|
134
|
+
self.k_contact = 8000.0
|
|
135
|
+
self.k_damp = 2.0
|
|
136
|
+
self.k_friction = 1.0
|
|
137
|
+
self.k_mu = 100000.0 # for cohesive materials
|
|
138
|
+
|
|
139
|
+
self.inv_mass = 64.0
|
|
140
|
+
|
|
141
|
+
self.grid = wp.HashGrid(128, 128, 128)
|
|
142
|
+
self.grid_cell_size = self.point_radius * 5.0
|
|
143
|
+
|
|
144
|
+
self.points = self.particle_grid(32, 64, 32, (0.0, 0.5, 0.0), self.point_radius, 0.1)
|
|
145
|
+
|
|
146
|
+
self.x = wp.array(self.points, dtype=wp.vec3)
|
|
147
|
+
self.v = wp.array(np.ones([len(self.x), 3]) * np.array([0.0, 0.0, 15.0]), dtype=wp.vec3)
|
|
148
|
+
self.f = wp.zeros_like(self.v)
|
|
149
|
+
|
|
150
|
+
if stage_path:
|
|
151
|
+
self.renderer = wp.render.UsdRenderer(stage_path)
|
|
152
|
+
self.renderer.render_ground()
|
|
153
|
+
else:
|
|
154
|
+
self.renderer = None
|
|
155
|
+
|
|
156
|
+
self.use_cuda_graph = wp.get_device().is_cuda
|
|
157
|
+
if self.use_cuda_graph:
|
|
158
|
+
with wp.ScopedCapture() as capture:
|
|
159
|
+
self.simulate()
|
|
160
|
+
self.graph = capture.graph
|
|
161
|
+
|
|
162
|
+
def simulate(self):
|
|
163
|
+
for _ in range(self.sim_substeps):
|
|
164
|
+
wp.launch(
|
|
165
|
+
kernel=apply_forces,
|
|
166
|
+
dim=len(self.x),
|
|
167
|
+
inputs=[
|
|
168
|
+
self.grid.id,
|
|
169
|
+
self.x,
|
|
170
|
+
self.v,
|
|
171
|
+
self.f,
|
|
172
|
+
self.point_radius,
|
|
173
|
+
self.k_contact,
|
|
174
|
+
self.k_damp,
|
|
175
|
+
self.k_friction,
|
|
176
|
+
self.k_mu,
|
|
177
|
+
],
|
|
178
|
+
)
|
|
179
|
+
wp.launch(
|
|
180
|
+
kernel=integrate,
|
|
181
|
+
dim=len(self.x),
|
|
182
|
+
inputs=[self.x, self.v, self.f, (0.0, -9.8, 0.0), self.sim_dt, self.inv_mass],
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
def step(self):
|
|
186
|
+
with wp.ScopedTimer("step"):
|
|
187
|
+
with wp.ScopedTimer("grid build", active=False):
|
|
188
|
+
self.grid.build(self.x, self.grid_cell_size)
|
|
189
|
+
|
|
190
|
+
if self.use_cuda_graph:
|
|
191
|
+
wp.capture_launch(self.graph)
|
|
192
|
+
else:
|
|
193
|
+
self.simulate()
|
|
194
|
+
|
|
195
|
+
self.sim_time += self.frame_dt
|
|
196
|
+
|
|
197
|
+
def render(self):
|
|
198
|
+
if self.renderer is None:
|
|
199
|
+
return
|
|
200
|
+
|
|
201
|
+
with wp.ScopedTimer("render"):
|
|
202
|
+
self.renderer.begin_frame(self.sim_time)
|
|
203
|
+
self.renderer.render_points(
|
|
204
|
+
points=self.x.numpy(), radius=self.point_radius, name="points", colors=(0.8, 0.3, 0.2)
|
|
205
|
+
)
|
|
206
|
+
self.renderer.end_frame()
|
|
207
|
+
|
|
208
|
+
# creates a grid of particles
|
|
209
|
+
def particle_grid(self, dim_x, dim_y, dim_z, lower, radius, jitter):
|
|
210
|
+
rng = np.random.default_rng(42)
|
|
211
|
+
points = np.meshgrid(np.linspace(0, dim_x, dim_x), np.linspace(0, dim_y, dim_y), np.linspace(0, dim_z, dim_z))
|
|
212
|
+
points_t = np.array((points[0], points[1], points[2])).T * radius * 2.0 + np.array(lower)
|
|
213
|
+
points_t = points_t + rng.random(size=points_t.shape) * radius * jitter
|
|
214
|
+
|
|
215
|
+
return points_t.reshape((-1, 3))
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
if __name__ == "__main__":
|
|
219
|
+
import argparse
|
|
220
|
+
|
|
221
|
+
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
222
|
+
parser.add_argument("--device", type=str, default=None, help="Override the default Warp device.")
|
|
223
|
+
parser.add_argument(
|
|
224
|
+
"--stage_path",
|
|
225
|
+
type=lambda x: None if x == "None" else str(x),
|
|
226
|
+
default="example_dem.usd",
|
|
227
|
+
help="Path to the output USD file.",
|
|
228
|
+
)
|
|
229
|
+
parser.add_argument("--num_frames", type=int, default=200, help="Total number of frames.")
|
|
230
|
+
|
|
231
|
+
args = parser.parse_known_args()[0]
|
|
232
|
+
|
|
233
|
+
with wp.ScopedDevice(args.device):
|
|
234
|
+
example = Example(stage_path=args.stage_path)
|
|
235
|
+
|
|
236
|
+
for _ in range(args.num_frames):
|
|
237
|
+
example.step()
|
|
238
|
+
example.render()
|
|
239
|
+
|
|
240
|
+
if example.renderer:
|
|
241
|
+
example.renderer.save()
|
|
@@ -0,0 +1,299 @@
|
|
|
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
|
+
###########################################################################
|
|
17
|
+
# Example Fluid
|
|
18
|
+
#
|
|
19
|
+
# Shows how to implement a simple 2D Stable Fluids solver using
|
|
20
|
+
# multidimensional arrays and launches.
|
|
21
|
+
#
|
|
22
|
+
###########################################################################
|
|
23
|
+
|
|
24
|
+
import math
|
|
25
|
+
|
|
26
|
+
import warp as wp
|
|
27
|
+
import warp.render
|
|
28
|
+
|
|
29
|
+
grid_width = wp.constant(256)
|
|
30
|
+
grid_height = wp.constant(128)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@wp.func
|
|
34
|
+
def lookup_float(f: wp.array2d(dtype=float), x: int, y: int):
|
|
35
|
+
x = wp.clamp(x, 0, grid_width - 1)
|
|
36
|
+
y = wp.clamp(y, 0, grid_height - 1)
|
|
37
|
+
|
|
38
|
+
return f[x, y]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@wp.func
|
|
42
|
+
def sample_float(f: wp.array2d(dtype=float), x: float, y: float):
|
|
43
|
+
lx = int(wp.floor(x))
|
|
44
|
+
ly = int(wp.floor(y))
|
|
45
|
+
|
|
46
|
+
tx = x - float(lx)
|
|
47
|
+
ty = y - float(ly)
|
|
48
|
+
|
|
49
|
+
s0 = wp.lerp(lookup_float(f, lx, ly), lookup_float(f, lx + 1, ly), tx)
|
|
50
|
+
s1 = wp.lerp(lookup_float(f, lx, ly + 1), lookup_float(f, lx + 1, ly + 1), tx)
|
|
51
|
+
|
|
52
|
+
s = wp.lerp(s0, s1, ty)
|
|
53
|
+
return s
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@wp.func
|
|
57
|
+
def lookup_vel(f: wp.array2d(dtype=wp.vec2), x: int, y: int):
|
|
58
|
+
if x < 0 or x >= grid_width:
|
|
59
|
+
return wp.vec2()
|
|
60
|
+
if y < 0 or y >= grid_height:
|
|
61
|
+
return wp.vec2()
|
|
62
|
+
|
|
63
|
+
return f[x, y]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@wp.func
|
|
67
|
+
def sample_vel(f: wp.array2d(dtype=wp.vec2), x: float, y: float):
|
|
68
|
+
lx = int(wp.floor(x))
|
|
69
|
+
ly = int(wp.floor(y))
|
|
70
|
+
|
|
71
|
+
tx = x - float(lx)
|
|
72
|
+
ty = y - float(ly)
|
|
73
|
+
|
|
74
|
+
s0 = wp.lerp(lookup_vel(f, lx, ly), lookup_vel(f, lx + 1, ly), tx)
|
|
75
|
+
s1 = wp.lerp(lookup_vel(f, lx, ly + 1), lookup_vel(f, lx + 1, ly + 1), tx)
|
|
76
|
+
|
|
77
|
+
s = wp.lerp(s0, s1, ty)
|
|
78
|
+
return s
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@wp.kernel
|
|
82
|
+
def advect(
|
|
83
|
+
u0: wp.array2d(dtype=wp.vec2),
|
|
84
|
+
u1: wp.array2d(dtype=wp.vec2),
|
|
85
|
+
rho0: wp.array2d(dtype=float),
|
|
86
|
+
rho1: wp.array2d(dtype=float),
|
|
87
|
+
dt: float,
|
|
88
|
+
):
|
|
89
|
+
i, j = wp.tid()
|
|
90
|
+
|
|
91
|
+
u = u0[i, j]
|
|
92
|
+
|
|
93
|
+
# trace backward
|
|
94
|
+
p = wp.vec2(float(i), float(j))
|
|
95
|
+
p = p - u * dt
|
|
96
|
+
|
|
97
|
+
# advect
|
|
98
|
+
u1[i, j] = sample_vel(u0, p[0], p[1])
|
|
99
|
+
rho1[i, j] = sample_float(rho0, p[0], p[1])
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@wp.kernel
|
|
103
|
+
def divergence(u: wp.array2d(dtype=wp.vec2), div: wp.array2d(dtype=float)):
|
|
104
|
+
i, j = wp.tid()
|
|
105
|
+
|
|
106
|
+
if i == grid_width - 1:
|
|
107
|
+
return
|
|
108
|
+
if j == grid_height - 1:
|
|
109
|
+
return
|
|
110
|
+
|
|
111
|
+
dx = (u[i + 1, j][0] - u[i, j][0]) * 0.5
|
|
112
|
+
dy = (u[i, j + 1][1] - u[i, j][1]) * 0.5
|
|
113
|
+
|
|
114
|
+
div[i, j] = dx + dy
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@wp.kernel
|
|
118
|
+
def pressure_solve(p0: wp.array2d(dtype=float), p1: wp.array2d(dtype=float), div: wp.array2d(dtype=float)):
|
|
119
|
+
i, j = wp.tid()
|
|
120
|
+
|
|
121
|
+
s1 = lookup_float(p0, i - 1, j)
|
|
122
|
+
s2 = lookup_float(p0, i + 1, j)
|
|
123
|
+
s3 = lookup_float(p0, i, j - 1)
|
|
124
|
+
s4 = lookup_float(p0, i, j + 1)
|
|
125
|
+
|
|
126
|
+
# Jacobi update
|
|
127
|
+
err = s1 + s2 + s3 + s4 - div[i, j]
|
|
128
|
+
|
|
129
|
+
p1[i, j] = err * 0.25
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@wp.kernel
|
|
133
|
+
def pressure_apply(p: wp.array2d(dtype=float), u: wp.array2d(dtype=wp.vec2)):
|
|
134
|
+
i, j = wp.tid()
|
|
135
|
+
|
|
136
|
+
if i == 0 or i == grid_width - 1:
|
|
137
|
+
return
|
|
138
|
+
if j == 0 or j == grid_height - 1:
|
|
139
|
+
return
|
|
140
|
+
|
|
141
|
+
# pressure gradient
|
|
142
|
+
f_p = wp.vec2(p[i + 1, j] - p[i - 1, j], p[i, j + 1] - p[i, j - 1]) * 0.5
|
|
143
|
+
|
|
144
|
+
u[i, j] = u[i, j] - f_p
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@wp.kernel
|
|
148
|
+
def integrate(u: wp.array2d(dtype=wp.vec2), rho: wp.array2d(dtype=float), dt: float):
|
|
149
|
+
i, j = wp.tid()
|
|
150
|
+
|
|
151
|
+
# gravity
|
|
152
|
+
f_g = wp.vec2(-90.8, 0.0) * rho[i, j]
|
|
153
|
+
|
|
154
|
+
# integrate
|
|
155
|
+
u[i, j] = u[i, j] + dt * f_g
|
|
156
|
+
|
|
157
|
+
# fade
|
|
158
|
+
rho[i, j] = rho[i, j] * (1.0 - 0.1 * dt)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@wp.kernel
|
|
162
|
+
def init(rho: wp.array2d(dtype=float), u: wp.array2d(dtype=wp.vec2), radius: int, dir: wp.vec2):
|
|
163
|
+
i, j = wp.tid()
|
|
164
|
+
|
|
165
|
+
d = wp.length(wp.vec2(float(i - grid_width / 2), float(j - grid_height / 2)))
|
|
166
|
+
|
|
167
|
+
if d < radius:
|
|
168
|
+
rho[i, j] = 1.0
|
|
169
|
+
u[i, j] = dir
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class Example:
|
|
173
|
+
def __init__(self):
|
|
174
|
+
fps = 60
|
|
175
|
+
self.frame_dt = 1.0 / fps
|
|
176
|
+
self.sim_substeps = 2
|
|
177
|
+
self.iterations = 100 # Number of pressure iterations
|
|
178
|
+
self.sim_dt = self.frame_dt / self.sim_substeps
|
|
179
|
+
self.sim_time = 0.0
|
|
180
|
+
|
|
181
|
+
shape = (grid_width, grid_height)
|
|
182
|
+
|
|
183
|
+
self.u0 = wp.zeros(shape, dtype=wp.vec2)
|
|
184
|
+
self.u1 = wp.zeros(shape, dtype=wp.vec2)
|
|
185
|
+
|
|
186
|
+
self.rho0 = wp.zeros(shape, dtype=float)
|
|
187
|
+
self.rho1 = wp.zeros(shape, dtype=float)
|
|
188
|
+
|
|
189
|
+
self.p0 = wp.zeros(shape, dtype=float)
|
|
190
|
+
self.p1 = wp.zeros(shape, dtype=float)
|
|
191
|
+
self.div = wp.zeros(shape, dtype=float)
|
|
192
|
+
|
|
193
|
+
# capture pressure solve as a CUDA graph
|
|
194
|
+
self.use_cuda_graph = wp.get_device().is_cuda
|
|
195
|
+
if self.use_cuda_graph:
|
|
196
|
+
with wp.ScopedCapture() as capture:
|
|
197
|
+
self.pressure_iterations()
|
|
198
|
+
self.graph = capture.graph
|
|
199
|
+
|
|
200
|
+
def step(self):
|
|
201
|
+
with wp.ScopedTimer("step"):
|
|
202
|
+
for _ in range(self.sim_substeps):
|
|
203
|
+
shape = (grid_width, grid_height)
|
|
204
|
+
dt = self.sim_dt
|
|
205
|
+
|
|
206
|
+
speed = 400.0
|
|
207
|
+
angle = math.sin(self.sim_time * 4.0) * 1.5
|
|
208
|
+
vel = wp.vec2(math.cos(angle) * speed, math.sin(angle) * speed)
|
|
209
|
+
|
|
210
|
+
# update emitters
|
|
211
|
+
wp.launch(init, dim=shape, inputs=[self.rho0, self.u0, 5, vel])
|
|
212
|
+
|
|
213
|
+
# force integrate
|
|
214
|
+
wp.launch(integrate, dim=shape, inputs=[self.u0, self.rho0, dt])
|
|
215
|
+
wp.launch(divergence, dim=shape, inputs=[self.u0, self.div])
|
|
216
|
+
|
|
217
|
+
# pressure solve
|
|
218
|
+
self.p0.zero_()
|
|
219
|
+
self.p1.zero_()
|
|
220
|
+
|
|
221
|
+
if self.use_cuda_graph:
|
|
222
|
+
wp.capture_launch(self.graph)
|
|
223
|
+
else:
|
|
224
|
+
self.pressure_iterations()
|
|
225
|
+
|
|
226
|
+
# velocity update
|
|
227
|
+
wp.launch(pressure_apply, dim=shape, inputs=[self.p0, self.u0])
|
|
228
|
+
|
|
229
|
+
# semi-Lagrangian advection
|
|
230
|
+
wp.launch(advect, dim=shape, inputs=[self.u0, self.u1, self.rho0, self.rho1, dt])
|
|
231
|
+
|
|
232
|
+
# swap buffers
|
|
233
|
+
(self.u0, self.u1) = (self.u1, self.u0)
|
|
234
|
+
(self.rho0, self.rho1) = (self.rho1, self.rho0)
|
|
235
|
+
|
|
236
|
+
self.sim_time += dt
|
|
237
|
+
|
|
238
|
+
def pressure_iterations(self):
|
|
239
|
+
for _ in range(self.iterations):
|
|
240
|
+
wp.launch(pressure_solve, dim=self.p0.shape, inputs=[self.p0, self.p1, self.div])
|
|
241
|
+
|
|
242
|
+
# swap pressure fields
|
|
243
|
+
(self.p0, self.p1) = (self.p1, self.p0)
|
|
244
|
+
|
|
245
|
+
def step_and_render_frame(self, frame_num=None, img=None):
|
|
246
|
+
self.step()
|
|
247
|
+
|
|
248
|
+
with wp.ScopedTimer("render"):
|
|
249
|
+
if img:
|
|
250
|
+
img.set_array(self.rho0.numpy())
|
|
251
|
+
|
|
252
|
+
return (img,)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
if __name__ == "__main__":
|
|
256
|
+
import argparse
|
|
257
|
+
|
|
258
|
+
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
259
|
+
parser.add_argument("--device", type=str, default=None, help="Override the default Warp device.")
|
|
260
|
+
parser.add_argument("--num_frames", type=int, default=100000, help="Total number of frames.")
|
|
261
|
+
parser.add_argument(
|
|
262
|
+
"--headless",
|
|
263
|
+
action="store_true",
|
|
264
|
+
help="Run in headless mode, suppressing the opening of any graphical windows.",
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
args = parser.parse_known_args()[0]
|
|
268
|
+
|
|
269
|
+
with wp.ScopedDevice(args.device):
|
|
270
|
+
example = Example()
|
|
271
|
+
|
|
272
|
+
if args.headless:
|
|
273
|
+
for _ in range(args.num_frames):
|
|
274
|
+
example.step()
|
|
275
|
+
else:
|
|
276
|
+
import matplotlib
|
|
277
|
+
import matplotlib.animation as anim
|
|
278
|
+
import matplotlib.pyplot as plt
|
|
279
|
+
|
|
280
|
+
fig = plt.figure()
|
|
281
|
+
|
|
282
|
+
img = plt.imshow(
|
|
283
|
+
example.rho0.numpy(),
|
|
284
|
+
origin="lower",
|
|
285
|
+
animated=True,
|
|
286
|
+
interpolation="antialiased",
|
|
287
|
+
)
|
|
288
|
+
img.set_norm(matplotlib.colors.Normalize(0.0, 1.0))
|
|
289
|
+
seq = anim.FuncAnimation(
|
|
290
|
+
fig,
|
|
291
|
+
example.step_and_render_frame,
|
|
292
|
+
fargs=(img,),
|
|
293
|
+
frames=args.num_frames,
|
|
294
|
+
blit=True,
|
|
295
|
+
interval=8,
|
|
296
|
+
repeat=False,
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
plt.show()
|
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
###########################################################################
|
|
17
|
+
# Example Graph Capture
|
|
18
|
+
#
|
|
19
|
+
# Shows how to implement CUDA graph capture using wp.ScopedCapture().
|
|
20
|
+
#
|
|
21
|
+
###########################################################################
|
|
22
|
+
|
|
23
|
+
import numpy as np
|
|
24
|
+
|
|
25
|
+
import warp as wp
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@wp.kernel
|
|
29
|
+
def fbm(
|
|
30
|
+
kernel_seed: int,
|
|
31
|
+
frequency: float,
|
|
32
|
+
amplitude: float,
|
|
33
|
+
x: wp.array(dtype=float),
|
|
34
|
+
y: wp.array(dtype=float),
|
|
35
|
+
z: wp.array2d(dtype=float),
|
|
36
|
+
):
|
|
37
|
+
i, j = wp.tid()
|
|
38
|
+
state = wp.rand_init(kernel_seed)
|
|
39
|
+
|
|
40
|
+
p = frequency * wp.vec2(x[j], y[i])
|
|
41
|
+
n = amplitude * wp.noise(state, p)
|
|
42
|
+
|
|
43
|
+
z[i, j] += n
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@wp.kernel
|
|
47
|
+
def slide(x: wp.array(dtype=float), shift: float):
|
|
48
|
+
tid = wp.tid()
|
|
49
|
+
x[tid] += shift
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class Example:
|
|
53
|
+
def __init__(self):
|
|
54
|
+
self.width = 128
|
|
55
|
+
self.height = 128
|
|
56
|
+
min_x, max_x = 0.0, 2.0
|
|
57
|
+
min_y, max_y = 0.0, 2.0
|
|
58
|
+
|
|
59
|
+
# create a grid of pixels
|
|
60
|
+
x = np.linspace(min_x, max_x, self.width)
|
|
61
|
+
y = np.linspace(min_y, max_y, self.height)
|
|
62
|
+
|
|
63
|
+
self.x = wp.array(x, dtype=float)
|
|
64
|
+
self.y = wp.array(y, dtype=float)
|
|
65
|
+
self.pixel_values = wp.zeros((self.width, self.height), dtype=float)
|
|
66
|
+
|
|
67
|
+
self.seed = 42
|
|
68
|
+
self.shift = 2e-2
|
|
69
|
+
self.frequency = 1.0
|
|
70
|
+
self.amplitude = 1.0
|
|
71
|
+
|
|
72
|
+
# use graph capture if launching from a CUDA-capable device
|
|
73
|
+
self.use_cuda_graph = wp.get_device().is_cuda
|
|
74
|
+
if self.use_cuda_graph:
|
|
75
|
+
# record launches
|
|
76
|
+
with wp.ScopedCapture() as capture:
|
|
77
|
+
self.fbm()
|
|
78
|
+
self.graph = capture.graph
|
|
79
|
+
|
|
80
|
+
def fbm(self):
|
|
81
|
+
for _ in range(16):
|
|
82
|
+
wp.launch(
|
|
83
|
+
kernel=fbm,
|
|
84
|
+
dim=(self.height, self.width),
|
|
85
|
+
inputs=[self.seed, self.frequency, self.amplitude, self.x, self.y],
|
|
86
|
+
outputs=[self.pixel_values],
|
|
87
|
+
)
|
|
88
|
+
self.frequency *= 2.0
|
|
89
|
+
self.amplitude *= 0.5
|
|
90
|
+
|
|
91
|
+
def step(self):
|
|
92
|
+
self.pixel_values.zero_()
|
|
93
|
+
self.frequency = 1.0
|
|
94
|
+
self.amplitude = 1.0
|
|
95
|
+
|
|
96
|
+
with wp.ScopedTimer("step", active=True):
|
|
97
|
+
wp.launch(kernel=slide, dim=self.width, inputs=[self.x, self.shift])
|
|
98
|
+
|
|
99
|
+
if self.use_cuda_graph:
|
|
100
|
+
wp.capture_launch(self.graph)
|
|
101
|
+
else: # cpu path
|
|
102
|
+
self.fbm()
|
|
103
|
+
|
|
104
|
+
def step_and_render(self, frame_num=None, img=None):
|
|
105
|
+
self.step()
|
|
106
|
+
|
|
107
|
+
with wp.ScopedTimer("render"):
|
|
108
|
+
if img:
|
|
109
|
+
pixels = self.pixel_values.numpy()
|
|
110
|
+
pixels = (pixels + 1.0) / 2.0
|
|
111
|
+
img.set_array(pixels)
|
|
112
|
+
|
|
113
|
+
return (img,)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
if __name__ == "__main__":
|
|
117
|
+
import argparse
|
|
118
|
+
|
|
119
|
+
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
120
|
+
parser.add_argument("--device", type=str, default=None, help="Override the default Warp device.")
|
|
121
|
+
parser.add_argument("--num_frames", type=int, default=1000, help="Total number of frames.")
|
|
122
|
+
parser.add_argument(
|
|
123
|
+
"--headless",
|
|
124
|
+
action="store_true",
|
|
125
|
+
help="Run in headless mode, suppressing the opening of any graphical windows.",
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
args = parser.parse_known_args()[0]
|
|
129
|
+
|
|
130
|
+
with wp.ScopedDevice(args.device):
|
|
131
|
+
example = Example()
|
|
132
|
+
|
|
133
|
+
if not args.headless:
|
|
134
|
+
import matplotlib.colors
|
|
135
|
+
import matplotlib.pyplot as plt
|
|
136
|
+
from matplotlib.animation import FuncAnimation
|
|
137
|
+
|
|
138
|
+
# Create the animation
|
|
139
|
+
fig = plt.figure()
|
|
140
|
+
img = plt.imshow(example.pixel_values.numpy(), "gray", origin="lower", animated=True)
|
|
141
|
+
img.set_norm(matplotlib.colors.Normalize(0.0, 1.0))
|
|
142
|
+
|
|
143
|
+
ani = FuncAnimation(fig, example.step_and_render, fargs=(img,), frames=1000, interval=30)
|
|
144
|
+
|
|
145
|
+
# Display the animation
|
|
146
|
+
plt.show()
|
|
147
|
+
|
|
148
|
+
else:
|
|
149
|
+
for _ in range(args.num_frames):
|
|
150
|
+
example.step()
|