These checks have been fired when comparing same elements like comp(a, a). Let's fix it. I don't have commit rights.
Danila Kutenin
kutdanila@yandex.ru
Differential D152152
[mlir][sparse] Fix strict weak ordering in sorting danlark on Jun 5 2023, 6:31 AM. Authored by
Details These checks have been fired when comparing same elements like comp(a, a). Let's fix it. I don't have commit rights. Danila Kutenin
Diff Detail
Event TimelineComment Actions Is there any change to the std::sort that requires such a change? In these two particular cases, there should not be any duplicated item from the array (otherwise, it leads to logical bugs). Comment Actions But do you have a example that trigger this? The sparse compiler has a non-dup property, and we would like to see the example that leads to this? Comment Actions We added checks in debug mode so it deliberately will https://reviews.llvm.org/D150264 In practice if there are more than 30 elements, it could and can (for example, by being a pivot and waiting for the false condition): https://stackoverflow.com/questions/38966516/should-sorting-algorithm-pass-same-element-in-the-comparison-function Comment Actions
I understand the general requirement for sort, but this sort is only used in particular situations by the sparse compiler. So my question is, do you have a test case that would trigger the assert at L35. Comment Actions I was not able to reproduce the issue. If we go down to the specifics of std::sort in LLVM, it should take 25 elements to find when comp(a, a) can be called. If we can make here 25 elements anyhow and reorder them as we want, we can fail it Comment Actions Any update on this? I am of course willing to accept this if needed, but I would really like to see the test case that exposes the new behavior (should not be too hard to set up, if you have any sequence that exposes this, you can simply construct one sparse vector with indices identical to that sequence). Comment Actions I checked and with the new implementation it's impossible to have comp(a, a) in the algorithm itself. My suggestion will be to change the assert to something like assert(std::addressof(l) == std::addressof(r) || l != r); Comment Actions Personally, I'd be a lot more comfortable with instead replacing the assertion with if (LLVM_UNLIKELY(l == r)) return false; which is just short-circuiting what the rest of the comparison function would compute anyways (modulo that it doesn't cause assertion error when l/r doesn't occur in order). Note that LoopId is just unsigned, so there's no funny business going on with the operator== in the for-loop. Comment Actions No, there are 3-4 more, I am unable to fix with my knowledge of llvm. One example is https://github.com/llvm/llvm-project/issues/64121 Comment Actions Ping. Looks like Dialect/SparseTensor/sparse_conv_2d_slice_based.mlir was a flake, I cannot reproduce Comment Actions We changed the std::sort to std::stable_sort in LoopEmitter.cpp@574 to fix some ordering issue a while back, it might have been already resolved.
|
hmm, the i++ was replaced with i
(did this pass tests? :-)
Fixing...