1#ifndef __MATH_DUDXYZ_KERNEL_H__
2#define __MATH_DUDXYZ_KERNEL_H__
46template<
typename T, const
int LX, const
int CHUNKS >
48 const T * __restrict__
u,
49 const T * __restrict__
dr,
50 const T * __restrict__
ds,
51 const T * __restrict__
dt,
52 const T * __restrict__
dx,
53 const T * __restrict__
dy,
54 const T * __restrict__
dz,
55 const T * __restrict__
jacinv) {
57 __shared__ T
shu[LX * LX * LX];
58 __shared__ T shdr[LX * LX * LX];
59 __shared__ T shds[LX * LX * LX];
60 __shared__ T shdt[LX * LX * LX];
62 __shared__ T
shdx[LX * LX];
63 __shared__ T
shdy[LX * LX];
64 __shared__ T
shdz[LX * LX];
66 __shared__ T shjacinv[LX * LX * LX];
68 const int e = blockIdx.x;
69 const int iii = threadIdx.x;
70 const int nchunks = (LX * LX * LX - 1) / CHUNKS + 1;
72 if (iii < (LX * LX)) {
79 while(l < (LX * LX * LX)) {
80 shu[l] =
u[l +
e * LX * LX * LX];
81 shdr[l] =
dr[l +
e * LX * LX * LX];
82 shds[l] =
ds[l +
e * LX * LX * LX];
83 shdt[l] =
dt[l +
e * LX * LX * LX];
84 shjacinv[l] =
jacinv[l +
e * LX * LX * LX];
90 for (
int n = 0; n < nchunks; n++) {
91 const int ijk = iii + n * CHUNKS;
92 const int jk = ijk / LX;
93 const int i = ijk - jk * LX;
94 const int k = jk / LX;
95 const int j = jk - k * LX;
96 if (
i < LX &&
j < LX && k < LX) {
100 for (
int l = 0; l < LX; l++) {
101 rtmp +=
shdx[
i + l * LX] *
shu[l +
j * LX + k * LX * LX];
102 stmp +=
shdy[
j + l * LX] *
shu[
i + l * LX + k * LX * LX];
103 ttmp +=
shdz[k + l * LX] *
shu[
i +
j * LX + l * LX * LX];
105 du[ijk +
e * LX * LX * LX] = ((rtmp * shdr[ijk])
107 + (ttmp * shdt[ijk]))
114template<
typename T, const
int LX, const
int EB >
116 dudxyz_kernel_kstep(T * __restrict__ du,
117 const T * __restrict__
u,
118 const T * __restrict__
dr,
119 const T * __restrict__
ds,
120 const T * __restrict__
dt,
121 const T * __restrict__
dx,
122 const T * __restrict__
dy,
123 const T * __restrict__
dz,
127 __shared__ T
shu[EB * LX * LX];
133 static_assert(
sizeof(
shu) +
138 "kstep block exceeds the LDS budget");
140 const int eb = (EB == 1) ? 0 : threadIdx.z;
148 const int j = threadIdx.y;
149 const int i = threadIdx.x;
166 for (
int k = 0; k < LX; ++k) {
177 for (
int k = 0; k < LX; ++k) {
178 const int ijk =
ij + k*LX*LX;
182 for (
int l = 0; l < LX; l++) {
183 ttmp +=
shdz[k+l*LX] *
ru[l];
190 for (
int l = 0; l < LX; l++) {
218#if defined(__gfx90a__) || defined(__gfx942__)
220template<
typename T, const
int LX, const
int NWF, const
int TILE >
221__device__
void dudxyz_mfma_elem(T * __restrict__ du,
222 const T * __restrict__
u,
223 const T * __restrict__
dr,
224 const T * __restrict__
ds,
225 const T * __restrict__
dt,
226 const T * __restrict__
dx,
227 const T * __restrict__
dy,
228 const T * __restrict__
dz,
229 const T * __restrict__
jacinv,
231 const int LX2 = LX * LX;
232 const int LX3 = LX * LX * LX;
244 static_assert(WPE * EB == NWF,
245 "wavefronts per block must split evenly over the elements");
247 __shared__ T
shdx[LX * LX];
248 __shared__ T
shdy[LX * LX];
249 __shared__ T
shdz[LX * LX];
250 __shared__ T
shu[EB * LX * LX * LX];
251 __shared__ T shr[EB * LX * LX * LX];
252 __shared__ T shs[EB * LX * LX * LX];
253 __shared__ T sht[EB * LX * LX * LX];
255 static_assert(
sizeof(
shdx) +
sizeof(
shdy) +
sizeof(
shdz) +
256 sizeof(
shu) +
sizeof(shr) +
sizeof(shs) +
sizeof(sht)
258 "mfma block exceeds the shared memory budget");
260 const int lane = threadIdx.x;
261 const int wf = threadIdx.y;
262 const int tid = wf * 64 + lane;
263 const int nthr = NWF * 64;
265 const int eb = wf / WPE;
266 const int sub = wf % WPE;
267 const int gtid = sub * 64 + lane;
268 const int gnthr = WPE * 64;
274 const int e_blk = blockIdx.x * EB +
eb;
277 const int ele =
e * LX3;
278 const int sh =
eb * LX3;
281 for (
int p = tid; p < LX2; p += nthr) {
287 for (
int p = gtid; p < LX3; p += gnthr)
295 mfma_contract_sel<T, LX, 0, false, false, WPE, TILE, 0, NEL>::run(
298 mfma_contract_sel<T, LX, 1, false, false, WPE, TILE, 0, NEL>::run(
301 mfma_contract_sel<T, LX, 2, false, false, WPE, TILE, 0, NEL>::run(
307 for (
int p = gtid; p < LX3; p += gnthr) {
308 const int gp = p +
ele;
311 + shs[
sh + p] *
ds[gp]
312 + sht[
sh + p] *
dt[gp]);
328template<
typename T, const
int LX, const
int NWF, const
int TILE >
330 __device__
static void run(T *,
const T *,
const T *,
const T *,
const T *,
331 const T *,
const T *,
const T *,
const T *,
335#if defined(__gfx90a__) || defined(__gfx942__)
338#define NEKO_DUDXYZ_MFMA_DISPATCH(TYPE, LXV) \
339 template< const int NWF, const int TILE > \
340 struct dudxyz_mfma_dispatch< TYPE, LXV, NWF, TILE > { \
341 __device__ static void run(TYPE * du, \
349 const TYPE * jacinv, \
351 dudxyz_mfma_elem< TYPE, LXV, NWF, TILE >(du, u, dr, ds, dt, dx, dy, dz, \
356NEKO_DUDXYZ_MFMA_DISPATCH(
double, 4);
357NEKO_DUDXYZ_MFMA_DISPATCH(
double, 5);
358NEKO_DUDXYZ_MFMA_DISPATCH(
double, 6);
359NEKO_DUDXYZ_MFMA_DISPATCH(
double, 7);
360NEKO_DUDXYZ_MFMA_DISPATCH(
double, 8);
361NEKO_DUDXYZ_MFMA_DISPATCH(
double, 9);
362NEKO_DUDXYZ_MFMA_DISPATCH(
double, 10);
363NEKO_DUDXYZ_MFMA_DISPATCH(
double, 11);
364NEKO_DUDXYZ_MFMA_DISPATCH(
double, 12);
366NEKO_DUDXYZ_MFMA_DISPATCH(
float, 2);
367NEKO_DUDXYZ_MFMA_DISPATCH(
float, 3);
368NEKO_DUDXYZ_MFMA_DISPATCH(
float, 4);
369NEKO_DUDXYZ_MFMA_DISPATCH(
float, 5);
370NEKO_DUDXYZ_MFMA_DISPATCH(
float, 6);
371NEKO_DUDXYZ_MFMA_DISPATCH(
float, 7);
372NEKO_DUDXYZ_MFMA_DISPATCH(
float, 8);
373NEKO_DUDXYZ_MFMA_DISPATCH(
float, 9);
374NEKO_DUDXYZ_MFMA_DISPATCH(
float, 10);
375NEKO_DUDXYZ_MFMA_DISPATCH(
float, 11);
376NEKO_DUDXYZ_MFMA_DISPATCH(
float, 12);
385template<
typename T, const
int LX, const
int NWF, const
int TILE >
387dudxyz_kernel_mfma(T * __restrict__ du,
388 const T * __restrict__
u,
389 const T * __restrict__
dr,
390 const T * __restrict__
ds,
391 const T * __restrict__
dt,
392 const T * __restrict__
dx,
393 const T * __restrict__
dy,
394 const T * __restrict__
dz,
395 const T * __restrict__
jacinv,
398 dudxyz_mfma_dispatch< T, LX, NWF, TILE >::run(du,
u,
dr,
ds,
dt,
dx,
dy,
dz,
__shared__ T shdy[LX *LX]
__shared__ T shu[EB *LX *LX]
__shared__ T shdz[LX *LX]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const int *__restrict__ const int nelv
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dz
__global__ void const T *__restrict__ const T *__restrict__ dx
__global__ void const T *__restrict__ u
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ dy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ jacinv
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ ds
__global__ void const T *__restrict__ const T *__restrict__ dr
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dt
__global__ void dudxyz_kernel_1d(T *__restrict__ du, const T *__restrict__ u, const T *__restrict__ dr, const T *__restrict__ ds, const T *__restrict__ dt, const T *__restrict__ dx, const T *__restrict__ dy, const T *__restrict__ dz, const T *__restrict__ jacinv)
#define NEKO_EB_BOUNDS(NT)
__global__ void __launch_bounds__((LX *LX *EB)) dudxyz_kernel_kstep(T *__restrict__ du
#define NEKO_MFMA_NEL_N(EB, LX, SZ, TILE)
#define NEKO_MFMA_EB_N(NWF, LX, SZ)
static __device__ void run(T *, const T *, const T *, const T *, const T *, const T *, const T *, const T *, const T *, const int)