Skip to content

Commit

Permalink
Implementation in nonblocking (delegating)
Browse files Browse the repository at this point in the history
  • Loading branch information
byjtew committed Jun 28, 2023
1 parent e3813c6 commit b1fab62
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 9 deletions.
121 changes: 121 additions & 0 deletions include/graphblas/nonblocking/blas3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,127 @@ namespace grb {
);
}

template<
Descriptor descr = descriptors::no_operation,
class Operator,
typename IOType, typename MaskType, typename InputType,
typename RIT_A, typename CIT_A, typename NIT_A,
typename RIT_M, typename CIT_M, typename NIT_M
>
RC foldl(
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
const Matrix< MaskType, nonblocking, RIT_M, CIT_M, NIT_M > &mask,
const InputType &x,
const Operator &op = Operator(),
const typename std::enable_if<
!grb::is_object< IOType >::value &&
!grb::is_object< InputType >::value &&
!grb::is_object< MaskType >::value &&
grb::is_operator< Operator >::value, void
>::type * const = nullptr
) {

#ifdef _DEBUG
std::cout << "In grb::foldl( nonblocking, matrix, mask, scalar, op )\n";
#endif
RC rc = SUCCESS;

if( grb::nnz( A ) == 0 ) {
return rc;
}

// Do local folding
rc = foldl< descr >( internal::getRefMatrix( A ), internal::getRefMatrix( mask ), x, op );

return rc;
}

template<
Descriptor descr = descriptors::no_operation,
class Operator,
typename IOType, typename MaskType, typename InputType,
typename RIT, typename CIT, typename NIT
>
RC foldl(
Matrix< IOType, nonblocking, RIT, CIT, NIT > &A,
const InputType &x,
const Operator &op = Operator(),
const typename std::enable_if<
!grb::is_object< IOType >::value &&
!grb::is_object< InputType >::value &&
!grb::is_object< MaskType >::value &&
grb::is_operator< Operator >::value, void
>::type * const = nullptr
) {

#ifdef _DEBUG
std::cout << "In grb::foldl( nonblocking, matrix, scalar, op )\n";
#endif
// nonblocking execution is not supported
// first, execute any computation that is not completed
internal::le.execution();

// second, delegate to the reference backend
return foldl< descr, Operator >( internal::getRefMatrix( A ), x, op );
}

template<
Descriptor descr = descriptors::no_operation,
class Operator,
typename IOType, typename MaskType, typename InputType,
typename RIT_A, typename CIT_A, typename NIT_A,
typename RIT_M, typename CIT_M, typename NIT_M
>
RC foldr(
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
const Matrix< MaskType, nonblocking, RIT_M, CIT_M, NIT_M > &mask,
const InputType &x,
const Operator &op = Operator(),
const typename std::enable_if<
!grb::is_object< IOType >::value &&
!grb::is_object< InputType >::value &&
!grb::is_object< MaskType >::value &&
grb::is_operator< Operator >::value, void
>::type * const = nullptr
) {

#ifdef _DEBUG
std::cout << "In grb::foldr( nonblocking, matrix, scalar, mask, op )\n";
#endif
// nonblocking execution is not supported
// first, execute any computation that is not completed
internal::le.execution();

// second, delegate to the reference backend
return foldr< descr, Operator >( internal::getRefMatrix( A ), internal::getRefMatrix( mask ), x, op );
}

template<
Descriptor descr = descriptors::no_operation,
class Operator,
typename IOType, typename InputType,
typename RIT, typename CIT, typename NIT
>
RC foldr(
Matrix< IOType, nonblocking, RIT, CIT, NIT > &A,
const InputType &x,
const Operator &op = Operator(),
const typename std::enable_if<
!grb::is_object< IOType >::value &&
!grb::is_object< InputType >::value &&
grb::is_operator< Operator >::value, void
>::type * const = nullptr
) {
#ifdef _DEBUG
std::cout << "In grb::foldr( nonblocking, matrix, scalar, op )\n";
#endif
// nonblocking execution is not supported
// first, execute any computation that is not completed
internal::le.execution();

// second, delegate to the reference backend
return foldr< descr, Operator >( internal::getRefMatrix( A ), x, op );
}
} // namespace grb

#undef NO_CAST_ASSERT
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ add_grb_executables( eWiseMul eWiseMul.cpp
)

add_grb_executables( fold_matrix_scalar_to_matrix fold_matrix_scalar_to_matrix.cpp
BACKENDS reference reference_omp hyperdags bsp1d hybrid
BACKENDS reference reference_omp bsp1d hybrid hyperdags nonblocking
)

add_grb_executables( muladd muladd.cpp
Expand Down
14 changes: 6 additions & 8 deletions tests/unit/unittests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,12 @@ for MODE in ${MODES}; do
grep 'Test OK' ${TEST_OUT_DIR}/ewiseapply_large_${MODE}_${BACKEND}_${P}_${T} || echo "Test FAILED"
echo " "

if [ "$BACKEND" != "nonblocking" ]; then
echo ">>> [x] [x] Testing grb::foldl and grb::foldr reducing sparse"
echo " matrix in-place using operators."
$runner ${TEST_BIN_DIR}/fold_matrix_scalar_to_matrix_${MODE}_${BACKEND} &> ${TEST_OUT_DIR}/fold_matrix_scalar_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log
head -1 ${TEST_OUT_DIR}/fold_matrix_scalar_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log
grep 'Test OK' ${TEST_OUT_DIR}/fold_matrix_scalar_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log || echo "Test FAILED"
echo " "
fi
echo ">>> [x] [x] Testing grb::foldl and grb::foldr reducing sparse"
echo " matrix in-place using operators."
$runner ${TEST_BIN_DIR}/fold_matrix_scalar_to_matrix_${MODE}_${BACKEND} &> ${TEST_OUT_DIR}/fold_matrix_scalar_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log
head -1 ${TEST_OUT_DIR}/fold_matrix_scalar_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log
grep 'Test OK' ${TEST_OUT_DIR}/fold_matrix_scalar_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log || echo "Test FAILED"
echo " "

echo ">>> [x] [x] Testing grb::foldl and grb::foldr reducing dense"
echo " vectors into scalars using operators and monoids."
Expand Down

0 comments on commit b1fab62

Please sign in to comment.