Skip to content

[ESIMD] Construct simd from simd_view using args deduction guide #4892

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

Closed

Conversation

v-klochkov
Copy link
Contributor

Signed-off-by: Vyacheslav N Klochkov [email protected]

v-klochkov added a commit to DenisBakhvalov/llvm-test-suite that referenced this pull request Nov 4, 2021
@v-klochkov
Copy link
Contributor Author

The E2E test for this patch is this one: intel/llvm-test-suite#454

@@ -137,6 +137,12 @@ template <typename Ty, int N, class Derived, class SFINAE> class simd_obj_impl {
init_from_array(std::move(Arr));
}

/// Construct from simd_view object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe each template and constructor parameter in documentation comment. I know that some of the API lack that, but this should be the general rule, as the ESIMD spec is generated from the doxygen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(did not hit Finish Review yesterday, sorry)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed for the new constructors: b7bc4dc

template <typename T1,
class = std::enable_if_t<detail::is_vectorizable_v<T1>>>
simd(T1 Val) : base_type((Ty)Val) {
__esimd_dbg_print(simd(T1 Val));
}

/// Construct from simd_view.
template <int ViewedSimdLength, typename RegionT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b7bc4dc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Seems like this is almost complete copy-paste of the simd_obj_impl variant. I missed that in the first review, unfortunately. Can duplication be somehow avoided? E.g. this simd variant just refers to the simd_obj_impl variant?

One more thing that I missed is simd_mask - it should also have this kind of constructor. I wonder if it is enough just to define that constructor in a generic way so that it is automatically inherited from simd_obj_impl by both simd and simd_mask w/o the need to define this constructor explicitly in them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it can be deleted, I'll do that.

Need to add though that the deduction guide needs to be defined for 'simd' class, not for 'simd_obj_impl'.
Having something like this will now work for the assignment: "simd_view SV = V; simd V1 = SV":

// Deduction guide for 'simd_obj_impl' constructor from a 'simd_view' object.
// It helps to infer the template parameter 'N' of the class 'simd_obj_impl'.
template <typename T, int ViewedSimdLength, typename RegionT>
simd_obj_impl(simd_view<simd<T, ViewedSimdLength>, RegionT>) -> simd_obj_impl<T, RegionT::length, simd<T, RegionT::length>>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more note: the mentioned 'simd' constructor can be deleted only because of this statement in simd class:

using base_type::base_type;

The same for 'simd -> simd_view' is not doable because 'simd_view' does not have such 'using' statement and the following ctor cannot be removed:
https://github.com/intel/llvm/blob/sycl/sycl/include/sycl/ext/intel/experimental/esimd/simd_view.hpp#L76

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the 'simd_mask' and doing the arguments deduction for it...
Currently, 'simd_mask' is declared as an alias template, not as a template class and thus the template args deduction guides do not work for it.

simd_mask<16> m16 = 0;
auto mask_view8 = m16.select<8, 1>(0);

detail::simd_mask_impl m8 = mask_view8; // Works well with some changes in headers
simd_mask m8 = mask_view8; // Does not work. The error is: "error: alias template 'simd_mask' requires template arguments; argument deduction only allowed for class templates"

I don't know why simd_mask is not defined as a class instead of an alias to a class in detail namespace.
Anyway, tackling this problem for simd_mask deserves a separate PR, IMO.

Signed-off-by: Vyacheslav N Klochkov <[email protected]>
@kbobrovs
Copy link
Contributor

kbobrovs commented Nov 4, 2021

The E2E test for this patch is this one: intel/llvm-test-suite#454

This PR does not seem to have a test case for simd construction from a simd_view - am I missing something?

@v-klochkov
Copy link
Contributor Author

The E2E test for this patch is this one: intel/llvm-test-suite#454

This PR does not seem to have a test case for simd construction from a simd_view - am I missing something?

The line 139 of the test there: "simd vb = vb_view;" tests this new constructor + deduction guide. That test fails without this PR. See the log: http://icl-jenkins.sc.intel.com:8080/blue/organizations/jenkins/LLVM-Test-Suite-CI-TMP%2FLLVM-Test-Suite-CI-Linux/detail/LLVM-Test-Suite-CI-Linux/908/pipeline

@kbobrovs
Copy link
Contributor

kbobrovs commented Nov 4, 2021

The E2E test for this patch is this one: intel/llvm-test-suite#454

This PR does not seem to have a test case for simd construction from a simd_view - am I missing something?

The line 139 of the test there: "simd vb = vb_view;" tests this new constructor + deduction guide. That test fails without this PR. See the log: http://icl-jenkins.sc.intel.com:8080/blue/organizations/jenkins/LLVM-Test-Suite-CI-TMP%2FLLVM-Test-Suite-CI-Linux/detail/LLVM-Test-Suite-CI-Linux/908/pipeline

I see, thanks for the pointer.

v-klochkov added a commit to DenisBakhvalov/llvm-test-suite that referenced this pull request Dec 17, 2021
@v-klochkov v-klochkov requested a review from a team as a code owner January 21, 2022 03:41
@keryell
Copy link
Contributor

keryell commented Apr 20, 2022

I have recently watched SIMD in C++20 - EVE of a new Era - Joël Falcou - CPPP 2021 on https://github.com/jfalcou/eve by @jfalcou and there are a lot of interesting design ideas which might be useful in some SYCL SIMD 1D & 2D extensions.
Just adding this here since I do not know where to mention it. :-)

@kbobrovs
Copy link
Contributor

I have recently watched SIMD in C++20 - EVE of a new Era - Joël Falcou - CPPP 2021 on https://github.com/jfalcou/eve by @jfalcou and there are a lot of interesting design ideas which might be useful in some SYCL SIMD 1D & 2D extensions. Just adding this here since I do not know where to mention it. :-)

Thanks, can be helpful indeed.

@github-actions github-actions bot added the Stale label Oct 18, 2022
@github-actions github-actions bot closed this Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants