r"""Write a ninja file that does the desired compiling and linking. `path`: Where to write this file `cflags`: list of flags to pass to $cxx. Can be None. `post_cflags`: list of flags to append to the $cxx invocation. Can be None. `cuda_cflags`: list of flags to pass to $nvcc. Can b
(path,
cflags,
post_cflags,
cuda_cflags,
cuda_post_cflags,
cuda_dlink_post_cflags,
sources,
objects,
ldflags,
library_target,
with_cuda)
| 2250 | |
| 2251 | |
| 2252 | def _write_ninja_file(path, |
| 2253 | cflags, |
| 2254 | post_cflags, |
| 2255 | cuda_cflags, |
| 2256 | cuda_post_cflags, |
| 2257 | cuda_dlink_post_cflags, |
| 2258 | sources, |
| 2259 | objects, |
| 2260 | ldflags, |
| 2261 | library_target, |
| 2262 | with_cuda) -> None: |
| 2263 | r"""Write a ninja file that does the desired compiling and linking. |
| 2264 | |
| 2265 | `path`: Where to write this file |
| 2266 | `cflags`: list of flags to pass to $cxx. Can be None. |
| 2267 | `post_cflags`: list of flags to append to the $cxx invocation. Can be None. |
| 2268 | `cuda_cflags`: list of flags to pass to $nvcc. Can be None. |
| 2269 | `cuda_postflags`: list of flags to append to the $nvcc invocation. Can be None. |
| 2270 | `sources`: list of paths to source files |
| 2271 | `objects`: list of desired paths to objects, one per source. |
| 2272 | `ldflags`: list of flags to pass to linker. Can be None. |
| 2273 | `library_target`: Name of the output library. Can be None; in that case, |
| 2274 | we do no linking. |
| 2275 | `with_cuda`: If we should be compiling with CUDA. |
| 2276 | """ |
| 2277 | def sanitize_flags(flags): |
| 2278 | if flags is None: |
| 2279 | return [] |
| 2280 | else: |
| 2281 | return [flag.strip() for flag in flags] |
| 2282 | |
| 2283 | cflags = sanitize_flags(cflags) |
| 2284 | post_cflags = sanitize_flags(post_cflags) |
| 2285 | cuda_cflags = sanitize_flags(cuda_cflags) |
| 2286 | cuda_post_cflags = sanitize_flags(cuda_post_cflags) |
| 2287 | cuda_dlink_post_cflags = sanitize_flags(cuda_dlink_post_cflags) |
| 2288 | ldflags = sanitize_flags(ldflags) |
| 2289 | |
| 2290 | # Sanity checks... |
| 2291 | assert len(sources) == len(objects) |
| 2292 | assert len(sources) > 0 |
| 2293 | |
| 2294 | compiler = get_cxx_compiler() |
| 2295 | |
| 2296 | # Version 1.3 is required for the `deps` directive. |
| 2297 | config = ['ninja_required_version = 1.3'] |
| 2298 | config.append(f'cxx = {compiler}') |
| 2299 | if with_cuda or cuda_dlink_post_cflags: |
| 2300 | if "PYTORCH_NVCC" in os.environ: |
| 2301 | nvcc = os.getenv("PYTORCH_NVCC") # user can set nvcc compiler with ccache using the environment variable here |
| 2302 | else: |
| 2303 | if IS_HIP_EXTENSION: |
| 2304 | nvcc = _join_rocm_home('bin', 'hipcc') |
| 2305 | else: |
| 2306 | nvcc = _join_cuda_home('bin', 'nvcc') |
| 2307 | config.append(f'nvcc = {nvcc}') |
| 2308 | |
| 2309 | if IS_HIP_EXTENSION: |
no test coverage detected
searching dependent graphs…