[inductor][ez] add src_hash property for Templates (#161468)

# why

enable caching/overriding/filtering based on src hash later

# what

- KernelTemplate has a src_hash that is None by default
- sha256 on TritonTemplate of the template src code
- None on ExternKernelChoice to have same API

# testing

n/a (not in use in this change)

Differential Revision: [](https://our.internmc.facebook.com/intern/diff/)

Differential Revision: [D81821149](https://our.internmc.facebook.com/intern/diff/D81821149)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161468
Approved by: https://github.com/eellison
ghstack dependencies: #161351, #161350, #162293
This commit is contained in:
Ruben Rodriguez Buchillon
2025-09-11 15:49:29 -07:00
committed by PyTorch MergeBot
parent 269c9907a0
commit 25f1a5d8d1
3 changed files with 20 additions and 3 deletions

View File

@ -2407,8 +2407,9 @@ class KernelTemplate:
return get_dtype
def __init__(self, name: str) -> None:
def __init__(self, name: str, hash: Optional[str] = None) -> None:
self.name = name
self._hash = hash
@property
def uid(self) -> str:
@ -2421,6 +2422,17 @@ class KernelTemplate:
# TODO(coconutruben): add some central registration to assert on global uniqueness
return self.name
@property
def src_hash(self) -> Union[str, None]:
"""
source hash for a Template.
Templates can optionally provide a src hash to make it easier to cache/validate that
a template has not changed from one version to another. Override this if that detection
is different for your specific Template
"""
return self._hash
def choice_or_none(self, **kwargs: Any) -> Optional[ChoiceCaller]:
"""
Maybe generates a new ChoiceCaller and returns it, or None if generation fails.