Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions backends/arm/runtime/EthosUBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
ArrayRef<CompileSpec> compile_specs) const override {
ET_LOG(Info, "EthosUBackend::init %p", processed->data());

char* data = (char*)processed->data();
const char* data = static_cast<const char*>(processed->data());
size_t size = processed->size();

// Verify format of vela_bin
Expand Down Expand Up @@ -160,15 +160,17 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
// we might do it).
EthosUBackendExecuteCallbacks CollectArm_CPU_Cycles;

ExecutionHandle* execution_handle = (ExecutionHandle*)input_handle;
ExecutionHandle* execution_handle =
static_cast<ExecutionHandle*>(input_handle);
VelaHandles handles;

// Command stream - we know at this point it's aligned
EXECUTORCH_PROF_START(
event_tracer,
event_tracer_local_scope,
"+EthosUBackend::execute()processed_data");
char* data = (char*)execution_handle->processed->data();
const char* data =
static_cast<const char*>(execution_handle->processed->data());
EXECUTORCH_PROF_END(event_tracer, event_tracer_local_scope);

ET_LOG(Debug, "EthosUBackend::execute %p", data);
Expand Down Expand Up @@ -256,7 +258,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
handles.inputs->io[i].elem_size == 2;

// Select a compatible copy routine
if (both_char and permuted_input_shape) {
if (both_char && permuted_input_shape) {
EXECUTORCH_PROF_SCOPE(
event_tracer,
"+EthosUBackend::execute()handles.input.permute_CHW_to_HWC()");
Expand All @@ -267,7 +269,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
tensor_in.size(1),
tensor_in.size(2),
tensor_in.size(3));
} else if (both_char or both_int or both_short) {
} else if (both_char || both_int || both_short) {
EXECUTORCH_PROF_SCOPE(
event_tracer, "+EthosUBackend::execute()handles.input.memcpy()");
// Sizes match and elt size matches so memcpy
Expand Down Expand Up @@ -322,7 +324,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
event_tracer, event_tracer_local_scope, "+EthosUBackend::execute()NPU");
result = ethosu_invoke_v3(
driver.get(),
(void*)handles.cmd_data,
static_cast<const void*>(handles.cmd_data),
handles.cmd_data_size,
bases,
bases_size,
Expand Down Expand Up @@ -357,13 +359,14 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
bool permuted_output_shape;
ET_CHECK_OK_OR_RETURN_ERROR(check_requires_permute(
i, tensor_out, &handles.outputs->io[i], &permuted_output_shape));
if (tensor_out.scalar_type() == ScalarType::Char and
if (tensor_out.scalar_type() == ScalarType::Char &&
permuted_output_shape) {
EXECUTORCH_PROF_SCOPE(
event_tracer,
"+EthosUBackend::execute()handles.output.permute_HWC_to_CHW()");

char* output_address = (char*)output_addr;
const char* output_address = static_cast<const char*>(output_addr);

permute_HWC_to_CHW(
output_address,
tensor_out.mutable_data_ptr<char>(),
Expand All @@ -375,10 +378,11 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
event_tracer, "+EthosUBackend::execute()handles.output.move()");
for (int j = 0; j < tensor_out.numel(); j++) {
if (tensor_out.scalar_type() == ScalarType::Char) {
char* output_address = (char*)output_addr;
const char* output_address = static_cast<const char*>(output_addr);
tensor_out.mutable_data_ptr<char>()[j] = output_address[j];
} else {
int* output_address = (int*)output_addr;
const int* output_address =
reinterpret_cast<const int*>(output_addr);
tensor_out.mutable_data_ptr<int>()[j] = output_address[j];
}
}
Expand Down Expand Up @@ -435,7 +439,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
return Error::Ok;
}

void permute_CHW_to_HWC(char* input, char* output, int C, int H, int W)
void permute_CHW_to_HWC(const char* input, char* output, int C, int H, int W)
const {
for (int i = 0; i != H * W; ++i) {
for (int j = 0; j < C; ++j) {
Expand All @@ -444,7 +448,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
}
}

void permute_HWC_to_CHW(char* input, char* output, int C, int H, int W)
void permute_HWC_to_CHW(const char* input, char* output, int C, int H, int W)
const {
for (int i = 0; i != H * W; ++i) {
for (int j = 0; j < C; ++j) {
Expand Down
13 changes: 7 additions & 6 deletions backends/arm/runtime/VelaBinStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ bool vela_bin_validate(const char* data, int size) {
// Check 16 byte alignment
bool valid = true;
if ((uintptr_t)data != next_mul_16((uintptr_t)data)) {
ET_LOG(Error, "Vela bin ptr not aligned to 16 bytes: %p", (void*)data);
ET_LOG(Error, "Vela bin ptr not aligned to 16 bytes: %p", data);
valid = false;
}
if ((uintptr_t)foot != next_mul_16((uintptr_t)foot)) {
ET_LOG(Error, "End of vela bin not aligned to 16 bytes: %p", (void*)foot);
ET_LOG(Error, "End of vela bin not aligned to 16 bytes: %p", foot);
valid = false;
}
// Check header and footer blocks are the right format
Expand All @@ -55,12 +55,13 @@ bool vela_bin_read(const char* data, VelaHandles* handles, int size) {
const char* ptr = data;

while (ptr - data < size) {
VelaBinBlock* b = (VelaBinBlock*)ptr;
VelaBinBlock* b = reinterpret_cast<VelaBinBlock*>(const_cast<char*>(ptr));
ptr += sizeof(VelaBinBlock) + next_mul_16(b->size);

if (!strncmp(b->name, "vela_bin_stream", strlen("vela_bin_stream"))) {
// expect vela_bin_stream first
if ((char*)b != (char*)data)
if (reinterpret_cast<char*>(b) !=
reinterpret_cast<char*>(const_cast<char*>(data)))
return false;
} else if (!strncmp(b->name, "cmd_data", strlen("cmd_data"))) {
// This driver magic header confirms a valid command stream in binary
Expand All @@ -76,9 +77,9 @@ bool vela_bin_read(const char* data, VelaHandles* handles, int size) {
reinterpret_cast<const uint32_t*>(b->data);
handles->scratch_data_size = *scratch_size_ptr;
} else if (!strncmp(b->name, "inputs", strlen("inputs"))) {
handles->inputs = (VelaIOs*)b->data;
handles->inputs = reinterpret_cast<VelaIOs*>(b->data);
} else if (!strncmp(b->name, "outputs", strlen("outputs"))) {
handles->outputs = (VelaIOs*)b->data;
handles->outputs = reinterpret_cast<VelaIOs*>(b->data);
} else if (!strncmp(
b->name, "vela_end_stream", strlen("vela_end_stream"))) {
// expect vela_end_stream last
Expand Down
Loading