MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
bilininteg_mass_kernels.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, 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
14namespace mfem
15{
16
17MassIntegrator::Kernels::Kernels()
18{
19 // 2D
20 // Q=P+1
30 // Q=P+2
40 // others
44 // 3D
45 // Q=P+1
55 // Q=P+2
65 // others
69}
70
71namespace internal
72{
73
74#ifdef MFEM_USE_OCCA
75void OccaPAMassApply2D(const int D1D,
76 const int Q1D,
77 const int NE,
78 const Array<real_t> &B,
79 const Array<real_t> &Bt,
80 const Vector &D,
81 const Vector &X,
82 Vector &Y)
83{
84 occa::properties props;
85 props["defines/D1D"] = D1D;
86 props["defines/Q1D"] = Q1D;
87 const occa::memory o_B = OccaMemoryRead(B.GetMemory(), B.Size());
88 const occa::memory o_Bt = OccaMemoryRead(Bt.GetMemory(), Bt.Size());
89 const occa::memory o_D = OccaMemoryRead(D.GetMemory(), D.Size());
90 const occa::memory o_X = OccaMemoryRead(X.GetMemory(), X.Size());
91 occa::memory o_Y = OccaMemoryReadWrite(Y.GetMemory(), Y.Size());
92 const occa_id_t id = std::make_pair(D1D,Q1D);
93 if (!Device::Allows(Backend::OCCA_CUDA))
94 {
95 static occa_kernel_t OccaMassApply2D_cpu;
96 if (OccaMassApply2D_cpu.find(id) == OccaMassApply2D_cpu.end())
97 {
98 const occa::kernel MassApply2D_CPU =
99 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
100 "MassApply2D_CPU", props);
101 OccaMassApply2D_cpu.emplace(id, MassApply2D_CPU);
102 }
103 OccaMassApply2D_cpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
104 }
105 else
106 {
107 static occa_kernel_t OccaMassApply2D_gpu;
108 if (OccaMassApply2D_gpu.find(id) == OccaMassApply2D_gpu.end())
109 {
110 const occa::kernel MassApply2D_GPU =
111 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
112 "MassApply2D_GPU", props);
113 OccaMassApply2D_gpu.emplace(id, MassApply2D_GPU);
114 }
115 OccaMassApply2D_gpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
116 }
117}
118
119void OccaPAMassApply3D(const int D1D,
120 const int Q1D,
121 const int NE,
122 const Array<real_t> &B,
123 const Array<real_t> &Bt,
124 const Vector &D,
125 const Vector &X,
126 Vector &Y)
127{
128 occa::properties props;
129 props["defines/D1D"] = D1D;
130 props["defines/Q1D"] = Q1D;
131 const occa::memory o_B = OccaMemoryRead(B.GetMemory(), B.Size());
132 const occa::memory o_Bt = OccaMemoryRead(Bt.GetMemory(), Bt.Size());
133 const occa::memory o_D = OccaMemoryRead(D.GetMemory(), D.Size());
134 const occa::memory o_X = OccaMemoryRead(X.GetMemory(), X.Size());
135 occa::memory o_Y = OccaMemoryReadWrite(Y.GetMemory(), Y.Size());
136 const occa_id_t id = std::make_pair(D1D,Q1D);
137 if (!Device::Allows(Backend::OCCA_CUDA))
138 {
139 static occa_kernel_t OccaMassApply3D_cpu;
140 if (OccaMassApply3D_cpu.find(id) == OccaMassApply3D_cpu.end())
141 {
142 const occa::kernel MassApply3D_CPU =
143 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
144 "MassApply3D_CPU", props);
145 OccaMassApply3D_cpu.emplace(id, MassApply3D_CPU);
146 }
147 OccaMassApply3D_cpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
148 }
149 else
150 {
151 static occa_kernel_t OccaMassApply3D_gpu;
152 if (OccaMassApply3D_gpu.find(id) == OccaMassApply3D_gpu.end())
153 {
154 const occa::kernel MassApply3D_GPU =
155 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
156 "MassApply3D_GPU", props);
157 OccaMassApply3D_gpu.emplace(id, MassApply3D_GPU);
158 }
159 OccaMassApply3D_gpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
160 }
161}
162#endif // MFEM_USE_OCCA
163
164} // namespace internal
165
166} // namespace mfem
Memory< T > & GetMemory()
Return a reference to the Memory object used by the Array.
Definition array.hpp:145
int Size() const
Return the logical size of the array.
Definition array.hpp:166
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