Skip to content

Commit 3523ab4

Browse files
authored
[Frontend][Cache] Include platform information in the key (#6000)
Note: This patch is an upstream version of what we use internally at Meta with the goal of reducing our internal patches. This PR adds platform specific information to the caching backend in order to make sure cached data does not get used incorrectly on a different platform. While one may say that on-disk local cache is only for that one machine, it is not uncommon that these files get transferred between machines either on purpose or accidental.
1 parent 852c05f commit 3523ab4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

third_party/nvidia/backend/driver.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ def library_dirs():
4747
return [libdevice_dir, *libcuda_dirs()]
4848

4949

50+
@functools.lru_cache()
51+
def platform_key():
52+
from platform import machine, system, architecture
53+
return ",".join([machine(), system(), *architecture()])
54+
55+
5056
def compile_module_from_src(src, name):
51-
key = hashlib.sha256(src.encode("utf-8")).hexdigest()
57+
key = hashlib.sha256((src + platform_key()).encode("utf-8")).hexdigest()
5258
cache = get_cache_manager(key)
5359
ext = sysconfig.get_config_var("EXT_SUFFIX").split(".")[-1]
5460
cache_path = cache.get_file(f"{name}.{ext}")

0 commit comments

Comments
 (0)