MCPcopy Create free account
hub / github.com/pytorch/pytorch / _write_ninja_file

Function _write_ninja_file

torch/utils/cpp_extension.py:2252–2397  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2250
2251
2252def _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:

Calls 12

sanitize_flagsFunction · 0.85
get_cxx_compilerFunction · 0.85
_join_rocm_homeFunction · 0.85
_join_cuda_homeFunction · 0.85
_is_cuda_fileFunction · 0.85
_maybe_writeFunction · 0.85
appendMethod · 0.45
joinMethod · 0.45
replaceMethod · 0.45
splitMethod · 0.45
decodeMethod · 0.45
check_outputMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…