-
Notifications
You must be signed in to change notification settings - Fork 256
compiler: Enhance IR to support more advanced parlang (CUDA/HIP/SYCL) features #2708
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
Changes from all commits
3a537eb
477540a
2c1e10b
810ab33
d548cdf
015c565
2ad006d
6764272
5b35bcd
2ba1d10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| from sympy import S | ||
| import numpy as np | ||
|
|
||
| from devito.finite_differences import IndexDerivative | ||
| from devito.finite_differences import IndexDerivative, Weights | ||
| from devito.ir import Backward, Forward, Interval, IterationSpace, Queue | ||
| from devito.passes.clusters.misc import fuse | ||
| from devito.symbolics import BasicWrapperMixin, reuse_if_untouched, uxreplace | ||
|
|
@@ -94,17 +94,39 @@ def _core(expr, c, ispace, weights, reusables, mapper, **kwargs): | |
|
|
||
|
|
||
| @_core.register(Symbol) | ||
| @_core.register(Indexed) | ||
| @_core.register(BasicWrapperMixin) | ||
| def _(expr, c, ispace, weights, reusables, mapper, **kwargs): | ||
| return expr, [] | ||
|
|
||
|
|
||
| @_core.register(Indexed) | ||
| def _(expr, c, ispace, weights, reusables, mapper, **kwargs): | ||
| if not isinstance(expr.function, Weights): | ||
| return expr, [] | ||
|
|
||
| # Lower or reuse a previously lowered Weights array | ||
| sregistry = kwargs['sregistry'] | ||
| subs_user = kwargs['subs'] | ||
|
|
||
| w0 = expr.function | ||
| k = tuple(w0.weights) | ||
| try: | ||
| w = weights[k] | ||
| except KeyError: | ||
| name = sregistry.make_name(prefix='w') | ||
| dtype = infer_dtype([w0.dtype, c.dtype]) # At least np.float32 | ||
|
Contributor
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.
Is this guaranteed somehow?
Contributor
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. yes, w0.dtype basically |
||
| initvalue = tuple(i.subs(subs_user) for i in k) | ||
| w = weights[k] = w0._rebuild(name=name, dtype=dtype, initvalue=initvalue) | ||
|
|
||
| rebuilt = expr._subs(w0.indexed, w.indexed) | ||
|
|
||
| return rebuilt, [] | ||
|
|
||
|
|
||
| @_core.register(IndexDerivative) | ||
| def _(expr, c, ispace, weights, reusables, mapper, **kwargs): | ||
| sregistry = kwargs['sregistry'] | ||
| options = kwargs['options'] | ||
| subs_user = kwargs['subs'] | ||
|
|
||
| try: | ||
| cbk0 = deriv_schedule_registry[options['deriv-schedule']] | ||
|
|
@@ -117,18 +139,10 @@ def _(expr, c, ispace, weights, reusables, mapper, **kwargs): | |
|
|
||
| # Create the concrete Weights array, or reuse an already existing one | ||
| # if possible | ||
| name = sregistry.make_name(prefix='w') | ||
| w0 = ideriv.weights.function | ||
| dtype = infer_dtype([w0.dtype, c.dtype]) # At least np.float32 | ||
| k = tuple(w0.weights) | ||
| try: | ||
| w = weights[k] | ||
| except KeyError: | ||
| initvalue = tuple(i.subs(subs_user) for i in k) | ||
| w = weights[k] = w0._rebuild(name=name, dtype=dtype, initvalue=initvalue) | ||
| w, _ = _core(ideriv.weights, c, ispace, weights, reusables, mapper, **kwargs) | ||
|
|
||
| # Replace the abstract Weights array with the concrete one | ||
| subs = {w0.indexed: w.indexed} | ||
| subs = {ideriv.weights.base: w.base} | ||
| init = uxreplace(init, subs) | ||
| ideriv = uxreplace(ideriv, subs) | ||
|
|
||
|
|
@@ -158,10 +172,10 @@ def _(expr, c, ispace, weights, reusables, mapper, **kwargs): | |
| # NOTE: created before recurring so that we ultimately get a sound ordering | ||
|
Contributor
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. "recurring" -> "recursing"? |
||
| try: | ||
| s = reusables.pop() | ||
| assert np.can_cast(s.dtype, dtype) | ||
| assert np.can_cast(s.dtype, w.dtype) | ||
| except KeyError: | ||
| name = sregistry.make_name(prefix='r') | ||
| s = Symbol(name=name, dtype=dtype) | ||
| s = Symbol(name=name, dtype=w.dtype) | ||
|
|
||
| # Go inside `expr` and recursively lower any nested IndexDerivatives | ||
| expr, processed = _core(expr, c, ispace1, weights, reusables, mapper, **kwargs) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1875,8 +1875,17 @@ def _mem_internal_lazy(self): | |
| return self._liveness == 'lazy' | ||
|
|
||
| """ | ||
| A modifier added to the subclass C declaration when it appears | ||
| in a function signature. For example, a subclass might define `_C_modifier = '&'` | ||
| A modifier added to the declaration of the LocalType when it appears in a | ||
| function signature. For example, a subclass might define `_C_modifier = '&'` | ||
| to impose pass-by-reference semantics. | ||
| """ | ||
| _C_modifier = None | ||
|
|
||
| """ | ||
| One or more optional keywords added to the declaration of the LocalType | ||
| in between the type and the variable name when it appears in a function | ||
| signature. For example, some languages support these to modify the way | ||
| the compiler generates code for passing the parameter and how the | ||
| runtime accesses it. | ||
| """ | ||
| _C_tag = None | ||
|
Contributor
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. this is something pro specific?
Contributor
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. used by PRO yes |
||
Uh oh!
There was an error while loading. Please reload this page.