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_math.py
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
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
|
-
from typing import NamedTuple
|
|
9
8
|
import unittest
|
|
9
|
+
from typing import NamedTuple
|
|
10
10
|
|
|
11
11
|
import numpy as np
|
|
12
12
|
|
|
13
13
|
import warp as wp
|
|
14
|
-
from warp.tests.
|
|
14
|
+
from warp.tests.unittest_utils import *
|
|
15
15
|
|
|
16
16
|
wp.init()
|
|
17
17
|
|
|
@@ -84,16 +84,110 @@ def test_scalar_math(test, device):
|
|
|
84
84
|
)
|
|
85
85
|
|
|
86
86
|
|
|
87
|
-
def
|
|
88
|
-
|
|
87
|
+
def test_vec_type(test, device):
|
|
88
|
+
vec5 = wp.vec(length=5, dtype=float)
|
|
89
|
+
v = vec5()
|
|
90
|
+
w = vec5()
|
|
91
|
+
a = vec5(1.0)
|
|
92
|
+
b = vec5(0.0, 0.0, 0.0, 0.0, 0.0)
|
|
93
|
+
c = vec5(0.0)
|
|
94
|
+
|
|
95
|
+
v[0] = 1.0
|
|
96
|
+
v.x = 0.0
|
|
97
|
+
v[1:] = [1.0, 1.0, 1.0, 1.0]
|
|
98
|
+
|
|
99
|
+
w[0] = 1.0
|
|
100
|
+
w[1:] = [0.0, 0.0, 0.0, 0.0]
|
|
101
|
+
|
|
102
|
+
if v[0] != w[1] or v.x != w.y:
|
|
103
|
+
raise ValueError("vec setter error")
|
|
104
|
+
|
|
105
|
+
for x in v[1:]:
|
|
106
|
+
if x != 1.0:
|
|
107
|
+
raise ValueError("vec slicing error")
|
|
108
|
+
|
|
109
|
+
if b != c:
|
|
110
|
+
raise ValueError("vec equality error")
|
|
111
|
+
|
|
112
|
+
if str(v) != "[0.0, 1.0, 1.0, 1.0, 1.0]":
|
|
113
|
+
raise ValueError("vec to string error")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_mat_type(test, device):
|
|
117
|
+
mat55 = wp.mat(shape=(5, 5), dtype=float)
|
|
118
|
+
m1 = mat55()
|
|
119
|
+
m2 = mat55()
|
|
120
|
+
|
|
121
|
+
for i in range(5):
|
|
122
|
+
for j in range(5):
|
|
123
|
+
if i == j:
|
|
124
|
+
m1[i, j] = 1.0
|
|
125
|
+
else:
|
|
126
|
+
m1[i, j] = 0.0
|
|
127
|
+
|
|
128
|
+
for i in range(5):
|
|
129
|
+
m2[i] = [1.0, 1.0, 1.0, 1.0, 1.0]
|
|
130
|
+
|
|
131
|
+
a = mat55(1.0)
|
|
132
|
+
b = mat55(
|
|
133
|
+
1.0,
|
|
134
|
+
0.0,
|
|
135
|
+
0.0,
|
|
136
|
+
0.0,
|
|
137
|
+
0.0,
|
|
138
|
+
0.0,
|
|
139
|
+
1.0,
|
|
140
|
+
0.0,
|
|
141
|
+
0.0,
|
|
142
|
+
0.0,
|
|
143
|
+
0.0,
|
|
144
|
+
0.0,
|
|
145
|
+
1.0,
|
|
146
|
+
0.0,
|
|
147
|
+
0.0,
|
|
148
|
+
0.0,
|
|
149
|
+
0.0,
|
|
150
|
+
0.0,
|
|
151
|
+
1.0,
|
|
152
|
+
0.0,
|
|
153
|
+
0.0,
|
|
154
|
+
0.0,
|
|
155
|
+
0.0,
|
|
156
|
+
0.0,
|
|
157
|
+
1.0,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
if m1 != b:
|
|
161
|
+
raise ValueError("mat element setting error")
|
|
162
|
+
|
|
163
|
+
if m2 != a:
|
|
164
|
+
raise ValueError("mat row setting error")
|
|
165
|
+
|
|
166
|
+
if m1[0, 0] != 1.0:
|
|
167
|
+
raise ValueError("mat element getting error")
|
|
168
|
+
|
|
169
|
+
if m2[0] != [1.0, 1.0, 1.0, 1.0, 1.0]:
|
|
170
|
+
raise ValueError("mat row getting error")
|
|
171
|
+
|
|
172
|
+
if (
|
|
173
|
+
str(b)
|
|
174
|
+
!= "[[1.0, 0.0, 0.0, 0.0, 0.0],\n [0.0, 1.0, 0.0, 0.0, 0.0],\n [0.0, 0.0, 1.0, 0.0, 0.0],\n [0.0, 0.0, 0.0, 1.0, 0.0],\n [0.0, 0.0, 0.0, 0.0, 1.0]]"
|
|
175
|
+
):
|
|
176
|
+
raise ValueError("mat to string error")
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
devices = get_test_devices()
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
class TestMath(unittest.TestCase):
|
|
183
|
+
pass
|
|
89
184
|
|
|
90
|
-
class TestMath(parent):
|
|
91
|
-
pass
|
|
92
185
|
|
|
93
|
-
|
|
94
|
-
|
|
186
|
+
add_function_test(TestMath, "test_scalar_math", test_scalar_math, devices=devices)
|
|
187
|
+
add_function_test(TestMath, "test_vec_type", test_vec_type, devices=devices)
|
|
188
|
+
add_function_test(TestMath, "test_mat_type", test_mat_type, devices=devices)
|
|
95
189
|
|
|
96
190
|
|
|
97
191
|
if __name__ == "__main__":
|
|
98
|
-
|
|
192
|
+
wp.build.clear_kernel_cache()
|
|
99
193
|
unittest.main(verbosity=2)
|
warp/tests/test_matmul.py
CHANGED
|
@@ -1,88 +1,107 @@
|
|
|
1
|
-
|
|
1
|
+
# Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
|
|
2
|
+
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
|
3
|
+
# and proprietary rights in and to this software, related documentation
|
|
4
|
+
# and any modifications thereto. Any use, reproduction, disclosure or
|
|
5
|
+
# distribution of this software and related documentation without an express
|
|
6
|
+
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|
7
|
+
|
|
2
8
|
import unittest
|
|
3
9
|
|
|
4
|
-
import
|
|
5
|
-
from warp.tests.test_base import *
|
|
10
|
+
import numpy as np
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
import warp as wp
|
|
13
|
+
from warp.tests.unittest_utils import *
|
|
8
14
|
|
|
9
15
|
wp.init()
|
|
10
|
-
|
|
16
|
+
|
|
17
|
+
from warp.context import runtime # noqa: E402
|
|
11
18
|
|
|
12
19
|
|
|
13
|
-
class
|
|
20
|
+
class gemm_test_bed_runner:
|
|
14
21
|
def __init__(self, dtype, device):
|
|
15
22
|
self.dtype = dtype
|
|
16
23
|
self.device = device
|
|
17
24
|
|
|
18
25
|
def alloc(self, m, n, k, batch_count):
|
|
26
|
+
rng = np.random.default_rng(42)
|
|
19
27
|
low = -4.5
|
|
20
28
|
high = 3.5
|
|
21
29
|
if batch_count == 1:
|
|
22
30
|
A = wp.array2d(
|
|
23
|
-
np.ceil(
|
|
31
|
+
np.ceil(rng.uniform(low=low, high=high, size=(m, k))),
|
|
32
|
+
dtype=self.dtype,
|
|
33
|
+
device=self.device,
|
|
34
|
+
requires_grad=True,
|
|
24
35
|
)
|
|
25
36
|
B = wp.array2d(
|
|
26
|
-
np.ceil(
|
|
37
|
+
np.ceil(rng.uniform(low=low, high=high, size=(k, n))),
|
|
38
|
+
dtype=self.dtype,
|
|
39
|
+
device=self.device,
|
|
40
|
+
requires_grad=True,
|
|
27
41
|
)
|
|
28
42
|
C = wp.array2d(
|
|
29
|
-
np.ceil(
|
|
43
|
+
np.ceil(rng.uniform(low=low, high=high, size=(m, n))),
|
|
44
|
+
dtype=self.dtype,
|
|
45
|
+
device=self.device,
|
|
46
|
+
requires_grad=True,
|
|
30
47
|
)
|
|
31
|
-
D = wp.array2d(np.zeros((m, n)), dtype=self.dtype, device=self.device)
|
|
32
|
-
adj_A = wp.array2d(np.zeros((m, k)), dtype=self.dtype, device=self.device)
|
|
33
|
-
adj_B = wp.array2d(np.zeros((k, n)), dtype=self.dtype, device=self.device)
|
|
34
|
-
adj_C = wp.array2d(np.zeros((m, n)), dtype=self.dtype, device=self.device)
|
|
35
|
-
adj_D = wp.array2d(np.ones((m, n)), dtype=self.dtype, device=self.device)
|
|
48
|
+
D = wp.array2d(np.zeros((m, n)), dtype=self.dtype, device=self.device, requires_grad=True)
|
|
36
49
|
else:
|
|
37
|
-
A = wp.
|
|
38
|
-
np.ceil(
|
|
50
|
+
A = wp.array3d(
|
|
51
|
+
np.ceil(rng.uniform(low=low, high=high, size=(batch_count, m, k))),
|
|
39
52
|
dtype=self.dtype,
|
|
40
53
|
device=self.device,
|
|
54
|
+
requires_grad=True,
|
|
41
55
|
)
|
|
42
|
-
B = wp.
|
|
43
|
-
np.ceil(
|
|
56
|
+
B = wp.array3d(
|
|
57
|
+
np.ceil(rng.uniform(low=low, high=high, size=(batch_count, k, n))),
|
|
44
58
|
dtype=self.dtype,
|
|
45
59
|
device=self.device,
|
|
60
|
+
requires_grad=True,
|
|
46
61
|
)
|
|
47
|
-
C = wp.
|
|
48
|
-
np.ceil(
|
|
62
|
+
C = wp.array3d(
|
|
63
|
+
np.ceil(rng.uniform(low=low, high=high, size=(batch_count, m, n))),
|
|
49
64
|
dtype=self.dtype,
|
|
50
65
|
device=self.device,
|
|
66
|
+
requires_grad=True,
|
|
51
67
|
)
|
|
52
|
-
D = wp.
|
|
53
|
-
|
|
54
|
-
adj_B = wp.array2d(np.zeros((batch_count, k, n)), dtype=self.dtype, device=self.device)
|
|
55
|
-
adj_C = wp.array2d(np.zeros((batch_count, m, n)), dtype=self.dtype, device=self.device)
|
|
56
|
-
adj_D = wp.array2d(np.ones((batch_count, m, n)), dtype=self.dtype, device=self.device)
|
|
57
|
-
return A, B, C, D, adj_A, adj_B, adj_C, adj_D
|
|
68
|
+
D = wp.array3d(np.zeros((batch_count, m, n)), dtype=self.dtype, device=self.device, requires_grad=True)
|
|
69
|
+
return A, B, C, D
|
|
58
70
|
|
|
59
71
|
def run_and_verify(self, m, n, k, batch_count, alpha, beta):
|
|
60
|
-
A, B, C, D
|
|
72
|
+
A, B, C, D = self.alloc(m, n, k, batch_count)
|
|
73
|
+
ones = wp.zeros_like(D)
|
|
74
|
+
ones.fill_(1.0)
|
|
75
|
+
|
|
61
76
|
if batch_count == 1:
|
|
62
|
-
wp.
|
|
77
|
+
tape = wp.Tape()
|
|
78
|
+
with tape:
|
|
79
|
+
wp.matmul(A, B, C, D, alpha, beta, False, self.device)
|
|
80
|
+
tape.backward(grads={D: ones})
|
|
81
|
+
|
|
63
82
|
D_np = alpha * (A.numpy() @ B.numpy()) + beta * C.numpy()
|
|
64
83
|
assert np.array_equal(D_np, D.numpy())
|
|
65
84
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
adj_C_np = beta * adj_D.numpy()
|
|
85
|
+
adj_A_np = alpha * np.matmul(ones.numpy(), B.numpy().transpose())
|
|
86
|
+
adj_B_np = alpha * (A.numpy().transpose() @ ones.numpy())
|
|
87
|
+
adj_C_np = beta * ones.numpy()
|
|
70
88
|
|
|
71
|
-
assert np.array_equal(adj_A_np, adj_A.numpy())
|
|
72
|
-
assert np.array_equal(adj_B_np, adj_B.numpy())
|
|
73
|
-
assert np.array_equal(adj_C_np, adj_C.numpy())
|
|
74
89
|
else:
|
|
75
|
-
wp.
|
|
90
|
+
tape = wp.Tape()
|
|
91
|
+
with tape:
|
|
92
|
+
wp.batched_matmul(A, B, C, D, alpha, beta, False, self.device)
|
|
93
|
+
tape.backward(grads={D: ones})
|
|
94
|
+
|
|
76
95
|
D_np = alpha * np.matmul(A.numpy(), B.numpy()) + beta * C.numpy()
|
|
77
96
|
assert np.array_equal(D_np, D.numpy())
|
|
78
97
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
98
|
+
adj_A_np = alpha * np.matmul(ones.numpy(), B.numpy().transpose((0, 2, 1)))
|
|
99
|
+
adj_B_np = alpha * np.matmul(A.numpy().transpose((0, 2, 1)), ones.numpy())
|
|
100
|
+
adj_C_np = beta * ones.numpy()
|
|
101
|
+
|
|
102
|
+
assert np.array_equal(adj_A_np, A.grad.numpy())
|
|
103
|
+
assert np.array_equal(adj_B_np, B.grad.numpy())
|
|
104
|
+
assert np.array_equal(adj_C_np, C.grad.numpy())
|
|
86
105
|
|
|
87
106
|
def run(self):
|
|
88
107
|
Ms = [64, 128, 512]
|
|
@@ -100,17 +119,156 @@ class GemmTestbedRunner:
|
|
|
100
119
|
self.run_and_verify(m, n, k, batch_count, alpha, beta)
|
|
101
120
|
|
|
102
121
|
|
|
122
|
+
class gemm_test_bed_runner_transpose:
|
|
123
|
+
def __init__(self, dtype, device):
|
|
124
|
+
self.dtype = dtype
|
|
125
|
+
self.device = device
|
|
126
|
+
|
|
127
|
+
def alloc(self, m, n, k, batch_count):
|
|
128
|
+
rng = np.random.default_rng(42)
|
|
129
|
+
low = -4.5
|
|
130
|
+
high = 3.5
|
|
131
|
+
if batch_count == 1:
|
|
132
|
+
A = wp.array2d(
|
|
133
|
+
np.ceil(rng.uniform(low=low, high=high, size=(m, k))),
|
|
134
|
+
dtype=self.dtype,
|
|
135
|
+
device=self.device,
|
|
136
|
+
requires_grad=True,
|
|
137
|
+
)
|
|
138
|
+
B = wp.array2d(
|
|
139
|
+
np.ceil(rng.uniform(low=low, high=high, size=(k, n))),
|
|
140
|
+
dtype=self.dtype,
|
|
141
|
+
device=self.device,
|
|
142
|
+
requires_grad=True,
|
|
143
|
+
)
|
|
144
|
+
C = wp.array2d(
|
|
145
|
+
np.ceil(rng.uniform(low=low, high=high, size=(m, n))),
|
|
146
|
+
dtype=self.dtype,
|
|
147
|
+
device=self.device,
|
|
148
|
+
requires_grad=True,
|
|
149
|
+
)
|
|
150
|
+
D = wp.array2d(np.zeros((m, n)), dtype=self.dtype, device=self.device, requires_grad=True)
|
|
151
|
+
AT = wp.array2d(A.numpy().transpose([1, 0]), dtype=self.dtype, device=self.device, requires_grad=True)
|
|
152
|
+
BT = wp.array2d(B.numpy().transpose([1, 0]), dtype=self.dtype, device=self.device, requires_grad=True)
|
|
153
|
+
else:
|
|
154
|
+
A = wp.array3d(
|
|
155
|
+
np.ceil(rng.uniform(low=low, high=high, size=(batch_count, m, k))),
|
|
156
|
+
dtype=self.dtype,
|
|
157
|
+
device=self.device,
|
|
158
|
+
requires_grad=True,
|
|
159
|
+
)
|
|
160
|
+
B = wp.array3d(
|
|
161
|
+
np.ceil(rng.uniform(low=low, high=high, size=(batch_count, k, n))),
|
|
162
|
+
dtype=self.dtype,
|
|
163
|
+
device=self.device,
|
|
164
|
+
requires_grad=True,
|
|
165
|
+
)
|
|
166
|
+
C = wp.array3d(
|
|
167
|
+
np.ceil(rng.uniform(low=low, high=high, size=(batch_count, m, n))),
|
|
168
|
+
dtype=self.dtype,
|
|
169
|
+
device=self.device,
|
|
170
|
+
requires_grad=True,
|
|
171
|
+
)
|
|
172
|
+
D = wp.array3d(np.zeros((batch_count, m, n)), dtype=self.dtype, device=self.device, requires_grad=True)
|
|
173
|
+
AT = wp.array3d(A.numpy().transpose([0, 2, 1]), dtype=self.dtype, device=self.device, requires_grad=True)
|
|
174
|
+
BT = wp.array3d(B.numpy().transpose([0, 2, 1]), dtype=self.dtype, device=self.device, requires_grad=True)
|
|
175
|
+
return A, B, C, D, AT, BT
|
|
176
|
+
|
|
177
|
+
def run_and_verify(self, m, n, k, batch_count, alpha, beta):
|
|
178
|
+
A, B, C1, D1, AT1, BT1 = self.alloc(m, n, k, batch_count)
|
|
179
|
+
C2 = wp.clone(C1)
|
|
180
|
+
C3 = wp.clone(C1)
|
|
181
|
+
D2 = wp.clone(D1)
|
|
182
|
+
D3 = wp.clone(D1)
|
|
183
|
+
AT2 = wp.clone(AT1)
|
|
184
|
+
BT2 = wp.clone(BT1)
|
|
185
|
+
ones1 = wp.zeros_like(D1)
|
|
186
|
+
ones1.fill_(1.0)
|
|
187
|
+
ones2 = wp.zeros_like(D2)
|
|
188
|
+
ones2.fill_(1.0)
|
|
189
|
+
ones3 = wp.zeros_like(D3)
|
|
190
|
+
ones3.fill_(1.0)
|
|
191
|
+
|
|
192
|
+
if batch_count == 1:
|
|
193
|
+
ATT1 = AT1.transpose([1, 0])
|
|
194
|
+
BTT1 = BT1.transpose([1, 0])
|
|
195
|
+
ATT2 = AT2.transpose([1, 0])
|
|
196
|
+
BTT2 = BT2.transpose([1, 0])
|
|
197
|
+
tape = wp.Tape()
|
|
198
|
+
with tape:
|
|
199
|
+
wp.matmul(A, BTT1, C1, D1, alpha, beta, False, self.device)
|
|
200
|
+
wp.matmul(ATT1, B, C2, D2, alpha, beta, False, self.device)
|
|
201
|
+
wp.matmul(ATT2, BTT2, C3, D3, alpha, beta, False, self.device)
|
|
202
|
+
tape.backward(grads={D1: ones1, D2: ones2, D3: ones3})
|
|
203
|
+
|
|
204
|
+
D_np = alpha * (A.numpy() @ B.numpy()) + beta * C1.numpy()
|
|
205
|
+
assert np.array_equal(D_np, D1.numpy())
|
|
206
|
+
assert np.array_equal(D_np, D2.numpy())
|
|
207
|
+
assert np.array_equal(D_np, D3.numpy())
|
|
208
|
+
|
|
209
|
+
adj_A_np = alpha * (ones1.numpy() @ B.numpy().transpose())
|
|
210
|
+
adj_B_np = alpha * (A.numpy().transpose() @ ones1.numpy())
|
|
211
|
+
adj_C_np = beta * ones1.numpy()
|
|
212
|
+
|
|
213
|
+
else:
|
|
214
|
+
ATT1 = AT1.transpose([0, 2, 1])
|
|
215
|
+
BTT1 = BT1.transpose([0, 2, 1])
|
|
216
|
+
ATT2 = AT2.transpose([0, 2, 1])
|
|
217
|
+
BTT2 = BT2.transpose([0, 2, 1])
|
|
218
|
+
tape = wp.Tape()
|
|
219
|
+
with tape:
|
|
220
|
+
wp.batched_matmul(A, BTT1, C1, D1, alpha, beta, False, self.device)
|
|
221
|
+
wp.batched_matmul(ATT1, B, C2, D2, alpha, beta, False, self.device)
|
|
222
|
+
wp.batched_matmul(ATT2, BTT2, C3, D3, alpha, beta, False, self.device)
|
|
223
|
+
tape.backward(grads={D1: ones1, D2: ones2, D3: ones3})
|
|
224
|
+
|
|
225
|
+
D_np = alpha * np.matmul(A.numpy(), B.numpy()) + beta * C1.numpy()
|
|
226
|
+
assert np.array_equal(D_np, D1.numpy())
|
|
227
|
+
assert np.array_equal(D_np, D2.numpy())
|
|
228
|
+
assert np.array_equal(D_np, D3.numpy())
|
|
229
|
+
|
|
230
|
+
adj_A_np = alpha * np.matmul(ones1.numpy(), B.numpy().transpose((0, 2, 1)))
|
|
231
|
+
adj_B_np = alpha * np.matmul(A.numpy().transpose((0, 2, 1)), ones1.numpy())
|
|
232
|
+
adj_C_np = beta * ones1.numpy()
|
|
233
|
+
|
|
234
|
+
assert np.array_equal(adj_A_np, A.grad.numpy())
|
|
235
|
+
assert np.array_equal(adj_A_np, ATT1.grad.numpy())
|
|
236
|
+
assert np.array_equal(adj_A_np, ATT2.grad.numpy())
|
|
237
|
+
assert np.array_equal(adj_B_np, B.grad.numpy())
|
|
238
|
+
assert np.array_equal(adj_B_np, BTT1.grad.numpy())
|
|
239
|
+
assert np.array_equal(adj_B_np, BTT2.grad.numpy())
|
|
240
|
+
assert np.array_equal(adj_C_np, C1.grad.numpy())
|
|
241
|
+
assert np.array_equal(adj_C_np, C2.grad.numpy())
|
|
242
|
+
assert np.array_equal(adj_C_np, C3.grad.numpy())
|
|
243
|
+
|
|
244
|
+
def run(self):
|
|
245
|
+
m = 16
|
|
246
|
+
n = 32
|
|
247
|
+
k = 64
|
|
248
|
+
batch_counts = [1, 4]
|
|
249
|
+
beta = 1.0
|
|
250
|
+
alpha = 1.0
|
|
251
|
+
|
|
252
|
+
for batch_count in batch_counts:
|
|
253
|
+
self.run_and_verify(m, n, k, batch_count, alpha, beta)
|
|
254
|
+
|
|
255
|
+
|
|
103
256
|
# NOTE: F16 tests are slow due to the performance of the reference numpy F16 matmuls performed on CPU.
|
|
104
257
|
def test_f16(test, device):
|
|
105
|
-
|
|
258
|
+
gemm_test_bed_runner(wp.float16, device).run()
|
|
259
|
+
gemm_test_bed_runner_transpose(wp.float16, device).run()
|
|
106
260
|
|
|
107
261
|
|
|
262
|
+
@unittest.skipUnless(runtime.core.is_cutlass_enabled(), "Warp was not built with CUTLASS support")
|
|
108
263
|
def test_f32(test, device):
|
|
109
|
-
|
|
264
|
+
gemm_test_bed_runner(wp.float32, device).run()
|
|
265
|
+
gemm_test_bed_runner_transpose(wp.float32, device).run()
|
|
110
266
|
|
|
111
267
|
|
|
268
|
+
@unittest.skipUnless(runtime.core.is_cutlass_enabled(), "Warp was not built with CUTLASS support")
|
|
112
269
|
def test_f64(test, device):
|
|
113
|
-
|
|
270
|
+
gemm_test_bed_runner(wp.float64, device).run()
|
|
271
|
+
gemm_test_bed_runner_transpose(wp.float64, device).run()
|
|
114
272
|
|
|
115
273
|
|
|
116
274
|
@wp.kernel
|
|
@@ -119,20 +277,22 @@ def matrix_sum_kernel(arr: wp.array2d(dtype=float), loss: wp.array(dtype=float))
|
|
|
119
277
|
wp.atomic_add(loss, 0, arr[i, j])
|
|
120
278
|
|
|
121
279
|
|
|
280
|
+
@unittest.skipUnless(runtime.core.is_cutlass_enabled(), "Warp was not built with CUTLASS support")
|
|
122
281
|
def test_tape(test, device):
|
|
282
|
+
rng = np.random.default_rng(42)
|
|
123
283
|
low = -4.5
|
|
124
284
|
high = 3.5
|
|
125
285
|
m = 64
|
|
126
286
|
n = 128
|
|
127
287
|
k = 256
|
|
128
288
|
A = wp.array2d(
|
|
129
|
-
np.ceil(
|
|
289
|
+
np.ceil(rng.uniform(low=low, high=high, size=(m, k))), dtype=float, device=device, requires_grad=True
|
|
130
290
|
)
|
|
131
291
|
B = wp.array2d(
|
|
132
|
-
np.ceil(
|
|
292
|
+
np.ceil(rng.uniform(low=low, high=high, size=(k, n))), dtype=float, device=device, requires_grad=True
|
|
133
293
|
)
|
|
134
294
|
C = wp.array2d(
|
|
135
|
-
np.ceil(
|
|
295
|
+
np.ceil(rng.uniform(low=low, high=high, size=(m, n))), dtype=float, device=device, requires_grad=True
|
|
136
296
|
)
|
|
137
297
|
D = wp.array2d(np.zeros((m, n)), dtype=float, device=device, requires_grad=True)
|
|
138
298
|
loss = wp.zeros(1, dtype=float, device=device, requires_grad=True)
|
|
@@ -145,6 +305,7 @@ def test_tape(test, device):
|
|
|
145
305
|
|
|
146
306
|
tape.backward(loss=loss)
|
|
147
307
|
A_grad = A.grad.numpy()
|
|
308
|
+
tape.reset()
|
|
148
309
|
|
|
149
310
|
# test adjoint
|
|
150
311
|
D.grad = wp.array2d(np.ones((m, n)), dtype=float, device=device)
|
|
@@ -156,17 +317,19 @@ def test_tape(test, device):
|
|
|
156
317
|
assert_array_equal(A.grad, wp.zeros_like(A))
|
|
157
318
|
|
|
158
319
|
|
|
320
|
+
@unittest.skipUnless(runtime.core.is_cutlass_enabled(), "Warp was not built with CUTLASS support")
|
|
159
321
|
def test_operator(test, device):
|
|
322
|
+
rng = np.random.default_rng(42)
|
|
160
323
|
low = -4.5
|
|
161
324
|
high = 3.5
|
|
162
325
|
m = 64
|
|
163
326
|
n = 128
|
|
164
327
|
k = 256
|
|
165
328
|
A = wp.array2d(
|
|
166
|
-
np.ceil(
|
|
329
|
+
np.ceil(rng.uniform(low=low, high=high, size=(m, k))), dtype=float, device=device, requires_grad=True
|
|
167
330
|
)
|
|
168
331
|
B = wp.array2d(
|
|
169
|
-
np.ceil(
|
|
332
|
+
np.ceil(rng.uniform(low=low, high=high, size=(k, n))), dtype=float, device=device, requires_grad=True
|
|
170
333
|
)
|
|
171
334
|
loss = wp.zeros(1, dtype=float, device=device, requires_grad=True)
|
|
172
335
|
|
|
@@ -180,7 +343,6 @@ def test_operator(test, device):
|
|
|
180
343
|
|
|
181
344
|
# test adjoint
|
|
182
345
|
D.grad = wp.array2d(np.ones((m, n)), dtype=float, device=device)
|
|
183
|
-
# deep copy, needed because transpose data is not contiguous
|
|
184
346
|
B_transpose = wp.array2d(B.transpose().numpy(), dtype=float, device=device)
|
|
185
347
|
|
|
186
348
|
adj_A = D.grad @ B_transpose
|
|
@@ -191,28 +353,102 @@ def test_operator(test, device):
|
|
|
191
353
|
assert_array_equal(A.grad, wp.zeros_like(A))
|
|
192
354
|
|
|
193
355
|
|
|
194
|
-
|
|
195
|
-
|
|
356
|
+
@unittest.skipUnless(runtime.core.is_cutlass_enabled(), "Warp was not built with CUTLASS support")
|
|
357
|
+
def test_large_batch_count(test, device):
|
|
358
|
+
rng = np.random.default_rng(42)
|
|
359
|
+
low = -4.5
|
|
360
|
+
high = 3.5
|
|
361
|
+
m = 2
|
|
362
|
+
n = 3
|
|
363
|
+
k = 4
|
|
364
|
+
batch_count = 65535 * 2 + int(65535 / 2)
|
|
365
|
+
A = wp.array3d(
|
|
366
|
+
np.ceil(rng.uniform(low=low, high=high, size=(batch_count, m, k))),
|
|
367
|
+
dtype=float,
|
|
368
|
+
device=device,
|
|
369
|
+
requires_grad=True,
|
|
370
|
+
)
|
|
371
|
+
B = wp.array3d(
|
|
372
|
+
np.ceil(rng.uniform(low=low, high=high, size=(batch_count, k, n))),
|
|
373
|
+
dtype=float,
|
|
374
|
+
device=device,
|
|
375
|
+
requires_grad=True,
|
|
376
|
+
)
|
|
377
|
+
C = wp.array3d(
|
|
378
|
+
np.ceil(rng.uniform(low=low, high=high, size=(batch_count, m, n))),
|
|
379
|
+
dtype=float,
|
|
380
|
+
device=device,
|
|
381
|
+
requires_grad=True,
|
|
382
|
+
)
|
|
383
|
+
D = wp.array3d(np.zeros((batch_count, m, n)), dtype=float, device=device, requires_grad=True)
|
|
384
|
+
ones = wp.zeros_like(D)
|
|
385
|
+
ones.fill_(1.0)
|
|
386
|
+
|
|
387
|
+
alpha = 1.0
|
|
388
|
+
beta = 1.0
|
|
196
389
|
|
|
197
|
-
|
|
198
|
-
|
|
390
|
+
tape = wp.Tape()
|
|
391
|
+
with tape:
|
|
392
|
+
wp.batched_matmul(A, B, C, D, alpha=alpha, beta=beta, allow_tf32x3_arith=False, device=device)
|
|
393
|
+
tape.backward(grads={D: ones})
|
|
199
394
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
395
|
+
D_np = alpha * np.matmul(A.numpy(), B.numpy()) + beta * C.numpy()
|
|
396
|
+
assert np.array_equal(D_np, D.numpy())
|
|
397
|
+
|
|
398
|
+
adj_A_np = alpha * np.matmul(ones.numpy(), B.numpy().transpose((0, 2, 1)))
|
|
399
|
+
adj_B_np = alpha * np.matmul(A.numpy().transpose((0, 2, 1)), ones.numpy())
|
|
400
|
+
adj_C_np = beta * ones.numpy()
|
|
401
|
+
|
|
402
|
+
assert np.array_equal(adj_A_np, A.grad.numpy())
|
|
403
|
+
assert np.array_equal(adj_B_np, B.grad.numpy())
|
|
404
|
+
assert np.array_equal(adj_C_np, C.grad.numpy())
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
@unittest.skipUnless(runtime.core.is_cutlass_enabled(), "Warp was not built with CUTLASS support")
|
|
408
|
+
def test_adjoint_accumulation(test, device):
|
|
409
|
+
a_np = np.ones(shape=(2, 3))
|
|
410
|
+
b_np = np.ones(shape=(3, 2))
|
|
411
|
+
c_np = np.zeros(shape=(2, 2))
|
|
412
|
+
d_np = np.zeros(shape=(2, 2))
|
|
413
|
+
|
|
414
|
+
a_wp = wp.from_numpy(a_np, dtype=float, requires_grad=True, device=device)
|
|
415
|
+
b_wp = wp.from_numpy(b_np, dtype=float, requires_grad=True, device=device)
|
|
416
|
+
c_wp = wp.from_numpy(c_np, dtype=float, requires_grad=True, device=device)
|
|
417
|
+
d1_wp = wp.from_numpy(d_np, dtype=float, requires_grad=True, device=device)
|
|
418
|
+
d2_wp = wp.from_numpy(d_np, dtype=float, requires_grad=True, device=device)
|
|
419
|
+
|
|
420
|
+
tape = wp.Tape()
|
|
421
|
+
|
|
422
|
+
with tape:
|
|
423
|
+
wp.matmul(a_wp, b_wp, c_wp, d1_wp, alpha=1.0, beta=1.0, device=device)
|
|
424
|
+
wp.matmul(a_wp, b_wp, d1_wp, d2_wp, alpha=1.0, beta=1.0, device=device)
|
|
425
|
+
|
|
426
|
+
d_grad = wp.zeros_like(d2_wp, device=device)
|
|
427
|
+
d_grad.fill_(1.0)
|
|
428
|
+
grads = {d2_wp: d_grad}
|
|
429
|
+
tape.backward(grads=grads)
|
|
430
|
+
|
|
431
|
+
assert np.array_equal(a_wp.grad.numpy(), 4.0 * np.ones(shape=(2, 3)))
|
|
432
|
+
assert np.array_equal(b_wp.grad.numpy(), 4.0 * np.ones(shape=(3, 2)))
|
|
433
|
+
assert np.array_equal(c_wp.grad.numpy(), np.ones(shape=(2, 2)))
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
devices = get_test_devices()
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
class TestMatmul(unittest.TestCase):
|
|
440
|
+
pass
|
|
203
441
|
|
|
204
|
-
if runtime.core.is_cutlass_enabled():
|
|
205
|
-
# add_function_test(TestMatmul, "test_f16", test_f16, devices=devices)
|
|
206
|
-
add_function_test(TestMatmul, "test_f32", test_f32, devices=devices)
|
|
207
|
-
add_function_test(TestMatmul, "test_f64", test_f64, devices=devices)
|
|
208
|
-
add_function_test(TestMatmul, "test_tape", test_tape, devices=devices)
|
|
209
|
-
add_function_test(TestMatmul, "test_operator", test_operator, devices=devices)
|
|
210
|
-
else:
|
|
211
|
-
print("Skipping matmul tests because CUTLASS is not supported in this build")
|
|
212
442
|
|
|
213
|
-
|
|
443
|
+
# add_function_test(TestMatmul, "test_f16", test_f16, devices=devices)
|
|
444
|
+
add_function_test(TestMatmul, "test_f32", test_f32, devices=devices)
|
|
445
|
+
add_function_test(TestMatmul, "test_f64", test_f64, devices=devices)
|
|
446
|
+
add_function_test(TestMatmul, "test_tape", test_tape, devices=devices)
|
|
447
|
+
add_function_test(TestMatmul, "test_operator", test_operator, devices=devices)
|
|
448
|
+
add_function_test(TestMatmul, "test_large_batch_count", test_large_batch_count, devices=devices)
|
|
449
|
+
add_function_test(TestMatmul, "test_adjoint_accumulation", test_adjoint_accumulation, devices=devices)
|
|
214
450
|
|
|
215
451
|
|
|
216
452
|
if __name__ == "__main__":
|
|
217
|
-
|
|
453
|
+
wp.build.clear_kernel_cache()
|
|
218
454
|
unittest.main(verbosity=2, failfast=False)
|