diffneusim 1.0.0__py3-none-any.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.
- diffneusim/__init__.py +1 -0
- diffneusim/_cache.py +42 -0
- diffneusim/_paths.py +5 -0
- diffneusim/bindings/rew14_ext.cu +115 -0
- diffneusim/bindings/soft14_capi.cpp +443 -0
- diffneusim/bindings/soft14_engine_ext.cu +596 -0
- diffneusim/bindings/soft_capi.cpp +782 -0
- diffneusim/bindings/soft_engine_ext.cu +495 -0
- diffneusim/core/cpu_engine/build.sh +40 -0
- diffneusim/core/cpu_engine/fiber/cuda_runtime.h +445 -0
- diffneusim/core/cpu_engine/x14_cpu.cpp +283 -0
- diffneusim/core/diff/dual.h +126 -0
- diffneusim/core/include/diffneusim/macros.h +35 -0
- diffneusim/core/kin/kinematic_tree.h +273 -0
- diffneusim/core/math/so3.h +182 -0
- diffneusim/core/soft/adj/out_adj.h +102 -0
- diffneusim/core/soft/adj/rnea_adj.h +425 -0
- diffneusim/core/soft/adj/rows_adj.h +439 -0
- diffneusim/core/soft/adj/rows_functor.h +89 -0
- diffneusim/core/soft/adj/rows_lanes.h +443 -0
- diffneusim/core/soft/adj/shell_adj.h +243 -0
- diffneusim/core/soft/adj/tree_adj.h +356 -0
- diffneusim/core/soft/collide.h +183 -0
- diffneusim/core/soft/gpu/adj14.cuh +233 -0
- diffneusim/core/soft/gpu/adj14_mus.cuh +98 -0
- diffneusim/core/soft/gpu/adj_shell.cuh +50 -0
- diffneusim/core/soft/gpu/adj_tab.cuh +49 -0
- diffneusim/core/soft/gpu/body14.cuh +47 -0
- diffneusim/core/soft/gpu/chol_rn.cuh +458 -0
- diffneusim/core/soft/gpu/chol_small.cuh +123 -0
- diffneusim/core/soft/gpu/chol_split.cuh +193 -0
- diffneusim/core/soft/gpu/engine_launch.cuh +263 -0
- diffneusim/core/soft/gpu/fk_rn.cuh +109 -0
- diffneusim/core/soft/gpu/generated/body_019e20820f86_mmfloor.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_62f77a4bb16b_mmfloor.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor.cuh +25 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +25 -0
- diffneusim/core/soft/gpu/generated/g1_soft_5db44fd45286.cuh +74 -0
- diffneusim/core/soft/gpu/generated/split_62f77a4bb16b_mmfloor.cuh +18 -0
- diffneusim/core/soft/gpu/generated/split_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +18 -0
- diffneusim/core/soft/gpu/generated/x14_soft_019e20820f86_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_62f77a4bb16b_mmfloor.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/k_mus.cuh +1038 -0
- diffneusim/core/soft/gpu/k_mus_host.cuh +377 -0
- diffneusim/core/soft/gpu/k_pre.cuh +52 -0
- diffneusim/core/soft/gpu/kernel_p.cuh +490 -0
- diffneusim/core/soft/gpu/kp14.cuh +465 -0
- diffneusim/core/soft/gpu/l2v2.cuh +367 -0
- diffneusim/core/soft/gpu/l2x14.cuh +319 -0
- diffneusim/core/soft/gpu/l3.cuh +1483 -0
- diffneusim/core/soft/gpu/model_view.cuh +48 -0
- diffneusim/core/soft/gpu/mus_case_fits.h +15 -0
- diffneusim/core/soft/gpu/mus_classes.h +182 -0
- diffneusim/core/soft/gpu/mus_row_cf.h +44 -0
- diffneusim/core/soft/gpu/rew14.cuh +177 -0
- diffneusim/core/soft/gpu/rows_ctab.cuh +44 -0
- diffneusim/core/soft/gpu/tree_m.cuh +247 -0
- diffneusim/core/soft/gpu/x14_engine_kernels.cuh +260 -0
- diffneusim/core/soft/gpu/x14_rowcf.h +14 -0
- diffneusim/core/soft/hand.h +124 -0
- diffneusim/core/soft/impedance.h +115 -0
- diffneusim/core/soft/jvp.h +202 -0
- diffneusim/core/soft/kin.h +250 -0
- diffneusim/core/soft/muscle.h +1208 -0
- diffneusim/core/soft/newton.h +371 -0
- diffneusim/core/soft/rows.h +176 -0
- diffneusim/core/soft/step.h +188 -0
- diffneusim/core/soft/tape.h +313 -0
- diffneusim/core/soft/x14/collide14.h +69 -0
- diffneusim/core/soft/x14/jvp14.h +182 -0
- diffneusim/core/soft/x14/law14.h +453 -0
- diffneusim/core/soft/x14adj/collide14_adj.h +134 -0
- diffneusim/core/soft/x14adj/passive14_adj.h +162 -0
- diffneusim/core/soft/x14adj/reward14.h +484 -0
- diffneusim/core/soft/x14adj/rows14_adj.h +400 -0
- diffneusim/core/soft/x14adj/scan14.h +349 -0
- diffneusim/core/soft/x14adj/shell14_adj.h +122 -0
- diffneusim/core/soft/x14adj/sweep14.h +255 -0
- diffneusim/core/soft/x14adj/tree14_adj.h +500 -0
- diffneusim/core/soft/x14adj/x14adj_common.h +96 -0
- diffneusim/data/mirror/H1622v2k_geyer_hfdeq.npz +0 -0
- diffneusim/data/mirror/H1622v2k_hfd.npz +0 -0
- diffneusim/data/mirror/H1622v2k_millard_hfdeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_calf2_pe.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01legs.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01lumbar.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_hinge.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_compound_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_luispe.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_trunk0701.npz +0 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01legs.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01lumbar.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1a.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n2.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_rom23.json +91 -0
- diffneusim/data/reference/musclemimic/myofullbody_mimic_sites.json +261 -0
- diffneusim/data/reference/pose3/pose3_scone.json +305 -0
- diffneusim/data/reference/pose3/pose3_scone.txt +3 -0
- diffneusim/data/reference/pose3/pose3_scone_gait.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_mirror.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_stand.npz +0 -0
- diffneusim/data/reference/x016run/MD5SUMS +241 -0
- diffneusim/data/reference/x016run/x016run_states.txt +240 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r3.npz +0 -0
- diffneusim/data/state_prior/lumbar_poly_fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/engine/__init__.py +0 -0
- diffneusim/engine/build_tag.py +52 -0
- diffneusim/engine/case_tables.py +46 -0
- diffneusim/engine/d16_body.py +80 -0
- diffneusim/engine/engine14.py +367 -0
- diffneusim/engine/gen_split.py +159 -0
- diffneusim/engine/hand_format.py +69 -0
- diffneusim/engine/live14.py +149 -0
- diffneusim/engine/phase_b_tree.py +137 -0
- diffneusim/engine/soft14.py +130 -0
- diffneusim/engine/soft_capi.py +373 -0
- diffneusim/engine/soft_engine.py +165 -0
- diffneusim/engine/step14.py +132 -0
- diffneusim/engine/tape_format.py +89 -0
- diffneusim/engine/x14cpu.py +163 -0
- diffneusim/env/__init__.py +0 -0
- diffneusim/env/absent.py +20 -0
- diffneusim/env/cpu14.py +105 -0
- diffneusim/env/e0loop14.py +224 -0
- diffneusim/env/env14.py +568 -0
- diffneusim/env/kin_contact14.py +193 -0
- diffneusim/env/mimic_sites_x14.json +366 -0
- diffneusim/env/old_count.py +78 -0
- diffneusim/env/rew14.py +114 -0
- diffneusim/env/rew14_hook.py +105 -0
- diffneusim/g1/__init__.py +1 -0
- diffneusim/g1/arm_a2.py +165 -0
- diffneusim/g1/arm_a3.py +576 -0
- diffneusim/g1/read_a3.py +79 -0
- diffneusim/g1/rg1_read.py +89 -0
- diffneusim/model/__init__.py +66 -0
- diffneusim/model/case.py +17 -0
- diffneusim/model/dnmodel.py +79 -0
- diffneusim/model/fuse_fixed.py +281 -0
- diffneusim/model/monitor.py +834 -0
- diffneusim/models/BODIES.toml +48 -0
- diffneusim/models/MANIFEST.toml +979 -0
- diffneusim/models/cases/G290/case.bin +0 -0
- diffneusim/models/cases/G290/case.json +1 -0
- diffneusim/models/cases/G356-SRC/case.bin +0 -0
- diffneusim/models/cases/G356-SRC/case.json +1 -0
- diffneusim/models/cases/G416/case.bin +0 -0
- diffneusim/models/cases/G416/case.json +1 -0
- diffneusim/models/cases/M290C-SRC/case.bin +0 -0
- diffneusim/models/cases/M290C-SRC/case.json +1 -0
- diffneusim/models/cases/M290R-SRC/case.bin +0 -0
- diffneusim/models/cases/M290R-SRC/case.json +1 -0
- diffneusim/models/cases/M356C-SRC/case.bin +0 -0
- diffneusim/models/cases/M356C-SRC/case.json +1 -0
- diffneusim/models/cases/M356R-SRC/case.bin +0 -0
- diffneusim/models/cases/M356R-SRC/case.json +1 -0
- diffneusim/models/cases/M416C-SRC/case.bin +0 -0
- diffneusim/models/cases/M416C-SRC/case.json +1 -0
- diffneusim/models/derived/d16_expanded_62f77a4bb16b1e67_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_expanded_a1e8b196b2cd7b3c_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_soft_law_019e20820f8633b9_mmfloor.json +7844 -0
- diffneusim/models/derived/d16_soft_law_62f77a4bb16b1e67_mmfloor.json +16855 -0
- diffneusim/models/derived/d16_soft_law_77dbb7213f26e821_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsd05_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsdef_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsmjd_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_a1e8b196b2cd7b3c_mmfloor_rampsb3l_n6t12.json +16894 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor.json +12655 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor_rampsb3l_n6t12.json +12700 -0
- diffneusim/models/derived/unitree_g1_soft_law.json +15580 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +28913 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +29202 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +46970 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +38570 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +38923 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_meshes/1mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2distph.stl +0 -0
- diffneusim/models/fullbody_meshes/2mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2midph.stl +0 -0
- diffneusim/models/fullbody_meshes/2proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/3distph.stl +0 -0
- diffneusim/models/fullbody_meshes/3mc.stl +0 -0
- diffneusim/models/fullbody_meshes/3midph.stl +0 -0
- diffneusim/models/fullbody_meshes/3proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/4distph.stl +0 -0
- diffneusim/models/fullbody_meshes/4mc.stl +0 -0
- diffneusim/models/fullbody_meshes/4midph.stl +0 -0
- diffneusim/models/fullbody_meshes/4proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/5distph.stl +0 -0
- diffneusim/models/fullbody_meshes/5mc.stl +0 -0
- diffneusim/models/fullbody_meshes/5midph.stl +0 -0
- diffneusim/models/fullbody_meshes/5proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/NOTICE +2 -0
- diffneusim/models/fullbody_meshes/capitate.stl +0 -0
- diffneusim/models/fullbody_meshes/clavicle.stl +0 -0
- diffneusim/models/fullbody_meshes/hamate.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_cervical.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_jaw.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_skull.stl +0 -0
- diffneusim/models/fullbody_meshes/humerus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/l_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/l_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/l_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/l_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar1.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar2.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar3.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar4.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar5.stl +0 -0
- diffneusim/models/fullbody_meshes/lunate.stl +0 -0
- diffneusim/models/fullbody_meshes/pisiform.stl +0 -0
- diffneusim/models/fullbody_meshes/r_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/r_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/r_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/r_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/r_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/r_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/radius.stl +0 -0
- diffneusim/models/fullbody_meshes/sacrum.stl +0 -0
- diffneusim/models/fullbody_meshes/scaphoid.stl +0 -0
- diffneusim/models/fullbody_meshes/scapula.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic10_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic11_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic12_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic1_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic2_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic3_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic4_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic5_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic6_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic7_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic8_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic9_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thorax.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbdist.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbprox.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezium.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezoid.stl +0 -0
- diffneusim/models/fullbody_meshes/triquetrum.stl +0 -0
- diffneusim/models/fullbody_meshes/ulna.stl +0 -0
- diffneusim/models/source/myo_fullbody/UPSTREAM.md +91 -0
- diffneusim/models/source/myoleg/UPSTREAM.md +52 -0
- diffneusim/models/source/unitree_g1/LICENSE.mjlab +202 -0
- diffneusim/models/source/unitree_g1/UPSTREAM.md +38 -0
- diffneusim/models/source/unitree_g1/assets/head_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/logo_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis_contour_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/torso_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_roll_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_yaw_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/dump_mjlab_reference.py +30 -0
- diffneusim/models/source/unitree_g1/g1.xml +308 -0
- diffneusim/models/source/unitree_g1/g1_constants.py +298 -0
- diffneusim/models/source/unitree_g1/mjlab_compiled_reference.json +857 -0
- diffneusim/models/unitree_g1.dnmodel +4393 -0
- diffneusim/models/unitree_g1_selfcol.dnmodel +20824 -0
- diffneusim/rl/__init__.py +2 -0
- diffneusim/rl/dynsyn_layer.py +146 -0
- diffneusim/rl/footstep_plan.py +337 -0
- diffneusim/rl/g1_bm_env.py +572 -0
- diffneusim/rl/g1_bm_eval.py +168 -0
- diffneusim/rl/g1_bm_fused.py +275 -0
- diffneusim/rl/g1_bm_ppo.py +622 -0
- diffneusim/rl/g1_bm_sapo.py +551 -0
- diffneusim/rl/g1_ppo.py +395 -0
- diffneusim/rl/g1_sapo_soft.py +240 -0
- diffneusim/rl/g1_soft_env.py +452 -0
- diffneusim/rl/g1_soft_grad.py +145 -0
- diffneusim/rl/geyer_curves_torch.py +108 -0
- diffneusim/rl/gpu_fullbody_vec_env.py +1241 -0
- diffneusim/rl/imitation.py +2027 -0
- diffneusim/rl/imitation_reward_v2.py +248 -0
- diffneusim/rl/imitation_reward_v3.py +349 -0
- diffneusim/rl/latent_task.py +175 -0
- diffneusim/rl/llc_reward.py +316 -0
- diffneusim/rl/millard_curves_torch.py +154 -0
- diffneusim/rl/mirror_symmetry.py +212 -0
- diffneusim/rl/model_path.py +35 -0
- diffneusim/rl/mvae_recon.py +123 -0
- diffneusim/rl/nets_shac.py +599 -0
- diffneusim/rl/reset_pool.py +154 -0
- diffneusim/rl/sapo_capture.py +873 -0
- diffneusim/rl/sapo_vec.py +1051 -0
- diffneusim/rl/shac_vec.py +346 -0
- diffneusim/rl/state_prior.py +151 -0
- diffneusim/rl/step_library.py +105 -0
- diffneusim/rl/task_walk_env.py +1793 -0
- diffneusim/rl/task_walk_reward.py +3300 -0
- diffneusim/run.py +23 -0
- diffneusim/run_env.py +46 -0
- diffneusim/tasks/__init__.py +147 -0
- diffneusim/tasks/legacy_names.py +63 -0
- diffneusim/tasks/paths.py +79 -0
- diffneusim/tasks/settings.py +202 -0
- diffneusim/third_party/instantmimic_947430ee/LICENSE +202 -0
- diffneusim/third_party/instantmimic_947430ee/NOTICE +19 -0
- diffneusim/third_party/instantmimic_947430ee/README.md +31 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/benchmark_protocol.py +106 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/metrics.py +214 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/reference.py +513 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/motion/quaternion.py +193 -0
- diffneusim/train/__init__.py +0 -0
- diffneusim/train/eval_ckpt.py +239 -0
- diffneusim/train/eval_mimic.py +133 -0
- diffneusim/train/gait_report.py +203 -0
- diffneusim/train/gcot_chain.py +51 -0
- diffneusim/train/levers.py +135 -0
- diffneusim/train/masked_reset.py +314 -0
- diffneusim/train/rl_algorithm_suite.py +917 -0
- diffneusim/train/train14.py +240 -0
- diffneusim/train/train_tw14.py +674 -0
- diffneusim/viz/__init__.py +5 -0
- diffneusim/viz/__main__.py +41 -0
- diffneusim/viz/camera.py +115 -0
- diffneusim/viz/dnrec.py +118 -0
- diffneusim/viz/dnrec_io.py +686 -0
- diffneusim/viz/hud.py +565 -0
- diffneusim/viz/meshes.py +458 -0
- diffneusim/viz/play.py +237 -0
- diffneusim/viz/record.py +74 -0
- diffneusim/viz/render.py +1402 -0
- diffneusim/viz/renderer.py +268 -0
- diffneusim/viz/rl_env_render.py +635 -0
- diffneusim/viz/snapshot.py +54 -0
- diffneusim/viz/strobe.py +124 -0
- diffneusim/viz/to_mp4.py +58 -0
- diffneusim/viz/ui.py +481 -0
- diffneusim/viz/viewer.py +2086 -0
- diffneusim-1.0.0.dist-info/METADATA +226 -0
- diffneusim-1.0.0.dist-info/RECORD +682 -0
- diffneusim-1.0.0.dist-info/WHEEL +5 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSE +201 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-ARMS-hand-wrist-4.3.txt +20 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-MoBL-ARMS.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/CC-BY-3.0-OpenSim-geometry.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Christophy2012-lumbarspine.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lai2017-model-high-flex.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lee2015-hand_muscle.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Rajagopal2016-full_body.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Uhlrich2022-fbmodpassivecal.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/NOTICE +274 -0
- diffneusim-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1483 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
// Portions of this file restate MuJoCo 3.16.0's primal Newton solve as core/soft/newton.h translates it
|
|
3
|
+
// (https://github.com/google-deepmind/mujoco), Copyright 2021 DeepMind Technologies Limited, and portions are derived from
|
|
4
|
+
// NablaEngine (https://github.com/OamIcs/NablaEngine at 70d0c8c, src/nablaengine/g1_engine/step.py: substep_post's exact line
|
|
5
|
+
// search, hessian()'s per-contact coefficients, rows_jtf's support-mask gather), Copyright 2026 The NablaEngine Authors; both
|
|
6
|
+
// licensed under the Apache License, Version 2.0. Changed by this project: rewritten as templated CUDA device code (float,
|
|
7
|
+
// double) on our hand and rows, with MuJoCo's warm start, island scale and stopping tests, refactor-and-reuse of H, register-
|
|
8
|
+
// resident contact metadata and staged J. See core/soft/NOTICE.md.
|
|
9
|
+
// D16 L3 (engine C, 2026-11-02): kernel N's work on the GPU (k_post: the solve, implicitfast, the position update), one world
|
|
10
|
+
// per 32-thread block. The soft law's Newton solve (tools/d16/L3_PREREG.md, path R), templated on the scalar T: float in
|
|
11
|
+
// production, double for the correctness gate (the same code, gated against core/soft/newton.h and step.h).
|
|
12
|
+
//
|
|
13
|
+
// Path R against newton.h (MuJoCo 3.16's mj_solPrimal, Newton):
|
|
14
|
+
// - the same: the warm-start rule (cost comparison, a tie keeps the warm start), the island scale 1 / trace M, the
|
|
15
|
+
// zero-iteration exits, H = M + J' D J on the QUADRATIC rows (MuJoCo's per-entry expression J[q, j] (J[q, i] D_q), rows in
|
|
16
|
+
// order, M added last), Cholesky with newton.h's mindiag rule (MuJoCo's threshold, but the column below a clamped pivot
|
|
17
|
+
// zeroed, which MuJoCo does not do: chol_rn.cuh's header), the Newton direction -H^-1 grad, the incremental qacc / Ma /
|
|
18
|
+
// Jaref updates, the stopping tests (improvement in (0, tol), gradient, decrement) and the loop order (step, constraint
|
|
19
|
+
// update, factor, gradient, solve, tests);
|
|
20
|
+
// - different: H is refactored from scratch whenever a row changed its zone and reused otherwise (no rank-1 updates);
|
|
21
|
+
// the line search is an exact 1-D Newton on the piecewise-quadratic cost with a bracket, exiting when a Newton step
|
|
22
|
+
// keeps every row on its piece (NablaEngine's), not PrimalSearch; one more stopping test, a step that changed no zone
|
|
23
|
+
// (on one piece the Newton step lands on the minimizer of a strictly convex cost: exact termination); chol(M) is formed
|
|
24
|
+
// only when the zero-iteration test needs M^-1 grad (MuJoCo's flg_gap matters only once flg_gradient holds) or when
|
|
25
|
+
// there are no rows (the tape's L_H).
|
|
26
|
+
// G1 (f64, v1): a* to 1.8e-13 against newton.h, niter equal to MuJoCo's on every corpus record.
|
|
27
|
+
// v2 (the falsifier's re-plan, ordered by v1's phase counters):
|
|
28
|
+
// - the Hessian is assembled straight into the factor's row registers: each active row of J is loaded once (coalesced,
|
|
29
|
+
// one row ahead), staged in shared memory for the broadcast, its all-zero 4-column groups skipped (uniform);
|
|
30
|
+
// - the factor and the triangular solves are chol_rn.cuh's (reciprocal pivots, solves blocked by 8 rows);
|
|
31
|
+
// - branches on warp-uniform values are voted (UNIFORM) so ptxas knows them uniform.
|
|
32
|
+
// Lanes: row-per-lane for M v, the assembly, the factor and the solves; lane-per-constraint-row for J v, the line search
|
|
33
|
+
// (each lane's rows in registers for all its steps) and the zones; lane-per-dof for J' f (rows in order).
|
|
34
|
+
// Deterministic: fixed lane ownership, xor-butterfly warp sums, no atomics. v2 still reads dense J rows from global memory
|
|
35
|
+
// (the tape corpus's and L2 v1's format); v3 reads the hand's contact-frame rows (con_J on the support dofs).
|
|
36
|
+
#include <cuda_runtime.h>
|
|
37
|
+
|
|
38
|
+
#include <cassert>
|
|
39
|
+
#include <type_traits>
|
|
40
|
+
|
|
41
|
+
#include "../collide.h" // V3, normalize3 (mju_normalize3)
|
|
42
|
+
#include "../impedance.h" // kMinVal (mjMINVAL)
|
|
43
|
+
#include "../kin.h" // quat_mul, quat_normalize
|
|
44
|
+
#include "../hand.h"
|
|
45
|
+
#include "chol_rn.cuh"
|
|
46
|
+
|
|
47
|
+
// The hand's layout at k_post's six sites (2026-11-08, B3c; tools/d16_bodies/PHASE_B.md items 1 and 6). A phase B body's hand holds
|
|
48
|
+
// M as kernel P's split storage of ::d16::split::WORDS words, the block L2 copies as it is (l2x14.cuh's HL); a layout without the
|
|
49
|
+
// split words is invalid (hand.h: ntri -1), so every reader names them. The bindings assert that this layout is L2's, field by field
|
|
50
|
+
// (hand_layout_same). Without D16_NV_GT64 the expansion is the call as it was, token for token (tools/d16_bodies/token_check.py).
|
|
51
|
+
#if defined(D16_NV_GT64)
|
|
52
|
+
#if !defined(D16_SPLIT_DEVICE)
|
|
53
|
+
#error "D16_NV_GT64: the body's generated split header (core/soft/gpu/generated/split_<tag>.cuh) comes before l3.cuh"
|
|
54
|
+
#endif
|
|
55
|
+
#define D16_L3_HAND_LAYOUT(NV, NC, NRH, KD) ::js::soft::hand_layout(NV, NC, NRH, KD, ::d16::split::WORDS)
|
|
56
|
+
#else
|
|
57
|
+
#define D16_L3_HAND_LAYOUT(NV, NC, NRH, KD) hand_layout(NV, NC, NRH, KD)
|
|
58
|
+
#endif
|
|
59
|
+
|
|
60
|
+
namespace js::soft::gpu::l3 {
|
|
61
|
+
|
|
62
|
+
constexpr unsigned kFull = 0xffffffffu;
|
|
63
|
+
using chol::tri;
|
|
64
|
+
|
|
65
|
+
// flags per world
|
|
66
|
+
constexpr int kFlagOverflow = 1; // nefc > NR: not solved (the gate fails on any)
|
|
67
|
+
constexpr int kFlagWarm = 2; // the warm start was kept
|
|
68
|
+
constexpr int kFlagCap = 4; // the Newton loop ended at its iteration cap without a stopping test
|
|
69
|
+
constexpr int kFlagLsCap = 8; // some line search ended at its step cap
|
|
70
|
+
constexpr int kFlagLanded = 16; // the loop ended on the zone-stable test (no other test fired)
|
|
71
|
+
constexpr int kFlagRankLoss = 32; // a factorization clamped a pivot to mindiag
|
|
72
|
+
constexpr int kFlagHandOrder = 64; // a hand contact's support slots are not strictly ascending dofs (the gate fails)
|
|
73
|
+
constexpr int kFlagStalled = 128; // the Newton loop ended on a zero step (MuJoCo: alpha 0), the tape's kTapeStalled
|
|
74
|
+
constexpr int kZoneWords = 6; // zone words in shared memory, at least (Shared::kZW: NR / 32 above it; the 14x's big path
|
|
75
|
+
// at NR 256 has 8, every G1 and fast-path solve keeps 6, so their layouts are unchanged)
|
|
76
|
+
constexpr int kTapeNpose = 32; // the tape's POSE block (k_pre writes it): the G1's 32 bodies
|
|
77
|
+
|
|
78
|
+
// the launcher's check of a tape's stride (host side: no device assert in the kernel)
|
|
79
|
+
#if defined(D16_NV_GT64) // B3c: a phase B record's layout needs the limit count and the split words (tape.h)
|
|
80
|
+
inline bool kpost_tape_ok(const void* tape, long long stride, int nv, int nc, int nrh, int nq, int npose, int nmus, bool lq, int nlim,
|
|
81
|
+
int mwords) {
|
|
82
|
+
return tape == nullptr || stride >= tape_layout(nq ? nq : nv + 1, nv, nc, nrh, npose ? npose : kTapeNpose, nmus, lq, nlim, mwords).words;
|
|
83
|
+
}
|
|
84
|
+
#else
|
|
85
|
+
inline bool kpost_tape_ok(const void* tape, long long stride, int nv, int nc, int nrh, int nq = 0, int npose = 0, int nmus = 0,
|
|
86
|
+
bool lq = true) {
|
|
87
|
+
return tape == nullptr || stride >= tape_layout(nq ? nq : nv + 1, nv, nc, nrh, npose ? npose : kTapeNpose, nmus, lq).words;
|
|
88
|
+
}
|
|
89
|
+
#endif
|
|
90
|
+
constexpr int kLsMax = 40; // line-search steps per search (NablaEngine's cap)
|
|
91
|
+
|
|
92
|
+
// L3_PROFILE (default off, a separately named build): per-world clock64 cycles by phase, lane 0, a __syncwarp() at every
|
|
93
|
+
// mark. Phases: 0 load, 1 warm start, 2 initial gradient, 3 zero-iteration test on M, 4 Hessian assembly + factor (v2 fuses
|
|
94
|
+
// them), 5 (unused in v2), 6 solve with H, 7 line search, 8 step update / forces / J'f / tests, 9 implicitfast, 10 outputs
|
|
95
|
+
constexpr int kNprof = 11;
|
|
96
|
+
#ifdef L3_PROFILE
|
|
97
|
+
#define L3_MARK(k) do { __syncwarp(); if (lane == 0) { const long long t_ = clock64(); prof_[k] += t_ - tprev_; tprev_ = t_; } } while (0)
|
|
98
|
+
#else
|
|
99
|
+
#define L3_MARK(k) do { } while (0)
|
|
100
|
+
#endif
|
|
101
|
+
|
|
102
|
+
// L3_PROFILE's sub-phases inside the hand assembly (cycles summed per block, lane 0, a __syncwarp() at every mark) and its
|
|
103
|
+
// counters; the binding points g_l3_sub at a zeroed [grid][kNsub] buffer. 0 zero L, 1 limits (lane 0, one global rowmeta load
|
|
104
|
+
// each, dependent), 2 C coefficients + ballots, 3 the pair table, 4 the first contact's staging (one global load, then shared),
|
|
105
|
+
// 5 the per-contact loop (shuffles, pairs, the next contact's staging), 6 L += M, 7 the factor; counters: 8 calls, 9 active
|
|
106
|
+
// contacts, 10 limit rows
|
|
107
|
+
constexpr int kNsub = 11;
|
|
108
|
+
#ifdef L3_PROFILE
|
|
109
|
+
__device__ long long* g_l3_sub;
|
|
110
|
+
#define L3_SUB_START long long tsub_ = clock64()
|
|
111
|
+
#define L3_SUB(k) do { __syncwarp(); if (lane == 0) { const long long t_ = clock64(); g_l3_sub[blockIdx.x * kNsub + (k)] += t_ - tsub_; tsub_ = t_; } } while (0)
|
|
112
|
+
#define L3_SUB_COUNT(k, v) do { if (lane == 0) g_l3_sub[blockIdx.x * kNsub + (k)] += (v); } while (0)
|
|
113
|
+
#else
|
|
114
|
+
#define L3_SUB_START do { } while (0)
|
|
115
|
+
#define L3_SUB(k) do { } while (0)
|
|
116
|
+
#define L3_SUB_COUNT(k, v) do { } while (0)
|
|
117
|
+
#endif
|
|
118
|
+
|
|
119
|
+
// The model's compile-time options (engine C, the 14x, 2026-11-02). The defaults are the G1's, so its instantiations do not
|
|
120
|
+
// change. kEuler: MuJoCo's Euler with explicit damping (EULERDAMP off, MuscleMimic's training setup; the damping is in
|
|
121
|
+
// qfrc_smooth): qvel' = qvel + h a*, no implicitfast factor, and no L_Q in the tape. kNball: ball joints integrated after
|
|
122
|
+
// the free root (mju_quatIntegrate: wxyz qpos, angular velocity in the child's frame, the root rotation's step), one lane
|
|
123
|
+
// each; an options type with kNball > 0 also gives __host__ __device__ static constexpr ball_q(b) / ball_d(b) (qpos and dof
|
|
124
|
+
// addresses; the model's generated values, the interface note). Their dofs carry hinge_qadr -1
|
|
125
|
+
// kLimGuard: a hand with more than 64 limit rows (two per lane) is flagged overflow; the G1's never has (<= 29 active).
|
|
126
|
+
// kNq / kNpose: the tape's nq and POSE count (0: the G1's nv + 1 and kTapeNpose)
|
|
127
|
+
struct ImplicitFastOpts {
|
|
128
|
+
static constexpr bool kEuler = false, kLimGuard = false;
|
|
129
|
+
static constexpr int kNball = 0, kNq = 0, kNpose = 0;
|
|
130
|
+
};
|
|
131
|
+
struct EulerOpts {
|
|
132
|
+
static constexpr bool kEuler = true, kLimGuard = false;
|
|
133
|
+
static constexpr int kNball = 0, kNq = 0, kNpose = 0;
|
|
134
|
+
};
|
|
135
|
+
// the tape's MUS count (an options type may omit kNmus: 0, no MUS block). The record has no L_Q block in the Euler form
|
|
136
|
+
// (tape_layout's lq = !kEuler: the afde993c, the 14x record of 1,792 words)
|
|
137
|
+
#if defined(D16_NV_GT64) // B3c: the body's limit count (the record's clamp words hold its active-limit mask): required for a phase B body
|
|
138
|
+
template <class O, class = void> struct OptNlim { static constexpr int value = -1; };
|
|
139
|
+
template <class O> struct OptNlim<O, std::void_t<decltype(O::kNlim)>> { static constexpr int value = O::kNlim; };
|
|
140
|
+
#define D16_L3_TAPE_LAYOUT(nq, nv, nc, nrh, np, nm, lq) tape_layout(nq, nv, nc, nrh, np, nm, lq, kTapeNlim, ::d16::split::WORDS)
|
|
141
|
+
#else
|
|
142
|
+
#define D16_L3_TAPE_LAYOUT(nq, nv, nc, nrh, np, nm, lq) tape_layout(nq, nv, nc, nrh, np, nm, lq)
|
|
143
|
+
#endif
|
|
144
|
+
template <class O, class = void> struct OptNmus { static constexpr int value = 0; };
|
|
145
|
+
template <class O> struct OptNmus<O, std::void_t<decltype(O::kNmus)>> { static constexpr int value = O::kNmus; };
|
|
146
|
+
// kLimitMask (the 14x): k_pre14 writes the active-limit mask into the record's clamp words, so k_post leaves them alone
|
|
147
|
+
// (an options type may omit it: false, k_post writes the clamp words as before)
|
|
148
|
+
template <class O, class = void> struct OptLimitMask { static constexpr bool value = false; };
|
|
149
|
+
template <class O> struct OptLimitMask<O, std::void_t<decltype(O::kLimitMask)>> { static constexpr bool value = O::kLimitMask; };
|
|
150
|
+
|
|
151
|
+
// a warp-uniform condition, voted so that ptxas knows the branch is uniform (NablaEngine's DK_UNIFORM)
|
|
152
|
+
__device__ __forceinline__ bool UNIFORM(bool c) { return __all_sync(kFull, c); }
|
|
153
|
+
|
|
154
|
+
#if defined(D16_B416_KPOST9) && !defined(D16_NV_GT64)
|
|
155
|
+
#error "D16_B416_KPOST9 is the 416's kpost14 layout lever (a phase B body, D16_NV_GT64); the 14x and G1 keep their layout"
|
|
156
|
+
#endif
|
|
157
|
+
template <class T, int NV, int NR> struct Shared {
|
|
158
|
+
#if defined(D16_NV_GT64) // B3c: M, H and their factor in the body's split storage (chol_split.cuh); xs: a vector in split order
|
|
159
|
+
static constexpr int kTri = ::d16::split::WORDS;
|
|
160
|
+
#else
|
|
161
|
+
static constexpr int kTri = NV * (NV + 1) / 2;
|
|
162
|
+
#endif
|
|
163
|
+
T L[kTri]; // (v3e: M, qfrc_smooth and qacc_smooth are read from the world's input in global memory through __ldg)
|
|
164
|
+
#if defined(D16_NV_GT64) // (after L, which must stay the struct's first member: tape_copy_factor moves it four words at a time, 16-byte aligned. B3d, 11-08:
|
|
165
|
+
T xs[NV]; // placed before L, it put L at word 77 and the taped forward faulted with a misaligned address on the device)
|
|
166
|
+
#endif
|
|
167
|
+
#if defined(D16_B416_KPOST9) // (11-09; tools/d16_bodies/kpost9/PREREG_KPOST9.md, deck-only) Mv right after xs, where it is 16-byte aligned: the struct's two
|
|
168
|
+
alignas(16) T Mv[NV]; // alignment paddings (4 B before Mv, 12 B before col) go, so <float, 77, 128> is 10,240 B and kpost14 runs 9 worlds per SM, not 8
|
|
169
|
+
#endif
|
|
170
|
+
T qacc[NV], Ma[NV], grad[NV], Mgrad[NV], search[NV], qfrc_c[NV], rinv[NV];
|
|
171
|
+
#if !defined(D16_B416_KPOST9)
|
|
172
|
+
alignas(16) T Mv[NV]; // M search; dead during the assembly, which stages rows in it (the second buffer)
|
|
173
|
+
#endif
|
|
174
|
+
T D[NR], Jaref[NR], Jv[NR]; // Jv: J search inside the line search, the rows' forces outside it
|
|
175
|
+
static constexpr int kZW = NR / 32 > kZoneWords ? NR / 32 : kZoneWords;
|
|
176
|
+
unsigned zw[kZW]; // the rows' zones (bit r: QUADRATIC), the same as every lane's registers; past NR / 32: 0
|
|
177
|
+
unsigned clw[2]; // the clamp mask's words (the tape's clamp source)
|
|
178
|
+
static_assert(NR % 32 == 0 && NR / 32 <= kZW, "the solve works in 32-row words");
|
|
179
|
+
alignas(16) T col[32]; // the factor's column broadcast; the assembly's first row buffer
|
|
180
|
+
// 16 blocks per SM on sm_89 need <= 5,376 B per block (100 KB per SM, 1 KB reserved per block, 128-byte granularity):
|
|
181
|
+
// <float, 35, 128> is 5,344 B
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
template <class T> struct Args {
|
|
185
|
+
int nw, nq;
|
|
186
|
+
// inputs, per world: M packed TRI; qfrc_smooth, qacc_smooth, warm start, qvel [NV]; qpos [nq]; nefc; J [NR][NV] row-major;
|
|
187
|
+
// aref, D [NR]; clamp: 2 u32 words (bit d: dof d's actuator at its forcerange)
|
|
188
|
+
const T *M, *qsm, *qa0, *warm, *J, *aref, *D, *qpos, *qvel;
|
|
189
|
+
const int* nefc;
|
|
190
|
+
const unsigned* clamp;
|
|
191
|
+
// model: kd per dof (0: no actuator), hinge_qadr per dof (-1: a free-root dof), the free root at dofs 0..5 / qpos 0..6
|
|
192
|
+
const T* kd;
|
|
193
|
+
const int* hinge_qadr;
|
|
194
|
+
T h, tol;
|
|
195
|
+
int iterations;
|
|
196
|
+
const int* order; // dispatch: block b solves world order[b] (k_post's row-count sort); null: block b solves world b
|
|
197
|
+
const T* hand; // k_post: the hand records [nw][hand words] (the dense inputs above are then unused)
|
|
198
|
+
// outputs, per world
|
|
199
|
+
T *a_star, *a_adv, *qvel1, *qpos1, *qfrc_c, *LH, *LQ;
|
|
200
|
+
unsigned* zone; // [zone_words] per world, bit r: row r QUADRATIC at a* (words past the solve's NR / 32 written 0)
|
|
201
|
+
int zone_words; // the zone output's stride: >= NR / 32 of every instantiation that writes it
|
|
202
|
+
int *niter, *flags, *nls, *nfact;
|
|
203
|
+
long long* cycles;
|
|
204
|
+
long long* prof; // [kNprof] per world, written only by an L3_PROFILE build
|
|
205
|
+
T* tape; // k_post: this substep's tape records (null: none); every word but POSE is written here
|
|
206
|
+
long long tape_stride; // words between consecutive worlds' records: REQUIRED with a tape (contiguous callers pass the
|
|
207
|
+
// record's words, the world-major [nw][nsub][words] tape passes nsub x words with tape = base +
|
|
208
|
+
// substep x words). The LAUNCHER asserts tape_stride >= the record's words (kpost_tape_ok):
|
|
209
|
+
// a device assert in this kernel cost ~1.8k SASS instructions and ~9% (A/B, 11-02)
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
template <class T> __device__ __forceinline__ T warp_sum(T v) {
|
|
213
|
+
#pragma unroll
|
|
214
|
+
for (int o = 16; o > 0; o >>= 1) v += __shfl_xor_sync(kFull, v, o);
|
|
215
|
+
return v;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// two warp sums in 6 shuffles instead of 10 (v3n): the high half sends its a and the low half its b across, each half then
|
|
219
|
+
// reduces one value (4 butterfly steps), and one exchange gives every lane both. Every lane ends bitwise equal (each step
|
|
220
|
+
// adds the same two operands on both partners), as in warp_sum.
|
|
221
|
+
template <class T> __device__ __forceinline__ void warp_sum2(T& a, T& b, int lane) {
|
|
222
|
+
const bool hi = (lane & 16) != 0;
|
|
223
|
+
const T recv = __shfl_xor_sync(kFull, hi ? a : b, 16);
|
|
224
|
+
T v = hi ? b + recv : a + recv;
|
|
225
|
+
#pragma unroll
|
|
226
|
+
for (int o = 8; o > 0; o >>= 1) v += __shfl_xor_sync(kFull, v, o);
|
|
227
|
+
const T other = __shfl_xor_sync(kFull, v, 16);
|
|
228
|
+
a = hi ? other : v;
|
|
229
|
+
b = hi ? v : other;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// dot of two shared NV vectors
|
|
233
|
+
template <class T, int NV> __device__ __forceinline__ T vdot(const T* a, const T* b, int lane) {
|
|
234
|
+
T s = T(0);
|
|
235
|
+
for (int i = lane; i < NV; i += 32) s += a[i] * b[i];
|
|
236
|
+
return warp_sum(s);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// vdot with a in global memory (read-only), the same order
|
|
240
|
+
template <class T, int NV> __device__ __forceinline__ T vdot_g(const T* a, const T* b, int lane) {
|
|
241
|
+
T s = T(0);
|
|
242
|
+
for (int i = lane; i < NV; i += 32) s += __ldg(a + i) * b[i];
|
|
243
|
+
return warp_sum(s);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// out = A v, A symmetric as its packed lower triangle (global, read-only: the world's M), row per lane
|
|
247
|
+
template <class T, int NV> __device__ void matvec(const T* A, const T* v, T* out, int lane) {
|
|
248
|
+
for (int i = lane; i < NV; i += 32) {
|
|
249
|
+
T acc = T(0);
|
|
250
|
+
#pragma unroll
|
|
251
|
+
for (int j = 0; j < NV; ++j) acc += __ldg(A + (j <= i ? tri(i, j) : tri(j, i))) * v[j];
|
|
252
|
+
out[i] = acc;
|
|
253
|
+
}
|
|
254
|
+
__syncwarp();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// B3c: k_post's M and H operations on a phase B body's split storage (PHASE_B.md items 1 and 6). The solve's call sites name them
|
|
258
|
+
// through the L3_* macros below; without D16_NV_GT64 each macro expands to the dense call as it was, token for token.
|
|
259
|
+
#if defined(D16_NV_GT64)
|
|
260
|
+
// the split word of the dense entry (i, j), either order; -1 where the split holds a structural zero (gen_split.py's gSplitWord)
|
|
261
|
+
__device__ __forceinline__ int split_word(int i, int j) { return chol::split_ld(&::d16::split::gSplitWord[i >= j ? tri(i, j) : tri(j, i)]); }
|
|
262
|
+
// out = M v, M in split storage in global memory: a row per lane, the structural zeros skipped
|
|
263
|
+
template <class T, int NV> __device__ void matvec_split(const T* A, const T* v, T* out, int lane) {
|
|
264
|
+
for (int i = lane; i < NV; i += 32) {
|
|
265
|
+
T acc = T(0);
|
|
266
|
+
for (int j = 0; j < NV; ++j) {
|
|
267
|
+
const int w = split_word(i, j);
|
|
268
|
+
if (w >= 0) acc += __ldg(A + w) * v[j];
|
|
269
|
+
}
|
|
270
|
+
out[i] = acc;
|
|
271
|
+
}
|
|
272
|
+
__syncwarp();
|
|
273
|
+
}
|
|
274
|
+
// the factor of s.L in place with the forward solve fused on s.Mgrad: s.xs = L^-1 Mgrad (split order); returns the clamped pivots
|
|
275
|
+
template <class T, int NV, int NR> __device__ __forceinline__ int split_factor_mgrad(Shared<T, NV, NR>& s, int lane) {
|
|
276
|
+
chol::split_gather<T>(s.Mgrad, s.xs, lane);
|
|
277
|
+
return chol::split_factor_fwd<T>(s.L, s.rinv, s.col, s.Mv, T(kMinVal), lane, s.xs);
|
|
278
|
+
}
|
|
279
|
+
// after split_factor_mgrad or split_solve_fwd_mgrad: Mgrad = L^-T xs (the global dof order)
|
|
280
|
+
template <class T, int NV, int NR> __device__ __forceinline__ void split_solve_bwd_mgrad(Shared<T, NV, NR>& s, int lane) {
|
|
281
|
+
chol::split_solve_bwd<T>(s.L, s.rinv, s.xs, lane);
|
|
282
|
+
chol::split_scatter<T>(s.xs, s.Mgrad, lane);
|
|
283
|
+
}
|
|
284
|
+
// on a stored factor: xs = L^-1 Mgrad (split order); split_solve_bwd_mgrad finishes
|
|
285
|
+
template <class T, int NV, int NR> __device__ __forceinline__ void split_solve_fwd_mgrad(Shared<T, NV, NR>& s, int lane) {
|
|
286
|
+
chol::split_gather<T>(s.Mgrad, s.xs, lane);
|
|
287
|
+
chol::split_solve_fwd<T>(s.L, s.rinv, s.xs, lane);
|
|
288
|
+
}
|
|
289
|
+
#define L3_FACTOR_M(s, lane) split_factor_mgrad<T, NV, NR>(s, lane)
|
|
290
|
+
#define L3_SOLVE_BWD(s, lane) split_solve_bwd_mgrad<T, NV, NR>(s, lane)
|
|
291
|
+
#define L3_SOLVE_FWD(s, lane) split_solve_fwd_mgrad<T, NV, NR>(s, lane)
|
|
292
|
+
#define L3_MATVEC(M, v, out, lane) matvec_split<T, NV>(M, v, out, lane)
|
|
293
|
+
#define L3_M_DIAG(M, i) __ldg(M + split_word(i, i))
|
|
294
|
+
#define L3_TRI(i, j) split_word(i, j)
|
|
295
|
+
#else
|
|
296
|
+
#define L3_FACTOR_M(s, lane) chol::factor_fwd<T, NV>(s.L, s.rinv, s.col, s.Mv, T(kMinVal), lane, s.Mgrad)
|
|
297
|
+
#define L3_SOLVE_BWD(s, lane) chol::solve_bwd<T, NV>(s.L, s.rinv, s.Mgrad, lane)
|
|
298
|
+
#define L3_SOLVE_FWD(s, lane) chol::solve_fwd<T, NV>(s.L, s.rinv, s.Mgrad, lane)
|
|
299
|
+
#define L3_MATVEC(M, v, out, lane) matvec<T, NV>(M, v, out, lane)
|
|
300
|
+
#define L3_M_DIAG(M, i) __ldg(M + tri(i, i))
|
|
301
|
+
#define L3_TRI(i, j) tri(i, j)
|
|
302
|
+
#endif
|
|
303
|
+
|
|
304
|
+
// out[r] = J[r] . v (- sub[r]) for the nefc rows, a row per lane (J in global memory, L1-cached)
|
|
305
|
+
template <class T, int NV> __device__ void rows_dot(const T* J, const T* v, const T* sub, T* out, int nefc, int lane) {
|
|
306
|
+
for (int r = lane; r < nefc; r += 32) {
|
|
307
|
+
const T* Jr = J + r * NV;
|
|
308
|
+
T acc = T(0);
|
|
309
|
+
#pragma unroll 7
|
|
310
|
+
for (int j = 0; j < NV; ++j) acc += __ldg(Jr + j) * v[j];
|
|
311
|
+
out[r] = sub ? acc - __ldg(sub + r) : acc;
|
|
312
|
+
}
|
|
313
|
+
__syncwarp();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// out = J' f over the rows with f != 0 in row order (mju_mulMatTVec), a dof per lane
|
|
317
|
+
template <class T, int NV> __device__ void mul_JT(const T* J, const T* f, T* out, int nefc, int lane) {
|
|
318
|
+
for (int i = lane; i < NV; i += 32) {
|
|
319
|
+
T acc = T(0);
|
|
320
|
+
for (int r = 0; r < nefc; ++r) {
|
|
321
|
+
const T fr = f[r];
|
|
322
|
+
if (fr != T(0)) acc += __ldg(J + r * NV + i) * fr;
|
|
323
|
+
}
|
|
324
|
+
out[i] = acc;
|
|
325
|
+
}
|
|
326
|
+
__syncwarp();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// the first QUADRATIC row after q (uniform; -1: none)
|
|
330
|
+
template <class T, int NV, int NR> __device__ __forceinline__ int next_row(const Shared<T, NV, NR>& s, int q) {
|
|
331
|
+
const int q1 = q + 1;
|
|
332
|
+
for (int t = q1 >> 5; t < NR / 32; ++t) {
|
|
333
|
+
unsigned m = s.zw[t];
|
|
334
|
+
const int b = q1 - 32 * t;
|
|
335
|
+
if (b > 0) m &= ~0u << b;
|
|
336
|
+
if (m) return 32 * t + __ffs(m) - 1;
|
|
337
|
+
}
|
|
338
|
+
return -1;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// H = M + J' D J over the QUADRATIC rows (s.zw), assembled into the factor's row registers, then factored into s.L / s.rinv.
|
|
342
|
+
// MuJoCo's order (mju_sqrMatTD_impl, then mju_addToSymSparse): per row in row order, entry (i, j) += J[q, j] (J[q, i] D_q)
|
|
343
|
+
// where J[q, i] != 0, then M. Lane r holds row r < 32; the tail rows' entries (32 + t, r) on lane r and their block on every
|
|
344
|
+
// lane, the factor's layout. Returns the number of clamped pivots.
|
|
345
|
+
template <class T, int NV, int NR>
|
|
346
|
+
__device__ __noinline__ int assemble_factor(Shared<T, NV, NR>& s, const T* J, const T* M, int lane) {
|
|
347
|
+
constexpr int NT = chol::Dims<NV>::NT, NTB = chol::Dims<NV>::NTB;
|
|
348
|
+
const int r = lane;
|
|
349
|
+
T a[32], tt[NT], tb[NTB];
|
|
350
|
+
#pragma unroll
|
|
351
|
+
for (int j = 0; j < 32; ++j) a[j] = T(0);
|
|
352
|
+
#pragma unroll
|
|
353
|
+
for (int t = 0; t < NT; ++t) tt[t] = T(0);
|
|
354
|
+
#pragma unroll
|
|
355
|
+
for (int u = 0; u < NTB; ++u) tb[u] = T(0);
|
|
356
|
+
int q = next_row(s, -1);
|
|
357
|
+
T jl = T(0), jt[NT], dq = T(0);
|
|
358
|
+
#pragma unroll
|
|
359
|
+
for (int t = 0; t < NT; ++t) jt[t] = T(0);
|
|
360
|
+
if (q >= 0) {
|
|
361
|
+
const T* Jq = J + q * NV;
|
|
362
|
+
jl = __ldg(Jq + r); dq = s.D[q];
|
|
363
|
+
#pragma unroll
|
|
364
|
+
for (int t = 0; t < NT; ++t) jt[t] = __ldg(Jq + 32 + t);
|
|
365
|
+
}
|
|
366
|
+
int buf = 0;
|
|
367
|
+
while (q >= 0) {
|
|
368
|
+
const int qn = next_row(s, q); // the next row's loads issued before this row's arithmetic
|
|
369
|
+
T jln = T(0), jtn[NT], dqn = T(0);
|
|
370
|
+
#pragma unroll
|
|
371
|
+
for (int t = 0; t < NT; ++t) jtn[t] = T(0);
|
|
372
|
+
if (qn >= 0) {
|
|
373
|
+
const T* Jq = J + qn * NV;
|
|
374
|
+
jln = __ldg(Jq + r); dqn = s.D[qn];
|
|
375
|
+
#pragma unroll
|
|
376
|
+
for (int t = 0; t < NT; ++t) jtn[t] = __ldg(Jq + 32 + t);
|
|
377
|
+
}
|
|
378
|
+
T* rb = buf ? s.Mv : s.col; // double buffer: one __syncwarp() per row
|
|
379
|
+
rb[r] = jl;
|
|
380
|
+
const unsigned nz = __ballot_sync(kFull, jl != T(0)); // the row's nonzero columns 0..31
|
|
381
|
+
__syncwarp();
|
|
382
|
+
if (jl != T(0)) {
|
|
383
|
+
const T sc = jl * dq; // J[q, i] D_q of row i = r
|
|
384
|
+
#pragma unroll
|
|
385
|
+
for (int g = 0; g < 32; g += 4) {
|
|
386
|
+
if (!((nz >> g) & 0xfu)) continue; // uniform: four zero columns add nothing
|
|
387
|
+
if (g > r) continue;
|
|
388
|
+
T c[4];
|
|
389
|
+
chol::load4(rb + g, c);
|
|
390
|
+
#pragma unroll
|
|
391
|
+
for (int m = 0; m < 4; ++m)
|
|
392
|
+
if (g + m <= r) a[g + m] += c[m] * sc;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
#pragma unroll
|
|
396
|
+
for (int t = 0; t < NT; ++t) {
|
|
397
|
+
if (jt[t] == T(0)) continue; // uniform
|
|
398
|
+
const T sct = jt[t] * dq; // J[q, 32 + t] D_q of row 32 + t
|
|
399
|
+
tt[t] += jl * sct;
|
|
400
|
+
#pragma unroll
|
|
401
|
+
for (int u = 0; u <= t; ++u) tb[t * (t + 1) / 2 + u] += jt[u] * sct;
|
|
402
|
+
}
|
|
403
|
+
jl = jln; dq = dqn;
|
|
404
|
+
#pragma unroll
|
|
405
|
+
for (int t = 0; t < NT; ++t) jt[t] = jtn[t];
|
|
406
|
+
q = qn;
|
|
407
|
+
buf ^= 1;
|
|
408
|
+
}
|
|
409
|
+
#pragma unroll
|
|
410
|
+
for (int j = 0; j < 32; ++j)
|
|
411
|
+
if (j <= r) a[j] += __ldg(M + tri(r, j));
|
|
412
|
+
#pragma unroll
|
|
413
|
+
for (int t = 0; t < NT; ++t) {
|
|
414
|
+
tt[t] += __ldg(M + tri(32 + t, r));
|
|
415
|
+
#pragma unroll
|
|
416
|
+
for (int u = 0; u <= t; ++u) tb[t * (t + 1) / 2 + u] += __ldg(M + tri(32 + t, 32 + u));
|
|
417
|
+
}
|
|
418
|
+
__syncwarp(); // the last staged row is read before the factor reuses col
|
|
419
|
+
return chol::factor_regs<T, NV, true>(a, tt, tb, s.L, s.rinv, s.col, s.Mv, T(kMinVal), lane, s.Mgrad); // rhs (v3g)
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// rows' forces into s.Jv (-D jar where jar < 0) and the zone words (every lane holds all RT words, s.zw too); returns the
|
|
423
|
+
// rows whose zone differs from old (when given)
|
|
424
|
+
template <class T, int NV, int NR>
|
|
425
|
+
__device__ __forceinline__ int constraint_update(Shared<T, NV, NR>& s, int nefc, unsigned* zw, const unsigned* old, int lane) {
|
|
426
|
+
constexpr int RT = NR / 32;
|
|
427
|
+
int nchg = 0;
|
|
428
|
+
#pragma unroll
|
|
429
|
+
for (int t = 0; t < RT; ++t) {
|
|
430
|
+
const int r = lane + 32 * t;
|
|
431
|
+
bool q = false;
|
|
432
|
+
if (r < nefc) {
|
|
433
|
+
const T jar = s.Jaref[r];
|
|
434
|
+
q = jar < T(0);
|
|
435
|
+
s.Jv[r] = q ? -s.D[r] * jar : T(0);
|
|
436
|
+
}
|
|
437
|
+
zw[t] = __ballot_sync(kFull, q);
|
|
438
|
+
if (lane == t) s.zw[t] = zw[t];
|
|
439
|
+
if (old) nchg += __popc(zw[t] ^ old[t]);
|
|
440
|
+
}
|
|
441
|
+
__syncwarp();
|
|
442
|
+
return nchg;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// The exact line search along s.search: returns alpha and the cost decrease (improvement, MuJoCo's -p.cost). Mv = M search
|
|
446
|
+
// and Jv = J search are left in shared memory for the update.
|
|
447
|
+
template <class T, int NV, int NR, class Rows>
|
|
448
|
+
__device__ __forceinline__ T line_search(Shared<T, NV, NR>& s, const Rows& R, const T* M, const T* qsm, int nefc, int lane,
|
|
449
|
+
T* impr, int* nsteps, bool* capped) {
|
|
450
|
+
constexpr int RT = NR / 32;
|
|
451
|
+
*impr = T(0);
|
|
452
|
+
T ss = T(0), g1 = T(0); // |search|^2 and quadGauss[1] = search . (Ma - qfrc_smooth), one paired reduction (v3n)
|
|
453
|
+
for (int i = lane; i < NV; i += 32) {
|
|
454
|
+
const T si = s.search[i];
|
|
455
|
+
ss += si * si;
|
|
456
|
+
g1 += si * (s.Ma[i] - __ldg(qsm + i));
|
|
457
|
+
}
|
|
458
|
+
warp_sum2(ss, g1, lane);
|
|
459
|
+
const T snorm = sqrt(ss);
|
|
460
|
+
if (UNIFORM(snorm < T(kMinVal))) return T(0);
|
|
461
|
+
L3_MATVEC(M, s.search, s.Mv, lane);
|
|
462
|
+
R.jv(s, s.search, nullptr, s.Jv, lane);
|
|
463
|
+
const T g2 = T(0.5) * vdot<T, NV>(s.search, s.Mv, lane); // quadGauss[2]
|
|
464
|
+
T x0[RT], jv[RT], dd[RT];
|
|
465
|
+
#pragma unroll
|
|
466
|
+
for (int t = 0; t < RT; ++t) {
|
|
467
|
+
const int r = lane + 32 * t;
|
|
468
|
+
const bool v = r < nefc;
|
|
469
|
+
x0[t] = v ? s.Jaref[r] : T(0);
|
|
470
|
+
jv[t] = v ? s.Jv[r] : T(0);
|
|
471
|
+
dd[t] = v ? s.D[r] : T(0);
|
|
472
|
+
}
|
|
473
|
+
const T eps = T(sizeof(T) == 4 ? 1.1920929e-7 : 2.220446049250313e-16);
|
|
474
|
+
T alpha = T(0), lo = T(0), hi = T(0), d0 = T(0);
|
|
475
|
+
bool has_hi = false, newton = false;
|
|
476
|
+
unsigned zprev = 0u;
|
|
477
|
+
int k = 0;
|
|
478
|
+
for (;; ++k) {
|
|
479
|
+
T fd = T(0), fdd = T(0);
|
|
480
|
+
unsigned z = 0u;
|
|
481
|
+
#pragma unroll
|
|
482
|
+
for (int t = 0; t < RT; ++t) {
|
|
483
|
+
const T x = x0[t] + alpha * jv[t];
|
|
484
|
+
if (x < T(0)) { z |= 1u << t; fd += dd[t] * x * jv[t]; fdd += dd[t] * jv[t] * jv[t]; }
|
|
485
|
+
}
|
|
486
|
+
if (k > 0 && __all_sync(kFull, newton && z == zprev)) break; // the Newton step stayed on its piece: exact
|
|
487
|
+
if (k == kLsMax) { *capped = true; break; }
|
|
488
|
+
warp_sum2(fd, fdd, lane);
|
|
489
|
+
fd += g1 + T(2) * alpha * g2;
|
|
490
|
+
fdd += T(2) * g2;
|
|
491
|
+
if (k == 0) {
|
|
492
|
+
d0 = fd;
|
|
493
|
+
if (UNIFORM(!(d0 < T(0)))) break; // not a descent direction (at the optimum up to roundoff): alpha stays 0
|
|
494
|
+
}
|
|
495
|
+
if (UNIFORM(fabs(fd) <= eps * fabs(d0))) break; // stationary to roundoff
|
|
496
|
+
if (fd < T(0)) lo = alpha; else { hi = alpha; has_hi = true; }
|
|
497
|
+
T nx = alpha - fd / fdd;
|
|
498
|
+
newton = nx > lo && (!has_hi || nx < hi);
|
|
499
|
+
if (!newton) nx = has_hi ? T(0.5) * (lo + hi) : T(2) * fmax(alpha, T(1e-6));
|
|
500
|
+
zprev = z;
|
|
501
|
+
alpha = nx;
|
|
502
|
+
}
|
|
503
|
+
*nsteps += k;
|
|
504
|
+
// the cost change at alpha (the rows on their pieces there, Gauss in closed form)
|
|
505
|
+
T dc = T(0);
|
|
506
|
+
#pragma unroll
|
|
507
|
+
for (int t = 0; t < RT; ++t) {
|
|
508
|
+
const T x = x0[t] + alpha * jv[t];
|
|
509
|
+
const T c1 = x < T(0) ? T(0.5) * dd[t] * x * x : T(0);
|
|
510
|
+
const T c0 = x0[t] < T(0) ? T(0.5) * dd[t] * x0[t] * x0[t] : T(0);
|
|
511
|
+
dc += c1 - c0;
|
|
512
|
+
}
|
|
513
|
+
dc = warp_sum(dc) + alpha * g1 + alpha * alpha * g2;
|
|
514
|
+
*impr = -dc;
|
|
515
|
+
return alpha;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// mju_quatIntegrate (step.h quat_integrate): quat <- normalize4(quat) * axisangle(vel / |vel|, h |vel|)
|
|
519
|
+
template <class T> __device__ void quat_integrate(T* quat, const T* vel, T h) {
|
|
520
|
+
V3<T> a{vel[0], vel[1], vel[2]};
|
|
521
|
+
const T n = normalize3(a);
|
|
522
|
+
const T angle = h * n;
|
|
523
|
+
T qrot[4] = {T(1), T(0), T(0), T(0)};
|
|
524
|
+
if (angle != T(0)) {
|
|
525
|
+
const T sn = sin(T(0.5) * angle);
|
|
526
|
+
qrot[0] = cos(T(0.5) * angle); qrot[1] = a.x * sn; qrot[2] = a.y * sn; qrot[3] = a.z * sn;
|
|
527
|
+
}
|
|
528
|
+
quat_normalize(quat);
|
|
529
|
+
T rq[4];
|
|
530
|
+
quat_mul(quat, qrot, rq);
|
|
531
|
+
for (int k = 0; k < 4; ++k) quat[k] = rq[k];
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// one world's inputs, from the dense arrays (the tape corpus's format) or from a hand record
|
|
535
|
+
template <class T> struct WorldIn {
|
|
536
|
+
const T *M, *qsm, *qa0, *D, *aref; // M packed TRI; aref, D [nefc]
|
|
537
|
+
unsigned cl0, cl1;
|
|
538
|
+
int nefc;
|
|
539
|
+
bool overflow;
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
// one world: the solve, the tape's factors, implicitfast and the position update; Rows: the constraint rows' operations
|
|
543
|
+
// (jv: out = J v - sub; jtf: out = J' f over the rows with f != 0; assemble_factor: H at the zones s.zw into s.L, factored)
|
|
544
|
+
template <class T, int NV, int NR, class Rows, class Opt = ImplicitFastOpts>
|
|
545
|
+
__device__ void solve(const Args<T>& A, Shared<T, NV, NR>& s, const WorldIn<T>& in, const Rows& R, int w, int lane) {
|
|
546
|
+
#if defined(D16_NV_GT64) // B3c: M's and H's words in the split storage (the dense outputs below copy as many)
|
|
547
|
+
constexpr int RT = NR / 32, NTRI = ::d16::split::WORDS;
|
|
548
|
+
#else
|
|
549
|
+
constexpr int RT = NR / 32, NTRI = NV * (NV + 1) / 2;
|
|
550
|
+
#endif
|
|
551
|
+
const long long t0 = clock64();
|
|
552
|
+
#ifdef L3_PROFILE
|
|
553
|
+
long long prof_[kNprof];
|
|
554
|
+
for (int k = 0; k < kNprof; ++k) prof_[k] = 0;
|
|
555
|
+
long long tprev_ = t0;
|
|
556
|
+
#endif
|
|
557
|
+
const T* M = in.M; // global: read through __ldg (v3e)
|
|
558
|
+
const T* qsm = in.qsm; // qfrc_smooth, global
|
|
559
|
+
const T* qa0 = in.qa0; // qacc_smooth, global
|
|
560
|
+
const T* aref = in.aref;
|
|
561
|
+
const int nefc = in.nefc;
|
|
562
|
+
const unsigned cl0 = in.cl0, cl1 = in.cl1;
|
|
563
|
+
#if defined(D16_NV_GT64) // B3c: implicitfast's L_Q and the actuator clamp words cover NV <= 64; a phase B body runs Euler
|
|
564
|
+
static_assert(Opt::kEuler, "a phase B body (NV > 64) runs the Euler form: no implicitfast factor in k_post");
|
|
565
|
+
#endif
|
|
566
|
+
const T tol = A.tol;
|
|
567
|
+
int flags = 0, niter = 0, nls = 0, nfact = 0;
|
|
568
|
+
if (in.overflow || nefc > NR) {
|
|
569
|
+
if (lane == 0) { A.flags[w] = kFlagOverflow; A.niter[w] = 0; A.nls[w] = 0; A.nfact[w] = 0; A.cycles[w] = 0; }
|
|
570
|
+
R.tape_overflow(A, w, lane);
|
|
571
|
+
// not solved: the substep HOLDS the state (q1 = q, v1 = v, the warm start carried, a_adv 0), a defined output whose VJP is the
|
|
572
|
+
// identity (the G1 adjoint skips the record, shell_adj.h; the 14x's training path fails fast on the record, train14.Window14).
|
|
573
|
+
// Before 11-11 nothing was written here and the ping-pong output kept stale memory (the G1's substep 1: the slot's state from a
|
|
574
|
+
// window earlier, zeros in the first window; the 14x: the state two substeps back)
|
|
575
|
+
{
|
|
576
|
+
const int nq = A.nq;
|
|
577
|
+
const T* q = A.qpos + w * nq;
|
|
578
|
+
T* q1 = A.qpos1 + w * nq;
|
|
579
|
+
for (int i = lane; i < nq; i += 32) q1[i] = q[i];
|
|
580
|
+
for (int i = lane; i < NV; i += 32) {
|
|
581
|
+
A.qvel1[w * NV + i] = A.qvel[w * NV + i];
|
|
582
|
+
A.a_star[w * NV + i] = A.warm[w * NV + i];
|
|
583
|
+
A.a_adv[w * NV + i] = T(0);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
for (int i = lane; i < NV; i += 32) s.qfrc_c[i] = T(0);
|
|
589
|
+
for (int r = lane; r < nefc; r += 32) s.D[r] = in.D[r];
|
|
590
|
+
if (lane < Shared<T, NV, NR>::kZW) s.zw[lane] = 0u;
|
|
591
|
+
if (lane < 2) s.clw[lane] = lane ? cl1 : cl0;
|
|
592
|
+
__syncwarp();
|
|
593
|
+
L3_MARK(0);
|
|
594
|
+
unsigned zw[RT];
|
|
595
|
+
#pragma unroll
|
|
596
|
+
for (int t = 0; t < RT; ++t) zw[t] = 0u;
|
|
597
|
+
bool lcur = false; // s.L holds the factor of H at the current zones
|
|
598
|
+
if (nefc == 0) { // qacc = qacc_smooth, no rows: L_H = chol(M)
|
|
599
|
+
for (int i = lane; i < NV; i += 32) { s.qacc[i] = __ldg(qa0 + i); s.Mgrad[i] = T(0); } // (the fused rhs: unused)
|
|
600
|
+
for (int e = lane; e < NTRI; e += 32) s.L[e] = __ldg(M + e);
|
|
601
|
+
__syncwarp();
|
|
602
|
+
if (L3_FACTOR_M(s, lane)) flags |= kFlagRankLoss;
|
|
603
|
+
lcur = true;
|
|
604
|
+
} else {
|
|
605
|
+
// warm start (engine_forward.c:1071-1150): the warm start's total cost against qacc_smooth's (Gauss 0 there)
|
|
606
|
+
for (int i = lane; i < NV; i += 32) {
|
|
607
|
+
const T a0 = __ldg(qa0 + i);
|
|
608
|
+
s.qacc[i] = A.warm[w * NV + i];
|
|
609
|
+
s.grad[i] = a0; // qacc_smooth staged (s.grad is free until the gradient)
|
|
610
|
+
s.Mgrad[i] = s.qacc[i] - a0; // da (scratch)
|
|
611
|
+
}
|
|
612
|
+
__syncwarp();
|
|
613
|
+
flags |= R.jv(s, s.qacc, aref, s.Jaref, lane); // jar at the warm start (and the hand's slot-order check)
|
|
614
|
+
R.jv(s, s.grad, aref, s.Jv, lane); // jar at qacc_smooth (scratch)
|
|
615
|
+
// (v3d's fused pair of passes, a second vector inside contact_jv, measured 12% slower overall in an interleaved A/B:
|
|
616
|
+
// the hot line-search J v carried the doubled loop; reverted)
|
|
617
|
+
L3_MATVEC(M, s.Mgrad, s.Mv, lane); // M da
|
|
618
|
+
T cw = T(0), cs = T(0);
|
|
619
|
+
#pragma unroll
|
|
620
|
+
for (int t = 0; t < RT; ++t) {
|
|
621
|
+
const int r = lane + 32 * t;
|
|
622
|
+
if (r < nefc) {
|
|
623
|
+
const T jw = s.Jaref[r], js = s.Jv[r];
|
|
624
|
+
if (jw < T(0)) cw += T(0.5) * s.D[r] * jw * jw;
|
|
625
|
+
if (js < T(0)) cs += T(0.5) * s.D[r] * js * js;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
for (int i = lane; i < NV; i += 32) cw += T(0.5) * s.Mgrad[i] * s.Mv[i]; // + 0.5 da' M da, in the same sum (v3n)
|
|
629
|
+
warp_sum2(cw, cs, lane);
|
|
630
|
+
if (UNIFORM(!(cw > cs))) flags |= kFlagWarm;
|
|
631
|
+
else { // qacc_smooth
|
|
632
|
+
for (int i = lane; i < NV; i += 32) s.qacc[i] = s.grad[i]; // qacc_smooth (staged above)
|
|
633
|
+
for (int r = lane; r < nefc; r += 32) s.Jaref[r] = s.Jv[r];
|
|
634
|
+
__syncwarp();
|
|
635
|
+
}
|
|
636
|
+
L3_MARK(1);
|
|
637
|
+
// the solver's context: Ma, the rows at qacc, the gradient (mj_solPrimal :2853-2945)
|
|
638
|
+
T trace = T(0);
|
|
639
|
+
for (int i = lane; i < NV; i += 32) trace += L3_M_DIAG(M, i);
|
|
640
|
+
const T scale = T(1) / warp_sum(trace);
|
|
641
|
+
L3_MATVEC(M, s.qacc, s.Ma, lane);
|
|
642
|
+
constraint_update<T, NV, NR>(s, nefc, zw, nullptr, lane);
|
|
643
|
+
R.jtf(s, s.Jv, s.qfrc_c, lane);
|
|
644
|
+
for (int i = lane; i < NV; i += 32) { const T g = s.Ma[i] - __ldg(qsm + i) - s.qfrc_c[i]; s.grad[i] = g; s.Mgrad[i] = g; }
|
|
645
|
+
__syncwarp();
|
|
646
|
+
L3_MARK(2);
|
|
647
|
+
// zero-iteration exits: done = flg_gap && flg_gradient; flg_gap (M^-1 grad) is formed only when flg_gradient holds
|
|
648
|
+
const T gg = vdot<T, NV>(s.grad, s.grad, lane);
|
|
649
|
+
const bool flg_gradient = UNIFORM(scale * sqrt(gg) < tol);
|
|
650
|
+
bool done = false;
|
|
651
|
+
if (flg_gradient) {
|
|
652
|
+
for (int e = lane; e < NTRI; e += 32) s.L[e] = __ldg(M + e);
|
|
653
|
+
__syncwarp();
|
|
654
|
+
L3_FACTOR_M(s, lane); // chol(M) (MuJoCo: qLD), forward fused
|
|
655
|
+
L3_SOLVE_BWD(s, lane);
|
|
656
|
+
done = UNIFORM(fmax(T(0), T(0.5) * scale * vdot<T, NV>(s.grad, s.Mgrad, lane)) < tol);
|
|
657
|
+
}
|
|
658
|
+
L3_MARK(3);
|
|
659
|
+
if (!done) {
|
|
660
|
+
for (int i = lane; i < NV; i += 32) s.Mgrad[i] = s.grad[i]; // the factor's fused rhs (v3g)
|
|
661
|
+
__syncwarp();
|
|
662
|
+
if (R.assemble_factor(s, lane)) flags |= kFlagRankLoss;
|
|
663
|
+
++nfact;
|
|
664
|
+
lcur = true;
|
|
665
|
+
L3_MARK(4);
|
|
666
|
+
L3_SOLVE_BWD(s, lane);
|
|
667
|
+
done = flg_gradient && UNIFORM(fmax(T(0), T(0.5) * scale * vdot<T, NV>(s.grad, s.Mgrad, lane)) < tol);
|
|
668
|
+
L3_MARK(6);
|
|
669
|
+
}
|
|
670
|
+
for (int i = lane; i < NV; i += 32) s.search[i] = -s.Mgrad[i];
|
|
671
|
+
__syncwarp();
|
|
672
|
+
bool stopped = done;
|
|
673
|
+
while (!done && niter < A.iterations) {
|
|
674
|
+
T ls_impr;
|
|
675
|
+
bool lscap = false;
|
|
676
|
+
const T alpha = line_search<T, NV, NR>(s, R, M, qsm, nefc, lane, &ls_impr, &nls, &lscap);
|
|
677
|
+
L3_MARK(7);
|
|
678
|
+
if (lscap) flags |= kFlagLsCap;
|
|
679
|
+
if (UNIFORM(alpha == T(0))) { stopped = true; flags |= kFlagStalled; break; } // MuJoCo: no step, not an iteration
|
|
680
|
+
for (int i = lane; i < NV; i += 32) { s.qacc[i] += alpha * s.search[i]; s.Ma[i] += alpha * s.Mv[i]; }
|
|
681
|
+
for (int r = lane; r < nefc; r += 32) s.Jaref[r] += alpha * s.Jv[r];
|
|
682
|
+
__syncwarp();
|
|
683
|
+
unsigned old[RT];
|
|
684
|
+
#pragma unroll
|
|
685
|
+
for (int t = 0; t < RT; ++t) old[t] = zw[t];
|
|
686
|
+
const int nchg = constraint_update<T, NV, NR>(s, nefc, zw, old, lane);
|
|
687
|
+
R.jtf(s, s.Jv, s.qfrc_c, lane); // before the refactor: the hand's assembly stages rows in s.Jv (the forces)
|
|
688
|
+
for (int i = lane; i < NV; i += 32) { const T g = s.Ma[i] - __ldg(qsm + i) - s.qfrc_c[i]; s.grad[i] = g; s.Mgrad[i] = g; }
|
|
689
|
+
__syncwarp();
|
|
690
|
+
L3_MARK(8);
|
|
691
|
+
if (UNIFORM(nchg != 0)) { // a refactor with the forward solve fused (v3g), then the backward half
|
|
692
|
+
if (R.assemble_factor(s, lane)) flags |= kFlagRankLoss;
|
|
693
|
+
++nfact;
|
|
694
|
+
L3_MARK(4);
|
|
695
|
+
L3_SOLVE_BWD(s, lane);
|
|
696
|
+
} else { // the factor is reused: both halves column by column (v3j)
|
|
697
|
+
L3_SOLVE_FWD(s, lane);
|
|
698
|
+
L3_SOLVE_BWD(s, lane);
|
|
699
|
+
}
|
|
700
|
+
L3_MARK(6);
|
|
701
|
+
const T improvement = scale * ls_impr;
|
|
702
|
+
const T gradient = scale * sqrt(vdot<T, NV>(s.grad, s.grad, lane));
|
|
703
|
+
const T decrement = fmax(T(0), T(0.5) * scale * vdot<T, NV>(s.grad, s.Mgrad, lane));
|
|
704
|
+
++niter;
|
|
705
|
+
const bool mj = UNIFORM((improvement > T(0) && improvement < tol) || gradient < tol || decrement < tol);
|
|
706
|
+
if (mj || nchg == 0) {
|
|
707
|
+
if (!mj) flags |= kFlagLanded;
|
|
708
|
+
stopped = true;
|
|
709
|
+
break;
|
|
710
|
+
}
|
|
711
|
+
for (int i = lane; i < NV; i += 32) s.search[i] = -s.Mgrad[i];
|
|
712
|
+
__syncwarp();
|
|
713
|
+
L3_MARK(8);
|
|
714
|
+
}
|
|
715
|
+
L3_MARK(8);
|
|
716
|
+
if (!stopped) flags |= kFlagCap;
|
|
717
|
+
if (!lcur) { // done at the zero-iteration test: the tape's factor at the final zones
|
|
718
|
+
if (R.assemble_factor(s, lane)) flags |= kFlagRankLoss;
|
|
719
|
+
++nfact;
|
|
720
|
+
L3_MARK(4);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
// outputs of the solve and the tape's L_H
|
|
724
|
+
// (the dense LH / LQ / zone / qfrc_c outputs are optional: null when a tape carries them; a_star is the next warm start)
|
|
725
|
+
if (A.LH) {
|
|
726
|
+
T* LH = A.LH + w * NTRI;
|
|
727
|
+
for (int e = lane; e < NTRI; e += 32) LH[e] = s.L[e];
|
|
728
|
+
}
|
|
729
|
+
for (int i = lane; i < NV; i += 32) A.a_star[w * NV + i] = s.qacc[i];
|
|
730
|
+
if (A.qfrc_c)
|
|
731
|
+
for (int i = lane; i < NV; i += 32) A.qfrc_c[w * NV + i] = s.qfrc_c[i];
|
|
732
|
+
if (A.zone) {
|
|
733
|
+
#pragma unroll
|
|
734
|
+
for (int t = 0; t < RT; ++t)
|
|
735
|
+
if (lane == t) A.zone[w * A.zone_words + t] = zw[t];
|
|
736
|
+
for (int t = RT + lane; t < A.zone_words; t += 32) A.zone[w * A.zone_words + t] = 0u;
|
|
737
|
+
}
|
|
738
|
+
__syncwarp();
|
|
739
|
+
R.tape_LH(A, s, w, lane); // the tape's L_H from s.L, before implicitfast reuses it
|
|
740
|
+
L3_MARK(10);
|
|
741
|
+
// implicitfast (step.h): qH = M + h kd on the unclamped actuated dofs; a_adv = qH^-1 (qfrc_smooth + qfrc_constraint).
|
|
742
|
+
// The Euler form (Opt::kEuler: a_adv = a*; no dense LQ output, no tape L_Q) compiles it out through constant guards at
|
|
743
|
+
// this scope: an if constexpr block around it moved one instruction in four of the G1 build's functions (P37e bisection,
|
|
744
|
+
// L3_RESULTS.md), and the G1's SASS must stay identical
|
|
745
|
+
for (int e = lane; e < (Opt::kEuler ? 0 : NTRI); e += 32) s.L[e] = __ldg(M + e);
|
|
746
|
+
__syncwarp();
|
|
747
|
+
for (int i = lane; i < NV; i += 32) {
|
|
748
|
+
const T kd = Opt::kEuler ? T(0) : A.kd[i];
|
|
749
|
+
#if defined(D16_NV_GT64) // B3c: a phase B body runs Euler (asserted in solve), where no dof is clamped here; no shift past bit 31
|
|
750
|
+
const bool clamped = i < 64 && ((i < 32 ? cl0 >> i : cl1 >> (i - 32)) & 1u) != 0u;
|
|
751
|
+
#else
|
|
752
|
+
const bool clamped = ((i < 32 ? cl0 >> i : cl1 >> (i - 32)) & 1u) != 0u;
|
|
753
|
+
#endif
|
|
754
|
+
if (kd != T(0) && !clamped) s.L[L3_TRI(i, i)] += A.h * kd;
|
|
755
|
+
s.Mgrad[i] = Opt::kEuler ? s.qacc[i] : __ldg(qsm + i) + s.qfrc_c[i];
|
|
756
|
+
}
|
|
757
|
+
__syncwarp();
|
|
758
|
+
if (!Opt::kEuler && L3_FACTOR_M(s, lane)) flags |= kFlagRankLoss;
|
|
759
|
+
if (!Opt::kEuler) L3_SOLVE_BWD(s, lane);
|
|
760
|
+
if (!Opt::kEuler && A.LQ) {
|
|
761
|
+
T* LQ = A.LQ + w * NTRI;
|
|
762
|
+
for (int e = lane; e < NTRI; e += 32) LQ[e] = s.L[e];
|
|
763
|
+
}
|
|
764
|
+
L3_MARK(9);
|
|
765
|
+
// mj_advance: qvel += h a_adv; positions with the new qvel (the free root: mju_quatIntegrate, body-frame angular velocity)
|
|
766
|
+
const T h = A.h;
|
|
767
|
+
for (int i = lane; i < NV; i += 32) {
|
|
768
|
+
const T v1 = A.qvel[w * NV + i] + h * s.Mgrad[i];
|
|
769
|
+
s.Mv[i] = v1; // (scratch: qvel')
|
|
770
|
+
A.a_adv[w * NV + i] = s.Mgrad[i];
|
|
771
|
+
A.qvel1[w * NV + i] = v1;
|
|
772
|
+
}
|
|
773
|
+
__syncwarp();
|
|
774
|
+
const int nq = A.nq;
|
|
775
|
+
const T* q = A.qpos + w * nq;
|
|
776
|
+
T* q1 = A.qpos1 + w * nq;
|
|
777
|
+
for (int i = lane; i < NV; i += 32) {
|
|
778
|
+
const int qa = A.hinge_qadr[i];
|
|
779
|
+
if (qa >= 0) q1[qa] = q[qa] + h * s.Mv[i];
|
|
780
|
+
}
|
|
781
|
+
if (lane == 0) {
|
|
782
|
+
T root[7];
|
|
783
|
+
for (int k = 0; k < 7; ++k) root[k] = q[k];
|
|
784
|
+
for (int k = 0; k < 3; ++k) root[k] += h * s.Mv[k];
|
|
785
|
+
if (Opt::kNball == 0) quat_integrate(root + 3, s.Mv + 3, h); // (with balls: below, one copy for every quaternion)
|
|
786
|
+
for (int k = 0; k < 7; ++k) q1[k] = root[k];
|
|
787
|
+
A.flags[w] = flags; A.niter[w] = niter; A.nls[w] = nls; A.nfact[w] = nfact;
|
|
788
|
+
}
|
|
789
|
+
if constexpr (Opt::kNball > 0) { // the root's rotation on lane 0, ball b on lane 1 + b: one inline quat_integrate (a
|
|
790
|
+
// second copy beside the root's raised the kernel's spills 32 -> 80 B and cost +3.9%, P37e)
|
|
791
|
+
static_assert(Opt::kNball <= 31, "one lane per ball");
|
|
792
|
+
if (lane <= Opt::kNball) {
|
|
793
|
+
int qa = 3, da = 3;
|
|
794
|
+
#pragma unroll
|
|
795
|
+
for (int k = 0; k < Opt::kNball; ++k)
|
|
796
|
+
if (lane == k + 1) { qa = Opt::ball_q(k); da = Opt::ball_d(k); }
|
|
797
|
+
T quat[4];
|
|
798
|
+
for (int k = 0; k < 4; ++k) quat[k] = q[qa + k];
|
|
799
|
+
quat_integrate(quat, s.Mv + da, h);
|
|
800
|
+
for (int k = 0; k < 4; ++k) q1[qa + k] = quat[k];
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
R.template tape_rest<!Opt::kEuler>(A, s, w, lane, niter, flags); // the rest but POSE (L_Q s.L, a_adv s.Mgrad, a* s.qacc)
|
|
804
|
+
if (lane == 0) A.cycles[w] = clock64() - t0;
|
|
805
|
+
L3_MARK(10);
|
|
806
|
+
if (lane == 0) {
|
|
807
|
+
#ifdef L3_PROFILE
|
|
808
|
+
for (int k = 0; k < kNprof; ++k) A.prof[w * kNprof + k] = prof_[k];
|
|
809
|
+
#endif
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
// ---- the constraint rows' operations: the dense rows (the tape corpus's / L2 v1's format) ----
|
|
815
|
+
template <class T, int NV, int NR> struct DenseRows {
|
|
816
|
+
const T* J; // [NR][NV]
|
|
817
|
+
const T* M; // packed TRI (global)
|
|
818
|
+
int nefc;
|
|
819
|
+
__device__ __forceinline__ int jv(Shared<T, NV, NR>&, const T* v, const T* sub, T* out, int lane) const {
|
|
820
|
+
rows_dot<T, NV>(J, v, sub, out, nefc, lane);
|
|
821
|
+
return 0;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
__device__ __forceinline__ void jtf(Shared<T, NV, NR>&, const T* f, T* out, int lane) const {
|
|
825
|
+
mul_JT<T, NV>(J, f, out, nefc, lane);
|
|
826
|
+
}
|
|
827
|
+
__device__ __forceinline__ int assemble_factor(Shared<T, NV, NR>& s, int lane) const {
|
|
828
|
+
return l3::assemble_factor<T, NV, NR>(s, J, M, lane);
|
|
829
|
+
}
|
|
830
|
+
__device__ __forceinline__ void tape_LH(const Args<T>&, Shared<T, NV, NR>&, int, int) const {}
|
|
831
|
+
template <bool kLQ = true>
|
|
832
|
+
__device__ __forceinline__ void tape_rest(const Args<T>&, Shared<T, NV, NR>&, int, int, int, int) const {}
|
|
833
|
+
__device__ __forceinline__ void tape_overflow(const Args<T>&, int, int) const {}
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
// ---- the hand's rows (core/soft/hand.h): limits +-e_dof; contacts as contact-frame rows on their support dofs ----
|
|
837
|
+
// v3b: each lane holds its two contacts' metadata (c = lane, lane + 32) for the whole solve (loaded once per world); the
|
|
838
|
+
// assembly stages each active contact's J in a shared double buffer with the next contact's loads in flight; J'f loads one
|
|
839
|
+
// contact ahead.
|
|
840
|
+
#if defined(D16_NV_GT64)
|
|
841
|
+
// B3c (2026-11-08; PHASE_B.md items 2, 3 and 5): the phase B body's contact side. KD 20 support slots in five dof words per
|
|
842
|
+
// contact, three dofs per lane in J'f (NV <= 96), dof masks of three words (the 2-word mask's shift past dof 63 was undefined,
|
|
843
|
+
// section 6.4), and up to four limit rows per lane (nlim <= 128; the 416 has 100 limits). Arithmetic and order as the 14x
|
|
844
|
+
// path in the #else branch, which stays as it was token for token.
|
|
845
|
+
constexpr int kConW = 5, kLimJ = 4, kPairJ = 7; // dof words per contact, limit rows per lane, slot pairs per lane
|
|
846
|
+
// a support slot's dof from the contact's five packed dof words (slot s may be a runtime value)
|
|
847
|
+
__device__ __forceinline__ int slot_dof(unsigned w0, unsigned w1, unsigned w2, unsigned w3, unsigned w4, int s) {
|
|
848
|
+
const unsigned w = s < 4 ? w0 : (s < 8 ? w1 : (s < 12 ? w2 : (s < 16 ? w3 : w4)));
|
|
849
|
+
return static_cast<int>((w >> (8 * (s & 3))) & 255u);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
template <class T> struct ConLane { // this lane's contacts c = lane (j = 0) and lane + 32 (j = 1); nd 0 past ncon
|
|
853
|
+
unsigned meta0, meta1, d00, d01, d02, d03, d04, d10, d11, d12, d13, d14;
|
|
854
|
+
unsigned lim0, lim1, lim2, lim3; // limit rows r = lane + 32 j: their rowmeta (0 past nlim)
|
|
855
|
+
unsigned pr0, pr1, pr2, pr3, pr4, pr5, pr6; // slot pairs p = lane + 32 j: a | b << 8 (a >= b); p >= 210 has a >= 20, never a slot
|
|
856
|
+
T mu0, mu1;
|
|
857
|
+
};
|
|
858
|
+
__device__ __forceinline__ unsigned con_pair_word(int p) { // slot pair p = a (a + 1) / 2 + b, a >= b
|
|
859
|
+
const int a = tri_row(p);
|
|
860
|
+
return static_cast<unsigned>(a) | static_cast<unsigned>(p - a * (a + 1) / 2) << 8;
|
|
861
|
+
}
|
|
862
|
+
template <class T> __device__ __forceinline__ unsigned con_lim(const ConLane<T>& c, int j) { // limit word j (j uniform or unrolled)
|
|
863
|
+
return j == 0 ? c.lim0 : (j == 1 ? c.lim1 : (j == 2 ? c.lim2 : c.lim3));
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
template <class T, int NV, int NC, int NRH, int KD>
|
|
867
|
+
__device__ __forceinline__ ConLane<T> con_lane(const T* rec, int ncon, int nlim, int lane) {
|
|
868
|
+
constexpr HandLayout H = D16_L3_HAND_LAYOUT(NV, NC, NRH, KD);
|
|
869
|
+
static_assert(NC <= 64 && KD == 4 * kConW && NV <= 96 && (KD * (KD + 1) / 2 + 31) / 32 == kPairJ,
|
|
870
|
+
"two contacts per lane; five dof words per contact; three dofs per lane; seven slot pairs per lane");
|
|
871
|
+
ConLane<T> c{};
|
|
872
|
+
const int c0 = lane, c1 = lane + 32;
|
|
873
|
+
c.meta0 = c0 < ncon ? tape_get_u(rec, H.conmeta + c0) : 0u;
|
|
874
|
+
c.meta1 = c1 < ncon ? tape_get_u(rec, H.conmeta + c1) : 0u;
|
|
875
|
+
c.mu0 = c0 < ncon ? rec[H.conmu + c0] : T(0);
|
|
876
|
+
c.mu1 = c1 < ncon ? rec[H.conmu + c1] : T(0);
|
|
877
|
+
const int o0 = H.condof + c0 * (KD / 4), o1 = H.condof + c1 * (KD / 4);
|
|
878
|
+
c.d00 = c0 < ncon ? tape_get_u(rec, o0) : ~0u; c.d01 = c0 < ncon ? tape_get_u(rec, o0 + 1) : ~0u;
|
|
879
|
+
c.d02 = c0 < ncon ? tape_get_u(rec, o0 + 2) : ~0u; c.d03 = c0 < ncon ? tape_get_u(rec, o0 + 3) : ~0u;
|
|
880
|
+
c.d04 = c0 < ncon ? tape_get_u(rec, o0 + 4) : ~0u;
|
|
881
|
+
c.d10 = c1 < ncon ? tape_get_u(rec, o1) : ~0u; c.d11 = c1 < ncon ? tape_get_u(rec, o1 + 1) : ~0u;
|
|
882
|
+
c.d12 = c1 < ncon ? tape_get_u(rec, o1 + 2) : ~0u; c.d13 = c1 < ncon ? tape_get_u(rec, o1 + 3) : ~0u;
|
|
883
|
+
c.d14 = c1 < ncon ? tape_get_u(rec, o1 + 4) : ~0u;
|
|
884
|
+
c.lim0 = lane < nlim ? tape_get_u(rec, H.rowmeta + lane) : 0u;
|
|
885
|
+
c.lim1 = lane + 32 < nlim ? tape_get_u(rec, H.rowmeta + lane + 32) : 0u;
|
|
886
|
+
c.lim2 = lane + 64 < nlim ? tape_get_u(rec, H.rowmeta + lane + 64) : 0u;
|
|
887
|
+
c.lim3 = lane + 96 < nlim ? tape_get_u(rec, H.rowmeta + lane + 96) : 0u;
|
|
888
|
+
c.pr0 = con_pair_word(lane); c.pr1 = con_pair_word(lane + 32); c.pr2 = con_pair_word(lane + 64);
|
|
889
|
+
c.pr3 = con_pair_word(lane + 96); c.pr4 = con_pair_word(lane + 128); c.pr5 = con_pair_word(lane + 160);
|
|
890
|
+
c.pr6 = con_pair_word(lane + 192);
|
|
891
|
+
return c;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
// one contact's J v on its lane: d_n, d_t1, d_t2 over its support, then its rows d_n + s mu d_t; a strict-order check
|
|
895
|
+
template <class T, int NV, int KD>
|
|
896
|
+
__device__ __forceinline__ bool contact_jv(const T* Jc, unsigned meta, T mu, unsigned w0, unsigned w1, unsigned w2,
|
|
897
|
+
unsigned w3, unsigned w4, const T* v, const T* sub, T* out) {
|
|
898
|
+
T j[3 * KD];
|
|
899
|
+
#pragma unroll
|
|
900
|
+
for (int e = 0; e < 3 * KD; e += 4) chol::load4(Jc + e, j + e);
|
|
901
|
+
const int nd = hand_con_nd(meta), row0 = hand_con_row0(meta);
|
|
902
|
+
T d0 = T(0), d1 = T(0), d2 = T(0);
|
|
903
|
+
int prev = -1;
|
|
904
|
+
bool bad = false;
|
|
905
|
+
#pragma unroll
|
|
906
|
+
for (int sl = 0; sl < KD; ++sl) {
|
|
907
|
+
if (sl < nd) {
|
|
908
|
+
const int dof = slot_dof(w0, w1, w2, w3, w4, sl);
|
|
909
|
+
bad |= dof <= prev || dof >= NV;
|
|
910
|
+
prev = dof;
|
|
911
|
+
const T x = v[dof < NV ? dof : 0];
|
|
912
|
+
d0 += j[sl] * x; d1 += j[KD + sl] * x; d2 += j[2 * KD + sl] * x;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
if (hand_con_condim(meta) == 1) {
|
|
916
|
+
out[row0] = sub ? d0 - sub[row0] : d0;
|
|
917
|
+
} else {
|
|
918
|
+
#pragma unroll
|
|
919
|
+
for (int k = 0; k < 4; ++k) {
|
|
920
|
+
const T val = d0 + (k % 2 == 0 ? mu : -mu) * (k < 2 ? d1 : d2);
|
|
921
|
+
out[row0 + k] = sub ? val - sub[row0 + k] : val;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return bad;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
// out[r] = J_r v (- sub[r]); returns kFlagHandOrder when some contact's slots are not strictly ascending dofs
|
|
928
|
+
template <class T, int NV, int NC, int NRH, int KD>
|
|
929
|
+
__device__ __noinline__ int hand_jv(const T* rec, int ncon, int nlim, ConLane<T> cl, const T* v, const T* sub, T* out,
|
|
930
|
+
int lane) {
|
|
931
|
+
constexpr HandLayout H = D16_L3_HAND_LAYOUT(NV, NC, NRH, KD);
|
|
932
|
+
#pragma unroll
|
|
933
|
+
for (int j = 0; j < kLimJ; ++j) { // limit rows r = lane + 32 j: their meta in registers
|
|
934
|
+
const int r = lane + 32 * j;
|
|
935
|
+
if (r < nlim) {
|
|
936
|
+
const uint32_t m = con_lim(cl, j);
|
|
937
|
+
const T x = v[hand_row_index(m)];
|
|
938
|
+
const T val = hand_row_neg(m) ? -x : x;
|
|
939
|
+
out[r] = sub ? val - sub[r] : val;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
bool bad = false;
|
|
943
|
+
if (lane < ncon)
|
|
944
|
+
bad |= contact_jv<T, NV, KD>(rec + H.conJ + lane * 3 * KD, cl.meta0, cl.mu0, cl.d00, cl.d01, cl.d02, cl.d03, cl.d04, v, sub,
|
|
945
|
+
out);
|
|
946
|
+
if (lane + 32 < ncon)
|
|
947
|
+
bad |= contact_jv<T, NV, KD>(rec + H.conJ + (lane + 32) * 3 * KD, cl.meta1, cl.mu1, cl.d10, cl.d11, cl.d12, cl.d13, cl.d14,
|
|
948
|
+
v, sub, out);
|
|
949
|
+
const bool any_bad = __any_sync(kFull, bad);
|
|
950
|
+
__syncwarp();
|
|
951
|
+
return any_bad ? kFlagHandOrder : 0;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// a contact's frame forces (sum f, mu (f0 - f1), mu (f2 - f3); condim 1: f0) and its 3-word support mask, on its lane
|
|
955
|
+
template <class T, int NV, int KD>
|
|
956
|
+
__device__ __forceinline__ void contact_g(unsigned meta, T mu, unsigned w0, unsigned w1, unsigned w2, unsigned w3, unsigned w4,
|
|
957
|
+
const T* f, T& g0, T& g1, T& g2, unsigned& m0, unsigned& m1, unsigned& m2) {
|
|
958
|
+
const int nd = hand_con_nd(meta), row0 = hand_con_row0(meta);
|
|
959
|
+
g0 = g1 = g2 = T(0); m0 = m1 = m2 = 0u;
|
|
960
|
+
if (nd == 0) return;
|
|
961
|
+
if (hand_con_condim(meta) == 1) {
|
|
962
|
+
g0 = f[row0];
|
|
963
|
+
} else {
|
|
964
|
+
const T f0 = f[row0], f1 = f[row0 + 1], f2 = f[row0 + 2], f3 = f[row0 + 3];
|
|
965
|
+
g0 = f0 + f1 + f2 + f3; g1 = mu * (f0 - f1); g2 = mu * (f2 - f3);
|
|
966
|
+
}
|
|
967
|
+
static_assert(NV <= 96, "the contact dof mask covers 96 dofs (three words)");
|
|
968
|
+
#pragma unroll
|
|
969
|
+
for (int sl = 0; sl < KD; ++sl)
|
|
970
|
+
if (sl < nd) {
|
|
971
|
+
const int dof = slot_dof(w0, w1, w2, w3, w4, sl);
|
|
972
|
+
if (dof < 32) m0 |= 1u << dof; else if (dof < 64) m1 |= 1u << (dof - 32); else if (dof < NV) m2 |= 1u << (dof - 64);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// out = J' f over the rows with f != 0: three dofs per lane (dA = lane, dB = lane + 32, dC = lane + 64); the limits in row order,
|
|
977
|
+
// then the contacts in contact order, each (sum f) Jn + mu (f0 - f1) Jt1 + mu (f2 - f3) Jt2 on its support; the next contact's
|
|
978
|
+
// loads in flight
|
|
979
|
+
template <class T, int NV, int NC, int NRH, int KD>
|
|
980
|
+
__device__ __noinline__ void hand_jtf(const T* rec, int ncon, int nlim, ConLane<T> cl, const T* f, T* out, int lane) {
|
|
981
|
+
constexpr HandLayout H = D16_L3_HAND_LAYOUT(NV, NC, NRH, KD);
|
|
982
|
+
T ga0, ga1, ga2, gb0, gb1, gb2;
|
|
983
|
+
unsigned ma0, ma1, ma2, mb0, mb1, mb2;
|
|
984
|
+
contact_g<T, NV, KD>(cl.meta0, cl.mu0, cl.d00, cl.d01, cl.d02, cl.d03, cl.d04, f, ga0, ga1, ga2, ma0, ma1, ma2);
|
|
985
|
+
contact_g<T, NV, KD>(cl.meta1, cl.mu1, cl.d10, cl.d11, cl.d12, cl.d13, cl.d14, f, gb0, gb1, gb2, mb0, mb1, mb2);
|
|
986
|
+
const int dA = lane, dB = lane + 32, dC = lane + 64;
|
|
987
|
+
const bool hasB = dB < NV, hasC = dC < NV;
|
|
988
|
+
T accA = T(0), accB = T(0), accC = T(0);
|
|
989
|
+
for (int r = 0; r < nlim; ++r) { // limit rows: J = +-e_dof (their meta from lane r & 31's word r >> 5)
|
|
990
|
+
const uint32_t m = __shfl_sync(kFull, con_lim(cl, r >> 5), r & 31);
|
|
991
|
+
const T fr = f[r];
|
|
992
|
+
if (fr == T(0)) continue; // uniform
|
|
993
|
+
const int dof = hand_row_index(m);
|
|
994
|
+
const T val = hand_row_neg(m) ? -fr : fr;
|
|
995
|
+
if (dof == dA) accA += val;
|
|
996
|
+
if (hasB && dof == dB) accB += val;
|
|
997
|
+
if (hasC && dof == dC) accC += val;
|
|
998
|
+
}
|
|
999
|
+
const unsigned below = (1u << lane) - 1u;
|
|
1000
|
+
// contact c's broadcast and this lane's loads (Jn, Jt1, Jt2 at its slot), fetched one contact ahead
|
|
1001
|
+
struct Fetch { T c0, c1, c2, xa[3], xb[3], xc[3]; bool ina, inb, inc; };
|
|
1002
|
+
auto fetch = [&](int c) {
|
|
1003
|
+
Fetch q{};
|
|
1004
|
+
const bool second = c >= 32; // uniform
|
|
1005
|
+
const int src = c & 31;
|
|
1006
|
+
q.c0 = __shfl_sync(kFull, second ? gb0 : ga0, src);
|
|
1007
|
+
q.c1 = __shfl_sync(kFull, second ? gb1 : ga1, src);
|
|
1008
|
+
q.c2 = __shfl_sync(kFull, second ? gb2 : ga2, src);
|
|
1009
|
+
const unsigned m0 = __shfl_sync(kFull, second ? mb0 : ma0, src), m1 = __shfl_sync(kFull, second ? mb1 : ma1, src),
|
|
1010
|
+
m2 = __shfl_sync(kFull, second ? mb2 : ma2, src);
|
|
1011
|
+
q.ina = q.c0 != T(0) && ((m0 >> lane) & 1u);
|
|
1012
|
+
q.inb = q.c0 != T(0) && hasB && ((m1 >> lane) & 1u);
|
|
1013
|
+
q.inc = q.c0 != T(0) && hasC && ((m2 >> lane) & 1u);
|
|
1014
|
+
const T* Jc = rec + H.conJ + c * 3 * KD;
|
|
1015
|
+
if (q.ina) {
|
|
1016
|
+
const int k = __popc(m0 & below);
|
|
1017
|
+
q.xa[0] = Jc[k]; q.xa[1] = Jc[KD + k]; q.xa[2] = Jc[2 * KD + k];
|
|
1018
|
+
}
|
|
1019
|
+
if (q.inb) {
|
|
1020
|
+
const int k = __popc(m0) + __popc(m1 & below);
|
|
1021
|
+
q.xb[0] = Jc[k]; q.xb[1] = Jc[KD + k]; q.xb[2] = Jc[2 * KD + k];
|
|
1022
|
+
}
|
|
1023
|
+
if (q.inc) {
|
|
1024
|
+
const int k = __popc(m0) + __popc(m1) + __popc(m2 & below);
|
|
1025
|
+
q.xc[0] = Jc[k]; q.xc[1] = Jc[KD + k]; q.xc[2] = Jc[2 * KD + k];
|
|
1026
|
+
}
|
|
1027
|
+
return q;
|
|
1028
|
+
};
|
|
1029
|
+
if (ncon > 0) {
|
|
1030
|
+
Fetch cur = fetch(0);
|
|
1031
|
+
for (int c = 0; c < ncon; ++c) {
|
|
1032
|
+
Fetch nxt{};
|
|
1033
|
+
if (c + 1 < ncon) nxt = fetch(c + 1);
|
|
1034
|
+
if (cur.ina) accA += cur.c0 * cur.xa[0] + cur.c1 * cur.xa[1] + cur.c2 * cur.xa[2];
|
|
1035
|
+
if (cur.inb) accB += cur.c0 * cur.xb[0] + cur.c1 * cur.xb[1] + cur.c2 * cur.xb[2];
|
|
1036
|
+
if (cur.inc) accC += cur.c0 * cur.xc[0] + cur.c1 * cur.xc[1] + cur.c2 * cur.xc[2];
|
|
1037
|
+
cur = nxt;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
out[dA] = accA;
|
|
1041
|
+
if (hasB) out[dB] = accB;
|
|
1042
|
+
if (hasC) out[dC] = accC;
|
|
1043
|
+
__syncwarp();
|
|
1044
|
+
}
|
|
1045
|
+
#else
|
|
1046
|
+
// a support slot's dof from the contact's four packed dof words (slot s may be a runtime value)
|
|
1047
|
+
__device__ __forceinline__ int slot_dof(unsigned w0, unsigned w1, unsigned w2, unsigned w3, int s) {
|
|
1048
|
+
const unsigned w = s < 4 ? w0 : (s < 8 ? w1 : (s < 12 ? w2 : w3));
|
|
1049
|
+
return static_cast<int>((w >> (8 * (s & 3))) & 255u);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
template <class T> struct ConLane { // this lane's contacts c = lane (j = 0) and lane + 32 (j = 1); nd 0 past ncon
|
|
1053
|
+
unsigned meta0, meta1, d00, d01, d02, d03, d10, d11, d12, d13;
|
|
1054
|
+
unsigned lim0, lim1; // limit rows r = lane, lane + 32: their rowmeta (0 past nlim)
|
|
1055
|
+
unsigned pr0, pr1, pr2, pr3, pr4; // this lane's support-slot pairs p = lane + 32 j: a | b << 8 (a >= b), constant per world
|
|
1056
|
+
T mu0, mu1;
|
|
1057
|
+
};
|
|
1058
|
+
__device__ __forceinline__ unsigned con_pair_word(int p) { // slot pair p = a (a + 1) / 2 + b, a >= b
|
|
1059
|
+
const int a = tri_row(p);
|
|
1060
|
+
return static_cast<unsigned>(a) | static_cast<unsigned>(p - a * (a + 1) / 2) << 8;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
template <class T, int NV, int NC, int NRH, int KD>
|
|
1064
|
+
__device__ __forceinline__ ConLane<T> con_lane(const T* rec, int ncon, int nlim, int lane) {
|
|
1065
|
+
constexpr HandLayout H = D16_L3_HAND_LAYOUT(NV, NC, NRH, KD);
|
|
1066
|
+
static_assert(NC <= 64 && KD == 16, "two contacts per lane; four dof words per contact");
|
|
1067
|
+
ConLane<T> c{};
|
|
1068
|
+
const int c0 = lane, c1 = lane + 32;
|
|
1069
|
+
c.meta0 = c0 < ncon ? tape_get_u(rec, H.conmeta + c0) : 0u;
|
|
1070
|
+
c.meta1 = c1 < ncon ? tape_get_u(rec, H.conmeta + c1) : 0u;
|
|
1071
|
+
c.mu0 = c0 < ncon ? rec[H.conmu + c0] : T(0);
|
|
1072
|
+
c.mu1 = c1 < ncon ? rec[H.conmu + c1] : T(0);
|
|
1073
|
+
const int o0 = H.condof + c0 * (KD / 4), o1 = H.condof + c1 * (KD / 4);
|
|
1074
|
+
c.d00 = c0 < ncon ? tape_get_u(rec, o0) : ~0u; c.d01 = c0 < ncon ? tape_get_u(rec, o0 + 1) : ~0u;
|
|
1075
|
+
c.d02 = c0 < ncon ? tape_get_u(rec, o0 + 2) : ~0u; c.d03 = c0 < ncon ? tape_get_u(rec, o0 + 3) : ~0u;
|
|
1076
|
+
c.d10 = c1 < ncon ? tape_get_u(rec, o1) : ~0u; c.d11 = c1 < ncon ? tape_get_u(rec, o1 + 1) : ~0u;
|
|
1077
|
+
c.d12 = c1 < ncon ? tape_get_u(rec, o1 + 2) : ~0u; c.d13 = c1 < ncon ? tape_get_u(rec, o1 + 3) : ~0u;
|
|
1078
|
+
c.lim0 = lane < nlim ? tape_get_u(rec, H.rowmeta + lane) : 0u;
|
|
1079
|
+
c.lim1 = lane + 32 < nlim ? tape_get_u(rec, H.rowmeta + lane + 32) : 0u;
|
|
1080
|
+
c.pr0 = con_pair_word(lane); c.pr1 = con_pair_word(lane + 32); c.pr2 = con_pair_word(lane + 64);
|
|
1081
|
+
c.pr3 = con_pair_word(lane + 96); c.pr4 = con_pair_word(lane + 128);
|
|
1082
|
+
return c;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
// one contact's J v on its lane: d_n, d_t1, d_t2 over its support, then its rows d_n + s mu d_t; a strict-order check
|
|
1086
|
+
template <class T, int NV, int KD>
|
|
1087
|
+
__device__ __forceinline__ bool contact_jv(const T* Jc, unsigned meta, T mu, unsigned w0, unsigned w1, unsigned w2,
|
|
1088
|
+
unsigned w3, const T* v, const T* sub, T* out) {
|
|
1089
|
+
T j[3 * KD];
|
|
1090
|
+
#pragma unroll
|
|
1091
|
+
for (int e = 0; e < 3 * KD; e += 4) chol::load4(Jc + e, j + e);
|
|
1092
|
+
const int nd = hand_con_nd(meta), row0 = hand_con_row0(meta);
|
|
1093
|
+
T d0 = T(0), d1 = T(0), d2 = T(0);
|
|
1094
|
+
int prev = -1;
|
|
1095
|
+
bool bad = false;
|
|
1096
|
+
#pragma unroll
|
|
1097
|
+
for (int sl = 0; sl < KD; ++sl) {
|
|
1098
|
+
if (sl < nd) {
|
|
1099
|
+
const int dof = slot_dof(w0, w1, w2, w3, sl);
|
|
1100
|
+
bad |= dof <= prev || dof >= NV;
|
|
1101
|
+
prev = dof;
|
|
1102
|
+
const T x = v[dof < NV ? dof : 0];
|
|
1103
|
+
d0 += j[sl] * x; d1 += j[KD + sl] * x; d2 += j[2 * KD + sl] * x;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
if (hand_con_condim(meta) == 1) {
|
|
1107
|
+
out[row0] = sub ? d0 - sub[row0] : d0;
|
|
1108
|
+
} else {
|
|
1109
|
+
#pragma unroll
|
|
1110
|
+
for (int k = 0; k < 4; ++k) {
|
|
1111
|
+
const T val = d0 + (k % 2 == 0 ? mu : -mu) * (k < 2 ? d1 : d2);
|
|
1112
|
+
out[row0 + k] = sub ? val - sub[row0 + k] : val;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
return bad;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
// out[r] = J_r v (- sub[r]); returns kFlagHandOrder when some contact's slots are not strictly ascending dofs
|
|
1119
|
+
template <class T, int NV, int NC, int NRH, int KD>
|
|
1120
|
+
__device__ __noinline__ int hand_jv(const T* rec, int ncon, int nlim, ConLane<T> cl, const T* v, const T* sub, T* out,
|
|
1121
|
+
int lane) {
|
|
1122
|
+
constexpr HandLayout H = D16_L3_HAND_LAYOUT(NV, NC, NRH, KD);
|
|
1123
|
+
#pragma unroll
|
|
1124
|
+
for (int j = 0; j < 2; ++j) { // limit rows r = lane, lane + 32: their meta in registers
|
|
1125
|
+
const int r = lane + 32 * j;
|
|
1126
|
+
if (r < nlim) {
|
|
1127
|
+
const uint32_t m = j ? cl.lim1 : cl.lim0;
|
|
1128
|
+
const T x = v[hand_row_index(m)];
|
|
1129
|
+
const T val = hand_row_neg(m) ? -x : x;
|
|
1130
|
+
out[r] = sub ? val - sub[r] : val;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
bool bad = false;
|
|
1134
|
+
if (lane < ncon)
|
|
1135
|
+
bad |= contact_jv<T, NV, KD>(rec + H.conJ + lane * 3 * KD, cl.meta0, cl.mu0, cl.d00, cl.d01, cl.d02, cl.d03, v, sub, out);
|
|
1136
|
+
if (lane + 32 < ncon)
|
|
1137
|
+
bad |= contact_jv<T, NV, KD>(rec + H.conJ + (lane + 32) * 3 * KD, cl.meta1, cl.mu1, cl.d10, cl.d11, cl.d12, cl.d13, v,
|
|
1138
|
+
sub, out);
|
|
1139
|
+
const bool any_bad = __any_sync(kFull, bad);
|
|
1140
|
+
__syncwarp();
|
|
1141
|
+
return any_bad ? kFlagHandOrder : 0;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// a contact's frame forces (sum f, mu (f0 - f1), mu (f2 - f3); condim 1: f0) and support mask, on its lane
|
|
1145
|
+
template <class T, int NV, int KD>
|
|
1146
|
+
__device__ __forceinline__ void contact_g(unsigned meta, T mu, unsigned w0, unsigned w1, unsigned w2, unsigned w3,
|
|
1147
|
+
const T* f, T& g0, T& g1, T& g2, unsigned& lo, unsigned& hi) {
|
|
1148
|
+
const int nd = hand_con_nd(meta), row0 = hand_con_row0(meta);
|
|
1149
|
+
g0 = g1 = g2 = T(0); lo = hi = 0u;
|
|
1150
|
+
if (nd == 0) return;
|
|
1151
|
+
if (hand_con_condim(meta) == 1) {
|
|
1152
|
+
g0 = f[row0];
|
|
1153
|
+
} else {
|
|
1154
|
+
const T f0 = f[row0], f1 = f[row0 + 1], f2 = f[row0 + 2], f3 = f[row0 + 3];
|
|
1155
|
+
g0 = f0 + f1 + f2 + f3; g1 = mu * (f0 - f1); g2 = mu * (f2 - f3);
|
|
1156
|
+
}
|
|
1157
|
+
#pragma unroll
|
|
1158
|
+
for (int sl = 0; sl < KD; ++sl)
|
|
1159
|
+
if (sl < nd) {
|
|
1160
|
+
const int dof = slot_dof(w0, w1, w2, w3, sl);
|
|
1161
|
+
if (dof < 32) lo |= 1u << dof; else if (dof < NV) hi |= 1u << (dof - 32);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
// out = J' f over the rows with f != 0: a lane per dof (rows 32.. on lanes 0..); the limits in row order, then the contacts in
|
|
1166
|
+
// contact order, each (sum f) Jn + mu (f0 - f1) Jt1 + mu (f2 - f3) Jt2 on its support; the next contact's loads in flight
|
|
1167
|
+
template <class T, int NV, int NC, int NRH, int KD>
|
|
1168
|
+
__device__ __noinline__ void hand_jtf(const T* rec, int ncon, int nlim, ConLane<T> cl, const T* f, T* out, int lane) {
|
|
1169
|
+
constexpr HandLayout H = D16_L3_HAND_LAYOUT(NV, NC, NRH, KD);
|
|
1170
|
+
T ga0, ga1, ga2, gb0, gb1, gb2;
|
|
1171
|
+
unsigned la, ha, lb, hb;
|
|
1172
|
+
contact_g<T, NV, KD>(cl.meta0, cl.mu0, cl.d00, cl.d01, cl.d02, cl.d03, f, ga0, ga1, ga2, la, ha);
|
|
1173
|
+
contact_g<T, NV, KD>(cl.meta1, cl.mu1, cl.d10, cl.d11, cl.d12, cl.d13, f, gb0, gb1, gb2, lb, hb);
|
|
1174
|
+
const int dA = lane, dB = lane + 32;
|
|
1175
|
+
const bool hasB = dB < NV;
|
|
1176
|
+
T accA = T(0), accB = T(0);
|
|
1177
|
+
for (int r = 0; r < nlim; ++r) { // limit rows: J = +-e_dof (their meta from lane r's registers)
|
|
1178
|
+
const uint32_t m = __shfl_sync(kFull, r < 32 ? cl.lim0 : cl.lim1, r & 31);
|
|
1179
|
+
const T fr = f[r];
|
|
1180
|
+
if (fr == T(0)) continue; // uniform
|
|
1181
|
+
const int dof = hand_row_index(m);
|
|
1182
|
+
const T val = hand_row_neg(m) ? -fr : fr;
|
|
1183
|
+
if (dof == dA) accA += val;
|
|
1184
|
+
if (hasB && dof == dB) accB += val;
|
|
1185
|
+
}
|
|
1186
|
+
const unsigned below = (1u << lane) - 1u;
|
|
1187
|
+
// contact c's broadcast and this lane's loads (Jn, Jt1, Jt2 at its slot), fetched one contact ahead
|
|
1188
|
+
struct Fetch { T c0, c1, c2, xa[3], xb[3]; bool ina, inb; };
|
|
1189
|
+
auto fetch = [&](int c) {
|
|
1190
|
+
Fetch q{};
|
|
1191
|
+
const bool second = c >= 32; // uniform
|
|
1192
|
+
const int src = c & 31;
|
|
1193
|
+
q.c0 = __shfl_sync(kFull, second ? gb0 : ga0, src);
|
|
1194
|
+
q.c1 = __shfl_sync(kFull, second ? gb1 : ga1, src);
|
|
1195
|
+
q.c2 = __shfl_sync(kFull, second ? gb2 : ga2, src);
|
|
1196
|
+
const unsigned lo = __shfl_sync(kFull, second ? lb : la, src), hi = __shfl_sync(kFull, second ? hb : ha, src);
|
|
1197
|
+
q.ina = q.c0 != T(0) && ((lo >> lane) & 1u);
|
|
1198
|
+
q.inb = q.c0 != T(0) && hasB && ((hi >> lane) & 1u);
|
|
1199
|
+
const T* Jc = rec + H.conJ + c * 3 * KD;
|
|
1200
|
+
if (q.ina) {
|
|
1201
|
+
const int k = __popc(lo & below);
|
|
1202
|
+
q.xa[0] = Jc[k]; q.xa[1] = Jc[KD + k]; q.xa[2] = Jc[2 * KD + k];
|
|
1203
|
+
}
|
|
1204
|
+
if (q.inb) {
|
|
1205
|
+
const int k = __popc(lo) + __popc(hi & below);
|
|
1206
|
+
q.xb[0] = Jc[k]; q.xb[1] = Jc[KD + k]; q.xb[2] = Jc[2 * KD + k];
|
|
1207
|
+
}
|
|
1208
|
+
return q;
|
|
1209
|
+
};
|
|
1210
|
+
if (ncon > 0) {
|
|
1211
|
+
Fetch cur = fetch(0);
|
|
1212
|
+
for (int c = 0; c < ncon; ++c) {
|
|
1213
|
+
Fetch nxt{};
|
|
1214
|
+
if (c + 1 < ncon) nxt = fetch(c + 1);
|
|
1215
|
+
if (cur.ina) accA += cur.c0 * cur.xa[0] + cur.c1 * cur.xa[1] + cur.c2 * cur.xa[2];
|
|
1216
|
+
if (cur.inb) accB += cur.c0 * cur.xb[0] + cur.c1 * cur.xb[1] + cur.c2 * cur.xb[2];
|
|
1217
|
+
cur = nxt;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
#if defined(D16_NV_LE32)
|
|
1221
|
+
if (dA < NV) out[dA] = accA; // a lane >= NV owns no dof
|
|
1222
|
+
#else
|
|
1223
|
+
out[dA] = accA;
|
|
1224
|
+
#endif
|
|
1225
|
+
if (hasB) out[dB] = accB;
|
|
1226
|
+
__syncwarp();
|
|
1227
|
+
}
|
|
1228
|
+
#endif // D16_NV_GT64
|
|
1229
|
+
|
|
1230
|
+
// a contact's Hessian coefficients C (nn, n1, 11, n2, 22) from its rows' D at their zones (s.zw), on its lane
|
|
1231
|
+
template <class T, int NV, int NR>
|
|
1232
|
+
__device__ __forceinline__ void contact_C(const Shared<T, NV, NR>& s, unsigned meta, T mu, T* C) {
|
|
1233
|
+
auto dq = [&](int r) { return ((s.zw[r >> 5] >> (r & 31)) & 1u) ? s.D[r] : T(0); };
|
|
1234
|
+
C[0] = C[1] = C[2] = C[3] = C[4] = T(0);
|
|
1235
|
+
if (hand_con_nd(meta) == 0) return;
|
|
1236
|
+
const int row0 = hand_con_row0(meta);
|
|
1237
|
+
if (hand_con_condim(meta) == 1) { C[0] = dq(row0); return; }
|
|
1238
|
+
const T d0 = dq(row0), d1 = dq(row0 + 1), d2 = dq(row0 + 2), d3 = dq(row0 + 3);
|
|
1239
|
+
C[0] = d0 + d1 + d2 + d3;
|
|
1240
|
+
C[1] = mu * (d0 - d1); C[2] = mu * mu * (d0 + d1); C[3] = mu * (d2 - d3); C[4] = mu * mu * (d2 + d3);
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
// H = M + J' D J at the zones s.zw into s.L, then factored: the limits on the diagonal (row order), each contact with a
|
|
1244
|
+
// QUADRATIC row as J_c' C J_c on its support pairs (a lane per slot pair a >= b), in contact order, then M. The contact's J
|
|
1245
|
+
// comes from a shared double buffer in s.Jv (free here: J'f has consumed the forces), the next active contact's loads issued
|
|
1246
|
+
// before the current one's arithmetic.
|
|
1247
|
+
template <class T, int NV, int NR, int NC, int NRH, int KD>
|
|
1248
|
+
__device__ __noinline__ int hand_assemble_factor(Shared<T, NV, NR>& s, const T* rec, int ncon, int nlim, ConLane<T> cl,
|
|
1249
|
+
int lane) {
|
|
1250
|
+
constexpr HandLayout H = D16_L3_HAND_LAYOUT(NV, NC, NRH, KD);
|
|
1251
|
+
#if defined(D16_NV_GT64) // B3c: M's words in the split storage, copied as they are (L2 wrote them in kernel P's layout)
|
|
1252
|
+
constexpr int NTRI = ::d16::split::WORDS, NPAIR = KD * (KD + 1) / 2, PJ = (NPAIR + 31) / 32, NJ = 3 * KD;
|
|
1253
|
+
#else
|
|
1254
|
+
constexpr int NTRI = NV * (NV + 1) / 2, NPAIR = KD * (KD + 1) / 2, PJ = (NPAIR + 31) / 32, NJ = 3 * KD;
|
|
1255
|
+
#endif
|
|
1256
|
+
static_assert(2 * NJ <= NR, "the double buffer fits s.Jv");
|
|
1257
|
+
L3_SUB_START;
|
|
1258
|
+
for (int e = lane; e < NTRI; e += 32) s.L[e] = __ldg(rec + H.M + e); // M first (MuJoCo adds it last: roundoff only)
|
|
1259
|
+
__syncwarp();
|
|
1260
|
+
L3_SUB(0);
|
|
1261
|
+
L3_SUB_COUNT(8, 1);
|
|
1262
|
+
L3_SUB_COUNT(10, nlim);
|
|
1263
|
+
for (int r = 0; r < nlim; ++r) { // the limit rows on the diagonal, in row order (their meta from lane r's registers)
|
|
1264
|
+
#if defined(D16_NV_GT64)
|
|
1265
|
+
const uint32_t m = __shfl_sync(kFull, con_lim(cl, r >> 5), r & 31);
|
|
1266
|
+
if (lane == 0 && ((s.zw[r >> 5] >> (r & 31)) & 1u)) s.L[L3_TRI(hand_row_index(m), hand_row_index(m))] += s.D[r];
|
|
1267
|
+
#else
|
|
1268
|
+
const uint32_t m = __shfl_sync(kFull, r < 32 ? cl.lim0 : cl.lim1, r & 31);
|
|
1269
|
+
if (lane == 0 && ((s.zw[r >> 5] >> (r & 31)) & 1u)) s.L[L3_TRI(hand_row_index(m), hand_row_index(m))] += s.D[r];
|
|
1270
|
+
#endif
|
|
1271
|
+
}
|
|
1272
|
+
__syncwarp();
|
|
1273
|
+
L3_SUB(1);
|
|
1274
|
+
T Ca[5], Cb[5]; // this lane's contacts' coefficients, all contacts at once
|
|
1275
|
+
contact_C<T, NV, NR>(s, cl.meta0, cl.mu0, Ca);
|
|
1276
|
+
contact_C<T, NV, NR>(s, cl.meta1, cl.mu1, Cb);
|
|
1277
|
+
const unsigned act0 = __ballot_sync(kFull, Ca[0] != T(0)), act1 = __ballot_sync(kFull, Cb[0] != T(0));
|
|
1278
|
+
__syncwarp();
|
|
1279
|
+
L3_SUB(2);
|
|
1280
|
+
L3_SUB_COUNT(9, __popc(act0) + __popc(act1));
|
|
1281
|
+
#if defined(D16_NV_GT64)
|
|
1282
|
+
static_assert(PJ == kPairJ, "seven slot pairs per lane (KD 20)");
|
|
1283
|
+
const unsigned prw[PJ] = {cl.pr0, cl.pr1, cl.pr2, cl.pr3, cl.pr4, cl.pr5, cl.pr6}; // this lane's slot pairs, once per world
|
|
1284
|
+
#else
|
|
1285
|
+
static_assert(PJ == 5, "five slot pairs per lane (KD 16)");
|
|
1286
|
+
const unsigned prw[PJ] = {cl.pr0, cl.pr1, cl.pr2, cl.pr3, cl.pr4}; // this lane's slot pairs, computed once per world
|
|
1287
|
+
#endif
|
|
1288
|
+
int pa[PJ], pb[PJ];
|
|
1289
|
+
#pragma unroll
|
|
1290
|
+
for (int jj = 0; jj < PJ; ++jj) { pa[jj] = static_cast<int>(prw[jj] & 255u); pb[jj] = static_cast<int>(prw[jj] >> 8); }
|
|
1291
|
+
L3_SUB(3);
|
|
1292
|
+
auto next_active = [&](int c) { // the first contact > c with a QUADRATIC row (uniform), -1: none
|
|
1293
|
+
for (int t = (c + 1) >> 5; t < 2; ++t) {
|
|
1294
|
+
unsigned m = t == 0 ? act0 : act1;
|
|
1295
|
+
const int b0 = c + 1 - 32 * t;
|
|
1296
|
+
if (b0 > 0) m &= b0 >= 32 ? 0u : ~0u << b0;
|
|
1297
|
+
if (m) return 32 * t + __ffs(m) - 1;
|
|
1298
|
+
}
|
|
1299
|
+
return -1;
|
|
1300
|
+
};
|
|
1301
|
+
const bool loader = lane < NJ / 4; // lanes 0..11 move the contact's 48 entries, four each
|
|
1302
|
+
T pend[4];
|
|
1303
|
+
int c = next_active(-1), buf = 0;
|
|
1304
|
+
if (c >= 0) {
|
|
1305
|
+
if (loader) {
|
|
1306
|
+
chol::load4(rec + H.conJ + c * NJ + 4 * lane, pend);
|
|
1307
|
+
#pragma unroll
|
|
1308
|
+
for (int m = 0; m < 4; ++m) s.Jv[4 * lane + m] = pend[m];
|
|
1309
|
+
}
|
|
1310
|
+
__syncwarp();
|
|
1311
|
+
}
|
|
1312
|
+
L3_SUB(4);
|
|
1313
|
+
while (c >= 0) {
|
|
1314
|
+
const int cn = next_active(c);
|
|
1315
|
+
if (cn >= 0 && loader) chol::load4(rec + H.conJ + cn * NJ + 4 * lane, pend); // in flight during c's arithmetic
|
|
1316
|
+
const bool second = c >= 32;
|
|
1317
|
+
const int src = c & 31;
|
|
1318
|
+
T C[5];
|
|
1319
|
+
#pragma unroll
|
|
1320
|
+
for (int k = 0; k < 5; ++k) C[k] = __shfl_sync(kFull, second ? Cb[k] : Ca[k], src);
|
|
1321
|
+
const unsigned meta = __shfl_sync(kFull, second ? cl.meta1 : cl.meta0, src);
|
|
1322
|
+
#if defined(D16_NV_GT64)
|
|
1323
|
+
const unsigned w0 = __shfl_sync(kFull, second ? cl.d10 : cl.d00, src), w1 = __shfl_sync(kFull, second ? cl.d11 : cl.d01, src),
|
|
1324
|
+
w2 = __shfl_sync(kFull, second ? cl.d12 : cl.d02, src), w3 = __shfl_sync(kFull, second ? cl.d13 : cl.d03, src),
|
|
1325
|
+
w4 = __shfl_sync(kFull, second ? cl.d14 : cl.d04, src);
|
|
1326
|
+
#else
|
|
1327
|
+
const unsigned w0 = __shfl_sync(kFull, second ? cl.d10 : cl.d00, src), w1 = __shfl_sync(kFull, second ? cl.d11 : cl.d01, src),
|
|
1328
|
+
w2 = __shfl_sync(kFull, second ? cl.d12 : cl.d02, src), w3 = __shfl_sync(kFull, second ? cl.d13 : cl.d03, src);
|
|
1329
|
+
#endif
|
|
1330
|
+
const int nd = hand_con_nd(meta);
|
|
1331
|
+
const T* Jb = s.Jv + buf * NJ;
|
|
1332
|
+
#pragma unroll
|
|
1333
|
+
for (int jj = 0; jj < PJ; ++jj) {
|
|
1334
|
+
const int a = pa[jj], b = pb[jj];
|
|
1335
|
+
if (a >= nd) continue;
|
|
1336
|
+
const T na = Jb[a], ta = Jb[KD + a], ua = Jb[2 * KD + a], nb = Jb[b], tb = Jb[KD + b], ub = Jb[2 * KD + b];
|
|
1337
|
+
const T gb0 = C[0] * nb + C[1] * tb + C[3] * ub, gb1 = C[1] * nb + C[2] * tb, gb2 = C[3] * nb + C[4] * ub;
|
|
1338
|
+
#if defined(D16_NV_GT64)
|
|
1339
|
+
s.L[L3_TRI(slot_dof(w0, w1, w2, w3, w4, a), slot_dof(w0, w1, w2, w3, w4, b))] += na * gb0 + ta * gb1 + ua * gb2;
|
|
1340
|
+
#else
|
|
1341
|
+
s.L[L3_TRI(slot_dof(w0, w1, w2, w3, a), slot_dof(w0, w1, w2, w3, b))] += na * gb0 + ta * gb1 + ua * gb2;
|
|
1342
|
+
#endif
|
|
1343
|
+
}
|
|
1344
|
+
__syncwarp(); // the next contact may share entries of L
|
|
1345
|
+
if (cn >= 0) {
|
|
1346
|
+
if (loader) {
|
|
1347
|
+
#pragma unroll
|
|
1348
|
+
for (int m = 0; m < 4; ++m) s.Jv[(buf ^ 1) * NJ + 4 * lane + m] = pend[m];
|
|
1349
|
+
}
|
|
1350
|
+
__syncwarp();
|
|
1351
|
+
}
|
|
1352
|
+
c = cn;
|
|
1353
|
+
buf ^= 1;
|
|
1354
|
+
}
|
|
1355
|
+
L3_SUB(5);
|
|
1356
|
+
L3_SUB(6);
|
|
1357
|
+
const int nlow = L3_FACTOR_M(s, lane); // rhs s.Mgrad (v3g)
|
|
1358
|
+
L3_SUB(7);
|
|
1359
|
+
return nlow;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
// v3m: a packed factor (NV x NV lower, TRI order) into a tape block of nwords words: the entries by 16-byte vectors, the last
|
|
1363
|
+
// ntri % 4 and the block's padding (zero words) by scalars. This is tape.h's tape_pack_range for a packed factor (ld 0),
|
|
1364
|
+
// word for word (T1 checks it bitwise against the CPU writer); the block and s.L are 16-byte aligned
|
|
1365
|
+
template <class T, int NV>
|
|
1366
|
+
__device__ __forceinline__ void tape_copy_factor(T* dst, const T* L, int nwords, int lane) {
|
|
1367
|
+
#if defined(D16_NV_GT64) // B3c: the factor is the split storage's words, copied in their own order
|
|
1368
|
+
constexpr int NTRI = ::d16::split::WORDS, NG = NTRI / 4;
|
|
1369
|
+
#else
|
|
1370
|
+
constexpr int NTRI = NV * (NV + 1) / 2, NG = NTRI / 4;
|
|
1371
|
+
#endif
|
|
1372
|
+
#pragma unroll 2
|
|
1373
|
+
for (int g = lane; g < NG; g += 32) {
|
|
1374
|
+
T v[4];
|
|
1375
|
+
chol::load4(L + 4 * g, v);
|
|
1376
|
+
#if defined(JS_TAPE_STREAM) // the 14x build: evict-first stores (tape.h tape_st)
|
|
1377
|
+
for (int m = 0; m < 4; ++m) js::soft::tape_st(dst + 4 * g + m, v[m]);
|
|
1378
|
+
#else
|
|
1379
|
+
chol::store4(dst + 4 * g, v);
|
|
1380
|
+
#endif
|
|
1381
|
+
}
|
|
1382
|
+
for (int k = 4 * NG + lane; k < nwords; k += 32) js::soft::tape_st(dst + k, k < NTRI ? L[k] : T(0));
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
template <class T, int NV, int NR, int NC, int NRH, int KD, class Opt = ImplicitFastOpts> struct HandRows {
|
|
1386
|
+
static constexpr int kTapeNq = Opt::kNq ? Opt::kNq : NV + 1, kTapeNp = Opt::kNpose ? Opt::kNpose : kTapeNpose;
|
|
1387
|
+
static constexpr int kTapeNm = OptNmus<Opt>::value;
|
|
1388
|
+
static constexpr bool kTapeLQ = !Opt::kEuler;
|
|
1389
|
+
static constexpr bool kTapeLimMask = OptLimitMask<Opt>::value;
|
|
1390
|
+
#if defined(D16_NV_GT64)
|
|
1391
|
+
static constexpr int kTapeNlim = OptNlim<Opt>::value;
|
|
1392
|
+
static_assert(kTapeNlim >= 0, "a phase B body's options name its limit count (kNlim): the record's clamp words hold the mask");
|
|
1393
|
+
#endif
|
|
1394
|
+
const T* rec;
|
|
1395
|
+
int nefc, ncon, nlim;
|
|
1396
|
+
ConLane<T> cl;
|
|
1397
|
+
__device__ __forceinline__ int jv(Shared<T, NV, NR>&, const T* v, const T* sub, T* out, int lane) const {
|
|
1398
|
+
return hand_jv<T, NV, NC, NRH, KD>(rec, ncon, nlim, cl, v, sub, out, lane);
|
|
1399
|
+
}
|
|
1400
|
+
__device__ __forceinline__ void jtf(Shared<T, NV, NR>&, const T* f, T* out, int lane) const {
|
|
1401
|
+
hand_jtf<T, NV, NC, NRH, KD>(rec, ncon, nlim, cl, f, out, lane);
|
|
1402
|
+
}
|
|
1403
|
+
__device__ __forceinline__ int assemble_factor(Shared<T, NV, NR>& s, int lane) const {
|
|
1404
|
+
return hand_assemble_factor<T, NV, NR, NC, NRH, KD>(s, rec, ncon, nlim, cl, lane);
|
|
1405
|
+
}
|
|
1406
|
+
// the tape record (tape.h, tape_pack_range: one writer per word): [LH, LQ) at the solve's end, then [0, LH) and [LQ, POSE).
|
|
1407
|
+
// The layout is a local constexpr in each method (a static member passed by reference would need a device definition)
|
|
1408
|
+
__device__ __forceinline__ void tape_LH(const Args<T>& A, Shared<T, NV, NR>& s, int w, int lane) const {
|
|
1409
|
+
constexpr TapeLayout TL = D16_L3_TAPE_LAYOUT(kTapeNq, NV, NC, NRH, kTapeNp, kTapeNm, kTapeLQ);
|
|
1410
|
+
if (!A.tape) return;
|
|
1411
|
+
// L_H's block ends at L_Q, or without L_Q at the next block present (its padding words are written 0, as the packer's)
|
|
1412
|
+
constexpr int kLHEnd = TL.LQ >= 0 ? TL.LQ : (TL.npose > 0 ? TL.pose : (TL.nmus > 0 ? TL.mus : TL.words));
|
|
1413
|
+
#if defined(D16_NV_GT64) // B3c: the block holds the split storage's words
|
|
1414
|
+
static_assert(TL.LH % 4 == 0 && kLHEnd % 4 == 0 && kLHEnd - TL.LH >= ::d16::split::WORDS, "16-byte factor blocks");
|
|
1415
|
+
#else
|
|
1416
|
+
static_assert(TL.LH % 4 == 0 && kLHEnd % 4 == 0 && kLHEnd - TL.LH >= NV * (NV + 1) / 2, "16-byte factor blocks");
|
|
1417
|
+
#endif
|
|
1418
|
+
tape_copy_factor<T, NV>(A.tape + static_cast<size_t>(w) * A.tape_stride + TL.LH, s.L, kLHEnd - TL.LH, lane);
|
|
1419
|
+
__syncwarp();
|
|
1420
|
+
}
|
|
1421
|
+
template <bool kLQ = true> // false: the Euler form (no L_Q block written)
|
|
1422
|
+
__device__ __forceinline__ void tape_rest(const Args<T>& A, Shared<T, NV, NR>& s, int w, int lane, int niter,
|
|
1423
|
+
int flags) const {
|
|
1424
|
+
constexpr TapeLayout TL = D16_L3_TAPE_LAYOUT(kTapeNq, NV, NC, NRH, kTapeNp, kTapeNm, kTapeLQ);
|
|
1425
|
+
if (!A.tape) return;
|
|
1426
|
+
constexpr HandLayout H = D16_L3_HAND_LAYOUT(NV, NC, NRH, KD);
|
|
1427
|
+
const T mn = rec[H.min_nu]; // the hand's min_nu (31232470: L2's warm min over non-plane contacts, +inf without one)
|
|
1428
|
+
TapeIn<T> in;
|
|
1429
|
+
in.ncon = ncon; in.nefc = nefc; in.nlim = nlim; in.niter = niter;
|
|
1430
|
+
in.flags = tape_flags((flags & kFlagOverflow) != 0, (flags & kFlagCap) != 0, (flags & kFlagWarm) != 0,
|
|
1431
|
+
(flags & kFlagStalled) != 0, mn);
|
|
1432
|
+
in.min_nu = mn;
|
|
1433
|
+
in.clamp_bits = s.clw; in.zone_bits = s.zw; in.con_meta = rec + H.conmeta;
|
|
1434
|
+
in.q = A.qpos + static_cast<size_t>(w) * A.nq; in.v = A.qvel + static_cast<size_t>(w) * NV;
|
|
1435
|
+
in.a_star = s.qacc; in.a_adv = s.Mgrad; in.L_Q = s.L;
|
|
1436
|
+
T* out = A.tape + static_cast<size_t>(w) * A.tape_stride;
|
|
1437
|
+
if (!kTapeLimMask) tape_pack_range(out, TL, in, 0, TL.LH, lane, 32);
|
|
1438
|
+
else { // the clamp words are k_pre14's active-limit mask (constant guard: the G1's path is the line above)
|
|
1439
|
+
tape_pack_range(out, TL, in, 0, TL.clamp, lane, 32);
|
|
1440
|
+
tape_pack_range(out, TL, in, TL.clamp + TL.n_clamp, TL.LH, lane, 32);
|
|
1441
|
+
}
|
|
1442
|
+
if constexpr (kLQ) tape_copy_factor<T, NV>(out + TL.LQ, s.L, (TL.npose > 0 ? TL.pose : TL.words) - TL.LQ, lane); // L_Q (v3m)
|
|
1443
|
+
__syncwarp();
|
|
1444
|
+
}
|
|
1445
|
+
__device__ __forceinline__ void tape_overflow(const Args<T>& A, int w, int lane) const { // the record is not valid
|
|
1446
|
+
constexpr TapeLayout TL = D16_L3_TAPE_LAYOUT(kTapeNq, NV, NC, NRH, kTapeNp, kTapeNm, kTapeLQ);
|
|
1447
|
+
if (!A.tape || lane != 0) return;
|
|
1448
|
+
T* out = A.tape + static_cast<size_t>(w) * A.tape_stride;
|
|
1449
|
+
tape_put_u(out, TL.hdr, static_cast<uint32_t>(ncon > 255 ? 255 : ncon) | static_cast<uint32_t>(nefc > 255 ? 255 : nefc) << 8);
|
|
1450
|
+
tape_put_u(out, TL.flags, kTapeOverflow | (TL.npose > 0 ? kTapePose : 0u) | (TL.nmus > 0 ? kTapeMus : 0u));
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
|
|
1454
|
+
// ---- entry points: one world from the dense arrays, or from its hand record (k_post) ----
|
|
1455
|
+
template <class T, int NV, int NR> __device__ void world_dense(const Args<T>& A, Shared<T, NV, NR>& s, int w, int lane) {
|
|
1456
|
+
constexpr int NTRI = NV * (NV + 1) / 2;
|
|
1457
|
+
const WorldIn<T> in{A.M + w * NTRI, A.qsm + w * NV, A.qa0 + w * NV, A.D + w * NR, A.aref + w * NR, A.clamp[2 * w],
|
|
1458
|
+
A.clamp[2 * w + 1], A.nefc[w], false};
|
|
1459
|
+
const DenseRows<T, NV, NR> R{A.J + static_cast<size_t>(w) * NR * NV, in.M, in.nefc};
|
|
1460
|
+
solve<T, NV, NR>(A, s, in, R, w, lane);
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
// k_post: NRS rows in shared memory (the fast path 128; the big path NRH), the hand at (NC, NRH, KD). A world whose nefc
|
|
1464
|
+
// exceeds NRS is flagged overflow (the dispatcher sends those to the NRS = NRH instantiation; counted, never silent)
|
|
1465
|
+
template <class T, int NV, int NRS, int NC, int NRH, int KD, class Opt = ImplicitFastOpts>
|
|
1466
|
+
__device__ void world_hand(const Args<T>& A, Shared<T, NV, NRS>& s, int w, int lane) {
|
|
1467
|
+
constexpr HandLayout H = D16_L3_HAND_LAYOUT(NV, NC, NRH, KD);
|
|
1468
|
+
static_assert(NRS <= (NRH + 31) / 32 * 32 && NC <= 64, "rows in shared at most the hand's, in the solve's 32-row words");
|
|
1469
|
+
const T* rec = A.hand + static_cast<size_t>(w) * H.words;
|
|
1470
|
+
const int ncon = static_cast<int>(tape_get_u(rec, H.counts)), nefc = static_cast<int>(tape_get_u(rec, H.counts + 1)),
|
|
1471
|
+
nlim = static_cast<int>(tape_get_u(rec, H.counts + 2));
|
|
1472
|
+
#if defined(D16_NV_GT64)
|
|
1473
|
+
const bool ovf = tape_get_u(rec, H.counts + 3) != 0u || ncon > NC || nefc > NRS || (Opt::kLimGuard && nlim > 32 * kLimJ);
|
|
1474
|
+
#else
|
|
1475
|
+
const bool ovf = tape_get_u(rec, H.counts + 3) != 0u || ncon > NC || nefc > NRS || (Opt::kLimGuard && nlim > 64);
|
|
1476
|
+
#endif
|
|
1477
|
+
const WorldIn<T> in{rec + H.M, rec + H.qfrc, rec + H.qacc, rec + H.efcD, rec + H.aref, tape_get_u(rec, H.clamp),
|
|
1478
|
+
tape_get_u(rec, H.clamp + 1), nefc, ovf};
|
|
1479
|
+
const HandRows<T, NV, NRS, NC, NRH, KD, Opt> R{rec, nefc, ncon, nlim, con_lane<T, NV, NC, NRH, KD>(rec, ncon, nlim, lane)};
|
|
1480
|
+
solve<T, NV, NRS, HandRows<T, NV, NRS, NC, NRH, KD, Opt>, Opt>(A, s, in, R, w, lane);
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
} // namespace js::soft::gpu::l3
|