Repository navigation
compiler: Misc tweaks to fully support FP16 storage/compute across all backends - #3109
FabioLuporini wants to merge 20 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3109 +/- ##
==========================================
+ Coverage 83.96% 84.04% +0.08%
==========================================
Files 261 261
Lines 60017 60238 +221
Branches 5065 5088 +23
==========================================
+ Hits 50393 50629 +236
+ Misses 8780 8762 -18
- Partials 844 847 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
9645b9a to
d500a13
Compare
| f = alias or self.target.c0 | ||
| neighborhood = f.grid.distributor.neighborhood | ||
| # Internal Arrays may retain a serialized, non-distributed Grid | ||
| neighborhood = args.grid.distributor.neighborhood |
There was a problem hiding this comment.
This gets rehashed in #3108 . Also pretty sure this is undoing a functions on subdomains bug that got patched...
| def _eval_is_integer(self): | ||
| dtype = extract_dtype(self.value) | ||
| if (self.value.is_integer or | ||
| isinstance(dtype, type) and issubclass(dtype, np.integer)): |
There was a problem hiding this comment.
Why would dtype not be a type?
| return self._dtype | ||
| ctype = self.dtype_base | ||
| if isinstance(ctype, CustomDtype): | ||
| return CustomDtype(ctype.name, ctype.template, ctype.modifier + self.stars) |
There was a problem hiding this comment.
Given that this is returning a new CustomDtype, does this property need caching to avoid duplication?
| op = Operator(Eq(f, f + 1), sym_opt=options) | ||
|
|
||
| assert op._sym_options['arithm-mode'] == mode | ||
| assert 'half-arith' not in op._sym_options |
There was a problem hiding this comment.
Seems a bit redundant to check the old name isn't in there?
| assert options == {'arithm-mode': mode} | ||
|
|
||
| @pytest.mark.parametrize('mode', [None, False, True, 1, 'float16', {}, []]) | ||
| def test_invalid_arithmetic_mode(self, mode): |
There was a problem hiding this comment.
Probably an overkill test?
| assert op1._soname == op2._soname | ||
|
|
||
| @pytest.mark.parametrize('mode', ['default', 'fp16']) | ||
| def test_jit_compiler_abi(self, mode, monkeypatch): |
There was a problem hiding this comment.
Try to avoid monkeypatching?
ec48742 to
6d18720
Compare
| return expr.func(*args) | ||
|
|
||
|
|
||
| @_uxreplace_handle.register(OrderedAdd) |
There was a problem hiding this comment.
Makes no sense OrderedAdd is an Add why doesn't the dispatch already do that
There was a problem hiding this comment.
that's exactly the point ; a plain Add, like also a sympy.Add, is subjected to reordering of the arguments based on the canonical ordering. Here we want to bypass that , so that if u have an Add a+b+c and then a substitution a->z so that u get z+b+c, then you remain with z+b+c, instead of b+c+z
There was a problem hiding this comment.
ah, maybe UnevaluatedAdd already did that? will look into this...
| def __getstate__(self): | ||
| state = dict(self.__dict__) | ||
| # Recreate process-local ctypes classes from the Function's dtype | ||
| state.pop('_C_ctype', None) |
There was a problem hiding this comment.
would be better if Pickable implementent something like _ignored_state so that don't need to add __getstate__ everywhere and just
_ignored_state = '_C_ctype`.
would extend to a bunch of place wehre we have stuff like that
|
|
||
| def test_dereference_base_plus_off(): | ||
| ptr = Pointer(name='p', dtype=np.float32) | ||
| ptr = Pointer(name='p', dtype_base=c_float) |
There was a problem hiding this comment.
Why would we used lowered ctypes instead of the numpy dtype and lower it like for everything else?
| __new__ = UnevaluableMixin.__new__ | ||
|
|
||
|
|
||
| class OrderedAdd(Add): |
There was a problem hiding this comment.
Not sure I appreciate why we need yet another class. Making UnevaluatedAdd ordered would make things much simpler and i doubt it would create issues.
There was a problem hiding this comment.
I can look into this. I may simply have forgotten how UnevaluatedAdd behaved
| return self._dtype | ||
| ctype = self.dtype_base | ||
| if isinstance(ctype, CustomDtype): | ||
| return CustomDtype(ctype.name, ctype.template, ctype.modifier + self.stars) |
There was a problem hiding this comment.
Why does it need to create a new one insted of letting the printer handle the stars like for Cast
c6f3d1a to
c8bf5ee
Compare
|
Notebooks changed:
Review visual diffs and comment on any notebook cell. All comments sync back to this PR. Powered by ReviewNB |
95db547 to
b1bac8d
Compare
Copilot now supplies saved Function replacements with matching ConditionalDimension factors, so the broad override filter is unnecessary.
Use arithm-mode throughout symbolic lowering and include generated source and compiler ABI in every Operator signature. Preserve scalar component and cast-pointer result types for ordinary packed accesses. Validate focused CPU typing, JIT identity and serialization checks, plus the dependent PRO GPU arithmetic checks.
Store the picklable pointee type and indirection in standard reconstruction metadata, deriving the full ctype on demand. Remove the custom ctypes pointer reducer and cover pointer depth, equality, scope and serialization.
Resolve MPI neighbors from the execution Grid so reconstructed internal Arrays communicate between decoupler workers. Also wrap the overlong symbolic-test imports.
Return a conservative result for C-only types such as size_t instead of passing NumPy's TypeError through FP16 code generation. Cover numeric ctypes and opaque dtypes in scalar and mixed argument queries. Validation: 9 targeted OSS symbolic tests, 12 CUDA regression and adjacent tests, isort, Flake8, and Ruff.
Select the RHS precision before creating an exact-precision printer and forward normalized Operator options to dtype-specific lowering passes.
Keep marked sums and products opaque to CSE and factorization, and preserve their stored operand order when printing. Dedicated uxreplace handlers retain the existing scalar reconstruction semantics. Cover FP16/FP32 printing, substitutions and Operator factorization.
Allow make_callable to instantiate a semantic Callable subclass and expose known cast access widths through cached metadata. Represent inline device helpers as DeviceFunctions alongside kernels. Validated with OSS symbolic regressions and PRO CPU/CUDA Operator tests.
b1bac8d to
07a2e2c
Compare
| elif product in getattr(self, 'math_macros', ()): | ||
| # Let SymPy print named constants such as `M_PI_2` | ||
| term = super()._print_Mul(product) | ||
| else: | ||
| prec = precedence(product) | ||
| if self.order in ('old', 'none'): | ||
| args = sympy.Mul.make_args(product) | ||
| else: | ||
| args = product.as_ordered_factors() | ||
|
|
||
| numerator, denominator = [], [] | ||
| for a in args: | ||
| if a.is_Pow and a.is_commutative and \ | ||
| a.exp.is_Rational and a.exp.is_negative: | ||
| base, exp = a.args | ||
| if exp != -1: | ||
| base = sympy.Pow(base, -exp, evaluate=False) | ||
| denominator.append(self.parenthesize(base, prec)) | ||
| else: | ||
| numerator.append(self.parenthesize(a, prec)) | ||
|
|
||
| term = '*'.join(numerator) or self._print(S.One) | ||
| if len(denominator) == 1: | ||
| term += f'/{denominator[0]}' | ||
| elif denominator: | ||
| term += f"/({'*'.join(denominator)})" |
There was a problem hiding this comment.
This is a lot of extra complexity without any clear explanation of what it's doing
| # E.g., unsympified `int` | ||
| args, eargs = [], [] | ||
| changed = False | ||
| changed = expr.__class__ in rule |
There was a problem hiding this comment.
Grab the # Exact type -> type substitution comment from before
| state = ret[2] if len(ret) > 2 else None | ||
| if state is None: | ||
| state = self.__dict__ | ||
| ignored = as_tuple(self.__rignored__) |
There was a problem hiding this comment.
Why not just set __rignored__ as a tuple consistently in the first place?
|
|
||
| class AbiCompiler(GNUCompiler): | ||
|
|
||
| """Give identically configured compilers distinct ABIs through their names.""" |
No description provided.