MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
bilininteg_mass_kernels.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
13#include "bilininteg_mass_pa_simplices.hpp" // IWYU pragma: keep
14
15namespace mfem
16{
17
18MassIntegrator::Kernels::Kernels()
19{
20 // 2D
21 // Q=P+1
31 // Q=P+2
41 // others
46
47 // 3D
48 // Q=P+1
58 // Q=P+2
68 // others
72}
73
74namespace internal
75{
76
77#ifdef MFEM_USE_OCCA
78void OccaPAMassApply2D(const int D1D,
79 const int Q1D,
80 const int NE,
81 const Array<real_t> &B,
82 const Array<real_t> &Bt,
83 const Vector &D,
84 const Vector &X,
85 Vector &Y)
86{
87 occa::properties props;
88 props["defines/D1D"] = D1D;
89 props["defines/Q1D"] = Q1D;
90 const occa::memory o_B = OccaMemoryRead(B.GetMemory(), B.Size());
91 const occa::memory o_Bt = OccaMemoryRead(Bt.GetMemory(), Bt.Size());
92 const occa::memory o_D = OccaMemoryRead(D.GetMemory(), D.Size());
93 const occa::memory o_X = OccaMemoryRead(X.GetMemory(), X.Size());
94 occa::memory o_Y = OccaMemoryReadWrite(Y.GetMemory(), Y.Size());
95 const occa_id_t id = std::make_pair(D1D,Q1D);
96 if (!Device::Allows(Backend::OCCA_CUDA))
97 {
98 static occa_kernel_t OccaMassApply2D_cpu;
99 if (OccaMassApply2D_cpu.find(id) == OccaMassApply2D_cpu.end())
100 {
101 const occa::kernel MassApply2D_CPU =
102 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
103 "MassApply2D_CPU", props);
104 OccaMassApply2D_cpu.emplace(id, MassApply2D_CPU);
105 }
106 OccaMassApply2D_cpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
107 }
108 else
109 {
110 static occa_kernel_t OccaMassApply2D_gpu;
111 if (OccaMassApply2D_gpu.find(id) == OccaMassApply2D_gpu.end())
112 {
113 const occa::kernel MassApply2D_GPU =
114 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
115 "MassApply2D_GPU", props);
116 OccaMassApply2D_gpu.emplace(id, MassApply2D_GPU);
117 }
118 OccaMassApply2D_gpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
119 }
120}
121
122void OccaPAMassApply3D(const int D1D,
123 const int Q1D,
124 const int NE,
125 const Array<real_t> &B,
126 const Array<real_t> &Bt,
127 const Vector &D,
128 const Vector &X,
129 Vector &Y)
130{
131 occa::properties props;
132 props["defines/D1D"] = D1D;
133 props["defines/Q1D"] = Q1D;
134 const occa::memory o_B = OccaMemoryRead(B.GetMemory(), B.Size());
135 const occa::memory o_Bt = OccaMemoryRead(Bt.GetMemory(), Bt.Size());
136 const occa::memory o_D = OccaMemoryRead(D.GetMemory(), D.Size());
137 const occa::memory o_X = OccaMemoryRead(X.GetMemory(), X.Size());
138 occa::memory o_Y = OccaMemoryReadWrite(Y.GetMemory(), Y.Size());
139 const occa_id_t id = std::make_pair(D1D,Q1D);
140 if (!Device::Allows(Backend::OCCA_CUDA))
141 {
142 static occa_kernel_t OccaMassApply3D_cpu;
143 if (OccaMassApply3D_cpu.find(id) == OccaMassApply3D_cpu.end())
144 {
145 const occa::kernel MassApply3D_CPU =
146 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
147 "MassApply3D_CPU", props);
148 OccaMassApply3D_cpu.emplace(id, MassApply3D_CPU);
149 }
150 OccaMassApply3D_cpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
151 }
152 else
153 {
154 static occa_kernel_t OccaMassApply3D_gpu;
155 if (OccaMassApply3D_gpu.find(id) == OccaMassApply3D_gpu.end())
156 {
157 const occa::kernel MassApply3D_GPU =
158 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
159 "MassApply3D_GPU", props);
160 OccaMassApply3D_gpu.emplace(id, MassApply3D_GPU);
161 }
162 OccaMassApply3D_gpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
163 }
164}
165#endif // MFEM_USE_OCCA
166
167} // namespace internal
168
169} // namespace mfem
Memory< T > & GetMemory()
Return a reference to the Memory object used by the Array.
Definition array.hpp:164
int Size() const
Return the logical size of the array.
Definition array.hpp:192
static void AddSpecialization()
Vector data type.
Definition vector.hpp:82
Memory< real_t > & GetMemory()
Return a reference to the Memory object used by the Vector.
Definition vector.hpp:265
int Size() const
Returns the size of the vector.
Definition vector.hpp:234
occa::memory OccaMemoryReadWrite(Memory< T > &mem, size_t size)
Wrap a Memory object as occa::memory for read-write access with the mfem::Device MemoryClass....
Definition occa.hpp:59
std::map< occa_id_t, occa::kernel > occa_kernel_t
Definition occa.hpp:79
const occa::memory OccaMemoryRead(const Memory< T > &mem, size_t size)
Wrap a Memory object as occa::memory for read only access with the mfem::Device MemoryClass....
Definition occa.hpp:37
occa::device & OccaDev()
Return the default occa::device used by MFEM.
Definition occa.cpp:27
std::pair< int, int > occa_id_t
Definition occa.hpp:78