Skip to content

Commit

Permalink
Use libdevice file hash rather than path (#3224)
Browse files Browse the repository at this point in the history
We've been trying to share cached compilations across machines, but
libdevice isn't always in the same place (we actually package it into
python archive files so we don't rely on the system CUDA installation).
By hashing the file instead of its path we can make this hash
consistent; and we really do care more about the contents of libdevice
than its path, anyways.
  • Loading branch information
bertmaher authored Mar 10, 2024
1 parent 5bcd351 commit ccc25eb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions third_party/nvidia/backend/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def ptx_get_version(cuda_version) -> int:
raise RuntimeError("Triton only support CUDA 10.0 or higher")


@functools.lru_cache(None)
def file_hash(path):
with open(path, "rb") as f:
return hashlib.sha256(f.read()).hexdigest()


@dataclass(frozen=True)
class CUDAOptions:
num_warps: int = 4
Expand All @@ -76,8 +82,10 @@ def __post_init__(self):
"num_warps must be a power of 2"

def hash(self):
key = '_'.join([f'{name}-{val}' for name, val in self.__dict__.items()])
return hashlib.md5(key.encode("utf-8")).hexdigest()
hash_dict = dict(self.__dict__)
hash_dict["extern_libs"] = tuple((k, file_hash(v)) for k, v in sorted(hash_dict["extern_libs"]))
key = "_".join([f"{name}-{val}" for name, val in sorted(hash_dict.items())])
return hashlib.sha256(key.encode("utf-8")).hexdigest()


class CUDABackend(BaseBackend):
Expand Down

0 comments on commit ccc25eb

Please sign in to comment.