Skip to content

Commit

Permalink
Fix bit math
Browse files Browse the repository at this point in the history
Summary:
Formerly `static_cast<StreamId>(bits)` and `static_cast<DeviceIndex>(bits)` were and-ed against `ull` types resulting in an integer promotion which later raised a warning in downcasting passes to  `Stream` and `Device`.

Moving the `&` operation inside the cast results in two `uint64_t` being operated on and then cast to the correct type, eliminating the warning.

Test Plan: Standard pre-commit test rig.

Differential Revision: D24481292

fbshipit-source-id: 16ba68690e58ce8b710bb082542c1a5451548742
  • Loading branch information
r-barnes authored and facebook-github-bot committed Oct 26, 2020
1 parent d94bd99 commit 02b1b02
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions c10/core/Stream.h
Expand Up @@ -124,11 +124,11 @@ class Stream final {
}

static Stream unpack(uint64_t bits) {
auto stream_id = static_cast<StreamId>(bits) & 0xFFFFFFFFull;
const auto stream_id = static_cast<StreamId>(bits & 0xFFFFFFFFull);
bits >>= 32;
auto device_index = static_cast<DeviceIndex>(bits) & 0xFFFFull;
const auto device_index = static_cast<DeviceIndex>(bits & 0xFFFFull);
bits >>= 16;
auto device_type = static_cast<DeviceType>(bits);
const auto device_type = static_cast<DeviceType>(bits);
TORCH_CHECK(isValidDeviceType(device_type));
// Unfortunately, we can't check if the StreamId is valid here; it
// will be checked upon first use.
Expand Down

0 comments on commit 02b1b02

Please sign in to comment.