Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion paddle/phi/kernels/xpu/strided_copy_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ void StridedCopyKernel(const Context& dev_ctx,
r = xpu::copy<XPUType>(dev_ctx.x_context(), input_data, output_data, 1);
PADDLE_ENFORCE_XDNN_SUCCESS(r, "copy");
} else {
int64_t data_size = input.Holder()->size() - input.meta().offset;
int64_t data_size_in = input.Holder()->size() - input.meta().offset;
int64_t data_size_out = out->Holder()->size() - out->meta().offset;
int64_t data_size = std::max(data_size_in, data_size_out);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strided_copy的size是不是应该跟out的size有关?如果in的size大于out的size,他是有多个输入写到同一个输出地址吗?overwrite?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的data_size是指原始的数据大小,即显存里实际存放的大小,不是逻辑上的tensor大小,输入输出的data_size由于stride的存在都有可能远大于tensor.numel(),是否overwrite由stride和shape共同控制,合法的strided_copy不应该存在overwrite的情形。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

理论上是不是不需要data_size这个参数?tensor的dim和stride可以推算出来

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加上这个参数 1 是为了做合法校验,防止paddle的bug,api参数检查会通过tensor的dim和stride计算tensor大小,不能大于data_size 2 对于API来说是必要的,因为单测要分配原始tensor大小的显存,需要预先定好

r = xpu::strided_copy<XPUType>(dev_ctx.x_context(),
input_data,
output_data,
Expand Down
Loading