-
Notifications
You must be signed in to change notification settings - Fork 407
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
#4092: DynamicView: rewrite without UVM #4129
#4092: DynamicView: rewrite without UVM #4129
Conversation
// Destroy the array of chunk pointers. | ||
// Two entries beyond the max chunks are allocation counters. | ||
for (unsigned i = 0; i < m_chunk_max; i++) { | ||
MemorySpace().deallocate( |
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'm not sure what the preferred allocation/deallocation style is. I went with this style throughout but could change it to use kokkos_malloc
if preferable.
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.
@crtrott Are you ok with the MemorySpace().allocate/deallocate
style used throughout?
@@ -93,6 +259,12 @@ class DynamicView : public Kokkos::ViewTraits<DataType, P...> { | |||
public: | |||
using traits = Kokkos::ViewTraits<DataType, P...>; | |||
|
|||
using value_type = typename traits::value_type; | |||
using device_space = typename traits::memory_space; | |||
using host_space = typename Kokkos::Impl::HostMirror<device_space>::Space::memory_space; |
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.
Is this the right trait to use for getting the HostMirror
memory space?
retest this please |
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 is pretty good. Other than adding two comments or so and maybe renaming some stuff as pointed out in the comments this is good to go.
using host_space = | ||
typename Kokkos::Impl::HostMirror<device_space>::Space::memory_space; | ||
using device_accessor = Impl::SmartMemoryAccessor<device_space, value_type>; | ||
using host_accessor = Impl::SmartMemoryAccessor<host_space, value_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.
might be worthwhile to think about a better name. Since this is just the outer array, it doesn't actually give you access to the primary data on the host after all 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.
Changed the name to ChunkedArrayManager
. Let me know if you can think of something better!
Also this crashed NVCC 9.2 with an internal error, and GCC 5.3 doesn't like it either:
So those need to be fixed too (in addition to the MSVC issue which doesn't like "not" as a keyword. |
retest this please |
1 similar comment
retest this please |
@crtrott I have everything passing. Can you take a final look at the changes I made? |
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.
Thanks, @lifflander ! Please see the questions and suggestions below.
nullptr) { | ||
using tag_type = | ||
typename ChunkedArrayManager<Space, ValueType>::INACCESSIBLE_TAG; | ||
return ChunkedArrayManager<Space, ValueType>{tag_type{}, other.m_chunk_max, |
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.
Why not use INACCESSIBLE_TAG{}
instead?
using value_type = ValueType; | ||
using pointer_type = ValueType*; | ||
using track_type = Kokkos::Impl::SharedAllocationTracker; | ||
|
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.
// 2 extra array elements (per allocation) to keep track of metadata for every allocation | |
constexpr unsigned n_allocation_counters = 2; |
void allocate_device(const std::string& label) { | ||
if (m_chunks == nullptr) { | ||
m_chunks = reinterpret_cast<pointer_type*>(MemorySpace().allocate( | ||
label.c_str(), (sizeof(pointer_type) * (m_chunk_max + 2)))); |
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.
label.c_str(), (sizeof(pointer_type) * (m_chunk_max + 2)))); | |
label.c_str(), (sizeof(pointer_type) * (m_chunk_max + n_allocation_counters)))); |
} | ||
|
||
void initialize() { | ||
for (unsigned i = 0; i < m_chunk_max + 2; i++) { |
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 (unsigned i = 0; i < m_chunk_max + 2; i++) { | |
for (unsigned i = 0; i < m_chunk_max + n_allocation_counters; i++) { |
// Destroy the linked allocation if we have one. | ||
if (m_linked != nullptr) { | ||
Space().deallocate(m_label.c_str(), m_linked, | ||
(sizeof(value_type*) * (m_chunk_max + 2))); |
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.
(sizeof(value_type*) * (m_chunk_max + 2))); | |
(sizeof(value_type*) * (m_chunk_max + n_allocation_counters))); |
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 this be (sizeof(value_type*) * (m_chunk_max))
?
typename std::enable_if<!IsAccessibleFrom<Space>::value>::type deep_copy_to( | ||
ChunkedArrayManager<Space, ValueType> const& other) { | ||
Kokkos::Impl::DeepCopy<Space, MemorySpace>( | ||
other.m_chunks, m_chunks, sizeof(pointer_type) * (m_chunk_max + 2)); |
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.
other.m_chunks, m_chunks, sizeof(pointer_type) * (m_chunk_max + 2)); | |
other.m_chunks, m_chunks, sizeof(pointer_type) * (m_chunk_max + n_allocation_counters)); |
bool m_valid = false; | ||
unsigned m_chunk_max = 0; | ||
pointer_type* m_chunks = nullptr; | ||
track_type m_track; |
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's this member for?
@@ -183,7 +355,7 @@ class DynamicView : public Kokkos::ViewTraits<DataType, P...> { | |||
KOKKOS_INLINE_FUNCTION | |||
size_t size() const noexcept { | |||
size_t extent_0 = | |||
*reinterpret_cast<const size_t*>(m_chunks + m_chunk_max + 1); | |||
*reinterpret_cast<const size_t*>(m_chunks_host + m_chunk_max + 1); |
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.
m_chunks_host
-> m_chunks
?
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.
that was actually a request from me adding the host since this is a host side pointer.
@@ -173,7 +344,8 @@ class DynamicView : public Kokkos::ViewTraits<DataType, P...> { | |||
|
|||
KOKKOS_INLINE_FUNCTION | |||
size_t allocation_extent() const noexcept { | |||
uintptr_t n = *reinterpret_cast<const uintptr_t*>(m_chunks + m_chunk_max); | |||
uintptr_t n = | |||
*reinterpret_cast<const uintptr_t*>(m_chunks_host + m_chunk_max); |
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.
m_chunks_host
-> m_chunks
?
#ifdef KOKKOS_ENABLE_CUDA | ||
template <> | ||
struct ChunkArraySpace<Kokkos::CudaSpace> { | ||
using memory_space = typename Kokkos::CudaUVMSpace; |
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 is the removal of UVM?
Fixes #4092