Skip to content

Commit d80ed92

Browse files
committed
Implementation in nonblocking (delegating)
1 parent e3813c6 commit d80ed92

File tree

3 files changed

+127
-9
lines changed

3 files changed

+127
-9
lines changed

include/graphblas/nonblocking/blas3.hpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,126 @@ namespace grb {
571571
);
572572
}
573573

574+
template<
575+
Descriptor descr = descriptors::no_operation,
576+
class Operator,
577+
typename IOType, typename MaskType, typename InputType,
578+
typename RIT_A, typename CIT_A, typename NIT_A,
579+
typename RIT_M, typename CIT_M, typename NIT_M
580+
>
581+
RC foldl(
582+
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
583+
const Matrix< MaskType, nonblocking, RIT_M, CIT_M, NIT_M > &mask,
584+
const InputType &x,
585+
const Operator &op = Operator(),
586+
const typename std::enable_if<
587+
!grb::is_object< IOType >::value &&
588+
!grb::is_object< InputType >::value &&
589+
!grb::is_object< MaskType >::value &&
590+
grb::is_operator< Operator >::value, void
591+
>::type * const = nullptr
592+
) {
593+
594+
#ifdef _DEBUG
595+
std::cout << "In grb::foldl( nonblocking, matrix, mask, scalar, op )\n";
596+
#endif
597+
RC rc = SUCCESS;
598+
599+
if( grb::nnz( A ) == 0 ) {
600+
return rc;
601+
}
602+
603+
// Do local folding
604+
rc = foldl< descr >( internal::getRefMatrix( A ), internal::getRefMatrix( mask ), x, op );
605+
606+
return rc;
607+
}
608+
609+
template<
610+
Descriptor descr = descriptors::no_operation,
611+
class Operator,
612+
typename IOType, typename InputType,
613+
typename RIT, typename CIT, typename NIT
614+
>
615+
RC foldl(
616+
Matrix< IOType, nonblocking, RIT, CIT, NIT > &A,
617+
const InputType &x,
618+
const Operator &op = Operator(),
619+
const typename std::enable_if<
620+
!grb::is_object< IOType >::value &&
621+
!grb::is_object< InputType >::value &&
622+
grb::is_operator< Operator >::value, void
623+
>::type * const = nullptr
624+
) {
625+
626+
#ifdef _DEBUG
627+
std::cout << "In grb::foldl( nonblocking, matrix, scalar, op )\n";
628+
#endif
629+
// nonblocking execution is not supported
630+
// first, execute any computation that is not completed
631+
internal::le.execution();
632+
633+
// second, delegate to the reference backend
634+
return foldl< descr, Operator >( internal::getRefMatrix( A ), x, op );
635+
}
636+
637+
template<
638+
Descriptor descr = descriptors::no_operation,
639+
class Operator,
640+
typename IOType, typename MaskType, typename InputType,
641+
typename RIT_A, typename CIT_A, typename NIT_A,
642+
typename RIT_M, typename CIT_M, typename NIT_M
643+
>
644+
RC foldr(
645+
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
646+
const Matrix< MaskType, nonblocking, RIT_M, CIT_M, NIT_M > &mask,
647+
const InputType &x,
648+
const Operator &op = Operator(),
649+
const typename std::enable_if<
650+
!grb::is_object< IOType >::value &&
651+
!grb::is_object< InputType >::value &&
652+
!grb::is_object< MaskType >::value &&
653+
grb::is_operator< Operator >::value, void
654+
>::type * const = nullptr
655+
) {
656+
657+
#ifdef _DEBUG
658+
std::cout << "In grb::foldr( nonblocking, matrix, scalar, mask, op )\n";
659+
#endif
660+
// nonblocking execution is not supported
661+
// first, execute any computation that is not completed
662+
internal::le.execution();
663+
664+
// second, delegate to the reference backend
665+
return foldr< descr, Operator >( internal::getRefMatrix( A ), internal::getRefMatrix( mask ), x, op );
666+
}
667+
668+
template<
669+
Descriptor descr = descriptors::no_operation,
670+
class Operator,
671+
typename IOType, typename InputType,
672+
typename RIT, typename CIT, typename NIT
673+
>
674+
RC foldr(
675+
Matrix< IOType, nonblocking, RIT, CIT, NIT > &A,
676+
const InputType &x,
677+
const Operator &op = Operator(),
678+
const typename std::enable_if<
679+
!grb::is_object< IOType >::value &&
680+
!grb::is_object< InputType >::value &&
681+
grb::is_operator< Operator >::value, void
682+
>::type * const = nullptr
683+
) {
684+
#ifdef _DEBUG
685+
std::cout << "In grb::foldr( nonblocking, matrix, scalar, op )\n";
686+
#endif
687+
// nonblocking execution is not supported
688+
// first, execute any computation that is not completed
689+
internal::le.execution();
690+
691+
// second, delegate to the reference backend
692+
return foldr< descr, Operator >( internal::getRefMatrix( A ), x, op );
693+
}
574694
} // namespace grb
575695

576696
#undef NO_CAST_ASSERT

tests/unit/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ add_grb_executables( eWiseMul eWiseMul.cpp
146146
)
147147

148148
add_grb_executables( fold_matrix_scalar_to_matrix fold_matrix_scalar_to_matrix.cpp
149-
BACKENDS reference reference_omp hyperdags bsp1d hybrid
149+
BACKENDS reference reference_omp bsp1d hybrid hyperdags nonblocking
150150
)
151151

152152
add_grb_executables( muladd muladd.cpp

tests/unit/unittests.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,12 @@ for MODE in ${MODES}; do
222222
grep 'Test OK' ${TEST_OUT_DIR}/ewiseapply_large_${MODE}_${BACKEND}_${P}_${T} || echo "Test FAILED"
223223
echo " "
224224

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

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

0 commit comments

Comments
 (0)