MFEM v4.8.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
40
41namespace internal
42{
43
44#ifdef MFEM_USE_OCCA
45void OccaPAMassApply2D(const int D1D,
46 const int Q1D,
47 const int NE,
48 const Array<real_t> &B,
49 const Array<real_t> &Bt,
50 const Vector &D,
51 const Vector &X,
52 Vector &Y)
53{
54 occa::properties props;
55 props["defines/D1D"] = D1D;
56 props["defines/Q1D"] = Q1D;
57 const occa::memory o_B = OccaMemoryRead(B.GetMemory(), B.Size());
58 const occa::memory o_Bt = OccaMemoryRead(Bt.GetMemory(), Bt.Size());
59 const occa::memory o_D = OccaMemoryRead(D.GetMemory(), D.Size());
60 const occa::memory o_X = OccaMemoryRead(X.GetMemory(), X.Size());
61 occa::memory o_Y = OccaMemoryReadWrite(Y.GetMemory(), Y.Size());
62 const occa_id_t id = std::make_pair(D1D,Q1D);
63 if (!Device::Allows(Backend::OCCA_CUDA))
64 {
65 static occa_kernel_t OccaMassApply2D_cpu;
66 if (OccaMassApply2D_cpu.find(id) == OccaMassApply2D_cpu.end())
67 {
68 const occa::kernel MassApply2D_CPU =
69 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
70 "MassApply2D_CPU", props);
71 OccaMassApply2D_cpu.emplace(id, MassApply2D_CPU);
72 }
73 OccaMassApply2D_cpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
74 }
75 else
76 {
77 static occa_kernel_t OccaMassApply2D_gpu;
78 if (OccaMassApply2D_gpu.find(id) == OccaMassApply2D_gpu.end())
79 {
80 const occa::kernel MassApply2D_GPU =
81 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
82 "MassApply2D_GPU", props);
83 OccaMassApply2D_gpu.emplace(id, MassApply2D_GPU);
84 }
85 OccaMassApply2D_gpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
86 }
87}
88
89void OccaPAMassApply3D(const int D1D,
90 const int Q1D,
91 const int NE,
92 const Array<real_t> &B,
93 const Array<real_t> &Bt,
94 const Vector &D,
95 const Vector &X,
96 Vector &Y)
97{
98 occa::properties props;
99 props["defines/D1D"] = D1D;
100 props["defines/Q1D"] = Q1D;
101 const occa::memory o_B = OccaMemoryRead(B.GetMemory(), B.Size());
102 const occa::memory o_Bt = OccaMemoryRead(Bt.GetMemory(), Bt.Size());
103 const occa::memory o_D = OccaMemoryRead(D.GetMemory(), D.Size());
104 const occa::memory o_X = OccaMemoryRead(X.GetMemory(), X.Size());
105 occa::memory o_Y = OccaMemoryReadWrite(Y.GetMemory(), Y.Size());
106 const occa_id_t id = std::make_pair(D1D,Q1D);
107 if (!Device::Allows(Backend::OCCA_CUDA))
108 {
109 static occa_kernel_t OccaMassApply3D_cpu;
110 if (OccaMassApply3D_cpu.find(id) == OccaMassApply3D_cpu.end())
111 {
112 const occa::kernel MassApply3D_CPU =
113 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
114 "MassApply3D_CPU", props);
115 OccaMassApply3D_cpu.emplace(id, MassApply3D_CPU);
116 }
117 OccaMassApply3D_cpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
118 }
119 else
120 {
121 static occa_kernel_t OccaMassApply3D_gpu;
122 if (OccaMassApply3D_gpu.find(id) == OccaMassApply3D_gpu.end())
123 {
124 const occa::kernel MassApply3D_GPU =
125 mfem::OccaDev().buildKernel("occa://mfem/fem/occa.okl",
126 "MassApply3D_GPU", props);
127 OccaMassApply3D_gpu.emplace(id, MassApply3D_GPU);
128 }
129 OccaMassApply3D_gpu.at(id)(NE, o_B, o_Bt, o_D, o_X, o_Y);
130 }
131}
132#endif // MFEM_USE_OCCA
133
134} // namespace internal
135
136} // namespace mfem
Memory< T > & GetMemory()
Return a reference to the Memory object used by the Array.
Definition array.hpp:126
int Size() const
Return the logical size of the array.
Definition array.hpp:147
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:257
int Size() const
Returns the size of the vector.
Definition vector.hpp:226
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