-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
{input_shape.dim(0), | ||
input_shape.dim(1) / (blocksize * blocksize), | ||
input_shape.dim(2) * blocksize, | ||
input_shape.dim(3) * blocksize}); | ||
} else { // channels_last | ||
updateOutputShape( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{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( |
{input_shape.dim(0), | ||
input_shape.dim(1) * blocksize, | ||
input_shape.dim(2) * blocksize, | ||
input_shape.dim(3) / (blocksize * blocksize)}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{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)}); | |
} |
ORT_RETURN_IF_ERROR(InputValidationsAndOutputDimsCalc<true>(input, | ||
batch, | ||
input_depth, input_height, input_width, | ||
output_depth, output_height, output_width, | ||
false)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)); | |
if (input.IsDataType<uint8_t>()) { | ||
|
||
return Transpose::DoTranspose( | ||
permutation, input, output, &virtual_input_shape, &virtual_output_shape, context->GetOperatorThreadPool()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()); | |
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | |
} |
TEST(DepthToSpaceOpTest, ContribCRD) { | ||
|
||
constexpr int64_t N = 2, H = 3, W = 2, C = 12; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
|
||
98, 102, 106, | ||
99, 103, 107, | ||
110, 114, 118, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
98, 102, 106, | |
99, 103, 107, | |
110, 114, 118, | |
98, 102, 106, | |
99, 103, 107, | |
110, 114, 118, |
134, 138, 142, | ||
135, 139, 143 | ||
}; | ||
std::vector<int64_t> output_shape = {N, H * blocksize, W * blocksize, C / (blocksize * blocksize)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Run lintrunner -a to apply this patch.
Description
Motivation and Context