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

Method load

torch/_inductor/codecache.py:1825–1846  ·  view source on GitHub ↗
(cls, source_code: str)

Source from the content-addressed store, hash-verified

1823
1824 @classmethod
1825 def load(cls, source_code: str) -> CDLL:
1826 picked_vec_isa = pick_vec_isa()
1827 cpp_command = repr(cpp_compile_command("i", "o", vec_isa=picked_vec_isa))
1828 key, input_path = write(source_code, "cpp", extra=cpp_command)
1829 if key not in cls.cache:
1830 from filelock import FileLock
1831
1832 lock_dir = get_lock_dir()
1833 lock = FileLock(os.path.join(lock_dir, key + ".lock"), timeout=LOCK_TIMEOUT)
1834 with lock:
1835 output_path = input_path[:-3] + "so"
1836 if not os.path.exists(output_path):
1837 cmd = shlex.split(
1838 cpp_compile_command(
1839 input=input_path, output=output_path, vec_isa=picked_vec_isa
1840 )
1841 )
1842 compile_file(input_path, output_path, cmd)
1843 cls.cache[key] = cls._load_library(output_path)
1844 cls.cache[key].key = key # type: ignore[attr-defined]
1845
1846 return cls.cache[key]
1847
1848
1849class PyCodeCache:

Callers

nothing calls this directly

Calls 8

pick_vec_isaFunction · 0.85
cpp_compile_commandFunction · 0.85
get_lock_dirFunction · 0.85
compile_fileFunction · 0.85
_load_libraryMethod · 0.80
writeFunction · 0.70
joinMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected