-
Notifications
You must be signed in to change notification settings - Fork 865
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
Convert byte_array_view to use std::byte #11424
Convert byte_array_view to use std::byte #11424
Conversation
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! Using std::byte
anywhere that arithmetic operations don’t matter and we just want a “data byte” with bitwise ops is a good choice.
I’m a little unsure about adding a “rep layout compatible” trait for a type that lacks a corresponding cudf data type. Can you illuminate that decision a bit more?
template <typename T> | ||
constexpr inline bool is_byte() | ||
{ | ||
return std::is_same_v<std::remove_const_t<T>, std::byte>; |
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.
Do we want a full decay, cv removal, reference removal, or just const removal? I’m not certain what choice is most appropriate for a trait like this
edit: removed suggestion for decay in favor of alternative remove_cv below
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 would even go as far as claiming something like is_byte<volatile T&>
should fail to compile, so this seems sensible to me.
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.
@upsj I’m not sure if I follow. Do you mean you prefer the current state of remove_const
?
On further inquiry, the std::is_integral
and std::is_floating_point
traits return true for any cv-qualifiers but not references. We probably want to remove volatile qualifiers but not reference-ness. (Not that we use volatile often, but I would like to align trait behaviors with the standard where possible.)
return std::is_same_v<std::remove_const_t<T>, std::byte>; | |
return std::is_same_v<std::remove_cv_t<T>, std::byte>; |
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.
Ah sorry, that was ambiguous. Yes, I believe a trait like is_byte should be rather restrictive, or are there use cases in cuDF where you need to call it on a decltype of an expression, or a volatile type? remove_cv
seems more appropriate than decay
though, I agree with staying consistent with the std library
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 didn't remove volatile because I wasn't sure the use-case where it was needed and I would rather have it fail to compile and force a decision at that point than to assume it would be ok. I'm ok with changing it to remove_cv_t
though.
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.
re: #11424 (comment)
@bdice: On further inquiry, the std::is_integral and std::is_floating_point traits return true for any cv-qualifiers but not references. We probably want to remove volatile qualifiers but not reference-ness.
@upsj: I agree with staying consistent with the std library
@hyperbolic2346 I think this is consensus among reviewers that remove_cv_t
is a good change for consistency with std
/ <type_traits>
.
Codecov Report
@@ Coverage Diff @@
## branch-22.10 #11424 +/- ##
===============================================
Coverage ? 86.47%
===============================================
Files ? 144
Lines ? 22856
Branches ? 0
===============================================
Hits ? 19765
Misses ? 3091
Partials ? 0 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Can you explain more what is the benefit of using |
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.
LGTM!
template <typename T> | ||
constexpr inline bool is_byte() | ||
{ | ||
return std::is_same_v<std::remove_const_t<T>, std::byte>; |
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 would even go as far as claiming something like is_byte<volatile T&>
should fail to compile, so this seems sensible to me.
Integer types and chars (signed or unsigned) are implied to represent numbers or letters of some kind. They have arithmetic operators defined like +, they exhibit overflow, they can be upcast to larger integer types, etc. None of these behaviors are desirable for a representation of pure bytes. The only behaviors we want are bitwise operators between byte types and the ability to safely use type aliasing as with
|
Yes but that's in general. I wanted to ask about the benefit of using it in this PR. What if we don't do that? Or this is just something that paves the way for better future development? |
This change is motivated by type safety. Only use an arithmetic type like |
This was Jake's suggestion. I asked him how he would expect this to move forward and he thought it would go into |
Co-authored-by: Tobias Ribizel <ribizel@kit.edu>
Sounds good to me! Approving. |
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.
Approving. You might apply the remove_cv_t
change, otherwise LGTM.
Is there a consensus on that? I'm ok going either way and debated it myself before submitting. |
…6/cudf into mwilson/byte_array_as_byte
rerun tests |
1 similar comment
rerun tests |
@gpucibot merge |
Description
When reviewing PR #11322 it was noted that it would be preferable to use
std::byte
for the data type, but at the time that didn't work out, so the plan was to address it later and issue #11362 was created to track it.Fixes #11362
Checklist