Astaroth  3.1
Scalable Multi-GPU Stencil Computations
Loading...
Searching...
No Matches
user_kernel.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2014-2026, Johannes Pekkila, Miikka Vaisala, Touko Puro.
3
4 This file is part of Astaroth.
5
6 Astaroth is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Astaroth is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20/* This header is to be included only by kernels generated by ACC. It provides
21 * the common ground shared by all generated kernels. */
22
23#pragma once
24
25#ifndef AC_RUNTIME_SOURCE
26
27// clang-format off
28#include "host_datatypes.h"
29#include "user_defines.h"
30// clang-format on
31
32#include "acc_runtime.h"
33#include "acc/implementation.h"
35#include "device_details.h"
36#include "errchk.h"
37#include "kernels.h"
38#include "math_utils.h"
39#include "random.cuh"
40#include "static_analysis.h"
41
42typedef void (*Kernel)(const int3, const int3, DeviceVertexBufferArray vba);
43extern __device__ __constant__ AcMeshInfoScalars d_mesh_info;
44extern __device__ AcReal stencils[NUM_STENCILS][STENCIL_DEPTH][STENCIL_HEIGHT][STENCIL_WIDTH];
45
46#define d_multigpu_offset (d_mesh_info.int3_params[AC_multigpu_offset])
47
48#include "dconst_decl.h"
49#include "get_address.h"
50#include "reduce_helpers_decls.h"
51#include "output_value_decl.h"
52#include "user_defines_runtime_lib.h"
53
54#include "extern_arrays_decl.h"
55
56#define PROFILE_X_Y_OR_Z_INDEX(i, j) ((i) + (j) * VAL(AC_mlocal).x)
57#define PROFILE_Y_X_OR_Z_INDEX(i, j) ((i) + (j) * VAL(AC_mlocal).y)
58#define PROFILE_Z_X_OR_Y_INDEX(i, j) ((i) + (j) * VAL(AC_mlocal).z)
59#define DEVICE_VTXBUF_IDX(i, j, k) \
60 ((i) + (j) * VAL(AC_mlocal).x + (k) * VAL(AC_mlocal_products).xy)
61#define DEVICE_VARIABLE_VTXBUF_IDX(i, j, k, dims) \
62 ((i) + dims.x * ((j) + (k) * dims.y))
63#define LOCAL_COMPDOMAIN_IDX(coord) \
64 ((coord.x) + (coord.y) * VAL(AC_nlocal).x + \
65 (coord.z) * VAL(AC_nlocal_products).xy)
66#define print(...) \
67 { \
68 if (!DCONST(AC_autotuning_at_work)) \
69 printf(__VA_ARGS__); \
70 }
71#define suppress_unused_warning(X) (void)X
72#define longlong long long
73#define size(arr) \
74 (int)(sizeof(arr) / sizeof(arr[0])) // Leads to bugs if the user
75#define error_message(error, message)
76#define fatal_error_message(error, message)
77#define ac_dummy_write(field, x, y, z)
78//TP: markers of the iteration-specific stencil calls hoisted in long rolled loops (see unroll_constant_loops), only used by the analysis
79#define ac_dynamic_stencils_begin()
80#define ac_dynamic_stencils_end()
81#define postprocess_reduce_result(DST,OP)
82
83#include "device_fields_info.h"
84#include "device_output_info.h"
85
86static __device__ UNUSED int3
87ac_get_field_halos(const Field& field)
88{
89 if (vtxbuf_compile_time_device_halos[field] != (int3){-1, -1, -1}) {
90 return vtxbuf_compile_time_device_halos[field];
91 }
92 return VAL(vtxbuf_run_time_device_halos[field]);
93}
94
95static __device__ UNUSED bool
96ac_field_has_default_dims(const Field& field)
97{
98 return vtxbuf_device_dims[field] == AC_mlocal;
99}
100
101static __device__ UNUSED bool
102ac_is_global(const AcRealOutputParam& param)
103{
104 return real_output_is_global_device[param];
105}
106
107static __device__ AcReal
108safe_access(const AcReal* arr, const int dims, const int index, const char* name)
109{
110 if (arr == NULL)
111 {
112 printf("Trying to access %s which is NULL!\n",name);
113 //TP: assert is not defined on Mahti :(
114 //assert(false);
115 return 0.0;
116 }
117 else if (index < 0 || index >= dims)
118 {
119 printf("Trying to access %s out of bounds!: %d\n",name,index);
120 //TP: assert is not defined on Mahti :(
121 //assert(false);
122 return 0.0;
123 }
124 return arr[index];
125}
126
127static __device__ UNUSED AcReal
128safe_access(const AcReal* arr, const int dims, const int index, const AcRealArrayParam param)
129{
130 return safe_access(arr, dims, index,real_array_names__device__[param]);
131}
132
133#endif /* AC_RUNTIME_SOURCE */
float AcReal
Definition acreal.h:11
Brief info.
#define UNUSED
Definition func_attributes.h:4
Brief info.
Definition acc_runtime.h:151
Definition acc_runtime.h:185
__device__ __constant__ AcMeshInfoScalars d_mesh_info
__device__ AcReal stencils[NUM_STENCILS][STENCIL_DEPTH][STENCIL_HEIGHT][STENCIL_WIDTH]
static __device__ const int dims
Definition user_kernel.h:128
void(* Kernel)(const int3, const int3, DeviceVertexBufferArray vba)
Definition user_kernel.h:42
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