Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
opr_opgrad.cu
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 "opgrad_kernel.h"
40#include <device/cuda/check.h>
41
42extern "C" {
43 #include <common/neko_log.h>
44}
45
46template < const int >
47int tune_opgrad(void *ux, void *uy, void *uz, void *u,
48 void *dx, void *dy, void *dz,
49 void *drdx, void *dsdx, void *dtdx,
50 void *drdy, void *dsdy, void *dtdy,
51 void *drdz, void *dsdz, void *dtdz,
52 void *w3, int *nel, int *lx);
53
54extern "C" {
55
59 void cuda_opgrad(void *ux, void *uy, void *uz, void *u,
60 void *dx, void *dy, void *dz,
61 void *drdx, void *dsdx, void *dtdx,
62 void *drdy, void *dsdy, void *dtdy,
63 void *drdz, void *dsdz, void *dtdz,
64 void *w3, int *nel, int *lx) {
65
66 static int autotune[17] = { 0 };
67
68 const dim3 nthrds_1d(1024, 1, 1);
69 const dim3 nthrds_kstep((*lx), (*lx), 1);
70 const dim3 nblcks((*nel), 1, 1);
71 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
72
73#define CASE_1D(LX) \
74 opgrad_kernel_1d<real, LX, 1024> \
75 <<<nblcks, nthrds_1d, 0, stream>>> \
76 ((real *) ux, (real *) uy, (real *) uz, (real *) u, \
77 (real *) dx, (real *) dy, (real *) dz, \
78 (real *) drdx, (real *) dsdx, (real *) dtdx, \
79 (real *) drdy, (real *) dsdy, (real *) dtdy, \
80 (real *) drdz, (real *) dsdz, (real *) dtdz, \
81 (real *) w3); \
82 CUDA_CHECK(cudaGetLastError());
83
84
85#define CASE_KSTEP(LX) \
86 opgrad_kernel_kstep<real, LX> <<<nblcks, nthrds_kstep, 0, stream>>> \
87 ((real *) ux, (real *) uy, (real *) uz, (real *) u, \
88 (real *) dx, (real *) dy, (real *) dz, \
89 (real *) drdx, (real *) dsdx, (real *) dtdx, \
90 (real *) drdy, (real *) dsdy, (real *) dtdy, \
91 (real *) drdz, (real *) dsdz, (real *) dtdz, \
92 (real *) w3); \
93 CUDA_CHECK(cudaGetLastError());
94
95#define CASE(LX) \
96 case LX: \
97 if(autotune[LX] == 0 ) { \
98 autotune[LX]=tune_opgrad<LX>(ux, uy, uz, u, \
99 dx, dy, dz, \
100 drdx, dsdx, dtdx, \
101 drdy, dsdy, dtdy, \
102 drdz, dsdz, dtdz, \
103 w3, nel, lx); \
104 } else if (autotune[LX] == 1 ) { \
105 CASE_1D(LX); \
106 } else if (autotune[LX] == 2 ) { \
107 CASE_KSTEP(LX); \
108 } \
109 break
110
111 switch(*lx) {
112 CASE(2);
113 CASE(3);
114 CASE(4);
115 CASE(5);
116 CASE(6);
117 CASE(7);
118 CASE(8);
119 CASE(9);
120 CASE(10);
121 CASE(11);
122 CASE(12);
123 CASE(13);
124 CASE(14);
125 CASE(15);
126 CASE(16);
127 default:
128 {
129 fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
130 exit(1);
131 }
132 }
133 }
134}
135
136template < const int LX >
137int tune_opgrad(void *ux, void *uy, void *uz, void *u,
138 void *dx, void *dy, void *dz,
139 void *drdx, void *dsdx, void *dtdx,
140 void *drdy, void *dsdy, void *dtdy,
141 void *drdz, void *dsdz, void *dtdz,
142 void *w3, int *nel, int *lx) {
144 float time1,time2;
145 int retval;
146
147 const dim3 nthrds_1d(1024, 1, 1);
148 const dim3 nthrds_kstep((*lx), (*lx), 1);
149 const dim3 nblcks((*nel), 1, 1);
150 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
151
152 char *env_value = NULL;
153 char neko_log_buf[80];
154
155 env_value=getenv("NEKO_AUTOTUNE");
156
157 sprintf(neko_log_buf, "Autotune opgrad (lx: %d)", *lx);
159
160 if(env_value) {
161 if( !strcmp(env_value,"1D") ) {
162 CASE_1D(LX);
163 sprintf(neko_log_buf,"Set by env : 1 (1D)");
166 return 1;
167 } else if( !strcmp(env_value,"KSTEP") ) {
168 CASE_KSTEP(LX);
169 sprintf(neko_log_buf,"Set by env : 2 (KSTEP)");
172 return 2;
173 } else {
174 sprintf(neko_log_buf, "Invalid value set for NEKO_AUTOTUNE");
176 }
177 }
178
181
183
184 for(int i = 0; i < 100; i++) {
185 CASE_1D(LX);
186 }
187
191
193
194 for(int i = 0; i < 100; i++) {
195 CASE_KSTEP(LX);
196 }
197
201
202 if(time1 < time2) {
203 retval = 1;
204 } else {
205 retval = 2;
206 }
207
208 sprintf(neko_log_buf, "Chose : %d (%s)", retval,
209 (retval > 1 ? "KSTEP" : "1D"));
212 return retval;
213}
214
__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__ drdy
__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__ drdz
__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__ dsdz
__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__ dsdy
const int i
__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__ dtdy
__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__ const T *__restrict__ const T *__restrict__ drdx
__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__ dtdz
__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__ dsdx
__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__ dtdx
__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__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w3
__global__ void dirichlet_apply_scalar_kernel(const int *__restrict__ msk, T *__restrict__ x, const T g, const int m)
__global__ void T *__restrict__ uy
__global__ void T *__restrict__ T *__restrict__ uz
void log_error(char *msg)
void log_message(char *msg)
void log_end_section()
void log_section(char *msg)
#define CASE(LX)
int tune_opgrad(void *ux, void *uy, void *uz, void *u, void *dx, void *dy, void *dz, void *drdx, void *dsdx, void *dtdx, void *drdy, void *dsdy, void *dtdy, void *drdz, void *dsdz, void *dtdz, void *w3, int *nel, int *lx)
#define CASE_KSTEP(LX)
void cuda_opgrad(void *ux, void *uy, void *uz, void *u, void *dx, void *dy, void *dz, void *drdx, void *dsdx, void *dtdx, void *drdy, void *dsdy, void *dtdy, void *drdz, void *dsdz, void *dtdz, void *w3, int *nel, int *lx)
Definition opr_opgrad.cu:59
#define CASE_1D(LX)