49 void *
dr,
void *
ds,
void *
dt,
50 void *
dx,
void *
dy,
void *
dz,
51 void *
jacinv,
int *nel,
int *lx,
int *eb_sel,
int *ch_sel,
52 int *nw_sel,
int *tw_sel);
60 void *
dr,
void *
ds,
void *
dt,
61 void *
dx,
void *
dy,
void *
dz,
62 void *
jacinv,
int *nel,
int *lx) {
64 static int autotune[16] = { 0 };
66 static int autotune_eb[16] = { 0 };
68 static int autotune_ch[16] = { 0 };
70 static int autotune_nw[16] = { 0 };
72 static int autotune_tw[16] = { 0 };
74 const dim3 nthrds_1d(1024, 1, 1);
75 const dim3 nthrds_kstep((*lx), (*lx), 1);
76 const dim3 nblcks((*nel), 1, 1);
79#define CASE_1D(LX, C) \
80 dudxyz_kernel_1d<real, LX, NEKO_CHUNKS(LX, C)> \
81 <<<nblcks, NEKO_CHUNKS_NTHRDS(LX, C), 0, stream>>> \
82 ((real *) du, (real *) u, \
83 (real *) dr, (real *) ds, (real *) dt, \
84 (real *) dx, (real *) dy, (real *) dz, \
86 CUDA_CHECK(cudaGetLastError());
89#define CASE_1D_SEL(LX, SEL) \
91 case 0: CASE_1D(LX, 0); break; \
92 case 1: CASE_1D(LX, 1); break; \
93 case 2: CASE_1D(LX, 2); break; \
94 default: CASE_1D(LX, 3); break; \
97#define CASE_KSTEP(LX, C) \
98 dudxyz_kernel_kstep<real, LX, NEKO_EB(LX, C)> \
99 <<<NEKO_EB_NBLCKS(*nel, LX, C), NEKO_EB_NTHRDS(LX, C), 0, stream>>> \
100 ((real *) du, (real *) u, \
101 (real *) dr, (real *) ds, (real *) dt, \
102 (real *) dx, (real *) dy, (real *) dz, \
103 (real *) jacinv, *nel); \
104 CUDA_CHECK(cudaGetLastError());
107#define CASE_KSTEP_SEL(LX, SEL) \
109 case 0: CASE_KSTEP(LX, 0); break; \
110 case 1: CASE_KSTEP(LX, 1); break; \
111 default: CASE_KSTEP(LX, 2); break; \
114#define CASE_DMMA(LX, C) \
115 dudxyz_kernel_dmma<real, LX, NEKO_DMMA_NW(C)> \
116 <<<NEKO_DMMA_NBLCKS(*nel, LX), NEKO_DMMA_NTHRDS(C), 0, stream>>> \
117 ((real *) du, (real *) u, \
118 (real *) dr, (real *) ds, (real *) dt, \
119 (real *) dx, (real *) dy, (real *) dz, \
120 (real *) jacinv, *nel); \
121 CUDA_CHECK(cudaGetLastError());
124#define CASE_DMMA_SEL(LX, SEL) \
126 case 0: CASE_DMMA(LX, 0); break; \
127 case 1: CASE_DMMA(LX, 1); break; \
128 default: CASE_DMMA(LX, 2); break; \
137#define CASE_DMMA_TMA(LX, C) \
138 dudxyz_kernel_dmma_tma<real, LX, NEKO_DMMA_NW(C)> \
139 <<<NEKO_DMMA_NBLCKS(*nel, LX), NEKO_DMMA_NTHRDS(C), 0, stream>>> \
140 ((real *) du, (real *) u, \
141 (real *) dr, (real *) ds, (real *) dt, \
142 (real *) dx, (real *) dy, (real *) dz, \
144 CUDA_CHECK(cudaGetLastError());
147#define CASE_DMMA_TMA_SEL(LX, SEL) \
149 case 0: CASE_DMMA_TMA(LX, 0); break; \
150 case 1: CASE_DMMA_TMA(LX, 1); break; \
151 default: CASE_DMMA_TMA(LX, 2); break; \
156 if(autotune[LX] == 0 ) { \
157 autotune[LX]=tune_dudxyz<LX>(du, u, \
160 jacinv, nel, lx, &autotune_eb[LX], \
161 &autotune_ch[LX], &autotune_nw[LX], \
163 } else if (autotune[LX] == 1 ) { \
164 CASE_1D_SEL(LX, autotune_ch[LX]); \
165 } else if (autotune[LX] == 2 ) { \
166 CASE_KSTEP_SEL(LX, autotune_eb[LX]); \
167 } else if (autotune[LX] == 3 ) { \
168 CASE_DMMA_SEL(LX, autotune_nw[LX]); \
169 } else if (autotune[LX] == 4 ) { \
170 CASE_DMMA_TMA_SEL(LX, autotune_tw[LX]); \
174#define CASE_LARGE(LX) \
193 fprintf(stderr, __FILE__
": size not supported: %d\n", *lx);
208 fprintf(stderr, __FILE__
": size not supported: %d\n", *lx);
216template < const
int LX >
218 void *
dr,
void *
ds,
void *
dt,
219 void *
dx,
void *
dy,
void *
dz,
220 void *
jacinv,
int *nel,
int *lx,
int *eb_sel,
int *ch_sel,
221 int *nw_sel,
int *tw_sel) {
222 cudaEvent_t start,stop;
262 const dim3 nthrds_1d(1024, 1, 1);
263 const dim3 nthrds_kstep((*lx), (*lx), 1);
264 const dim3 nblcks((*nel), 1, 1);
267 char *env_value = NULL;
268 char neko_log_buf[80];
270 env_value=getenv(
"NEKO_AUTOTUNE");
272 sprintf(neko_log_buf,
"Autotune dudxyz (lx: %d)", *lx);
288 if( !strcmp(env_value,
"1D") ) {
290 }
else if( !strcmp(env_value,
"KSTEP") ) {
292 }
else if( !strcmp(env_value,
"DMMA") ) {
296 sprintf(neko_log_buf,
"DMMA strategy not available for this config");
299 }
else if( !strcmp(env_value,
"DMMA_TMA") ) {
303 sprintf(neko_log_buf,
304 "DMMA_TMA strategy not available for this config");
308 sprintf(neko_log_buf,
"Invalid value set for NEKO_AUTOTUNE");
316 const int pin = (strat == 1) ? ch_pin : (strat == 2) ? eb_pin :
317 (strat == 3) ? nw_pin : (strat == 4) ? tw_pin : -1;
324 sprintf(neko_log_buf,
"Set by env : 1 (1D, %d chunk)",
330 sprintf(neko_log_buf,
"Set by env : 2 (KSTEP, %d elem/block)",
336 sprintf(neko_log_buf,
"Set by env : 3 (DMMA, %d warps)",
342 sprintf(neko_log_buf,
"Set by env : 4 (DMMA_TMA, %d warps)",
352 sprintf(neko_log_buf,
"Set by env : %d (%s)", strat, env_value);
357 const bool try_1d = (strat == 0 || strat == 1);
358 const bool try_kstep = (strat == 0 || strat == 2);
359 const bool try_dmma = dmma && (strat == 0 || strat == 3);
360 const bool try_tma = tma && (strat == 0 || strat == 4);
362 cudaEventCreate(&start);
363 cudaEventCreate(&stop);
384 for (
int r = 0; r < rounds; r++) {
412 if (time1[best1] < time2[best]) {
420 float tbest = (retval == 1) ? time1[best1] : time2[best];
422 if (time3[best3] < tbest) {
424 tbest = time3[best3];
426 if (time4[best4] < tbest) {
434 }
else if (retval == 2) {
436 }
else if (retval == 3) {
443 sprintf(neko_log_buf,
"Chose : 1 (1D, %d chunk)",
445 }
else if (retval == 2) {
446 sprintf(neko_log_buf,
"Chose : 2 (KSTEP, %d elem/block)",
448 }
else if (retval == 3) {
449 sprintf(neko_log_buf,
"Chose : 3 (DMMA, %d warps, %d elem/blk)",
452 sprintf(neko_log_buf,
"Chose : 4 (DMMA_TMA, %d warps)",
#define CASE_DMMA_SEL(LX, SEL)
#define CASE_KSTEP_SEL(LX, SEL)
#define CASE_1D_SEL(LX, SEL)
#define CASE_DMMA_TMA_SEL(LX, SEL)
__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__ const T *__restrict__ dr
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dt
#define NEKO_CHUNKS_CANDIDATES
#define NEKO_EB_CANDIDATES
#define NEKO_EB_SEL(LX, SEL)
#define NEKO_CHUNKS_SEL(LX, SEL)
static int neko_chunks_pin()
#define NEKO_TUNE_TIME(T, LAUNCH, LX, C, ITERS)
static int neko_tune_rounds()
#define NEKO_TUNE_LOG(LX, T1, T2)
#define NEKO_TUNE_BEST(T, BEST, N)
static int neko_tune_iters()
#define NEKO_TUNE_FOR(C, ON, PIN, N)
static int neko_eb_sweep()
#define NEKO_DMMA_CANDIDATES
static bool cuda_have_dmma()
#define NEKO_DMMA_PACK(LX)
static bool dmma_lx_supported()
#define NEKO_TUNE_LOG_DMMA(LX, T3)
static int neko_dmma_pin()
#define NEKO_TUNE_LOG_DMMA_TMA(LX, T4)
static bool dmma_tma_dudxyz_lx_supported()
static int neko_dmma_tma_pin()
static bool dmma_tma_dudxyz_aligned(const void *du, const void *u, const void *dr, const void *ds, const void *dt, const void *jacinv)
static bool cuda_have_tma()
void log_error(char *msg)
void log_message(char *msg)
void log_section(char *msg)
void cuda_dudxyz(void *du, void *u, void *dr, void *ds, void *dt, void *dx, void *dy, void *dz, void *jacinv, int *nel, int *lx)
#define CASE_DMMA_SEL(LX, SEL)
#define CASE_KSTEP_SEL(LX, SEL)
#define CASE_1D_SEL(LX, SEL)
int tune_dudxyz(void *du, void *u, void *dr, void *ds, void *dt, void *dx, void *dy, void *dz, void *jacinv, int *nel, int *lx, int *eb_sel, int *ch_sel, int *nw_sel, int *tw_sel)
#define CASE_DMMA_TMA_SEL(LX, SEL)