Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
opr_cdtp.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>
41#include "cdtp_kernel.h"
42
43extern "C" {
44 #include <common/neko_log.h>
45}
46
47template < const int >
48int tune_cdtp(void *dtx, void *x,
49 void *dr, void *ds, void *dt,
50 void *dxt, void *dyt, void *dzt,
51 void *w3, int *nel, int *lx);
52
53extern "C" {
54
58 void hip_cdtp(void *dtx, void *x,
59 void *dr, void *ds, void *dt,
60 void *dxt, void *dyt, void *dzt,
61 void *w3, 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(cdtp_kernel_1d<real, LX, 1024> ), \
71 nblcks, nthrds_1d, 0, (hipStream_t) glb_cmd_queue, \
72 (real *) dtx, (real *) x, \
73 (real *) dr, (real *) ds, (real *) dt, \
74 (real *) dxt, (real *) dyt, (real *) dzt, \
75 (real *) w3); \
76 HIP_CHECK(hipGetLastError());
77
78#define CASE_KSTEP(LX) \
79 hipLaunchKernelGGL( HIP_KERNEL_NAME(cdtp_kernel_kstep<real, LX> ), \
80 nblcks, nthrds_kstep, 0, (hipStream_t) glb_cmd_queue, \
81 (real *) dtx, (real *) x, \
82 (real *) dr, (real *) ds, (real *) dt, \
83 (real *) dxt, (real *) dyt, (real *) dzt, \
84 (real *) w3); \
85 HIP_CHECK(hipGetLastError());
86
87#define CASE(LX) \
88 case LX: \
89 if(autotune[LX] == 0 ) { \
90 autotune[LX]=tune_cdtp<LX>(dtx, x, \
91 dr, ds, dt, \
92 dxt, dyt, dzt, \
93 w3, nel, lx); \
94 } else if (autotune[LX] == 1 ) { \
95 CASE_1D(LX); \
96 } else if (autotune[LX] == 2 ) { \
97 CASE_KSTEP(LX); \
98 } \
99 break
100
101#define CASE_LARGE(LX) \
102 case LX: \
103 CASE_KSTEP(LX); \
104 break
105
106
107 if ((*lx) < 13) {
108 switch(*lx) {
109 CASE(2);
110 CASE(3);
111 CASE(4);
112 CASE(5);
113 CASE(6);
114 CASE(7);
115 CASE(8);
116 CASE(9);
117 CASE(10);
118 CASE(11);
119 CASE(12);
120 default:
121 {
122 fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
123 exit(1);
124 }
125 }
126 }
127 else {
128 switch(*lx) {
129 CASE_LARGE(13);
130 CASE_LARGE(14);
131 CASE_LARGE(15);
132 CASE_LARGE(16);
133 default:
134 {
135 fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
136 exit(1);
137 }
138 }
139 }
140 }
141}
142
143template < const int LX >
144int tune_cdtp(void *dtx, void *x,
145 void *dr, void *ds, void *dt,
146 void *dxt, void *dyt, void *dzt,
147 void *w3, int *nel, int *lx) {
149 float time1,time2;
150 int retval;
151
152 const dim3 nthrds_1d(1024, 1, 1);
153 const dim3 nthrds_kstep((*lx), (*lx), 1);
154 const dim3 nblcks((*nel), 1, 1);
155
156 char *env_value = NULL;
157 char neko_log_buf[80];
158
159 env_value=getenv("NEKO_AUTOTUNE");
160
161 sprintf(neko_log_buf, "Autotune cdtp (lx: %d)", *lx);
163
164 if(env_value) {
165 if( !strcmp(env_value,"1D") ) {
166 CASE_1D(LX);
167 sprintf(neko_log_buf,"Set by env : 1 (1D)");
170 return 1;
171 } else if( !strcmp(env_value,"KSTEP") ) {
172 CASE_KSTEP(LX);
173 sprintf(neko_log_buf,"Set by env : 2 (KSTEP)");
176 return 2;
177 } else {
178 sprintf(neko_log_buf, "Invalid value set for NEKO_AUTOTUNE");
180 }
181 }
182
185
187
188 for(int i = 0; i < 100; i++) {
189 CASE_1D(LX);
190 }
191
195
197
198 for(int i = 0; i < 100; i++) {
199 CASE_KSTEP(LX);
200 }
201
205
206 if(time1 < time2) {
207 retval = 1;
208 } else {
209 retval = 2;
210 }
211
212 sprintf(neko_log_buf, "Chose : %d (%s)", retval,
213 (retval > 1 ? "KSTEP" : "1D"));
216 return retval;
217}
const int i
__global__ void const T *__restrict__ const T *__restrict__ dr
__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__ const T *__restrict__ const T *__restrict__ dt
__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__ w3
__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
__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)
int tune_cdtp(void *dtx, void *x, void *dr, void *ds, void *dt, void *dxt, void *dyt, void *dzt, void *w3, int *nel, int *lx)
Definition opr_cdtp.hip:144
#define CASE(LX)
#define CASE_KSTEP(LX)
void hip_cdtp(void *dtx, void *x, void *dr, void *ds, void *dt, void *dxt, void *dyt, void *dzt, void *w3, int *nel, int *lx)
Definition opr_cdtp.hip:58
#define CASE_LARGE(LX)
#define CASE_1D(LX)