build_code_hash is called by torch_key to hash all torch source files.
Previously it read and hashed files sequentially; now it collects all
file paths first, then hashes them in parallel using a thread pool
(capped at 64 workers). Each file is hashed independently — using
hashlib.file_digest (pure C, bypasses Python I/O) on Python 3.11+ with
a f.read() fallback on 3.10 — and the per-file digests are combined in
sorted order for determinism. This gives a ~1.7x speedup to
inductor_codecache_torch_key, from ~355-362ms to ~196-218ms (typical
~360ms to ~210ms). Note: the hash value changes from the old sequential
scheme, so existing caches will be invalidated on first run.
Authored with Claude.
Pull Request resolved: #182180
Approved by: https://github.com/aorenste, https://github.com/zou3519
SOCIAL SHARE CARD GENERATOR