forked from Field-Robotics-Lab/dave
-
Notifications
You must be signed in to change notification settings - Fork 18
Add vendor-agnostic wgpu compute backend #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
naitikpahwa18
wants to merge
7
commits into
IOES-Lab:ros2
Choose a base branch
from
naitikpahwa18:wgpu_integration
base: ros2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d655441
Add vendor-agnostic wgpu compute backend
naitikpahwa18 bbf0a1e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e812a99
add CUDA backend with runtime selection, rustfft migration
naitikpahwa18 4f9ad66
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 494b0df
Add Zero-Padding & Remove CPU Fallback
naitikpahwa18 e74f7f5
Merge branch 'ros2' into wgpu_integration
woensug-choi b15574d
Add Demo Guide to run Multi-Backend
naitikpahwa18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Multibeam Sonar Demo Guide | ||
|
|
||
| Build and run the GPU multibeam sonar demo. The plugin supports wgpu (Vulkan), CUDA (NVIDIA), and CPU backends—pick one at launch without recompiling. | ||
|
|
||
| ## Setup | ||
|
|
||
| **Prerequisites:** | ||
| - Ubuntu 24.04 | ||
| - ROS 2 Rolling | ||
| - Gazebo Jetty (gz-sim 10) | ||
| - Rust/Cargo | ||
| - Vulkan driver | ||
| - CUDA 12+ (if using the CUDA backend) | ||
|
|
||
| Clone and check out the branch: | ||
| ```bash | ||
| git clone https://github.com/naitikpahwa18/dave.git | ||
| cd dave | ||
| git checkout wgpu_integration | ||
| ``` | ||
|
|
||
| ## Build | ||
|
|
||
| Build in two steps on a fresh clone (the Rust library must be ready before the plugin can link to it): | ||
|
|
||
| ```bash | ||
| source /opt/ros/rolling/setup.bash | ||
|
|
||
| # Step 1: build and install the Rust library | ||
| colcon build --packages-select wgpu_vendor | ||
| source install/setup.bash | ||
|
|
||
| # Step 2: build the plugin and everything else | ||
| colcon build --packages-select dave_demos dave_worlds dave_interfaces multibeam_sonar multibeam_sonar_system dave_multibeam_sonar_demo dave_sensor_models | ||
| source install/setup.bash | ||
| ``` | ||
|
|
||
| On subsequent builds, you can run all packages in one command. | ||
|
|
||
| ## Run | ||
|
|
||
| ```bash | ||
| ros2 launch dave_multibeam_sonar_demo multibeam_sonar_demo.launch.py compute_backend:=wgpu | ||
| ``` | ||
|
|
||
| Use `compute_backend:=cuda` for CUDA, `compute_backend:=cpu` for CPU, or `compute_backend:=auto` to pick the best available (tries wgpu -> cuda -> cpu). | ||
|
|
||
| You'll see RViz2 launch with a point cloud display. The sonar fan should update in real time. Check the terminal for initialization messages and per-frame timing. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| **`Could not find wgpu_vendorConfig.cmake`** -> You skipped Step 1. Build `wgpu_vendor` first, source install, then build the rest. | ||
|
|
||
| **`Another world of the same name is running`** -> Kill stale Gazebo with `pkill -9 -f gz` and try again. | ||
|
|
||
| **CUDA backend won't initialize** -> Run `nvidia-smi` to check if the driver is loaded. If not, reinstall or reload with `sudo modprobe nvidia`. | ||
|
|
||
|
|
||
| ## How It Works | ||
|
|
||
| Each frame, Gazebo renders depth and surface normals. The sonar plugin reads these and runs acoustic physics on your selected backend. The wgpu backend dispatches four compute shaders: backscatter (acoustic return per ray), convert (fixed-point i32 -> f32), matmul (beam correction), and FFT (range compression). Output goes to ROS 2 topics as a point cloud and sonar image via ros_gz_bridge. The Rust library compiles to a static library linked into the C++ Gazebo plugin via C FFI. | ||
|
|
||
| ## Data Flow | ||
|
|
||
| **Pipeline stages:** | ||
|
|
||
| 1. **Input Buffers** - CPU writes depth, normal maps, reflectivity, window function, beam correction matrix | ||
| 2. **backscatter.wgsl** - Computes acoustic return per ray using Lambert model, outputs to atomic accumulators | ||
| 3. **convert.wgsl** - Converts fixed-point i32 results to f32 | ||
| 4. **matmul.wgsl** - Applies beam correction matrix to each beam | ||
| 5. **fft.wgsl** - Performs in-place FFT with zero-padding to power-of-2 for range compression | ||
| 6. **Readback** - CPU reads first n_freq bins from staging buffers | ||
| 7. **Output** - Results published to ROS 2 as point cloud and sonar image | ||
|
|
||
| **Buffer details:** | ||
|
|
||
| | Buffer | Dimensions | Type | Usage | | ||
| |--------|-----------|------|-------| | ||
| | depth_buf, normal_buf, refl_buf | n_beams × n_rays | f32 | Input from Gazebo | | ||
| | out_re_i32, out_im_i32 | n_beams × n_freq | i32 | Atomic accumulators (zeroed each frame) | | ||
| | mm_re_in, mm_im_in | n_beams × n_freq | f32 | After convert pass | | ||
| | mm_re_out, mm_im_out | n_beams × n_freq | f32 | After beam correction | | ||
| | p_re_buf, p_im_buf | n_beams × fft_len | f32 | FFT input/output (zero-padded) | | ||
| | stg_re, stg_im | n_beams × fft_len | f32 | Staging for CPU readback | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.