- edited description
Implementing panel-based matrix class
I am working on a proof-of-concept implementation of panel-based matrices using Blaze (see https://bitbucket.org/blaze-lib/blaze/issues/181/making-blaze-even-faster#comment-54174699). As suggested by @Klaus Iglberger , I create new matrix classesStaticPanelMatrix
and DynamicPanelMatrix
, which both derive from a common base PanelMatrix
.
As I am not fully familiar with the implementation details of Blaze, I created this issue to ask questions. Here are my questions so far:
- I am not sure whether
PanelMatrix
should derive fromMatrix
or fromDenseMatrix
. On the one hand,PanelMatrix
is a matrix with dense storage, and all functions that are implemented forDenseMatrix
in terms of element access operators should work the same way on aPanelMatrix
. Re-implementing them forPanelMatrix
would be too much work. On the other hand,DenseMatrix
exposes the pointer to its data via thedata
() function, and the data layout ofPanelMatrix
is different from the one ofStaticMatrix
andDynamicMatrix
. Functions that directly access matrix data will not work onPanelMatrix
. For example, the BLAS functions acceptDenseMatrix
arguments, but obviously they will not work as intended on panel matrices. I wonder if similar problems can occur in other places (i.e. with iterators, with the use of SIMD operations likeload()
andstore()
in the expression classes, with vectorized kernels etc.).
Comments (8)
-
reporter -
reporter - edited description
-
Hi Misha!
The fact that you want to implement two different matrix classes (
StaticPanelMatrix
andDynamicPanelMatrix
) suggest that you don’t want to implement a matrix type, but an adaptor. Please take a look atLowerMatrix
to get an impression on the implementation of adaptors.You are correct, you’ll have to overload all operations, that require data access (via
data()
or SIMD functions) since the behavior of the interface is different. Note that this includes all expressions (addition, subtraction, multiplication, reduction, inversion, …).Best regards,
Klaus!
-
reporter Q2. As a start, I copied the relevant parts of the
StaticMatrix
implementation to the newStaticPanelMatrix
class. There are specializations of trait classes s.a.AddTraitEval2
,SubTraitEval2
etc. inmath/dense/StaticMatrix.h
. As I understand, they define the resulting type of different matrix operations depending on the type of arguments. It looks somewhat like the following:template< typename T1, typename T2 > struct AddTraitEval2< T1, T2 , EnableIf_t< IsMatrix_v<T1> && IsMatrix_v<T2> && ( Size_v<T1,0UL> != DefaultSize_v || Size_v<T2,0UL> != DefaultSize_v ) && ( Size_v<T1,1UL> != DefaultSize_v || Size_v<T2,1UL> != DefaultSize_v ) > > { // ... using Type = StaticMatrix< AddTrait_t<ET1,ET2>, M, N, SO >; };
As far as I understand, I need to define the same kind of specializations for
StaticPanelMatrix
. However, ifStaticPanelMatrix
is derived fromMatrix
and a specialization ofSize<>
forStaticPanelMatrix
is defined properly, theAddTraitEval2
` above will be enabled for bothStaticMatrix
andStaticPanelMatrix
, leading to compiler error. I don’t see how I can specializeAddTraitEval2
forStaticPanelMatrix
without changing the code above. I also don’t fully understand why the part of theEnableIf_t<…>
expression looks like( Size_v<T1,0UL> != DefaultSize_v || Size_v<T2,0UL> != DefaultSize_v ) && ( Size_v<T1,1UL> != DefaultSize_v || Size_v<T2,1UL> != DefaultSize_v )
and not
IsStatic_v<T1> && IsStatic_v<T2>
?
-
reporter Hello Klaus,
Regarding your comments on Q1. I have looked at the
LowerMatrix
code. Do I understand you correctly, that you suggest implementing aPanelMatrix
adapter, which would adapt eitherStaticMatrix
orDynamicMatrix
? Would such adaptor inherit fromDenseMatrix
or something else?As far as I can see, I will need to re-implement pretty much the same set of operations for an adaptor as for a matrix class. What is the advantage of the adaptor approach?
Best regards,
Misha
-
Hi Misha!
Q1) As you can see in
<blaze/math/adaptors/lowermatrix/Dense.h>
and<blaze/math/adaptors/lowermatrix/Sparse.h>
it would be possible that a panel matrix is dense or sparse. For your purposes you should useDenseMatrix
. The adaptor approach would build on the already existing data containers. From my current point of view a panel matrix would primarily store the elements in a different order than a regular matrix, but would require the same underlying memory (an array). Thus it appears like the adaptor approach can save you time an effort as you can build on the already existing matrix classes. An adaptor would allow you to focus on the special requirements.Q2) Initially you would not have to worry about any trait specialization. The existing specializations will also work for any new matrix type. Thus I would recommend to focus on the more general problems first before dealing with the smaller details.
I expect that this endeavour will create a large amount of code and changes. For that reason I recommend that you consider to set up a Blaze project (see the list of projects on the main page). This would give you a lot of benefits, most importantly a bigger visibility. In this setting you would stay in control of the development and could try many different ways of implementation. You would be free to implement anything you want and you could introduce any changes.
Best regards,
Klaus!
-
reporter Hello Klaus!
Thank you for your suggestions. It indeed looks more like a separate project. I am not sure how far it will go, but at the moment the idea of combining the performance advantages given by the panel format with template-based implementation looks promising to me.
-
reporter - changed status to on hold
- Log in to comment