-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathENERGY-Hip.cpp
More file actions
270 lines (227 loc) · 8.89 KB
/
Copy pathENERGY-Hip.cpp
File metadata and controls
270 lines (227 loc) · 8.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Copyright (c) Lawrence Livermore National Security, LLC and other
// RAJA Project Developers. See top-level LICENSE and COPYRIGHT
// files for dates and other details. No copyright assignment is required
// to contribute to RAJA Performance Suite.
//
// SPDX-License-Identifier: (BSD-3-Clause)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
#include "ENERGY.hpp"
#include "RAJA/RAJA.hpp"
#if defined(RAJA_ENABLE_HIP)
#include "common/HipDataUtils.hpp"
#include <iostream>
namespace rajaperf
{
namespace apps
{
template < size_t block_size >
__launch_bounds__(block_size)
__global__ void energycalc1(Real_ptr e_new, Real_ptr e_old, Real_ptr delvc,
Real_ptr p_old, Real_ptr q_old, Real_ptr work,
Index_type iend)
{
Index_type i = blockIdx.x * block_size + threadIdx.x;
if (i < iend) {
ENERGY_BODY1;
}
}
template < size_t block_size >
__launch_bounds__(block_size)
__global__ void energycalc2(Real_ptr delvc, Real_ptr q_new,
Real_ptr compHalfStep, Real_ptr pHalfStep,
Real_ptr e_new, Real_ptr bvc, Real_ptr pbvc,
Real_ptr ql_old, Real_ptr qq_old,
Real_type rho0,
Index_type iend)
{
Index_type i = blockIdx.x * block_size + threadIdx.x;
if (i < iend) {
ENERGY_BODY2;
}
}
template < size_t block_size >
__launch_bounds__(block_size)
__global__ void energycalc3(Real_ptr e_new, Real_ptr delvc,
Real_ptr p_old, Real_ptr q_old,
Real_ptr pHalfStep, Real_ptr q_new,
Index_type iend)
{
Index_type i = blockIdx.x * block_size + threadIdx.x;
if (i < iend) {
ENERGY_BODY3;
}
}
template < size_t block_size >
__launch_bounds__(block_size)
__global__ void energycalc4(Real_ptr e_new, Real_ptr work,
Real_type e_cut, Real_type emin,
Index_type iend)
{
Index_type i = blockIdx.x * block_size + threadIdx.x;
if (i < iend) {
ENERGY_BODY4;
}
}
template < size_t block_size >
__launch_bounds__(block_size)
__global__ void energycalc5(Real_ptr delvc,
Real_ptr pbvc, Real_ptr e_new, Real_ptr vnewc,
Real_ptr bvc, Real_ptr p_new,
Real_ptr ql_old, Real_ptr qq_old,
Real_ptr p_old, Real_ptr q_old,
Real_ptr pHalfStep, Real_ptr q_new,
Real_type rho0, Real_type e_cut, Real_type emin,
Index_type iend)
{
Index_type i = blockIdx.x * block_size + threadIdx.x;
if (i < iend) {
ENERGY_BODY5;
}
}
template < size_t block_size >
__launch_bounds__(block_size)
__global__ void energycalc6(Real_ptr delvc,
Real_ptr pbvc, Real_ptr e_new, Real_ptr vnewc,
Real_ptr bvc, Real_ptr p_new,
Real_ptr q_new,
Real_ptr ql_old, Real_ptr qq_old,
Real_type rho0, Real_type q_cut,
Index_type iend)
{
Index_type i = blockIdx.x * block_size + threadIdx.x;
if (i < iend) {
ENERGY_BODY6;
}
}
template < size_t block_size >
void ENERGY::runHipVariantImpl(VariantID vid)
{
setBlockSize(block_size);
const Index_type run_reps = getRunReps();
const Index_type ibegin = 0;
const Index_type iend = getActualProblemSize();
auto res{getHipResource()};
ENERGY_DATA_SETUP;
if ( vid == Base_HIP ) {
startTimer();
// Loop counter increment uses macro to quiet C++20 compiler warning
for (RepIndex_type irep = 0; irep < run_reps; RP_REPCOUNTINC(irep)) {
const size_t grid_size = RAJA_DIVIDE_CEILING_INT(iend, block_size);
constexpr size_t shmem = 0;
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_1));
RPlaunchHipKernel( (energycalc1<block_size>),
grid_size, block_size,
shmem, res.get_stream(),
e_new, e_old, delvc,
p_old, q_old, work,
iend );
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_1));
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_2));
RPlaunchHipKernel( (energycalc2<block_size>),
grid_size, block_size,
shmem, res.get_stream(),
delvc, q_new,
compHalfStep, pHalfStep,
e_new, bvc, pbvc,
ql_old, qq_old,
rho0,
iend );
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_2));
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_3));
RPlaunchHipKernel( (energycalc3<block_size>),
grid_size, block_size,
shmem, res.get_stream(),
e_new, delvc,
p_old, q_old,
pHalfStep, q_new,
iend );
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_3));
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_4));
RPlaunchHipKernel( (energycalc4<block_size>),
grid_size, block_size,
shmem, res.get_stream(),
e_new, work,
e_cut, emin,
iend );
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_4));
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_5));
RPlaunchHipKernel( (energycalc5<block_size>),
grid_size, block_size,
shmem, res.get_stream(),
delvc,
pbvc, e_new, vnewc,
bvc, p_new,
ql_old, qq_old,
p_old, q_old,
pHalfStep, q_new,
rho0, e_cut, emin,
iend );
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_5));
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_6));
RPlaunchHipKernel( (energycalc6<block_size>),
grid_size, block_size,
shmem, res.get_stream(),
delvc,
pbvc, e_new, vnewc,
bvc, p_new,
q_new,
ql_old, qq_old,
rho0, q_cut,
iend );
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_6));
}
stopTimer();
} else if ( vid == RAJA_HIP ) {
const bool async = true;
startTimer();
// Loop counter increment uses macro to quiet C++20 compiler warning
for (RepIndex_type irep = 0; irep < run_reps; RP_REPCOUNTINC(irep)) {
RAJA::region<RAJA::seq_region>( [=]() {
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_1));
RAJA::forall< RAJA::hip_exec<block_size, async> >( res,
RAJA::RangeSegment(ibegin, iend), [=] __device__ (Index_type i) {
ENERGY_BODY1;
});
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_1));
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_2));
RAJA::forall< RAJA::hip_exec<block_size, async> >( res,
RAJA::RangeSegment(ibegin, iend), [=] __device__ (Index_type i) {
ENERGY_BODY2;
});
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_2));
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_3));
RAJA::forall< RAJA::hip_exec<block_size, async> >( res,
RAJA::RangeSegment(ibegin, iend), [=] __device__ (Index_type i) {
ENERGY_BODY3;
});
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_3));
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_4));
RAJA::forall< RAJA::hip_exec<block_size, async> >( res,
RAJA::RangeSegment(ibegin, iend), [=] __device__ (Index_type i) {
ENERGY_BODY4;
});
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_4));
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_5));
RAJA::forall< RAJA::hip_exec<block_size, async> >( res,
RAJA::RangeSegment(ibegin, iend), [=] __device__ (Index_type i) {
ENERGY_BODY5;
});
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_5));
RP_CALI_MARK_BEGIN(RP_CALI_REGION(ENERGY_6));
RAJA::forall< RAJA::hip_exec<block_size, async> >( res,
RAJA::RangeSegment(ibegin, iend), [=] __device__ (Index_type i) {
ENERGY_BODY6;
});
RP_CALI_MARK_END(RP_CALI_REGION(ENERGY_6));
}); // end sequential region (for single-source code)
}
stopTimer();
} else {
getCout() << "\n ENERGY : Unknown Hip variant id = " << vid << std::endl;
}
}
RAJAPERF_GPU_BLOCK_SIZE_TUNING_DEFINE_BOILERPLATE(ENERGY, Hip, Base_HIP, RAJA_HIP)
} // end namespace apps
} // end namespace rajaperf
#endif // RAJA_ENABLE_HIP