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

Add safety check for fusion #281

Merged
merged 2 commits into from
Jul 19, 2024
Merged

Conversation

NaderAlAwar
Copy link
Contributor

Added a safety check to prevent fusion of kernels that could introduce a dependency between threads in the fused kernel. Dependencies can only come from views, so the safety check looks at the what indices are used to access the views. Two kernels which access views only through their thread ID will not introduce a dependency between threads in the fused kernel.

@NaderAlAwar NaderAlAwar requested a review from gliga July 18, 2024 10:35
@NaderAlAwar NaderAlAwar merged commit 9e3a3d8 into kokkos:main Jul 19, 2024
5 checks passed
def is_safe_to_fuse(self, current: List[TracerOperation], current_views: Set[ViewType], current_safety_info: Dict[Tuple[int, int], Tuple[AccessIndex, AccessMode]], next: TracerOperation, next_views: Set[ViewType]) -> bool:
"""
Check whether the next operation is safe to fuse with the
current operations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment should document the conditions under which it would be safe to fuse

@@ -305,7 +458,7 @@ def fuse_operations(self, operations: List[TracerOperation]) -> TracerOperation:
# Avoid long names
fused_name = "_".join(names[:5]) + hashlib.md5(("".join(names)).encode()).hexdigest()

return TracerOperation(None, future, fused_name, policy, workunits, operation, parsers, fused_name, args, dependencies)
return TracerOperation(None, future, fused_name, policy, workunits, operation, parsers, fused_name, args, dependencies, fused_safety_info)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some tests for the newly introduced checks?

Copy link
Contributor

@gliga gliga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be easier to review if some tests were there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants