19 #include <gtest/gtest.h>
20 #include <gtest/internal/gtest-port.h>
30 class IntSimdMatrixTest :
public ::testing::Test {
33 std::locale::global(std::locale(
""));
39 for (
int i = 0; i < no; ++i) {
40 for (
int j = 0; j < ni; ++j) {
41 a(i, j) = static_cast<int8_t>(
random_.SignedRand(INT8_MAX));
47 std::vector<int8_t> RandomVector(
int size,
const IntSimdMatrix& matrix) {
48 int rounded_size = matrix.RoundInputs(size);
49 std::vector<int8_t> v(rounded_size, 0);
50 for (
int i = 0; i < size; ++i) {
51 v[i] = static_cast<int8_t>(
random_.SignedRand(INT8_MAX));
58 for (
int i = 0; i < size; ++i) {
59 v[i] = 1.0 +
random_.SignedRand(1.0);
64 void ExpectEqualResults(
const IntSimdMatrix& matrix) {
66 for (
int num_out = 1; num_out < 130; ++num_out) {
67 for (
int num_in = 1; num_in < 130; ++num_in) {
69 std::vector<int8_t> u = RandomVector(num_in, matrix);
71 std::vector<double> base_result(num_out);
73 std::vector<double> test_result(num_out);
74 std::vector<int8_t> shaped_wi;
75 matrix.Init(w, shaped_wi);
76 if (matrix.matrixDotVectorFunction) {
77 matrix.matrixDotVectorFunction(w.
dim1(), w.
dim2(), &shaped_wi[0],
78 &scales[0], &u[0], &test_result[0]);
82 for (
int i = 0; i < num_out; ++i) {
83 EXPECT_FLOAT_EQ(base_result[i], test_result[i]) <<
"i=" << i;
84 total += base_result[i];
89 EXPECT_FLOAT_EQ(total, -423243.392011);
96 TEST_F(IntSimdMatrixTest, C) {
97 static const IntSimdMatrix matrix = {
nullptr, 1, 1, 1, 1};
98 ExpectEqualResults(matrix);
102 TEST_F(IntSimdMatrixTest, SSE) {
103 #if defined(HAVE_SSE4_1)
105 GTEST_LOG_(
INFO) <<
"No SSE found! Not tested!";
110 GTEST_LOG_(
INFO) <<
"SSE unsupported! Not tested!";
116 TEST_F(IntSimdMatrixTest, AVX2) {
117 #if defined(HAVE_AVX2)
119 GTEST_LOG_(
INFO) <<
"No AVX2 found! Not tested!";
124 GTEST_LOG_(
INFO) <<
"AVX2 unsupported! Not tested!";