-
Notifications
You must be signed in to change notification settings - Fork 415
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
SpaceAwareAccessor #7074
SpaceAwareAccessor #7074
Conversation
Needs a rebase after merging the thing with the default mdspan on. |
{ | ||
int errors; | ||
using acc_t = | ||
Kokkos::Impl::SpaceAwareAccessor<memory_space_t, | ||
Kokkos::default_accessor<const T>>; | ||
acc_t acc{}; | ||
typename acc_t::data_handle_type ptr = v.data(); | ||
|
||
Kokkos::parallel_reduce( | ||
Kokkos::RangePolicy<ExecutionSpace>(0, v.extent(0)), | ||
KOKKOS_LAMBDA(int i, int& error) { | ||
if (acc.access(ptr, i) != ptr[i]) error++; | ||
static_assert(std::is_same_v<typename acc_t::element_type, const T>); | ||
static_assert(std::is_same_v<typename acc_t::reference, const T&>); | ||
static_assert( | ||
std::is_same_v<typename acc_t::data_handle_type, const T*>); | ||
static_assert(std::is_same_v<typename acc_t::offset_policy, acc_t>); | ||
static_assert( | ||
std::is_same_v<typename acc_t::memory_space, memory_space_t>); | ||
static_assert(std::is_empty_v<acc_t>); | ||
}, | ||
errors); | ||
ASSERT_EQ(errors, 0); | ||
} |
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.
Don't you get this for free if you instantiate your test for a const-qualified type?
Please get rid of that block and instantiate for some const T.
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 guess I can instantiate the View with remove_const
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.
done
|
||
KOKKOS_FUNCTION | ||
constexpr reference access(data_handle_type p, size_t i) const noexcept { | ||
// Same error as Kokkos view in case anyone greps for this in their tools |
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 understand your comment and unsure on what's best to do here (pretend it is a view error or say accessor)
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.
Interesting question actually: originally I thought we just check error here, but that means no label. I guess we could internally use an mdspan without SpaceAwareAccessor and just use one with SpaceAwareAccessor in the public interfaces.
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.
changed the message
template <class, class> | ||
friend struct SpaceAwareAccessor; | ||
}; | ||
|
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.
Should we attempt to handle the case where NestedAccessor is a specialization of SpaceAwareAccessor in which case we may be able to "collapse" and not produce and double-nested accessor?
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 and when we make this public maybe. For now I wouldn't say so since we are not gonna use it in generic contexts?
}; | ||
|
||
template <class NestedAccessor> | ||
struct SpaceAwareAccessor<AnonymousSpace, NestedAccessor> { |
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 suppose since NestedAccessor can be some potentially weird user-defined type, it is not safe to just derive from it to save on the boiler plate code below?
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.
yeah, not sure I prefer inheritance even if it worked, i mean there isn't that much stuff defined.
#include <Kokkos_Concepts.hpp> | ||
#include <impl/Kokkos_Utilities.hpp> |
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.
What are you using from these?
I think all you need is an include for Impl::runtime_check_memory_access_violation()
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.
Macros: KOKKOS_FUNCTION
Concepts: is_memory_space
Utilities: runtime_check_memory_access_violation
or?
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.
#include <Kokkos_Concepts.hpp> | |
#include <impl/Kokkos_Utilities.hpp> | |
#include <Kokkos_Core_fwd.hpp> // runtime_check_memory_access_violation |
runtime_check_memory_access_violation
(without ViewTracker
and ViewMapping
argument) is defined in Kokkos_Core_fwd.hpp
(which also includes Kokkos_Macros.hpp
).
cmake/kokkos_enable_options.cmake
Outdated
@@ -76,7 +76,7 @@ KOKKOS_ENABLE_OPTION(IMPL_HIP_UNIFIED_MEMORY OFF "Whether to leverage unified me | |||
KOKKOS_ENABLE_OPTION(DESUL_ATOMICS_EXTERNAL OFF "Whether to use an external desul installation") | |||
KOKKOS_ENABLE_OPTION(ATOMICS_BYPASS OFF "**NOT RECOMMENDED** Whether to make atomics non-atomic for non-threaded MPI-only use cases") | |||
|
|||
KOKKOS_ENABLE_OPTION(IMPL_MDSPAN OFF "Whether to enable experimental mdspan support") | |||
KOKKOS_ENABLE_OPTION(IMPL_MDSPAN ON "Whether to enable experimental mdspan support") |
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 suppose you refer to this change and the CI configuration ones when you talk about needing to rebase.
In any case commenting here to note this does not belong to this PR.
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 now I ran into #7069
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.
rebase has happened
typename Traits::memory_space, | ||
Kokkos::default_accessor<typename Traits::value_type>>; | ||
using mdspan_type = mdspan<typename Traits::value_type, extents_type, | ||
mdspan_layout_type, accessor_type>; |
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.
Should we comment somewhere that the converting constructor from a mdspan strips out the accessor and just require convertibility to a space-aware default accessor?
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.
not sure what you mean, the constructor takes this thing. So all the rules for mdspan conversion apply anyway. View will only do something with it after the user thing was converted to mdspan_type
} | ||
#endif | ||
|
||
TEST(TEST_CATEGORY_DEATH, memory_access_violations_from_device) { |
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.
We might want some sort of mdpan_
prefix to classify that test properly.
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.
its not mdspan. I guess I can prefix it with space_aware_accessor
making it space_aware_accessor_memory_access_violations_from_device
...
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.
changed the name
00fcb08
to
165bcb4
Compare
This mdspan accessor wraps otehr accessors, and adds memory space accessibility checks.
That version is convertible into all other variants
fc4f684
to
f29c746
Compare
CI serviced these. Also turn off tests if mdspan is not enabled
f29c746
to
6c78f4b
Compare
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.
Looks good, I think we just need to figure out the explicit
conversion thing
std::enable_if_t<std::is_constructible_v<NestedAccessor, | ||
OtherNestedAccessorType>, | ||
int> = 0> | ||
KOKKOS_FUNCTION constexpr SpaceAwareAccessor( |
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.
At the very least I think this constructor should be explicit
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.
We will probably discuss this either during the team meeting or a separate meeting
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 want to have a full discussion on how to consistently deal with explicitness for View and related facilities.
: nested_acc(other.nested_acc) {} | ||
|
||
KOKKOS_FUNCTION | ||
SpaceAwareAccessor(const NestedAccessor& acc) : nested_acc(acc) {} |
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 too
Kokkos::parallel_reduce( | ||
Kokkos::RangePolicy<ExecutionSpace>(0, v.extent(0)), | ||
KOKKOS_LAMBDA(int i, int& error) { | ||
if (acc.access(ptr, i) != ptr[i]) error++; |
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.
very nitpicky but we may want to make an using acc_base_t = Kokkos::default_accessor<T>
and make this check acc.access(ptr,i) != acc_base.access(ptr,i)
just to make the requirements clearer
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 agree with that necessarily pretending this tests whether we really just call through seems at best misleading.
#else | ||
[[no_unique_address]] | ||
#endif | ||
NestedAccessor nested_acc; |
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.
Because the question came up: yes you need no_unique_address
recursively for it to work:
https://godbolt.org/z/T84E7Yb1f
#include <Kokkos_Concepts.hpp> | ||
#include <impl/Kokkos_Utilities.hpp> |
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.
#include <Kokkos_Concepts.hpp> | |
#include <impl/Kokkos_Utilities.hpp> | |
#include <Kokkos_Core_fwd.hpp> // runtime_check_memory_access_violation |
runtime_check_memory_access_violation
(without ViewTracker
and ViewMapping
argument) is defined in Kokkos_Core_fwd.hpp
(which also includes Kokkos_Macros.hpp
).
|
||
namespace Kokkos { | ||
|
||
// For now use the accessors in IMPL namespace, as an |
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.
// For now use the accessors in IMPL namespace, as an | |
// For now use the accessors in Impl namespace, as an |
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.
Kokkos_Core_fwd.hpp
straight includes impl/Kokkos_Utilities.hpp
but it doesn't include Kokkos_Concept.hpp
so no reason to change that.
|
||
using memory_space = MemorySpace; | ||
|
||
static_assert(is_memory_space<memory_space>::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.
static_assert(is_memory_space<memory_space>::value); | |
static_assert(is_memory_space_v<memory_space>); |
This will be the default accessor for View adding memory access check.