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

fix tests in lite/kernels/internal #20296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions tensorflow/contrib/lite/kernels/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ cc_library(
hdrs = ["test_util.h"],
deps = [
":types",
"//tensorflow/contrib/lite:string",
],
)

Expand Down Expand Up @@ -588,6 +589,7 @@ cc_test(
deps = [
":optimized_base",
":reference_base",
"//tensorflow/contrib/lite:string",
"@com_google_googletest//:gtest_main",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ limitations under the License.
#include <gtest/gtest.h>
#include "tensorflow/contrib/lite/kernels/internal/optimized/optimized_ops.h"
#include "tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h"
#include "tensorflow/contrib/lite/string.h"

namespace {
namespace tflite {

class NumberGenerator {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ limitations under the License.
#include "tensorflow/contrib/lite/kernels/internal/quantization_util.h"
#include "tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h"
#include "tensorflow/contrib/lite/kernels/internal/test_util.h"
#include "tensorflow/contrib/lite/string.h"

namespace tflite {
namespace {
Expand Down
32 changes: 16 additions & 16 deletions tensorflow/contrib/lite/kernels/internal/quantization_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,22 @@ void RunSafeCastTests() {
}

TEST(QuantizationUtilTest, SafeCast) {
RunSafeCastTests<float, int8>();
RunSafeCastTests<double, int8>();
RunSafeCastTests<float, int16>();
RunSafeCastTests<double, int16>();
RunSafeCastTests<float, int32>();
RunSafeCastTests<double, int32>();
RunSafeCastTests<float, int64>();
RunSafeCastTests<double, int64>();
RunSafeCastTests<float, uint8>();
RunSafeCastTests<double, uint8>();
RunSafeCastTests<float, uint16>();
RunSafeCastTests<double, uint16>();
RunSafeCastTests<float, uint32>();
RunSafeCastTests<double, uint32>();
RunSafeCastTests<float, uint64>();
RunSafeCastTests<double, uint64>();
RunSafeCastTests<float, int8_t>();
RunSafeCastTests<double, int8_t>();
RunSafeCastTests<float, int16_t>();
RunSafeCastTests<double, int16_t>();
RunSafeCastTests<float, int32_t>();
RunSafeCastTests<double, int32_t>();
RunSafeCastTests<float, int64_t>();
RunSafeCastTests<double, int64_t>();
RunSafeCastTests<float, uint8_t>();
RunSafeCastTests<double, uint8_t>();
RunSafeCastTests<float, uint16_t>();
RunSafeCastTests<double, uint16_t>();
RunSafeCastTests<float, uint32_t>();
RunSafeCastTests<double, uint32_t>();
RunSafeCastTests<float, uint64_t>();
RunSafeCastTests<double, uint64_t>();
}

// Example taken from http://www.tensorflow.org/performance/quantization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ limitations under the License.
#include "tensorflow/contrib/lite/kernels/internal/quantization_util.h"
#include "tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h"
#include "tensorflow/contrib/lite/kernels/internal/test_util.h"
#include "tensorflow/contrib/lite/string.h"

namespace tflite {
namespace {
Expand Down
16 changes: 9 additions & 7 deletions tensorflow/contrib/lite/kernels/internal/tensor_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ TEST(uKernels, SymmetricQuantizeFloatsTest) {
static float input[kVectorSize] = {-640, -635.0, -630, 10.0, 2.0,
-5.0, -10.0, 0.0, 1000.0};

int8 output[kVectorSize];
int8_t output[kVectorSize];
float min, max, scaling_factor;
SymmetricQuantizeFloats(input, kVectorSize, output, &min, &max,
&scaling_factor);
Expand All @@ -72,7 +72,7 @@ TEST(uKernels, SymmetricQuantizeFloatsAllZerosTest) {
constexpr int kVectorSize = 9;
static float input[kVectorSize] = {0, 0, 0, 0, 0, 0, 0, 0, 0};

int8 output[kVectorSize];
int8_t output[kVectorSize];
float min, max, scaling_factor;
SymmetricQuantizeFloats(input, kVectorSize, output, &min, &max,
&scaling_factor);
Expand All @@ -88,7 +88,7 @@ TEST(uKernels, SymmetricQuantizeFloatsAllAlmostZeroTest) {
static float input[kVectorSize] = {-1e-5, 3e-5, -7e-6, -9e-5, 1e-6,
4e-5, 9e-6, 2e-4, 0};

int8 output[kVectorSize];
int8_t output[kVectorSize];
float min, max, scaling_factor;
SymmetricQuantizeFloats(input, kVectorSize, output, &min, &max,
&scaling_factor);
Expand Down Expand Up @@ -126,6 +126,7 @@ TEST(uKernels, MatrixBatchVectorMultiplyAccumulateTest) {
-1., 3., 7., 3., 23., 3.})));
}

#ifdef __ANDROID__
TEST(uKernels, MatrixBatchVectorMultiplyAccumulateSymmetricQuantizedTest) {
// Note we use 29 columns as this exercises all the neon kernel: the
// 16-block SIMD code, the 8-block postamble, and the leftover postamble.
Expand All @@ -149,13 +150,13 @@ TEST(uKernels, MatrixBatchVectorMultiplyAccumulateSymmetricQuantizedTest) {
-13.13, 14.14, -15.15, 16.16, -17.17, 18.18, -19.19, 20.2, -21.21, 22.22,
-23.23, 24.24, -25.25, 26.26, -27.27, 28.28, 0};

int8* a_int8_data = reinterpret_cast<int8*>(
int8_t* a_int8_data = reinterpret_cast<int8_t*>(
aligned_malloc(a_rows * a_cols, kWeightsPerUint32));
float a_min, a_max;
float scaling_factor_a;
SymmetricQuantizeFloats(a_float_data, a_rows * a_cols, a_int8_data, &a_min,
&a_max, &scaling_factor_a);
const int8 expected_a_int8_data[] = {
const int8_t expected_a_int8_data[] = {
/* 1st row */
5,
10,
Expand Down Expand Up @@ -346,7 +347,7 @@ TEST(uKernels, MatrixBatchVectorMultiplyAccumulateSymmetricQuantizedTest) {
};

// Quantized values of B:
int8 b_int8_data[b_rows * b_cols * batches];
int8_t b_int8_data[b_rows * b_cols * batches];
float b_min, b_max;
float scaling_factor_b[batches];
SymmetricQuantizeFloats(b_float_data, b_rows * b_cols, b_int8_data, &b_min,
Expand All @@ -355,7 +356,7 @@ TEST(uKernels, MatrixBatchVectorMultiplyAccumulateSymmetricQuantizedTest) {
&b_int8_data[b_rows * b_cols], &b_min, &b_max,
&scaling_factor_b[1]);

const int8 expected_b_int8_data[] = {
const int8_t expected_b_int8_data[] = {
/* batch 1 */
127,
-127,
Expand Down Expand Up @@ -448,6 +449,7 @@ TEST(uKernels, MatrixBatchVectorMultiplyAccumulateSymmetricQuantizedTest) {

aligned_free(a_int8_data);
}
#endif // __ANDROID__

TEST(uKernels, VectorVectorCwiseProductTest) {
constexpr int kVectorSize = 10;
Expand Down