Created
October 25, 2015 23:26
-
-
Save petewarden/6c534a78b59099aae529 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Runs a small set of hand-calculated data through the implementation. | |
void TestWithSmallData() { | |
const int m = 4; | |
const int n = 2; | |
const int k = 3; | |
// Matrix A (LHS) is: | |
// | 7 | 10 | 13 | 16 | | |
// | 8 | 11 | 14 | 17 | | |
// | 9 | 12 | 15 | 18 | | |
const uint8_t a_data[] = {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; | |
// Matrix B (RHS) is: | |
// | 1 | 3 | 5 | | |
// | 2 | 4 | 6 | | |
const uint8_t b_data[] = {1, 2, 3, 4, 5, 6}; | |
// Here are the results we expect, from hand calculations: | |
// (1 * 7) + (3 * 8) + (5 * 9) = 76 | |
// (2 * 7) + (4 * 8) + (6 * 9) = 100 | |
// (1 * 10) + (3 * 11) + (5 * 12) = 103 | |
// (2 * 10) + (4 * 11) + (6 * 12) = 136 | |
// (1 * 13) + (3 * 14) + (5 * 15) = 130 | |
// (2 * 13) + (4 * 14) + (6 * 15) = 172 | |
// (1 * 16) + (3 * 17) + (5 * 18) = 157 | |
// (2 * 16) + (4 * 17) + (6 * 18) = 208 | |
// That means matrix C should be: | |
// | 76 | 103 | 130 | 157 | | |
// | 100 | 136 | 172 | 208 | | |
const uint8_t expected_data[] = {76, 100, 103, 136, 130, 172, 157, 208}; | |
const int c_count = m * n; | |
std::unique_ptr<uint8_t[]> output_data(new uint8_t[c_count]); | |
const bool is_a_transposed = true; | |
const bool is_b_transposed = true; | |
const bool is_c_transposed = true; | |
const int lda = k; | |
const int ldb = n; | |
const int ldc = n; | |
const int a_offset = 0; | |
const int b_offset = 0; | |
const int c_offset = 0; | |
const int c_mult = 1; | |
const int c_shift = 0; | |
gemmlowp::eight_bit_int_gemm::EightBitIntGemm( | |
is_a_transposed, is_b_transposed, is_c_transposed, m, n, k, a_data, | |
a_offset, lda, b_data, b_offset, ldb, output_data.get(), c_offset, | |
c_mult, c_shift, ldc, eight_bit_int_gemm::BitDepthSetting::A8B8); | |
ResultStats stats; | |
GetResultStats(output_data.get(), expected_data, c_count, &stats); | |
ResultStatsBounds bounds; | |
const bool good = CheckResultStatsBounds(stats, bounds); | |
printf("TestWithSmallData: %s\n", good ? "PASS" : "FAIL"); | |
ReportResultStats(stats, bounds); | |
Check(good); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment