-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds standalone test for data pooling. Signed-off-by: Alan Green <[email protected]>
- Loading branch information
1 parent
21a4efb
commit 85bedda
Showing
8 changed files
with
4,510 additions
and
38 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2021 The CFU-Playground Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef _POOL_03_H | ||
#define _POOL_03_H | ||
|
||
#include <cstdint> | ||
|
||
#include "pool_call.h" | ||
|
||
extern PoolData pool_03_data; | ||
|
||
#endif // _POOL_03_H |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2022 The CFU-Playground Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "pool_call.h" | ||
|
||
#include <cstdio> | ||
|
||
#include "playground_util/dump.h" | ||
#include "tensorflow/lite/kernels/internal/reference/integer_ops/pooling.h" | ||
#include "tflite.h" | ||
|
||
void test_pool(const PoolData* data) { | ||
printf("Testing Pool %s\n", data->name); | ||
// Copy input arena | ||
int8_t* arena_input = reinterpret_cast<int8_t*>(tflite_tensor_arena); | ||
auto input_shape = | ||
*(reinterpret_cast<const tflite::RuntimeShape*>(data->input_shape)); | ||
for (int i = 0; i < input_shape.FlatSize(); i++) { | ||
arena_input[i] = data->input_data[i]; | ||
} | ||
// Set up output arena | ||
int8_t* arena_output = | ||
reinterpret_cast<int8_t*>(tflite_tensor_arena) + 128 * 1024; | ||
const tflite::RuntimeShape& output_shape = | ||
*(reinterpret_cast<const tflite::RuntimeShape*>(data->output_shape)); | ||
|
||
tflite::reference_integer_ops::MaxPool( | ||
*(reinterpret_cast<const tflite::PoolParams*>(data->params)), input_shape, | ||
arena_input, output_shape, arena_output); | ||
|
||
// Check for differences with output | ||
int diff_count = 0; | ||
int first_diff = 0; | ||
int num_words = output_shape.FlatSize() / 4; | ||
const int32_t* arena_words = reinterpret_cast<const int32_t*>(arena_output); | ||
const int32_t* expected_words = | ||
reinterpret_cast<const int32_t*>(data->output_data); | ||
for (int i = 0; i < num_words; i++) { | ||
if (arena_words[i] != expected_words[i]) { | ||
diff_count++; | ||
if (diff_count == 1) { | ||
first_diff = i; | ||
} | ||
} | ||
} | ||
|
||
if (diff_count == 0) { | ||
printf("OK - output identical to golden output\n"); | ||
} else { | ||
printf("FAIL - %d differences, first at word %d\n", diff_count, first_diff); | ||
printf("actual:\n"); | ||
dump_hex(arena_words + first_diff, 16); | ||
printf("expected:\n"); | ||
dump_hex(expected_words + first_diff, 16); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2022 The CFU-Playground Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef _POOL_CALL_H | ||
#define _POOL_CALL_H | ||
|
||
#include <cstdint> | ||
|
||
// Functionality for calling MaxPool from a test harnesses | ||
|
||
struct PoolData { | ||
const char* name; | ||
const uint8_t* params; | ||
const uint8_t* input_shape; | ||
const uint8_t* input_data; | ||
const uint8_t* output_shape; | ||
const uint8_t* output_data; | ||
}; | ||
|
||
// Tests MaxPool with the data in the given structure | ||
void test_pool(const PoolData* data); | ||
|
||
#endif // _POOL_CALL_H |
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
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
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