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
7 changes: 5 additions & 2 deletions backends/cadence/fusion_g3/operators/op_native_layer_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,15 @@ std::tuple<Tensor&, Tensor&, Tensor&> native_layer_norm_out(
num_elm *= normalized_shape[i];
}

constexpr size_t kAlignment =
16; // 16-byte alignment for vectorized operations

float* weight_data;
if (weight.has_value()) {
weight_data = weight.value().mutable_data_ptr<float>();
} else {
executorch::runtime::Result<void*> temp_mem_weight =
ctx.allocate_temp(num_elm * sizeof(float));
ctx.allocate_temp(num_elm * sizeof(float), kAlignment);
weight_data = (float*)(temp_mem_weight.get());

for (int i = 0; i < num_elm; i++) {
Expand All @@ -238,7 +241,7 @@ std::tuple<Tensor&, Tensor&, Tensor&> native_layer_norm_out(
bias_data = bias.value().mutable_data_ptr<float>();
} else {
executorch::runtime::Result<void*> temp_mem_bias =
ctx.allocate_temp(num_elm * sizeof(float));
ctx.allocate_temp(num_elm * sizeof(float), kAlignment);
bias_data = (float*)(temp_mem_bias.get());

for (int i = 0; i < num_elm; i++) {
Expand Down
14 changes: 11 additions & 3 deletions backends/cadence/hifi/kernels/kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ memcpy(void* dst, const void* src, size_t num_bytes) {
}

void* allocate_temp_memory(KernelRuntimeContext& ctx, size_t size) {
ET_LOG(Info, "Attempting to allocate %zu bytes of temp memory", size);
Result<void*> temp_mem_res = ctx.allocate_temp(size);
constexpr size_t kAlignment =
16; // 16-byte alignment for vectorized operations
ET_LOG(
Info,
"Attempting to allocate %zu bytes of temp memory (16-byte aligned)",
size);
Result<void*> temp_mem_res = ctx.allocate_temp(size, kAlignment);
if (temp_mem_res.ok()) {
void* ptr = temp_mem_res.get();
ET_LOG(Info, "Successfully allocated temp memory at %p", ptr);
ET_LOG(
Info,
"Successfully allocated temp memory at %p (16-byte aligned)",
ptr);
return ptr;
} else {
ET_LOG(
Expand Down
Loading