Neko 1.99.7
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
pc_jacobi.hip
Go to the documentation of this file.
1/*
2 Copyright (c) 2021-2026, The Neko Authors
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16
17 * Neither the name of the authors nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33*/
34
35#include <hip/hip_runtime.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <device/hip/check.h>
40
41template< typename T, const int LX >
43 const T * __restrict__ dxt,
44 const T * __restrict__ dyt,
45 const T * __restrict__ dzt,
46 const T * __restrict__ G11,
47 const T * __restrict__ G22,
48 const T * __restrict__ G33,
49 const T * __restrict__ G12,
50 const T * __restrict__ G13,
51 const T * __restrict__ G23,
52 const int nel) {
53 const int idx = threadIdx.x + blockIdx.x * blockDim.x;
54 const int e = idx / (LX*LX*LX);
55 const int ijk = idx - e*LX*LX*LX;
56 const int jk = ijk / LX;
57 const int i = ijk - jk * LX;
58 const int k = jk / LX;
59 const int j = jk - k * LX;
60
61
62
63 if (e >= nel)
64 return;
65
66 T d = 0.0;
67
68 for (int l = 0; l < LX; l++) {
69 T g = G11[l + LX*j + LX*LX*k + LX*LX*LX*e];
70 T t = dxt[i + LX*l];
71 d += g*t*t;
72 }
73
74 for (int l = 0; l < LX; l++) {
75 T g = G22[i + LX*l + LX*LX*k + LX*LX*LX*e];
76 T t = dyt[j + LX*l];
77 d += g*t*t;
78 }
79
80 for (int l = 0; l < LX; l++) {
81 T g = G33[i + LX*j + LX*LX*l + LX*LX*LX*e];
82 T t = dzt[k + LX*l];
83 d += g*t*t;
84 }
85
86 // Corrections for deformed elements
87 if (i == 0 || i == LX-1) {
88 d += G12[i + LX*j + LX*LX*k + LX*LX*LX*e] * dxt[i + LX*i] * dyt[j + LX*j];
89 d += G13[i + LX*j + LX*LX*k + LX*LX*LX*e] * dxt[i + LX*i] * dzt[k + LX*k];
90 }
91
92 if (j == 0 || j == LX-1) {
93 d += G12[i + LX*j + LX*LX*k + LX*LX*LX*e] * dyt[j + LX*j] * dxt[i + LX*i];
94 d += G23[i + LX*j + LX*LX*k + LX*LX*LX*e] * dyt[j + LX*j] * dzt[k + LX*k];
95 }
96
97 if (k == 0 || k == LX-1) {
98 d += G13[i + LX*j + LX*LX*k + LX*LX*LX*e] * dzt[k + LX*k] * dxt[i + LX*i];
99 d += G23[i + LX*j + LX*LX*k + LX*LX*LX*e] * dzt[k + LX*k] * dyt[j + LX*j];
100 }
101
102
103
104 du[idx] = d;
105}
106
107extern "C" {
108 void hip_jacobi_update(void *d,
109 void *dxt, void *dyt, void *dzt,
110 void *G11, void *G22, void *G33,
111 void *G12, void *G13, void *G23,
112 int *nel, int *lxp) {
113
114 const int lx = *lxp;
115 const int threads = 1024;
116 const int blocks = ((*nel * lx*lx*lx) + threads - 1) / threads;
117
118#define CASE(N)\
119 case N:\
120 hipLaunchKernelGGL(HIP_KERNEL_NAME( jacobi_kernel<real, N> ),\
121 blocks, threads, 0, (hipStream_t) glb_cmd_queue,\
122 (real *) d,\
123 (real *) dxt, (real *) dyt, (real *) dzt,\
124 (real *) G11, (real *) G22, (real *) G33,\
125 (real *) G12, (real *) G13, (real *) G23,\
126 *nel);\
127 break
128
129 switch (lx) {
130 CASE(1);
131 CASE(2);
132 CASE(3);
133 CASE(4);
134 CASE(5);
135 CASE(6);
136 CASE(7);
137 CASE(8);
138 CASE(9);
139 CASE(10);
140 CASE(11);
141 CASE(12);
142 CASE(13);
143 CASE(14);
144 CASE(15);
145 CASE(16);
146 default:
147 {
148 fprintf(stderr, __FILE__ ": size not supported: %d\n", lx);
149 exit(1);
150 }
151 }
152
154 }
155}
__global__ void ale_add_kinematics_kernel(const int n, T *__restrict__ wx, T *__restrict__ wy, T *__restrict__ wz, const T *__restrict__ x_ref, const T *__restrict__ y_ref, const T *__restrict__ z_ref, const T *__restrict__ phi, const T *__restrict__ x, const T *__restrict__ y, const T *__restrict__ z, const kinematics_params_t kin_params)
const int i
const int e
const int j
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dzt
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dyt
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dxt
#define HIP_CHECK(err)
Definition check.h:8
#define CASE(N)
void hip_jacobi_update(void *d, void *dxt, void *dyt, void *dzt, void *G11, void *G22, void *G33, void *G12, void *G13, void *G23, int *nel, int *lxp)
__global__ void jacobi_kernel(T *__restrict__ du, const T *__restrict__ dxt, const T *__restrict__ dyt, const T *__restrict__ dzt, const T *__restrict__ G11, const T *__restrict__ G22, const T *__restrict__ G33, const T *__restrict__ G12, const T *__restrict__ G13, const T *__restrict__ G23, const int nel)
Definition pc_jacobi.hip:42