Conversation
| def __neg__(self): | ||
| self._checkMultipleScalarMults() | ||
| return ScalarMultiplication(-1.0, self) | ||
| return -1.0 * self |
There was a problem hiding this comment.
Why don't we need to check multiple scalar units here?
There was a problem hiding this comment.
That's done via __rmul__ calling __mul__; there we auto-merge with existing scalar multiplications. If we don't have a scalar multiplication, then the old and the new version behave identically (i.e. __mul__ creates a ScalarMultiplication node).
EDIT: that didn't happen so far; nevermind. Both should be completely identical.
The previous implementation (i.e. self._checkMultipleScalarMults()) just aborted at that point instead.
(that said—the case (a * A) * (b * B) should, by tracing the code paths, also still fail with the new version, instead of turning it into (a * b) * A * B or the likes ... Though that might also be rather straight-forward to fix I think)
vikaskurapati
left a comment
There was a problem hiding this comment.
Seems good to me from what I understand. Could some small test be added for this?
Did you check SeisSol along with this version of YaTeTo to check that there were no issues?
|
That issue didn't occur in SeisSol so far iirc (or only the non-changed code path); I fixed this issue due to an external comment (from tandem). But yeah; I've added a Yateto self test for that issue. (which does, albeit, not yet check if the result also conforms with what we'd really "expect"; i.e. with pre-computed test data—that'll probably be more work to set up properly) |
da20527 to
6707b39
Compare
|
Ok; nevermind all that. Turns out the whole issue will still need a tiny bit more work—probably more like a pass that'll merge scalar multiplications and/or ad-hoc multiply them before an operation (it's doable; but it'll take me a tiny bit more time—I'm setting everything back to draft for now). |
This may be an unrelated comment, but do the current tests with YaTeTo have tests that are generic enough to ensure functionalities across different software packages? And do you think it is a good idea to invite developers from Tandem, e.g., Piyush, to check such PRs which were intended for them. This may help with testing respective features.
I don't fully understand this comment, tbh, but that's probably due to my limited knowledge of the entire software package. But what is the self-test check that is currently implemented? And if we could actually check with something we know is correct as a test, it would be great, imo. |
Yeah, we can do that imo. Reagarding the tests: we do check different CPU codegen packages right now; but not so much GPU codegen packages—mostly due to the instability of the CI and hardware access. (probably, CUDA/AdaptiveCpp would be possible to test against)
The self-test is currently implemented IIRC as follows: take some pseudo-random initialization data, and compute the reference solution from the un-optimized kernels (i.e. no matrix multiplication/tensor contraction optimization; everything might as well be one big loop). Testing that is possible, if you were to manually implement some kernels yourselves and compare against the kernel you'd get. Not 100%ly sure how to best do it idiomatically; it can range from just having a C++ file with some kernels and the sample solutions coded in there, to providing extra test cases for Yateto (e.g. just provide data for all tensors you'd expect as input and output—but you're yourself responsible for supplying the correct input data). |
Okay. Any checks possible would be nice to have, for sure. If you are worried about bloating the test suite too much, we could then choose the more important ones and turn off the non-important ones later on.
Okay. I am just thinking out loud here: Could we, in that case, implement some basic checks as tests, for example, multiplying a random matrix by an identity should always return the same matrix, etc.? Or something similar, which are simple to implement but we know that they should be this way?
This sounds okay to me, imo. Maybe we could take a few matrices from SeisSol, and check against what we expect in those scenarios? We could have a more extensive discussion about it later if you want. |
Just for the sake of information, I added @piyushkarki with write access. |
(by the way—I've run the current Yateto-internal tests for SeisSol for all kernels (i.e. all orders, equations, precisions, etc.) on the CPU in SeisSol/#1421—they basically all passed save for about six with some slightly too big relative errors in some extreme cases—which might also come from the unit test implementation) |
Fix e.g.
A - a * B.(it's decomposed into
-1.0 * (a * B)which in turn was not allowed by the__neg__operator—but the__mul__operator did allow it)