@@ -16,9 +16,7 @@ namespace ce = compute_engine;
16
16
// operation itself while the uniform tests are used to verify the bitpacking
17
17
// with different bitwidths
18
18
template <class TIn >
19
- void test_bitpacking_nonuniform_input_rowwise () {
20
- const auto bitpacking_axis = ce::core::Axis::RowWise;
21
-
19
+ void test_bitpacking_nonuniform_input () {
22
20
// input matrix (row-major memory laytout)
23
21
const std::size_t num_rows = 2 , num_cols = 8 ;
24
22
std::array<TIn, 16 > input{1 , 1 , -1 , 1 , -1 , -1 , -1 , 1 ,
@@ -32,164 +30,71 @@ void test_bitpacking_nonuniform_input_rowwise() {
32
30
else
33
31
expected = {0b01110100 , 0b00111010 };
34
32
35
- std::vector<std::uint8_t > output;
36
- std::size_t num_rows_bp = 0 , num_cols_bp = 0 , bitpadding = 0 ;
37
- ce::core::packbits_matrix<ce::core::BitpackOrder::Optimized>(
38
- input.data (), num_rows, num_cols, output, num_rows_bp, num_cols_bp,
39
- bitpadding, bitpacking_axis);
40
-
41
- EXPECT_EQ (num_rows_bp, expected_num_rows);
42
- EXPECT_EQ (num_cols_bp, expected_num_cols);
43
- EXPECT_EQ (output.size (), num_rows_bp * num_cols_bp);
44
- EXPECT_THAT (output, ::testing::ElementsAreArray (expected));
45
- }
46
-
47
- template <class TIn >
48
- void test_bitpacking_nonuniform_input_colwise () {
49
- const auto bitpacking_axis = ce::core::Axis::ColWise;
50
-
51
- // input matrix (row-major memory laytout)
52
- const std::size_t num_rows = 8 , num_cols = 2 ;
53
- std::array<TIn, 16 > input{1 , 1 , 1 , -1 , -1 , 1 , 1 , -1 ,
54
- -1 , -1 , -1 , -1 , -1 , 1 , 1 , 1 };
55
-
56
- // expected output matrix after bitpacking
57
- const std::size_t expected_num_rows = 1 , expected_num_cols = 2 ;
58
- std::vector<std::uint8_t > expected;
59
- if (CE_IS_BIG_ENDIAN)
60
- expected = {0b00101110 , 0b01011100 };
61
- else
62
- expected = {0b01110100 , 0b00111010 };
63
-
64
- std::vector<std::uint8_t > output;
65
- std::size_t num_rows_bp = 0 , num_cols_bp = 0 , bitpadding = 0 ;
33
+ std::vector<std::uint8_t > output (
34
+ ce::core::GetPackedMatrixSize<std::uint8_t >(num_rows, num_cols));
66
35
ce::core::packbits_matrix<ce::core::BitpackOrder::Optimized>(
67
- input.data (), num_rows, num_cols, output, num_rows_bp, num_cols_bp,
68
- bitpadding, bitpacking_axis);
36
+ input.data (), num_rows, num_cols, output.data ());
69
37
70
- EXPECT_EQ (num_rows_bp, expected_num_rows);
71
- EXPECT_EQ (num_cols_bp, expected_num_cols);
72
- EXPECT_EQ (output.size (), num_rows_bp * num_cols_bp);
73
38
EXPECT_THAT (output, ::testing::ElementsAreArray (expected));
74
39
}
75
40
76
41
template <class TIn , class TOut , std::size_t num_rows, std::size_t num_cols>
77
- void test_bitpacking (const ce::core::Axis bitpacking_axis,
78
- const std::size_t expected_num_rows,
42
+ void test_bitpacking (const std::size_t expected_num_rows,
79
43
const std::size_t expected_num_cols) {
80
44
const std::size_t bitwidth = std::numeric_limits<TOut>::digits;
81
45
82
46
const std::size_t num_elems = num_rows * num_cols;
83
47
std::array<TIn, num_elems> input;
84
48
input.fill (-1 );
85
49
86
- std::vector<TOut> output;
87
- std:: size_t num_rows_bp = 0 , num_cols_bp = 0 , bitpadding = 0 ;
50
+ std::vector<TOut> output (
51
+ ce::core::GetPackedMatrixSize<TOut>(num_rows, num_cols)) ;
88
52
ce::core::packbits_matrix<ce::core::BitpackOrder::Optimized>(
89
- input.data (), num_rows, num_cols, output, num_rows_bp, num_cols_bp,
90
- bitpadding, bitpacking_axis);
53
+ input.data (), num_rows, num_cols, output.data ());
91
54
92
55
TOut expected_value = std::numeric_limits<TOut>::max ();
93
56
const std::size_t num_elems_bp = num_elems / bitwidth;
94
57
std::array<TOut, num_elems_bp> expected;
95
58
expected.fill (expected_value);
96
59
97
- EXPECT_EQ (num_rows_bp, expected_num_rows);
98
- EXPECT_EQ (num_cols_bp, expected_num_cols);
99
- EXPECT_EQ (bitpadding, 0 );
100
- EXPECT_EQ (output.size (), num_rows_bp * num_cols_bp);
101
60
EXPECT_THAT (output, ::testing::ElementsAreArray (expected));
102
61
}
103
62
104
63
TEST (BitpackingTests, BitpackingRowMajorUInt8NonUniformInput) {
105
- test_bitpacking_nonuniform_input_rowwise<float >();
106
- }
107
-
108
- TEST (BitpackingTests, BitpackingColMajorUInt8NonUniformInput) {
109
- test_bitpacking_nonuniform_input_colwise<float >();
64
+ test_bitpacking_nonuniform_input<float >();
110
65
}
111
66
112
67
TEST (BitpackingTests, BitpackingRowMajorUInt8) {
113
- test_bitpacking<float , std::uint8_t , 2 , 128 >(ce::core::Axis::RowWise, 2 , 16 );
68
+ test_bitpacking<float , std::uint8_t , 2 , 128 >(2 , 16 );
114
69
}
115
70
116
71
TEST (BitpackingTests, BitpackingRowMajorUInt32) {
117
- test_bitpacking<float , std::uint32_t , 2 , 128 >(ce::core::Axis::RowWise, 2 , 4 );
72
+ test_bitpacking<float , std::uint32_t , 2 , 128 >(2 , 4 );
118
73
}
119
74
120
75
TEST (BitpackingTests, BitpackingRowMajorUInt64) {
121
- test_bitpacking<float , std::uint64_t , 2 , 128 >(ce::core::Axis::RowWise, 2 , 2 );
122
- }
123
-
124
- TEST (BitpackingTests, BitpackingColumnMajorUInt8) {
125
- test_bitpacking<float , std::uint8_t , 128 , 2 >(ce::core::Axis::ColWise, 16 , 2 );
126
- }
127
-
128
- TEST (BitpackingTests, BitpackingColumnMajorUInt32) {
129
- test_bitpacking<float , std::uint32_t , 128 , 2 >(ce::core::Axis::ColWise, 4 , 2 );
130
- }
131
-
132
- TEST (BitpackingTests, BitpackingColumnMajorUInt64) {
133
- test_bitpacking<float , std::uint64_t , 128 , 2 >(ce::core::Axis::ColWise, 2 , 2 );
76
+ test_bitpacking<float , std::uint64_t , 2 , 128 >(2 , 2 );
134
77
}
135
78
136
79
TEST (BitpackingWithBitPaddingTests, RowMajorPadding) {
137
- const auto bitpacking_axis = ce::core::Axis::RowWise;
138
80
// input matrix
139
81
const int num_rows = 2 ;
140
82
const int num_cols = 9 ;
141
83
std::vector<float > input{-1 , -1 , 1 , -1 , 1 , 1 , 1 , -1 , -1 ,
142
84
-1 , 1 , -1 , 1 , 1 , 1 , -1 , -1 , 1 };
143
85
144
86
// expected output matrix after bitpacking
145
- const std::size_t expected_num_rows = 2 ;
146
- const std::size_t expected_num_cols = 2 ;
147
87
std::vector<std::uint8_t > expected;
148
88
if (CE_IS_BIG_ENDIAN)
149
89
expected = {0b11010001 , 0b10000000 , 0b10100011 , 0b00000000 };
150
90
else
151
91
expected = {0b10001011 , 0b00000001 , 0b11000101 , 0b00000000 };
152
92
153
- std::vector<std::uint8_t > output;
154
- std::size_t num_rows_bp = 0 , num_cols_bp = 0 , bitpadding = 0 ;
155
- ce::core::packbits_matrix<ce::core::BitpackOrder::Optimized>(
156
- input.data (), num_rows, num_cols, output, num_rows_bp, num_cols_bp,
157
- bitpadding, bitpacking_axis);
158
-
159
- EXPECT_EQ (num_rows_bp, expected_num_rows);
160
- EXPECT_EQ (num_cols_bp, expected_num_cols);
161
- EXPECT_EQ (bitpadding, 7 );
162
- EXPECT_EQ (output.size (), num_rows_bp * num_cols_bp);
163
- EXPECT_THAT (output, ::testing::ElementsAreArray (expected));
164
- };
165
-
166
- TEST (BitpackingWithBitPaddingTests, ColMajorPadding) {
167
- const auto bitpacking_axis = ce::core::Axis::ColWise;
168
- // The input matrix is:
169
- const int num_rows = 9 ;
170
- const int num_cols = 2 ;
171
- std::vector<float > input{-1 , -1 , -1 , 1 , 1 , -1 , -1 , 1 , 1 ,
172
- 1 , 1 , 1 , 1 , -1 , -1 , -1 , -1 , 1 };
173
-
174
- // expected output matrix after bitpacking
175
- const std::size_t expected_num_rows = 2 ;
176
- const std::size_t expected_num_cols = 2 ;
177
- std::vector<std::uint8_t > expected;
178
- if (CE_IS_BIG_ENDIAN)
179
- expected = {0b11010001 , 0b10100011 , 0b10000000 , 0b00000000 };
180
- else
181
- expected = {0b10001011 , 0b11000101 , 0b00000001 , 0b00000000 };
182
-
183
- std::vector<std::uint8_t > output;
184
- std::size_t num_rows_bp = 0 , num_cols_bp = 0 , bitpadding = 0 ;
93
+ std::vector<std::uint8_t > output (
94
+ ce::core::GetPackedMatrixSize<std::uint8_t >(num_rows, num_cols));
185
95
ce::core::packbits_matrix<ce::core::BitpackOrder::Optimized>(
186
- input.data (), num_rows, num_cols, output, num_rows_bp, num_cols_bp,
187
- bitpadding, bitpacking_axis);
96
+ input.data (), num_rows, num_cols, output.data ());
188
97
189
- EXPECT_EQ (num_rows_bp, expected_num_rows);
190
- EXPECT_EQ (num_cols_bp, expected_num_cols);
191
- EXPECT_EQ (bitpadding, 7 );
192
- EXPECT_EQ (output.size (), num_rows_bp * num_cols_bp);
193
98
EXPECT_THAT (output, ::testing::ElementsAreArray (expected));
194
99
};
195
100
0 commit comments