0.1.8
Loading...
Searching...
No Matches
runtime.py
Go to the documentation of this file.
1"""
2PyHelios Runtime GPU Detection Module
3
4This module provides runtime GPU detection capabilities for PyHelios testing and validation.
5Implements proper fail-fast detection without silent fallbacks, following CLAUDE.md guidelines.
6"""
7
8import logging
9from typing import Dict, Any, Optional
10
11logger = logging.getLogger(__name__)
12
13
14def is_gpu_runtime_available() -> bool:
15 """
16 Check if GPU runtime (CUDA/OptiX) is available for PyHelios.
17
18 Returns:
19 bool: True if GPU runtime is available, False otherwise
20
21 Raises:
22 RuntimeError: If GPU detection system is unavailable (fail-fast)
23 """
24 try:
25 from pyhelios.config.dependency_resolver import PluginDependencyResolver
26 resolver = PluginDependencyResolver()
27 return resolver._check_cuda()
28 except ImportError as e:
29 raise RuntimeError(
30 f"GPU detection system unavailable: {e}. "
31 f"This indicates a PyHelios installation or import issue."
32 ) from e
33 except Exception as e:
34 raise RuntimeError(
35 f"GPU detection failed: {e}. "
36 f"Check CUDA installation and GPU drivers."
37 ) from e
38
39
40def get_gpu_runtime_info() -> Dict[str, Any]:
41 """
42 Get detailed GPU runtime information for PyHelios.
43
44 Returns:
45 Dict containing GPU runtime status and details
46
47 Raises:
48 RuntimeError: If GPU detection system is unavailable (fail-fast)
49 """
50 try:
51 from pyhelios.config.dependency_resolver import PluginDependencyResolver
52 resolver = PluginDependencyResolver()
53
54 cuda_available = resolver._check_cuda()
55
56 info = {
57 'cuda_available': cuda_available,
58 'gpu_runtime_available': cuda_available,
59 }
60
61 if not cuda_available:
62 info['error_message'] = 'CUDA/GPU not available'
63 info['suggestions'] = [
64 'Install NVIDIA CUDA toolkit',
65 'Ensure NVIDIA GPU drivers are installed',
66 'Check that nvcc is in PATH'
67 ]
68
69 return info
70
71 except ImportError as e:
72 raise RuntimeError(
73 f"GPU detection system unavailable: {e}. "
74 f"This indicates a PyHelios installation or import issue."
75 ) from e
76 except Exception as e:
77 raise RuntimeError(
78 f"GPU detection failed: {e}. "
79 f"Check CUDA installation and GPU drivers."
80 ) from e
81
82
83def validate_gpu_requirements() -> None:
84 """
85 Validate that GPU requirements are met for GPU-dependent operations.
86
87 Raises:
88 RuntimeError: If GPU requirements are not met (fail-fast)
89 """
91 gpu_info = get_gpu_runtime_info()
92 error_msg = gpu_info.get('error_message', 'GPU not available')
93 suggestions = gpu_info.get('suggestions', [])
94
95 raise RuntimeError(
96 f"GPU requirements not met: {error_msg}. "
97 f"Required for GPU-dependent plugins (radiation, energybalance, etc.). "
98 f"Solutions: {'; '.join(suggestions)}"
99 )
None validate_gpu_requirements()
Validate that GPU requirements are met for GPU-dependent operations.
Definition runtime.py:89
bool is_gpu_runtime_available()
Check if GPU runtime (CUDA/OptiX) is available for PyHelios.
Definition runtime.py:23
Dict[str, Any] get_gpu_runtime_info()
Get detailed GPU runtime information for PyHelios.
Definition runtime.py:49