Create a test program that runs the kernel.
(
self,
compiled_kernel: Dict[str, Any],
model_info: Dict[str, Any],
temp_path: Path
)
| 202 | return self._estimate_metrics(compiled_kernel, model_info) |
| 203 | |
| 204 | def _create_test_program( |
| 205 | self, |
| 206 | compiled_kernel: Dict[str, Any], |
| 207 | model_info: Dict[str, Any], |
| 208 | temp_path: Path |
| 209 | ) -> Optional[Path]: |
| 210 | """Create a test program that runs the kernel.""" |
| 211 | operation = compiled_kernel.get("operation", "unknown") |
| 212 | kernel_code = compiled_kernel.get("full_code", "") |
| 213 | |
| 214 | if not kernel_code: |
| 215 | return None |
| 216 | |
| 217 | test_code = self._generate_test_harness(operation, kernel_code, model_info) |
| 218 | |
| 219 | cuda_file = temp_path / "test_kernel.cu" |
| 220 | exe_file = temp_path / ("test_kernel.exe" if platform.system() == "Windows" else "test_kernel") |
| 221 | |
| 222 | with open(cuda_file, 'w') as f: |
| 223 | f.write(test_code) |
| 224 | |
| 225 | from .compiler import CUDACompiler |
| 226 | compiler = CUDACompiler() |
| 227 | |
| 228 | compile_cmd = [ |
| 229 | compiler.nvcc_path, |
| 230 | "-O3", |
| 231 | "-std=c++14" |
| 232 | ] + compiler.arch_flags + [ |
| 233 | "-o", str(exe_file), |
| 234 | str(cuda_file) |
| 235 | ] |
| 236 | |
| 237 | try: |
| 238 | result = subprocess.run( |
| 239 | compile_cmd, |
| 240 | capture_output=True, |
| 241 | text=True, |
| 242 | check=True |
| 243 | ) |
| 244 | return exe_file |
| 245 | except subprocess.CalledProcessError as e: |
| 246 | console.print(f"[red]Failed to compile test program: {e.stderr}[/red]") |
| 247 | return None |
| 248 | |
| 249 | def _generate_test_harness( |
| 250 | self, |
no test coverage detected