38#include <hip/hip_runtime.h>
50 void *
dr,
void *
ds,
void *
dt,
52 void *
w3,
int *nel,
int *lx,
int *eb_sel,
int *ch_sel,
61 void *
dr,
void *
ds,
void *
dt,
63 void *
w3,
int *nel,
int *lx) {
65 static int autotune[17] = { 0 };
67 static int autotune_eb[17] = { 0 };
69 static int autotune_ch[17] = { 0 };
71 static int autotune_nwf[17] = { 0 };
73 const dim3 nthrds_1d(1024, 1, 1);
74 const dim3 nthrds_kstep((*lx), (*lx), 1);
75 const dim3 nblcks((*nel), 1, 1);
77#define CASE_1D(LX, C) \
78 hipLaunchKernelGGL( HIP_KERNEL_NAME( \
79 cdtp_kernel_1d<real, LX, NEKO_CHUNKS(LX, C)> ), \
80 nblcks, NEKO_CHUNKS_NTHRDS(LX, C), 0, \
81 (hipStream_t) glb_cmd_queue, \
82 (real *) dtx, (real *) x, \
83 (real *) dr, (real *) ds, (real *) dt, \
84 (real *) dxt, (real *) dyt, (real *) dzt, \
86 HIP_CHECK(hipGetLastError());
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 hipLaunchKernelGGL( HIP_KERNEL_NAME( \
99 cdtp_kernel_kstep<real, LX, NEKO_EB(LX, C)> ), \
100 NEKO_EB_NBLCKS(*nel, LX, C), NEKO_EB_NTHRDS(LX, C), 0, \
101 (hipStream_t) glb_cmd_queue, \
102 (real *) dtx, (real *) x, \
103 (real *) dr, (real *) ds, (real *) dt, \
104 (real *) dxt, (real *) dyt, (real *) dzt, \
105 (real *) w3, *nel); \
106 HIP_CHECK(hipGetLastError());
109#define CASE_KSTEP_SEL(LX, SEL) \
111 case 0: CASE_KSTEP(LX, 0); break; \
112 case 1: CASE_KSTEP(LX, 1); break; \
113 default: CASE_KSTEP(LX, 2); break; \
116#define CASE_MFMA(LX, C) \
117 hipLaunchKernelGGL( HIP_KERNEL_NAME( \
118 cdtp_kernel_mfma<real, LX, NEKO_MFMA_NWF(C), \
119 NEKO_MFMA_TILE(C)> ), \
120 NEKO_MFMA_NBLCKS(*nel, LX, C), NEKO_MFMA_NTHRDS(C), 0, \
121 (hipStream_t) glb_cmd_queue, \
122 (real *) dtx, (real *) x, \
123 (real *) dr, (real *) ds, (real *) dt, \
124 (real *) dxt, (real *) dyt, (real *) dzt, \
125 (real *) w3, *nel); \
126 HIP_CHECK(hipGetLastError());
130#define CASE_MFMA_SEL(LX, SEL) \
132 case 0: CASE_MFMA(LX, 0); break; \
133 case 1: CASE_MFMA(LX, 1); break; \
134 case 2: CASE_MFMA(LX, 2); break; \
135 case 3: CASE_MFMA(LX, 3); break; \
136 case 4: CASE_MFMA(LX, 4); break; \
137 case 5: CASE_MFMA(LX, 5); break; \
138 case 6: CASE_MFMA(LX, 6); break; \
139 case 7: CASE_MFMA(LX, 7); break; \
140 case 8: CASE_MFMA(LX, 8); break; \
141 default: CASE_MFMA(LX, 9); break; \
148 "CASE_MFMA_SEL does not cover the candidate space");
152 if(autotune[LX] == 0 ) { \
153 autotune[LX]=tune_cdtp<LX>(dtx, x, \
156 w3, nel, lx, &autotune_eb[LX], \
158 &autotune_nwf[LX]); \
159 } else if (autotune[LX] == 1 ) { \
160 CASE_1D_SEL(LX, autotune_ch[LX]); \
161 } else if (autotune[LX] == 2 ) { \
162 CASE_KSTEP_SEL(LX, autotune_eb[LX]); \
163 } else if (autotune[LX] == 3 ) { \
164 CASE_MFMA_SEL(LX, autotune_nwf[LX]); \
168#define CASE_LARGE(LX) \
189 fprintf(stderr, __FILE__
": size not supported: %d\n", *lx);
202 fprintf(stderr, __FILE__
": size not supported: %d\n", *lx);
210template < const
int LX >
212 void *
dr,
void *
ds,
void *
dt,
214 void *
w3,
int *nel,
int *lx,
int *eb_sel,
int *ch_sel,
216 hipEvent_t start,stop;
250 const dim3 nthrds_1d(1024, 1, 1);
251 const dim3 nthrds_kstep((*lx), (*lx), 1);
252 const dim3 nblcks((*nel), 1, 1);
255 char *env_value = NULL;
256 char neko_log_buf[80];
258 env_value=getenv(
"NEKO_AUTOTUNE");
260 sprintf(neko_log_buf,
"Autotune cdtp (lx: %d)", *lx);
274 if( !strcmp(env_value,
"1D") ) {
276 }
else if( !strcmp(env_value,
"KSTEP") ) {
278 }
else if( !strcmp(env_value,
"MFMA") ) {
282 sprintf(neko_log_buf,
"MFMA strategy not available for this config");
286 sprintf(neko_log_buf,
"Invalid value set for NEKO_AUTOTUNE");
294 const int pin = (strat == 1) ? ch_pin : (strat == 2) ? eb_pin :
295 (strat == 3) ? nwf_pin : -1;
302 sprintf(neko_log_buf,
"Set by env : 1 (1D, %d chunk)",
308 sprintf(neko_log_buf,
"Set by env : 2 (KSTEP, %d elem/block)",
314 sprintf(neko_log_buf,
"Set by env : 3 (MFMA %s, %d wf, %d elem/blk)",
324 sprintf(neko_log_buf,
"Set by env : %d (%s)", strat, env_value);
331 const bool try_1d = (strat == 0 || strat == 1);
332 const bool try_kstep = (strat == 0 || strat == 2);
333 const bool try_mfma = mfma && ((strat == 3) ||
347 void **vins[] = { &
x };
349 (*nel) * LX * LX * LX, stream)) {
350 sprintf(neko_log_buf,
"Verify : rel tol %.1e, synthetic input",
367 "skipped, no memory for it" :
"off (NEKO_TUNE_VERIFY=0)");
388 for (
int r = 0; r < rounds; r++) {
416 if (time1[best1] < time2[best]) {
424 if (time3[best3] < ((retval == 1) ? time1[best1] : time2[best])) {
432 }
else if (retval == 2) {
439 sprintf(neko_log_buf,
"Chose : 1 (1D, %d chunk)",
441 }
else if (retval == 2) {
442 sprintf(neko_log_buf,
"Chose : 2 (KSTEP, %d elem/block)",
445 sprintf(neko_log_buf,
"Chose : 3 (MFMA %s, %d wf, %d elem/blk)",
#define CASE_KSTEP_SEL(LX, SEL)
#define CASE_1D_SEL(LX, SEL)
#define CASE_MFMA_SEL(LX, SEL)
__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__ ds
__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__ x
__global__ void const T *__restrict__ const T *__restrict__ dr
__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__ dxt
__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
#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()
static void neko_tune_verify_ref(neko_tune_verify_t *v, hipStream_t stream)
#define NEKO_TUNE_VERIFY_CAND(VF, REJ, LAUNCH, LX, C, NAME)
static void neko_tune_verify_end(neko_tune_verify_t *v, hipStream_t stream)
static int neko_tune_verify_on()
static int neko_tune_verify_begin(neko_tune_verify_t *v, real **outs, const int nout, void ***ins, const int nin, const int n, hipStream_t stream)
#define NEKO_TUNE_APPLY_REJ(T, REJ, N)
static bool mfma_lx_supported()
#define NEKO_TUNE_LOG_MFMA(LX, T3)
static const char * mfma_tile_name(const int c)
#define NEKO_MFMA_CANDIDATES
static int neko_mfma_pin()
static int neko_mfma_candidates()
static bool hip_have_mfma()
#define NEKO_MFMA_EB(LX, C)
static int neko_mfma_sweep()
void log_error(char *msg)
void log_message(char *msg)
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, int *eb_sel, int *ch_sel, int *nwf_sel)
#define CASE_KSTEP_SEL(LX, SEL)
#define CASE_1D_SEL(LX, SEL)
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)
#define CASE_MFMA_SEL(LX, SEL)