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

#4092: DynamicView: rewrite without UVM #4129

Merged
merged 13 commits into from
Aug 2, 2021

Conversation

lifflander
Copy link
Contributor

Fixes #4092

@lifflander lifflander requested a review from crtrott June 28, 2021 19:00
// 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(
Copy link
Contributor Author

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.

Copy link
Contributor Author

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;
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 this the right trait to use for getting the HostMirror memory space?

@lifflander
Copy link
Contributor Author

retest this please

Copy link
Member

@crtrott crtrott left a 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.

containers/src/Kokkos_DynamicView.hpp Outdated Show resolved Hide resolved
containers/src/Kokkos_DynamicView.hpp Outdated Show resolved Hide resolved
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>;
Copy link
Member

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?

Copy link
Contributor Author

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!

@crtrott
Copy link
Member

crtrott commented Jun 30, 2021

Also this crashed NVCC 9.2 with an internal error, and GCC 5.3 doesn't like it either:

/var/jenkins/workspace/Kokkos/containers/src/Kokkos_DynamicView.hpp:537:5: error: 'is_accessible_from' is not a member template function

     if (m_chunks.template is_accessible_from<host_space>) {

So those need to be fixed too (in addition to the MSVC issue which doesn't like "not" as a keyword.

@lifflander lifflander requested a review from crtrott June 30, 2021 18:31
@lifflander lifflander marked this pull request as ready for review June 30, 2021 18:31
@lifflander
Copy link
Contributor Author

retest this please

1 similar comment
@lifflander
Copy link
Contributor Author

retest this please

@lifflander lifflander requested a review from crtrott July 7, 2021 17:37
@lifflander
Copy link
Contributor Author

@crtrott I have everything passing. Can you take a final look at the changes I made?

@crtrott crtrott added this to In progress in Kokkos Release 3.5 Jul 14, 2021
@crtrott crtrott moved this from In progress to Awaiting Feedback in Kokkos Release 3.5 Jul 14, 2021
@e10harvey e10harvey self-requested a review July 14, 2021 21:29
@crtrott crtrott moved this from Awaiting Feedback to Done in Kokkos Release 3.5 Jul 17, 2021
@crtrott crtrott moved this from Done to Awaiting Feedback in Kokkos Release 3.5 Jul 17, 2021
@lifflander lifflander requested a review from dalg24 July 21, 2021 18:11
Copy link
Contributor

@e10harvey e10harvey left a 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,
Copy link
Contributor

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;

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
// 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))));
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
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++) {
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
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)));
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
(sizeof(value_type*) * (m_chunk_max + 2)));
(sizeof(value_type*) * (m_chunk_max + n_allocation_counters)));

Copy link
Contributor

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));
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
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;
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Member

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);
Copy link
Contributor

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;
Copy link
Contributor

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?

Developer: E10HARVEY automation moved this from To do to Reviewer approved Jul 29, 2021
@crtrott crtrott merged commit d721229 into kokkos:develop Aug 2, 2021
Kokkos Release 3.5 automation moved this from Awaiting Feedback to Done Aug 2, 2021
Developer: E10HARVEY automation moved this from Reviewer approved to Done Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants