-
Notifications
You must be signed in to change notification settings - Fork 60
Ensure Consistency among Data Accesses in the same Thread Block #551
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
11bfd0f
wip
caiomcbr cb51bee
wip
caiomcbr d0d1210
wip
caiomcbr 4d6e173
wip
caiomcbr c2bf3e6
wip
caiomcbr 877ac45
wip
caiomcbr 377dbe9
wip
caiomcbr 12f739c
wip
caiomcbr b117833
wip
caiomcbr 6fab08f
wip
caiomcbr 0f2404e
wip
caiomcbr 993d190
WIP
Binyang2014 dd4edc4
wip
caiomcbr 603ca3c
wip
caiomcbr 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from sortedcontainers import SortedDict | ||
caiomcbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from typing import List | ||
from mscclpp.language.internal.types import BufferType, DataAccessType | ||
from mscclpp.language.internal.operations import * | ||
from enum import Enum | ||
|
||
|
||
class BuffersAccess: | ||
def __init__(self): | ||
self.intervals = { | ||
BufferType.input: SortedDict(), | ||
BufferType.output: SortedDict(), | ||
BufferType.scratch: SortedDict(), | ||
} | ||
|
||
def process_operations(self, operations): | ||
result_operations = [] | ||
for operation in operations: | ||
if operation.name == Instruction.nop or operation.name == Instruction.barrier: | ||
self.clear_data_access() | ||
else: | ||
data_access = operation.local_data_access() | ||
sync_added = False | ||
for data_access_element in data_access: | ||
if self.compute_data_access(data_access_element) and not sync_added: | ||
result_operations.append(SyncOperation()) | ||
sync_added = True | ||
|
||
result_operations.append(operation) | ||
|
||
return result_operations | ||
|
||
def compute_data_access(self, data_access: DataAccess) -> bool: | ||
keys = self.intervals[data_access.buffer_type].keys() | ||
idx = self.lower_bound(0, len(keys) - 1, keys, data_access) | ||
conflict = False | ||
|
||
while len(keys) > 0 and data_access.overlaps(keys[idx]): | ||
conflict_data_access = keys[idx] | ||
conflict_operation_type = self.intervals[data_access.buffer_type][conflict_data_access] | ||
if data_access.check_conflict(conflict_data_access): | ||
self.clear_data_access() | ||
conflict = True | ||
break | ||
|
||
self.intervals[data_access.buffer_type].pop(conflict_data_access) | ||
if conflict_data_access.end > data_access.end: | ||
self.intervals[data_access.buffer_type][ | ||
DataAccess( | ||
conflict_data_access.operation_id, | ||
data_access.end + 1, | ||
conflict_data_access.end, | ||
conflict_data_access.buffer_type, | ||
conflict_operation_type, | ||
) | ||
] = conflict_operation_type | ||
if conflict_data_access.start < data_access.start: | ||
self.intervals[data_access.buffer_type][ | ||
DataAccess( | ||
conflict_data_access.operation_id, | ||
conflict_data_access.start, | ||
data_access.start - 1, | ||
conflict_data_access.buffer_type, | ||
conflict_operation_type, | ||
) | ||
] = conflict_operation_type | ||
|
||
keys = self.intervals[data_access.buffer_type].keys() | ||
idx = self.lower_bound(0, len(keys) - 1, keys, data_access) | ||
|
||
self.intervals[data_access.buffer_type][data_access] = data_access.data_access_type | ||
return conflict | ||
|
||
def clear_data_access(self): | ||
self.intervals[BufferType.input].clear() | ||
self.intervals[BufferType.output].clear() | ||
self.intervals[BufferType.scratch].clear() | ||
|
||
def lower_bound(self, init_pos, final_pos, data_access_list, data_access): | ||
if init_pos >= final_pos: | ||
return init_pos | ||
|
||
mid_pos = (init_pos + final_pos) // 2 | ||
if data_access.start <= data_access_list[mid_pos].end: | ||
final_pos = mid_pos | ||
else: | ||
init_pos = mid_pos + 1 | ||
return self.lower_bound(init_pos, final_pos, data_access_list, data_access) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.