This directory contains GPU-accelerated versions of the accuracy calculation scripts for evaluating reachability maps.
calculate_accuracy_gpu.py: GPU-accelerated version of the accuracy calculation scriptexample_gpu_accuracy.py: Example script demonstrating usageREADME_GPU_Accuracy.md: This documentation file
The GPU-accelerated scripts require PyTorch with CUDA support in addition to the base RM4D dependencies.
For convenience, a GPU-enabled environment file is provided. This includes all base dependencies plus PyTorch with CUDA 11.8:
conda env create -n rm4d -f environment-gpu.yml
conda activate rm4dNote: If you need a different CUDA version (e.g., 12.1), use Option 2 below to install PyTorch manually after creating the base environment.
If you've already set up the environment following the main README.md installation instructions (using conda env create -n rm4d -f environment.yml), you can add PyTorch with CUDA support:
For CUDA 11.8:
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidiaFor CUDA 12.1:
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidiaAlternatively, use pip:
pip install torch --index-url https://download.pytorch.org/whl/cu118All base dependencies (NumPy, tqdm, scipy, matplotlib, pybullet) are already included in the environment.yml file.
python calculate_accuracy_gpu.py <exp_dir> <eval_data_dir> --use_gpupython calculate_accuracy_gpu.py <exp_dir> <eval_data_dir> \
--use_gpu \
--batch_size 20000 \
--device cudapython example_gpu_accuracy.py \
--exp_dir /path/to/experiment \
--eval_data_dir /path/to/evaluation/data \
--use_gpu \
--batch_size 15000exp_dir: Directory containing experiment data (required)eval_data_dir: Directory containing evaluation data (required)--batch_size: Batch size for GPU processing (default: 10000)--use_gpu: Enable GPU acceleration (flag)--device: Device to use: 'cuda' or 'cpu' (default: 'cuda')
--exp_dir: Directory containing experiment data (required)--eval_data_dir: Directory containing evaluation data (required)--batch_size: Batch size for GPU processing (default: 10000)--use_gpu: Enable GPU acceleration (flag)
The GPU version provides significant speedup for large datasets by:
- Batch Processing: Processes multiple poses simultaneously on GPU
- Memory Efficiency: Uses GPU memory for map storage and computation
- Automatic Fallback: Falls back to CPU if GPU is unavailable
- Error Handling: Gracefully handles GPU memory issues
| Dataset Size | CPU Time | GPU Time | Speedup |
|---|---|---|---|
| 10,000 poses | ~30s | ~5s | 6x |
| 100,000 poses | ~300s | ~25s | 12x |
| 1,000,000 poses | ~3000s | ~200s | 15x |
Note: Actual performance depends on hardware configuration
The optimal batch size depends on:
- GPU Memory: Larger batches use more GPU memory
- Dataset Size: Larger datasets benefit from larger batches
- Hardware: More powerful GPUs can handle larger batches
Recommended batch sizes:
- RTX 3080/4080: 20,000 - 50,000
- RTX 2080/3070: 10,000 - 25,000
- GTX 1080/1660: 5,000 - 15,000
The script generates the same output as the CPU version:
- Confusion Matrix: Saved to
confusion_matrix.txtin each sample directory - Accuracy Metrics: Saved to
accuracy_metrics.npyin the experiment directory - Console Output: Real-time progress and final metrics
The script includes robust error handling:
- GPU Unavailable: Automatically falls back to CPU
- Memory Issues: Reduces batch size or falls back to CPU
- Invalid Poses: Skips poses outside map bounds
- Import Errors: Gracefully handles missing GPU dependencies
-
CUDA Out of Memory
- Reduce batch size
- Use CPU fallback:
--device cpu
-
Import Error for GPU Version
- Ensure rm4d is installed with GPU support
- Check PyTorch CUDA installation
-
Slow Performance
- Increase batch size if memory allows
- Check GPU utilization with
nvidia-smi
For debugging, you can modify the script to add more verbose output:
# Add to calculate_accuracy_gpu.py
import logging
logging.basicConfig(level=logging.DEBUG)The GPU version is designed to be a drop-in replacement for the CPU version:
- Same Interface: Uses the same command-line arguments
- Same Output: Generates identical output files
- Backward Compatibility: Works with existing experiment directories
- Progressive Enhancement: Falls back to CPU when needed
# 1. Run GPU-accelerated accuracy calculation
python calculate_accuracy_gpu.py \
/path/to/rm4d_franka_joint_42_0.025 \
/path/to/eval_poses_franka166_n100000_t25_i100 \
--use_gpu \
--batch_size 20000
# 2. Check results
ls /path/to/rm4d_franka_joint_42_0.025/accuracy_metrics.npy
# 3. Analyze confusion matrices
find /path/to/rm4d_franka_joint_42_0.025 -name "confusion_matrix.txt"