1#ifndef __MATH_ELEM_BLOCK_TUNE_H__
2#define __MATH_ELEM_BLOCK_TUNE_H__
62#include <hip/hip_runtime.h>
78#ifndef NEKO_EB_SWEEP_DEFAULT
79#define NEKO_EB_SWEEP_DEFAULT 1
82#define NEKO_TUNE_INIT 1.0e30f
83#define NEKO_TUNE_WARMUP 20
87 const char *
v =
getenv(
"NEKO_EB_TUNE");
90 return (
atoi(
v) != 0);
107 const char *
v =
getenv(
"NEKO_EB");
124 const char *
v =
getenv(
"NEKO_CHUNKS");
140 const char *
v =
getenv(
"NEKO_TUNE_ROUNDS");
143 return (n < 1) ? 1 : n;
148 const char *
v =
getenv(
"NEKO_TUNE_ITERS");
151 return (n < 1) ? 1 : n;
167#define NEKO_TUNE_FOR(C, ON, PIN, N) \
168 for (int C = (((PIN) >= 0) ? (PIN) : 0), \
169 C##_last_ = ((ON) ? (((PIN) >= 0) ? (PIN) + 1 : (N)) : 0); \
173#define NEKO_TUNE_TIME(T, LAUNCH, LX, C, ITERS) \
176 HIP_CHECK(hipEventRecord(start, stream)); \
177 for (int i_ = 0; i_ < (ITERS); i_++) { LAUNCH(LX, C); } \
178 HIP_CHECK(hipEventRecord(stop, stream)); \
179 HIP_CHECK(hipEventSynchronize(stop)); \
180 HIP_CHECK(hipEventElapsedTime(&t_, start, stop)); \
181 if (t_ < (T)[C]) { (T)[C] = t_; } \
193#define NEKO_TUNE_US(T, ITERS) ((T) * 1000.0 / (double) (ITERS))
195#define NEKO_TUNE_BEST(T, BEST, N) \
197 for (int c = 1; c < (N); c++) { \
198 if ((T)[c] < (T)[BEST]) { BEST = c; } \
205#define NEKO_TUNE_LOG_1D(LX, T1) \
207 for (int c = 0; c < NEKO_CHUNKS_CANDIDATES; c++) { \
208 if ((T1)[c] >= NEKO_TUNE_INIT) { continue; } \
209 sprintf(neko_log_buf, "1D ch=%-4d: %9.2f us/call", \
210 NEKO_CHUNKS_SEL(LX, c), NEKO_TUNE_US((T1)[c], iters)); \
211 log_message(neko_log_buf); \
215#define NEKO_TUNE_LOG_KSTEP(LX, T2) \
217 for (int c = 0; c < NEKO_EB_CANDIDATES; c++) { \
218 if ((T2)[c] >= NEKO_TUNE_INIT) { continue; } \
219 sprintf(neko_log_buf, "KSTEP eb=%-4d: %9.2f us/call", \
220 NEKO_EB_SEL(LX, c), NEKO_TUNE_US((T2)[c], iters)); \
221 log_message(neko_log_buf); \
226#define NEKO_TUNE_LOG(LX, T1, T2) \
228 NEKO_TUNE_LOG_1D(LX, T1); \
229 NEKO_TUNE_LOG_KSTEP(LX, T2); \
274#ifndef NEKO_TUNE_VERIFY_DEFAULT
275#define NEKO_TUNE_VERIFY_DEFAULT 1
277#define NEKO_TUNE_VERIFY_BLOCKS 256
278#define NEKO_TUNE_VERIFY_THREADS 256
279#define NEKO_TUNE_VERIFY_MAXIN 8
281#define NEKO_TUNE_MAXCAND 16
285 const char *
v =
getenv(
"NEKO_TUNE_VERIFY");
288 return (
atoi(
v) != 0);
295 const char *
v =
getenv(
"NEKO_TUNE_VERIFY_TOL");
300 return (
sizeof(
real) == 4) ? 1.0e-4 : 1.0e-10;
306 const unsigned int seed) {
309 unsigned int h = (
unsigned int)
i * 2654435761u +
seed * 40503u;
324 double md = 0.0,
mr = 0.0;
329 const double y = (
double) b[
i];
330 const double d =
fabs(
x - y);
331 const double r =
fabs(y);
344 for (
int s =
blockDim.x / 2; s > 0; s >>= 1) {
382 const int nout,
void ***ins,
const int nin,
410 for (
int i = 0;
i < nin;
i++) {
414 x, n, (
unsigned int) (
i + 1));
416 v->saved[
i] = *ins[
i];
417 *ins[
i] = (
void *)
x;
425 for (
int j = 0;
j <
v->nout;
j++) {
430 v->outs[
j], (
size_t)
v->n *
sizeof(
real),
449 for (
int j = 0;
j <
v->nout;
j++) {
462 if (part[2 * b + 1] > *
maxref) {
463 *
maxref = part[2 * b + 1];
474 for (
int i = 0;
i <
v->nin;
i++) {
475 *
v->ins[
i] =
v->saved[
i];
484#define NEKO_TUNE_VERIFY_CAND(VF, REJ, LAUNCH, LX, C, NAME) \
488 (REJ).rej[C] = !neko_tune_verify_check(&(VF), stream, &md_, &mr_); \
489 if ((REJ).rej[C]) { \
490 sprintf(neko_log_buf, \
491 "%-5s cand %2d REJECTED: |diff| %.1e, |ref| %.1e", \
492 NAME, C, md_, mr_); \
493 log_message(neko_log_buf); \
498#define NEKO_TUNE_APPLY_REJ(T, REJ, N) \
500 for (int c = 0; c < (N); c++) { \
501 if ((REJ).rej[c]) { (T)[c] = NEKO_TUNE_INIT; } \
__global__ void ale_add_kinematics_kernel(const int n, T *__restrict__ wx, T *__restrict__ wy, T *__restrict__ wz, const T *__restrict__ x_ref, const T *__restrict__ y_ref, const T *__restrict__ z_ref, const T *__restrict__ phi, const T *__restrict__ x, const T *__restrict__ y, const T *__restrict__ z, const kinematics_params_t kin_params)
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
__global__ void const T *__restrict__ x
#define NEKO_CHUNKS_CANDIDATES
#define NEKO_EB_CANDIDATES
#define NEKO_EB_SWEEP_DEFAULT
static int neko_chunks_pin()
static int neko_tune_rounds()
static int neko_tune_iters()
static int neko_eb_sweep()
#define NEKO_TUNE_VERIFY_THREADS
static void neko_tune_verify_ref(neko_tune_verify_t *v, hipStream_t stream)
static double neko_tune_verify_tol()
#define NEKO_TUNE_MAXCAND
static int neko_tune_verify_check(neko_tune_verify_t *v, hipStream_t stream, double *maxdiff, double *maxref)
static void neko_tune_verify_end(neko_tune_verify_t *v, hipStream_t stream)
static int neko_tune_verify_on()
#define NEKO_TUNE_VERIFY_MAXIN
static __global__ void neko_tune_fill_kernel(real *__restrict__ x, const int n, const unsigned int seed)
#define NEKO_TUNE_VERIFY_DEFAULT
#define NEKO_TUNE_VERIFY_BLOCKS
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)
static __global__ void neko_tune_diff_kernel(const real *__restrict__ a, const real *__restrict__ b, const int n, double *__restrict__ part)