Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <executorch/kernels/portable/cpu/util/kernel_ops_util.h>
#include <executorch/runtime/kernel/kernel_includes.h>

#include <cstring>

namespace torch {
namespace executor {
namespace native {
Expand Down Expand Up @@ -171,6 +173,13 @@ Tensor& max_pool2d_with_indices_backward_out(

static constexpr auto name = "max_pool2d_with_indices_backward.grad_input";

// max_pool_backward_impl scatter-adds into grad_input (`grad_input_ptr[maxindex] += ...`), writing
// only the argmax positions. resize_tensor does not clear the buffer and the memory planner recycles
// arena allocations across ops and iterations, so every other element would accumulate onto stale
// data. ATen zeroes gradInput before dispatching the identical loop
// (aten/src/ATen/native/DilatedMaxPool2d.cpp).
memset(grad_input.mutable_data_ptr(), 0, grad_input.nbytes());

ET_SWITCH_FLOATHBF16_TYPES(input.scalar_type(), ctx, name, CTYPE, [&]() {
max_pool_backward_impl<CTYPE, false>(grad_input, grad_output, indices);
});
Expand Down
Loading