Stage compilation files and return (command, artifact_path). Writes build_ext.py, solution.json, and C++/CUDA source files to output_dir. Injects gencode flags for the target hardware. The CLI should run the command in output_dir. After success, the artifact (benchm
(self)
| 161 | dest.write_text(src.content) |
| 162 | |
| 163 | def compile(self) -> tuple[list[str], str]: |
| 164 | """Stage compilation files and return (command, artifact_path). |
| 165 | |
| 166 | Writes build_ext.py, solution.json, and C++/CUDA source files to |
| 167 | output_dir. Injects gencode flags for the target hardware. |
| 168 | |
| 169 | The CLI should run the command in output_dir. |
| 170 | After success, the artifact (benchmark_kernel.so) will be at artifact_path. |
| 171 | """ |
| 172 | assert self._is_cpp, ( |
| 173 | f"compile() only handles C++/CUDA solutions, " |
| 174 | f"got languages={self.solution.spec.languages}" |
| 175 | ) |
| 176 | |
| 177 | sol_dict = json.loads(self.solution.model_dump_json()) |
| 178 | sol_dict = self._inject_gencode_flags(sol_dict) |
| 179 | |
| 180 | # Overwrite solution.json with injected gencode flags. |
| 181 | (self.output_dir / "solution.json").write_text(json.dumps(sol_dict)) |
| 182 | (self.output_dir / "build_ext.py").write_text( |
| 183 | (_TEMPLATES_DIR / "build_ext.py").read_text() |
| 184 | ) |
| 185 | |
| 186 | cmd = ["python", "build_ext.py"] |
| 187 | artifact_path = str(self.output_dir / "benchmark_kernel.so") |
| 188 | |
| 189 | return cmd, artifact_path |
| 190 | |
| 191 | def execute(self) -> list[str]: |
| 192 | """Stage execution files and return the command to run. |