Analyze a CUDA kernel and extract relevant information. Returns: Dictionary containing: - kernel_name: Name of the kernel function - parameters: List of parameter names - shared_memory_usage: Detected shared memory usage
(self, code: str)
| 7 | """Analyzes CUDA kernels to extract information and identify optimization opportunities.""" |
| 8 | |
| 9 | def analyze_kernel(self, code: str) -> Dict[str, Any]: |
| 10 | """ |
| 11 | Analyze a CUDA kernel and extract relevant information. |
| 12 | |
| 13 | Returns: |
| 14 | Dictionary containing: |
| 15 | - kernel_name: Name of the kernel function |
| 16 | - parameters: List of parameter names |
| 17 | - shared_memory_usage: Detected shared memory usage |
| 18 | - patterns: Detected computational patterns |
| 19 | - optimization_opportunities: List of potential optimizations |
| 20 | - performance_hints: Performance-related suggestions |
| 21 | """ |
| 22 | analysis = { |
| 23 | "kernel_name": self._extract_kernel_name(code), |
| 24 | "parameters": self._extract_parameters(code), |
| 25 | "launch_bounds": self._extract_launch_bounds(code), |
| 26 | "shared_memory_usage": self._analyze_shared_memory(code), |
| 27 | "global_accesses": self._analyze_global_memory(code), |
| 28 | "patterns": self._detect_patterns(code), |
| 29 | "optimization_opportunities": [], |
| 30 | "performance_hints": [], |
| 31 | "complexity": self._estimate_complexity(code), |
| 32 | "synchronization": self._analyze_synchronization(code), |
| 33 | "arithmetic_intensity": self._estimate_arithmetic_intensity(code) |
| 34 | } |
| 35 | |
| 36 | # Identify optimization opportunities |
| 37 | analysis["optimization_opportunities"] = self._identify_optimizations(code, analysis) |
| 38 | analysis["performance_hints"] = self._generate_performance_hints(code, analysis) |
| 39 | |
| 40 | return analysis |
| 41 | |
| 42 | def _extract_kernel_name(self, code: str) -> str: |
| 43 | """Extract the kernel function name.""" |
no test coverage detected