Skip to content

Commit 89c40e2

Browse files
committed
Implementation in nonblocking (delegating)
1 parent 0a3da01 commit 89c40e2

File tree

3 files changed

+167
-9
lines changed

3 files changed

+167
-9
lines changed

include/graphblas/nonblocking/blas3.hpp

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,166 @@ 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 >(
609+
internal::getRefMatrix( A ),
610+
internal::getRefMatrix( mask ),
611+
internal::getRefMatrix( B ),
612+
monoid
613+
);
614+
}
615+
616+
template<
617+
Descriptor descr = descriptors::no_operation,
618+
class Monoid,
619+
typename IOType, typename InputType,
620+
typename RIT_A, typename CIT_A, typename NIT_A,
621+
typename RIT_B, typename CIT_B, typename NIT_B
622+
>
623+
RC foldl(
624+
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
625+
const Matrix< InputType, nonblocking, RIT_B, CIT_B, NIT_B > &B,
626+
const Monoid &monoid = Monoid(),
627+
const typename std::enable_if<
628+
!grb::is_object< IOType >::value &&
629+
!grb::is_object< InputType >::value &&
630+
grb::is_monoid< Monoid >::value, void
631+
>::type * const = nullptr
632+
) {
633+
if( internal::NONBLOCKING::warn_if_not_native &&
634+
config::PIPELINE::warn_if_not_native
635+
) {
636+
std::cerr << "Warning: foldl( nonblocking ) currently delegates to a "
637+
<< "blocking implementation.\n"
638+
<< " Further similar such warnings will be suppressed.\n";
639+
internal::NONBLOCKING::warn_if_not_native = false;
640+
}
641+
642+
// nonblocking execution is not supported
643+
// first, execute any computation that is not completed
644+
internal::le.execution();
645+
646+
// second, delegate to the reference backend
647+
return foldl< descr, Monoid >(
648+
internal::getRefMatrix( A ),
649+
internal::getRefMatrix( B ),
650+
monoid
651+
);
652+
}
653+
654+
template<
655+
Descriptor descr = descriptors::no_operation,
656+
class Monoid,
657+
typename IOType, typename MaskType, typename InputType,
658+
typename RIT_A, typename CIT_A, typename NIT_A,
659+
typename RIT_M, typename CIT_M, typename NIT_M,
660+
typename RIT_B, typename CIT_B, typename NIT_B
661+
>
662+
RC foldr(
663+
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
664+
const Matrix< MaskType, nonblocking, RIT_M, CIT_M, NIT_M > &mask,
665+
const Matrix< InputType, nonblocking, RIT_B, CIT_B, NIT_B > &B,
666+
const Monoid &monoid = Monoid(),
667+
const typename std::enable_if<
668+
!grb::is_object< IOType >::value &&
669+
!grb::is_object< InputType >::value &&
670+
!grb::is_object< MaskType >::value &&
671+
grb::is_monoid< Monoid >::value, void
672+
>::type * const = nullptr
673+
) {
674+
if( internal::NONBLOCKING::warn_if_not_native &&
675+
config::PIPELINE::warn_if_not_native
676+
) {
677+
std::cerr << "Warning: foldr( nonblocking ) currently delegates to a "
678+
<< "blocking implementation.\n"
679+
<< " Further similar such warnings will be suppressed.\n";
680+
internal::NONBLOCKING::warn_if_not_native = false;
681+
}
682+
683+
// nonblocking execution is not supported
684+
// first, execute any computation that is not completed
685+
internal::le.execution();
686+
687+
// second, delegate to the reference backend
688+
return foldr< descr, Monoid >(
689+
internal::getRefMatrix( A ),
690+
internal::getRefMatrix( mask ),
691+
internal::getRefMatrix( B ),
692+
monoid
693+
);
694+
}
695+
696+
template<
697+
Descriptor descr = descriptors::no_operation,
698+
class Monoid,
699+
typename IOType, typename InputType,
700+
typename RIT_A, typename CIT_A, typename NIT_A,
701+
typename RIT_B, typename CIT_B, typename NIT_B
702+
>
703+
RC foldr(
704+
Matrix< IOType, nonblocking, RIT_A, CIT_A, NIT_A > &A,
705+
const Matrix< InputType, nonblocking, RIT_B, CIT_B, NIT_B > &B,
706+
const Monoid &monoid = Monoid(),
707+
const typename std::enable_if<
708+
!grb::is_object< IOType >::value &&
709+
!grb::is_object< InputType >::value &&
710+
grb::is_monoid< Monoid >::value, void
711+
>::type * const = nullptr
712+
) {
713+
if( internal::NONBLOCKING::warn_if_not_native &&
714+
config::PIPELINE::warn_if_not_native
715+
) {
716+
std::cerr << "Warning: foldr( nonblocking ) currently delegates to a "
717+
<< "blocking implementation.\n"
718+
<< " Further similar such warnings will be suppressed.\n";
719+
internal::NONBLOCKING::warn_if_not_native = false;
720+
}
721+
722+
// nonblocking execution is not supported
723+
// first, execute any computation that is not completed
724+
internal::le.execution();
725+
726+
// second, delegate to the reference backend
727+
return foldr< descr, Monoid >(
728+
internal::getRefMatrix( A ),
729+
internal::getRefMatrix( B ),
730+
monoid
731+
);
732+
}
733+
574734
} // namespace grb
575735

576736
#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)