Skip to content

Commit 46f9cb8

Browse files
hidanielesgitDenis Jelovina
authored andcommitted
# This is a combination of 14 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 <yzelman@linux.fritz.box> 2022-01-14 15:52:26 Committer: Albert-Jan Yzelman <yzelman@linux.fritz.box> 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
1 parent 5c5aeec commit 46f9cb8

File tree

9 files changed

+534
-6
lines changed

9 files changed

+534
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ paths.mk
88
[Bb]uild*/
99
[Oo]bj*/
1010
[Ii]nstall*/
11-
cmake-build-*/
11+
cmake-build-*/
12+
.vscode/

include/graphblas/base/matrix.hpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#include <graphblas/descriptors.hpp>
3838
#include <graphblas/ops.hpp>
3939
#include <graphblas/rc.hpp>
40+
#include <graphblas/storage.hpp>
41+
#include <graphblas/structures.hpp>
42+
#include <graphblas/utils.hpp>
43+
#include <graphblas/views.hpp>
4044

4145

4246
namespace grb {
@@ -391,6 +395,82 @@ namespace grb {
391395

392396
};
393397

398+
/**
399+
* An ALP structured matrix.
400+
*
401+
* This is an opaque data type for that implements the below functions.
402+
*
403+
* @tparam T The type of the matrix elements. \a T shall not be a GraphBLAS
404+
* 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.
413+
*
414+
* \note The presence of different combination of structures and views could produce many specialization
415+
* with lots of logic replication.
416+
*/
417+
template< typename T, typename Structure, typename StorageSchemeType, typename View, enum Backend backend >
418+
class StructuredMatrix {
419+
420+
size_t m, n;
421+
422+
/**
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.
426+
*/
427+
T * __restrict__ data;
428+
429+
/**
430+
* The container's storage scheme. \a storage_scheme is not exposed to the user as an option
431+
* but can defined by ALP at different points in the execution depending on the \a backend choice.
432+
* For example, if the container is associated to an I/O matrix, with a reference backend
433+
* it might be set to reflect the storage scheme of the user data as specified at buildMatrix.
434+
* If \a backend is set to \a mlir then the scheme could be fixed by the JIT compiler to effectively
435+
* support its optimization strategy.
436+
* At construction time and until the moment the scheme decision is made it may be set to
437+
* an appropriate default choice, e.g. if \a StorageSchemeType is \a storage::Dense then
438+
* \a storage::Dense::full could be used.
439+
*/
440+
StorageSchemeType storage_scheme;
441+
442+
/** Whether the container presently is initialized or not. */
443+
bool initialized;
444+
445+
public :
446+
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 );
451+
452+
/**
453+
* In case of non-original views should set up the container so to share the data of other.
454+
*/
455+
StructuredMatrix( const StructuredMatrix< T, Structure, StorageSchemeType, View, backend > & other );
456+
457+
/**
458+
* Usable only in case of an \a original view. Otherwise the view should only reference another view.
459+
*/
460+
StructuredMatrix( StructuredMatrix< T, Structure, StorageSchemeType, View, backend > && other );
461+
462+
/**
463+
* When view is \a original data should be properly deallocated.
464+
*/
465+
~StructuredMatrix();
466+
};
467+
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+
}
473+
394474
} // end namespace ``grb''
395475

396476
#endif // end _H_GRB_MATRIX_BASE

include/graphblas/denseref/matrix.hpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,83 @@
2323
#ifndef _H_GRB_DENSEREF_MATRIX
2424
#define _H_GRB_DENSEREF_MATRIX
2525

26+
#include <graphblas/backends.hpp>
27+
#include <graphblas/base/matrix.hpp>
28+
#include <graphblas/config.hpp>
29+
#include <graphblas/utils.hpp>
30+
#include <graphblas/ops.hpp>
31+
#include <graphblas/rc.hpp>
32+
//#include <graphblas/reference/blas1.hpp>
33+
//#include <graphblas/reference/compressed_storage.hpp>
34+
//#include <graphblas/reference/init.hpp>
35+
#include <graphblas/type_traits.hpp>
36+
#include <graphblas/utils/autodeleter.hpp>
37+
//#include <graphblas/utils/pattern.hpp> //for help with dealing with pattern matrix input
38+
2639
namespace grb {
2740

2841
/** \internal TODO */
2942
template< typename T >
3043
class Matrix< T, reference_dense > {
44+
private:
45+
/** Our own type. */
46+
typedef Matrix< T, reference_dense > self_type;
47+
48+
/**
49+
* The number of rows.
50+
*
51+
* \internal Not declared const to be able to implement move in an elegant way.
52+
*/
53+
size_t m;
54+
55+
/**
56+
* The number of columns.
57+
*
58+
* \internal Not declared const to be able to implement move in an elegant way.
59+
*/
60+
size_t n;
61+
62+
/** Whether the container presently is uninitialized. */
63+
bool initialized;
64+
65+
std::vector< T > container;
66+
public:
67+
/** @see Matrix::value_type */
68+
typedef T value_type;
69+
70+
/** @see Matrix::Matrix() */
71+
Matrix( const size_t rows, const size_t columns ): m( rows ), n( columns ), initialized( false ) {
72+
73+
}
74+
75+
/** @see Matrix::Matrix( const Matrix & ) */
76+
Matrix( const Matrix< T, reference_dense > &other ) : Matrix( other.m, other.n ) {
77+
initialized = other.initialized;
78+
}
79+
80+
/** @see Matrix::Matrix( Matrix&& ). */
81+
Matrix( self_type &&other ) noexcept {
82+
moveFromOther( std::forward< self_type >(other) );
83+
}
84+
85+
/** * Move from temporary. */
86+
self_type& operator=( self_type &&other ) noexcept {
87+
moveFromOther( std::forward< self_type >(other) );
88+
return *this;
89+
}
90+
91+
/** @see Matrix::~Matrix(). */
92+
~Matrix() {
93+
94+
}
95+
96+
};
97+
98+
// template specialisation for GraphBLAS type traits
99+
template< typename T >
100+
struct is_container< Matrix< T, reference_dense > > {
101+
/** A reference_dense Matrix is a GraphBLAS object. */
102+
static const constexpr bool value = true;
31103
};
32104

33105
} // end namespace ``grb''

include/graphblas/matrix.hpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
// now include all specialisations contained in the backend directories:
3030
#ifdef _GRB_WITH_REFERENCE
31-
#include <graphblas/reference/matrix.hpp>
32-
#include <graphblas/denseref/matrix.hpp>
31+
#include <graphblas/reference/matrix.hpp>
3332
#endif
3433
#ifdef _GRB_WITH_HYPERDAGS
3534
#include <graphblas/hyperdags/matrix.hpp>
@@ -38,10 +37,10 @@
3837
#include "graphblas/nonblocking/matrix.hpp"
3938
#endif
4039
#ifdef _GRB_WITH_LPF
41-
#include <graphblas/bsp1d/matrix.hpp>
40+
#include <graphblas/bsp1d/matrix.hpp>
4241
#endif
4342
#ifdef _GRB_WITH_BANSHEE
44-
#include <graphblas/banshee/matrix.hpp>
43+
#include <graphblas/banshee/matrix.hpp>
4544
#endif
4645

4746
// specify default only if requested during compilation
@@ -55,7 +54,14 @@ namespace grb {
5554
typename NonzeroIndexType = config::NonzeroIndexType
5655
>
5756
class Matrix;
58-
}
57+
58+
/*
59+
* The default value of \a StorageSchemeType could also be made conditional (Dense or Sparse) depending on \a config::default_backend
60+
*/
61+
template< typename T, typename Structure, typename StorageSchemeType = storage::Dense, typename View = view::Identity< void >, enum Backend backend = config::default_backend >
62+
class StructuredMatrix;
63+
64+
} // namespace grb
5965
#endif
6066

6167
#endif // end ``_H_GRB_MATRIX''

include/graphblas/storage.hpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2021 Huawei Technologies Co., Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
*
19+
* @file This file registers matrix storage schemes that are either
20+
* implemented, under implementation, or were at any point in time
21+
* conceived and noteworthy enough to be recorded for future consideration.
22+
*/
23+
24+
#ifndef _H_GRB_STORAGE
25+
#define _H_GRB_STORAGE
26+
27+
#include <tuple>
28+
#include <type_traits>
29+
30+
namespace grb {
31+
32+
namespace storage {
33+
34+
/**
35+
* Collection of possible storage scheme options for dense matrices (or now including classic BLAS/LAPACK storage schemes).
36+
* \note Assumption is row-major but a complete specification might depend by a similar row/column-major option perhaps included
37+
* at the level of Matrix (general ).
38+
*/
39+
enum Dense {
40+
41+
/**
42+
* Conventional storage in a 2D array. The matrix element \f$A(i,j)\f$ is stored in array element \f$a(i,j)\f$.
43+
* Although some non-general structured matrices may forbid access to part of the array,
44+
* with this storage option a full rectangular array must be allocated.
45+
* This option could also be used as default/initial choice when a storage scheme decision has not yet been made.
46+
*/
47+
full,
48+
49+
/**
50+
* Compact 2D storage for Band matrices. An \f$m-\times-n\f$ band matrix with \f$kl\f$ subdiagonals
51+
* and \f$ku\f$ superdiagonals may be stored compactly in a 2D array with \f$m\f$ rows and \f$kl+ku+1\f$ columns.
52+
* Rows of the matrix are stored in corresponding rows of the array, and diagonals of the matrix are stored
53+
* in columns of the array.
54+
* This storage scheme should be used in practice only if \f$kl, ku \ll \min(m,n)\f$, although it should work correctly
55+
* for all values of \f$kl\f$ and \f$ku\f$.
56+
*/
57+
band,
58+
59+
/**
60+
* A tridiagonal matrix of order \f$n\f$ is stored in three 1D arrays, one of length \f$n\f$
61+
* containing the diagonal elements, and two of length \f$n-1\f$ containing the subdiagonal
62+
* and superdiagonal elements.
63+
* Symmetric tridiagonal and bidiagonal matrices are stored in two 1D arrays, one of length \f$n\f$
64+
* containing the diagonal elements, and one of length \f$n-1\f$ containing the off-diagonal elements.
65+
* A diagonal matrix is stored as a 1D array of length \f$n\f$.
66+
* Symmetric, Hermitian or triangular matrices store the relevant triangle packed by rows in a 1D array:
67+
* \li \c AlignLeft \f$A(i,j)\f$ is stored in \f$a( j + i*(i + 1)/2 )\f$ for \f$i \leq j\f$
68+
* \li \c AlignLeft \f$A(i,j)\f$ is stored in \f$a( j + i*(2*n - i - 1)/2 )\f$ for \f$j \leq i\f$
69+
*/
70+
array1d
71+
}; // Dense
72+
73+
// enum Sparse {
74+
// ...
75+
// };
76+
77+
} // namespace storage
78+
79+
} // namespace grb
80+
81+
#endif // _H_GRB_STORAGE

0 commit comments

Comments
 (0)