Skip to content
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

[Zero-Dim] support ONEDNN 0D for full_kernel #51265

Merged
merged 1 commit into from
Mar 9, 2023
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
3 changes: 3 additions & 0 deletions paddle/phi/backends/onednn/onednn_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ inline OneDNNMemoryFormat OneDNNFormatForSize(size_t dims_size,

inline dnnl::memory::format_tag GetPlainOneDNNFormat(int tensor_rank) {
switch (tensor_rank) {
case 0:
// use 1D to represent 0D
return dnnl::memory::format_tag::a;
case 1:
return dnnl::memory::format_tag::a;
case 2:
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/kernels/onednn/transpose_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void TransposeGradKernel(const Context& dev_ctx,

const auto& onednn_engine = dev_ctx.GetEngine();

if (axis.size() == 1) {
if (axis.size() == 1 || axis.size() == 0) {
Copy<Context>(dev_ctx, out_grad, out_grad.place(), false, x_grad);
x_grad->set_mem_desc(out_grad.mem_desc());
return;
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/kernels/onednn/transpose_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void TransposeKernel(const Context& dev_ctx,
SetInMemDescWithLogicalLayoutFusesSupport(
dev_ctx, const_cast<DenseTensor*>(&x), x.mem_desc());

if (axis.size() == 1) {
if (axis.size() == 1 || axis.size() == 0) {
Copy<Context>(dev_ctx, x, x.place(), false, out);
out->set_mem_desc(x.mem_desc());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@ def initTestCase(self):
self.axis = (4, 2, 3, 1, 0, 5)


class TestCase_ZeroDim(TestTransposeMKLDNN):
def initTestCase(self):
self.shape = ()
self.axis = ()


if __name__ == '__main__':
unittest.main()