Repository navigation
Transitions raycaster to warp backend - #4967
Conversation
There was a problem hiding this comment.
Ray Caster → Warp Transition Review
Solid migration from torch-based ray casting to native Warp kernels. The kernel architecture is clean — single update_ray_caster_kernel for pose+ray transforms, masked raycast_mesh_masked_kernel for the actual casts, and a fill+z-drift pair. Good use of enable_backward=False since these are inference-only paths.
A few things I'd flag:
🔴 Potential Memory Safety Issue — Offset Warp Arrays
In _initialize_impl(), the offset warp arrays are created from ephemeral .contiguous() calls:
self._offset_pos_wp = wp.from_torch(self._offset[0].contiguous(), dtype=wp.vec3f)
self._offset_quat_wp = wp.from_torch(self._offset[1].contiguous(), dtype=wp.quatf)wp.from_torch creates a zero-copy view. If self._offset[0] is already contiguous, .contiguous() returns the same tensor (safe). But if it's not contiguous, .contiguous() creates a temporary copy that's not stored anywhere — once GC'd, the warp array points to freed memory. Either store the contiguous tensor explicitly or use a warp-owned copy:
self._offset_pos_contiguous = self._offset[0].contiguous()
self._offset_pos_wp = wp.from_torch(self._offset_pos_contiguous, dtype=wp.vec3f)🟡 Breaking Public API — data.pos_w / data.ray_hits_w Now Return wp.array
The RayCasterData properties now return wp.array instead of torch.Tensor. Every downstream consumer needs wp.to_torch() wrappers. The PR updates the bundled scripts/MDP/tasks, but any external code using sensor.data.ray_hits_w as a torch tensor will break silently (warp arrays support some indexing but not all torch ops).
Consider either:
- Deprecation path: Keep returning torch tensors from the properties (using the internal
_*_torchviews) and add newpos_w_wp/ray_hits_w_wpproperties for warp access. Then deprecate the torch versions in a future release. - Documentation: If this is intentionally breaking, the changelog/migration guide should call it out explicitly.
🟡 MultiMeshRayCasterCameraData No Longer Inherits RayCasterData
The change from class MultiMeshRayCasterCameraData(CameraData, RayCasterData) to just class MultiMeshRayCasterCameraData(CameraData) means isinstance(data, RayCasterData) checks will fail for multi-mesh camera data. If anything in the codebase or user code uses that check, it'll break. Might be intentional given the divergent buffer strategies, but worth verifying.
🟡 Quaternion Convention in _get_view_transforms_wp
For XformPrimView, the code does:
poses = torch.cat([pos_w, quat_w], dim=-1).contiguous()
return wp.from_torch(poses).view(wp.transformf)wp.transformf expects (px, py, pz, qx, qy, qz, qw) — 7 floats. Isaac Sim's XformPrimView.get_world_poses() typically returns quaternions as (w, x, y, z). Make sure the ordering matches warp's expectation, or the rotations will be wrong. The PhysX view methods (get_root_transforms, get_transforms) use (x, y, z, w) convention which matches warp. This potential mismatch only affects the XformPrimView path.
Minor Items
- Extra blank line at
ray_caster.py~line 359 (in_debug_vis_callback) — cosmetic. - The
ray_cast_utils.pyimport ofobtain_world_pose_from_viewwas removed fromray_caster.pybut is still used inmulti_mesh_ray_caster.py— verify it's still importable from there. - Good that
_update_ray_infosnow takesenv_mask: wp.arrayinstead ofenv_ids— this is more GPU-friendly and avoids thenonzero()→ index gather pattern. - The kernel launch dimensions use
(self._num_envs, self.num_rays)even when only some envs need updates, but theenv_maskearly-return in the kernel handles this efficiently. For very large env counts with sparse updates, a compacted launch could save GPU cycles, but that's an optimization for later.
Overall direction is right — moving the hot path into Warp kernels will eliminate the torch↔warp round-trips and enable better GPU utilization. The memory safety issue with the offset arrays is the most pressing concern.
Replace Python-level torch wrappers with direct wp.launch calls across all four ray caster sensor classes: - RayCaster: new kernels.py with update_ray_caster_kernel, fill_vec3_inf_kernel, raycast_mesh_masked_kernel, apply_z_drift_kernel - MultiMeshRayCaster: add env_mask to raycast_dynamic_meshes_kernel (reuse instead of duplicate); mesh transform buffers (_mesh_positions_w, _mesh_orientations_w) converted from torch to wp.array2d with zero-copy torch views - RayCasterCamera: new kernels for raycast_camera_mesh_masked_kernel, compute_distance_to_image_plane_masked_kernel, and depth clipping; all buffers warp-owned with zero-copy torch views - MultiMeshRayCasterCamera: same pattern as MultiMeshRayCaster camera; uses raycast_dynamic_meshes_kernel directly with env_mask All world-frame ray buffers are warp-owned with zero-copy torch views to eliminate per-step allocations and avoid redundant host-device copies.
- Fix stale warp views after RayCasterCamera.set_intrinsic_matrices: _ray_starts_local and _ray_directions_local are now recreated from the updated torch tensors when intrinsic matrices change - Migrate MultiMeshRayCasterCamera distance_to_image_plane to warp: uses compute_distance_to_image_plane_masked_kernel and the clipping kernels, matching RayCasterCamera and making NaN handling consistent between the two camera classes; add _quat_w_wp warp-backed orientation buffer updated each step from _update_ray_infos - Eliminate per-step dummy buffer allocations in MultiMeshRayCaster: _dummy_normal_w and _dummy_face_id_w moved to _initialize_rays_impl - Use ALIGNMENT_BASE constant instead of literal 2 in RayCasterCamera; name the 1e6 upper-bound raycast distance _CAMERA_RAYCAST_MAX_DIST - Fix fill_vec3_inf_kernel docstring Args order and add missing [m] SI unit annotations to ray-start parameters in kernels.py
Kernel and code deduplication: - Unify apply_depth_clipping_max/zero_masked_kernel into a single apply_depth_clipping_masked_kernel(fill_val) — eliminates a near- identical kernel pair - Extract MultiMeshRayCaster._update_mesh_transforms() and call it from MultiMeshRayCasterCamera instead of duplicating the 25-line loop - Add RayCasterCamera._apply_depth_clipping() helper and use it in both camera classes, replacing four separate wp.launch blocks Critical behavioral fixes: - MultiMeshRayCasterCamera was passing cfg.max_distance as the kernel ray-cast limit; now uses CAMERA_RAYCAST_MAX_DIST (1e6) matching RayCasterCamera so both classes see the same hit/miss boundary - MultiMeshRayCasterCamera was using torch.clip for distance_to_camera while RayCasterCamera used the warp kernel; both now use warp kernels through _apply_depth_clipping, making NaN handling consistent Performance fixes: - RayCasterCamera offset buffers are now warp-primary with zero-copy torch views, removing per-step wp.from_torch re-wrapping - Cache all-True env_mask in raycast_dynamic_meshes by (n_envs, device) to avoid a per-call boolean tensor allocation Constants: move CAMERA_RAYCAST_MAX_DIST to kernels.py so it is shared
Move raycast_mesh_masked_kernel to utils/warp/kernels alongside the existing raycast_mesh_kernel, replacing the two near-identical sensor-specific kernels (raycast_mesh_masked_kernel and raycast_camera_mesh_masked_kernel) with a single kernel that has return_distance and return_normal flags — matching the design of the existing raycast_mesh_kernel. RayCaster passes return_distance=0, return_normal=0 with dummy (1,1) buffers. RayCasterCamera passes return_distance=1 with its existing distance and normal buffers.
|
|
||
|
|
||
| @wp.func | ||
| def quat_yaw_only( |
There was a problem hiding this comment.
@AntoineRichard this would be one of our math utils, I remember there was the idea to transition all of them to warp. What happened with that idea?
There was a problem hiding this comment.
That did not happen in the end, right now we're keeping the torch stuff for compat, there is only so much we can break in a single release x)
There was a problem hiding this comment.
could we have another file (math_warp.py) where we place those kernels? otherwise I would now have to introduce that one here and that is not the correct place IMO
There was a problem hiding this comment.
Agreed — quat_yaw_only is a math utility and doesn't belong in the ray-caster-specific kernels.py. Moving it to isaaclab/utils/warp/ (e.g. as a new math_warp.py or alongside existing warp utilities) is the right long-term home. However, moving it is out of scope for this PR since it would add a new public symbol to the utils package, potentially touching unrelated modules. I'll keep it here for now and open a follow-up to relocate it properly.
Pre-fill ray_dist_w and ray_normal_w output buffers with a sentinel value (-1.0) so that assertions checking 'flag=0 → buffer not written' are meaningful. Previously zero-initialised buffers made those checks vacuous (kernel writing 0.0 would still pass). Also: - Move _raycast_mesh_masked_kernel import to the top of the file - Add distance assertion to test_with_normal - Assert sentinel in masked-env distance check
- Change _SENTINEL from -1.0 to -2.0 (outside [-1, 1]) so it cannot equal any normalized vector component, making "not written" checks unambiguous without relying on composite-vec3 reasoning - Add ray_normal_w sentinel assertion to env_mask test (coverage gap) - Fix _make_masked_buffers docstring: remove inaccurate ray_hits_w claim - Update with_normal test docstring to reflect both return flags are set
…ests Appends two new pytest functions to test_ray_caster_camera.py: - test_frame_counter_increments_per_update: verifies the frame counter increments by exactly 1 per update() call and resets to 0 on both partial (env_ids=[0]) and full reset() calls. - test_set_intrinsic_matrices_updates_output: verifies that depth output changes after set_intrinsic_matrices() is called, catching regressions where stale warp ray buffers would silently ignore intrinsic updates.
- test_frame_counter_increments_per_update: pass force_recompute=True to camera.update() so _update_buffers_impl is called each step and _frame actually increments (lazy invocation otherwise skips it) - test_ray_caster_reset_resamples_drift: add assertion that drift values change after reset(), not just that they stay in range - test_yaw_alignment_direction_unchanged: use non-zero local offset (+1,0,0) so yaw-only rotation of start positions is observable; world mode hits x≈1.0, yaw mode hits x≈cos(45°)≈0.707, confirming modes differ
- test_frame_counter_increments_per_update: pass force_recompute=True to camera.update() so _update_buffers_impl is called each step and _frame actually increments (lazy invocation otherwise skips it) - test_ray_caster_reset_resamples_drift: add assertion that drift values change after reset(), not just that they stay in range - test_yaw_alignment_direction_unchanged: use non-zero local offset (+1,0,0) so yaw-only rotation of start positions is observable; world mode hits x≈1.0, yaw mode hits x≈cos(45°)≈0.707, confirming modes differ
a5507ff to
f6406b0
Compare
PR Review: Transitions raycaster to warp backendBranch: Overall this is a well-executed migration. Clean kernel design with Critical Issues (4)C1: Breaking API —
|
- C1: Restore original raycast_dynamic_meshes_kernel (no env_mask); add raycast_dynamic_meshes_masked_kernel with env_mask for MultiMeshRayCaster. Update call-site to use masked variant. - C3: Fix RayCasterCamera._debug_vis_callback to filter inf values and guard against zero valid points before calling visualize(). - C4: Add explicit elif/else branches to _apply_depth_clipping: "none" is a no-op, unknown values raise ValueError. - I1: Fix "z-component" → "x-component" in compute_distance_to_image_plane_masked_kernel docstring. - I2: Fix incorrect "return_distance" references in docstrings of raycast_static_meshes_kernel and raycast_dynamic_meshes_kernel. - I3: Fix ray_caster_camera_cfg.py docstring: "nan" → "inf" for missed rays with depth_clipping_behavior="none"; fix missing quote. - I4: Add comment about XformPrimView quaternion convention in _get_view_transforms_wp. - I7: Cache wp.to_torch() views at init in RayCasterCamera to avoid per-step Python wrapper allocation. - I8: Override _invalidate_initialize_callback in MultiMeshRayCaster to clear mesh_views on invalidation. - Tests: fix test_ray_caster_reset_resamples_drift (call sensor.reset() explicitly after sim.reset()); fix test_set_intrinsic_matrices assertion to allow inf for missed rays with clipping="none".
Keep all HEAD improvements: warp kernel caching, masked kernels, debug vis inf filtering, depth clipping validation, and drift test fix. Adopt upstream version bump (4.6.2) and include new changelog entries.
|
This will likely conflict with https://github.com/isaac-sim/IsaacLab/pull/5179/changes. we should coordinate which one gets in first. |
|
@AntoineRichard and @kellyguo11 -- should be good for another review |
yes, that might clash, whatever is more ready should get in first |
Add 17 pure-warp unit tests covering raycast_dynamic_meshes_kernel, compute_distance_to_image_plane_masked_kernel, apply_depth_clipping, apply_z_drift_kernel, and quat_yaw_only gimbal lock edge case. Add 6 integration tests (require Isaac Sim) covering ArticulationView and RigidBodyView transform paths, MultiMeshRayCaster env_mask, MultiMeshRayCasterCamera set_intrinsic_matrices propagation, and depth clipping ordering independence. Fix _update_mesh_transforms in MultiMeshRayCaster which used naive subtraction (pos_w -= pos_offset) instead of proper frame composition. With non-identity orientation offsets the tracked mesh positions were wrong. Now uses combine_frame_transforms matching the pattern used throughout the codebase. Fix migration guide dim ordering (num_meshes, num_envs, num_rays), add MultiMeshRayCaster/Camera to warp backend migration table, and correct ray_alignment="yaw" docstring to clarify only ray starts are rotated.
|
I'd merge this one first. @pascal-roth I made some touch-ups, lmk when you had time to look at them! |
# Conflicts: # source/isaaclab/config/extension.toml # source/isaaclab/docs/CHANGELOG.rst # source/isaaclab/isaaclab/sim/schemas/schemas_cfg.py # source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py
84d9678 to
9ba27d9
Compare
| Use ``isaaclab_physx.sim.spawners.materials`` instead. | ||
| * Removed :class:`DeformableObjectSpawnerCfg` from ``isaaclab.sim.spawners``. Use | ||
| ``isaaclab_physx.sim.spawners.spawner_cfg.DeformableObjectSpawnerCfg`` instead. | ||
| >>>>>>> origin/develop |
There was a problem hiding this comment.
lingering line from merge?
There was a problem hiding this comment.
Weird that the pre-commit check didn't catch it....
|
could you also double check on the test failures? I though our CI should be more green now. |
|
cannot reproduce any of the test failures, will retrigger the tests |
# Conflicts: # source/isaaclab/docs/CHANGELOG.rst
The RayCaster.meshes ClassVar cached warp meshes keyed only by prim path. When tests (or user code) create a RayCaster on CPU and later on CUDA in the same process, the CUDA instance would reuse the CPU-resident mesh, causing an illegal memory access on CI where unified memory is not available. Include the device string in the cache key so each device gets its own mesh instance.
|
@pascal-roth Look at the last changes. Looks like it was a garbage collection issue on CI.... |
A stray >>>>>>> origin/develop line was left after a merge resolution, causing the Sphinx doc build to fail (warnings treated as errors).
|
amazing catch! then we just have to document this as another breaking change as the classvar is changing |
…warp # Conflicts: # source/isaaclab/docs/CHANGELOG.rst
The cache key for the RayCaster.meshes ClassVar changed from prim_path to (prim_path, device) to avoid cross-device reuse. Add a migration guide subsection and a CHANGELOG entry with migration guidance so external callers of the ClassVar can update.
# Description Transitions the raycaster to warp ## Type of change - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Co-authored-by: Antoine Richard <[email protected]>
Description
Transitions the raycaster to warp
Type of change
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there