| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
// |
| 34 |
|
| 35 |
#include <gtest/gtest.h> |
| 36 |
#include <stk_mesh/base/NgpMesh.hpp> |
| 37 |
#include <stk_mesh/base/BulkData.hpp> |
| 38 |
#include <stk_mesh/base/GetNgpField.hpp> |
| 39 |
#include <stk_mesh/base/GetNgpMesh.hpp> |
| 40 |
#include <stk_mesh/base/GetEntities.hpp> |
| 41 |
#include <stk_mesh/base/GetNgpExecutionSpace.hpp> |
| 42 |
#include <stk_mesh/base/ExodusTranslator.hpp> |
| 43 |
#include <stk_util/environment/WallTime.hpp> |
| 44 |
#include <stk_util/environment/perf_util.hpp> |
| 45 |
#include <stk_util/parallel/ParallelReduce.hpp> |
| 46 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 47 |
#include <stk_unit_test_utils/TextMesh.hpp> |
| 48 |
#include <stk_unit_test_utils/getOption.h> |
| 49 |
#include <stk_unit_test_utils/GetMeshSpec.hpp> |
| 50 |
#include <stk_unit_test_utils/timer.hpp> |
| 51 |
#include <stk_performance_tests/stk_mesh/multi_block.hpp> |
| 52 |
#include <Kokkos_Core.hpp> |
| 53 |
#include <cstdlib> |
| 54 |
#include <string> |
| 55 |
#include <time.h> |
| 56 |
#include <chrono> |
| 57 |
#include <thread> |
| 58 |
|
| 59 |
#define SPEEDUP_DELTA 1.0 |
| 60 |
|
| 61 |
class NgpFieldAsyncTest : public stk::unit_test_util::MeshFixture |
| 62 |
{ |
| 63 |
public: |
| 64 |
NgpFieldAsyncTest() |
| 65 |
: stk::unit_test_util::MeshFixture(), |
| 66 |
m_numBlocks(1), |
| 67 |
m_numElemsPerDim(100), |
| 68 |
m_numElements(std::pow(m_numElemsPerDim, 3)), |
| 69 |
m_numComponents(3), |
| 70 |
m_increment(10), |
| 71 |
m_defaultLaunchBlockingEnvVarSet(false), |
| 72 |
m_defaultLaunchBlockingEnvVarValue(0) |
| 73 |
{ |
| 74 |
set_launch_blocking_env_var(); |
| 75 |
} |
| 76 |
|
| 77 |
~NgpFieldAsyncTest() |
| 78 |
{ |
| 79 |
revert_launch_blocking_env_var(); |
| 80 |
} |
| 81 |
|
| 82 |
void setup_simple_mesh_with_fields(unsigned numElemsPerDim) |
| 83 |
{ |
| 84 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 85 |
m_numElemsPerDim = numElemsPerDim; |
| 86 |
setup_fields(); |
| 87 |
setup_mesh_with_many_blocks_many_elements(); |
| 88 |
} |
| 89 |
|
| 90 |
void setup_multi_block_mesh_with_field_per_block(unsigned numElemsPerDim, unsigned numBlocks, unsigned numFields) |
| 91 |
{ |
| 92 |
m_numElemsPerDim = numElemsPerDim; |
| 93 |
m_numBlocks = numBlocks; |
| 94 |
|
| 95 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 96 |
setup_fields_on_all_blocks(numFields); |
| 97 |
setup_mesh_with_many_blocks_many_elements(); |
| 98 |
} |
| 99 |
|
| 100 |
void setup_fields() |
| 101 |
{ |
| 102 |
std::vector<int> init; |
| 103 |
setup_field_component_data(init); |
| 104 |
|
| 105 |
auto field1 = &get_meta().declare_field<int>(stk::topology::ELEMENT_RANK, "intField1", 1); |
| 106 |
auto field2 = &get_meta().declare_field<int>(stk::topology::ELEMENT_RANK, "intField2", 1); |
| 107 |
auto field3 = &get_meta().declare_field<int>(stk::topology::ELEMENT_RANK, "intField3", 1); |
| 108 |
|
| 109 |
stk::mesh::put_field_on_mesh(*field1, get_meta().universal_part(), m_numComponents, init.data()); |
| 110 |
stk::mesh::put_field_on_mesh(*field2, get_meta().universal_part(), m_numComponents, init.data()); |
| 111 |
stk::mesh::put_field_on_mesh(*field3, get_meta().universal_part(), m_numComponents, init.data()); |
| 112 |
} |
| 113 |
|
| 114 |
void setup_fields_on_all_blocks(unsigned numFields) |
| 115 |
{ |
| 116 |
unsigned numStates = 1; |
| 117 |
std::vector<int> init; |
| 118 |
setup_field_component_data(init); |
| 119 |
|
| 120 |
for(unsigned i = 1; i <= m_numBlocks; i++) { |
| 121 |
std::string blockName = "block_" + std::to_string(i); |
| 122 |
|
| 123 |
stk::mesh::Part& part = get_meta().declare_part_with_topology(blockName, stk::topology::HEX_8); |
| 124 |
get_meta().set_part_id(part, i); |
| 125 |
EXPECT_NE(&part, nullptr); |
| 126 |
|
| 127 |
for(unsigned j = 1; j <= numFields; j++) { |
| 128 |
std::string fieldName = "intField" + std::to_string(j); |
| 129 |
stk::mesh::Field<int>& field = get_meta().declare_field<int>(stk::topology::ELEM_RANK, fieldName, numStates); |
| 130 |
stk::mesh::put_field_on_mesh(field, part, m_numComponents, init.data()); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
void setup_mesh_with_many_blocks_many_elements(stk::mesh::BulkData::AutomaticAuraOption auraOption = stk::mesh::BulkData::NO_AUTO_AURA) |
| 136 |
{ |
| 137 |
std::string meshDesc = "generated:" + std::to_string(m_numElemsPerDim) + "x" |
| 138 |
+ std::to_string(m_numElemsPerDim) + "x" |
| 139 |
+ std::to_string(m_numElemsPerDim); |
| 140 |
stk::performance_tests::setup_multiple_blocks(get_meta(), m_numBlocks); |
| 141 |
setup_mesh(meshDesc, auraOption); |
| 142 |
stk::performance_tests::move_elements_to_other_blocks(get_bulk(), m_numElemsPerDim); |
| 143 |
} |
| 144 |
|
| 145 |
void pass_time_on_device(const stk::ngp::ExecSpace& space, unsigned iterationSpent = 100) |
| 146 |
{ |
| 147 |
typedef typename stk::ngp::DeviceTeamPolicy::member_type TeamHandleType; |
| 148 |
const auto& teamPolicy = stk::ngp::DeviceTeamPolicy(space, 10, Kokkos::AUTO); |
| 149 |
|
| 150 |
Kokkos::parallel_for("run_with_team_policy", teamPolicy, |
| 151 |
KOKKOS_LAMBDA(const TeamHandleType & /*team*/) { |
| 152 |
for(unsigned j = 0; j < iterationSpent; ++j) { |
| 153 |
clock_t start = clock(); |
| 154 |
clock_t now; |
| 155 |
for (;;) { |
| 156 |
now = clock(); |
| 157 |
clock_t cycles = now > start ? now - start : now + (0xffffffff - start); |
| 158 |
if (cycles >= 1e6) { |
| 159 |
break; |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
); |
| 165 |
} |
| 166 |
|
| 167 |
void pass_time_on_host(unsigned sleepMilliseconds) |
| 168 |
{ |
| 169 |
std::this_thread::sleep_for(std::chrono::milliseconds(sleepMilliseconds)); |
| 170 |
} |
| 171 |
|
| 172 |
template<typename Func> |
| 173 |
void set_fields_values_on_host(stk::mesh::FieldVector& fields, Func&& setValue) |
| 174 |
{ |
| 175 |
for(auto field : fields) { |
| 176 |
stk::mesh::EntityVector elems; |
| 177 |
stk::mesh::get_selected_entities(stk::mesh::Selector(*field), get_bulk().buckets(stk::topology::ELEM_RANK), elems); |
| 178 |
|
| 179 |
for(auto elem : elems) { |
| 180 |
int* data = reinterpret_cast<int*>(stk::mesh::field_data(*field, elem)); |
| 181 |
unsigned numComponents = stk::mesh::field_scalars_per_entity(*field, elem); |
| 182 |
for(unsigned j = 0; j < numComponents; j++) { |
| 183 |
setValue(data, j); |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
void update_fields_values_on_host(stk::mesh::FieldVector& fields) |
| 190 |
{ |
| 191 |
auto updateValueFunc = [this](int* data, unsigned component) |
| 192 |
{ |
| 193 |
data[component] += m_increment; |
| 194 |
}; |
| 195 |
|
| 196 |
set_fields_values_on_host(fields, updateValueFunc); |
| 197 |
} |
| 198 |
|
| 199 |
void reset_fields_values_on_host(stk::mesh::FieldVector& fields) |
| 200 |
{ |
| 201 |
auto updateValueFunc = [](int* data, unsigned component) |
| 202 |
{ |
| 203 |
data[component] = component; |
| 204 |
}; |
| 205 |
|
| 206 |
set_fields_values_on_host(fields, updateValueFunc); |
| 207 |
} |
| 208 |
|
| 209 |
void set_fields_values_on_device(stk::mesh::FieldVector& fields, unsigned value) |
| 210 |
{ |
| 211 |
stk::mesh::NgpMesh& ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 212 |
|
| 213 |
for(auto field : fields) { |
| 214 |
stk::mesh::NgpField<int> ngpField = stk::mesh::get_updated_ngp_field<int>(*field); |
| 215 |
|
| 216 |
stk::mesh::for_each_entity_run(ngpMesh, stk::topology::ELEM_RANK, stk::mesh::Selector(*field), |
| 217 |
KOKKOS_LAMBDA(const stk::mesh::FastMeshIndex& entityIndex) { |
| 218 |
const int numScalarsPerEntity = ngpField.get_num_components_per_entity(entityIndex); |
| 219 |
|
| 220 |
for (int component = 0; component < numScalarsPerEntity; component++) { |
| 221 |
ngpField(entityIndex, component) = value; |
| 222 |
} |
| 223 |
}); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
void verify_values_on_device(stk::mesh::FieldVector& fields) |
| 228 |
{ |
| 229 |
stk::mesh::NgpMesh& ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 230 |
unsigned numComponents = m_numComponents; |
| 231 |
unsigned increments = m_increment; |
| 232 |
|
| 233 |
for(auto field : fields) { |
| 234 |
auto ngpField = stk::mesh::get_updated_ngp_field<int>(*field); |
| 235 |
|
| 236 |
stk::mesh::for_each_entity_run(ngpMesh, stk::topology::ELEM_RANK, stk::mesh::Selector(*field), |
| 237 |
KOKKOS_LAMBDA(const stk::mesh::FastMeshIndex& elem) |
| 238 |
{ |
| 239 |
for(unsigned i = 0; i < numComponents; i++) { |
| 240 |
int expected = i + increments; |
| 241 |
int fieldValue = ngpField(elem, i); |
| 242 |
NGP_EXPECT_EQ(expected, fieldValue); |
| 243 |
} |
| 244 |
}); |
| 245 |
} |
| 246 |
|
| 247 |
Kokkos::fence(); |
| 248 |
} |
| 249 |
|
| 250 |
void verify_values_on_host(stk::mesh::FieldVector& fields, unsigned expectedValue) |
| 251 |
{ |
| 252 |
for(auto field : fields) { |
| 253 |
auto ngpField = stk::mesh::get_updated_ngp_field<int>(*field); |
| 254 |
|
| 255 |
stk::mesh::EntityVector elems; |
| 256 |
stk::mesh::get_selected_entities(stk::mesh::Selector(*field), get_bulk().buckets(stk::topology::ELEM_RANK), elems); |
| 257 |
|
| 258 |
for(auto elem : elems) { |
| 259 |
int* data = reinterpret_cast<int*>(stk::mesh::field_data(*field, elem)); |
| 260 |
unsigned numComponents = stk::mesh::field_scalars_per_entity(*field, elem); |
| 261 |
for(unsigned j = 0; j < numComponents; j++) { |
| 262 |
EXPECT_EQ((int)expectedValue, data[j]); |
| 263 |
} |
| 264 |
} |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
private: |
| 269 |
void setup_field_component_data(std::vector<int>& init) |
| 270 |
{ |
| 271 |
for(unsigned i = 0; i < m_numComponents; i++) { |
| 272 |
init.push_back(i); |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
void revert_launch_blocking_env_var() |
| 277 |
{ |
| 278 |
if(m_defaultLaunchBlockingEnvVarSet) { |
| 279 |
setenv(m_launchBlockingEnvVar.c_str(), std::to_string(m_defaultLaunchBlockingEnvVarValue).c_str(), 1); |
| 280 |
} else { |
| 281 |
unsetenv(m_launchBlockingEnvVar.c_str()); |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
void set_launch_blocking_env_var() |
| 286 |
{ |
| 287 |
char* varValue = std::getenv(m_launchBlockingEnvVar.c_str()); |
| 288 |
m_defaultLaunchBlockingEnvVarSet = (varValue != nullptr); |
| 289 |
|
| 290 |
if(m_defaultLaunchBlockingEnvVarSet) { |
| 291 |
m_defaultLaunchBlockingEnvVarValue = stk::get_env_var_as_int(m_launchBlockingEnvVar, 0); |
| 292 |
setenv(m_launchBlockingEnvVar.c_str(), "0", 1); |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
unsigned m_numBlocks; |
| 297 |
unsigned m_numElemsPerDim; |
| 298 |
unsigned m_numElements; |
| 299 |
unsigned m_numComponents; |
| 300 |
unsigned m_increment; |
| 301 |
|
| 302 |
bool m_defaultLaunchBlockingEnvVarSet; |
| 303 |
int m_defaultLaunchBlockingEnvVarValue; |
| 304 |
const std::string m_launchBlockingEnvVar = "CUDA_LAUNCH_BLOCKING"; |
| 305 |
}; |
| 306 |
|
| 307 |
TEST_F(NgpFieldAsyncTest, SyncToDeviceAsyncTiming) |
| 308 |
{ |
| 309 |
if(get_parallel_size() != 1) return; |
| 310 |
|
| 311 |
unsigned NUM_RUNS = 5; |
| 312 |
unsigned NUM_ITERS = stk::unit_test_util::get_command_line_option("-r", 50); |
| 313 |
unsigned numStreams = stk::unit_test_util::get_command_line_option("-s", 3); |
| 314 |
unsigned numElemsPerDim = stk::unit_test_util::get_command_line_option("-e", 50); |
| 315 |
unsigned waitIteration = stk::unit_test_util::get_command_line_option("-p", 100); |
| 316 |
stk::unit_test_util::BatchTimer batchTimer(MPI_COMM_WORLD); |
| 317 |
stk::unit_test_util::BatchTimer batchTimer2(MPI_COMM_WORLD); |
| 318 |
batchTimer.initialize_batch_timer(); |
| 319 |
batchTimer2.initialize_batch_timer(); |
| 320 |
|
| 321 |
setup_simple_mesh_with_fields(numElemsPerDim); |
| 322 |
|
| 323 |
stk::mesh::FieldBase* intField1 = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField1"); |
| 324 |
stk::mesh::FieldBase* intField2 = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField2"); |
| 325 |
stk::mesh::FieldBase* intField3 = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField3"); |
| 326 |
stk::mesh::NgpField<int>& ngpIntField1 = stk::mesh::get_updated_ngp_field<int>(*intField1); |
| 327 |
stk::mesh::NgpField<int>& ngpIntField2 = stk::mesh::get_updated_ngp_field<int>(*intField2); |
| 328 |
stk::mesh::NgpField<int>& ngpIntField3 = stk::mesh::get_updated_ngp_field<int>(*intField3); |
| 329 |
stk::mesh::FieldVector fields{intField1, intField2, intField3}; |
| 330 |
std::vector<stk::mesh::NgpField<int>*> ngpFields = {&ngpIntField1, &ngpIntField2, &ngpIntField3}; |
| 331 |
|
| 332 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 333 |
batchTimer.start_batch_timer(); |
| 334 |
|
| 335 |
for (unsigned i = 0; i < NUM_ITERS; i++) { |
| 336 |
|
| 337 |
auto defaultExecSpace = Kokkos::DefaultExecutionSpace(); |
| 338 |
reset_fields_values_on_host(fields); |
| 339 |
update_fields_values_on_host(fields); |
| 340 |
|
| 341 |
for(auto ngpField : ngpFields) { |
| 342 |
ngpField->modify_on_host(); |
| 343 |
ngpField->sync_to_device(); |
| 344 |
pass_time_on_device(defaultExecSpace, waitIteration); |
| 345 |
ngpField->fence(); |
| 346 |
} |
| 347 |
|
| 348 |
verify_values_on_device(fields); |
| 349 |
} |
| 350 |
batchTimer.stop_batch_timer(); |
| 351 |
} |
| 352 |
|
| 353 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 354 |
batchTimer2.start_batch_timer(); |
| 355 |
|
| 356 |
for (unsigned i = 0; i < NUM_ITERS; i++) { |
| 357 |
reset_fields_values_on_host(fields); |
| 358 |
update_fields_values_on_host(fields); |
| 359 |
|
| 360 |
std::vector<stk::mesh::ExecSpaceWrapper<stk::ngp::ExecSpace>> spaces; |
| 361 |
for(unsigned s = 0; s < numStreams; s++) { |
| 362 |
auto space = stk::mesh::get_execution_space_with_stream(); |
| 363 |
spaces.push_back(space); |
| 364 |
} |
| 365 |
|
| 366 |
for(unsigned f = 0; f < ngpFields.size(); f++) { |
| 367 |
auto ngpField = ngpFields[f]; |
| 368 |
auto space = spaces[f % spaces.size()]; |
| 369 |
ngpField->modify_on_host(); |
| 370 |
ngpField->sync_to_device(space); |
| 371 |
pass_time_on_device(space, waitIteration); |
| 372 |
} |
| 373 |
|
| 374 |
stk::mesh::ngp_field_fence(get_meta()); |
| 375 |
verify_values_on_device(fields); |
| 376 |
} |
| 377 |
batchTimer2.stop_batch_timer(); |
| 378 |
} |
| 379 |
|
| 380 |
double blockingSyncTime = batchTimer.get_min_batch_time(); |
| 381 |
double nonBlockingSyncTime = batchTimer2.get_min_batch_time(); |
| 382 |
double speedup = blockingSyncTime / nonBlockingSyncTime; |
| 383 |
|
| 384 |
EXPECT_GE(speedup, 1.0); |
| 385 |
EXPECT_LE(speedup, numStreams + SPEEDUP_DELTA); |
| 386 |
|
| 387 |
batchTimer2.print_batch_timing(NUM_ITERS); |
| 388 |
} |
| 389 |
|
| 390 |
TEST_F(NgpFieldAsyncTest, SyncToHostAsyncTiming) |
| 391 |
{ |
| 392 |
if(get_parallel_size() != 1) return; |
| 393 |
|
| 394 |
unsigned NUM_RUNS = 5; |
| 395 |
unsigned NUM_ITERS = stk::unit_test_util::get_command_line_option("-r", 50); |
| 396 |
unsigned numStreams = stk::unit_test_util::get_command_line_option("-s", 3); |
| 397 |
unsigned numElemsPerDim = stk::unit_test_util::get_command_line_option("-e", 50); |
| 398 |
unsigned waitIteration = stk::unit_test_util::get_command_line_option("-p", 100); |
| 399 |
stk::unit_test_util::BatchTimer batchTimer(MPI_COMM_WORLD); |
| 400 |
stk::unit_test_util::BatchTimer batchTimer2(MPI_COMM_WORLD); |
| 401 |
batchTimer.initialize_batch_timer(); |
| 402 |
batchTimer2.initialize_batch_timer(); |
| 403 |
|
| 404 |
setup_simple_mesh_with_fields(numElemsPerDim); |
| 405 |
|
| 406 |
stk::mesh::FieldBase* intField1 = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField1"); |
| 407 |
stk::mesh::FieldBase* intField2 = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField2"); |
| 408 |
stk::mesh::FieldBase* intField3 = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField3"); |
| 409 |
stk::mesh::NgpField<int>& ngpIntField1 = stk::mesh::get_updated_ngp_field<int>(*intField1); |
| 410 |
stk::mesh::NgpField<int>& ngpIntField2 = stk::mesh::get_updated_ngp_field<int>(*intField2); |
| 411 |
stk::mesh::NgpField<int>& ngpIntField3 = stk::mesh::get_updated_ngp_field<int>(*intField3); |
| 412 |
stk::mesh::FieldVector fields{intField1, intField2, intField3}; |
| 413 |
std::vector<stk::mesh::NgpField<int>*> ngpFields = {&ngpIntField1, &ngpIntField2, &ngpIntField3}; |
| 414 |
|
| 415 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 416 |
batchTimer.start_batch_timer(); |
| 417 |
|
| 418 |
for (unsigned i = 0; i < NUM_ITERS; i++) { |
| 419 |
|
| 420 |
unsigned initialValue = 0; |
| 421 |
unsigned setValue = i+1; |
| 422 |
|
| 423 |
auto defaultExecSpace = Kokkos::DefaultExecutionSpace(); |
| 424 |
set_fields_values_on_device(fields, initialValue); |
| 425 |
set_fields_values_on_device(fields, setValue); |
| 426 |
|
| 427 |
for(auto ngpField : ngpFields) { |
| 428 |
ngpField->modify_on_device(); |
| 429 |
ngpField->sync_to_host(); |
| 430 |
pass_time_on_device(defaultExecSpace, waitIteration); |
| 431 |
ngpField->fence(); |
| 432 |
} |
| 433 |
|
| 434 |
verify_values_on_host(fields, setValue); |
| 435 |
} |
| 436 |
batchTimer.stop_batch_timer(); |
| 437 |
} |
| 438 |
|
| 439 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 440 |
batchTimer2.start_batch_timer(); |
| 441 |
|
| 442 |
for (unsigned i = 0; i < NUM_ITERS; i++) { |
| 443 |
|
| 444 |
unsigned initialValue = 0; |
| 445 |
unsigned setValue = i+1; |
| 446 |
|
| 447 |
set_fields_values_on_device(fields, initialValue); |
| 448 |
set_fields_values_on_device(fields, setValue); |
| 449 |
|
| 450 |
std::vector<stk::mesh::ExecSpaceWrapper<stk::ngp::ExecSpace>> spaces; |
| 451 |
for(unsigned s = 0; s < numStreams; s++) { |
| 452 |
auto space = stk::mesh::get_execution_space_with_stream(); |
| 453 |
spaces.push_back(space); |
| 454 |
} |
| 455 |
|
| 456 |
for(unsigned f = 0; f < ngpFields.size(); f++) { |
| 457 |
auto ngpField = ngpFields[f]; |
| 458 |
auto space = spaces[f % spaces.size()]; |
| 459 |
ngpField->modify_on_device(); |
| 460 |
ngpField->sync_to_host(space); |
| 461 |
pass_time_on_device(space, waitIteration); |
| 462 |
} |
| 463 |
|
| 464 |
stk::mesh::ngp_field_fence(get_meta()); |
| 465 |
verify_values_on_host(fields, setValue); |
| 466 |
} |
| 467 |
batchTimer2.stop_batch_timer(); |
| 468 |
} |
| 469 |
|
| 470 |
double blockingSyncTime = batchTimer.get_min_batch_time(); |
| 471 |
double nonBlockingSyncTime = batchTimer2.get_min_batch_time(); |
| 472 |
double speedup = blockingSyncTime / nonBlockingSyncTime; |
| 473 |
|
| 474 |
EXPECT_GE(speedup, 1.0); |
| 475 |
EXPECT_LE(speedup, numStreams + SPEEDUP_DELTA); |
| 476 |
|
| 477 |
batchTimer2.print_batch_timing(NUM_ITERS); |
| 478 |
} |
| 479 |
|
| 480 |
TEST_F(NgpFieldAsyncTest, SyncAsyncTiming) |
| 481 |
{ |
| 482 |
if(get_parallel_size() != 1) return; |
| 483 |
|
| 484 |
unsigned NUM_RUNS = 5; |
| 485 |
unsigned NUM_ITERS = stk::unit_test_util::get_command_line_option("-r", 50); |
| 486 |
unsigned numStreams = stk::unit_test_util::get_command_line_option("-s", 3); |
| 487 |
unsigned numElemsPerDim = stk::unit_test_util::get_command_line_option("-e", 50); |
| 488 |
unsigned waitIteration = stk::unit_test_util::get_command_line_option("-p", 100); |
| 489 |
stk::unit_test_util::BatchTimer batchTimer(MPI_COMM_WORLD); |
| 490 |
stk::unit_test_util::BatchTimer batchTimer2(MPI_COMM_WORLD); |
| 491 |
batchTimer.initialize_batch_timer(); |
| 492 |
batchTimer2.initialize_batch_timer(); |
| 493 |
|
| 494 |
setup_simple_mesh_with_fields(numElemsPerDim); |
| 495 |
|
| 496 |
stk::mesh::FieldBase* intField1 = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField1"); |
| 497 |
stk::mesh::FieldBase* intField2 = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField2"); |
| 498 |
stk::mesh::FieldBase* intField3 = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField3"); |
| 499 |
stk::mesh::NgpField<int>& ngpIntField1 = stk::mesh::get_updated_ngp_field<int>(*intField1); |
| 500 |
stk::mesh::NgpField<int>& ngpIntField2 = stk::mesh::get_updated_ngp_field<int>(*intField2); |
| 501 |
stk::mesh::NgpField<int>& ngpIntField3 = stk::mesh::get_updated_ngp_field<int>(*intField3); |
| 502 |
stk::mesh::FieldVector fields{intField1, intField2, intField3}; |
| 503 |
std::vector<stk::mesh::NgpField<int>*> ngpFields = {&ngpIntField1, &ngpIntField2, &ngpIntField3}; |
| 504 |
|
| 505 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 506 |
batchTimer.start_batch_timer(); |
| 507 |
|
| 508 |
for (unsigned i = 0; i < NUM_ITERS; i++) { |
| 509 |
|
| 510 |
auto defaultExecSpace = Kokkos::DefaultExecutionSpace(); |
| 511 |
reset_fields_values_on_host(fields); |
| 512 |
update_fields_values_on_host(fields); |
| 513 |
|
| 514 |
for(auto ngpField : ngpFields) { |
| 515 |
ngpField->modify_on_host(); |
| 516 |
ngpField->sync_to_device(); |
| 517 |
pass_time_on_device(defaultExecSpace, waitIteration); |
| 518 |
ngpField->modify_on_device(); |
| 519 |
ngpField->sync_to_host(); |
| 520 |
ngpField->fence(); |
| 521 |
} |
| 522 |
|
| 523 |
} |
| 524 |
batchTimer.stop_batch_timer(); |
| 525 |
} |
| 526 |
|
| 527 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 528 |
batchTimer2.start_batch_timer(); |
| 529 |
|
| 530 |
for (unsigned i = 0; i < NUM_ITERS; i++) { |
| 531 |
reset_fields_values_on_host(fields); |
| 532 |
update_fields_values_on_host(fields); |
| 533 |
|
| 534 |
std::vector<stk::mesh::ExecSpaceWrapper<stk::ngp::ExecSpace>> spaces; |
| 535 |
for(unsigned s = 0; s < numStreams; s++) { |
| 536 |
auto space = stk::mesh::get_execution_space_with_stream(); |
| 537 |
spaces.push_back(space); |
| 538 |
} |
| 539 |
|
| 540 |
for(unsigned f = 0; f < ngpFields.size(); f++) { |
| 541 |
auto ngpField = ngpFields[f]; |
| 542 |
auto space = spaces[f % spaces.size()]; |
| 543 |
|
| 544 |
ngpField->modify_on_host(); |
| 545 |
ngpField->sync_to_device(space); |
| 546 |
pass_time_on_device(space, waitIteration); |
| 547 |
ngpField->modify_on_device(); |
| 548 |
ngpField->sync_to_host(space); |
| 549 |
} |
| 550 |
|
| 551 |
stk::mesh::ngp_field_fence(get_meta()); |
| 552 |
} |
| 553 |
batchTimer2.stop_batch_timer(); |
| 554 |
} |
| 555 |
|
| 556 |
double blockingSyncTime = batchTimer.get_min_batch_time(); |
| 557 |
double nonBlockingSyncTime = batchTimer2.get_min_batch_time(); |
| 558 |
double speedup = blockingSyncTime / nonBlockingSyncTime; |
| 559 |
|
| 560 |
EXPECT_GE(speedup, 1.0); |
| 561 |
EXPECT_LE(speedup, numStreams + SPEEDUP_DELTA); |
| 562 |
|
| 563 |
batchTimer2.print_batch_timing(NUM_ITERS); |
| 564 |
} |
| 565 |
|
| 566 |
TEST_F(NgpFieldAsyncTest, PartialSyncToDeviceAsyncTiming) |
| 567 |
{ |
| 568 |
if(get_parallel_size() != 1) return; |
| 569 |
|
| 570 |
unsigned NUM_RUNS = 5; |
| 571 |
unsigned NUM_ITERS = stk::unit_test_util::get_command_line_option("-r", 50); |
| 572 |
unsigned numStreams = stk::unit_test_util::get_command_line_option("-s", 3); |
| 573 |
unsigned numFields = stk::unit_test_util::get_command_line_option("-f", 3); |
| 574 |
unsigned numBlocks = stk::unit_test_util::get_command_line_option("-b", 3); |
| 575 |
unsigned numBlocksToSync = stk::unit_test_util::get_command_line_option("-c", 1); |
| 576 |
EXPECT_TRUE(numBlocksToSync <= numBlocks && numBlocksToSync >= 1); |
| 577 |
unsigned numElemsPerDim = stk::unit_test_util::get_command_line_option("-e", 50); |
| 578 |
unsigned waitIteration = stk::unit_test_util::get_command_line_option("-p", 100); |
| 579 |
stk::unit_test_util::BatchTimer batchTimer(MPI_COMM_WORLD); |
| 580 |
stk::unit_test_util::BatchTimer batchTimer2(MPI_COMM_WORLD); |
| 581 |
batchTimer.initialize_batch_timer(); |
| 582 |
batchTimer2.initialize_batch_timer(); |
| 583 |
|
| 584 |
setup_multi_block_mesh_with_field_per_block(numElemsPerDim, numBlocks, numFields); |
| 585 |
|
| 586 |
stk::mesh::FieldVector fields; |
| 587 |
std::vector<stk::mesh::NgpField<int>*> ngpFields; |
| 588 |
|
| 589 |
for(unsigned i = 1; i <= numFields; i++) { |
| 590 |
stk::mesh::FieldBase* intField = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField" + std::to_string(i)); |
| 591 |
EXPECT_NE(nullptr, intField); |
| 592 |
fields.push_back(intField); |
| 593 |
|
| 594 |
stk::mesh::NgpField<int>& ngpIntField = stk::mesh::get_updated_ngp_field<int>(*intField); |
| 595 |
ngpFields.push_back(&ngpIntField); |
| 596 |
} |
| 597 |
|
| 598 |
stk::mesh::Selector selector; |
| 599 |
for(unsigned i = 1; i <= numBlocksToSync; i++) { |
| 600 |
selector = selector | stk::mesh::Selector(*get_meta().get_part("block_" + std::to_string(i))); |
| 601 |
} |
| 602 |
|
| 603 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 604 |
batchTimer.start_batch_timer(); |
| 605 |
|
| 606 |
for (unsigned i = 0; i < NUM_ITERS; i++) { |
| 607 |
|
| 608 |
auto defaultExecSpace = Kokkos::DefaultExecutionSpace(); |
| 609 |
reset_fields_values_on_host(fields); |
| 610 |
update_fields_values_on_host(fields); |
| 611 |
|
| 612 |
for(auto ngpField : ngpFields) { |
| 613 |
ngpField->modify_on_host(selector); |
| 614 |
ngpField->sync_to_device(); |
| 615 |
pass_time_on_device(defaultExecSpace, waitIteration); |
| 616 |
ngpField->fence(); |
| 617 |
} |
| 618 |
|
| 619 |
} |
| 620 |
batchTimer.stop_batch_timer(); |
| 621 |
} |
| 622 |
|
| 623 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 624 |
batchTimer2.start_batch_timer(); |
| 625 |
|
| 626 |
for (unsigned i = 0; i < NUM_ITERS; i++) { |
| 627 |
|
| 628 |
reset_fields_values_on_host(fields); |
| 629 |
update_fields_values_on_host(fields); |
| 630 |
|
| 631 |
std::vector<stk::mesh::ExecSpaceWrapper<stk::ngp::ExecSpace>> spaces; |
| 632 |
for(unsigned s = 0; s < numStreams; s++) { |
| 633 |
auto space = stk::mesh::get_execution_space_with_stream(); |
| 634 |
spaces.push_back(space); |
| 635 |
} |
| 636 |
|
| 637 |
for(unsigned f = 0; f < ngpFields.size(); f++) { |
| 638 |
auto ngpField = ngpFields[f]; |
| 639 |
auto space = spaces[f % spaces.size()]; |
| 640 |
|
| 641 |
ngpField->modify_on_host(selector); |
| 642 |
ngpField->sync_to_device(space); |
| 643 |
pass_time_on_device(space, waitIteration); |
| 644 |
} |
| 645 |
|
| 646 |
stk::mesh::ngp_field_fence(get_meta()); |
| 647 |
} |
| 648 |
batchTimer2.stop_batch_timer(); |
| 649 |
} |
| 650 |
|
| 651 |
double blockingSyncTime = batchTimer.get_min_batch_time(); |
| 652 |
double nonBlockingSyncTime = batchTimer2.get_min_batch_time(); |
| 653 |
double speedup = blockingSyncTime / nonBlockingSyncTime; |
| 654 |
|
| 655 |
EXPECT_GE(speedup, 1.0); |
| 656 |
EXPECT_LE(speedup, numStreams + SPEEDUP_DELTA); |
| 657 |
|
| 658 |
batchTimer2.print_batch_timing(NUM_ITERS); |
| 659 |
} |
| 660 |
|
| 661 |
TEST_F(NgpFieldAsyncTest, PartialSyncToHostAsyncTiming) |
| 662 |
{ |
| 663 |
if(get_parallel_size() != 1) { GTEST_SKIP(); } |
| 664 |
|
| 665 |
unsigned NUM_RUNS = 5; |
| 666 |
unsigned NUM_ITERS = stk::unit_test_util::get_command_line_option("-r", 50); |
| 667 |
unsigned numStreams = stk::unit_test_util::get_command_line_option("-s", 3); |
| 668 |
unsigned numFields = stk::unit_test_util::get_command_line_option("-f", 3); |
| 669 |
unsigned numBlocks = stk::unit_test_util::get_command_line_option("-b", 3); |
| 670 |
unsigned numBlocksToSync = stk::unit_test_util::get_command_line_option("-c", 1); |
| 671 |
EXPECT_TRUE(numBlocksToSync <= numBlocks && numBlocksToSync >= 1); |
| 672 |
unsigned numElemsPerDim = stk::unit_test_util::get_command_line_option("-e", 50); |
| 673 |
unsigned waitIteration = stk::unit_test_util::get_command_line_option("-p", 100); |
| 674 |
stk::unit_test_util::BatchTimer batchTimer(MPI_COMM_WORLD); |
| 675 |
stk::unit_test_util::BatchTimer batchTimer2(MPI_COMM_WORLD); |
| 676 |
batchTimer.initialize_batch_timer(); |
| 677 |
batchTimer2.initialize_batch_timer(); |
| 678 |
|
| 679 |
setup_multi_block_mesh_with_field_per_block(numElemsPerDim, numBlocks, numFields); |
| 680 |
|
| 681 |
stk::mesh::FieldVector fields; |
| 682 |
std::vector<stk::mesh::NgpField<int>*> ngpFields; |
| 683 |
|
| 684 |
for(unsigned i = 1; i <= numFields; i++) { |
| 685 |
stk::mesh::FieldBase* intField = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField" + std::to_string(i)); |
| 686 |
EXPECT_NE(nullptr, intField); |
| 687 |
fields.push_back(intField); |
| 688 |
|
| 689 |
stk::mesh::NgpField<int>& ngpIntField = stk::mesh::get_updated_ngp_field<int>(*intField); |
| 690 |
ngpFields.push_back(&ngpIntField); |
| 691 |
} |
| 692 |
|
| 693 |
stk::mesh::Selector selector; |
| 694 |
for(unsigned i = 1; i <= numBlocksToSync; i++) { |
| 695 |
selector = selector | stk::mesh::Selector(*get_meta().get_part("block_" + std::to_string(i))); |
| 696 |
} |
| 697 |
|
| 698 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 699 |
batchTimer.start_batch_timer(); |
| 700 |
|
| 701 |
for (unsigned i = 0; i < NUM_ITERS; i++) { |
| 702 |
|
| 703 |
unsigned initialValue = 0; |
| 704 |
unsigned setValue = i+1; |
| 705 |
|
| 706 |
auto defaultExecSpace = Kokkos::DefaultExecutionSpace(); |
| 707 |
set_fields_values_on_device(fields, initialValue); |
| 708 |
set_fields_values_on_device(fields, setValue); |
| 709 |
|
| 710 |
for(auto ngpField : ngpFields) { |
| 711 |
ngpField->modify_on_device(selector); |
| 712 |
ngpField->sync_to_host(); |
| 713 |
pass_time_on_device(defaultExecSpace, waitIteration); |
| 714 |
ngpField->fence(); |
| 715 |
} |
| 716 |
|
| 717 |
} |
| 718 |
batchTimer.stop_batch_timer(); |
| 719 |
} |
| 720 |
|
| 721 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 722 |
batchTimer2.start_batch_timer(); |
| 723 |
|
| 724 |
for (unsigned i = 0; i < NUM_ITERS; i++) { |
| 725 |
|
| 726 |
unsigned initialValue = 0; |
| 727 |
unsigned setValue = i+1; |
| 728 |
|
| 729 |
set_fields_values_on_device(fields, initialValue); |
| 730 |
set_fields_values_on_device(fields, setValue); |
| 731 |
|
| 732 |
std::vector<stk::mesh::ExecSpaceWrapper<stk::ngp::ExecSpace>> spaces; |
| 733 |
for(unsigned s = 0; s < numStreams; s++) { |
| 734 |
auto space = stk::mesh::get_execution_space_with_stream(); |
| 735 |
spaces.push_back(space); |
| 736 |
} |
| 737 |
|
| 738 |
for(unsigned f = 0; f < ngpFields.size(); f++) { |
| 739 |
auto ngpField = ngpFields[f]; |
| 740 |
auto space = spaces[f % spaces.size()]; |
| 741 |
|
| 742 |
ngpField->modify_on_device(selector); |
| 743 |
ngpField->sync_to_host(space); |
| 744 |
pass_time_on_device(space, waitIteration); |
| 745 |
} |
| 746 |
|
| 747 |
stk::mesh::ngp_field_fence(get_meta()); |
| 748 |
} |
| 749 |
batchTimer2.stop_batch_timer(); |
| 750 |
} |
| 751 |
|
| 752 |
double blockingSyncTime = batchTimer.get_min_batch_time(); |
| 753 |
double nonBlockingSyncTime = batchTimer2.get_min_batch_time(); |
| 754 |
double speedup = blockingSyncTime / nonBlockingSyncTime; |
| 755 |
|
| 756 |
EXPECT_GE(speedup, 1.0); |
| 757 |
EXPECT_LE(speedup, numStreams + SPEEDUP_DELTA); |
| 758 |
|
| 759 |
batchTimer2.print_batch_timing(NUM_ITERS); |
| 760 |
} |
| 761 |
|
| 762 |
TEST_F(NgpFieldAsyncTest, AsyncDeepCopyTiming) |
| 763 |
{ |
| 764 |
if(get_parallel_size() != 1) { GTEST_SKIP(); } |
| 765 |
|
| 766 |
unsigned NUM_RUNS = 5; |
| 767 |
unsigned NUM_ITERS = stk::unit_test_util::get_command_line_option("-r", 50); |
| 768 |
unsigned numStreams = stk::unit_test_util::get_command_line_option("-s", 10); |
| 769 |
unsigned numFields = stk::unit_test_util::get_command_line_option("-f", 10); |
| 770 |
unsigned numBlocks = stk::unit_test_util::get_command_line_option("-b", 1); |
| 771 |
unsigned numElemsPerDim = stk::unit_test_util::get_command_line_option("-e", 100); |
| 772 |
unsigned sleepTime = stk::unit_test_util::get_command_line_option("-m", 50); |
| 773 |
unsigned waitIteration = stk::unit_test_util::get_command_line_option("-p", 20); |
| 774 |
stk::unit_test_util::BatchTimer batchTimer(MPI_COMM_WORLD); |
| 775 |
stk::unit_test_util::BatchTimer batchTimer2(MPI_COMM_WORLD); |
| 776 |
stk::unit_test_util::BatchTimer batchTimer3(MPI_COMM_WORLD); |
| 777 |
batchTimer.initialize_batch_timer(); |
| 778 |
batchTimer2.initialize_batch_timer(); |
| 779 |
batchTimer3.initialize_batch_timer(); |
| 780 |
|
| 781 |
setup_multi_block_mesh_with_field_per_block(numElemsPerDim, numBlocks, numFields); |
| 782 |
|
| 783 |
stk::mesh::FieldVector fields; |
| 784 |
std::vector<stk::mesh::NgpField<int>*> ngpFields; |
| 785 |
|
| 786 |
for(unsigned i = 1; i <= numFields; i++) { |
| 787 |
stk::mesh::FieldBase* intField = get_meta().get_field(stk::topology::ELEMENT_RANK, "intField" + std::to_string(i)); |
| 788 |
EXPECT_NE(nullptr, intField); |
| 789 |
fields.push_back(intField); |
| 790 |
|
| 791 |
stk::mesh::NgpField<int>& ngpIntField = stk::mesh::get_updated_ngp_field<int>(*intField); |
| 792 |
ngpFields.push_back(&ngpIntField); |
| 793 |
} |
| 794 |
|
| 795 |
std::vector<stk::mesh::ExecSpaceWrapper<stk::ngp::ExecSpace>> spaces; |
| 796 |
for(unsigned i = 0; i < numStreams; i++) { |
| 797 |
auto space = stk::mesh::get_execution_space_with_stream(); |
| 798 |
spaces.push_back(space); |
| 799 |
} |
| 800 |
|
| 801 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 802 |
|
| 803 |
reset_fields_values_on_host(fields); |
| 804 |
update_fields_values_on_host(fields); |
| 805 |
|
| 806 |
batchTimer.start_batch_timer(); |
| 807 |
|
| 808 |
for (unsigned iter = 0; iter < NUM_ITERS; iter++) { |
| 809 |
|
| 810 |
Kokkos::fence(); |
| 811 |
|
| 812 |
auto defaultExecSpace = Kokkos::DefaultExecutionSpace(); |
| 813 |
|
| 814 |
for(auto ngpField : ngpFields) { |
| 815 |
ngpField->modify_on_host(); |
| 816 |
ngpField->sync_to_device(); |
| 817 |
pass_time_on_device(defaultExecSpace, waitIteration); |
| 818 |
} |
| 819 |
pass_time_on_host(sleepTime); |
| 820 |
|
| 821 |
} |
| 822 |
batchTimer.stop_batch_timer(); |
| 823 |
} |
| 824 |
|
| 825 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 826 |
|
| 827 |
reset_fields_values_on_host(fields); |
| 828 |
update_fields_values_on_host(fields); |
| 829 |
|
| 830 |
batchTimer2.start_batch_timer(); |
| 831 |
|
| 832 |
for (unsigned iter = 0; iter < NUM_ITERS; iter++) { |
| 833 |
|
| 834 |
auto defaultExecSpace = Kokkos::DefaultExecutionSpace(); |
| 835 |
|
| 836 |
for(auto ngpField : ngpFields) { |
| 837 |
ngpField->modify_on_host(); |
| 838 |
ngpField->sync_to_device(defaultExecSpace); |
| 839 |
pass_time_on_device(defaultExecSpace, waitIteration); |
| 840 |
} |
| 841 |
pass_time_on_host(sleepTime); |
| 842 |
|
| 843 |
stk::mesh::ngp_field_fence(get_meta()); |
| 844 |
} |
| 845 |
batchTimer2.stop_batch_timer(); |
| 846 |
} |
| 847 |
|
| 848 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 849 |
|
| 850 |
reset_fields_values_on_host(fields); |
| 851 |
update_fields_values_on_host(fields); |
| 852 |
|
| 853 |
batchTimer3.start_batch_timer(); |
| 854 |
|
| 855 |
for (unsigned iter = 0; iter < NUM_ITERS; iter++) { |
| 856 |
|
| 857 |
for(unsigned i = 0; i < ngpFields.size(); i++) { |
| 858 |
auto ngpField = ngpFields[i]; |
| 859 |
auto space = spaces[i % spaces.size()]; |
| 860 |
ngpField->modify_on_host(); |
| 861 |
ngpField->sync_to_device(space); |
| 862 |
pass_time_on_device(space, waitIteration); |
| 863 |
} |
| 864 |
pass_time_on_host(sleepTime); |
| 865 |
|
| 866 |
stk::mesh::ngp_field_fence(get_meta()); |
| 867 |
} |
| 868 |
batchTimer3.stop_batch_timer(); |
| 869 |
} |
| 870 |
|
| 871 |
EXPECT_LE(batchTimer2.get_min_batch_time(), batchTimer.get_min_batch_time()); |
| 872 |
EXPECT_LE(batchTimer3.get_min_batch_time(), batchTimer2.get_min_batch_time()); |
| 873 |
|
| 874 |
batchTimer3.print_batch_timing(NUM_ITERS); |
| 875 |
} |