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