Skip to content

Vector pa kernels #4861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 46 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
68ae66c
vecmass PA setup
camierjs May 9, 2025
93dbe14
PAVectorMassApply3D with Eval3d
camierjs May 9, 2025
3949dec
PAVectorMassApply2D with Eval2d
camierjs May 10, 2025
d2e2834
VectorMassIntegrator PA specializations
camierjs May 10, 2025
b08d12b
VectorMassIntegrator 2D with MatrixFunctionCoefficients
camierjs May 12, 2025
0892f19
VectorMassIntegrator 3D MatrixFunctionCoefficient
camierjs May 12, 2025
1c04593
VectorMassIntegrator cleanup
camierjs May 12, 2025
72d28e0
VectorDiffusionIntegrator AssemblePA vector coefficients
camierjs May 12, 2025
ba4befc
VectorDiffusionIntegrator wip Matrix coefficient
camierjs May 12, 2025
c707a4d
jj=ii
camierjs May 12, 2025
3086dae
WIP PAVectorDiffusionApply2D mcoeff
camierjs May 13, 2025
5827732
WIP 0 1
camierjs May 13, 2025
7f7e5f6
All c, d
camierjs May 13, 2025
031cd67
VectorDiffusionIntegrator 2D mcoeff
camierjs May 13, 2025
2a3c1c5
VectorDiffusionIntegrator 2D cleanup
camierjs May 13, 2025
3c2f98b
test_vector_pa_integrator all tests passed
camierjs May 13, 2025
3fb13a3
WIP 3D vector diffusion with sym mcoeff
camierjs May 13, 2025
d27fa84
Pre AssemblePA 2D vector diffusion
camierjs May 13, 2025
580dc6f
Simplify VectorDiffusionIntegrator::AssemblePA
camierjs May 13, 2025
6a04555
SmemPAVectorDiffusionApply2D
camierjs May 13, 2025
795a121
SmemPAVectorDiffusionApply3D
camierjs May 13, 2025
686feff
VectorDiffusionAddMultPA registered
camierjs May 13, 2025
51c28ad
Fix grad ii vs. jj matrix coeff
camierjs May 14, 2025
eb68434
Simplify regs_t kernels types on CPU
May 15, 2025
e41c782
Use explicit type names for registers
May 15, 2025
62dd1ae
Cleanup
May 16, 2025
ea25a9b
Remove PAVectorDiffusionApply kernels, fuse SDIM != DIM diffusion vec…
camierjs May 17, 2025
3b88332
Merge branch 'master' into vector-pa-kernels
camierjs May 17, 2025
6bb5f8a
Change pa data layout
camierjs May 18, 2025
190c4a0
WIP SmemPAVectorMassApply2D layouts
camierjs May 18, 2025
2ead488
Pre SmemPAVectorMassApply2D cleanup
camierjs May 18, 2025
82c2e01
Cleanup
camierjs May 18, 2025
7a37cc2
MSVC header guards
camierjs May 18, 2025
c50905e
MAX_T1D for WIN32
camierjs May 18, 2025
f3443f9
MSVC fix
camierjs May 18, 2025
b3e9ddd
WIN32 cmath
camierjs May 18, 2025
f9972a5
Simplify back SmemPAVectorMassApply2D
camierjs May 19, 2025
716c201
GPU vector kernels fix
camierjs May 19, 2025
0742475
test_pa_kernels tags
camierjs May 19, 2025
189c201
Fix shadowing
camierjs May 19, 2025
7dba460
Move kernel methods to fem/kernels.hpp
camierjs May 19, 2025
acbe258
CMake remove header
camierjs May 19, 2025
6145305
Merge branch 'master' into vector-pa-kernels
camierjs May 28, 2025
2e70688
Merge branch 'master' into vector-pa-kernels
camierjs Jun 13, 2025
ba70885
Merge branch 'master' into vector-pa-kernels
camierjs Jun 16, 2025
319b870
Use future namespace for tensor
camierjs Jun 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP SmemPAVectorMassApply2D layouts
  • Loading branch information
camierjs committed May 18, 2025
commit 190c4a091d48bf594bb6516d87a579c199711151
51 changes: 40 additions & 11 deletions fem/integ/bilininteg_vecmass_pa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
#include "../../general/forall.hpp"
#include "../../linalg/dtensor.hpp"
#include "../../linalg/kernels.hpp"
#include "../../linalg/ttensor.hpp"
#include "../../linalg/vector.hpp"
#include "../bilininteg.hpp"

#include "bilininteg_kernels.hpp"
using mfem::kernels::internal::SetMaxOf;

#if __has_include("general/nvtx.hpp") && !defined(MSVC)
#undef NVTX_COLOR
#define NVTX_COLOR ::nvtx::kGold
#include "general/nvtx.hpp"
#else
#define dbg(...)
#endif

namespace mfem
{

Expand All @@ -43,6 +52,8 @@ void SmemPAVectorMassApply2D(const int NE,
const int D1D = T_D1D ? T_D1D : d1d;
const int Q1D = T_Q1D ? T_Q1D : q1d;

dbg("D1D:{} Q1D:{} NE:{} coeff_vdim:{}", D1D, Q1D, NE, coeff_vdim);

const bool const_coeff = coeff_vdim == 1;
const bool vector_coeff = coeff_vdim == DIM;
const bool matrix_coeff = coeff_vdim == DIM*DIM;
Expand All @@ -55,6 +66,7 @@ void SmemPAVectorMassApply2D(const int NE,
{
constexpr int MD1 = T_D1D > 0 ? SetMaxOf(T_D1D) : DofQuadLimits::MAX_T1D;
constexpr int MQ1 = T_Q1D > 0 ? SetMaxOf(T_Q1D) : DofQuadLimits::MAX_T1D;
dbg("MQ1:{} VDIM:{}", MQ1, VDIM);

MFEM_SHARED real_t sB[MD1][MQ1], smem[MQ1][MQ1];
kernels::internal::vd_regs2d_t<VDIM, 1, MQ1> r0, r1;
Expand All @@ -68,34 +80,51 @@ void SmemPAVectorMassApply2D(const int NE,
{
const real_t Qx = r1[0][0][qy][qx];
const real_t Qy = r1[1][0][qy][qx];
real_t u[2] = { Qx, Qy }, v[2];
const real_t u[2] = { Qx, Qy };
real_t v[2];

const real_t D0 = D(0, qx, qy, e);

if (const_coeff)
{
r0[0][0][qy][qx] = D0 * Qx;
r0[1][0][qy][qx] = D0 * Qy;
real_t *y0 = &r0(0,0,qy,qx);
using layout_t = StridedLayout1D<2,1>;
using r0_layout_t = StridedLayout1D<2,MQ1*MQ1>;

// TAssignHD<AssignOp::Set>(layout_t{}, v, layout_t{}, u);
// TAssignHD<AssignOp::Mult>(layout_t{}, v, D0);
#if 1
// TAssignHD<AssignOp::Set>(r0_layout_t {}, y0, layout_t {}, v);
TAssignHD<AssignOp::Set>(r0_layout_t{}, y0, layout_t{}, u);
TAssignHD<AssignOp::Mult>(r0_layout_t {}, y0, D0);
#else
r0[0][0][qy][qx] = v[0];
r0[1][0][qy][qx] = v[1];
#endif
}
if (vector_coeff)
{
using layout_t = StridedLayout1D<2,1>;
TAssignHD<AssignOp::Set>( layout_t {}, v, layout_t {}, u);
TAssignHD<AssignOp::Mult>(layout_t{}, v, layout_t{}, &D(0, qx, qy, e));
#if 0
using r0_lyt = OffsetStridedLayout1D<2,1>;
real_t *y0 = &(r0[0][0][qy][qx]);
TAssignHD<AssignOp::Set>(r0_lyt{MQ1*MQ1}, y0, layout_t {}, v);
#elif 0
r0[0][0][qy][qx] = v[0];
r0[1][0][qy][qx] = v[1];
#else
const real_t D1 = D(1, qx, qy, e);
r0[0][0][qy][qx] = D0 * Qx;
r0[1][0][qy][qx] = D1 * Qy;
#endif
}
if (matrix_coeff)
{
#if 1
kernels::MultTranspose(2, 2, &D(0, qx, qy, e), u, v);
r0[0][0][qy][qx] = v[0];
r0[1][0][qy][qx] = v[1];
#else
const real_t D1 = D(1, qx, qy, e);
const real_t D2 = D(2, qx, qy, e);
const real_t D3 = D(3, qx, qy, e);
r0[0][0][qy][qx] = D0 * Qx + D1 * Qy;
r0[1][0][qy][qx] = D2 * Qx + D3 * Qy;
#endif
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions linalg/ttensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ struct TensorOps<1> // rank = 1
mfem::Assign<Op>(A_data[A_layout.ind(i1)], B_data[B_layout.ind(i1)]);
}
}

// Assign: A {=,+=,*=} B
template <AssignOp::Type Op,
typename A_layout_t, typename A_data_t,
typename B_layout_t, typename B_data_t>
MFEM_HOST_DEVICE
static void AssignHD(const A_layout_t &A_layout, A_data_t &A_data,
const B_layout_t &B_layout, const B_data_t &B_data)
{
MFEM_STATIC_ASSERT(A_layout_t::rank == 1 && B_layout_t::rank == 1,
"invalid ranks");
MFEM_STATIC_ASSERT(A_layout_t::dim_1 == B_layout_t::dim_1,
"invalid dimensions");
for (int i1 = 0; i1 < A_layout_t::dim_1; i1++)
{
mfem::AssignHD<Op>(A_data[A_layout.ind(i1)], B_data[B_layout.ind(i1)]);
}
}
};

template <>
Expand Down Expand Up @@ -281,6 +299,19 @@ inline void TAssign(const A_layout_t &A_layout, A_data_t &A_data,
template Assign<Op>(A_layout, A_data, B_layout, B_data);
}

// Tensor assign function: A {=,+=,*=} B that allows different input and output
// layouts. With suitable layouts this function can be used to permute
// (transpose) tensors, extract sub-tensors, etc.
template <AssignOp::Type Op,
typename A_layout_t, typename A_data_t,
typename B_layout_t, typename B_data_t>
MFEM_HOST_DEVICE
inline void TAssignHD(const A_layout_t &A_layout, A_data_t &A_data,
const B_layout_t &B_layout, const B_data_t &B_data)
{
internal::TensorOps<A_layout_t::rank>::
template AssignHD<Op>(A_layout, A_data, B_layout, B_data);
}

// classes TVector, TMatrix, TTensor3, TTensor4

Expand Down