Benchmark a standalone user kernel.
(
self,
compiled_kernel: Dict[str, Any],
analysis: Dict[str, Any]
)
| 30 | self.cuda_context.pop() |
| 31 | |
| 32 | def benchmark_kernel_standalone( |
| 33 | self, |
| 34 | compiled_kernel: Dict[str, Any], |
| 35 | analysis: Dict[str, Any] |
| 36 | ) -> Dict[str, Any]: |
| 37 | """Benchmark a standalone user kernel.""" |
| 38 | kernel_name = analysis.get('kernel_name', 'user_kernel') |
| 39 | |
| 40 | console.print(f"\n[cyan]Benchmarking {kernel_name} kernel...[/cyan]") |
| 41 | |
| 42 | try: |
| 43 | # Create synthetic test data based on kernel parameters |
| 44 | test_data = self._create_test_data(analysis) |
| 45 | |
| 46 | # Run kernel with test data |
| 47 | kernel_times = self._benchmark_cuda_kernel( |
| 48 | compiled_kernel, |
| 49 | inputs=test_data['inputs'], |
| 50 | output_shape=test_data['output_shape'], |
| 51 | kernel_name=kernel_name, |
| 52 | block_size=test_data.get('block_size', (256, 1, 1)), |
| 53 | grid_size=test_data.get('grid_size', (1024, 1, 1)), |
| 54 | warmup=self.warmup_iterations, |
| 55 | iterations=self.iterations |
| 56 | ) |
| 57 | |
| 58 | if kernel_times and all(t != float('inf') for t in kernel_times): |
| 59 | return { |
| 60 | "avg_time_ms": statistics.median(kernel_times), |
| 61 | "min_time_ms": min(kernel_times), |
| 62 | "max_time_ms": max(kernel_times), |
| 63 | "std_dev_ms": statistics.stdev(kernel_times) if len(kernel_times) > 1 else 0, |
| 64 | "success": True |
| 65 | } |
| 66 | else: |
| 67 | return { |
| 68 | "avg_time_ms": float('inf'), |
| 69 | "min_time_ms": float('inf'), |
| 70 | "max_time_ms": float('inf'), |
| 71 | "std_dev_ms": 0, |
| 72 | "success": False |
| 73 | } |
| 74 | |
| 75 | except Exception as e: |
| 76 | console.print(f"[red]Error during benchmarking: {e}[/red]") |
| 77 | return { |
| 78 | "avg_time_ms": float('inf'), |
| 79 | "min_time_ms": float('inf'), |
| 80 | "max_time_ms": float('inf'), |
| 81 | "std_dev_ms": 0, |
| 82 | "success": False, |
| 83 | "error": str(e) |
| 84 | } |
| 85 | |
| 86 | def _create_test_data(self, analysis: Dict[str, Any]) -> Dict[str, Any]: |
| 87 | """Create synthetic test data based on kernel analysis.""" |
no test coverage detected