-
Notifications
You must be signed in to change notification settings - Fork 99
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
Small fixes to spgemm, and plug gaps in testing #1159
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,9 +246,11 @@ bool is_same_matrix(crsMat_t output_mat_actual, crsMat_t output_mat_reference) { | |
} | ||
} // namespace Test | ||
|
||
// Generate matrices and test all supported spgemm algorithms. | ||
// C := AB, where A is m*k, B is k*n, and C is m*n. | ||
template <typename scalar_t, typename lno_t, typename size_type, | ||
typename device> | ||
void test_spgemm(lno_t numRows, size_type nnz, lno_t bandwidth, | ||
void test_spgemm(lno_t m, lno_t k, lno_t n, size_type nnz, lno_t bandwidth, | ||
lno_t row_size_variance, bool oldInterface = false) { | ||
using namespace Test; | ||
// device::execution_space::initialize(); | ||
|
@@ -260,22 +262,21 @@ void test_spgemm(lno_t numRows, size_type nnz, lno_t bandwidth, | |
// typedef typename graph_t::entries_type::non_const_type lno_nnz_view_t; | ||
// typedef typename crsMat_t::values_type::non_const_type scalar_view_t; | ||
|
||
lno_t numCols = numRows; | ||
// Generate random compressed sparse row matrix. Randomly generated (non-zero) | ||
// values are stored in a 1-D (1 rank) array. | ||
crsMat_t input_mat = KokkosKernels::Impl::kk_generate_sparse_matrix<crsMat_t>( | ||
numRows, numCols, nnz, row_size_variance, bandwidth); | ||
crsMat_t A = KokkosKernels::Impl::kk_generate_sparse_matrix<crsMat_t>( | ||
m, k, nnz, row_size_variance, bandwidth); | ||
crsMat_t B = KokkosKernels::Impl::kk_generate_sparse_matrix<crsMat_t>( | ||
k, n, nnz, row_size_variance, bandwidth); | ||
|
||
crsMat_t output_mat2; | ||
if (oldInterface) | ||
run_spgemm_old_interface<crsMat_t, device>(input_mat, input_mat, | ||
SPGEMM_DEBUG, output_mat2); | ||
run_spgemm_old_interface<crsMat_t, device>(A, B, SPGEMM_DEBUG, output_mat2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the old interface be removed? Has the old interface already been marked for deprecation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @e10harvey For now the "old" interface is not deprecated - it's just an alternative. The CrsMatrix based interface is implemented in terms of it. We test both just to be safe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also there are some users that want to have close control on memory allocations that prefer the "old" interface. |
||
else | ||
run_spgemm<crsMat_t, device>(input_mat, input_mat, SPGEMM_DEBUG, | ||
output_mat2); | ||
run_spgemm<crsMat_t, device>(A, B, SPGEMM_DEBUG, output_mat2); | ||
|
||
std::vector<SPGEMMAlgorithm> algorithms = {SPGEMM_KK_MEMORY, SPGEMM_KK_SPEED, | ||
SPGEMM_KK_MEMSPEED}; | ||
std::vector<SPGEMMAlgorithm> algorithms = { | ||
SPGEMM_KK, SPGEMM_KK_MEMORY, SPGEMM_KK_SPEED, SPGEMM_KK_MEMSPEED}; | ||
|
||
#ifdef HAVE_KOKKOSKERNELS_MKL | ||
algorithms.push_back(SPGEMM_MKL); | ||
|
@@ -309,7 +310,7 @@ void test_spgemm(lno_t numRows, size_type nnz, lno_t bandwidth, | |
} | ||
// if size_type is larger than int, mkl casts it to int. | ||
// it will fail if casting cause overflow. | ||
if (input_mat.values.extent(0) > max_integer) { | ||
if (A.values.extent(0) > max_integer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check all extents against max_integer here? If this is protecting a code path in the production code, this check should really be moved to the production code where an exception case raised and then we can try-catch the exception here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed this too - luckily the MKL wrapper also has this check:
|
||
is_expected_to_fail = true; | ||
} | ||
|
||
|
@@ -333,11 +334,10 @@ void test_spgemm(lno_t numRows, size_type nnz, lno_t bandwidth, | |
int res = 0; | ||
try { | ||
if (oldInterface) | ||
res = run_spgemm_old_interface<crsMat_t, device>( | ||
input_mat, input_mat, spgemm_algorithm, output_mat); | ||
res = run_spgemm_old_interface<crsMat_t, device>(A, B, spgemm_algorithm, | ||
output_mat); | ||
else | ||
res = run_spgemm<crsMat_t, device>(input_mat, input_mat, | ||
spgemm_algorithm, output_mat); | ||
res = run_spgemm<crsMat_t, device>(A, B, spgemm_algorithm, output_mat); | ||
} catch (const char *message) { | ||
EXPECT_TRUE(is_expected_to_fail) << algo; | ||
failed = true; | ||
|
@@ -433,14 +433,20 @@ void test_issue402() { | |
<< "KKMEM still has issue 402 bug; C=AA' is incorrect!\n"; | ||
} | ||
|
||
#define EXECUTE_TEST(SCALAR, ORDINAL, OFFSET, DEVICE) \ | ||
TEST_F(TestCategory, \ | ||
sparse##_##spgemm##_##SCALAR##_##ORDINAL##_##OFFSET##_##DEVICE) { \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(10000, 10000 * 20, 500, 10); \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(0, 0, 10, 10); \ | ||
test_issue402<SCALAR, ORDINAL, OFFSET, DEVICE>(); \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(10000, 10000 * 20, 500, 10, \ | ||
true); \ | ||
#define EXECUTE_TEST(SCALAR, ORDINAL, OFFSET, DEVICE) \ | ||
TEST_F(TestCategory, \ | ||
sparse##_##spgemm##_##SCALAR##_##ORDINAL##_##OFFSET##_##DEVICE) { \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(10000, 10000, 10000, \ | ||
10000 * 20, 500, 10, false); \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(10000, 10000, 10000, \ | ||
10000 * 20, 500, 10, true); \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(0, 0, 0, 0, 10, 10, false); \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(0, 0, 0, 0, 10, 10, true); \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(0, 12, 5, 0, 10, 0, false); \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(0, 12, 5, 0, 10, 0, true); \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(10, 10, 0, 0, 10, 10, false); \ | ||
test_spgemm<SCALAR, ORDINAL, OFFSET, DEVICE>(10, 10, 0, 0, 10, 10, true); \ | ||
test_issue402<SCALAR, ORDINAL, OFFSET, DEVICE>(); \ | ||
} | ||
|
||
// test_spgemm<SCALAR,ORDINAL,OFFSET,DEVICE>(50000, 50000 * 30, 100, 10); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the handle destroyed when
kh
goes out of scope or was this just a typo?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, kh is passed in (by reference, so it doesn't go out of scope) from the user and it must have had
create_spgemm_handle(...)
called on it. Removing this destroy for 2 reasons:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reuse issue affected a user on slack btw, that's how I found out about it