diff --git a/paddle/fluid/operators/npu_op_runner.cc b/paddle/fluid/operators/npu_op_runner.cc index 7ccc6b60c1ef2dc26dab91fcdbf4c0efda3be4a3..f7c3597da4a68cc119108e4db1a25ffc902baff4 100644 --- a/paddle/fluid/operators/npu_op_runner.cc +++ b/paddle/fluid/operators/npu_op_runner.cc @@ -185,6 +185,21 @@ NpuOpRunner &NpuOpRunner::AddInputs(const std::vector &tensors) { return *this; } +// NOTE(zhiqiu): For operators whose input is a list (such as concat, stack), +// It is needed to set the name of each input tensor. +NpuOpRunner &NpuOpRunner::AddInputNames(const std::vector &names) { + PADDLE_ENFORCE_EQ(names.size(), input_descs_.size(), + platform::errors::InvalidArgument( + "The size of input names should be " + "equal to the size of input descs, but got the size " + "of input names is %d, the size of input descs is %d.", + names.size(), input_descs_.size())); + for (size_t i = 0; i < names.size(); ++i) { + aclSetTensorDescName(input_descs_[i], names[i].c_str()); + } + return *this; +} + NpuOpRunner &NpuOpRunner::AddOutputs(const std::vector &tensors) { for (auto tensor : tensors) { // create aclTensorDesc diff --git a/paddle/fluid/operators/npu_op_runner.h b/paddle/fluid/operators/npu_op_runner.h index 97468364eec7921f0bb71647506d3cfcca4f9cc7..2ead0d5b5458a69422fed0af4387e43161692d7c 100644 --- a/paddle/fluid/operators/npu_op_runner.h +++ b/paddle/fluid/operators/npu_op_runner.h @@ -53,6 +53,8 @@ class NpuOpRunner { NpuOpRunner &AddInputs(const std::vector &tensors); + NpuOpRunner &AddInputNames(const std::vector &names); + NpuOpRunner &AddOutputs(const std::vector &tensors); aclTensorDesc *GetInputDesc(size_t index);