Skip to content

Commit 5d6b097

Browse files
committed
Implementation in nonblocking (delegating)
1 parent 0a3da01 commit 5d6b097

File tree

3 files changed

+149
-9
lines changed

3 files changed

+149
-9
lines changed

include/graphblas/nonblocking/blas3.hpp

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

574+
template<
575+
Descriptor descr = descriptors::no_operation,
576+
class Monoid,
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+
typename RIT_B, typename CIT_B, typename NIT_B
581+
>
582+
RC foldl(
583+
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
584+
const Matrix< MaskType, nonblocking, RIT_M, CIT_M, NIT_M > &mask,
585+
const Matrix< InputType, nonblocking, RIT_B, CIT_B, NIT_B > &B,
586+
const Monoid &monoid = Monoid(),
587+
const typename std::enable_if<
588+
!grb::is_object< IOType >::value &&
589+
!grb::is_object< InputType >::value &&
590+
!grb::is_object< MaskType >::value &&
591+
grb::is_monoid< Monoid >::value, void
592+
>::type * const = nullptr
593+
) {
594+
if( internal::NONBLOCKING::warn_if_not_native &&
595+
config::PIPELINE::warn_if_not_native
596+
) {
597+
std::cerr << "Warning: foldl( nonblocking ) currently delegates to a "
598+
<< "blocking implementation.\n"
599+
<< " Further similar such warnings will be suppressed.\n";
600+
internal::NONBLOCKING::warn_if_not_native = false;
601+
}
602+
603+
// nonblocking execution is not supported
604+
// first, execute any computation that is not completed
605+
internal::le.execution();
606+
607+
// second, delegate to the reference backend
608+
return foldl< descr, Monoid >( getRefMatrix( A ), getRefMatrix( mask ), getRefMatrix( B ), monoid );
609+
}
610+
611+
template<
612+
Descriptor descr = descriptors::no_operation,
613+
class Monoid,
614+
typename IOType, typename InputType,
615+
typename RIT_A, typename CIT_A, typename NIT_A,
616+
typename RIT_B, typename CIT_B, typename NIT_B
617+
>
618+
RC foldl(
619+
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
620+
const Matrix< InputType, nonblocking, RIT_B, CIT_B, NIT_B > &B,
621+
const Monoid &monoid = Monoid(),
622+
const typename std::enable_if<
623+
!grb::is_object< IOType >::value &&
624+
!grb::is_object< InputType >::value &&
625+
grb::is_monoid< Monoid >::value, void
626+
>::type * const = nullptr
627+
) {
628+
if( internal::NONBLOCKING::warn_if_not_native &&
629+
config::PIPELINE::warn_if_not_native
630+
) {
631+
std::cerr << "Warning: foldl( nonblocking ) currently delegates to a "
632+
<< "blocking implementation.\n"
633+
<< " Further similar such warnings will be suppressed.\n";
634+
internal::NONBLOCKING::warn_if_not_native = false;
635+
}
636+
637+
// nonblocking execution is not supported
638+
// first, execute any computation that is not completed
639+
internal::le.execution();
640+
641+
// second, delegate to the reference backend
642+
return foldl< descr, Monoid >( getRefMatrix( A ), getRefMatrix( B ), monoid );
643+
}
644+
645+
template<
646+
Descriptor descr = descriptors::no_operation,
647+
class Monoid,
648+
typename IOType, typename MaskType, typename InputType,
649+
typename RIT_A, typename CIT_A, typename NIT_A,
650+
typename RIT_M, typename CIT_M, typename NIT_M,
651+
typename RIT_B, typename CIT_B, typename NIT_B
652+
>
653+
RC foldr(
654+
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
655+
const Matrix< MaskType, nonblocking, RIT_M, CIT_M, NIT_M > &mask,
656+
const Matrix< InputType, nonblocking, RIT_B, CIT_B, NIT_B > &B,
657+
const Monoid &monoid = Monoid(),
658+
const typename std::enable_if<
659+
!grb::is_object< IOType >::value &&
660+
!grb::is_object< InputType >::value &&
661+
!grb::is_object< MaskType >::value &&
662+
grb::is_monoid< Monoid >::value, void
663+
>::type * const = nullptr
664+
) {
665+
if( internal::NONBLOCKING::warn_if_not_native &&
666+
config::PIPELINE::warn_if_not_native
667+
) {
668+
std::cerr << "Warning: foldr( nonblocking ) currently delegates to a "
669+
<< "blocking implementation.\n"
670+
<< " Further similar such warnings will be suppressed.\n";
671+
internal::NONBLOCKING::warn_if_not_native = false;
672+
}
673+
674+
// nonblocking execution is not supported
675+
// first, execute any computation that is not completed
676+
internal::le.execution();
677+
678+
// second, delegate to the reference backend
679+
return foldr< descr, Monoid >( getRefMatrix( A ), getRefMatrix( mask ), getRefMatrix( B ), monoid );
680+
}
681+
682+
template<
683+
Descriptor descr = descriptors::no_operation,
684+
class Monoid,
685+
typename IOType, typename InputType,
686+
typename RIT_A, typename CIT_A, typename NIT_A,
687+
typename RIT_B, typename CIT_B, typename NIT_B
688+
>
689+
RC foldr(
690+
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
691+
const Matrix< InputType, nonblocking, RIT_B, CIT_B, NIT_B > &B,
692+
const Monoid &monoid = Monoid(),
693+
const typename std::enable_if<
694+
!grb::is_object< IOType >::value &&
695+
!grb::is_object< InputType >::value &&
696+
grb::is_monoid< Monoid >::value, void
697+
>::type * const = nullptr
698+
) {
699+
if( internal::NONBLOCKING::warn_if_not_native &&
700+
config::PIPELINE::warn_if_not_native
701+
) {
702+
std::cerr << "Warning: foldr( nonblocking ) currently delegates to a "
703+
<< "blocking implementation.\n"
704+
<< " Further similar such warnings will be suppressed.\n";
705+
internal::NONBLOCKING::warn_if_not_native = false;
706+
}
707+
708+
// nonblocking execution is not supported
709+
// first, execute any computation that is not completed
710+
internal::le.execution();
711+
712+
// second, delegate to the reference backend
713+
return foldr< descr, Monoid >( getRefMatrix( A ), getRefMatrix( B ), monoid );
714+
}
715+
574716
} // namespace grb
575717

576718
#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_to_matrix fold_matrix_to_matrix.cpp
149-
BACKENDS reference reference_omp hyperdags bsp1d hybrid
149+
BACKENDS reference reference_omp hyperdags bsp1d hybrid 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 an operator."
228-
$runner ${TEST_BIN_DIR}/fold_matrix_to_matrix_${MODE}_${BACKEND} ${P} &> ${TEST_OUT_DIR}/fold_matrix_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log
229-
head -1 ${TEST_OUT_DIR}/fold_matrix_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log
230-
grep 'Test OK' ${TEST_OUT_DIR}/fold_matrix_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 an operator."
227+
$runner ${TEST_BIN_DIR}/fold_matrix_to_matrix_${MODE}_${BACKEND} ${P} &> ${TEST_OUT_DIR}/fold_matrix_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log
228+
head -1 ${TEST_OUT_DIR}/fold_matrix_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log
229+
grep 'Test OK' ${TEST_OUT_DIR}/fold_matrix_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)