From 02b1b02f573bce1f753bed1f25e6e40a1547fbb1 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Sun, 25 Oct 2020 23:05:57 -0700 Subject: [PATCH] Fix bit math Summary: Formerly `static_cast(bits)` and `static_cast(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 --- c10/core/Stream.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/c10/core/Stream.h b/c10/core/Stream.h index 6962be72bf72..5baac5325af7 100644 --- a/c10/core/Stream.h +++ b/c10/core/Stream.h @@ -124,11 +124,11 @@ class Stream final { } static Stream unpack(uint64_t bits) { - auto stream_id = static_cast(bits) & 0xFFFFFFFFull; + const auto stream_id = static_cast(bits & 0xFFFFFFFFull); bits >>= 32; - auto device_index = static_cast(bits) & 0xFFFFull; + const auto device_index = static_cast(bits & 0xFFFFull); bits >>= 16; - auto device_type = static_cast(bits); + const auto device_type = static_cast(bits); TORCH_CHECK(isValidDeviceType(device_type)); // Unfortunately, we can't check if the StreamId is valid here; it // will be checked upon first use.