Skip to content

[onedpl][ranges] L3 Range based algo API and implementation (memory group) #2292

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

Open
wants to merge 77 commits into
base: main
Choose a base branch
from

Conversation

MikeDvorskiy
Copy link
Contributor

[onedpl][ranges] L3 Range based algo API and implementation (memory group)

@MikeDvorskiy MikeDvorskiy marked this pull request as draft June 2, 2025 15:41
@MikeDvorskiy MikeDvorskiy force-pushed the dev/mdvorski/ranges_algo_L3_memory-origin_UXL branch 4 times, most recently from 606f4fa to 39d183b Compare June 3, 2025 13:31
@MikeDvorskiy MikeDvorskiy marked this pull request as ready for review June 3, 2025 15:18
@MikeDvorskiy MikeDvorskiy force-pushed the dev/mdvorski/ranges_algo_L3_memory-origin_UXL branch 3 times, most recently from 22f1c16 to 0ec2d06 Compare June 4, 2025 15:11
@MikeDvorskiy MikeDvorskiy force-pushed the dev/mdvorski/ranges_algo_L3_memory-origin_UXL branch from 0ec2d06 to 470f339 Compare June 10, 2025 14:46
int val1; //value initialization
int val2;

Elem_0(): val1() {}
Copy link
Contributor

@SergeyKopienko SergeyKopienko Jun 11, 2025

Choose a reason for hiding this comment

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

Can you explain in comments the idea of works with structure in which data is uninitialized and from this point may have any state?

Copy link
Contributor

Choose a reason for hiding this comment

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

int will be set to 0 due to zero-initialization (a sub-case of value initialization). I've corrected the comment above and moved it to this line for clarity.


oneapi::dpl::uninitialized_fill(std::forward<_ExecutionPolicy>(__exec), __first, __last, __value);

return {__last};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return {__last};
return __last;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

{} is written intentionally, because it is equivalent to std::ranges::borrowed_iterator_t<_R>{__last} (see the return type for the function).

Copy link
Contributor

Choose a reason for hiding this comment

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

Will we have compile error in the next case?

    return __last;

Copy link
Contributor

Choose a reason for hiding this comment

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

Just for note: practically we never have returns with this form for cases when we return one value, as I seen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • return __last; tells the function returns an instance of "decltype(__last)"
  • return {__last}; tells the function returns an instance of new type (return type), which is created from __last.

Copy link
Contributor

@dmitriy-sobolev dmitriy-sobolev Jun 12, 2025

Choose a reason for hiding this comment

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

My two cents:

  • I like (1) when a function is short: no duplication, you see the return type and {} suggests that is it not the type of __last.
  • I do not like (2). It is as (1) but it does not benefit from {}. Adding {} is not that extra number of symbol we should avoid.
  • I do not like (3), because I think that having the return type in the function signature is more important.
  • I like (4) when a function is large.

It's mostly a matter of preference (and now looks like bikeshedding), but __pattern_uninitialized_fill is small, so I vote for (1).

Copy link
Contributor

@SergeyKopienko SergeyKopienko Jun 12, 2025

Choose a reason for hiding this comment

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

Probably it's a good topic to discuss shortly on our meeting.

UPD: the option (1) described at https://en.cppreference.com/w/cpp/language/list_initialization.html
And this variant has strongly defined semantic when make sense to apply in.
As far as we haven't compile errors here there is no reasons to apply it in the discussing cases I believe.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree here fully with @dmitriy-sobolev . (1) when short, (4) when large.

I think these options make the code most clear and readable, which is my rule of thumb.

Copy link
Contributor

Choose a reason for hiding this comment

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

After some discussion with @SergeyKopienko offline and exploring with godbolt, I realized that (1) is not explicitly invoking the constructor, but rather creating an initializer list, and then still using implicit construction of the return type from that initializer list.

https://godbolt.org/z/dTo84fooz

While not the exact same error message, (1) and (2) both don't work with explicit constructors. I guess (1) may give the perception that the type will be changing, (1) is not a shorthand equivalent to (4).

So, I guess perhaps I prefer (4) generally. For short functions, I think (1) and (2) are both fine, its probably not worth a whole lot more time discussing.

Copy link
Contributor

Choose a reason for hiding this comment

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

...from cppreference.com :

https://en.cppreference.com/w/cpp/language/return.html

2) Uses [copy-list-initialization](https://en.cppreference.com/w/cpp/language/list_initialization.html) to construct the return value of the function.

https://en.cppreference.com/w/cpp/language/list_initialization.html

8) in a return statement with a brace-enclosed initializer list used as the return expression and list-initialization initializes the returned object

@MikeDvorskiy MikeDvorskiy force-pushed the dev/mdvorski/ranges_algo_L3_memory-origin_UXL branch 3 times, most recently from ee23b56 to 9aad8b3 Compare June 12, 2025 10:28
int val1;
int val2;

Elem() { val1 = 1; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have additional comments in the code why we don't initialize each field in constructors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Added a comment:

// It is sufficient to initialize only one field, the other can be used to verify that the raw memory is correctly set

Actually, I do not see strong reasons to have multiple members, but I suggest leaving it as it is. A side effect is checking the internal test infrastructure where it sets the raw memory.

@MikeDvorskiy MikeDvorskiy force-pushed the dev/mdvorski/ranges_algo_L3_memory-origin_UXL branch from 3db16f1 to 80e2660 Compare June 23, 2025 10:26
@dmitriy-sobolev dmitriy-sobolev force-pushed the dev/mdvorski/ranges_algo_L3_memory-origin_UXL branch from 80e2660 to be1d1a7 Compare July 29, 2025 14:48
MikeDvorskiy and others added 26 commits July 29, 2025 22:59
…t_symmetric_difference, high level API"

This reverts commit 42a98e8.
…anges::set_intersection high level API"

This reverts commit c3f437e.
@dmitriy-sobolev dmitriy-sobolev force-pushed the dev/mdvorski/ranges_algo_L3_memory-origin_UXL branch from 3926ae2 to 86c4ff3 Compare July 29, 2025 21:59
@dmitriy-sobolev dmitriy-sobolev force-pushed the dev/mdvorski/ranges_algo_L3_memory-origin_UXL branch from f4db229 to 9cf3a70 Compare July 30, 2025 10:47
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