1#ifndef __MATH_DUDXYZ_KERNEL_H__
2#define __MATH_DUDXYZ_KERNEL_H__
45template<
typename T, const
int LX, const
int CHUNKS >
47 const T * __restrict__
u,
48 const T * __restrict__
dr,
49 const T * __restrict__
ds,
50 const T * __restrict__
dt,
51 const T * __restrict__
dx,
52 const T * __restrict__
dy,
53 const T * __restrict__
dz,
54 const T * __restrict__
jacinv) {
56 __shared__ T
shu[LX * LX * LX];
57 __shared__ T shdr[LX * LX * LX];
58 __shared__ T shds[LX * LX * LX];
59 __shared__ T shdt[LX * LX * LX];
61 __shared__ T
shdx[LX * LX];
62 __shared__ T
shdy[LX * LX];
63 __shared__ T
shdz[LX * LX];
65 __shared__ T shjacinv[LX * LX * LX];
67 const int e = blockIdx.x;
68 const int iii = threadIdx.x;
69 const int nchunks = (LX * LX * LX - 1) / CHUNKS + 1;
71 if (iii < (LX * LX)) {
78 while(l < (LX * LX * LX)) {
79 shu[l] =
u[l +
e * LX * LX * LX];
80 shdr[l] =
dr[l +
e * LX * LX * LX];
81 shds[l] =
ds[l +
e * LX * LX * LX];
82 shdt[l] =
dt[l +
e * LX * LX * LX];
83 shjacinv[l] =
jacinv[l +
e * LX * LX * LX];
89 for (
int n = 0; n < nchunks; n++) {
90 const int ijk = iii + n * CHUNKS;
91 const int jk = ijk / LX;
92 const int i = ijk - jk * LX;
93 const int k = jk / LX;
94 const int j = jk - k * LX;
95 if (
i < LX &&
j < LX && k < LX) {
99 for (
int l = 0; l < LX; l++) {
100 rtmp +=
shdx[
i + l * LX] *
shu[l +
j * LX + k * LX * LX];
101 stmp +=
shdy[
j + l * LX] *
shu[
i + l * LX + k * LX * LX];
102 ttmp +=
shdz[k + l * LX] *
shu[
i +
j * LX + l * LX * LX];
104 du[ijk +
e * LX * LX * LX] = ((rtmp * shdr[ijk])
106 + (ttmp * shdt[ijk]))
113template<
typename T, const
int LX, const
int EB >
115 dudxyz_kernel_kstep(T * __restrict__ du,
116 const T * __restrict__
u,
117 const T * __restrict__
dr,
118 const T * __restrict__
ds,
119 const T * __restrict__
dt,
120 const T * __restrict__
dx,
121 const T * __restrict__
dy,
122 const T * __restrict__
dz,
126 __shared__ T
shu[EB * LX * LX];
132 static_assert(
sizeof(
shu) +
137 "kstep block exceeds the shared memory budget");
139 const int eb = (EB == 1) ? 0 : threadIdx.z;
147 const int j = threadIdx.y;
148 const int i = threadIdx.x;
165 for (
int k = 0; k < LX; ++k) {
176 for (
int k = 0; k < LX; ++k) {
177 const int ijk =
ij + k*LX*LX;
181 for (
int l = 0; l < LX; l++) {
182 ttmp +=
shdz[k+l*LX] *
ru[l];
189 for (
int l = 0; l < LX; l++) {
226#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 800) && (__CUDA_ARCH__ < 1000)
228template< const
int LX, const
int NW >
229__device__ __forceinline__
230void dudxyz_dmma_elem(
double * __restrict__ du,
231 const double * __restrict__
u,
232 const double * __restrict__
dr,
233 const double * __restrict__
ds,
234 const double * __restrict__
dt,
235 const double * __restrict__
dx,
236 const double * __restrict__
dy,
237 const double * __restrict__
dz,
238 const double * __restrict__
jacinv,
250 __shared__ __align__(16)
double shr[
DMMA_CUBE];
251 __shared__ __align__(16)
double shs[
DMMA_CUBE];
252 __shared__ __align__(16)
double sht[
DMMA_CUBE];
254 static_assert(sizeof(
shdx) +
262 "dmma block exceeds the shared memory budget");
269 PACK = PPA * PPA * PPA,
273 typedef dmma_pack< LX, PPA > pack;
275 const int nthrds = 32 * NW;
276 const int tid = threadIdx.x;
277 const int wf = tid >> 5;
278 const int ebase = pack::ebase();
284 for (
int p = tid; p <
DMMA_CUBE; p += nthrds) {
289 for (
int p = tid; p <
DMMA_MAT; p += nthrds) {
300 for (
int p = tid; p < LX * LX; p += nthrds) {
301 const int i = p % LX;
302 const int l = p / LX;
304 for (
int b = 0; b < PPA; b++) {
305 const int m = (b * LX +
i) +
DMMA_P * (b * LX + l);
312 for (
int p = tid; p < NP; p += nthrds) {
313 const dmma_idx
x = pack::map(p, ebase,
nelv);
320 dmma_contract< 0, false, false, NW >(shr,
shdx,
shu, wf);
321 dmma_contract< 1, false, false, NW >(shs,
shdy,
shu, wf);
322 dmma_contract< 2, false, false, NW >(sht,
shdz,
shu, wf);
330 for (
int p = tid; p < NP; p += nthrds) {
331 const dmma_idx
x = pack::map(p, ebase,
nelv);
337 du[gp] =
jacinv[gp] * ((shr[c] *
dr[gp])
339 + (sht[c] *
dt[gp]));
356template<
typename T, const
int LX, const
int NW >
358 __device__
static void run(T * __restrict__,
359 const T * __restrict__,
360 const T * __restrict__,
361 const T * __restrict__,
362 const T * __restrict__,
363 const T * __restrict__,
364 const T * __restrict__,
365 const T * __restrict__,
366 const T * __restrict__,
370#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 800) && (__CUDA_ARCH__ < 1000)
373#define NEKO_DUDXYZ_DMMA_DISPATCH(LXV) \
374 template< const int NW > \
375 struct dudxyz_dmma_dispatch< double, LXV, NW > { \
376 __device__ static void run(double * __restrict__ du, \
377 const double * __restrict__ u, \
378 const double * __restrict__ dr, \
379 const double * __restrict__ ds, \
380 const double * __restrict__ dt, \
381 const double * __restrict__ dx, \
382 const double * __restrict__ dy, \
383 const double * __restrict__ dz, \
384 const double * __restrict__ jacinv, \
386 dudxyz_dmma_elem< LXV, NW >(du, u, dr, ds, dt, \
387 dx, dy, dz, jacinv, nelv); \
391NEKO_DUDXYZ_DMMA_DISPATCH(2);
392NEKO_DUDXYZ_DMMA_DISPATCH(3);
393NEKO_DUDXYZ_DMMA_DISPATCH(4);
394NEKO_DUDXYZ_DMMA_DISPATCH(5);
395NEKO_DUDXYZ_DMMA_DISPATCH(6);
396NEKO_DUDXYZ_DMMA_DISPATCH(7);
397NEKO_DUDXYZ_DMMA_DISPATCH(8);
401template<
typename T, const
int LX, const
int NW >
403dudxyz_kernel_dmma(T * __restrict__ du,
404 const T * __restrict__
u,
405 const T * __restrict__
dr,
406 const T * __restrict__
ds,
407 const T * __restrict__
dt,
408 const T * __restrict__
dx,
409 const T * __restrict__
dy,
410 const T * __restrict__
dz,
411 const T * __restrict__
jacinv,
445#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 900) && \
446 (__CUDA_ARCH__ < 1000) && NEKO_TMA_TOOLKIT
448template< const
int LX, const
int NW >
449__device__ __forceinline__
450void dudxyz_dmma_tma_elem(
double * __restrict__ du,
451 const double * __restrict__
u,
452 const double * __restrict__
dr,
453 const double * __restrict__
ds,
454 const double * __restrict__
dt,
455 const double * __restrict__
dx,
456 const double * __restrict__
dy,
457 const double * __restrict__
dz,
458 const double * __restrict__
jacinv) {
470 __shared__ __align__(128)
double shr[
DMMA_CUBE];
471 __shared__ __align__(128)
double shs[
DMMA_CUBE];
472 __shared__ __align__(128)
double sht[
DMMA_CUBE];
475 __shared__ __align__(128)
double shgr[
DMMA_CUBE];
476 __shared__ __align__(128)
double shgs[
DMMA_CUBE];
477 __shared__ __align__(128)
double shgt[
DMMA_CUBE];
478 __shared__ __align__(128)
double shgj[
DMMA_CUBE];
480 __shared__ __align__(8)
unsigned long long bar_u;
481 __shared__ __align__(8)
unsigned long long bar_g;
483 static_assert(sizeof(
shdx) +
497 "dudxyz dmma tma block exceeds the shared memory budget");
502 static_assert(LX ==
DMMA_P,
503 "the dmma tma variant stages whole cubes only");
505 enum { CUBE_BYTES =
DMMA_CUBE * (int)
sizeof(double),
508 const int nthrds = 32 * NW;
509 const int tid = threadIdx.x;
510 const int wf = tid >> 5;
511 const int ebase = blockIdx.x *
DMMA_CUBE;
514 tma_barrier_init(&bar_u, 1);
515 tma_barrier_init(&bar_g, 1);
520 for (
int p = tid; p <
DMMA_MAT; p += nthrds) {
531 tma_expect(&bar_u, CUBE_BYTES);
532 tma_load(
shu,
u + ebase, CUBE_BYTES, &bar_u);
534 tma_expect(&bar_g, NG * CUBE_BYTES);
535 tma_load(shgr,
dr + ebase, CUBE_BYTES, &bar_g);
536 tma_load(shgs,
ds + ebase, CUBE_BYTES, &bar_g);
537 tma_load(shgt,
dt + ebase, CUBE_BYTES, &bar_g);
538 tma_load(shgj,
jacinv + ebase, CUBE_BYTES, &bar_g);
544 dmma_contract< 0, false, false, NW >(shr,
shdx,
shu, wf);
545 dmma_contract< 1, false, false, NW >(shs,
shdy,
shu, wf);
546 dmma_contract< 2, false, false, NW >(sht,
shdz,
shu, wf);
555 for (
int p = tid; p <
DMMA_CUBE; p += nthrds) {
556 shu[p] = shgj[p] * ((shr[p] * shgr[p])
558 + (sht[p] * shgt[p]));
568 tma_store(du + ebase,
shu, CUBE_BYTES);
585template<
typename T, const
int LX, const
int NW >
587 __device__
static void run(T * __restrict__,
588 const T * __restrict__,
589 const T * __restrict__,
590 const T * __restrict__,
591 const T * __restrict__,
592 const T * __restrict__,
593 const T * __restrict__,
594 const T * __restrict__,
595 const T * __restrict__) { }
598#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 900) && \
599 (__CUDA_ARCH__ < 1000) && NEKO_TMA_TOOLKIT
602#define NEKO_DUDXYZ_DMMA_TMA_DISPATCH(LXV) \
603 template< const int NW > \
604 struct dudxyz_dmma_tma_dispatch< double, LXV, NW > { \
605 __device__ static void run(double * __restrict__ du, \
606 const double * __restrict__ u, \
607 const double * __restrict__ dr, \
608 const double * __restrict__ ds, \
609 const double * __restrict__ dt, \
610 const double * __restrict__ dx, \
611 const double * __restrict__ dy, \
612 const double * __restrict__ dz, \
613 const double * __restrict__ jacinv) { \
614 dudxyz_dmma_tma_elem< LXV, NW >(du, u, dr, ds, dt, \
615 dx, dy, dz, jacinv); \
619NEKO_DUDXYZ_DMMA_TMA_DISPATCH(8);
623template<
typename T, const
int LX, const
int NW >
625dudxyz_kernel_dmma_tma(T * __restrict__ du,
626 const T * __restrict__
u,
627 const T * __restrict__
dr,
628 const T * __restrict__
ds,
629 const T * __restrict__
dt,
630 const T * __restrict__
dx,
631 const T * __restrict__
dy,
632 const T * __restrict__
dz,
633 const T * __restrict__
jacinv) {
__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__ x
__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)
static __device__ void run(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)
static __device__ void run(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__)