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

Prefer defaulted default constructor for Bitset #6524

Merged
merged 5 commits into from
Oct 25, 2023

Conversation

dalg24
Copy link
Member

@dalg24 dalg24 commented Oct 18, 2023

The default argument to the constructor that takes the size of the bitset was deferring to another constructor that creates an empty view with a label argument. This alocates 128 bits for the view header. This showed when constructing an UnorderedMap with a pointless 128-bit "header-only" allocation which implies an unnecessary fence.

cc @uliegecsm @romintomasetti

The default argument to the constructor that takes the size of the
bitset was deferring to another constructor that creates an empty view
with a label argument.  This alocates 128 bits for the view header.
This showed when constructing an UnorderedMap with a pointless 128-bit
"header-only" allocation which implies an unnecessary fence.
@dalg24 dalg24 added Performance Code showing unusually slow performance for an architecture and/or backend Kokkos-Containers labels Oct 18, 2023
@masterleinad
Copy link
Contributor

Fixes #6467.

@romintomasetti
Copy link
Contributor

romintomasetti commented Oct 18, 2023

Fixes #6467.

@masterleinad It fixes part of #6467 I think. What about #6467 (comment) ?

/// arg_size := number of bit in set
Bitset(unsigned arg_size = 0u) : Bitset(Kokkos::view_alloc(), arg_size) {}
Bitset(unsigned arg_size) : Bitset(Kokkos::view_alloc(), arg_size) {}
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
Bitset(unsigned arg_size) : Bitset(Kokkos::view_alloc(), arg_size) {}
explicit Bitset(unsigned arg_size) : Bitset(Kokkos::view_alloc(), arg_size) {}

Copy link
Member Author

Choose a reason for hiding this comment

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

I tend to agree with the suggested change but I will note that it was not explicit before and that is besides the scope of this PR.
That said I will apply the suggested change if other reviewers would like me to.

Copy link
Member

Choose a reason for hiding this comment

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

May need to do this with a "deprecated" guard.

@masterleinad
Copy link
Contributor

masterleinad commented Oct 18, 2023

@masterleinad I fixes part of #6467 I think. What about #6467 (comment) ?

That's a separate discussion and isn't reflected in the title or description of the pull request and serves as a motivation. Open a separate issue for it if you want to discuss it in a larger context.

@dalg24
Copy link
Member Author

dalg24 commented Oct 18, 2023

Fixes #6467.

Thanks for pointed that out. I will admit I had overlooked it :/

@romintomasetti
Copy link
Contributor

@dal24 @masterleinad Would you like me to open a new issue with #6467 (comment) ?

@dalg24
Copy link
Member Author

dalg24 commented Oct 18, 2023

@dal24 @masterleinad Would you like me to open a new issue with #6467 (comment) ?

Please do so

@romintomasetti
Copy link
Contributor

@dal24 @masterleinad Would you like me to open a new issue with #6467 (comment) ?

Please do so

Just did, it is #6526. Please tell me if the title is OK with you 😉

@masterleinad
Copy link
Contributor

/__w/kokkos/kokkos/containers/unit_tests/TestBitset.hpp:159: Failure
Value of: b1.is_allocated()
  Actual: false
Expected: true

which was anticipated in #6467 (comment).

@dalg24
Copy link
Member Author

dalg24 commented Oct 19, 2023

SYCL build timed out but I intend to ignore if I can get a 2nd approval

@dalg24 dalg24 force-pushed the bitset_defaulted_default_constructor branch from 94c533c to 7cd6aa8 Compare October 20, 2023 18:29
Comment on lines 267 to 278
auto success = validate_existence(
[&]() {
Kokkos::Bitset bs1(0);
EXPECT_TRUE(bs1.is_allocated());

Kokkos::Bitset bs2(Kokkos::view_alloc("MyBitset"), 0);
EXPECT_TRUE(bs2.is_allocated());
},
[&](AllocateDataEvent) {
return MatchDiagnostic{true, {"Found alloc event"}};
});
ASSERT_TRUE(success);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this test be done in 2 distinct validate_existence ? If I understand it correctly, in its current state, the first allocation bs1(0) could in fact not allocate anything and the test would still pass if bs2 allocates something?

Not requesting any change though, I just wanted to make sure I understand validate_existence 😄

BTW is there any helper in the Kokkos testing toolbox that would not only allow us to ensure that some event occurred (in this case AllocateDataEvent) but also to count them ?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are correct and that is how I had written the test initially but I didn't think it was worth the boiler plate code.

I don't know that there is currently something to count the number of allocations even though writing directly a tool that does that would be trivial.

@crtrott
Copy link
Member

crtrott commented Oct 25, 2023

Three of the CUDA builds seg faulted during compilation. The CUDA 12 build was fine.

@dalg24
Copy link
Member Author

dalg24 commented Oct 25, 2023

Retest this please

@dalg24 dalg24 merged commit 3bcf965 into kokkos:develop Oct 25, 2023
28 checks passed
@dalg24 dalg24 deleted the bitset_defaulted_default_constructor branch October 25, 2023 21:35
@masterleinad masterleinad mentioned this pull request Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Kokkos-Containers Performance Code showing unusually slow performance for an architecture and/or backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants