Skip to content

Commit

Permalink
Rework test accuracy for spsv
Browse files Browse the repository at this point in the history
  • Loading branch information
Rbiessy committed Sep 12, 2024
1 parent 7aa5177 commit 70cdbe0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tests/unit_tests/sparse_blas/include/test_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ template <typename fpType>
fpType generate_data(bool is_diag) {
rand_scalar<fpType> rand_data;
if (is_diag) {
// Guarantee an amplitude >= 0.1
// Guarantee a large amplitude
fpType sign = (std::rand() % 2) * 2 - 1;
return rand_data(0.1, 0.5) * sign;
return rand_data(10, 20) * sign;
}
return rand_data(-0.5, 0.5);
}
Expand Down
7 changes: 4 additions & 3 deletions tests/unit_tests/sparse_blas/source/sparse_spsv_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ int test_spsv(sycl::device *dev, sparse_matrix_format_t format, intType m, doubl
matrix_properties.find(oneapi::mkl::sparse::matrix_property::symmetric) !=
matrix_properties.cend();

// Use a fixed seed for operations very sensible to the input data
std::srand(1);

// Input matrix
std::vector<intType> ia_host, ja_host;
std::vector<fpType> a_host;
Expand Down Expand Up @@ -171,10 +174,8 @@ int test_spsv(sycl::device *dev, sparse_matrix_format_t format, intType m, doubl

// Compare the results of reference implementation and DPC++ implementation.
// Increase default relative error margin for tests that lead to large numeric values.
double abs_error_factor = 10;
double rel_error_factor = 1E5;
auto y_acc = y_buf.get_host_access(sycl::read_only);
bool valid = check_equal_vector(y_acc, y_ref_host, abs_error_factor, rel_error_factor);
bool valid = check_equal_vector(y_acc, y_ref_host);

return static_cast<int>(valid);
}
Expand Down
7 changes: 4 additions & 3 deletions tests/unit_tests/sparse_blas/source/sparse_spsv_usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ int test_spsv(sycl::device *dev, sparse_matrix_format_t format, intType m, doubl
matrix_properties.find(oneapi::mkl::sparse::matrix_property::symmetric) !=
matrix_properties.cend();

// Use a fixed seed for operations very sensible to the input data
std::srand(1);

// Input matrix
std::vector<intType> ia_host, ja_host;
std::vector<fpType> a_host;
Expand Down Expand Up @@ -219,10 +222,8 @@ int test_spsv(sycl::device *dev, sparse_matrix_format_t format, intType m, doubl

// Compare the results of reference implementation and DPC++ implementation.
// Increase default relative error margin for tests that lead to large numeric values.
double abs_error_factor = 10;
double rel_error_factor = 1E5;
ev_copy.wait_and_throw();
bool valid = check_equal_vector(y_host, y_ref_host, abs_error_factor, rel_error_factor);
bool valid = check_equal_vector(y_host, y_ref_host);

return static_cast<int>(valid);
}
Expand Down

0 comments on commit 70cdbe0

Please sign in to comment.