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

NHWC DepthToSpace U8 and its transformation #23784

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

yihonglyu
Copy link
Contributor

Description

Motivation and Context

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

You can commit the suggested changes from lintrunner.

Comment on lines +3743 to +3748
{input_shape.dim(0),
input_shape.dim(1) / (blocksize * blocksize),
input_shape.dim(2) * blocksize,
input_shape.dim(3) * blocksize});
} else { // channels_last
updateOutputShape(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{input_shape.dim(0),
input_shape.dim(1) / (blocksize * blocksize),
input_shape.dim(2) * blocksize,
input_shape.dim(3) * blocksize});
} else { // channels_last
updateOutputShape(
{input_shape.dim(0),
input_shape.dim(1) / (blocksize * blocksize),
input_shape.dim(2) * blocksize,
input_shape.dim(3) * blocksize});
} else { // channels_last
updateOutputShape(

Comment on lines +3751 to +3755
{input_shape.dim(0),
input_shape.dim(1) * blocksize,
input_shape.dim(2) * blocksize,
input_shape.dim(3) / (blocksize * blocksize)});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{input_shape.dim(0),
input_shape.dim(1) * blocksize,
input_shape.dim(2) * blocksize,
input_shape.dim(3) / (blocksize * blocksize)});
}
{input_shape.dim(0),
input_shape.dim(1) * blocksize,
input_shape.dim(2) * blocksize,
input_shape.dim(3) / (blocksize * blocksize)});
}

Comment on lines +174 to +179
ORT_RETURN_IF_ERROR(InputValidationsAndOutputDimsCalc<true>(input,
batch,
input_depth, input_height, input_width,
output_depth, output_height, output_width,
false));

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ORT_RETURN_IF_ERROR(InputValidationsAndOutputDimsCalc<true>(input,
batch,
input_depth, input_height, input_width,
output_depth, output_height, output_width,
false));
ORT_RETURN_IF_ERROR(InputValidationsAndOutputDimsCalc<true>(input,
batch,
input_depth, input_height, input_width,
output_depth, output_height, output_width,
false));

Comment on lines +201 to +205
if (input.IsDataType<uint8_t>()) {

return Transpose::DoTranspose(
permutation, input, output, &virtual_input_shape, &virtual_output_shape, context->GetOperatorThreadPool());

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (input.IsDataType<uint8_t>()) {
return Transpose::DoTranspose(
permutation, input, output, &virtual_input_shape, &virtual_output_shape, context->GetOperatorThreadPool());
if (input.IsDataType<uint8_t>()) {
return Transpose::DoTranspose(
permutation, input, output, &virtual_input_shape, &virtual_output_shape, context->GetOperatorThreadPool());

Comment on lines +45 to +135
TEST(DepthToSpaceOpTest, ContribDCR) {

constexpr int64_t N = 2, H = 3, W = 2, C = 12;
constexpr int64_t blocksize = 2;
std::vector<uint8_t> input = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,

24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,

48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,


72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,

96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,

120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143
};
std::vector<int64_t> input_shape = {N, H, W, C};
std::vector<uint8_t> output = {
0, 1, 2,
3, 4, 5,
12, 13, 14,
15, 16, 17,

6, 7, 8,
9, 10, 11,
18, 19, 20,
21, 22, 23,

24, 25, 26,
27, 28, 29,
36, 37, 38,
39, 40, 41,

30, 31, 32,
33, 34, 35,
42, 43, 44,
45, 46, 47,

48, 49, 50,
51, 52, 53,
60, 61, 62,
63, 64, 65,

54, 55, 56,
57, 58, 59,
66, 67, 68,
69, 70, 71,


72, 73, 74,
75, 76, 77,
84, 85, 86,
87, 88, 89,

78, 79, 80,
81, 82, 83,
90, 91, 92,
93, 94, 95,

96, 97, 98,
99, 100, 101,
108, 109, 110,
111, 112, 113,

102, 103, 104,
105, 106, 107,
114, 115, 116,
117, 118, 119,

120, 121, 122,
123, 124, 125,
132, 133, 134,
135, 136, 137,

126, 127, 128,
129, 130, 131,
138, 139, 140,
141, 142, 143
};
std::vector<int64_t> output_shape = {N, H * blocksize, W * blocksize, C / (blocksize * blocksize)};

RunDepthToSpace<uint8_t>(input, input_shape, blocksize, 1, "DCR", output, output_shape);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TEST(DepthToSpaceOpTest, ContribDCR) {
constexpr int64_t N = 2, H = 3, W = 2, C = 12;
constexpr int64_t blocksize = 2;
std::vector<uint8_t> input = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143
};
std::vector<int64_t> input_shape = {N, H, W, C};
std::vector<uint8_t> output = {
0, 1, 2,
3, 4, 5,
12, 13, 14,
15, 16, 17,
6, 7, 8,
9, 10, 11,
18, 19, 20,
21, 22, 23,
24, 25, 26,
27, 28, 29,
36, 37, 38,
39, 40, 41,
30, 31, 32,
33, 34, 35,
42, 43, 44,
45, 46, 47,
48, 49, 50,
51, 52, 53,
60, 61, 62,
63, 64, 65,
54, 55, 56,
57, 58, 59,
66, 67, 68,
69, 70, 71,
72, 73, 74,
75, 76, 77,
84, 85, 86,
87, 88, 89,
78, 79, 80,
81, 82, 83,
90, 91, 92,
93, 94, 95,
96, 97, 98,
99, 100, 101,
108, 109, 110,
111, 112, 113,
102, 103, 104,
105, 106, 107,
114, 115, 116,
117, 118, 119,
120, 121, 122,
123, 124, 125,
132, 133, 134,
135, 136, 137,
126, 127, 128,
129, 130, 131,
138, 139, 140,
141, 142, 143
};
std::vector<int64_t> output_shape = {N, H * blocksize, W * blocksize, C / (blocksize * blocksize)};
RunDepthToSpace<uint8_t>(input, input_shape, blocksize, 1, "DCR", output, output_shape);
}
TEST(DepthToSpaceOpTest, ContribDCR) {
constexpr int64_t N = 2, H = 3, W = 2, C = 12;
constexpr int64_t blocksize = 2;
std::vector<uint8_t> input = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143};
std::vector<int64_t> input_shape = {N, H, W, C};
std::vector<uint8_t> output = {
0, 1, 2,
3, 4, 5,
12, 13, 14,
15, 16, 17,
6, 7, 8,
9, 10, 11,
18, 19, 20,
21, 22, 23,
24, 25, 26,
27, 28, 29,
36, 37, 38,
39, 40, 41,
30, 31, 32,
33, 34, 35,
42, 43, 44,
45, 46, 47,
48, 49, 50,
51, 52, 53,
60, 61, 62,
63, 64, 65,
54, 55, 56,
57, 58, 59,
66, 67, 68,
69, 70, 71,
72, 73, 74,
75, 76, 77,
84, 85, 86,
87, 88, 89,
78, 79, 80,
81, 82, 83,
90, 91, 92,
93, 94, 95,
96, 97, 98,
99, 100, 101,
108, 109, 110,
111, 112, 113,
102, 103, 104,
105, 106, 107,
114, 115, 116,
117, 118, 119,
120, 121, 122,
123, 124, 125,
132, 133, 134,
135, 136, 137,
126, 127, 128,
129, 130, 131,
138, 139, 140,
141, 142, 143};
std::vector<int64_t> output_shape = {N, H * blocksize, W * blocksize, C / (blocksize * blocksize)};
RunDepthToSpace<uint8_t>(input, input_shape, blocksize, 1, "DCR", output, output_shape);
}

Comment on lines +137 to +139
TEST(DepthToSpaceOpTest, ContribCRD) {

constexpr int64_t N = 2, H = 3, W = 2, C = 12;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TEST(DepthToSpaceOpTest, ContribCRD) {
constexpr int64_t N = 2, H = 3, W = 2, C = 12;
TEST(DepthToSpaceOpTest, ContribCRD) {
constexpr int64_t N = 2, H = 3, W = 2, C = 12;

Comment on lines +141 to +156
std::vector<uint8_t> input = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,

24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,

48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,


72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,

96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
std::vector<uint8_t> input = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
std::vector<uint8_t> input = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,

Comment on lines +158 to +206
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143
};
std::vector<int64_t> input_shape = {N, H, W, C};
std::vector<uint8_t> output = {
0, 4, 8,
1, 5, 9,
12, 16, 20,
13, 17, 21,

2, 6, 10,
3, 7, 11,
14, 18, 22,
15, 19, 23,

24, 28, 32,
25, 29, 33,
36, 40, 44,
37, 41, 45,

26, 30, 34,
27, 31, 35,
38, 42, 46,
39, 43, 47,

48, 52, 56,
49, 53, 57,
60, 64, 68,
61, 65, 69,

50, 54, 58,
51, 55, 59,
62, 66, 70,
63, 67, 71,


72, 76, 80,
73, 77, 81,
84, 88, 92,
85, 89, 93,

74, 78, 82,
75, 79, 83,
86, 90, 94,
87, 91, 95,

96, 100, 104,
97, 101, 105,
108, 112, 116,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143
};
std::vector<int64_t> input_shape = {N, H, W, C};
std::vector<uint8_t> output = {
0, 4, 8,
1, 5, 9,
12, 16, 20,
13, 17, 21,
2, 6, 10,
3, 7, 11,
14, 18, 22,
15, 19, 23,
24, 28, 32,
25, 29, 33,
36, 40, 44,
37, 41, 45,
26, 30, 34,
27, 31, 35,
38, 42, 46,
39, 43, 47,
48, 52, 56,
49, 53, 57,
60, 64, 68,
61, 65, 69,
50, 54, 58,
51, 55, 59,
62, 66, 70,
63, 67, 71,
72, 76, 80,
73, 77, 81,
84, 88, 92,
85, 89, 93,
74, 78, 82,
75, 79, 83,
86, 90, 94,
87, 91, 95,
96, 100, 104,
97, 101, 105,
108, 112, 116,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143};
std::vector<int64_t> input_shape = {N, H, W, C};
std::vector<uint8_t> output = {
0, 4, 8,
1, 5, 9,
12, 16, 20,
13, 17, 21,
2, 6, 10,
3, 7, 11,
14, 18, 22,
15, 19, 23,
24, 28, 32,
25, 29, 33,
36, 40, 44,
37, 41, 45,
26, 30, 34,
27, 31, 35,
38, 42, 46,
39, 43, 47,
48, 52, 56,
49, 53, 57,
60, 64, 68,
61, 65, 69,
50, 54, 58,
51, 55, 59,
62, 66, 70,
63, 67, 71,
72, 76, 80,
73, 77, 81,
84, 88, 92,
85, 89, 93,
74, 78, 82,
75, 79, 83,
86, 90, 94,
87, 91, 95,
96, 100, 104,
97, 101, 105,
108, 112, 116,

Comment on lines +208 to +211

98, 102, 106,
99, 103, 107,
110, 114, 118,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
98, 102, 106,
99, 103, 107,
110, 114, 118,
98, 102, 106,
99, 103, 107,
110, 114, 118,

Comment on lines +221 to +224
134, 138, 142,
135, 139, 143
};
std::vector<int64_t> output_shape = {N, H * blocksize, W * blocksize, C / (blocksize * blocksize)};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
134, 138, 142,
135, 139, 143
};
std::vector<int64_t> output_shape = {N, H * blocksize, W * blocksize, C / (blocksize * blocksize)};
134, 138, 142,
135, 139, 143};
std::vector<int64_t> output_shape = {N, H * blocksize, W * blocksize, C / (blocksize * blocksize)};

@@ -0,0 +1,230 @@
// Copyright (c) Microsoft Corporation. All rights reserved.

Check warning

Code scanning / lintrunner

CLANGFORMAT/format Warning test

See https://clang.llvm.org/docs/ClangFormat.html.
Run lintrunner -a to apply this patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant