feat: add GPU acceleration support OpenSpec proposal

新增 GPU 加速支援的 OpenSpec 變更提案

主要內容:
- 在環境建置腳本中加入 GPU 偵測功能
- 自動安裝對應 CUDA 版本的 PaddlePaddle GPU 套件
- 在 OCR 處理程式中加入 GPU 可用性偵測
- 自動啟用 GPU 加速(可用時)或使用 CPU(不可用時)
- 支援強制 CPU 模式選項
- 加入 GPU 狀態報告到健康檢查 API

變更範圍:
- 新增 capability: environment-setup (環境設置)
- 修改 capability: ocr-processing (加入 GPU 支援)

實作任務包含:
1. 環境設置腳本增強 (GPU 偵測、CUDA 安裝)
2. 配置更新 (GPU 相關環境變數)
3. OCR 服務 GPU 整合 (自動偵測、記憶體管理)
4. 健康檢查與監控 (GPU 狀態報告)
5. 文檔更新
6. 測試與效能評估
7. 錯誤處理與邊界情況

預期效果:
- GPU 系統: 3-10x OCR 處理速度提升
- CPU 系統: 無影響,向後相容
- 自動硬體偵測與優化配置

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
egg
2025-11-14 07:34:06 +08:00
parent d7e64737b7
commit 6452797abe
4 changed files with 315 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
# Change: Add GPU Acceleration Support for OCR Processing
## Why
PaddleOCR supports CUDA GPU acceleration which can significantly improve OCR processing speed for batch operations. Currently, the system always uses CPU processing, which is slower and less efficient for large document batches. By adding GPU detection and automatic CUDA support, the system will:
- Automatically utilize available GPU hardware when present
- Fall back gracefully to CPU processing when GPU is unavailable
- Reduce processing time for large batches by leveraging parallel GPU computation
- Improve overall system throughput and user experience
## What Changes
- Add GPU detection logic to environment setup script (`setup_dev_env.sh`)
- Automatically install CUDA-enabled PaddlePaddle when compatible GPU is detected
- Install CPU-only PaddlePaddle when no compatible GPU is found
- Add GPU availability detection in OCR processing code
- Automatically enable GPU acceleration in PaddleOCR when GPU is available
- Add configuration option to force CPU mode (for testing or troubleshooting)
- Add GPU status reporting in API health check endpoint
- Update documentation with GPU requirements and setup instructions
## Impact
- **Affected capabilities**:
- `ocr-processing`: Add GPU acceleration support with automatic detection
- `environment-setup`: Add GPU detection and CUDA installation logic
- **Affected code**:
- `setup_dev_env.sh`: GPU detection and conditional CUDA package installation
- `backend/app/services/ocr_service.py`: GPU availability detection and configuration
- `backend/app/api/v1/endpoints/health.py`: GPU status reporting
- `backend/app/core/config.py`: GPU configuration settings
- `.env.local`: GPU-related environment variables
- **Dependencies**:
- When GPU available: `paddlepaddle-gpu` (with matching CUDA version)
- When GPU unavailable: `paddlepaddle` (CPU-only, current default)
- Detection tools: `nvidia-smi` (NVIDIA GPUs), `lspci` (hardware detection)
- **Configuration**:
- New env var: `FORCE_CPU_MODE` (default: false) - Override GPU detection
- New env var: `CUDA_VERSION` (auto-detected or manual override)
- GPU memory allocation settings for PaddleOCR
- Batch size adjustment based on GPU memory availability
- **Performance Impact**:
- Expected 3-10x speedup for OCR processing on GPU-enabled systems
- No performance degradation on CPU-only systems (same as current behavior)
- Automatic memory management to prevent GPU OOM errors
- **Backward Compatibility**:
- Fully backward compatible - existing CPU-only installations continue to work
- No breaking changes to API or configuration
- Existing installations can opt-in by re-running setup script on GPU-enabled hardware