Nektar++
Loading...
Searching...
No Matches
RobBndCondDeviceKernels.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: RobBndCondDeviceKernels.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:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
38
40{
41
42#if defined(NEKTAR_ENABLE_DEVICE) && defined(DEVICE_COMPILE_ONLY)
43template <typename TthreadBlock, typename TData>
45 const size_t nsize, const size_t *NEK_RESTRICT offsetPtr,
46 const TData *NEK_RESTRICT matPtr, const size_t *NEK_RESTRICT mapPtr,
47 const TData *NEK_RESTRICT incoeffPtr, TData *NEK_RESTRICT coeffPtr,
48 const TthreadBlock &threadBlock)
49{
50 size_t idx0 = getGlobalIdx(threadBlock);
51 size_t stride = getGlobalRange(threadBlock);
52
53 for (size_t i = idx0; i < nsize; i += stride)
54 {
55 const size_t offset = offsetPtr[i];
56 const size_t map = mapPtr[i];
57
58 TData *const ptr = coeffPtr + offset + map;
59 const TData val = matPtr[i] * incoeffPtr[offset + map];
60 Nektar::atomic_add<NektarSpaces::GlobalScope>(ptr, val);
61 }
62}
63
64template <typename TthreadBlock, typename TData>
66 const size_t nsize, const unsigned int *NEK_RESTRICT ncoeffPtr,
67 const size_t *NEK_RESTRICT offsetPtr,
68 const size_t *NEK_RESTRICT matOffsetPtr,
69 const size_t *NEK_RESTRICT mapOffsetPtr, const TData *NEK_RESTRICT matPtr,
70 const size_t *NEK_RESTRICT mapPtr, const int *NEK_RESTRICT signPtr,
71 const TData *NEK_RESTRICT incoeffPtr, TData *NEK_RESTRICT coeffPtr,
72 unsigned char *NEK_RESTRICT shmemptr, const TthreadBlock &threadBlock)
73{
75
76 TData *vEdgeCoeffs = (TData *)shmemptr;
77
78 unsigned int j = getBlockIdx(threadBlock);
79
80 while (j < nsize)
81 {
82 const unsigned int ncoeff = ncoeffPtr[j];
83 const size_t offset = offsetPtr[j];
84 const size_t matOffset = matOffsetPtr[j];
85 const size_t mapOffset = mapOffsetPtr[j];
86
87 unsigned int idx0 = getLocalIdx(threadBlock);
88 unsigned int stride = getLocalRange(threadBlock);
89
90 for (unsigned int i = idx0; i < ncoeff; i += stride)
91 {
92 const size_t index = mapOffset + i;
93 vEdgeCoeffs[i] =
94 incoeffPtr[offset + mapPtr[index]] * signPtr[index];
95 }
96
97 Nektar::localBarrier(threadBlock);
98
99 for (unsigned int i = idx0; i < ncoeff; i += stride)
100 {
101 TData tmp = 0.0;
102 for (unsigned int k = 0; k < ncoeff; k++)
103 {
104 tmp += matPtr[matOffset + ncoeff * k + i] * vEdgeCoeffs[k];
105 }
106
107 const size_t index = mapOffset + i;
108 TData *const ptr = coeffPtr + offset + mapPtr[index];
109 const TData val = tmp * signPtr[index];
110 Nektar::atomic_add<NektarSpaces::GlobalScope>(ptr, val);
111 }
112
113 Nektar::localBarrier(threadBlock);
114
115 j += getBlockRange(threadBlock);
116 }
117}
118
119template <
120 typename ExecSpace, typename TData,
121 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
122 Enable = true>
124 const size_t nsize, const size_t *offsetPtr, const TData *matPtr,
125 const size_t *mapPtr, const TData *incoeffPtr, TData *coeffPtr,
126 const unsigned int streamID)
127{
128 const unsigned int blockSize = NektarSpaces::Device::warpSize;
129 const unsigned int gridSize = (nsize + blockSize - 1u) / blockSize;
130
131 DEVICE_1DGRID_KERNEL_LAUNCHER_NOSHMEM(RobBndCond1DKernel, gridSize,
132 blockSize, streamID, nsize, offsetPtr,
133 matPtr, mapPtr, incoeffPtr, coeffPtr);
134}
135
136template <
137 typename ExecSpace, typename TData,
138 std::enable_if_t<std::is_same_v<ExecSpace, NektarSpaces::Device>, bool>
139 Enable = true>
141 const unsigned int nmaxcoeff, const size_t nsize,
142 const unsigned int *ncoeffPtr, const size_t *offsetPtr,
143 const size_t *matOffsetPtr, const size_t *mapOffsetPtr, const TData *matPtr,
144 const size_t *mapPtr, const int *signPtr, const TData *incoeffPtr,
145 TData *coeffPtr, const unsigned int streamID)
146{
147 const unsigned int shmemsize = sizeof(TData) * nmaxcoeff;
148 const unsigned int blockSize = NektarSpaces::Device::warpSize;
149 const unsigned int gridSize = nsize;
150
151 DEVICE_1DGRID_KERNEL_LAUNCHER(RobBndCond2DKernel, gridSize, blockSize,
152 shmemsize, streamID, nsize, ncoeffPtr,
153 offsetPtr, matOffsetPtr, mapOffsetPtr, matPtr,
154 mapPtr, signPtr, incoeffPtr, coeffPtr);
155}
156#endif
157
158} // namespace Nektar::MultiRegions::detail
#define NEK_RESTRICT
Definition Backends.hpp:254
#define NEK_DEVICE_KERNEL
Definition Backends.hpp:297
#define NEK_FORCE_INLINE
Definition NekInline.hpp:46
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT const bool const bool unsigned char const TthreadBlock & threadBlock
static NEK_FORCE_INLINE void RobBndCond1DKernel(const size_t nsize, const size_t *offsetPtr, const TData *matPtr, const size_t *mapPtr, const TData *incoeffPtr, TData *coeffPtr, const unsigned int streamID)
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT const bool const bool unsigned char * shmemptr
static NEK_FORCE_INLINE void RobBndCond2DKernel(const unsigned int nmaxcoeff, const size_t nsize, const unsigned int *ncoeffPtr, const size_t *offsetPtr, const size_t *matOffsetPtr, const size_t *mapOffsetPtr, const TData *matPtr, const size_t *mapPtr, const int *signPtr, const TData *incoeffPtr, TData *coeffPtr, const unsigned int streamID)
static constexpr unsigned int warpSize
Definition Backends.hpp:143