-
Notifications
You must be signed in to change notification settings - Fork 790
[ESIMD] Fix 'ambiguous operator' error with length 1 simd operands #4149
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s | ||
// expected-no-diagnostics | ||
|
||
// This test checks that compiler does not report 'ambiguous operator' error | ||
// when compiling simd or simd_view operations with lenth = 1. | ||
|
||
#include <sycl/ext/intel/experimental/esimd.hpp> | ||
|
||
#include <cstdint> | ||
|
||
using namespace sycl::ext::intel::experimental::esimd; | ||
|
||
template <typename T1, typename T2> | ||
void test_esimd_ops(simd<T1, 1> a, T2 b, T2 w) SYCL_ESIMD_FUNCTION { | ||
T2 c1 = a[0] * w + b; | ||
T2 c2 = a[0] * T2{2} + b; | ||
T2 c3 = T2{2} * a[0] + b; | ||
T2 d1 = a[0] ^ w; | ||
T2 d2 = a[0] ^ T2 { 2 }; | ||
T2 d3 = T2{2} ^ a[0]; | ||
auto e1 = a[0] < w; | ||
auto e2 = a[0] < T2{2}; | ||
auto e3 = T2{2} < a[0]; | ||
simd<T1, 1> z{4}; | ||
auto f1 = a[0] ^ z; | ||
auto f2 = z ^ a[0]; | ||
auto f3 = a[0] < z; | ||
auto f4 = z < a[0]; | ||
} | ||
|
||
void foo() SYCL_ESIMD_FUNCTION { | ||
test_esimd_ops(simd<uint32_t, 1>(3), (int)1, (int)9); | ||
test_esimd_ops(simd<int, 1>(3), (uint32_t)1, (uint32_t)9); | ||
test_esimd_ops(simd<uint16_t, 1>(3), 1, 9); | ||
test_esimd_ops(simd<int16_t, 1>(3), 1, 9); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As I understood
a[0] + x
was ambiguous when the underlying types were different, right? E.g.,int
anduint32_t
.You resolve it by disabling one of the candidates and rely on implicit conversion to underlying type and built-in operator+ for primitive types.
Can we sink those two BINOP overloads into the derived class of generic
simd_view
implementation? That way I think we don't need this SFINAE trick.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.
not really. int - int causes the failure too. In the test I just modelled the user test case where the types were different.
yes, with length == 1, simd_view_impl and value_type are implicitly convertible to the element type, thus compiler will always be able to resolve
BINOP(const simd_view_impl &, const value_type &)
to the built-in operation over primitive types after implicitly converting both sides.not sure I understand. Do you mean moving BINOP from simd_view_impl to simd_view? That won't affect resolution in any way, since simd_view already binds to simd_view_impl w/o any conversions as simd_view extends simd_view_impl.
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.
Per discussion with @DenisBakhvalov: his suggestion was to move BINOP to simd_view to make them unavailable for the length=1 simd_view specialization. That might make sense, but (1) would be pretty intrusive change at this point (2) my upcoming simd_mask introduction patch refactors operators anyway (none will be friends), so this can be re-visited when reviewing that patch. So we decided to go with the current fix at this point.