Skip to content

Latest commit

 

History

History
192 lines (133 loc) · 5.61 KB

File metadata and controls

192 lines (133 loc) · 5.61 KB

GPU-Accelerated Accuracy Calculation for Reachability Maps

This directory contains GPU-accelerated versions of the accuracy calculation scripts for evaluating reachability maps.

Files

  • calculate_accuracy_gpu.py: GPU-accelerated version of the accuracy calculation script
  • example_gpu_accuracy.py: Example script demonstrating usage
  • README_GPU_Accuracy.md: This documentation file

Requirements

The GPU-accelerated scripts require PyTorch with CUDA support in addition to the base RM4D dependencies.

Option 1: Use GPU Environment File (Recommended)

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 rm4d

Note: If you need a different CUDA version (e.g., 12.1), use Option 2 below to install PyTorch manually after creating the base environment.

Option 2: Add PyTorch to Existing 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 nvidia

For CUDA 12.1:

conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

Alternatively, use pip:

pip install torch --index-url https://download.pytorch.org/whl/cu118

All base dependencies (NumPy, tqdm, scipy, matplotlib, pybullet) are already included in the environment.yml file.

Usage

Basic Usage

python calculate_accuracy_gpu.py <exp_dir> <eval_data_dir> --use_gpu

Advanced Usage

python calculate_accuracy_gpu.py <exp_dir> <eval_data_dir> \
    --use_gpu \
    --batch_size 20000 \
    --device cuda

Using the Example Script

python example_gpu_accuracy.py \
    --exp_dir /path/to/experiment \
    --eval_data_dir /path/to/evaluation/data \
    --use_gpu \
    --batch_size 15000

Command Line Arguments

calculate_accuracy_gpu.py

  • 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)
  • --device: Device to use: 'cuda' or 'cpu' (default: 'cuda')

example_gpu_accuracy.py

  • --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)

Features

GPU Acceleration

The GPU version provides significant speedup for large datasets by:

  1. Batch Processing: Processes multiple poses simultaneously on GPU
  2. Memory Efficiency: Uses GPU memory for map storage and computation
  3. Automatic Fallback: Falls back to CPU if GPU is unavailable
  4. Error Handling: Gracefully handles GPU memory issues

Performance Comparison

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

Batch Size Optimization

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

Output

The script generates the same output as the CPU version:

  1. Confusion Matrix: Saved to confusion_matrix.txt in each sample directory
  2. Accuracy Metrics: Saved to accuracy_metrics.npy in the experiment directory
  3. Console Output: Real-time progress and final metrics

Error Handling

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

Troubleshooting

Common Issues

  1. CUDA Out of Memory

    • Reduce batch size
    • Use CPU fallback: --device cpu
  2. Import Error for GPU Version

    • Ensure rm4d is installed with GPU support
    • Check PyTorch CUDA installation
  3. Slow Performance

    • Increase batch size if memory allows
    • Check GPU utilization with nvidia-smi

Debug Mode

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)

Integration with Existing Workflows

The GPU version is designed to be a drop-in replacement for the CPU version:

  1. Same Interface: Uses the same command-line arguments
  2. Same Output: Generates identical output files
  3. Backward Compatibility: Works with existing experiment directories
  4. Progressive Enhancement: Falls back to CPU when needed

Example Workflow

# 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"