Neko 1.99.1
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
opr_convect_scalar.hip
Go to the documentation of this file.
1/*
2 Copyright (c) 2021-2023, 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 <string.h>
36#include <stdlib.h>
37#include <stdio.h>
38#include <hip/hip_runtime.h>
40#include <device/hip/check.h>
42
43extern "C" {
44 #include <common/neko_log.h>
45}
46
47template < const int >
48int tune_convect_scalar(void *du, void *u,
49 void *cr, void *cs, void *ct,
50 void *dx, void *dy, void *dz,
51 int *nel, int *lx);
52
53extern "C" {
54
58 void hip_convect_scalar(void *du, void *u,
59 void *cr, void *cs, void *ct,
60 void *dx, void *dy, void *dz,
61 int *nel, int *lx) {
62
63 static int autotune[17] = { 0 };
64
65 const dim3 nthrds_1d(1024, 1, 1);
66 const dim3 nthrds_kstep((*lx), (*lx), 1);
67 const dim3 nblcks((*nel), 1, 1);
68
69#define CASE_1D(LX) \
70 hipLaunchKernelGGL( HIP_KERNEL_NAME(convect_scalar_kernel_1d<real, LX, 1024> ), \
71 nblcks, nthrds_1d, 0, (hipStream_t) glb_cmd_queue, \
72 (real *) du, (real *) u, \
73 (real *) cr, (real *) cs, (real *) ct, \
74 (real *) dx, (real *) dy, (real *) dz); \
75 HIP_CHECK(hipGetLastError());
76
77#define CASE_KSTEP(LX) \
78 hipLaunchKernelGGL( HIP_KERNEL_NAME(convect_scalar_kernel_kstep<real, LX> ), \
79 nblcks, nthrds_kstep, 0, (hipStream_t) glb_cmd_queue, \
80 (real *) du, (real *) u, \
81 (real *) cr, (real *) cs, (real *) ct, \
82 (real *) dx, (real *) dy, (real *) dz); \
83 HIP_CHECK(hipGetLastError());
84
85#define CASE(LX) \
86 case LX: \
87 if(autotune[LX] == 0 ) { \
88 autotune[LX]=tune_convect_scalar<LX>(du, u, \
89 cr, cs, ct, \
90 dx, dy, dz, \
91 nel, lx); \
92 } else if (autotune[LX] == 1 ) { \
93 CASE_1D(LX); \
94 } else if (autotune[LX] == 2 ) { \
95 CASE_KSTEP(LX); \
96 } \
97 break
98
99#define CASE_LARGE(LX) \
100 case LX: \
101 CASE_KSTEP(LX); \
102 break
103
104
105 if ((*lx) < 11) {
106 switch(*lx) {
107 CASE(2);
108 CASE(3);
109 CASE(4);
110 CASE(5);
111 CASE(6);
112 CASE(7);
113 CASE(8);
114 CASE(9);
115 CASE(10);
116 default:
117 {
118 fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
119 exit(1);
120 }
121 }
122 }
123 else {
124 switch(*lx) {
125 CASE_LARGE(11);
126 CASE_LARGE(12);
127 CASE_LARGE(13);
128 CASE_LARGE(14);
129 CASE_LARGE(15);
130 CASE_LARGE(16);
131 default:
132 {
133 fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
134 exit(1);
135 }
136 }
137 }
138 }
139}
140
141template < const int LX >
142int tune_convect_scalar(void *du, void *u,
143 void *cr, void *cs, void *ct,
144 void *dx, void *dy, void *dz,
145 int *nel, int *lx) {
147 float time1,time2;
148 int retval;
149
150 const dim3 nthrds_1d(1024, 1, 1);
151 const dim3 nthrds_kstep((*lx), (*lx), 1);
152 const dim3 nblcks((*nel), 1, 1);
153
154 char *env_value = NULL;
155 char neko_log_buf[80];
156
157 env_value=getenv("NEKO_AUTOTUNE");
158
159 sprintf(neko_log_buf, "Autotune convect_scalar (lx: %d)", *lx);
161
162 if(env_value) {
163 if( !strcmp(env_value,"1D") ) {
164 CASE_1D(LX);
165 sprintf(neko_log_buf,"Set by env : 1 (1D)");
168 return 1;
169 } else if( !strcmp(env_value,"KSTEP") ) {
170 CASE_KSTEP(LX);
171 sprintf(neko_log_buf,"Set by env : 2 (KSTEP)");
174 return 2;
175 } else {
176 sprintf(neko_log_buf, "Invalid value set for NEKO_AUTOTUNE");
178 }
179 }
180
183
185
186 for(int i = 0; i < 100; i++) {
187 CASE_1D(LX);
188 }
189
193
195
196 for(int i = 0; i < 100; i++) {
197 CASE_KSTEP(LX);
198 }
199
203
204 if(time1 < time2) {
205 retval = 1;
206 } else {
207 retval = 2;
208 }
209
210 sprintf(neko_log_buf, "Chose : %d (%s)", retval,
211 (retval > 1 ? "KSTEP" : "1D"));
214 return retval;
215}
const int i
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dy
__global__ void const T *__restrict__ const T *__restrict__ cr
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ cs
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ ct
__global__ void dirichlet_apply_scalar_kernel(const int *__restrict__ msk, T *__restrict__ x, const T g, const int m)
#define HIP_CHECK(err)
Definition check.h:8
void log_error(char *msg)
void log_message(char *msg)
void log_end_section()
void log_section(char *msg)
#define CASE(LX)
#define CASE_KSTEP(LX)
#define CASE_LARGE(LX)
#define CASE_1D(LX)
int tune_convect_scalar(void *du, void *u, void *cr, void *cs, void *ct, void *dx, void *dy, void *dz, int *nel, int *lx)
void hip_convect_scalar(void *du, void *u, void *cr, void *cs, void *ct, void *dx, void *dy, void *dz, int *nel, int *lx)