Intrepid2
Intrepid2_PAMatrix.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Intrepid2 Package
4//
5// Copyright 2007 NTESS and the Intrepid2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
14
15#ifndef __INTREPID2_PAMATRIX_HPP__
16#define __INTREPID2_PAMATRIX_HPP__
17
18#include "Intrepid2_ConfigDefs.hpp"
19
20#include "Intrepid2_Types.hpp"
21
22#include "Intrepid2_Basis.hpp"
23#include "Intrepid2_Data.hpp"
26
27#include "Kokkos_Core.hpp"
28
29#include <map>
30#include <tuple>
31#include <vector>
32
33namespace Intrepid2 {
34
71
80 template<typename DeviceType = Kokkos::DefaultExecutionSpace::device_type,
81 typename Scalar = double>
82 class PAMatrix {
83 public:
84 using View1D = Kokkos::View<Scalar*,DeviceType>;
85 using BasisPtrType = BasisPtr<DeviceType,Scalar,Scalar>;
86
87 struct OpSpec {
88 View1D opView;
89 int M;
90 int N;
91 };
93 int C;
94 int P;
95 int a0;
96 int b0;
97 int aSpan;
98 int bSpan;
99
100 bool operator<(const PointDataSpec &otherSpec) const {
101 return std::tie(C, P, a0, b0, aSpan, bSpan) < std::tie(otherSpec.C, otherSpec.P, otherSpec.a0, otherSpec.b0, otherSpec.aSpan, otherSpec.bSpan);
102 }
103
104 bool operator==(const PointDataSpec &otherSpec) const {
105 return std::tie(C, P, a0, b0, aSpan, bSpan) == std::tie(otherSpec.C, otherSpec.P, otherSpec.a0, otherSpec.b0, otherSpec.aSpan, otherSpec.bSpan);
106 }
107 };
108
109 using ComponentSequence = std::tuple<std::vector<OpSpec>, PointDataSpec, std::vector<OpSpec>, int, int, int, int>;
110
129 const TransformedBasisValues<Scalar,DeviceType> basisValuesRight,
130 const ScalarView<Orientation,DeviceType> orientations = ScalarView<Orientation,DeviceType>(),
131 const BasisPtrType basisLeft = Teuchos::null,
132 const BasisPtrType basisRight = Teuchos::null);
133
146 const ScalarView<Orientation,DeviceType> orientations,
147 const BasisPtrType basis = Teuchos::null);
148
150 PAMatrix() = default;
151
156
161
164 Kokkos::View<Scalar*,DeviceType> allocateWorkspace(const ordinal_type &worksetSize) const;
165
168 Kokkos::View<Scalar*,DeviceType> allocateWorkspace(const ordinal_type &worksetSize, const ordinal_type &n) const;
169
180 template <typename OutputViewType, typename InputViewType>
181 void apply(const OutputViewType &outputVector,
182 const InputViewType & inputVector,
183 const Kokkos::View<Scalar*,DeviceType> &workspace,
184 const bool sumInto = false,
185 const int worksetSizeIn = 0) const;
186
199 void assemble(Data<Scalar,DeviceType> &integrals,
201
205 void extractDiagonal(const Data<Scalar,DeviceType> &diagonal) const;
206
208 const TransformedBasisValues<Scalar,DeviceType> & leftBasisValues() const { return _basisValuesLeft; }
209
211 const TransformedBasisValues<Scalar,DeviceType> & rightBasisValues() const { return _basisValuesRight; }
212
214 const TensorData<Scalar,DeviceType> & cellMeasures() const { return _cellMeasures; }
215
217 const ScalarView<Orientation,DeviceType> & orientations() const { return _orientations; }
218
220 const BasisPtrType & leftBasis() const { return _basisLeft; }
221
223 const BasisPtrType & rightBasis() const { return _basisRight; }
224
226 bool hasOrdinalFilter() const { return (leftOrdinalFilter_.extent_int(0) > 0) || (rightOrdinalFilter_.extent_int(0) > 0); }
227
229 bool hasNontrivialOrientations() const { return _hasNontrivialOrientations; }
230
247
248 static void setGEMMStatisticsEnabled(const bool enabled);
249
251 static bool gemmStatisticsEnabled();
252
254 static double gemmFlopCount();
255
257 static double gemmTimeSeconds();
258
260 static double gemmThroughputGFlops(const double baseFlopCount = 0, const double baseTimeSeconds = 0);
262
267 bool supportsDirectAssembly() const;
268
274 void init(const TransformedBasisValues<Scalar,DeviceType> basisValuesLeft,
276 const TransformedBasisValues<Scalar,DeviceType> basisValuesRight,
277 const ScalarView<Orientation,DeviceType> orientations);
278
280 void assembleUnoriented(Data<Scalar,DeviceType> &integrals, const PAMatrixAssemblyOptions &options) const;
281
283 void assembleDirect(Data<Scalar,DeviceType> &integrals, const PAMatrixAssemblyOptions &options) const;
284
286 void assembleUnitColumns(Data<Scalar,DeviceType> &integrals, const PAMatrixAssemblyOptions &options) const;
287
289 void assembleByApply(Data<Scalar,DeviceType> &integrals, const PAMatrixAssemblyOptions &options) const;
290
292 void orientAssembledMatrix(Data<Scalar,DeviceType> &integrals) const;
293
295 size_t applyWorkspacePerCell() const;
296
301 template <typename OutputViewType, typename InputViewType>
302 void applyUnorientedWorkset(const OutputViewType &output, const ordinal_type outputCellOffset,
303 const InputViewType &input, const ordinal_type inputCellOffset,
304 const ordinal_type startCell, const ordinal_type Cw, const ordinal_type N,
305 Scalar *workspace1, Scalar *workspace2) const;
307
308 private:
309 Data<Scalar,DeviceType> _composedWeightedTransform; // (C,P[,D1[,D2]]), used for general case
310 std::map<PointDataSpec,View1D> _pointDataCache; // copies of appropriate slices of _composedWeightedTransform
311 TensorData<Scalar,DeviceType> _cellMeasures; // (C,P)
312 TransformedBasisValues<Scalar,DeviceType> _basisValuesLeft, _basisValuesRight;
313 ScalarView<Orientation,DeviceType> _orientations;
314 BasisPtrType _basisLeft, _basisRight;
315 bool _hasNontrivialOrientations = false;
316 size_t maxIntermediateSize_ = 0;
317
318 std::vector<ComponentSequence> componentIntegralsToSum_;
319 std::vector<std::pair<int,int>> componentIntegralGroups_; // for each entry in componentIntegralsToSum_: (left group, right group), where a group is a (family, component) pair; used by assemble()
320 // Ordinal filters (e.g., for Serendipity bases): matrix row/column i corresponds to full tensor-basis field
321 // ordinal filter(i). Empty when there is no filter. componentIntegralsToSum_ refers to full tensor-basis ordinals.
322 // Supported by assemble(); other operations reject filtered PAMatrix objects.
323 Kokkos::View<ordinal_type*,DeviceType> leftOrdinalFilter_, rightOrdinalFilter_;
324 int numUnfilteredFieldsLeft_ = 0, numUnfilteredFieldsRight_ = 0;
325 }; // end PAMatrix class
326
327} // end namespace Intrepid2
328
329// include templated definitions
331
332#endif
Header file for the abstract base class Intrepid2::Basis.
Teuchos::RCP< Basis< DeviceType, OutputType, PointType > > BasisPtr
Basis Pointer.
Defines the Data class, a wrapper around a Kokkos::View that allows data that is constant or repeatin...
Header file for the Intrepid2::Orientation class.
Header file for the Intrepid2::PAMatrix implementations; provides support for matrix partial assembly...
Structure-preserving representation of transformed basis values; reference space values and transform...
Contains definitions of custom data types in Intrepid2.
Wrapper around a Kokkos::View that allows data that is constant or repeating in various logical dimen...
void assembleByApply(Data< Scalar, DeviceType > &integrals, const PAMatrixAssemblyOptions &options) const
assembles by apply() to blocked unit columns
Kokkos::View< Scalar *, DeviceType > allocateWorkspace(const ordinal_type &worksetSize) const
Allocates and returns workspace storage suitable for providing to apply() to a vector with a workset ...
static void setGEMMStatisticsEnabled(const bool enabled)
Enables or disables recording of GEMM statistics (off by default).
void orientAssembledMatrix(Data< Scalar, DeviceType > &integrals) const
applies orientations in place to an assembled (C,F1,F2) matrix
static double gemmFlopCount()
Returns the cumulative estimated floating-point operation count for recorded GEMM calls.
static bool gemmStatisticsEnabled()
Returns true if GEMM statistics are being recorded.
const BasisPtrType & rightBasis() const
The right basis (null if none was provided).
const TransformedBasisValues< Scalar, DeviceType > & leftBasisValues() const
The left basis values (with transform) from which the matrix was constructed.
bool supportsDirectAssembly() const
True if assemble() can use direct sum factorization (or contraction of unit columns) for this matrix'...
const TensorData< Scalar, DeviceType > & cellMeasures() const
The cell measures (quadrature weights times Jacobian determinants) from which the matrix was construc...
void applyUnorientedWorkset(const OutputViewType &output, const ordinal_type outputCellOffset, const InputViewType &input, const ordinal_type inputCellOffset, const ordinal_type startCell, const ordinal_type Cw, const ordinal_type N, Scalar *workspace1, Scalar *workspace2) const
Applies the unoriented matrix to cells [startCell, startCell+Cw), accumulating into output....
const TransformedBasisValues< Scalar, DeviceType > & rightBasisValues() const
The right basis values (with transform) from which the matrix was constructed.
Data< Scalar, DeviceType > allocateMatrixStorage() const
Allocates storage for a fully-assembled matrix.
const ScalarView< Orientation, DeviceType > & orientations() const
The cell orientations (empty if none were provided).
bool hasOrdinalFilter() const
True if the left or right basis values have an ordinal filter (e.g., for Serendipity bases).
void extractDiagonal(const Data< Scalar, DeviceType > &diagonal) const
Extracts the diagonal of the matrix, placing it in diagonal. If the matrix is not square,...
bool hasNontrivialOrientations() const
True if orientations were provided and at least one cell is not aligned to the reference.
const BasisPtrType & leftBasis() const
The left basis (null if none was provided).
PAMatrix()=default
Constructs an empty PAMatrix, which may be assigned to from a constructed one.
size_t applyWorkspacePerCell() const
the workspace size, in entries per cell and vector, required by apply()
void assemble(Data< Scalar, DeviceType > &integrals, const PAMatrixAssemblyOptions &options=PAMatrixAssemblyOptions::defaultsWithEnvironmentOverrides()) const
Fully assembles the matrix, using sum factorization.
void assembleUnitColumns(Data< Scalar, DeviceType > &integrals, const PAMatrixAssemblyOptions &options) const
assembles by contraction of unit columns (requires supportsDirectAssembly())
void apply(const OutputViewType &outputVector, const InputViewType &inputVector, const Kokkos::View< Scalar *, DeviceType > &workspace, const bool sumInto=false, const int worksetSizeIn=0) const
Applies the matrix to inputVector, placing the result in outputVector, without explicit assembly and ...
static double gemmThroughputGFlops(const double baseFlopCount=0, const double baseTimeSeconds=0)
Returns the GEMM throughput in GFlop/s; baseFlopCount and baseTimeSeconds, if provided,...
PAMatrix(const TransformedBasisValues< Scalar, DeviceType > basisValuesLeft, const TensorData< Scalar, DeviceType > cellMeasures, const TransformedBasisValues< Scalar, DeviceType > basisValuesRight, const ScalarView< Orientation, DeviceType > orientations=ScalarView< Orientation, DeviceType >(), const BasisPtrType basisLeft=Teuchos::null, const BasisPtrType basisRight=Teuchos::null)
Constructs a PAMatrix representing the contraction of basisValuesLeft against basisValuesRight contai...
Data< Scalar, DeviceType > allocateDiagonalStorage() const
Allocates and returns a container with shape (C,F), where F=min(F1,F2).
std::tuple< std::vector< OpSpec >, PointDataSpec, std::vector< OpSpec >, int, int, int, int > ComponentSequence
left, pointData, right, left offset, left output span, right offset, right input span
void assembleUnoriented(Data< Scalar, DeviceType > &integrals, const PAMatrixAssemblyOptions &options) const
assembles the matrix for the unoriented bases
static double gemmTimeSeconds()
Returns the cumulative time spent in recorded GEMM calls.
void assembleDirect(Data< Scalar, DeviceType > &integrals, const PAMatrixAssemblyOptions &options) const
assembles by direct sum factorization (requires supportsDirectAssembly())
View-like interface to tensor data; tensor components are stored separately and multiplied together a...
Structure-preserving representation of transformed vector data; reference space values and transforma...
Options for PAMatrix::assemble(). The defaults are appropriate in most cases; the other settings are ...
static PAMatrixAssemblyOptions defaultsWithEnvironmentOverrides()
Returns default options, overridden by any of the following environment variables (for testing and pe...
Algorithm
Algorithm used by assemble().
@ Automatic
direct sum factorization where the structure supports it, column-blocked unit-column contraction othe...
@ ApplyToColumns
apply() to blocked unit columns (the most general path)
@ UnitColumns
column-blocked unit-column contraction where supported, apply() to unit columns otherwise
SparseLastStage
Use of the sparse last stage in the direct path when ordinal filters are present.
@ Automatic
used when fewer than a quarter of the (row, column) pairs of the unfiltered matrix are kept
@ Always
used whenever there is an ordinal filter
double workspaceMB
Workspace budget, in MB, used to choose the workset size for assembly.