Skip to content
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

Change usage of _PSTL_UD[R/S]_PRESENT macros #1551

Merged
merged 7 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/oneapi/dpl/pstl/algorithm_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3882,7 +3882,7 @@ _RandomAccessIterator
__brick_min_element(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
/* __is_vector = */ ::std::true_type) noexcept
{
#if (_PSTL_UDR_PRESENT || _ONEDPL_UDR_PRESENT)
danhoeflinger marked this conversation as resolved.
Show resolved Hide resolved
#if _ONEDPL_DEFINED_AND_NOT_ZERO(_PSTL_UDR_PRESENT) || _ONEDPL_UDR_PRESENT
return __unseq_backend::__simd_min_element(__first, __last - __first, __comp);
#else
return ::std::min_element(__first, __last, __comp);
Expand Down Expand Up @@ -3949,7 +3949,7 @@ ::std::pair<_RandomAccessIterator, _RandomAccessIterator>
__brick_minmax_element(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
/* __is_vector = */ ::std::true_type) noexcept
{
#if (_PSTL_UDR_PRESENT || _ONEDPL_UDR_PRESENT)
#if _ONEDPL_DEFINED_AND_NOT_ZERO(_PSTL_UDR_PRESENT) || _ONEDPL_UDR_PRESENT
return __unseq_backend::__simd_minmax_element(__first, __last - __first, __comp);
#else
return ::std::minmax_element(__first, __last, __comp);
Expand Down
3 changes: 2 additions & 1 deletion include/oneapi/dpl/pstl/numeric_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,14 @@ __brick_transform_scan(_RandomAccessIterator __first, _RandomAccessIterator __la
_UnaryOperation __unary_op, _Tp __init, _BinaryOperation __binary_op, _Inclusive,
/*is_vector=*/::std::true_type) noexcept
{
#if (_PSTL_UDS_PRESENT || _ONEDPL_UDS_PRESENT)
#if _ONEDPL_DEFINED_AND_NOT_ZERO(_PSTL_UDS_PRESENT) || _ONEDPL_UDS_PRESENT
if (_Inclusive() || !oneapi::dpl::__internal::__iterators_possibly_equal(__first, __result))
{
return __unseq_backend::__simd_scan(__first, __last - __first, __result, __unary_op, __init, __binary_op,
_Inclusive());
}
#endif

Copy link
Contributor

Choose a reason for hiding this comment

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

extra space

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.

// We need to call serial brick here to call function for inclusive and exclusive scan that depends on _Inclusive() value
return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, __init, __binary_op, _Inclusive(),
/*is_vector=*/::std::false_type());
Expand Down
2 changes: 2 additions & 0 deletions include/oneapi/dpl/pstl/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
# include <cstring> // memcpy
#endif

#define _ONEDPL_DEFINED_AND_NOT_ZERO(X) (X + 0)
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 this doesn't do what we are advertising by the name (and we want the semantics of the name I think).
_PSTL_UDS_PRESENT is defined to empty in the external std lib def when it is "true" and left undefined when it is "false".

This macro will convert that empty string to a "false" rather than a "true".

I think we want it to be "true" / "1" any time it is defined and not explicitly set to "0".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are correct. This macro should be truthy if the input is defined and empty, but that is not the case here.

I made this godbolt to try to write a macro that has all of the properties that we want, but I cannot come up with a macro that satisfies everything. So perhaps the original version of the PR is the solution that we should go with for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is kind of an annoying case.

How about this:
https://godbolt.org/z/GY1qTjb5e

It would require basically converting the public pstl defines to our own local copy of the pstl defines (which would be "0" or "1"), then we could use our own copy as "normal".

Its possible that we could work it out so that our local _ONEDPL_UDS_PRESENT is our "local" copy, where we only attempt to define it ourselves if it is undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After some offline discussion, @danhoeflinger and I arrived at a version of the macro that now correctly determines if the input define is either 1 or defined but empty.


namespace oneapi
{
namespace dpl
Expand Down
Loading