Skip to content

Commit a0b997c

Browse files
committed
Bug fix in Ethos runtime backend (#9517)
Summary: See the comment in source for explanation. Differential Revision: D71658384
1 parent 0dd7e4e commit a0b997c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

backends/arm/runtime/EthosUBackend.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ void __attribute__((weak)) EthosUBackend_execute_begin() {}
8383
void __attribute__((weak)) EthosUBackend_execute_end() {}
8484
}
8585

86+
// If the address is >= 0x80000000, cast to uint64_t signed extends it to 0xFFFFFFFFXXXXXXXX,
87+
// which causes address validity check in Ethos driver to fail. Given Cortex-M is 32-bit, it
88+
// is safe to clear the upper 32 bits after the cast and keep the address valid.
89+
static inline uint64_t cast_address_to_uint64(void* p) {
90+
return (0xFFFFFFFF & reinterpret_cast<uint64_t>(p));
91+
}
92+
8693
class EthosUBackendExecuteCallbacks {
8794
public:
8895
EthosUBackendExecuteCallbacks() {
@@ -282,7 +289,8 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
282289
// constant weight data, then scratch (which contains input and output)
283290
// scratch is written above in this function.
284291
uint64_t bases[2] = {
285-
(uint64_t)handles.weight_data, (uint64_t)handles.scratch_data};
292+
cast_address_to_uint64(handles.weight_data),
293+
cast_address_to_uint64(handles.scratch_data)};
286294
size_t bases_size[2] = {
287295
handles.weight_data_size, handles.scratch_data_size};
288296
int result = 0;

0 commit comments

Comments
 (0)