Skip to content

[NPU]pad kernel support nonzero padding value #1702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
20 changes: 2 additions & 18 deletions backends/npu/kernels/pad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ void AclopPadKernel(const Context& dev_ctx,

auto pad_value = pad_value_scalar.to<float>();

PADDLE_ENFORCE_LT(
abs(pad_value),
1e-5,
phi::errors::Unimplemented("npu npu only support pad_value=0 right now,"
"but received pad_value is %f .",
pad_value));

NpuOpRunner runner;
runner.SetType("Pad")
.AddInput(x)
Expand All @@ -56,24 +49,15 @@ void PadKernel(const Context& dev_ctx,

dev_ctx.template Alloc<T>(out);
auto stream = dev_ctx.stream();
auto pad_value = pad_value_scalar.to<float>();

PADDLE_ENFORCE_LT(
abs(pad_value),
1e-5,
phi::errors::Unimplemented("npu npu only support pad_value=0 right now,"
"but received pad_value is %f .",
pad_value));

phi::Scalar value = 0;
std::vector<int64_t> paddings_;
int x_dims = x.dims().size();
for (int i = x_dims - 1; i >= 0; --i) {
paddings_.push_back(paddings[2 * i]);
paddings_.push_back(paddings[2 * i + 1]);
}

EXEC_NPU_CMD(aclnnConstantPadNd, dev_ctx, x, paddings_, value, *out);
EXEC_NPU_CMD(
aclnnConstantPadNd, dev_ctx, x, paddings_, pad_value_scalar, *out);
}

template <typename T, typename Context>
Expand Down