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

Tests/Eigen: make the dimensions changeable at runtime #500

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions tests/eigen_gemm/double14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ struct eigen_test_data {
static int eigen_gemm_double14_init(struct test *test) {
test->data = new(eigen_test_data);
try {
CAST(test->data)->lhs = Mat::Random(M_DIM, M_DIM);
CAST(test->data)->rhs = Mat::Random(M_DIM, M_DIM);
Mat::Index dim = get_testspecific_knob_value_int(test, "Dim", M_DIM);
CAST(test->data)->lhs = Mat::Random(dim, dim);
CAST(test->data)->rhs = Mat::Random(dim, dim);
CAST(test->data)->prod = CAST(test->data)->lhs * CAST(test->data)->rhs;
} catch (...) {
report_fail_msg("Exception on Eigen code, most probably OOM");
Expand Down
7 changes: 4 additions & 3 deletions tests/eigen_gemm/gemm_cdouble_dynamic_square.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ struct eigen_test_data {
static int eigen_gemm_cdouble_dynamic_square_init(struct test *test) {
test->data = new(eigen_test_data);
try {
CAST(test->data)->lhs = Mat::Random(M_DIM, M_DIM);
CAST(test->data)->rhs = Mat::Random(M_DIM, M_DIM);
Mat::Index dim = get_testspecific_knob_value_int(test, "Dim", M_DIM);
CAST(test->data)->lhs = Mat::Random(dim, dim);
CAST(test->data)->rhs = Mat::Random(dim, dim);
CAST(test->data)->prod = CAST(test->data)->lhs * CAST(test->data)->rhs;
} catch (...) {
report_fail_msg("Exception on Eigen code, most probably OOM");
Expand All @@ -62,7 +63,7 @@ static int eigen_gemm_cdouble_dynamic_square_run(struct test *test, int cpu) {
x = testdata->lhs * testdata->rhs;

memcmp_or_fail(reinterpret_cast<double *>(x.data()),
reinterpret_cast<double *>(testdata->prod.data()), 2 * M_DIM * M_DIM);
reinterpret_cast<double *>(testdata->prod.data()), 2 * x.rows() * x.cols());
} while (test_time_condition(test));
//log_info("Num iters = %i\n", i);
return EXIT_SUCCESS;
Expand Down
7 changes: 4 additions & 3 deletions tests/eigen_gemm/gemm_double_dynamic_square.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ struct eigen_test_data {
static int eigen_gemm_double_dynamic_square_init(struct test *test) {
test->data = new(eigen_test_data);
try {
CAST(test->data)->lhs = Mat::Random(M_DIM, M_DIM);
CAST(test->data)->rhs = Mat::Random(M_DIM, M_DIM);
Mat::Index dim = get_testspecific_knob_value_int(test, "Dim", M_DIM);
CAST(test->data)->lhs = Mat::Random(dim, dim);
CAST(test->data)->rhs = Mat::Random(dim, dim);
CAST(test->data)->prod = CAST(test->data)->lhs * CAST(test->data)->rhs;
} catch (...) {
report_fail_msg("Exception on Eigen code, most probably OOM");
Expand All @@ -59,7 +60,7 @@ static int eigen_gemm_double_dynamic_square_run(struct test *test, int cpu) {
Mat x;
x = testdata->lhs * testdata->rhs;

memcmp_or_fail(x.data(), testdata->prod.data(), M_DIM * M_DIM);
memcmp_or_fail(x.data(), testdata->prod.data(), x.rows() * x.cols());
} while (test_time_condition(test));
//log_info("Num iters = %i\n", i);
return EXIT_SUCCESS;
Expand Down
7 changes: 4 additions & 3 deletions tests/eigen_gemm/gemm_float_dynamic_square.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ struct eigen_test_data {
static int eigen_gemm_float_dynamic_square_init(struct test *test) {
test->data = new(eigen_test_data);
try {
CAST(test->data)->lhs = Mat::Random(M_DIM, M_DIM);
CAST(test->data)->rhs = Mat::Random(M_DIM, M_DIM);
Mat::Index dim = get_testspecific_knob_value_int(test, "Dim", M_DIM);
CAST(test->data)->lhs = Mat::Random(dim, dim);
CAST(test->data)->rhs = Mat::Random(dim, dim);
CAST(test->data)->prod = CAST(test->data)->lhs * CAST(test->data)->rhs;
} catch (...) {
report_fail_msg("Exception on Eigen code, most probably OOM");
Expand All @@ -60,7 +61,7 @@ static int eigen_gemm_float_dynamic_square_run(struct test *test, int cpu) {
Mat x;
x = testdata->lhs * testdata->rhs;

memcmp_or_fail(x.data(), testdata->prod.data(), M_DIM * M_DIM);
memcmp_or_fail(x.data(), testdata->prod.data(), x.rows() * x.cols());
} while (test_time_condition(test));
//log_info("Num iters = %i\n", i);
return EXIT_SUCCESS;
Expand Down
19 changes: 12 additions & 7 deletions tests/eigen_svd/sandstone_eigen_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,28 @@ template <typename SVD, int Dim> struct EigenSVDTest
}

template <typename FP> static inline std::enable_if_t<boost::is_complex<FP>::value>
compare_or_fail(const FP *actual, const FP *expected, const char *name)
compare_or_fail(const FP *actual, const FP *expected, typename Mat::Index rows,
typename Mat::Index cols, const char *name)
{
memcmp_or_fail(reinterpret_cast<const typename FP::value_type *>(actual),
reinterpret_cast<const typename FP::value_type *>(expected),
2 * Dim * Dim, name);
2 * rows * cols, name);
}

template <typename FP> static inline std::enable_if_t<!boost::is_complex<FP>::value>
compare_or_fail(const FP *actual, const FP *expected, const char *name)
compare_or_fail(const FP *actual, const FP *expected, typename Mat::Index rows,
typename Mat::Index cols, const char *name)
{
memcmp_or_fail(actual, expected, Dim * Dim, name);
memcmp_or_fail(actual, expected, rows * cols, name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be correlated to the FP size. Otherwise, it's shorter region to compare.

}

static int init(struct test *test)
{
auto d = new eigen_test_data;
d->orig_matrix = Mat::Random(Dim, Dim);
typename Mat::Index dim = Dim;
if constexpr (Mat::RowsAtCompileTime == Eigen::Dynamic)
dim = get_testspecific_knob_value_int(test, "Dim", dim);
d->orig_matrix = Mat::Random(dim, dim);
calculate_once(d->orig_matrix, d->u_matrix, d->v_matrix);
test->data = d;
return EXIT_SUCCESS;
Expand All @@ -67,8 +72,8 @@ template <typename SVD, int Dim> struct EigenSVDTest
Mat u, v;
calculate_once(d->orig_matrix, u, v);

compare_or_fail(u.data(), d->u_matrix.data(), "Matrix U");
compare_or_fail(v.data(), d->v_matrix.data(), "Matrix V");
compare_or_fail(u.data(), d->u_matrix.data(), u.rows(), u.cols(), "Matrix U");
compare_or_fail(v.data(), d->v_matrix.data(), v.rows(), v.cols(), "Matrix V");
} while (test_time_condition(test));
return EXIT_SUCCESS;
}
Expand Down