Repository navigation
compiler: Misc dtype lowering tweaks #3090
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -635,7 +635,11 @@ def _prepare_arguments(self, autotune=None, estimate_memory=False, **kwargs): | |
|
|
||
| # Process data-carrier overrides | ||
| for p in overrides: | ||
| args.update(p._arg_values(estimate_memory=estimate_memory, **kwargs)) | ||
| values = p._arg_values(estimate_memory=estimate_memory, **kwargs) | ||
| # A replacement may supply defaults for other arguments, such as | ||
| # a ConditionalDimension's factor. Explicit overrides take precedence | ||
| args.update({k: v for k, v in values.items() | ||
|
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. this is gonna get dropped |
||
| if k == p.name or k not in kwargs}) | ||
| try: | ||
| args.reduce_inplace() | ||
| except ValueError as e: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| from devito.symbolics.extended_sympy import CallFromPointer, Cast, DefFunction, Reserved | ||
| from devito.symbolics.queries import q_routine | ||
| from devito.tools import as_tuple, is_integer, prod | ||
| from devito.tools.dtypes_lowering import infer_dtype | ||
| from devito.tools.dtypes_lowering import dtypes_vector_mapper, infer_dtype | ||
|
|
||
| __all__ = ['compare_ops', 'estimate_cost', 'has_integer_args', 'sympy_dtype'] | ||
|
|
||
|
|
@@ -311,7 +311,7 @@ def has_integer_args(*args): | |
|
|
||
| def sympy_dtype(expr, base=None, default=None, smin=None): | ||
| """ | ||
| Infer the dtype of the expression. | ||
| Infer the scalar precision of the expression. | ||
| """ | ||
| if expr is None: | ||
| return default | ||
|
|
@@ -324,6 +324,7 @@ def sympy_dtype(expr, base=None, default=None, smin=None): | |
| if not dtypes or not np.issubdtype(base, np.complexfloating): | ||
| dtypes.update({base} - {None}) | ||
|
|
||
| dtypes = {dtypes_vector_mapper.get_base_dtype(i, i) for i in dtypes} | ||
|
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. second place it's like that, why not move it inside infer_dtype? |
||
| dtype = infer_dtype(dtypes) | ||
|
|
||
| # Promote if we missed complex number, i.e f + I | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,7 +93,7 @@ def add_dtype(self, field_name, count): | |
|
|
||
| def get_base_dtype(self, v, default=None): | ||
| for (base_dtype, _), dtype in self.items(): | ||
| if dtype is v: | ||
| if dtype == v: | ||
| return base_dtype | ||
|
|
||
| if default is not None: | ||
|
|
@@ -364,7 +364,12 @@ def infer_dtype(dtypes): | |
| * In the case of multiple floating dtypes, return the dtype with | ||
| highest precision; | ||
| * If there's at least one floating dtype, ignore any integer dtypes. | ||
|
|
||
| Preserve vector length when combining compatible vector and scalar operands. | ||
| """ | ||
| dtypes = set(dtypes) | ||
| n = max(map(dtype_len, dtypes), default=1) | ||
|
|
||
| # Resolve the vector types, if any | ||
| dtypes = {dtypes_vector_mapper.get_base_dtype(i, i) for i in dtypes} | ||
| # Only keep number types | ||
|
|
@@ -373,19 +378,32 @@ def infer_dtype(dtypes): | |
| fdtypes = {i for i in dtypes if np.issubdtype(i, np.floating) or | ||
| np.issubdtype(i, np.complexfloating)} | ||
| if len(fdtypes) > 1: | ||
| return max(fdtypes, key=lambda i: np.dtype(i).itemsize) | ||
| dtype = max(fdtypes, key=lambda i: np.dtype(i).itemsize) | ||
| elif len(fdtypes) == 1: | ||
| return fdtypes.pop() | ||
| dtype = fdtypes.pop() | ||
| elif len(dtypes) == 1: | ||
| return dtypes.pop() | ||
| dtype = dtypes.pop() | ||
| else: | ||
| # E.g., mixed integer arithmetic | ||
| return max(dtypes, key=lambda i: np.dtype(i).itemsize, default=None) | ||
| dtype = max(dtypes, key=lambda i: np.dtype(i).itemsize, default=None) | ||
|
|
||
| return dtypes_vector_mapper[dtype, n] if n > 1 else dtype | ||
|
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. likely need |
||
|
|
||
|
|
||
| def extract_dtype(expr): | ||
| """Extract the "winning" dtype from an expression""" | ||
| dtypes = {getattr(e, 'dtype', None) | ||
| for e in expr.free_symbols} | ||
| """ | ||
| Extract the result dtype, retaining typed vector operands such as float2. | ||
| """ | ||
| # Arithmetic nodes may expose only their Functions' scalar precision | ||
| if not (expr.is_Add or expr.is_Mul or expr.is_Pow): | ||
|
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. so what does it leave? THis is an off check |
||
| try: | ||
| dtype = expr.dtype | ||
| except AttributeError: | ||
| pass | ||
| else: | ||
| if dtype is not None: | ||
| return dtype | ||
|
|
||
| dtypes = {extract_dtype(i) for i in expr.args} - {None} | ||
|
|
||
| return infer_dtype(dtypes - {None}) | ||
| return infer_dtype(dtypes) | ||
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.
this looks like a bug in _arg_values