-
Notifications
You must be signed in to change notification settings - Fork 5
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
Generalized domains #698
Generalized domains #698
Conversation
d42ad0e
to
b18c085
Compare
9196b14
to
5d8ac57
Compare
f17f86f
to
bc58e5c
Compare
b734484
to
e2b02c6
Compare
6b779a1
to
adaa00b
Compare
64ca9f7
to
f297957
Compare
The feature is almost ready but the integration could be further improved:
A slight overhead might be observed in algorithms in order to support the generalized discrete domains. It is out of scope of the current PR but a future work should allow to slice a ChunkSpan<T, DiscreteDomain<DDim1, DDim2>> chk_span1;
ChunkSpan<T, StridedDiscreteDomain<DDim1>> chk_span2 = chk_span1[strided_slice(DiscreteVector<DDim1>(2), DiscreteVector<DDim1>(10), DiscreteVector<DDim1>(2)][DiscreteVector<DDim2>(2)]; similar to https://en.cppreference.com/w/cpp/container/mdspan/strided_slice |
a7b6d26
to
360ed44
Compare
360ed44
to
b9eecc3
Compare
b9eecc3
to
ce3cda4
Compare
|
||
template <class InputIt1, class InputIt2> | ||
KOKKOS_FUNCTION bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2) | ||
{ |
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.
Could a is_pointer_v
based concept help with better usage of this free function?
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.
Discussed in person, I don't think so because it would require to assume an implementation detail on Kokkos iterators.
count -= step + 1; | ||
} else { | ||
count = step; | ||
} |
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.
Could count
be updated as count = last - first
just after this if-then-else
construct? first
could be updated as it is being updated right now and last
could be updated inside the else
block as last = it
. In this way, count
is updated in the same manner it was initialized.
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.
I don't, to be honest I copy-pasted the version found on cppref
KOKKOS_FUNCTION ForwardIt lower_bound(ForwardIt first, ForwardIt last, const T& value, Compare comp) | ||
{ | ||
ForwardIt it; | ||
typename std::iterator_traits<ForwardIt>::difference_type count = last - first; |
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.
This type is referenced for defining step
also. A type alias could be created.
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.
Yes I will update
bool binary_search(ForwardIt first, ForwardIt last, const T& value, Compare comp) | ||
{ | ||
first = ::ddc::detail::lower_bound(first, last, value, comp); | ||
return (!(first == last) && !(comp(value, *first))); |
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.
If we are sufficiently careful with how lower_bound
and comp
are implemented, could just !(first == last)
be enough?
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.
Same as lower_bound
, this is a copy paste of the version found on cppref
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.
I had a closer look at std::binary_search and std::lower_bound and understand better now. I was wrong in my previous comment. Both !(first == last)
and !(comp(value, *first))
are needed. lower_bound
searches for the first element in the partitioned range [first, last)
which is not ordered before value
. lower_bound
can return last
only if bool(comp(*iter, value))
is true
for all iter
s. Both lower_bound
and binary_search
assume that [first, last)
is partitioned. Also comp
behaves like <
and not <=
. If for any element elem
of [first, last)
, if bool(comp(elem, value))
does not imply !bool(comp(value, elem))
then the behavior is undefined. Hence the first element for which bool(comp(*iter, value))
is false
should be either equal or greater than value
.
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.
Ok thanks a lot for the explanation!
@science-enthusiast do you think it can be merged as is ? |
Yes, I think it can be merged. So that people can start using it. I have a few doubts that I will ask you. For me, this has been a good way to go deeper into the DDC code base. In the future, I will be able to make deeper comments. |
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.
The DDC code base is new to me and I continue to understand it better by reviewing this PR. It is better to merge these changes and let people start using it. Issues can be addressed in the future.
Yes thank you for your time. |
PoC for #438
Steps:
Chunk
andChunkSpan
withSupportType
being a customization pointStridedDiscreteDomain
StorageDiscreteDomain
Not clear if we should define an equivalent of the slice operator taking a
DiscreteDomain
cc @science-enthusiast