26#include "builtin_enums.h"
32#include "profiles_info.h"
33#include "scalar_reduce_buffer_defs.h"
34#include "user_built-in_constants.h"
35#include "user_defines.h"
36#include "user_input_typedefs.h"
39#if AC_RUNTIME_COMPILATION
43#ifndef AC_RUNTIME_SOURCE
52#include "is_array_param.h"
53#include "is_comptime_param.h"
54#include "is_output_param.h"
57#define AC_INDEX_ORDER(i,j,k,x,y,z) \
60#define DEVICE_INLINE __device__ __forceinline__
62#define AC_SIZE(arr) sizeof(arr)/sizeof(arr[0])
65#if defined(__cplusplus) || (__STDC_VERSION__ >= 202311L)
66#define CONSTEXPR constexpr
67#define MAYBE_UNUSED [[maybe_unused]]
101#define NUM_REDUCE_SCRATCHPADS (2)
111#include "output_decl.h"
116#include "comp_loaded_decl.h"
118#include "loaded_info_access_operators.h"
123#include "comp_loaded_decl.h"
125#include "loaded_info_access_operators.h"
130#include "comp_decl.h"
132#include "comp_info_access_operators.h"
142typedef struct AcMeshInfoLoaded {
143#include "info_loaded_decl.h"
146#include "info_loaded_operator_decl.h"
152#include "device_mesh_info_decl.h"
158#include "device_mesh_info_decl.h"
159#include "array_decl.h"
172#include "info_access_operators.h"
177#include "input_decl.h"
186 void*
in[NUM_VTXBUF_HANDLES];
187 void*
out[NUM_VTXBUF_HANDLES];
198#if AC_DOUBLE_PRECISION
236#include "scalar_reduce_buffers_in_vba.h"
249acGetFieldHalos(
const AcMeshInfo info,
const VertexBufferHandle vtxbuf)
252 if( vtxbuf_compile_time_halos[vtxbuf].x != -1
253 && vtxbuf_compile_time_halos[vtxbuf].y != -1
254 && vtxbuf_compile_time_halos[vtxbuf].z != -1
257 return vtxbuf_compile_time_halos[vtxbuf];
259 return info.int3_params[vtxbuf_run_time_halos[vtxbuf]];
298 FUNC_DEFINE(
AcResult,
acLaunchKernelBase,(
const AcKernel kernel,
const int3 start,
const int3 end,
VertexBufferArray vba,
const dim3 bpg,
const dim3 tpb,
const size_t smem,
const cudaStream_t stream,
bool perform_error_check));
315#include "load_and_store_uniform_header.h"
330prof_count(
const Profile prof,
const size3_t counts)
332 if(NUM_PROFILES == 0)
return 0;
334 prof_types[prof] ==
PROFILE_X ? counts.x :
335 prof_types[prof] ==
PROFILE_Y ? counts.y :
336 prof_types[prof] ==
PROFILE_Z ? counts.z :
337 prof_types[prof] ==
PROFILE_XY ? counts.x*counts.y :
338 prof_types[prof] ==
PROFILE_XZ ? counts.x*counts.z :
339 prof_types[prof] ==
PROFILE_YX ? counts.y*counts.x :
340 prof_types[prof] ==
PROFILE_YZ ? counts.y*counts.z :
341 prof_types[prof] ==
PROFILE_ZX ? counts.z*counts.x :
342 prof_types[prof] ==
PROFILE_ZY ? counts.z*counts.y :
346prof_size(
const Profile prof,
const size3_t counts)
348 return prof_count(prof,counts)*
sizeof(
AcReal);
354#if AC_RUNTIME_COMPILATION
365 const AcComplex value);
367#if AC_DOUBLE_PRECISION
373#ifndef AC_RUNTIME_SOURCE
374#include "load_comp_info.h"
392#if AC_DOUBLE_PRECISION
412#define GEN_LOAD_COMP_INFO(PARAM_TYPE,VAL_TYPE,TYPE) \
413 static AcResult __attribute__((unused)) acLoadCompInfo(const PARAM_TYPE param, const VAL_TYPE val, AcCompInfo* info) {return acLoad##TYPE##CompInfo(param,val,info);};
414#include "load_comp_info_overloads.h"
415#include "load_ac_kernel_params_def.h"
419 template <
typename P>
420 constexpr static array_info
421 get_array_info(
const P array)
423#include "get_array_info.h"
425 return (array_info){};
429 get_name(
const AcRealOutputParam&
param)
431 if constexpr(NUM_REAL_OUTPUTS == 0)
return "NO REAL OUTPUTS";
432 return real_output_names[
param];
435 get_name(
const AcIntOutputParam&
param)
437 if constexpr(NUM_INT_OUTPUTS == 0)
return "NO INT OUTPUTS";
438 else return int_output_names[
param];
440#if AC_DOUBLE_PRECISION
442 get_name(
const AcFloatOutputParam&
param)
444 if constexpr(NUM_FLOAT_OUTPUTS == 0)
return "NO FLOAT OUTPUTS";
445 else return float_output_names[
param];
450 get_name(
const Profile&
param)
452 if constexpr(NUM_PROFILES==0)
return "NO_PROFILES";
453 else return profile_names[
param];
457 get_name(
const Field&
param)
459 return field_names[
param];
462 template <
typename P>
463 constexpr const char*
464 get_array_name(
const P array)
466 return get_array_info(array).name;
469 template <
typename P>
470 constexpr const char*
471 get_param_name(
const P
param)
473#include "get_param_name.h"
479 template <
typename P>
480 constexpr static const char*
481 get_name(
const P
param)
483 if constexpr (IsArrayParam(
param))
return get_array_name(
param);
484 else return get_param_name(
param);
487 template <
typename P>
488 constexpr static bool
489 is_dconst(
const P array)
491 return get_array_info(array).is_dconst;
494 template <
typename P>
495 constexpr static bool
496 is_alive(
const P array)
498 return get_array_info(array).is_alive;
501 template <
typename P>
502 constexpr static bool
503 is_accessed(
const P array)
505 return get_array_info(array).is_accessed;
509 template <
typename P>
510 constexpr static auto
511 get_array_dims(
const P array)
513 return get_array_info(array).dims;
516 template <
typename P>
517 constexpr static bool
518 has_const_dims(
const P array)
520 auto dims = get_array_dims(array);
521 int num_dims = get_array_info(array).num_dims;
523 for(
int i = 0; i < num_dims; ++i)
524 res &= !
dims[i].from_config;
528 template <
typename P>
530 get_array_n_dims(
const P array)
532 return get_array_info(array).num_dims;
535 template <
typename P>
537 get_const_dims_array_length(
const P array)
539 auto dims = get_array_info(array).dims;
540 int num_dims = get_array_info(array).num_dims;
542 for(
int i = 0; i < num_dims; ++i)
547 template <
typename P>
548 constexpr static auto
549 get_array_dim_sizes(
const P array,
const AcMeshInfo info)
551 auto dims = get_array_info(array).dims;
552 int num_dims = get_array_info(array).num_dims;
553 std::array<size_t,20> res{};
554 for(
int i = 0; i < num_dims; ++i)
556 if(!
dims[i].from_config)
558 res[i] =
dims[i].base;
561 if(
dims[i].member == NULL)
563 if(
dims[i].run_const)
569 res[i] = info.int_params[
dims[i].base];
573 if(!strcmp(
dims[i].member,
"x"))
575 res[i] = info.int3_params[
dims[i].base].x;
578 if(!strcmp(
dims[i].member,
"y"))
580 res[i] = info.int3_params[
dims[i].base].y;
583 if(!strcmp(
dims[i].member,
"z"))
585 res[i] = info.int3_params[
dims[i].base].z;
592 template <
typename P>
593 constexpr static size_t
594 get_array_length(
const P array,
const AcMeshInfo info)
596 auto sizes = get_array_dim_sizes(array,info);
598 int num_dims = get_array_info(array).num_dims;
599 for(
int i = 0; i < num_dims; ++i)
604 template <
typename P>
606 get_dconst_array_length(
const P array)
608 return get_array_info(array).length;
611 template <
typename P>
613 get_dconst_array_offset(
const P array)
615 return get_array_info(array).d_offset;
618 template <
typename P>
619 constexpr static size_t
623#include "get_num_params.h"
625 static_assert(res >= 0);
630 template<std::size_t... Is>
631 constexpr std::array<int,
sizeof...(Is)> make_array(std::index_sequence<Is...>) {
636 template<std::
size_t N>
637 constexpr std::array<int, N> createIntArray() {
638 return make_array(std::make_index_sequence<N>{});
642 template<
typename P, std::size_t N, std::size_t... Is>
643 constexpr std::array<P, N> createEnumArrayImpl(
const std::array<int, N>& intArray, std::index_sequence<Is...>) {
644 return {{
static_cast<P
>(intArray[Is])... }};
647 template<
typename P, std::
size_t N>
648 constexpr std::array<P, N> createEnumArray(
const std::array<int, N>& intArray) {
649 return createEnumArrayImpl<P>(intArray, std::make_index_sequence<N>{});
652 template <
typename P>
656 return createEnumArray<P>(
657 createIntArray<get_num_params<P>()>()
663 return createEnumArray<Field>(createIntArray<NUM_VTXBUF_HANDLES>());
667 template <
typename P>
669 get_empty_pointer(
const P
param)
672#include "get_empty_pointer.h"
677#include "load_and_store_uniform_overloads.h"
679 template<
typename T,
typename... Ts>
682 template<
template<
typename>
typename F,
typename... Args>
683 static constexpr void run(Args&&... args)
685 ForEach<T>::template run<F>(std::forward<Args>(args)...);
686 ForEach<Ts...>::template run<F>(std::forward<Args>(args)...);
693 template<
template<
typename>
typename F,
typename... Args>
694 static constexpr void run(Args&&... args)
696 F<T>{}(std::forward<Args>(args)...);
701 using AcScalarTypes = ForEach<
702#include "scalar_types.h"
706 using AcScalarCompTypes = ForEach<
707#include "scalar_comp_types.h"
712 using AcArrayTypes = ForEach<
713#include "array_types.h"
717 using AcArrayCompTypes = ForEach<
718#include "array_comp_types.h"
AcResult acUpdateArrays(const AcMeshInfo config)
AcResult acBenchmarkKernel(AcKernel kernel, const int3 start, const int3 end, VertexBufferArray vba)
AcResult acKernelFlushFloat(const cudaStream_t stream, float *arr, const size_t n, const float value)
AcResult acLoadStencil(const Stencil stencil, const cudaStream_t stream, const AcReal data[STENCIL_DEPTH][STENCIL_HEIGHT][STENCIL_WIDTH])
const AcKernel * acGetKernels()
AcResult acLaunchKernel(AcKernel func, const cudaStream_t stream, const Volume start, const Volume end, VertexBufferArray)
AcResult acPreprocessScratchPad(VertexBufferArray, const int variable, const AcType type, const AcReduceOp op)
AcResult acKernelFlushComplex(const cudaStream_t stream, AcComplex *arr, const size_t n, const AcComplex value)
int acGetKernelReduceScratchPadMinSize()
AcResult acVBAReset(const cudaStream_t stream, VertexBufferArray *vba)
void acVBADestroy(VertexBufferArray *vba, const AcMeshInfo config)
Volume acKernelLaunchGetLastTPB(void)
bool acRuntimeIsInitialized()
AcResult acAllocateArrays(const AcMeshInfo config)
size_t acGetRealScratchpadSize(const size_t i)
AcResult acSetReduceOffset(AcKernel func, const Volume start, const Volume end, VertexBufferArray)
AcAutotuneMeasurement(* AcMeasurementGatherFunc)(const AcAutotuneMeasurement)
Definition acc_runtime.h:262
int acGetKernelReduceScratchPadSize(const AcKernel kernel)
AcResult acKernelFlush(const cudaStream_t stream, AcReal *arr, const size_t n, const AcReal value)
size3_t acGetProfileReduceScratchPadDims(const int profile, const AcMeshDims dims)
AcKernel acGetOptimizedKernel(const AcKernel, const acKernelInputParams vba)
VertexBufferArray acVBACreate(const AcMeshInfo config)
AcResult acKernelFlushInt(const cudaStream_t stream, int *arr, const size_t n, const int value)
AcResult acKernelFlushReal(const cudaStream_t stream, AcReal *arr, const size_t n, const AcReal value)
AcResult acRuntimeInit(const AcMeshInfo config)
AcResult acLaunchKernelWithTPB(AcKernel kernel, const cudaStream_t stream, const Volume start_volume, const Volume end_volume, VertexBufferArray vba, const dim3 tpb)
AcResult acRandInitAlt(const uint64_t seed, const size_t count, const size_t rank)
AcResult acInitializeRuntimeMPI(const int grid_pid, const int nprocs, AcMeasurementGatherFunc)
AcResult acStoreStencil(const Stencil stencil, const cudaStream_t stream, AcReal data[STENCIL_DEPTH][STENCIL_HEIGHT][STENCIL_WIDTH])
int3 acGetOptimTPB(const AcKernel, const Volume start, const Volume end)
AcResult acLaunchKernelBase(const AcKernel kernel, const int3 start, const int3 end, VertexBufferArray vba, const dim3 bpg, const dim3 tpb, const size_t smem, const cudaStream_t stream, bool perform_error_check)
AcResult acFreeArrays(const AcMeshInfo config)
float AcReal
Definition acreal.h:11
static const Stream stream
Definition astaroth_device.h:187
AcResult AcMeshInfo * config
Definition astaroth_utils.h:113
#define ERRCHK_ALWAYS(retval)
Definition errchk.h:95
#define UNUSED
Definition func_attributes.h:4
#define AC_BEGIN_C_DECLARATIONS
Definition func_define.h:14
#define AC_END_C_DECLARATIONS
Definition func_define.h:15
#define FUNC_DEFINE(return_type, func_name,...)
Definition func_define.h:69
#define cudaStream_t
Definition hip.h:25
Volume size3_t
Definition host_datatypes.h:76
AcResult
Definition host_datatypes.h:10
AcReduceOp
Definition host_datatypes.h:26
@ PROFILE_ZY
Definition host_datatypes.h:45
@ PROFILE_YX
Definition host_datatypes.h:42
@ PROFILE_XZ
Definition host_datatypes.h:41
@ PROFILE_Z
Definition host_datatypes.h:39
@ PROFILE_Y
Definition host_datatypes.h:38
@ PROFILE_YZ
Definition host_datatypes.h:43
@ PROFILE_XY
Definition host_datatypes.h:40
@ PROFILE_ZX
Definition host_datatypes.h:44
@ PROFILE_X
Definition host_datatypes.h:37
AcMeshOrder
Definition host_datatypes.h:17
Definition acc_runtime.h:243
dim3 tpb
Definition acc_runtime.h:245
float time
Definition acc_runtime.h:244
Definition acc_runtime.h:206
bool on_device
Definition acc_runtime.h:209
size_t count
Definition acc_runtime.h:208
AcReal * data
Definition acc_runtime.h:207
AcShape shape
Definition acc_runtime.h:210
Definition acc_runtime.h:129
Definition acc_runtime.h:122
Definition acc_runtime.h:115
Definition acc_runtime.h:136
AcCompInfoConfig config
Definition acc_runtime.h:137
AcCompInfoLoaded is_loaded
Definition acc_runtime.h:138
AcCompInfoHasDefaultValue has_default_value
Definition acc_runtime.h:139
Definition acc_runtime.h:110
Definition acc_runtime.h:104
Volume nn
Definition acc_runtime.h:105
AcReal3 lengths
Definition acc_runtime.h:106
Definition host_datatypes.h:84
Definition acc_runtime.h:142
Definition acc_runtime.h:151
Definition acc_runtime.h:156
bool runtime_compilation_skip_autotuning
Definition acc_runtime.h:167
const char * runtime_compilation_build_path
Definition acc_runtime.h:163
const char * runtime_compilation_log_dst
Definition acc_runtime.h:162
const char * runtime_compilation_base_path
Definition acc_runtime.h:164
AcCompInfo run_consts
Definition acc_runtime.h:169
AcCommunicator * comm
Definition acc_runtime.h:168
const char * acc_compiler_path
Definition acc_runtime.h:165
AcMeshInfoLoadedInfo is_loaded
Definition acc_runtime.h:161
bool runtime_compilation_skip_make_if_nothing_has_changed
Definition acc_runtime.h:166
Definition acc_runtime.h:216
AcMeshOrder mem_order
Definition acc_runtime.h:219
AcBuffer src
Definition acc_runtime.h:217
AcReal ** cub_tmp
Definition acc_runtime.h:220
AcBuffer transposed
Definition acc_runtime.h:218
size_t * cub_tmp_size
Definition acc_runtime.h:221
Definition acc_runtime.h:92
const AcReduceOp reduce_op
Definition acc_runtime.h:93
const char * name
Definition acc_runtime.h:98
const AcKernel map_vtxbuf_single
Definition acc_runtime.h:95
const AcKernel map_vtxbuf_vec
Definition acc_runtime.h:96
const AcReductionPostProcessingOp post_processing_op
Definition acc_runtime.h:94
const AcKernel map_vtxbuf_vec_scal
Definition acc_runtime.h:97
Definition acc_runtime.h:195
AcReduceOp reals[NUM_REAL_SCRATCHPADS+1]
Definition acc_runtime.h:196
AcReduceOp ints[NUM_INT_OUTPUTS+1]
Definition acc_runtime.h:197
Definition host_datatypes.h:48
Definition acc_runtime.h:185
int reduce_offset
Definition acc_runtime.h:190
void * out[NUM_VTXBUF_HANDLES]
Definition acc_runtime.h:187
int3 block_factor
Definition acc_runtime.h:192
void * in[NUM_VTXBUF_HANDLES]
Definition acc_runtime.h:186
acKernelInputParams kernel_input_params
Definition acc_runtime.h:189
ProfileBufferArray profiles
Definition acc_runtime.h:191
AcComplex * complex_in[NUM_COMPLEX_FIELDS+1]
Definition acc_runtime.h:188
Definition acc_runtime.h:73
int variable
Definition acc_runtime.h:74
AcReductionPostProcessingOp postprocess_op
Definition acc_runtime.h:77
AcReduceOp op
Definition acc_runtime.h:76
AcKernel kernel
Definition acc_runtime.h:78
AcType type
Definition acc_runtime.h:75
Definition acc_runtime.h:180
AcReal * out[NUM_PROFILES+1]
Definition acc_runtime.h:182
AcReal * in[NUM_PROFILES+1]
Definition acc_runtime.h:181
Definition acc_runtime.h:224
DeviceVertexBufferArray on_device
Definition acc_runtime.h:233
size_t profile_counts[NUM_PROFILES+1]
Definition acc_runtime.h:230
size_t profile_count
Definition acc_runtime.h:234
AcMeshDims dims[NUM_ALL_FIELDS]
Definition acc_runtime.h:228
size_t bytes[NUM_ALL_FIELDS]
Definition acc_runtime.h:227
AcMeshDims profile_dims[NUM_PROFILES+1]
Definition acc_runtime.h:229
size_t counts[NUM_ALL_FIELDS]
Definition acc_runtime.h:226
AcReduceBuffer profile_reduce_buffers[NUM_PROFILES+1]
Definition acc_runtime.h:239
AcScratchpadStates * scratchpad_states
Definition acc_runtime.h:238
AcMeshDims computational_dims
Definition acc_runtime.h:231
static __device__ const int dims
Definition user_kernel.h:128
static __device__ const int const int index
Definition user_kernel.h:128
static __device__ const int const int const AcRealArrayParam param
Definition user_kernel.h:129