Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

319 provide select submatrix #320

Draft
wants to merge 58 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
eff687b
Masked outer product implementation
aleksamilisavljevic Jan 26, 2024
1a9663b
Add unit test for the masked outer product
aleksamilisavljevic Jan 26, 2024
de9a6ce
OpenMP support and code changes
aleksamilisavljevic Feb 13, 2024
99a1040
test improvement
aleksamilisavljevic Feb 13, 2024
f5562e1
code cleanup
aleksamilisavljevic Feb 13, 2024
f64dee8
clear the matrix in special cases
aleksamilisavljevic Feb 13, 2024
ef07fec
special case of an empty mask
aleksamilisavljevic Feb 13, 2024
b79e7ff
empty mask special case
aleksamilisavljevic Feb 15, 2024
7b3f795
nonblocking implementation
byjtew Feb 16, 2024
99f5c84
Merge branch 'develop' into 283-provide-the-implementation-of-the-mas…
byjtew Feb 16, 2024
8dff749
Implementation in base + documentation
byjtew Feb 16, 2024
0a89a08
hyperdags implementation
byjtew Feb 16, 2024
6843e53
bsp1d+hybrid implementation
byjtew Feb 16, 2024
cbae669
Enable test for all backends
byjtew Feb 16, 2024
8b48135
rename maskedOuter to outer
aleksamilisavljevic Feb 15, 2024
abcc356
Masked outer product implementation
aleksamilisavljevic Jan 26, 2024
89b1184
Add unit test for the masked outer product
aleksamilisavljevic Jan 26, 2024
4dc1e37
OpenMP support and code changes
aleksamilisavljevic Feb 13, 2024
dfafe0c
test improvement
aleksamilisavljevic Feb 13, 2024
a73fcb1
code cleanup
aleksamilisavljevic Feb 13, 2024
6b91b64
clear the matrix in special cases
aleksamilisavljevic Feb 13, 2024
e91f9ed
special case of an empty mask
aleksamilisavljevic Feb 13, 2024
76bd102
empty mask special case
aleksamilisavljevic Feb 15, 2024
279894c
nonblocking implementation
byjtew Feb 16, 2024
eeed910
Implementation in base + documentation
byjtew Feb 16, 2024
28281fd
hyperdags implementation
byjtew Feb 16, 2024
6d3522b
bsp1d+hybrid implementation
byjtew Feb 16, 2024
f15bc07
Enable test for all backends
byjtew Feb 16, 2024
4a171bd
rename maskedOuter to outer
aleksamilisavljevic Feb 15, 2024
98d62b2
rename
aleksamilisavljevic Feb 16, 2024
7addcf7
descriptors support
aleksamilisavljevic Feb 19, 2024
fcf975f
Merge branch '283-provide-the-implementation-of-the-masked-outer-prod…
aleksamilisavljevic Feb 19, 2024
296ca85
unmerged conflict
aleksamilisavljevic Feb 19, 2024
e9012ba
code cleanup
aleksamilisavljevic Feb 20, 2024
48594d1
masked set matrix to matrix
aleksamilisavljevic Feb 21, 2024
0ef5c3d
tests
aleksamilisavljevic Feb 21, 2024
cabc337
tests refactor
aleksamilisavljevic Feb 21, 2024
4040f69
nonblocking implementation
aleksamilisavljevic Feb 21, 2024
a570690
hyperdags implementation
aleksamilisavljevic Feb 21, 2024
b038241
Merge branch 'develop' into 283-provide-the-implementation-of-the-mas…
byjtew Feb 22, 2024
da9de37
unsupport structural complement
aleksamilisavljevic Feb 24, 2024
7289248
fix print of the unit test
aleksamilisavljevic Feb 26, 2024
c410d8f
code cleanup
aleksamilisavljevic Feb 26, 2024
9df4dc7
Merge branch 'develop' into 283-provide-the-implementation-of-the-mas…
aleksamilisavljevic Feb 26, 2024
b063624
unit test fix
aleksamilisavljevic Feb 26, 2024
3de4e27
rename
aleksamilisavljevic Feb 26, 2024
883479e
code cleanup
aleksamilisavljevic Feb 26, 2024
c36b4d9
handle void matrix mask
aleksamilisavljevic Feb 26, 2024
e5223c1
handle invert masks properly
aleksamilisavljevic Feb 27, 2024
46f58f3
code cleanup
aleksamilisavljevic Feb 27, 2024
cf2e317
omp reductions
aleksamilisavljevic Feb 27, 2024
b8bf1eb
Merge branch 'develop' into 268-provide-grbsetmatrix-out-matrix-mask-…
aleksamilisavljevic Feb 27, 2024
5c639a8
draft of the submask selection functionality
aleksamilisavljevic Feb 27, 2024
8ecab8a
rename
aleksamilisavljevic Feb 27, 2024
eff8f6c
rename
aleksamilisavljevic Feb 27, 2024
bf3e316
Merge branch '283-provide-the-implementation-of-the-masked-outer-prod…
aleksamilisavljevic Feb 27, 2024
307be9f
Merge branch '268-provide-grbsetmatrix-out-matrix-mask-matrix-in' int…
aleksamilisavljevic Feb 27, 2024
0de1411
merge of required features
aleksamilisavljevic Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions include/graphblas/base/blas3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,96 @@ namespace grb {
return ret == SUCCESS ? UNSUPPORTED : ret;
}

/**
* Masked outer product of two vectors. Assuming vectors \a u and \a v are
* oriented column-wise, the result matrix \a A will contain \f$ uv^T \f$,
* masked to non-zero values from \a mask. This is an out-of-place
* function and will be updated soon to be in-place instead.
*
* \internal Implemented via mxm as a multiplication of a column vector with
* a row vector, while following the given mask.
*
* @tparam descr The descriptor to be used. Optional; the default is
* #grb::descriptors::no_operation.
* @tparam Operator The operator to use.
* @tparam InputType1 The value type of the left-hand vector.
* @tparam InputType2 The value type of the right-hand vector.
* @tparam MaskType The value type of the mask matrix.
* @tparam OutputType The value type of the ouput matrix
*
* @param[out] A The output matrix.
* @param[out] mask The mask matrix.
* @param[in] u The left-hand input vector.
* @param[in] v The right-hand input vector.
* @param[in] op The operator.
* @param[in] phase The #grb::Phase the call should execute. Optional; the
* default parameter is #grb::EXECUTE.
*
* @return #grb::SUCCESS On successful completion of this call.
* @return #grb::MISMATCH Whenever the dimensions of the inputs and/or outputs
* do not match. All input data containers are left
* untouched if this exit code is returned; it will be
* be as though this call was never made.
* @return #grb::FAILED If \a phase is #grb::EXECUTE, indicates that the
* capacity of \a A was insufficient. The output
* matrix \a A is cleared, and the call to this function
* has no further effects.
* @return #grb::OUTOFMEM If \a phase is #grb::RESIZE, indicates an
* out-of-memory exception. The call to this function
* shall have no other effects beyond returning this
* error code; the previous state of \a A is retained.
* @return #grb::PANIC A general unmitigable error has been encountered. If
* returned, ALP enters an undefined state and the user
* program is encouraged to exit as quickly as possible.
*
* \par Performance semantics
*
* Each backend must define performance semantics for this primitive.
*
* @see perfSemantics
*/
template<
Descriptor descr = descriptors::no_operation,
class Operator,
typename InputType1, typename InputType2,
typename OutputType, typename MaskType,
typename Coords,
typename RIT, typename CIT, typename NIT,
Backend backend
>
RC outer(
Matrix< OutputType, backend, RIT, CIT, NIT > &A,
const Matrix< MaskType, backend, RIT, CIT, NIT > &mask,
const Vector< InputType1, backend, Coords > &u,
const Vector< InputType2, backend, Coords > &v,
const Operator &op = Operator(),
const Phase &phase = EXECUTE,
const typename std::enable_if<
grb::is_operator< Operator >::value &&
!grb::is_object< InputType1 >::value &&
!grb::is_object< InputType2 >::value &&
!grb::is_object< MaskType >::value &&
!grb::is_object< OutputType >::value,
void >::type * const = nullptr
) {
(void) A;
(void) mask;
(void) u;
(void) v;
(void) op;
(void) phase;
#ifdef _DEBUG
std::cerr << "Selected backend does not implement grb::outer\n";
#endif
#ifndef NDEBUG
const bool selected_backend_does_not_support_masked_outer = false;
assert( selected_backend_does_not_support_masked_outer );
#endif
const RC ret = grb::clear( A );
return ret == SUCCESS ? UNSUPPORTED : ret;
}


/**
* @}
*/
Expand Down
44 changes: 44 additions & 0 deletions include/graphblas/bsp1d/blas3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,50 @@ namespace grb {
return internal::checkGlobalErrorStateOrClear( C, ret );
}

/** \internal Simply delegates to process-local backend */
template<
Descriptor descr = descriptors::no_operation,
class Operator,
typename InputType1, typename InputType2,
typename MaskType, typename OutputType,
typename Coords,
typename RIT, typename CIT, typename NIT
>
RC outer(
Matrix< OutputType, BSP1D, RIT, CIT, NIT > &A,
const Matrix< MaskType, BSP1D, RIT, CIT, NIT > &mask,
const Vector< InputType1, BSP1D, Coords > &u,
const Vector< InputType2, BSP1D, Coords > &v,
const Operator &mul = Operator(),
const Phase &phase = EXECUTE,
const typename std::enable_if<
grb::is_operator< Operator >::value &&
!grb::is_object< InputType1 >::value &&
!grb::is_object< InputType2 >::value &&
!grb::is_object< MaskType >::value &&
!grb::is_object< OutputType >::value,
void >::type * const = nullptr
) {
assert( phase != TRY );
RC ret = outer< descr, Operator >(
internal::getLocal( A ),
internal::getLocal( mask ),
internal::getLocal( u ),
internal::getLocal( v ),
mul,
phase
);
if( phase == RESIZE ) {
if( collectives<>::allreduce( ret, operators::any_or< RC >() ) != SUCCESS ) {
return PANIC;
} else {
return SUCCESS;
}
}
assert( phase == EXECUTE );
return internal::checkGlobalErrorStateOrClear( A, ret );
}

} // namespace grb

#endif
Expand Down
53 changes: 53 additions & 0 deletions include/graphblas/hyperdags/blas3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,59 @@ namespace grb {
return ret;
}

template<
Descriptor descr = descriptors::no_operation,
class Operator,
typename InputType1, typename InputType2,
typename MaskType, typename OutputType,
typename Coords,
typename RIT, typename CIT, typename NIT
>
RC outer(
Matrix< OutputType, hyperdags, RIT, CIT, NIT > &A,
const Matrix< MaskType, hyperdags, RIT, CIT, NIT > &mask,
const Vector< InputType1, hyperdags, Coords > &u,
const Vector< InputType2, hyperdags, Coords > &v,
const Operator &mul = Operator(),
const Phase &phase = EXECUTE,
const typename std::enable_if<
grb::is_operator< Operator >::value &&
!grb::is_object< InputType1 >::value &&
!grb::is_object< InputType2 >::value &&
!grb::is_object< MaskType >::value &&
!grb::is_object< OutputType >::value,
void >::type * const = nullptr
) {
const RC ret = outer< descr >(
internal::getMatrix( A ),
internal::getMatrix( mask ),
internal::getVector( u ),
internal::getVector( v ),
mul,
phase
);
if( ret != SUCCESS ) { return ret; }
if( phase != EXECUTE ) { return ret; }
if( nrows( A ) == 0 || ncols( A ) == 0 ) { return ret; }
std::array< const void *, 0 > sourcesP{};
std::array< uintptr_t, 4 > sourcesC{
getID( internal::getVector(u) ),
getID( internal::getVector(v) ),
getID( internal::getMatrix(mask) ),
getID( internal::getMatrix(A) )
};
std::array< uintptr_t, 1 > destinations{
getID( internal::getMatrix(A) )
};
internal::hyperdags::generator.addOperation(
internal::hyperdags::MASKED_OUTER,
sourcesP.begin(), sourcesP.end(),
sourcesC.begin(), sourcesC.end(),
destinations.begin(), destinations.end()
);
return ret;
}

template<
Descriptor descr = descriptors::no_operation,
typename OutputType, typename InputType1, typename InputType2,
Expand Down
7 changes: 6 additions & 1 deletion include/graphblas/hyperdags/hyperdags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,16 @@ namespace grb {

SET_MATRIX_MATRIX_INPUT2,

SET_MATRIX_MATRIX_MASKED,

MXM_MATRIX_MATRIX_MATRIX_SEMIRING,

MXM_MATRIX_MATRIX_MATRIX_MONOID,

OUTER,

MASKED_OUTER,

UNZIP_VECTOR_VECTOR_VECTOR,

ZIP_MATRIX_VECTOR_VECTOR_VECTOR,
Expand Down Expand Up @@ -493,7 +497,7 @@ namespace grb {
};

/** \internal How many operation vertex types exist. */
const constexpr size_t numOperationVertexTypes = 106;
const constexpr size_t numOperationVertexTypes = 107;

/** \internal An array of all operation vertex types. */
const constexpr enum OperationVertexType
Expand Down Expand Up @@ -553,6 +557,7 @@ namespace grb {
MXM_MATRIX_MATRIX_MATRIX_SEMIRING,
MXM_MATRIX_MATRIX_MATRIX_MONOID,
OUTER,
MASKED_OUTER,
UNZIP_VECTOR_VECTOR_VECTOR,
ZIP_MATRIX_VECTOR_VECTOR_VECTOR,
ZIP_MATRIX_VECTOR_VECTOR,
Expand Down
35 changes: 35 additions & 0 deletions include/graphblas/hyperdags/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,41 @@ namespace grb {
return ret;
}

template<
Descriptor descr = descriptors::no_operation,
typename OutputType, typename MaskType, typename InputType,
typename RIT1, typename CIT1, typename NIT1,
typename RIT2, typename CIT2, typename NIT2
>
RC set(
Matrix< OutputType, hyperdags, RIT1, CIT1, NIT1 > &C,
const Matrix< MaskType, hyperdags, RIT2, CIT2, NIT2 > &M,
const Matrix< InputType, hyperdags, RIT2, CIT2, NIT2 > &A,
const Phase &phase = EXECUTE
) {
const RC ret = set< descr >(
internal::getMatrix( C ), internal::getMatrix( M ),
internal::getMatrix( A ), phase
);
if( ret != SUCCESS ) { return ret; }
if( phase != EXECUTE ) { return ret; }
if( nrows( A ) == 0 || ncols( A ) == 0 ) { return ret; }
std::array< const void *, 0 > sourcesP{};
std::array< uintptr_t, 3 > sourcesC{
getID( internal::getMatrix(A) ),
getID( internal::getMatrix(M) ),
getID( internal::getMatrix(C) )
};
std::array< uintptr_t, 1 > destinations{ getID( internal::getMatrix(C) ) };
internal::hyperdags::generator.addOperation(
internal::hyperdags::SET_MATRIX_MATRIX_MASKED,
sourcesP.begin(), sourcesP.end(),
sourcesC.begin(), sourcesC.end(),
destinations.begin(), destinations.end()
);
return ret;
}

template< typename DataType, typename Coords >
RC clear( Vector< DataType, hyperdags, Coords > &x ) {
const RC ret = clear( internal::getVector( x ) );
Expand Down
46 changes: 46 additions & 0 deletions include/graphblas/nonblocking/blas3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,52 @@ namespace grb {
);
}

template<
Descriptor descr = descriptors::no_operation,
class Operator,
typename InputType1, typename InputType2,
typename OutputType, typename MaskType,
typename Coords,
typename RIT, typename CIT, typename NIT
>
RC outer(
Matrix< OutputType, nonblocking, RIT, CIT, NIT > &A,
const Matrix< MaskType, nonblocking, RIT, CIT, NIT > &mask,
const Vector< InputType1, nonblocking, Coords > &u,
const Vector< InputType2, nonblocking, Coords > &v,
const Operator &mul = Operator(),
const Phase &phase = EXECUTE,
const typename std::enable_if<
grb::is_operator< Operator >::value &&
!grb::is_object< InputType1 >::value &&
!grb::is_object< InputType2 >::value &&
!grb::is_object< MaskType >::value &&
!grb::is_object< OutputType >::value,
void >::type * const = nullptr
) {
if( internal::NONBLOCKING::warn_if_not_native &&
config::PIPELINE::warn_if_not_native
) {
std::cerr << "Warning: outer (nonblocking) currently delegates "
<< "to a blocking implementation.\n"
<< " Further similar such warnings will be suppressed.\n";
internal::NONBLOCKING::warn_if_not_native = false;
}

// nonblocking execution is not supported
// first, execute any computation that is not completed
internal::le.execution();

// second, delegate to the reference backend
return outer< descr, Operator >(
internal::getRefMatrix( A ),
internal::getRefMatrix( mask ),
internal::getRefVector( u ),
internal::getRefVector( v ),
mul, phase
);
}

namespace internal {

template<
Expand Down
35 changes: 35 additions & 0 deletions include/graphblas/nonblocking/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,41 @@ namespace grb {
}
}


template<
Descriptor descr = descriptors::no_operation,
typename OutputType, typename MaskType, typename InputType,
typename RIT1, typename CIT1, typename NIT1,
typename RIT2, typename CIT2, typename NIT2
>
RC set(
Matrix< OutputType, nonblocking, RIT1, CIT1, NIT1 > &C,
const Matrix< MaskType, nonblocking, RIT2, CIT2, NIT2 > &M,
const Matrix< InputType, nonblocking, RIT2, CIT2, NIT2 > &A,
const Phase &phase = EXECUTE
) noexcept {
if( internal::NONBLOCKING::warn_if_not_native &&
config::PIPELINE::warn_if_not_native
) {
std::cerr << "Warning: masked set (nonblocking) currently delegates "
<< "to a blocking implementation.\n"
<< " Further similar such warnings will be suppressed.\n";
internal::NONBLOCKING::warn_if_not_native = false;
}

// nonblocking execution is not supported
// first, execute any computation that is not completed
internal::le.execution();

// second, delegate to the reference backend
return set< descr >(
internal::getRefMatrix( C ),
internal::getRefMatrix( M ),
internal::getRefMatrix( A ),
phase
);
}

template<
Descriptor descr = descriptors::no_operation,
typename InputType,
Expand Down
Loading
Loading