feat: #1039 - [E3-F3-P2] Implement to_warp() with manual transfer control#1045
Merged
Gorkowski merged 2 commits intouncscode:mainfrom Feb 3, 2026
Merged
feat: #1039 - [E3-F3-P2] Implement to_warp() with manual transfer control#1045Gorkowski merged 2 commits intouncscode:mainfrom
Gorkowski merged 2 commits intouncscode:mainfrom
Conversation
Implement conversion functions for transferring ParticleData and GasData containers to GPU using NVIDIA Warp arrays. This is phase E3-F3-P2 of the GPU integration feature. New functions: - to_warp_particle_data(): Transfer ParticleData to WarpParticleData - to_warp_gas_data(): Transfer GasData to WarpGasData with vapor_pressure handling Key features: - Device selection support (cuda, cuda:0, cuda:1, cpu) - Copy parameter for copy vs zero-copy transfer modes - Proper error handling for unavailable Warp and invalid devices - Bool to int32 conversion for partitioning field - Optional vapor_pressure parameter (defaults to zeros) Closes uncscode#1039 ADW-ID: 8864132c
Remove unused variables and reorder imports to fix lint errors: - Remove unused n_boxes and n_species variables in test_single_box_gas_data (F841 lint fix) - Reorder TYPE_CHECKING imports alphabetically in conversion.py for consistency (isort/ruff format fix) ADW-ID: 8864132c
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Target Branch:
mainFixes #1039 | Workflow:
8864132cSummary
Implements
to_warp_particle_data()andto_warp_gas_data()functions that transfer CPU-sideParticleDataandGasDatacontainers to GPU using NVIDIA Warp arrays. These functions provide explicit control over device selection and copy behavior, enabling long GPU-resident simulations where data stays on GPU across many timesteps without CPU round-trips.This phase builds on the Warp struct definitions from E3-F3-P1 (#1038), completing the CPU→GPU transfer capability as the entry point for GPU-accelerated simulations.
What Changed
New Components
particula/gpu/conversion.py- New module (~240 LOC) containing:_ensure_warp_available()- Helper that validates Warp installation_validate_device()- Helper that validates device strings (cuda, cuda:0, cpu, etc.)to_warp_particle_data()- Transfers ParticleData to GPU with device/copy controlto_warp_gas_data()- Transfers GasData to GPU with device/copy/vapor_pressure controlparticula/gpu/tests/conversion_test.py- Comprehensive test suite (~418 LOC) covering:Modified Components
particula/gpu/__init__.py- Added exports for new conversion functions:to_warp_particle_datato_warp_gas_dataHow It Works
The conversion functions enable one-time CPU→GPU transfer at simulation start:
Usage pattern:
Implementation Notes
wp.get_device()validationcopy=True(default): Useswp.array()- always copies to devicecopy=False: Useswp.from_numpy()- may avoid copy if compatiblenamefield excluded (strings not GPU-compatible)partitioningconverted from bool → int32 (True→1, False→0)vapor_pressureparameter added (defaults to zeros if not provided)Testing
pytest.importorskip("warp")for graceful skip without Warp.numpy()comparison