Skip to content

Commit c12b31c

Browse files
committed
Implementation for BSP1D backend
1 parent dd99daa commit c12b31c

File tree

4 files changed

+142
-8
lines changed

4 files changed

+142
-8
lines changed

include/graphblas/bsp1d/blas3.hpp

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,140 @@ namespace grb {
205205
return internal::checkGlobalErrorStateOrClear( C, ret );
206206
}
207207

208+
template<
209+
Descriptor descr = descriptors::no_operation,
210+
class Operator,
211+
typename IOType, typename MaskType, typename InputType,
212+
typename RIT, typename CIT, typename NIT
213+
>
214+
RC foldl(
215+
Matrix< IOType, BSP1D, RIT, CIT, NIT > &A,
216+
const InputType &x,
217+
const Operator &op = Operator(),
218+
const typename std::enable_if<
219+
!grb::is_object< IOType >::value &&
220+
!grb::is_object< InputType >::value &&
221+
!grb::is_object< MaskType >::value &&
222+
grb::is_operator< Operator >::value, void
223+
>::type * const = nullptr
224+
) {
225+
226+
#ifdef _DEBUG
227+
std::cout << "In grb::foldl( BSP1D, matrix, scalar, op )\n";
228+
#endif
229+
RC rc = SUCCESS;
230+
231+
if( grb::nnz( A ) == 0 ) {
232+
return rc;
233+
}
234+
235+
// Do local folding
236+
rc = foldl< descr >( internal::getLocal( A ), x, op );
237+
238+
return rc;
239+
}
240+
241+
template<
242+
Descriptor descr = descriptors::no_operation,
243+
class Operator,
244+
typename IOType, typename MaskType, typename InputType,
245+
typename RIT_A, typename CIT_A, typename NIT_A,
246+
typename RIT_M, typename CIT_M, typename NIT_M
247+
>
248+
RC foldl(
249+
Matrix< IOType, BSP1D, RIT_A, CIT_A, NIT_A > &A,
250+
const Matrix< MaskType, BSP1D, RIT_M, CIT_M, NIT_M > &mask,
251+
const InputType &x,
252+
const Operator &op = Operator(),
253+
const typename std::enable_if<
254+
!grb::is_object< IOType >::value &&
255+
!grb::is_object< InputType >::value &&
256+
!grb::is_object< MaskType >::value &&
257+
grb::is_operator< Operator >::value, void
258+
>::type * const = nullptr
259+
) {
260+
261+
#ifdef _DEBUG
262+
std::cout << "In grb::foldl( BSP1D, matrix, mask, scalar, op )\n";
263+
#endif
264+
RC rc = SUCCESS;
265+
266+
if( grb::nnz( A ) == 0 ) {
267+
return rc;
268+
}
269+
270+
// Do local folding
271+
rc = foldl< descr >( internal::getLocal( A ), internal::getLocal( mask ), x, op );
272+
273+
return rc;
274+
}
275+
276+
template<
277+
Descriptor descr = descriptors::no_operation,
278+
class Operator,
279+
typename IOType, typename MaskType, typename InputType,
280+
typename RIT_A, typename CIT_A, typename NIT_A,
281+
typename RIT_M, typename CIT_M, typename NIT_M
282+
>
283+
RC foldr(
284+
Matrix< IOType, BSP1D, RIT_A, CIT_A, NIT_A > &A,
285+
const Matrix< MaskType, BSP1D, RIT_M, CIT_M, NIT_M > &mask,
286+
const InputType &x,
287+
const Operator &op = Operator(),
288+
const typename std::enable_if<
289+
!grb::is_object< IOType >::value &&
290+
!grb::is_object< InputType >::value &&
291+
!grb::is_object< MaskType >::value &&
292+
grb::is_operator< Operator >::value, void
293+
>::type * const = nullptr
294+
) {
295+
296+
#ifdef _DEBUG
297+
std::cout << "In grb::foldr( BSP1D, matrix, scalar, mask, op )\n";
298+
#endif
299+
RC rc = SUCCESS;
300+
301+
if( grb::nnz( A ) == 0 ) {
302+
return rc;
303+
}
304+
305+
// Do local folding
306+
rc = foldr< descr >( internal::getLocal( A ), internal::getLocal( mask ), x, op );
307+
308+
return rc;
309+
}
310+
311+
template<
312+
Descriptor descr = descriptors::no_operation,
313+
class Operator,
314+
typename IOType, typename InputType,
315+
typename RIT, typename CIT, typename NIT
316+
>
317+
RC foldr(
318+
Matrix< IOType, BSP1D, RIT, CIT, NIT > &A,
319+
const InputType &x,
320+
const Operator &op = Operator(),
321+
const typename std::enable_if<
322+
!grb::is_object< IOType >::value &&
323+
!grb::is_object< InputType >::value &&
324+
grb::is_operator< Operator >::value, void
325+
>::type * const = nullptr
326+
) {
327+
#ifdef _DEBUG
328+
std::cout << "In grb::foldr( BSP1D, matrix, scalar, op )\n";
329+
#endif
330+
RC rc = SUCCESS;
331+
332+
if( grb::nnz( A ) == 0 ) {
333+
return rc;
334+
}
335+
336+
// Do local folding
337+
rc = foldr< descr >( internal::getLocal( A ), x, op );
338+
339+
return rc;
340+
}
341+
208342
} // namespace grb
209343

210344
#endif

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
149+
BACKENDS reference reference_omp hyperdags bsp1d hybrid
150150
)
151151

152152
add_grb_executables( muladd muladd.cpp

tests/unit/fold_matrix_scalar_to_matrix.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ struct input {
109109
const OpFoldl & opFoldl;
110110
const OpFoldr & opFoldr = OpFoldr();
111111

112-
input( const char * test_label,
113-
const char * test_description,
114-
const grb::Matrix< T > & initial,
115-
const grb::Matrix< M > & mask,
116-
const S scalar,
117-
const grb::Matrix< T > & expected,
112+
input( const char * test_label = "",
113+
const char * test_description = "",
114+
const grb::Matrix< T > & initial = {0,0},
115+
const grb::Matrix< M > & mask = {0,0},
116+
const S scalar = 0,
117+
const grb::Matrix< T > & expected = {0,0},
118118
bool skip_masked = false,
119119
bool skip_unmasked = false,
120120
const OpFoldl & opFoldl = OpFoldl(),

tests/unit/unittests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ 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" = "reference" ] || [ "$BACKEND" = "reference_omp" ] || [ "$BACKEND" = "hyperdags" ]; then
225+
if [ "$BACKEND" != "nonblocking" ]; then
226226
echo ">>> [x] [x] Testing grb::foldl and grb::foldr reducing sparse"
227227
echo " matrix in-place using operators."
228228
$runner ${TEST_BIN_DIR}/fold_matrix_scalar_to_matrix_${MODE}_${BACKEND} &> ${TEST_OUT_DIR}/fold_matrix_scalar_to_matrix_${MODE}_${BACKEND}_${P}_${T}.log

0 commit comments

Comments
 (0)