-
Notifications
You must be signed in to change notification settings - Fork 240
compiler: Enhance IR to support more advanced parlang (CUDA/HIP/SYCL) features #2717
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
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
44067bf
compiler: Add FunctionMap type
FabioLuporini 616135e
compiler: Add ULONG to __all__
FabioLuporini 67a2179
compiler: Improve lowering of LocalObjects
FabioLuporini 4a903d3
compiler: Add LocalObject._mem_shared
FabioLuporini 24db970
compiler: Add BitwiseNot and BitwiseXor
FabioLuporini 59ff1bf
compiler: Add LocalType._C_tag
FabioLuporini c5891d2
compiler: Move and enhance FunctionMap
FabioLuporini fec3357
arch: async-loads -> async-pipe
FabioLuporini e54965e
compiler: Fix IREq.__repr__
FabioLuporini 5863361
compiler: Generalize ideriv lowering
FabioLuporini 582784e
compiler: Avoid CSE across Reserved keywords
FabioLuporini 5f680d4
compiler: Introduce Terminal mixin for SymPy subclasses
FabioLuporini eab6282
compiler: Pass ctx down to _map_function_on_high_bw_mem
FabioLuporini ea09060
compiler: Enhance _alloc_object_on_low_lat_mem
FabioLuporini b877bb5
compiler: Fix abstract_object(Array)
FabioLuporini f7c6f97
compiler: Avoid spurious items in sub_iters and dirs
FabioLuporini af2339d
misc: Fix typo
FabioLuporini 0917757
compiler: Pass kwargs to make_parallel
FabioLuporini 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
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 |
---|---|---|
|
@@ -775,17 +775,19 @@ def __init__(self, intervals, sub_iterators=None, directions=None): | |
super().__init__(intervals) | ||
|
||
# Normalize sub-iterators | ||
sub_iterators = dict([(k, tuple(filter_ordered(as_tuple(v)))) | ||
for k, v in (sub_iterators or {}).items()]) | ||
sub_iterators = sub_iterators or {} | ||
sub_iterators = {d: tuple(filter_ordered(as_tuple(v))) | ||
for d, v in sub_iterators.items() if d in self.intervals} | ||
sub_iterators.update({i.dim: () for i in self.intervals | ||
if i.dim not in sub_iterators}) | ||
self._sub_iterators = frozendict(sub_iterators) | ||
|
||
# Normalize directions | ||
if directions is None: | ||
self._directions = frozendict([(i.dim, Any) for i in self.intervals]) | ||
else: | ||
self._directions = frozendict(directions) | ||
directions = directions or {} | ||
directions = {d: v for d, v in directions.items() if d in self.intervals} | ||
directions.update({i.dim: Any for i in self.intervals | ||
if i.dim not in directions}) | ||
self._directions = frozendict(directions) | ||
|
||
def __repr__(self): | ||
ret = ', '.join(["%s%s" % (repr(i), repr(self.directions[i.dim])) | ||
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. Leftover non-fstring |
||
|
@@ -807,8 +809,7 @@ def __lt__(self, other): | |
return len(self.itintervals) < len(other.itintervals) | ||
|
||
def __hash__(self): | ||
return hash((super().__hash__(), self.sub_iterators, | ||
self.directions)) | ||
return hash((super().__hash__(), self.sub_iterators, self.directions)) | ||
|
||
def __contains__(self, d): | ||
try: | ||
|
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 |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
|
||
from collections import OrderedDict | ||
from ctypes import c_uint64 | ||
from functools import singledispatch | ||
from operator import itemgetter | ||
|
||
import numpy as np | ||
|
@@ -97,17 +96,29 @@ def _alloc_object_on_low_lat_mem(self, site, obj, storage): | |
""" | ||
decl = Definition(obj) | ||
|
||
if obj._C_init: | ||
definition = (decl, obj._C_init) | ||
init = obj._C_init | ||
if not init: | ||
definition = decl | ||
efuncs = () | ||
elif isinstance(init, (list, tuple)): | ||
assert len(init) == 2, "Expected (efunc, call)" | ||
init, definition = init | ||
efuncs = (init,) | ||
elif init.is_Callable: | ||
definition = Call(init.name, init.parameters, | ||
retobj=obj if init.retval else None) | ||
efuncs = (init,) | ||
else: | ||
definition = (decl) | ||
definition = (decl, init) | ||
efuncs = () | ||
|
||
frees = obj._C_free | ||
|
||
if obj.free_symbols - {obj}: | ||
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. kwargs = {'objs' if obj.free_symbols - {obj} else 'standalones': definition,
efuncs': efuncs, 'frees': frees}
storage.update(obj, site, **kwargs) perhaps? |
||
storage.update(obj, site, objs=definition, frees=frees) | ||
storage.update(obj, site, objs=definition, efuncs=efuncs, frees=frees) | ||
else: | ||
storage.update(obj, site, standalones=definition, frees=frees) | ||
storage.update(obj, site, standalones=definition, efuncs=efuncs, | ||
frees=frees) | ||
|
||
def _alloc_array_on_low_lat_mem(self, site, obj, storage): | ||
""" | ||
|
@@ -554,7 +565,7 @@ class DeviceAwareDataManager(DataManager): | |
def __init__(self, options=None, **kwargs): | ||
self.gpu_fit = options['gpu-fit'] | ||
self.gpu_create = options['gpu-create'] | ||
self.pmode = options.get('place-transfers') | ||
self.gpu_place_transfers = options.get('place-transfers') | ||
|
||
super().__init__(**kwargs) | ||
|
||
|
@@ -587,7 +598,8 @@ def _map_array_on_high_bw_mem(self, site, obj, storage): | |
|
||
storage.update(obj, site, maps=mmap, unmaps=unmap) | ||
|
||
def _map_function_on_high_bw_mem(self, site, obj, storage, devicerm, read_only=False): | ||
def _map_function_on_high_bw_mem(self, site, obj, storage, devicerm, | ||
read_only=False, **kwargs): | ||
""" | ||
Map a Function already defined in the host memory in to the device high | ||
bandwidth memory. | ||
|
@@ -620,42 +632,41 @@ def _map_function_on_high_bw_mem(self, site, obj, storage, devicerm, read_only=F | |
storage.update(obj, site, maps=mmap, unmaps=unmap, efuncs=efuncs) | ||
|
||
@iet_pass | ||
def place_transfers(self, iet, data_movs=None, **kwargs): | ||
def place_transfers(self, iet, data_movs=None, ctx=None, **kwargs): | ||
""" | ||
Create a new IET with host-device data transfers. This requires mapping | ||
symbols to the suitable memory spaces. | ||
""" | ||
if not self.pmode: | ||
if not self.gpu_place_transfers: | ||
return iet, {} | ||
|
||
@singledispatch | ||
def _place_transfers(iet, data_movs): | ||
if not isinstance(iet, EntryFunction): | ||
return iet, {} | ||
|
||
@_place_transfers.register(EntryFunction) | ||
def _(iet, data_movs): | ||
reads, writes = data_movs | ||
reads, writes = data_movs | ||
|
||
# Special symbol which gives user code control over data deallocations | ||
devicerm = DeviceRM() | ||
# Special symbol which gives user code control over data deallocations | ||
devicerm = DeviceRM() | ||
|
||
storage = Storage() | ||
for i in filter_sorted(writes): | ||
if i.is_Array: | ||
self._map_array_on_high_bw_mem(iet, i, storage) | ||
else: | ||
self._map_function_on_high_bw_mem(iet, i, storage, devicerm) | ||
for i in filter_sorted(reads - writes): | ||
if i.is_Array: | ||
self._map_array_on_high_bw_mem(iet, i, storage) | ||
else: | ||
self._map_function_on_high_bw_mem(iet, i, storage, devicerm, True) | ||
|
||
iet, efuncs = self._inject_definitions(iet, storage) | ||
storage = Storage() | ||
for i in filter_sorted(writes): | ||
if i.is_Array: | ||
self._map_array_on_high_bw_mem(iet, i, storage) | ||
else: | ||
self._map_function_on_high_bw_mem( | ||
iet, i, storage, devicerm, ctx=ctx | ||
) | ||
for i in filter_sorted(reads - writes): | ||
if i.is_Array: | ||
self._map_array_on_high_bw_mem(iet, i, storage) | ||
else: | ||
self._map_function_on_high_bw_mem( | ||
iet, i, storage, devicerm, read_only=True, ctx=ctx | ||
) | ||
|
||
return iet, {'efuncs': efuncs} | ||
iet, efuncs = self._inject_definitions(iet, storage) | ||
|
||
return _place_transfers(iet, data_movs=data_movs) | ||
return iet, {'efuncs': efuncs} | ||
|
||
@iet_pass | ||
def place_devptr(self, iet, **kwargs): | ||
|
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
Oops, something went wrong.
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.
Would it be worth renaming the direction
Any
to avoid potential squatting ontyping.Any
?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.
we should rather ask the python developers to revisit their type hinting crazyness 😂