-
Notifications
You must be signed in to change notification settings - Fork 21
algorithms: inclusive_scan
#319
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
Open
IvanGrigorik
wants to merge
3
commits into
main
Choose a base branch
from
grigorik/scan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import pykokkos as pk | ||
|
|
||
|
|
||
| @pk.workunit | ||
| def init_data(i: int, view: pk.View1D[int]): | ||
| view[i] = i + 1 | ||
|
|
||
|
|
||
| # Test inclusive_scan with scratch memory | ||
| @pk.workunit | ||
| def team_scan(team_member: pk.TeamMember, view: pk.View1D[int]): | ||
| team_size: int = team_member.team_size() | ||
| offset: int = team_member.league_rank() * team_size | ||
| localIdx: int = team_member.team_rank() | ||
| globalIdx: int = offset + localIdx | ||
| team_rank: int = team_member.team_rank() | ||
|
|
||
| scratch: pk.ScratchView1D[int] = pk.ScratchView1D( | ||
| team_member.team_scratch(0), team_size | ||
| ) | ||
|
|
||
| scratch[team_rank] = view[globalIdx] | ||
| team_member.team_barrier() | ||
|
|
||
| pk.inclusive_scan(team_member, scratch) | ||
| team_member.team_barrier() | ||
|
|
||
| view[globalIdx] = scratch[team_rank] | ||
|
|
||
|
|
||
| def main(): | ||
| N = 64 | ||
| team_size = 32 | ||
| num_teams = (N + team_size - 1) // team_size | ||
|
|
||
| view: pk.View1D[int] = pk.View([N], int) | ||
| p_init = pk.RangePolicy(pk.ExecutionSpace.OpenMP, 0, N) | ||
| pk.parallel_for(p_init, init_data, view=view) | ||
|
|
||
| print(f"Total elements: {N}, Team size: {team_size}, Number of teams: {num_teams}") | ||
|
|
||
| # Use TeamPolicy | ||
| team_policy = pk.TeamPolicy(pk.ExecutionSpace.OpenMP, num_teams, team_size) | ||
|
|
||
| # for now these functions are useless, since they are not implemented corectly | ||
| # TODO: implement scratch size setting | ||
| # scratch_size = pk.ScratchView1D[int].shmem_size(team_size) | ||
| # team_policy.set_scratch_size(0, pk.PerTeam(scratch_size)) | ||
|
|
||
| # Kernel call - just allocate and write to scratch | ||
| print("Running kernel...") | ||
| pk.parallel_for(team_policy, team_scan, view=view) | ||
| print(f"View, splitted by two groups of size = {team_size}") | ||
| print(view) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interfaces modified to support linting and highlighting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from pykokkos.interface.hierarchical import TeamMember | ||
| from pykokkos.interface.views import ViewType | ||
|
|
||
|
|
||
| def inclusive_scan(team_member: TeamMember, view: ViewType, size: int = -1): | ||
| """ | ||
| Perform an inclusive scan on a view using a team member. | ||
|
|
||
| **`team_barrier()` should always be called before accessing scanned data.** | ||
|
|
||
| :param team_member: the team member | ||
| :param view: the view to scan | ||
| :param size: (optional) the number of elements to scan | ||
| """ | ||
| pass |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified to include
inclusive_scan