Skip to content

Conversation

@kbobrovs
Copy link
Contributor

@kbobrovs kbobrovs commented Apr 16, 2021

[ESIMD] Make all simd_view constructors non-public.

This addresses long due ESIMD library review comments below.
This may break backward compatibility, as some of the public APIs are removed. But ESIMD is experimental feature, this is allowed.
Real impact should be negligible, as simd_view objects are most conveniently created with select API.

// TODO @rolandschulz
// {quote}
// Why is this and the next constructor public ? Those should only be called
// internally by e.g.select, correct ?
// {/quote}

// TODO @rolandschulz
// {quote}
// Is this intentional not a correct copy constructor (would need to be const
// for that)? I believe we agreed that simd_view would have a deleted copy and
// move constructor.Why are they suddenly back ?
// {/quote}

Signed-off-by: kbobrovs [email protected]

[ESIMD] Make all simd_view constructors non-public.

This addresses long due ESIMD library review comments:

// TODO @rolandschulz
// {quote}
// Why is this and the next constructor public ? Those should only be called
// internally by e.g.select, correct ?
// {/quote}

// TODO @rolandschulz
// {quote}
// Is this intentional not a correct copy constructor (would need to be const
// for that)? I believe we agreed that simd_view would have a deleted copy and
// move constructor.Why are they suddenly back ?
// {/quote}
@kbobrovs kbobrovs force-pushed the kbobrovs-simd_view-move-ctor branch from 9ed5b45 to 922ae96 Compare April 16, 2021 08:35
@kbobrovs kbobrovs changed the title Signed-off-by: kbobrovs <[email protected]> [ESIMD] Make all simd_view constructors non-public. Apr 16, 2021
/// \ingroup sycl_esimd
template <typename BaseTy, typename RegionTy> class simd_view {
template <typename, int> friend class simd;
template <typename, typename> friend class simd_view;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed? Looks like you're trying to make a class be a friend of itself.

Copy link
Contributor Author

@kbobrovs kbobrovs Apr 17, 2021

Choose a reason for hiding this comment

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

Yes, this is needed. Otherwise you can't access private members - such as private constructors - from member functions.
Note that this is not a class, this is templated class. Each instantiation generates unrelated class which are not friends to each other, unless explicitly declared so.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. This is to allow accessing private constructors from different template instantiations of a class. Makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just in case, I would like to confirm this with C++/FE experts, since it caught your and @pvchupin 's eyes.

@erichkeane, can you please take a look if this friend template class declaration below is a good way to allow
calling private constructor from select:

template <typename BaseTy, typename RegionTy> class simd_view {
  template <typename, typename> friend class simd_view; // <=== all simd_view instantiations are friends
  ...
private:
  simd_view(BaseTy &Base, RegionTy Region) : M_base(Base), M_region(Region) {}
  simd_view(BaseTy &&Base, RegionTy Region) : M_base(Base), M_region(Region) {}

public:
  template <int Size, int Stride, typename T = simd_view,
            typename = sycl::detail::enable_if_t<T::is1D()>>
  auto select(uint16_t Offset = 0) {
    using TopRegionTy = region1d_t<element_type, Size, Stride>;
    using NewRegionTy = std::pair<TopRegionTy, RegionTy>;
    using RetTy = simd_view<BaseTy, NewRegionTy>; // <======= call private constructor
    TopRegionTy TopReg(Offset);
    return RetTy{this->M_base, std::make_pair(TopReg, M_region)};
  }
  ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, thats a pretty typical way to do that. Note that the line you have labeled as 'call private constructor' isn't actually doing the call! That is a 'using' statement. It appears the 'return' line 2 lines lower is the one actually calling the private constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Yes, I should've put the comment below to return of course.

@kbobrovs kbobrovs requested a review from DenisBakhvalov April 17, 2021 06:31
Copy link
Contributor

@pvchupin pvchupin left a comment

Choose a reason for hiding this comment

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

Red left hand side reworked looks ok to me.

simd_view(simd_view &Other) = delete;
simd_view(simd_view &&Other)
: M_base(Other.M_base), M_region(Other.M_region) {}
public:
Copy link
Contributor

Choose a reason for hiding this comment

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

Side note: access specifiers of deleted constructors is pretty meaningless here. This 'public' doesn't actually do anything as far as I remember.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is just restoring the visibility for the following members (conversion, assignments,...) after injected private for the two constructors.

@kbobrovs kbobrovs merged commit e4c82cc into intel:sycl Apr 18, 2021
@kbobrovs kbobrovs deleted the kbobrovs-simd_view-move-ctor branch April 18, 2021 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants