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

Properly compute tree bounds with indexables #894

Merged
merged 1 commit into from
Jul 22, 2023

Conversation

aprokop
Copy link
Contributor

@aprokop aprokop commented Jun 12, 2023

Leaf nodes will not always store bounding volume inside. We have to use the indexable for a degenerate tree.

@aprokop aprokop mentioned this pull request Jun 12, 2023
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.

src/details/ArborX_DetailsTreeConstruction.hpp Outdated Show resolved Hide resolved
src/details/ArborX_DetailsTreeConstruction.hpp Outdated Show resolved Hide resolved
src/ArborX_LinearBVH.hpp Outdated Show resolved Hide resolved
@aprokop
Copy link
Contributor Author

aprokop commented Jun 24, 2023

@dalg24 integrated your changes and merged bounds with the hierarchy generation.

@aprokop aprokop force-pushed the 6.5-fix-root-bounding_volume branch from 6d46363 to 6559ec0 Compare June 26, 2023 19:27
@aprokop aprokop force-pushed the 6.5-fix-root-bounding_volume branch from 6559ec0 to 0f3d411 Compare June 27, 2023 18:00
@aprokop
Copy link
Contributor Author

aprokop commented Jun 27, 2023

5% slowdown on Cuda for the smallest (10K) tree construction. I think need to revert some part of the patch to not make it part of the hierarchy generation for loop. Pretty annoyed, this is taking so much longer than expected.

Co-authored-by: Damien L-G <dalg24@gmail.com>
@aprokop aprokop force-pushed the 6.5-fix-root-bounding_volume branch from c41fc42 to 22bf054 Compare July 19, 2023 19:14
@aprokop aprokop added the refactoring Code reorganization label Jul 19, 2023
@aprokop
Copy link
Contributor Author

aprokop commented Jul 19, 2023

Latest version has no slowdown.

Comment on lines +70 to +73
// Skip initialization so that we don't execute a kernel launch
Kokkos::View<BoundingVolume, typename Nodes::memory_space> bounding_volume(
Kokkos::view_alloc(space, Kokkos::WithoutInitializing,
"ArborX::BVH::getSingleLeafBounds::bounding_volume"));
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
// Skip initialization so that we don't execute a kernel launch
Kokkos::View<BoundingVolume, typename Nodes::memory_space> bounding_volume(
Kokkos::view_alloc(space, Kokkos::WithoutInitializing,
"ArborX::BVH::getSingleLeafBounds::bounding_volume"));
using MemorySpace = typename Nodes::memory_space;
auto bounding_volume = Kokkos::create_mirror_view(
Kokkos::view_alloc(space, Kokkos::WithoutInitializing,
"ArborX::BVH::getSingleLeafBounds::bounding_volume",
MemorySpace()),
Kokkos::View<BoundingVolume, Kokkos::HostSpace, Kokkos::MemoryUnmanaged>(
&bounds));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, this does not work because of the labels. view_alloc in create_mirror_view does not allow a label. Which results in bounding_volume having a label _mirror, which fails out labels tests.

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 a bug on the Kokkos side. I am tempted to just filter out "_mirror".

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 the bug that it does not allow a label?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, can just do what I did before.

Comment on lines +128 to +142
Kokkos::deep_copy(
space,
Kokkos::View<BoundingVolume, Kokkos::HostSpace,
Kokkos::MemoryUnmanaged>(&bounds),
Kokkos::View<BoundingVolume const, MemorySpace,
Kokkos::MemoryUnmanaged>(getRootBoundingVolumePtr()));
}

KOKKOS_FUNCTION
BoundingVolume const *getRootBoundingVolumePtr() const
{
// Need address of the root node's bounding box to copy it back on the host,
// but can't access node elements from the constructor since the data is on
// the device.
return &_internal_nodes.data()->bounding_volume;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you prefer this approach as opposed to the one in the 3rd round of aprokop#16
(_bounds member which is a mirror view of the bounds argument)?
Was the extra allocation causing slowdowns? Is that why we are still using this hack to get the address of the bounding volume of the root node.
I am a bit surprised and if the performance is the same I would prefer the extra member.

Copy link
Contributor Author

@aprokop aprokop Jul 20, 2023

Choose a reason for hiding this comment

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

Using any extra variable with an assignment inside the operator() was slowing things down for the smallest problem. We had 10K the smallest, but the relative slowdown would have been worse for smaller. Essentially, the thread taking the longest (i.e., traversing all the way to the root), was necessarily doing an extra Box assignment, which was non-trivial.

The only way to avoid that was to not use any extra variables. In which case, I ended up just deep copying.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. It might be worth expanding/updating the comment to explain that we chose to be naughty although we had alternatives for performance reasons.

@aprokop aprokop force-pushed the 6.5-fix-root-bounding_volume branch 2 times, most recently from 74c7ddd to 22bf054 Compare July 21, 2023 20:10
@aprokop
Copy link
Contributor Author

aprokop commented Jul 21, 2023

Reverted the last changes.

@aprokop aprokop merged commit 9dcb3ba into arborx:master Jul 22, 2023
@aprokop aprokop deleted the 6.5-fix-root-bounding_volume branch July 22, 2023 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Code reorganization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants