Nektar++
Loading...
Searching...
No Matches
PhysLiftProjectBlockOp.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: PhysLiftProjectBlockOp.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Per-block interface of the lift-and-project element operator.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35/**
36 * @file PhysLiftProjectBlockOp.hpp
37 * @brief Per-block interface of the PhysLiftProject element operator, and
38 * the choice of its form for a block.
39 *
40 * @details
41 * A PhysLiftProjectBlockOp computes, for every element of one block,
42 * \f[ u \mathrel{(+)=} s\, B M^{-1} B^{\mathsf T} (f + L g), \f]
43 * with @c f the physical-space inner products of the element (the
44 * pre-\f$B^{\mathsf T}\f$ arrays IProductWRTDerivBase and
45 * IProductWRTPhysTrace write), @c g the element-local trace values and
46 * @c L the trace lift of IProductWRTPhysTrace; see PhysLiftProjectOp.hpp.
47 * Besides the block states and the factory entry the class carries the
48 * scale and append settings, ApplyLift(), which applies the block with the
49 * lift of its block of trace values, and master's four block operators in
50 * sequence for the ElmtInvMass form (CreateChain(), ApplyElmtInvMass()),
51 * which every implementation takes there.
52 *
53 * detail::PhysLiftProjectFormOf() is the one place the form of a block is
54 * decided, shared by the whole-field operator (which hands the per-element
55 * inverse mass matrices only to the blocks that read them) and the
56 * implementations.
57 */
58
59#pragma once
60
66
67#include <memory>
68#include <vector>
69
71{
72
73namespace detail
74{
75
76/// How a block applies \f$B M^{-1} B^{\mathsf T}\f$.
78{
79 /// As many modes as quadrature points: B is square, so
80 /// \f$B M^{-1} B^{\mathsf T} = (W J)^{-1}\f$, a pointwise scale by the
81 /// quadrature weight and the Jacobian, affine or deformed.
83 /// Affine elements: the basis transpose, the standard inverse mass over
84 /// the element's Jacobian and the backward transform.
86 /// Deformed elements: IProductWRTPhysTrace, IProductWRTBase,
87 /// MultiplyByElmtInvMass with each element's own inverse mass, and
88 /// BwdTrans, in sequence.
90};
91
92/// Which of the Device fused kernels of the StdInvMass form a shared-memory
93/// size is for.
95{
96 /// The lift and the form with a diagonal standard inverse mass in one
97 /// launch (PhysLiftProjectKernelLauncher()).
98 Fused,
99 /// The lift and the basis transpose, before the dense product
100 /// (PhysLiftProjectLiftBasisTransposeKernelLauncher()).
102 /// The scale and the backward transform, after it
103 /// (PhysLiftProjectScaleBwdTransKernelLauncher()).
105};
106
107/**
108 * @brief The form the block whose representative expansion is @p exp takes.
109 * The square test is on the total counts: equal per-direction counts do
110 * not make B square on a collapsed-coordinate shape, whose mode count is a
111 * fraction of the tensor product.
112 */
115{
116 if (exp->GetNcoeffs() == exp->GetTotPoints())
117 {
119 }
120 if (exp->GetGeomFactors()->GetGtype() == SpatialDomains::eDeformed)
121 {
123 }
125}
126
127/// The most points per element the Device SumFacTOP implementation applies
128/// the StdInvMass form of a collapsed shape through the dense projector at
129/// (PhysLiftProjectDenseTail()): 125, order 4 on the default rules (5^3
130/// points), the highest order it was measured at, where it is still 1.6 to
131/// 1.8 times faster than the sum-factorised kernel on GH200 and MI210. It is
132/// not tied to the block size: order 5 has 6^3 = 216 points, so any cap from
133/// 125 to 215 admits the same elements. The projector's cost per element
134/// grows as nqTot^2, against about nqTot^(4/3) for sum-factorisation, so the
135/// crossover lies above order 4; the cap moves there once it is measured.
136static constexpr unsigned int physLiftProjectDenseTailMaxPoints = 125u;
137
138/**
139 * @brief Whether the Device SumFacTOP implementation applies the block whose
140 * representative expansion is @p exp through the dense projector: the
141 * StdInvMass form of a tetrahedron, prism or pyramid of at most
142 * #physLiftProjectDenseTailMaxPoints points whose traces have the volume's
143 * points in one in-trace direction at least. On an affine element
144 * \f$B M^{-1} B^{\mathsf T} = J^{-1} P\f$ with
145 * \f$P = B M_{\mathrm{std}}^{-1} B^{\mathsf T}\f$, one nqTot x nqTot matrix
146 * per block, so the trace is lifted directly onto every point with the
147 * division by the Jacobian, and one batched product applies @em P to every
148 * element, in place of the basis transpose, the inverse mass and the
149 * backward transform.
150 */
153{
154 const auto shape = exp->DetShapeType();
156 !(shape == LibUtilities::Tet || shape == LibUtilities::Prism ||
157 shape == LibUtilities::Pyr) ||
158 exp->IsNodalNonTensorialExp() ||
159 static_cast<unsigned int>(exp->GetTotPoints()) >
161 {
162 return false;
163 }
164 const auto pointsKeys = exp->GetPointsKeys();
165 for (int tr = 0; tr < exp->GetNtraces(); ++tr)
166 {
167 unsigned int collocated = 0;
168 for (unsigned int d = 0; d < 2; ++d)
169 {
170 const auto traceKey = exp->GetTraceBasisKey(tr, d).GetPointsKey();
171 collocated +=
172 pointsKeys[exp->GetGeom()->GetDir(tr, d)] == traceKey ? 1 : 0;
173 }
174 if (collocated == 0)
175 {
176 return false;
177 }
178 }
179 return true;
180}
181
182} // namespace detail
183
184/**
185 * @brief Base class of the per-block lift-and-project operators: physical
186 * space in, with the trace values through ApplyLift(), physical space out.
187 *
188 * @tparam TData Floating-point type of the field data.
189 */
190template <typename TData>
192 : public ElmtBlockOp<FieldState::Phys, FieldState::Phys, TData>
193{
194public:
195 /// Create a block operator through the block-operator factory; see
196 /// ElmtBlockOp::Create().
197 static std::shared_ptr<PhysLiftProjectBlockOp<TData>> Create(
198 const unsigned int block_idx,
201 const std::string &execStr, const std::string &implStr)
202 {
204 template Create<PhysLiftProjectBlockOp>(
205 block_idx, exp, dataWarehouse, execStr, implStr);
206 }
207
208 /// Block-operator base name; the factory key appends the execution
209 /// space and the implementation.
210 static inline const std::string name = "BlockPhysLiftProject";
211
212 /// The factor the result is scaled by.
213 void SetScale(const TData &scale)
214 {
215 m_scale = scale;
216 }
217
218 /// Accumulate onto the output instead of overwriting it.
219 void SetAppend(const bool &append)
220 {
221 m_append = append;
222 }
223
224 /// Apply the block's operator to @p inblock with the lift of the block
225 /// of trace values @p trace onto it; Apply() leaves the lift out.
233
234protected:
235 /// The implementation's ApplyLift().
236 virtual void v_ApplyLift(
240
241 TData m_scale = 1.0;
242 bool m_append = false;
243 /// The block of trace values lifted onto the inner products, set by
244 /// v_ApplyLift() for that application alone and null otherwise.
246 /// The ElmtInvMass form (CreateChain()): master's four block operators
247 /// and the scratch of the inner products with the trace lifted onto
248 /// them and of the coefficients before and after the inverse mass,
249 /// sized on the first ApplyElmtInvMass().
250 std::shared_ptr<IProductWRTPhysTraceBlockOp<TData>> m_chainLift;
251 std::shared_ptr<IProductWRTBaseBlockOp<TData>> m_chainBasisTranspose;
252 std::shared_ptr<MultiplyByElmtInvMassBlockOp<TData>> m_chainInvMass;
253 std::shared_ptr<BwdTransBlockOp<TData>> m_chainBwdTrans;
254 std::unique_ptr<LibUtilities::BlockAccessor<TData, FieldState::Phys>>
256 std::unique_ptr<LibUtilities::BlockAccessor<TData, FieldState::Coeff>>
258
260 const unsigned int block_idx,
263 : ElmtBlockOp<FieldState::Phys, FieldState::Phys, TData>(block_idx, exp,
264 dataWarehouse)
265 {
266 }
267
268 ~PhysLiftProjectBlockOp() override = default;
269
270 /**
271 * @brief Create the block operators of the ElmtInvMass form in
272 * execution space @p execStr: IProductWRTPhysTrace appending,
273 * IProductWRTBase without the metric, MultiplyByElmtInvMass and
274 * BwdTrans, the first two and the last of implementation @p implStr.
275 */
276 void CreateChain(const std::string &execStr, const std::string &implStr)
277 {
279 this->m_block_idx, this->m_exp, this->m_dataWarehouse, execStr,
280 implStr);
281 m_chainLift->SetAppend(true);
283 this->m_block_idx, this->m_exp, this->m_dataWarehouse, execStr,
284 implStr);
285 m_chainBasisTranspose->SetIntegration(false);
287 this->m_block_idx, this->m_exp, this->m_dataWarehouse, execStr,
290 this->m_block_idx, this->m_exp, this->m_dataWarehouse, execStr,
291 implStr);
292 }
293
294 /**
295 * @brief The ElmtInvMass form, master's chain: @p in copied into the
296 * scratch, the trace lifted onto it, then the basis transpose with the
297 * scale, each element's own inverse mass and the backward transform into
298 * @p out, the copy on stream @p streamID. The scratch is sized after
299 * @p in; the scale and append settings are set here, where they are used.
300 */
301 template <typename MemSpace>
305 const unsigned int streamID = 0)
306 {
307 const unsigned int ncomp = in.GetNumComponents();
308 const unsigned int nhomo = in.GetNumHomoModes();
309 if (!m_chainVol || m_chainVol->GetNumComponents() != ncomp ||
310 m_chainVol->GetNumHomoModes() != nhomo)
311 {
312 const size_t nelmtPad = in.GetNumElementsWithPadding();
313 const unsigned int nmTot = this->m_exp->GetNcoeffs();
314 m_chainVol = std::make_unique<
316 in.GetNumElements(), nelmtPad, in.GetNumData(), 1,
317 LibUtilities::MemoryRegion<TData>(in.CompSize() * ncomp *
318 nhomo),
319 nullptr, ncomp, nhomo);
320 m_chainCoef = std::make_unique<
322 in.GetNumElements(), nelmtPad, nmTot, 1,
323 LibUtilities::MemoryRegion<TData>(nelmtPad * nmTot * ncomp *
324 nhomo),
325 nullptr, ncomp, nhomo);
326 m_chainCoef2 = std::make_unique<
328 in.GetNumElements(), nelmtPad, nmTot, 1,
329 LibUtilities::MemoryRegion<TData>(nelmtPad * nmTot * ncomp *
330 nhomo),
331 nullptr, ncomp, nhomo);
332 }
333 m_chainVol->template Copy<MemSpace>(in, streamID);
334 if (m_trace)
335 {
336 m_chainLift->Apply(*m_trace, *m_chainVol);
337 }
341 m_chainBwdTrans->SetAppend(m_append);
342 m_chainBwdTrans->Apply(*m_chainCoef2, out);
343 }
344};
345
346} // namespace Nektar::MultiRegions
Per-block interface class of the backward-transform operator.
Block-level base class, implementation-strategy tags and device launch helpers shared by every elemen...
Per-block interface of the IProductWRTBase element operator.
Per-block interface class of the discontinuous Galerkin lifting operator IProductWRTPhysTrace.
Per-block interface of the MultiplyByElmtInvMass element operator.
Get the BlockAttributes for a given field state from an ExpList. This method basically captures ident...
Definition Block.hpp:144
A MemoryRegion represents a memory region.
unsigned int m_block_idx
Index of the block within the expansion list's Collections.
LocalRegions::ExpansionSharedPtr m_exp
Representative expansion of the block (its first element).
LibUtilities::NekDataWarehouseSharedPtr m_dataWarehouse
Data warehouse shared with the other operators on the expansion list.
static std::shared_ptr< BwdTransBlockOp< TData > > Create(const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse, const std::string &execStr, const std::string &implStr)
Create one backward-transform block operator through the block-operator factory, under the key "Block...
Base class of the per-family block operators: applies one element operation to every element of one b...
static std::shared_ptr< IProductWRTBaseBlockOp< TData > > Create(const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse, const std::string &execStr, const std::string &implStr)
Create one IProductWRTBase block operator through the block-operator factory.
static std::shared_ptr< IProductWRTPhysTraceBlockOp< TData > > Create(const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse, const std::string &execStr, const std::string &implStr)
Create one trace inner-product block operator through the block-operator factory, under the key "Bloc...
static std::shared_ptr< MultiplyByElmtInvMassBlockOp< TData > > Create(const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse, const std::string &execStr, const std::string &implStr)
Create one inverse mass block operator through the block-operator factory.
Base class of the per-block lift-and-project operators: physical space in, with the trace values thro...
std::unique_ptr< LibUtilities::BlockAccessor< TData, FieldState::Coeff > > m_chainCoef2
void SetScale(const TData &scale)
The factor the result is scaled by.
void SetAppend(const bool &append)
Accumulate onto the output instead of overwriting it.
static std::shared_ptr< PhysLiftProjectBlockOp< TData > > Create(const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse, const std::string &execStr, const std::string &implStr)
Create a block operator through the block-operator factory; see ElmtBlockOp::Create().
void ApplyLift(LibUtilities::BlockAccessor< TData, FieldState::Phys > &inblock, LibUtilities::BlockAccessor< TData, FieldState::Phys > &trace, LibUtilities::BlockAccessor< TData, FieldState::Phys > &outblock)
Apply the block's operator to inblock with the lift of the block of trace values trace onto it; Apply...
void ApplyElmtInvMass(LibUtilities::BlockAccessor< TData, FieldState::Phys > &in, LibUtilities::BlockAccessor< TData, FieldState::Phys > &out, const unsigned int streamID=0)
The ElmtInvMass form, master's chain: in copied into the scratch, the trace lifted onto it,...
PhysLiftProjectBlockOp(const unsigned int block_idx, const LocalRegions::ExpansionSharedPtr &exp, LibUtilities::NekDataWarehouseSharedPtr dataWarehouse)
void CreateChain(const std::string &execStr, const std::string &implStr)
Create the block operators of the ElmtInvMass form in execution space execStr: IProductWRTPhysTrace a...
std::shared_ptr< BwdTransBlockOp< TData > > m_chainBwdTrans
std::unique_ptr< LibUtilities::BlockAccessor< TData, FieldState::Coeff > > m_chainCoef
std::unique_ptr< LibUtilities::BlockAccessor< TData, FieldState::Phys > > m_chainVol
std::shared_ptr< IProductWRTPhysTraceBlockOp< TData > > m_chainLift
The ElmtInvMass form (CreateChain()): master's four block operators and the scratch of the inner prod...
static const std::string name
Block-operator base name; the factory key appends the execution space and the implementation.
virtual void v_ApplyLift(LibUtilities::BlockAccessor< TData, FieldState::Phys > &inblock, LibUtilities::BlockAccessor< TData, FieldState::Phys > &trace, LibUtilities::BlockAccessor< TData, FieldState::Phys > &outblock)=0
The implementation's ApplyLift().
std::shared_ptr< MultiplyByElmtInvMassBlockOp< TData > > m_chainInvMass
LibUtilities::BlockAccessor< TData, FieldState::Phys > * m_trace
The block of trace values lifted onto the inner products, set by v_ApplyLift() for that application a...
std::shared_ptr< IProductWRTBaseBlockOp< TData > > m_chainBasisTranspose
std::shared_ptr< NekDataWarehouse > NekDataWarehouseSharedPtr
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition Expansion.h:66
static constexpr unsigned int physLiftProjectDenseTailMaxPoints
The most points per element the Device SumFacTOP implementation applies the StdInvMass form of a coll...
bool PhysLiftProjectDenseTail(const LocalRegions::ExpansionSharedPtr &exp)
Whether the Device SumFacTOP implementation applies the block whose representative expansion is exp t...
@ StdInvMass
Affine elements: the basis transpose, the standard inverse mass over the element's Jacobian and the b...
@ Pointwise
As many modes as quadrature points: B is square, so , a pointwise scale by the quadrature weight and ...
@ ElmtInvMass
Deformed elements: IProductWRTPhysTrace, IProductWRTBase, MultiplyByElmtInvMass with each element's o...
PhysLiftProjectForm PhysLiftProjectFormOf(const LocalRegions::ExpansionSharedPtr &exp)
The form the block whose representative expansion is exp takes. The square test is on the total count...
PhysLiftProjectKernel
Which of the Device fused kernels of the StdInvMass form a shared-memory size is for.
@ ScaleBwdTrans
The scale and the backward transform, after it (PhysLiftProjectScaleBwdTransKernelLauncher()).
@ Fused
The lift and the form with a diagonal standard inverse mass in one launch (PhysLiftProjectKernelLaunc...
@ LiftBasisTranspose
The lift and the basis transpose, before the dense product (PhysLiftProjectLiftBasisTransposeKernelLa...
@ eDeformed
Geometry is curved or has non-constant factors.
FieldState
Possible states for Field data.
static const std::string name