Skip to content

Commit 8ba837b

Browse files
hidanielesgitDenis Jelovina
authored andcommitted
# This is a combination of 55 commits.
# This is the 1st commit message: Issue #303: framework for reference_dense added This commit comes from a split of the original commit whose details are as follows: SHA1 ID: a7c1db0 Author: Albert-Jan Yzelman <[email protected]> 2022-01-14 15:52:26 Committer: Albert-Jan Yzelman <[email protected]> 2022-01-30 13:48:35 The reason for splitting is to separate the changes irrelevant to the branch 303 into a separate branch. The split produced 3 separate commits. This commit is number 1. This commit in particular is relevant to 303 and will remain in it. # This is the commit message #2: Issue #303: unify script argument similar to --no-reference # This is the commit message #3: Issue #303: complete implementation of Vector< reference_dense >, modulo output iteration. # This is the commit message #4: Issue #303: modified vector implementation according to option 3 in handling dense container construction. # This is the commit message #5: Issue #303: vectors now have an iterator for the user to extract data from. # This is the commit message #6: Issue #303, fixed silly oops: the difference between two iterators should be an integer # This is the commit message #7: Issue #303: containers are now uninitialized on construction. Iteration over uninitialized containers returns nothing. # This is the commit message #8: Issue #303: configure and cmake now properly do make install with reference_dense # This is the commit message #9: Issue #303: cmake infra has updated-- make dense_reference additions compatible to it # This is the commit message #10: Drafting structured matrix interface using reference_dense backend # This is the commit message #11: Issue #303: Copy test mxm.cpp to dense_mxm.cpp as a starting point # This is the commit message #12: Issue #303: Add partial first version of Matrix interface for denseref # This is the commit message #13: Issue #303: WIP: dense mxm test # This is the commit message #14: Issue #303: Add dense mxm test to CMakeLists # This is the commit message #15: Issue #303: Separate reference and reference_dense includes # This is the commit message #16: Issue #303: Fix grb include name mismatch # This is the commit message #17: Issue #303: Add src files for reference dense backend # This is the commit message #18: Issue #303: Add project related option for dense backend # This is the commit message #19: Issue #303: Remove dense_reference-related code from reference cmake # This is the commit message #20: Keeping a clean separate denseref backend when building with cmake. # This is the commit message #21: Fix cmake option name # This is the commit message #22: Use a proper data container for a denseref matrix # This is the commit message #23: Change PRIVATE to INTERFACE for denseref backend # This is the commit message #24: fix cmake config for building backend # This is the commit message #25: Add friend functions for accessing matrix dimensions and raw data # This is the commit message #26: Add first version of blas3 mxm for reference dense backend # This is the commit message #27: Add temporary code for matrix data initialization # This is the commit message #28: Complete first working dense mxm unit test # This is the commit message #29: Added structured matrix test including draft static views and references # This is the commit message #30: Convert spaces to tabs # This is the commit message #31: Make use of operators and monoid provided to mxm # This is the commit message #32: Add friend getter/setter for field 'initialized' of denseref matrix # This is the commit message #33: Revert "Add temporary code for matrix data initialization" This reverts commit 676cb4d. # This is the commit message #34: Add temporary way for allocating data of a denseref matrix # This is the commit message #35: Add functions to initialize matrix data from provided forward iterator # This is the commit message #36: Make getters const # This is the commit message #37: Exploit new features in mxm unit test New features are building a matrix from an iterator and handling of uninitialized matrices. # This is the commit message #38: added get/remove_ref type traits for StructuredMatrix types # This is the commit message #39: Temporary switch to pointers to target matrices to enable empty init. # This is the commit message #40: First draft of index mapping functions # This is the commit message #41: Cleaned up StructuredMatrix-related doxygen drafts # This is the commit message #42: Added to the spec draft # This is the commit message #43: Add alloc primitives for denseref Currently they are a copy of the same primitives for reference backend. Think whether it makes sense to group the alloc functions for these two backends. # This is the commit message #44: Handle memory allocation failure. Implement destructor. # This is the commit message #45: WIP: Add data size calculator depending on Storage scheme and structure. Also add a simple test to showcase the usage of this feature. # This is the commit message #46: Add buildMatrix for general full StructuredMatrix # This is the commit message #47: Add a check for size mismatch in buildMatrix # This is the commit message #48: Add mxm for dense Structured Matrices # This is the commit message #49: Introducing grb::get_view<> draft # This is the commit message #50: Add UpperTriangular StructuredMatrix (container and view) # This is the commit message #51: Implement polymorphic comparison of IMFs # This is the commit message #52: Add to structures a compatibility check from source structure and IMF functions This is to be used when creating a view over a source matrix using provided IMF functions. The compatibility of TargetStructure depends on the SourceStructure and provided IMF functions. This is a runtime check. # This is the commit message #53: Add constructor taking two IMFs to reference SM with general structure # This is the commit message #54: Implement gather through view with provided TargetStructure and IMFs # This is the commit message #55: Add test for gathers on StructuredMatrix using views with IMFs
1 parent f9b15c2 commit 8ba837b

35 files changed

+2323
-127
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ endif()
5050
### CONFIGURATION OPTIONS
5151
# to choose backends and dependencies
5252
option( WITH_REFERENCE_BACKEND "With Reference backend" ON )
53-
option( WITH_DENSE_BACKEND "With Dense backend" ON )
53+
option( WITH_DENSEREF_BACKEND "With Reference Dense backend" ON )
5454
option( WITH_OMP_BACKEND "With OMP backend" ON )
5555
option( WITH_HYPERDAGS_BACKEND "With Hyperdags backend" ON )
5656
if( WITH_HYPERDAGS_BACKEND )

bootstrap.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ the current directory before invocation or confirm the deletion of its content w
369369
CMAKE_OPTS+=" -DWITH_NONBLOCKING_BACKEND=OFF"
370370
fi
371371
if [[ "${dense}" == "no" ]]; then
372-
CMAKE_OPTS+=" -DWITH_DENSE_BACKEND=OFF"
372+
CMAKE_OPTS+=" -DWITH_DENSEREF_BACKEND=OFF"
373373
else
374-
CMAKE_OPTS+=" -DWITH_DENSE_BACKEND=ON"
374+
CMAKE_OPTS+=" -DWITH_DENSEREF_BACKEND=ON"
375375
fi
376376
if [[ "${lpf}" == "yes" ]]; then
377377
CMAKE_OPTS+=" -DLPF_INSTALL_PATH='${ABSOLUTE_LPF_INSTALL_PATH}'"

cmake/AddGRBInstall.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ install( EXPORT GraphBLASTargets
4545
set( ALP_UTILS_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}" )
4646
set( SHMEM_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/sequential" )
4747
set( HYPERDAGS_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hyperdags" )
48+
set( DENSEREF_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/denseref" )
4849
set( BSP1D_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/spmd" )
4950
set( HYBRID_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hybrid" )
5051

@@ -121,10 +122,10 @@ if( WITH_REFERENCE_BACKEND )
121122
)
122123
endif()
123124

124-
if( WITH_DENSE_BACKEND )
125+
if( WITH_DENSEREF_BACKEND )
125126
addBackendWrapperGenOptions( "reference_dense"
126-
COMPILE_DEFINITIONS "${DENSE_SELECTION_DEFS}"
127-
LINK_FLAGS "${SHMEM_BACKEND_INSTALL_DIR}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a"
127+
COMPILE_DEFINITIONS "DENSEREF_INCLUDE_DEFS" "${DENSEREF_SELECTION_DEFS}"
128+
LINK_FLAGS "${DENSEREF_BACKEND_INSTALL_DIR}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a"
128129
)
129130
endif()
130131

cmake/AddGRBVars.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ set( BSP1D_BACKEND_DEFAULT_NAME "backend_bsp1d" )
3333
set( HYBRID_BACKEND_DEFAULT_NAME "backend_hybrid" )
3434
set( HYPERDAGS_BACKEND_DEFAULT_NAME "backend_hyperdags" )
3535
set( NONBLOCKING_BACKEND_DEFAULT_NAME "backend_nonblocking" )
36-
set( DENSE_BACKEND_DEFAULT_NAME "backend_reference_dense" )
36+
set( DENSEREF_BACKEND_DEFAULT_NAME "backend_reference_dense" )
3737

3838

3939
### COMPILER DEFINITIONS FOR HEADERS INCLUSION AND FOR BACKEND SELECTION
@@ -44,7 +44,7 @@ set( REFERENCE_OMP_INCLUDE_DEFS "_GRB_WITH_OMP" )
4444
set( HYPERDAGS_INCLUDE_DEFS "_GRB_WITH_HYPERDAGS" )
4545
set( NONBLOCKING_INCLUDE_DEFS "_GRB_WITH_NONBLOCKING" )
4646
set( LPF_INCLUDE_DEFS "_GRB_WITH_LPF" )
47-
set( DENSE_INCLUDE_DEFS "_GRB_WITH_DENSE" )
47+
set( DENSEREF_INCLUDE_DEFS "_GRB_WITH_DENSEREF" )
4848

4949
# compiler definitions to select a backend
5050
set( REFERENCE_SELECTION_DEFS "_GRB_BACKEND=reference" )
@@ -54,7 +54,7 @@ set( HYPERDAGS_SELECTION_DEFS
5454
"_GRB_WITH_HYPERDAGS_USING=${WITH_HYPERDAGS_USING}"
5555
)
5656
set( NONBLOCKING_SELECTION_DEFS "_GRB_BACKEND=nonblocking" )
57-
set( DENSE_SELECTION_DEFS "_GRB_BACKEND=reference_dense" )
57+
set( DENSEREF_SELECTION_DEFS "_GRB_BACKEND=reference_dense" )
5858
set( BSP1D_SELECTION_DEFS
5959
"_GRB_BACKEND=BSP1D"
6060
"_GRB_BSP1D_BACKEND=reference"
@@ -94,7 +94,7 @@ if( WITH_NONBLOCKING_BACKEND )
9494
list( APPEND AVAILABLE_BACKENDS "nonblocking" )
9595
endif()
9696

97-
if( WITH_DENSE_BACKEND )
97+
if( WITH_DENSEREF_BACKEND )
9898
list( APPEND AVAILABLE_BACKENDS "reference_dense" )
9999
endif()
100100

include/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ if( WITH_REFERENCE_BACKEND_HEADERS )
120120
install( TARGETS backend_reference_headers EXPORT GraphBLASTargets )
121121
endif()
122122

123-
if( WITH_DENSE_BACKEND )
123+
if( WITH_DENSEREF_BACKEND )
124124
add_library( backend_reference_dense_headers INTERFACE )
125125
target_link_libraries( backend_reference_dense_headers INTERFACE backend_headers_nodefs )
126126
target_compile_definitions( backend_reference_dense_headers INTERFACE "${DENSEREF_INCLUDE_DEFS}" )

include/graphblas/base/matrix.hpp

Lines changed: 110 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
#define _H_GRB_MATRIX_BASE
2929

3030
#include <iterator>
31-
3231
#include <stddef.h>
33-
32+
#include <type_traits>
3433
#include <utility>
34+
#include <memory>
3535

3636
#include <graphblas/backends.hpp>
3737
#include <graphblas/descriptors.hpp>
@@ -41,6 +41,7 @@
4141
#include <graphblas/structures.hpp>
4242
#include <graphblas/utils.hpp>
4343
#include <graphblas/views.hpp>
44+
#include <graphblas/imf.hpp>
4445

4546

4647
namespace grb {
@@ -395,39 +396,112 @@ namespace grb {
395396

396397
};
397398

399+
template< typename InputType, Backend backend >
400+
RC clear( Matrix< InputType, backend > & A ) noexcept {
401+
// this is the generic stub implementation
402+
return UNSUPPORTED;
403+
}
404+
398405
/**
399-
* An ALP structured matrix.
406+
* \brief An ALP structured matrix.
400407
*
401-
* This is an opaque data type for that implements the below functions.
408+
* This is an opaque data type for structured matrices.
409+
* This container allows to maintain the interface of grb::Matrix and grb::Vector
410+
* unaltered enabling back-compatibility while building on them to create
411+
* semantically reacher algebraic objects.
412+
* A structured matrix is generalized over five parameters further described
413+
* below: its data type,
414+
* its structure, whether it is stored using a dense or sparse storage scheme,
415+
* a static view and the backend for which it is implemented.
416+
* At a high level of abstraction a structured matrix exposes a mathematical
417+
* \em logical layout which allows to express implementation-oblivious concepts
418+
* (e.g., the transpose of a symmetric matrix).
419+
* At the lowest level, the logical layout maps to its physical counterpart via
420+
* a particular choice of a storage scheme within those exposed by the chosen
421+
* backend. grb::Matrix and grb::Vector are used as interfaces to the physical
422+
* layout.
423+
* To visualize this, you could think of a band matrix. Using either the
424+
* \a storage::Dense:full or \a storage::Dense:band storage schemes would require
425+
* the use of a \a grb::Matrix container (see include/graphblas/storage.hpp for
426+
* more details about the two storage schemes). However, the interpration of its
427+
* content would differ in the two cases being a function of both the Structure
428+
* information and the storage scheme combined.
429+
*
430+
* Views can be used to create logical \em perspectives on top of a container.
431+
* For example, I could decide to refer to the transpose of a matrix or to see
432+
* a for limited part of my program a square matrix as symmetric.
433+
* If a view can be expressed as concept invariant of specific runtime features,
434+
* such views can be defined statically (for example I can always refer to the
435+
* transpose or the diagonal of a matrix irrespective of features such as its
436+
* size). Other may depend on features such as the size of a matrix
437+
* and can be expressed as linear transformations via operations such as \a mxm
438+
* (e.g., gathering/scattering the rows/columns of a matrix or permuting them).
439+
* Structured matrices defined as views on other matrices do not instantiate a
440+
* new container but refer to the one used by their targets. (See the
441+
* documentation of StructuredMatrix for both scenarios within the \em denseref
442+
* backend folder).
402443
*
403444
* @tparam T The type of the matrix elements. \a T shall not be a GraphBLAS
404445
* type.
405-
* @tparam Structure One of the matrix structures in grb::structures.
406-
* @tparam view One of the matrix views in enum grb::Views. All static views except for
407-
* \a Views::original disable the possibility to instantiate a new container and only
408-
* allow the creation of a reference to an existing \a StructuredMatrix
409-
* (note that this could be view itself). A view could be instanciated into a separate container
410-
* than its original source by explicit copy.
411-
* @tparam backend Allows multiple backends to implement different
412-
* versions of this data type.
446+
* @tparam Structure One of the matrix structures in \a grb::structures.
447+
* @tparam StorageSchemeType Either \em enum \a storage::Dense or \em enum
448+
* \a storage::Sparse.
449+
* A StructuredMatrix will be allowed to pick among the storage schemes
450+
* within their specified \a StorageSchemeType.
451+
* @tparam View One of the matrix views in \a grb::view.
452+
* All static views except for \a view::Identity (via
453+
* \a view::identity<void> cannot instantiate a new container and only
454+
* allow to refer to an existing \a StructuredMatrix.
455+
* The \a View parameter should not be used directly by the user but
456+
* can be set using specific member types appropriately
457+
* defined by each StructuredMatrix. (See examples of StructuredMatrix
458+
* definitions within \a include/graphblas/denseref/matrix.hpp and the
459+
* \a dense_structured_matrix.cpp unit test).
460+
* @tparam backend Allows multiple backends to implement different versions
461+
* of this data type.
413462
*
414-
* \note The presence of different combination of structures and views could produce many specialization
415-
* with lots of logic replication.
463+
* \note The presence of different combination of structures and views could
464+
* produce many specialization with lots of logic replication. We might
465+
* could use some degree of inheritence to limit this.
416466
*/
417467
template< typename T, typename Structure, typename StorageSchemeType, typename View, enum Backend backend >
418468
class StructuredMatrix {
419469

420-
size_t m, n;
470+
471+
/**
472+
* Whether the container presently is initialized or not.
473+
* We differentiate the concept of empty matrix (matrix of size \f$0\times 0\f$)
474+
* from the one of uninitialized (matrix of size \f$m\times n\f$ which was never set)
475+
* and that of zero matrix (matrix with all zero elements).
476+
* \note in sparse format a zero matrix result in an ampty data structure. Is this
477+
* used to refer to uninitialized matrix in ALP/GraphBLAS?
478+
**/
479+
bool initialized;
480+
481+
/**
482+
* The two following members define the \em logical layout of a structured matrix:
483+
* Its structure and access relations. This is enabled only if the structured matrix
484+
* does not define a View on another matrix.
485+
*/
486+
using structure = Structure;
487+
/**
488+
* A pair of pointers to index mapping functions (see imf.hpp) that express the
489+
* logical access to the structured matrix.
490+
*/
491+
std::shared_ptr<imf::IMF> imf_l, imf_r;
421492

422493
/**
423-
* The container's data.
424-
* The geometry and access scheme are specified by a combination of
425-
* \a Structure, \a storage_scheme, \a m, and \a n.
494+
* When a structured matrix instanciate a \em container it defines a new \em physical
495+
* (concrete?) layout. This is characterized by an ALP container (aka a \a Matrix) and a
496+
* storage scheme that defines a unique interpretation of its content.
497+
* The combination of the logical and physical layout of a structured matrix enables to
498+
* identify a precise mapping between an element in the structured matrix and a position
499+
* wihtin one or more 1/2D-arrays that store it.
426500
*/
427-
T * __restrict__ data;
501+
Matrix< T, reference_dense > * _container;
428502

429503
/**
430-
* The container's storage scheme. \a storage_scheme is not exposed to the user as an option
504+
* A container's storage scheme. \a storage_scheme is not exposed to the user as an option
431505
* but can defined by ALP at different points in the execution depending on the \a backend choice.
432506
* For example, if the container is associated to an I/O matrix, with a reference backend
433507
* it might be set to reflect the storage scheme of the user data as specified at buildMatrix.
@@ -439,37 +513,32 @@ class StructuredMatrix {
439513
*/
440514
StorageSchemeType storage_scheme;
441515

442-
/** Whether the container presently is initialized or not. */
443-
bool initialized;
516+
/**
517+
* When a structured matrix defines a View over another matrix, it contains a pointer
518+
* to the latter. Its type can be identified via the View parameter.
519+
*/
520+
using target_type = typename std::enable_if<! std::is_same<View, view::Identity<void> >::value, typename View::applied_to>::type;
521+
target_type * ref;
444522

445523
public :
446524

447-
/**
448-
* Usable only in case of an \a original view. Otherwise the view should only reference another view.
449-
*/
450-
StructuredMatrix( const size_t m, const size_t n );
525+
StructuredMatrix( const size_t m, const size_t n );
451526

452-
/**
453-
* In case of non-original views should set up the container so to share the data of other.
454-
*/
455527
StructuredMatrix( const StructuredMatrix< T, Structure, StorageSchemeType, View, backend > & other );
456528

457-
/**
458-
* Usable only in case of an \a original view. Otherwise the view should only reference another view.
459-
*/
460529
StructuredMatrix( StructuredMatrix< T, Structure, StorageSchemeType, View, backend > && other );
461530

462-
/**
463-
* When view is \a original data should be properly deallocated.
464-
*/
465531
~StructuredMatrix();
466-
};
467532

468-
template< typename InputType, Backend backend >
469-
RC clear( Matrix< InputType, backend > & A ) noexcept {
470-
// this is the generic stub implementation
471-
return UNSUPPORTED;
472-
}
533+
}; // class StructuredMatrix
534+
535+
/**
536+
* Check if type \a T is a StructuredMatrix.
537+
*/
538+
template< typename T >
539+
struct is_structured_matrix : std::false_type {};
540+
template< typename T, typename Structure, typename StorageSchemeType, typename View, enum Backend backend >
541+
struct is_structured_matrix< StructuredMatrix< T, Structure, StorageSchemeType, View, backend > > : std::true_type {};
473542

474543
} // end namespace ``grb''
475544

include/graphblas/benchmark.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
#ifdef _GRB_WITH_REFERENCE
3131
#include "graphblas/reference/benchmark.hpp"
3232
#endif
33-
#ifdef _GRB_WITH_DENSE
34-
#include "graphblas/denseref/benchmark.hpp"
35-
#endif
33+
// #ifdef _GRB_WITH_DENSE
34+
// #include "graphblas/denseref/benchmark.hpp"
35+
// #endif
3636
#ifdef _GRB_WITH_HYPERDAGS
3737
#include "graphblas/hyperdags/benchmark.hpp"
3838
#endif

0 commit comments

Comments
 (0)