Skip to content

Commit

Permalink
Example using nx dispatch hooks (WIP) to print timing
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw committed Dec 11, 2024
1 parent 3509513 commit b0c32a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions _nx_cugraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,27 @@
# always be in <major>.<minor>.<build> format.
(_version_major, _version_minor) = __version__.split(".")[:2]


def dispatch_hook_impl(hook_name, hook_token, **kwargs):
import time

if hook_name == "on_call_with_backend_begin":
hook_token["cugraph"]["t0"] = time.time()
elif hook_name == "on_call_with_backend_end":
t = time.time() - hook_token["cugraph"]["t0"]
backend_name = kwargs["backend_name"]
dispatch_name = hook_token.dispatchable.name
print(f"{backend_name!r} backend ran {dispatch_name} in {t:.3g} seconds")


# Entries between BEGIN and END are automatically generated
_info = {
"backend_name": "cugraph",
"project": "nx-cugraph",
"package": "nx_cugraph",
"url": "https://rapids.ai/nx-cugraph",
"short_summary": "GPU-accelerated backend.",
"dispatch_hook_impl": dispatch_hook_impl,
# "description": "TODO",
"functions": {
# BEGIN: functions
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ ignore = [
"__init__.py" = ["F401"] # Allow unused imports (w/o defining `__all__`)
# Allow assert, print, RNG, and no docstring
"nx_cugraph/**/tests/*py" = ["S101", "S311", "T201", "D103", "D100"]
"_nx_cugraph/__init__.py" = ["E501"]
"_nx_cugraph/__init__.py" = ["E501", "T201"]
"nx_cugraph/__init__.py" = ["E402"] # Allow module level import not at top of file
"nx_cugraph/algorithms/**/*py" = ["D205", "D401"] # Allow flexible docstrings for algorithms
"nx_cugraph/generators/**/*py" = ["D205", "D401"] # Allow flexible docstrings for generators
Expand Down

0 comments on commit b0c32a9

Please sign in to comment.