Skip to content

Commit c43d5ad

Browse files
authored
Alternative approach to handling memory offset shift (#9406)
Summary: To support embedded system builds which threw an error on the warning for left shift by 32 on a 32 bit dtype, the code was modified to: ``` memory_offset |= static_cast<size_t>(memory_offset_high) << (sizeof(size_t) - sizeof(uint32_t)); ``` This fails for build of OSS qwen example however. Instead, we modify to add a check for ``` sizeof(size_t) > sizeof(uint32_t) ``` in the conditional instead of changing the computation. In our builds of interest, this compiles away the if branch Reviewed By: digantdesai, dpalmasan Differential Revision: D71488571
1 parent 9d243e9 commit c43d5ad

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

runtime/executor/tensor_parser_exec_aten.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ ET_NODISCARD Result<void*> getMemPlannedPtr(
5656
const uint32_t memory_offset_high = allocation_info->memory_offset_high();
5757

5858
size_t memory_offset = memory_offset_low;
59-
if (memory_offset_high > 0) {
59+
if ((sizeof(size_t) > sizeof(uint32_t)) && (memory_offset_high > 0)) {
6060
// The compiler should remove this always-true check on 64-bit systems.
6161
ET_CHECK_OR_RETURN_ERROR(
6262
sizeof(size_t) >= sizeof(uint64_t),
6363
NotSupported,
6464
"size_t cannot hold memory offset 0x%08" PRIx32 ".%08" PRIx32,
6565
memory_offset_high,
6666
memory_offset_low);
67-
memory_offset |= static_cast<size_t>(memory_offset_high)
68-
<< (sizeof(size_t) - sizeof(uint32_t));
67+
memory_offset |= static_cast<size_t>(memory_offset_high) << 32;
6968
}
7069
return allocator->get_offset_address(memory_id, memory_offset, nbytes);
7170
}

0 commit comments

Comments
 (0)