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

Use Kokkos::view_alloc with Kokkos::resize/realloc and Kokkos::create_mirror* for Kokkos 3.7 #749

Merged
merged 6 commits into from
Apr 4, 2023

Conversation

masterleinad
Copy link
Collaborator

Fixes #641. Only files in src are changed.

@aprokop
Copy link
Contributor

aprokop commented Sep 21, 2022

I really dislike how view_alloc just spread all over the place. But I suppose this is the only way to do it.

@masterleinad masterleinad force-pushed the kokkos_view_alloc branch 3 times, most recently from 3777eb5 to 9a7012e Compare September 21, 2022 19:29
@masterleinad
Copy link
Collaborator Author

Retest this please.

#else
#if KOKKOS_VERSION >= 30700
auto boxes_host =
Kokkos::create_mirror_view(Kokkos::view_alloc(space), boxes);
#else
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need a space.fence()? I think not, but I'm not entirely confident

@masterleinad
Copy link
Collaborator Author

Retest this please.

@masterleinad masterleinad marked this pull request as ready for review October 14, 2022 13:31
Copy link
Contributor

@dalg24 dalg24 left a comment

Choose a reason for hiding this comment

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

I would slightly prefer if we waited for our requiring Kokkos 3.7

src/details/ArborX_DetailsUtils.hpp Outdated Show resolved Hide resolved
Comment on lines +110 to +106
static_assert(Kokkos::is_execution_space<ExecutionSpace>::value);
static_assert(Kokkos::is_memory_space<MemorySpace>::value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Both have an _v version (not requesting you to change)

@masterleinad masterleinad force-pushed the kokkos_view_alloc branch 2 times, most recently from 0908795 to fe99cbc Compare October 20, 2022 19:07
@aprokop
Copy link
Contributor

aprokop commented Mar 3, 2023

This will need to be rebased on #834. It also has to be reconciled with #833. I propose not doing changes related to create_layout_right_mirror* here, instead doing them in #833. The rest of the PR should be straightforward.

@masterleinad
Copy link
Collaborator Author

This will need to be rebased on #834. It also has to be reconciled with #833. I propose not doing changes related to create_layout_right_mirror* here, instead doing them in #833. The rest of the PR should be straightforward.

I'm happy to rebase this on top of #833 and #834 but I still think that we should also address create_layout_right_mirror here.

Copy link
Contributor

@aprokop aprokop left a comment

Choose a reason for hiding this comment

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

Partial review

Comment on lines 49 to 53
if [ "${clang_format_major_version}" -ne 14 ] || [ "${clang_format_minor_version}" -ne 0 ] || [ "${clang_format_patch_version}" -ne 0 ]; then
echo "*** ArborX requires clang-format version 14.0.0,"
echo "*** but version ${clang_format_major_version}.${clang_format_minor_version}.${clang_format_patch_version} was found instead."
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove this?

@@ -236,7 +236,7 @@ void queryImpl(ExecutionSpace const &space, Tree const &tree,
// Exit early if either no results were found for any of the queries, or
// nothing was inserted inside a callback for found results. This check
// guarantees that the second pass will not be executed.
Kokkos::resize(out, 0);
Kokkos::resize(Kokkos::view_alloc(space), out, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the space if we resize to 0?

auto tmp_view =
Kokkos::create_mirror_view_and_copy(space, imports_layout_right);
auto tmp_view = Kokkos::create_mirror_view_and_copy(
Kokkos::view_alloc(space, typename ExecutionSpace::memory_space{}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need WithoutInitializing, or is that done by default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's done by default.

@@ -184,7 +188,9 @@ DistributedTree<MemorySpace, Enable>::DistributedTree(
"ArborX::DistributedTree::"
"leave_count_in_local_trees"),
comm_size);
auto bottom_tree_sizes_host = Kokkos::create_mirror_view(_bottom_tree_sizes);
auto bottom_tree_sizes_host = Kokkos::create_mirror_view(
Kokkos::view_alloc(host_exec), _bottom_tree_sizes);
Copy link
Contributor

Choose a reason for hiding this comment

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

WithoutInitializing?

@@ -163,7 +165,9 @@ DistributedTree<MemorySpace, Enable>::DistributedTree(
static_cast<void *>(boxes.data()), sizeof(Box), MPI_BYTE,
getComm());
#else
auto boxes_host = Kokkos::create_mirror_view(boxes);
auto boxes_host =
Kokkos::create_mirror_view(Kokkos::view_alloc(host_exec), boxes);
Copy link
Contributor

Choose a reason for hiding this comment

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

WithoutInitializing

@@ -103,11 +103,16 @@ determineBufferLayout(ExecutionSpace const &space, InputView batched_ranks,
auto restricted_unique_ranks = InputView(
compact_ranks, std::make_pair(0, static_cast<int>(n_unique_ranks)));

auto const unique_ranks_host = Kokkos::create_mirror_view_and_copy(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a version of create_mirror_view_and_copy that does that without intialization? It seems a bit weird to split this function into create_mirror_view and deep_copy just so that it does not initialize.

auto device_permutation_indices =
Kokkos::create_mirror_view(DeviceType(), permutation_indices);
auto device_permutation_indices = Kokkos::create_mirror_view(
Kokkos::view_alloc(space, typename DeviceType::memory_space{}),
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 can be WithoutInitializing.

@@ -299,13 +305,13 @@ class Distributor

dest_buffer_mirror =
ArborX::Details::create_layout_right_mirror_view_and_copy(
typename ImportView::memory_space(), dest_buffer);
space, typename ImportView::memory_space(), dest_buffer);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not initialize, check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

create_layout_right_mirror_view_and_copy doesn't initialize anyway.

@aprokop
Copy link
Contributor

aprokop commented Mar 7, 2023

I think there are too many changes in this single PR, and would prefer to split it.

@masterleinad
Copy link
Collaborator Author

I'm still waiting for #833.

@masterleinad masterleinad marked this pull request as draft March 7, 2023 22:52
@aprokop
Copy link
Contributor

aprokop commented Mar 7, 2023

I'm still waiting for #833.

Ah, OK. I did not understand that. So we want to merge #833 in some form first?

@masterleinad
Copy link
Collaborator Author

Ah, OK. I did not understand that. So we want to merge #833 in some form first?

Yes, I was pretty much good with it and would just suggest #833 (comment) to be addressed. After that, I would incorporate the changes here, possibly also addressing #833 (comment).
We can of course discuss splitting this further.

@masterleinad
Copy link
Collaborator Author

Retest this please.

@masterleinad masterleinad marked this pull request as ready for review March 15, 2023 19:17
Copy link
Contributor

@aprokop aprokop left a comment

Choose a reason for hiding this comment

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

Partial review. I haven't looked at the distributed changes yet, or at the changes to add a memory space to creating right layout views. I have to understand why those are necessary.

@@ -26,11 +26,11 @@ stages:
tags:
- nobatch

.BuildKokkos:
BuildKokkos:
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 it's fine to leave it open, so that it rebuilds every time.

Comment on lines -705 to -707
num_components =
static_cast<int>(n) -
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, num_edges)();
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this a bug?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not really in the sense you get the right answer. The change here are about using the execution space provided to transfer to the host instead of the default one.

Comment on lines +58 to +59
Kokkos::realloc(Kokkos::view_alloc(space, Kokkos::WithoutInitializing), v, n0,
n1, n2, n3, n4, n5, n6, n7);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we get rid of reallocWithoutInitializing completely? It's an empty function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I avoided doing that so far thinking that someone would care about the shorter name.

Comment on lines +67 to +68
Kokkos::realloc(Kokkos::view_alloc(space, Kokkos::WithoutInitializing), v,
layout);
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, should we get rid of this function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I avoided doing that so far thinking that someone would care about the shorter name.

Comment on lines +96 to +97
return Kokkos::create_mirror(Kokkos::view_alloc(typename View::memory_space{},
space,
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to do something different from what it used to. In the previous iteration, the memory space was taken from the execution space, now it is taken from the view. Not saying it's wrong, just a change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's fair. To me, the function reads "copy the View with all its properties" using the execution space given. If we take the memory space from the execution space, the memory space might change (especially for Views in shared memory spaces).

Comment on lines -107 to -108
cloneWithoutInitializingNorCopying(ExecutionSpace const &space, View const &v,
std::string const &label)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was the label version removed? Was it not used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was not used and Kokkos::create_mirror doesn't allow passing a new label.

Comment on lines +607 to +608
Kokkos::resize(Kokkos::view_alloc(exec_space, Kokkos::WithoutInitializing),
offsets, num_offsets);
Copy link
Contributor

@aprokop aprokop Mar 16, 2023

Choose a reason for hiding this comment

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

This seems like a bug. We want to resize the offsets array, but keep its values. Or does it do that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It avoids initializing the new elements.

aprokop
aprokop previously approved these changes Mar 30, 2023
@aprokop aprokop dismissed their stale review March 30, 2023 18:09

Doesn't actually compile.

@masterleinad
Copy link
Collaborator Author

Retest this please.

@masterleinad masterleinad requested a review from aprokop April 4, 2023 12:59
@aprokop aprokop merged commit b3a4b6d into arborx:master Apr 4, 2023
@aprokop aprokop deleted the kokkos_view_alloc branch April 4, 2023 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve/fix synchronous behavior
4 participants