Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use base64 for shorter cache directories #2

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions python/triton/runtime/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Dict, List, Optional
import base64
import hashlib


Expand Down Expand Up @@ -255,6 +256,11 @@ def put_group(self, filename: str, group: Dict[str, str]):
__cache_cls_nme = "DEFAULT"


def _base64(key):
# Assume key is a hex string.
return base64.urlsafe_b64encode(bytes.fromhex(key)).decode("utf-8").rstrip("=")


def get_cache_manager(key) -> CacheManager:
import os

Expand All @@ -268,15 +274,15 @@ def get_cache_manager(key) -> CacheManager:
__cache_cls = getattr(module, clz_nme)
__cache_cls_nme = user_cache_manager

return __cache_cls(key)
return __cache_cls(_base64(key))


def get_override_manager(key) -> CacheManager:
return __cache_cls(key, override=True)
return __cache_cls(_base64(key), override=True)


def get_dump_manager(key) -> CacheManager:
return __cache_cls(key, dump=True)
return __cache_cls(_base64(key), dump=True)


def make_so_cache_key(version_hash, signature, constants, ids, **kwargs):
Expand All @@ -286,4 +292,4 @@ def make_so_cache_key(version_hash, signature, constants, ids, **kwargs):
for kw in kwargs:
key = f"{key}-{kwargs.get(kw)}"
key = hashlib.sha256(key.encode("utf-8")).hexdigest()
return key
return _base64(key)
Loading