Skip to content

Simplify endianness check using std::endian#186854

Open
lakshayg wants to merge 3 commits into
pytorch:mainfrom
lakshayg:simplify-endianness-check
Open

Simplify endianness check using std::endian#186854
lakshayg wants to merge 3 commits into
pytorch:mainfrom
lakshayg:simplify-endianness-check

Conversation

@lakshayg

Copy link
Copy Markdown
Collaborator

std::endian is available since C++20 #176662

`std::endian` is available since C++20 pytorch#176662
@pytorch-bot

pytorch-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/186854

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures, 2 Unrelated Failures

As of commit 70b9da7 with merge base b9a2479 (image):

NEW FAILURES - The following jobs have failed:

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@lakshayg lakshayg self-assigned this Jun 10, 2026
@lakshayg lakshayg added topic: not user facing topic category ciflow/trunk Trigger trunk jobs on your pull request ciflow/vllm labels Jun 10, 2026
@@ -107,8 +108,11 @@ static uint64_t decodeUInt64ByteSwapped(const uint8_t* data) {
namespace torch::utils {

THPByteOrder THP_nativeByteOrder() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

constexpr this function?

@lakshayg lakshayg Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. BTW do you why we did not define it using the preprocessor macros used in the header?

THPByteOrder THP_nativeByteOrder() {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  return THP_LITTLE_ENDIAN;
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  return THP_BIG_ENDIAN;
#else
  static_assert(false, ...);
#endif
}

I ask because I'm trying to understand if there was a reason behind making this a runtime vs compile time check

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't know its history, but you can simplify

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible for the library to be compiled on a machine of one endian and run on a machine of another?

@cyyever cyyever requested a review from ezyang June 10, 2026 05:36
Comment thread torch/csrc/utils/byte_order.cpp Outdated
THPByteOrder THP_nativeByteOrder() {
uint32_t x = 1;
return *(uint8_t*)&x ? THP_LITTLE_ENDIAN : THP_BIG_ENDIAN;
constexpr THPByteOrder THP_nativeByteOrder() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Think this has to be header only now that it's constexpr right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh right, it won't be usable at compile time unless it is in the header. However, I don't want to put C++20 stuff in header since it ends up causing problems with vllm. Should I just remove the constexpr for now?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unfortunately more and more CPP20 stuff will be in headers soon so I recommend VLLM upgrades soon.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How is it getting past the hard CPP20 version guard anyway?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

They use PyTorch libs and headers. libs are compiled with C++20 but headers that make use of C++20 features and get included in their build cause issues IIUC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request ciflow/vllm open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants