Skip to content

Commit a69ebfa

Browse files
authored
Use base32 encoded cache keys to avoid names starting with a hyphen (triton-lang#5088)
Modify the _base64 function used for filename generation to ensure filenames do not start with a hyphen (`-`). This change prevents issues on Unix-like systems where filenames beginning with a hyphen can be misinterpreted as command-line options. in this way we adhere to to the [The Linux Information Project's File Naming Conventions](https://www.linfo.org/file_name.html): > "File names should never begin with a hyphen"
1 parent db2aece commit a69ebfa

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

python/triton/runtime/cache.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ def put_group(self, filename: str, group: Dict[str, str]):
256256
__cache_cls_nme = "DEFAULT"
257257

258258

259-
def _base64(key):
259+
def _base32(key):
260260
# Assume key is a hex string.
261-
return base64.urlsafe_b64encode(bytes.fromhex(key)).decode("utf-8").rstrip("=")
261+
return base64.b32encode(bytes.fromhex(key)).decode("utf-8").rstrip("=")
262262

263263

264264
def get_cache_manager(key) -> CacheManager:
@@ -274,15 +274,15 @@ def get_cache_manager(key) -> CacheManager:
274274
__cache_cls = getattr(module, clz_nme)
275275
__cache_cls_nme = user_cache_manager
276276

277-
return __cache_cls(_base64(key))
277+
return __cache_cls(_base32(key))
278278

279279

280280
def get_override_manager(key) -> CacheManager:
281-
return __cache_cls(_base64(key), override=True)
281+
return __cache_cls(_base32(key), override=True)
282282

283283

284284
def get_dump_manager(key) -> CacheManager:
285-
return __cache_cls(_base64(key), dump=True)
285+
return __cache_cls(_base32(key), dump=True)
286286

287287

288288
def make_so_cache_key(version_hash, signature, constants, ids, **kwargs):
@@ -292,4 +292,4 @@ def make_so_cache_key(version_hash, signature, constants, ids, **kwargs):
292292
for kw in kwargs:
293293
key = f"{key}-{kwargs.get(kw)}"
294294
key = hashlib.sha256(key.encode("utf-8")).hexdigest()
295-
return _base64(key)
295+
return _base32(key)

0 commit comments

Comments
 (0)