| 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_util/stk_config.h> |
| 37 |
#include <stk_mesh/base/Ngp.hpp> |
| 38 |
#include <stk_unit_test_utils/getOption.h> |
| 39 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 40 |
#include <stk_unit_test_utils/TextMesh.hpp> |
| 41 |
#include <stk_unit_test_utils/GetMeshSpec.hpp> |
| 42 |
#include <stk_unit_test_utils/PerformanceTester.hpp> |
| 43 |
#include <stk_mesh/base/MetaData.hpp> |
| 44 |
#include <stk_mesh/base/BulkData.hpp> |
| 45 |
#include <stk_mesh/base/Bucket.hpp> |
| 46 |
#include <stk_mesh/base/Field.hpp> |
| 47 |
#include <stk_mesh/base/Entity.hpp> |
| 48 |
#include <stk_mesh/base/GetEntities.hpp> |
| 49 |
#include <stk_mesh/base/GetNgpField.hpp> |
| 50 |
#include <stk_mesh/base/GetNgpMesh.hpp> |
| 51 |
#include <stk_mesh/base/Types.hpp> |
| 52 |
#include <stk_mesh/base/ForEachEntity.hpp> |
| 53 |
#include <stk_mesh/base/NgpForEachEntity.hpp> |
| 54 |
#include <stk_mesh/base/NgpFieldBLAS.hpp> |
| 55 |
#include <stk_util/util/StkNgpVector.hpp> |
| 56 |
#include "NgpFieldTestUtils.hpp" |
| 57 |
#include <string> |
| 58 |
#include <cstdlib> |
| 59 |
|
| 60 |
namespace ngp_field_blas_test { |
| 61 |
|
| 62 |
class NgpFieldBLAS : public stk::unit_test_util::MeshFixture |
| 63 |
{ |
| 64 |
public: |
| 65 |
NgpFieldBLAS() |
| 66 |
{ |
| 67 |
setup_three_fields_five_hex_three_block_mesh(); |
| 68 |
} |
| 69 |
|
| 70 |
void setup_three_fields_five_hex_three_block_mesh() |
| 71 |
{ |
| 72 |
const unsigned numStates = 1; |
| 73 |
const unsigned bucketCapacity = 2; |
| 74 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA, bucketCapacity, bucketCapacity); |
| 75 |
|
| 76 |
stkField1 = &get_meta().declare_field<double>(stk::topology::ELEM_RANK, "variableLengthField1", numStates); |
| 77 |
stkField2 = &get_meta().declare_field<double>(stk::topology::ELEM_RANK, "variableLengthField2", numStates); |
| 78 |
stkField3 = &get_meta().declare_field<double>(stk::topology::ELEM_RANK, "variableLengthField3", numStates); |
| 79 |
stkField4 = &get_meta().declare_field<double>(stk::topology::ELEM_RANK, "variableLengthField4", numStates); |
| 80 |
stkField5 = &get_meta().declare_field<double>(stk::topology::ELEM_RANK, "variableLengthField5", numStates); |
| 81 |
|
| 82 |
stk::mesh::Part& block1 = get_meta().declare_part_with_topology("block_1", stk::topology::HEX_8); |
| 83 |
stk::mesh::Part& block2 = get_meta().declare_part_with_topology("block_2", stk::topology::HEX_8); |
| 84 |
get_meta().declare_part_with_topology("block_3", stk::topology::HEX_8); |
| 85 |
|
| 86 |
const std::vector<double> init1(numComponent1, -1); |
| 87 |
stk::mesh::put_field_on_mesh(*stkField1, block1, numComponent1, init1.data()); |
| 88 |
|
| 89 |
const std::vector<double> init2(numComponent2, -2); |
| 90 |
stk::mesh::put_field_on_mesh(*stkField1, block2, numComponent2, init2.data()); |
| 91 |
|
| 92 |
const std::vector<double> init3(numComponent1, -1); |
| 93 |
stk::mesh::put_field_on_mesh(*stkField2, block1, numComponent1, init3.data()); |
| 94 |
|
| 95 |
const std::vector<double> init4(numComponent2, -2); |
| 96 |
stk::mesh::put_field_on_mesh(*stkField2, block2, numComponent2, init4.data()); |
| 97 |
|
| 98 |
const std::vector<double> init5(numComponent1, -1); |
| 99 |
stk::mesh::put_field_on_mesh(*stkField3, block1, numComponent1, init5.data()); |
| 100 |
|
| 101 |
const std::vector<double> init6(numComponent2, -2); |
| 102 |
stk::mesh::put_field_on_mesh(*stkField3, block2, numComponent2, init6.data()); |
| 103 |
|
| 104 |
|
| 105 |
const std::vector<double> init7(numComponent1, -1); |
| 106 |
stk::mesh::put_field_on_mesh(*stkField4, block1, numComponent1, init7.data()); |
| 107 |
|
| 108 |
const std::vector<double> init8(numComponent2, -2); |
| 109 |
stk::mesh::put_field_on_mesh(*stkField4, block2, numComponent2, init8.data()); |
| 110 |
|
| 111 |
const std::vector<double> init9(numComponent1, -1); |
| 112 |
stk::mesh::put_field_on_mesh(*stkField5, block1, numComponent1, init9.data()); |
| 113 |
|
| 114 |
const std::vector<double> init10(numComponent2, -2); |
| 115 |
stk::mesh::put_field_on_mesh(*stkField5, block2, numComponent2, init10.data()); |
| 116 |
|
| 117 |
const std::string meshDesc = "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1\n" |
| 118 |
"0,2,HEX_8,5,6,7,8,9,10,11,12,block_1\n" |
| 119 |
"0,3,HEX_8,9,13,14,15,16,17,18,19,block_2\n" |
| 120 |
"0,4,HEX_8,9,20,21,22,23,24,25,26,block_2\n" |
| 121 |
"0,5,HEX_8,9,27,28,29,30,31,32,33,block_3"; |
| 122 |
stk::unit_test_util::setup_text_mesh(get_bulk(), meshDesc); |
| 123 |
|
| 124 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 125 |
} |
| 126 |
|
| 127 |
const int numComponent1 = 8; |
| 128 |
const int numComponent2 = 3; |
| 129 |
stk::mesh::Field<double>* stkField1 = nullptr; |
| 130 |
stk::mesh::Field<double>* stkField2 = nullptr; |
| 131 |
stk::mesh::Field<double>* stkField3 = nullptr; |
| 132 |
stk::mesh::Field<double>* stkField4 = nullptr; |
| 133 |
stk::mesh::Field<double>* stkField5 = nullptr; |
| 134 |
}; |
| 135 |
|
| 136 |
class NgpFieldBLASNode : public stk::unit_test_util::MeshFixture |
| 137 |
{ |
| 138 |
public: |
| 139 |
NgpFieldBLASNode() |
| 140 |
{ |
| 141 |
setup_three_fields_three_hex_three_block_mesh(); |
| 142 |
} |
| 143 |
|
| 144 |
void setup_three_fields_three_hex_three_block_mesh() |
| 145 |
{ |
| 146 |
const unsigned numStates = 1; |
| 147 |
const unsigned bucketCapacity = 2; |
| 148 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA, bucketCapacity, bucketCapacity); |
| 149 |
|
| 150 |
stkField1 = &get_meta().declare_field<double>(stk::topology::NODE_RANK, "variableLengthNodeField1", numStates); |
| 151 |
stkField2 = &get_meta().declare_field<double>(stk::topology::NODE_RANK, "variableLengthNodeField2", numStates); |
| 152 |
stkField3 = &get_meta().declare_field<double>(stk::topology::NODE_RANK, "variableLengthNodeField3", numStates); |
| 153 |
|
| 154 |
|
| 155 |
stk::mesh::Part& block1 = get_meta().declare_part_with_topology("block_1", stk::topology::HEX_8); |
| 156 |
stk::mesh::Part& block2 = get_meta().declare_part_with_topology("block_2", stk::topology::HEX_8); |
| 157 |
get_meta().declare_part_with_topology("block_3", stk::topology::HEX_8); |
| 158 |
|
| 159 |
const std::vector<double> init1(numComponent1, -1); |
| 160 |
stk::mesh::put_field_on_mesh(*stkField1, block1, numComponent1, init1.data()); |
| 161 |
|
| 162 |
const std::vector<double> init2(numComponent2, -2); |
| 163 |
stk::mesh::put_field_on_mesh(*stkField1, block2, numComponent2, init2.data()); |
| 164 |
|
| 165 |
const std::vector<double> init3(numComponent1, -1); |
| 166 |
stk::mesh::put_field_on_mesh(*stkField2, block1, numComponent1, init3.data()); |
| 167 |
|
| 168 |
const std::vector<double> init4(numComponent2, -2); |
| 169 |
stk::mesh::put_field_on_mesh(*stkField2, block2, numComponent2, init4.data()); |
| 170 |
|
| 171 |
const std::vector<double> init5(numComponent1, -1); |
| 172 |
stk::mesh::put_field_on_mesh(*stkField3, block1, numComponent1, init5.data()); |
| 173 |
|
| 174 |
const std::vector<double> init6(numComponent2, -2); |
| 175 |
stk::mesh::put_field_on_mesh(*stkField3, block2, numComponent2, init6.data()); |
| 176 |
|
| 177 |
const std::string meshDesc = "0,1,HEX_8,1,2,3,4,5,6,7,8,block_1\n" |
| 178 |
"0,2,HEX_8,9,10,11,12,13,14,15,16,block_2\n" |
| 179 |
"0,3,HEX_8,17,18,19,20,21,22,23,24,block_3\n" |
| 180 |
"|coordinates:" |
| 181 |
// elem 1 |
| 182 |
"0,0,0, 1,0,0, 1,1,0, 0,1,0, " |
| 183 |
"0,0,1, 1,0,1, 1,1,1, 0,1,1, " |
| 184 |
// elem 2 |
| 185 |
"2,0,0, 3,0,0, 3,1,0, 2,1,0, " |
| 186 |
"2,0,1, 3,0,1, 3,1,1, 2,1,1, " |
| 187 |
// elem 3 |
| 188 |
"4,0,0, 5,0,0, 5,1,0, 4,1,0, " |
| 189 |
"4,0,1, 5,0,1, 5,1,1, 4,1,1"; |
| 190 |
stk::unit_test_util::setup_text_mesh(get_bulk(), meshDesc); |
| 191 |
|
| 192 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 193 |
} |
| 194 |
|
| 195 |
const int numComponent1 = 8; |
| 196 |
const int numComponent2 = 3; |
| 197 |
stk::mesh::Field<double>* stkField1 = nullptr; |
| 198 |
stk::mesh::Field<double>* stkField2 = nullptr; |
| 199 |
stk::mesh::Field<double>* stkField3 = nullptr; |
| 200 |
}; |
| 201 |
|
| 202 |
namespace { |
| 203 |
std::vector<double> func1(const double* coords) |
| 204 |
{ |
| 205 |
double v = coords[0] + 2*coords[1] + 3*coords[2]; |
| 206 |
return {v, v + 1, v + 2, v + 3, v + 4, v + 5, v + 6, v + 7}; |
| 207 |
} |
| 208 |
|
| 209 |
std::vector<double> func2(const double* coords) |
| 210 |
{ |
| 211 |
double v = coords[0] + 2*coords[1] + 3*coords[2]; |
| 212 |
return {v + 8, v + 9, v + 10, v + 11, v + 12, v + 13, v + 14, v + 15}; |
| 213 |
} |
| 214 |
|
| 215 |
} |
| 216 |
|
| 217 |
#ifdef STK_USE_DEVICE_MESH |
| 218 |
|
| 219 |
TEST_F(NgpFieldBLAS, field_fill_device) |
| 220 |
{ |
| 221 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 222 |
|
| 223 |
const double myConstantValue = 55.5; |
| 224 |
|
| 225 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::ExecSpace()); |
| 226 |
|
| 227 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 228 |
|
| 229 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 230 |
stk::mesh::NgpField<double>& ngpField1 = stk::mesh::get_updated_ngp_field<double>(*stkField1); |
| 231 |
|
| 232 |
stk::mesh::Selector selector(*stkField1); |
| 233 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField1, selector, myConstantValue); |
| 234 |
|
| 235 |
const double initialValue = -1; |
| 236 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField1, selector, initialValue); |
| 237 |
|
| 238 |
stkField1->sync_to_host(); |
| 239 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField1, selector, myConstantValue); |
| 240 |
} |
| 241 |
|
| 242 |
TEST_F(NgpFieldBLAS, field_fill_device_multiple) |
| 243 |
{ |
| 244 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 245 |
|
| 246 |
const double myConstantValue = 55.5; |
| 247 |
|
| 248 |
std::vector<const stk::mesh::FieldBase*> allFields = {stkField1, stkField2, stkField3, stkField4, stkField5}; |
| 249 |
stk::mesh::field_fill(myConstantValue, allFields, stk::ngp::ExecSpace()); |
| 250 |
|
| 251 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 252 |
for (const stk::mesh::FieldBase* field : allFields) |
| 253 |
{ |
| 254 |
EXPECT_TRUE(field->need_sync_to_host()); |
| 255 |
|
| 256 |
stk::mesh::NgpField<double>& ngpField = stk::mesh::get_updated_ngp_field<double>(*field); |
| 257 |
|
| 258 |
stk::mesh::Selector selector(*field); |
| 259 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField, selector, myConstantValue); |
| 260 |
|
| 261 |
const double initialValue = -1; |
| 262 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *field, selector, initialValue); |
| 263 |
|
| 264 |
field->sync_to_host(); |
| 265 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *field, selector, myConstantValue); |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
TEST_F(NgpFieldBLAS, field_fill_selector_device) |
| 270 |
{ |
| 271 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 272 |
|
| 273 |
const double myConstantValue = 55.5; |
| 274 |
stk::mesh::Part& block2 = *get_meta().get_part("block_2"); |
| 275 |
stk::mesh::Selector selector = block2; |
| 276 |
stk::mesh::field_fill(myConstantValue, *stkField1, selector, stk::ngp::ExecSpace()); |
| 277 |
|
| 278 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 279 |
|
| 280 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 281 |
stk::mesh::NgpField<double>& ngpField1 = stk::mesh::get_updated_ngp_field<double>(*stkField1); |
| 282 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField1, selector, myConstantValue); |
| 283 |
|
| 284 |
stkField1->sync_to_host(); |
| 285 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField1, selector, myConstantValue); |
| 286 |
} |
| 287 |
|
| 288 |
TEST_F(NgpFieldBLAS, field_fill_component_selector_device) |
| 289 |
{ |
| 290 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 291 |
|
| 292 |
constexpr int component = 1; |
| 293 |
constexpr double myConstantComponentValue = 15.5; |
| 294 |
constexpr double myConstantValue = 55.5; |
| 295 |
stk::mesh::Part& block2 = *get_meta().get_part("block_2"); |
| 296 |
stk::mesh::Selector selector = block2; |
| 297 |
stk::mesh::field_fill(myConstantValue, *stkField1, selector, stk::ngp::ExecSpace()); |
| 298 |
stk::mesh::field_fill(myConstantComponentValue, *stkField1, component, selector, stk::ngp::ExecSpace()); |
| 299 |
|
| 300 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 301 |
|
| 302 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 303 |
stk::mesh::NgpField<double>& ngpField1 = stk::mesh::get_updated_ngp_field<double>(*stkField1); |
| 304 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField1, selector, myConstantValue, component, myConstantComponentValue); |
| 305 |
|
| 306 |
stkField1->sync_to_host(); |
| 307 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField1, selector, myConstantValue, component, myConstantComponentValue); |
| 308 |
} |
| 309 |
|
| 310 |
TEST_F(NgpFieldBLAS, field_fill_device_component_multiple) |
| 311 |
{ |
| 312 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 313 |
|
| 314 |
const int component = 1; |
| 315 |
const double myConstantComponentValue = 15.5; |
| 316 |
const double myConstantValue = 55.5; |
| 317 |
|
| 318 |
std::vector<const stk::mesh::FieldBase*> allFields = {stkField1, stkField2, stkField3, stkField4, stkField5}; |
| 319 |
stk::mesh::Part& block2 = *get_meta().get_part("block_2"); |
| 320 |
stk::mesh::Selector selector = block2; |
| 321 |
stk::mesh::field_fill(myConstantValue, allFields, selector, stk::ngp::ExecSpace()); |
| 322 |
stk::mesh::field_fill(myConstantComponentValue, allFields, component, selector, stk::ngp::ExecSpace()); |
| 323 |
|
| 324 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 325 |
for (const stk::mesh::FieldBase* field : allFields) |
| 326 |
{ |
| 327 |
EXPECT_TRUE(field->need_sync_to_host()); |
| 328 |
|
| 329 |
stk::mesh::NgpField<double>& ngpField = stk::mesh::get_updated_ngp_field<double>(*field); |
| 330 |
|
| 331 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField, selector, myConstantValue, component, myConstantComponentValue); |
| 332 |
|
| 333 |
field->sync_to_host(); |
| 334 |
|
| 335 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *field, selector, myConstantValue, component, myConstantComponentValue); |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
TEST_F(NgpFieldBLAS, field_fill_host_ngp) |
| 341 |
{ |
| 342 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 343 |
|
| 344 |
const double myConstantValue = 55.5; |
| 345 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::HostExecSpace{}); |
| 346 |
|
| 347 |
#ifdef STK_ENABLE_GPU |
| 348 |
EXPECT_TRUE(stkField1->need_sync_to_device()); |
| 349 |
#else |
| 350 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 351 |
stkField1->sync_to_host(); |
| 352 |
#endif |
| 353 |
|
| 354 |
stk::mesh::Selector selector(*stkField1); |
| 355 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField1, selector, myConstantValue); |
| 356 |
} |
| 357 |
|
| 358 |
#else /* not-defined STK_USE_DEVICE_MESH */ |
| 359 |
|
| 360 |
TEST_F(NgpFieldBLAS, field_fill_host) |
| 361 |
{ |
| 362 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 363 |
|
| 364 |
const double myConstantValue = 55.5; |
| 365 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::HostExecSpace{}); |
| 366 |
|
| 367 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 368 |
|
| 369 |
stk::mesh::Selector selector(*stkField1); |
| 370 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 371 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField1, selector, myConstantValue); |
| 372 |
} |
| 373 |
|
| 374 |
TEST_F(NgpFieldBLAS, field_fill_selector_host) |
| 375 |
{ |
| 376 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 377 |
|
| 378 |
const double myConstantValue = 55.5; |
| 379 |
const double myBlock2Value = 95.5; |
| 380 |
stk::mesh::Part& block2 = *get_meta().get_part("block_2"); |
| 381 |
stk::mesh::Selector selector = block2; |
| 382 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::HostExecSpace{}); |
| 383 |
stk::mesh::field_fill(myBlock2Value, *stkField1, selector, stk::ngp::HostExecSpace{}); |
| 384 |
|
| 385 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 386 |
|
| 387 |
stk::mesh::Selector all(*stkField1); |
| 388 |
stk::mesh::Selector notBlock2 = all - selector; |
| 389 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 390 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField1, notBlock2, myConstantValue); |
| 391 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField1, selector, myBlock2Value); |
| 392 |
} |
| 393 |
|
| 394 |
TEST_F(NgpFieldBLAS, field_fill_device_with_host_build) |
| 395 |
{ |
| 396 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 397 |
|
| 398 |
const double myConstantValue = 55.5; |
| 399 |
constexpr bool MarkModOnDevice = true; |
| 400 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::HostExecSpace{}, MarkModOnDevice); |
| 401 |
|
| 402 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 403 |
stkField1->sync_to_host(); |
| 404 |
|
| 405 |
stk::mesh::Selector selector(*stkField1); |
| 406 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 407 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField1, selector, myConstantValue); |
| 408 |
} |
| 409 |
|
| 410 |
#endif |
| 411 |
|
| 412 |
#ifdef STK_USE_DEVICE_MESH |
| 413 |
|
| 414 |
TEST_F(NgpFieldBLAS, field_copy_device) |
| 415 |
{ |
| 416 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 417 |
|
| 418 |
const double myConstantValue = 55.5; |
| 419 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::ExecSpace()); |
| 420 |
stk::mesh::field_copy(*stkField1, *stkField2, stk::ngp::ExecSpace()); |
| 421 |
|
| 422 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 423 |
EXPECT_TRUE(stkField2->need_sync_to_host()); |
| 424 |
|
| 425 |
stk::mesh::Selector selector(*stkField1); |
| 426 |
|
| 427 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 428 |
auto ngpField1 = stk::mesh::get_updated_ngp_field<double>(*stkField1); |
| 429 |
auto ngpField2 = stk::mesh::get_updated_ngp_field<double>(*stkField2); |
| 430 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField1, selector, myConstantValue); |
| 431 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField2, selector, myConstantValue); |
| 432 |
|
| 433 |
stkField1->sync_to_host(); |
| 434 |
stkField2->sync_to_host(); |
| 435 |
|
| 436 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField1, selector, myConstantValue); |
| 437 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField2, selector, myConstantValue); |
| 438 |
} |
| 439 |
|
| 440 |
TEST_F(NgpFieldBLAS, field_copy_selector_device) |
| 441 |
{ |
| 442 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 443 |
|
| 444 |
const double myConstantValue = 55.5; |
| 445 |
const double myBlock2Value = 95.5; |
| 446 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::ExecSpace()); |
| 447 |
stk::mesh::field_copy(*stkField1, *stkField2, stk::ngp::ExecSpace()); |
| 448 |
stk::mesh::Part& block2 = *get_meta().get_part("block_2"); |
| 449 |
stk::mesh::Selector selector = block2; |
| 450 |
stk::mesh::field_fill(myBlock2Value, *stkField1, selector, stk::ngp::ExecSpace()); |
| 451 |
stk::mesh::field_copy(*stkField1, *stkField2, selector, stk::ngp::ExecSpace()); |
| 452 |
|
| 453 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 454 |
EXPECT_TRUE(stkField2->need_sync_to_host()); |
| 455 |
|
| 456 |
stk::mesh::Selector notBlock2(*stkField1); |
| 457 |
notBlock2 -= selector; |
| 458 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 459 |
auto ngpField1 = stk::mesh::get_updated_ngp_field<double>(*stkField1); |
| 460 |
auto ngpField2 = stk::mesh::get_updated_ngp_field<double>(*stkField2); |
| 461 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField1, notBlock2, myConstantValue); |
| 462 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField2, notBlock2, myConstantValue); |
| 463 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField1, selector, myBlock2Value); |
| 464 |
ngp_field_test_utils::check_field_data_on_device(ngpMesh, ngpField2, selector, myBlock2Value); |
| 465 |
|
| 466 |
stkField1->sync_to_host(); |
| 467 |
stkField2->sync_to_host(); |
| 468 |
|
| 469 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField1, notBlock2, myConstantValue); |
| 470 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField2, notBlock2, myConstantValue); |
| 471 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField1, selector, myBlock2Value); |
| 472 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField2, selector, myBlock2Value); |
| 473 |
} |
| 474 |
|
| 475 |
TEST_F(NgpFieldBLAS, field_copy_host_ngp) |
| 476 |
{ |
| 477 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 478 |
|
| 479 |
const double myConstantValue = 55.5; |
| 480 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::HostExecSpace{}); |
| 481 |
stk::mesh::field_copy(*stkField1, *stkField2, stk::ngp::HostExecSpace{}); |
| 482 |
|
| 483 |
#ifdef STK_ENABLE_GPU |
| 484 |
EXPECT_TRUE(stkField1->need_sync_to_device()); |
| 485 |
EXPECT_TRUE(stkField2->need_sync_to_device()); |
| 486 |
#else |
| 487 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 488 |
EXPECT_TRUE(stkField2->need_sync_to_host()); |
| 489 |
stkField1->sync_to_host(); |
| 490 |
stkField2->sync_to_host(); |
| 491 |
#endif |
| 492 |
|
| 493 |
|
| 494 |
stk::mesh::Selector selector(*stkField1); |
| 495 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField1, selector, myConstantValue); |
| 496 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField2, selector, myConstantValue); |
| 497 |
} |
| 498 |
|
| 499 |
#else /* not-defined STK_USE_DEVICE_MESH */ |
| 500 |
|
| 501 |
TEST_F(NgpFieldBLAS, field_copy_host) |
| 502 |
{ |
| 503 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 504 |
|
| 505 |
const double myConstantValue = 55.5; |
| 506 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::HostExecSpace{}); |
| 507 |
stk::mesh::field_copy(*stkField1, *stkField2, stk::ngp::HostExecSpace{}); |
| 508 |
|
| 509 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 510 |
EXPECT_FALSE(stkField2->need_sync_to_host()); |
| 511 |
|
| 512 |
stk::mesh::Selector selector(*stkField1); |
| 513 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 514 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField1, selector, myConstantValue); |
| 515 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField2, selector, myConstantValue); |
| 516 |
} |
| 517 |
|
| 518 |
TEST_F(NgpFieldBLAS, field_copy_selector_host) |
| 519 |
{ |
| 520 |
if (get_parallel_size() != 1) { GTEST_SKIP(); } |
| 521 |
|
| 522 |
const double myConstantValue = 55.5; |
| 523 |
const double myBlock2Value = 95.5; |
| 524 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::HostExecSpace{}); |
| 525 |
stk::mesh::field_copy(*stkField1, *stkField2, stk::ngp::HostExecSpace{}); |
| 526 |
stk::mesh::Part& block2 = *get_meta().get_part("block_2"); |
| 527 |
stk::mesh::Selector selector = block2; |
| 528 |
stk::mesh::field_fill(myBlock2Value, *stkField1, selector, stk::ngp::HostExecSpace{}); |
| 529 |
stk::mesh::field_copy(*stkField1, *stkField2, selector, stk::ngp::HostExecSpace{}); |
| 530 |
|
| 531 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 532 |
EXPECT_FALSE(stkField2->need_sync_to_host()); |
| 533 |
|
| 534 |
stk::mesh::Selector all(*stkField1); |
| 535 |
stk::mesh::Selector notBlock2 = all - selector; |
| 536 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 537 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField1, notBlock2, myConstantValue); |
| 538 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField2, notBlock2, myConstantValue); |
| 539 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField1, selector, myBlock2Value); |
| 540 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField2, selector, myBlock2Value); |
| 541 |
} |
| 542 |
|
| 543 |
TEST_F(NgpFieldBLAS, field_copy_device_with_host_build) |
| 544 |
{ |
| 545 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 546 |
|
| 547 |
const double myConstantValue = 55.5; |
| 548 |
constexpr bool MarkModOnDevice = true; |
| 549 |
stk::mesh::field_fill(myConstantValue, *stkField1, stk::ngp::HostExecSpace{}, MarkModOnDevice); |
| 550 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 551 |
|
| 552 |
stk::mesh::field_copy(*stkField1, *stkField2, stk::ngp::HostExecSpace{}, MarkModOnDevice); |
| 553 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 554 |
EXPECT_TRUE(stkField2->need_sync_to_host()); |
| 555 |
|
| 556 |
stk::mesh::Selector selector(*stkField1); |
| 557 |
auto ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 558 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField1, selector, myConstantValue); |
| 559 |
ngp_field_test_utils::check_field_data_on_host(ngpMesh, *stkField2, selector, myConstantValue); |
| 560 |
} |
| 561 |
|
| 562 |
#endif |
| 563 |
|
| 564 |
#ifdef STK_USE_DEVICE_MESH |
| 565 |
|
| 566 |
TEST_F(NgpFieldBLASNode, field_axpbyz_device) |
| 567 |
{ |
| 568 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 569 |
|
| 570 |
stk::mesh::Selector selectRule(*stkField1); |
| 571 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 572 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 573 |
|
| 574 |
double alpha = 2.0; |
| 575 |
double beta = 5.0; |
| 576 |
auto f_expected = [&](const double* coords) |
| 577 |
{ |
| 578 |
std::vector<double> vals1 = func1(coords); |
| 579 |
std::vector<double> vals2 = func2(coords); |
| 580 |
std::vector<double> result(vals1.size()); |
| 581 |
for (size_t i=0; i < vals1.size(); ++i) |
| 582 |
{ |
| 583 |
result[i] = alpha * vals1[i] + beta * vals2[i]; |
| 584 |
} |
| 585 |
|
| 586 |
return result; |
| 587 |
}; |
| 588 |
|
| 589 |
|
| 590 |
stk::mesh::field_axpbyz(get_bulk(), alpha, *stkField1, beta, *stkField2, *stkField3, selectRule, stk::ngp::ExecSpace()); |
| 591 |
EXPECT_TRUE(stkField3->need_sync_to_host()); |
| 592 |
|
| 593 |
stkField3->sync_to_host(); |
| 594 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField3, selectRule, {stkField1, stkField2}, f_expected); |
| 595 |
} |
| 596 |
|
| 597 |
TEST_F(NgpFieldBLASNode, field_axpbyz_host) |
| 598 |
{ |
| 599 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 600 |
|
| 601 |
stk::mesh::Selector selectRule(*stkField1); |
| 602 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 603 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 604 |
|
| 605 |
double alpha = 2.0; |
| 606 |
double beta = 5.0; |
| 607 |
auto f_expected = [&](const double* coords) |
| 608 |
{ |
| 609 |
std::vector<double> vals1 = func1(coords); |
| 610 |
std::vector<double> vals2 = func2(coords); |
| 611 |
std::vector<double> result(vals1.size()); |
| 612 |
for (size_t i=0; i < vals1.size(); ++i) |
| 613 |
{ |
| 614 |
result[i] = alpha * vals1[i] + beta * vals2[i]; |
| 615 |
} |
| 616 |
|
| 617 |
return result; |
| 618 |
}; |
| 619 |
|
| 620 |
|
| 621 |
stk::mesh::field_axpbyz(get_bulk(), alpha, *stkField1, beta, *stkField2, *stkField3, selectRule, stk::ngp::HostExecSpace()); |
| 622 |
|
| 623 |
#ifdef STK_ENABLE_GPU |
| 624 |
EXPECT_TRUE(stkField3->need_sync_to_device()); |
| 625 |
#else |
| 626 |
EXPECT_TRUE(stkField3->need_sync_to_host()); |
| 627 |
#endif |
| 628 |
|
| 629 |
stkField3->sync_to_host(); |
| 630 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField3, selectRule, {stkField1, stkField2}, f_expected); |
| 631 |
} |
| 632 |
|
| 633 |
#else |
| 634 |
|
| 635 |
TEST_F(NgpFieldBLASNode, field_axpbyz_exec_space) |
| 636 |
{ |
| 637 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 638 |
|
| 639 |
stk::mesh::Selector selectRule(*stkField1); |
| 640 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 641 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 642 |
|
| 643 |
double alpha = 2.0; |
| 644 |
double beta = 5.0; |
| 645 |
auto f_expected = [&](const double* coords) |
| 646 |
{ |
| 647 |
std::vector<double> vals1 = func1(coords); |
| 648 |
std::vector<double> vals2 = func2(coords); |
| 649 |
std::vector<double> result(vals1.size()); |
| 650 |
for (size_t i=0; i < vals1.size(); ++i) |
| 651 |
{ |
| 652 |
result[i] = alpha * vals1[i] + beta * vals2[i]; |
| 653 |
} |
| 654 |
|
| 655 |
return result; |
| 656 |
}; |
| 657 |
|
| 658 |
|
| 659 |
stk::mesh::field_axpbyz(get_bulk(), alpha, *stkField1, beta, *stkField2, *stkField3, selectRule, stk::ngp::ExecSpace()); |
| 660 |
EXPECT_FALSE(stkField3->need_sync_to_host()); |
| 661 |
|
| 662 |
stkField3->sync_to_host(); |
| 663 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField3, selectRule, {stkField1, stkField2}, f_expected); |
| 664 |
} |
| 665 |
|
| 666 |
TEST_F(NgpFieldBLASNode, field_axpbyz_no_selector) |
| 667 |
{ |
| 668 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 669 |
|
| 670 |
stk::mesh::Selector selectRule(*stkField1); |
| 671 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 672 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 673 |
|
| 674 |
double alpha = 2.0; |
| 675 |
double beta = 5.0; |
| 676 |
auto f_expected = [&](const double* coords) |
| 677 |
{ |
| 678 |
std::vector<double> vals1 = func1(coords); |
| 679 |
std::vector<double> vals2 = func2(coords); |
| 680 |
std::vector<double> result(vals1.size()); |
| 681 |
for (size_t i=0; i < vals1.size(); ++i) |
| 682 |
{ |
| 683 |
result[i] = alpha * vals1[i] + beta * vals2[i]; |
| 684 |
} |
| 685 |
|
| 686 |
return result; |
| 687 |
}; |
| 688 |
|
| 689 |
|
| 690 |
stk::mesh::field_axpbyz(get_bulk(), alpha, *stkField1, beta, *stkField2, *stkField3, stk::ngp::ExecSpace()); |
| 691 |
EXPECT_FALSE(stkField3->need_sync_to_host()); |
| 692 |
|
| 693 |
stkField3->sync_to_host(); |
| 694 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField3, selectRule, {stkField1, stkField2}, f_expected); |
| 695 |
} |
| 696 |
|
| 697 |
#endif |
| 698 |
|
| 699 |
#ifdef STK_USE_DEVICE_MESH |
| 700 |
|
| 701 |
TEST_F(NgpFieldBLASNode, field_axpby_device) |
| 702 |
{ |
| 703 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 704 |
|
| 705 |
stk::mesh::Selector selectRule(*stkField1); |
| 706 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 707 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 708 |
|
| 709 |
double alpha = 2.0; |
| 710 |
double beta = 5.0; |
| 711 |
auto f_expected = [&](const double* coords) |
| 712 |
{ |
| 713 |
std::vector<double> vals1 = func1(coords); |
| 714 |
std::vector<double> vals2 = func2(coords); |
| 715 |
std::vector<double> result(vals1.size()); |
| 716 |
for (size_t i=0; i < vals1.size(); ++i) |
| 717 |
{ |
| 718 |
result[i] = alpha * vals1[i] + beta * vals2[i]; |
| 719 |
} |
| 720 |
|
| 721 |
return result; |
| 722 |
}; |
| 723 |
|
| 724 |
|
| 725 |
stk::mesh::field_axpby(get_bulk(), alpha, *stkField1, beta, *stkField2, selectRule, stk::ngp::ExecSpace()); |
| 726 |
EXPECT_TRUE(stkField2->need_sync_to_host()); |
| 727 |
|
| 728 |
stkField2->sync_to_host(); |
| 729 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f_expected); |
| 730 |
} |
| 731 |
|
| 732 |
TEST_F(NgpFieldBLASNode, field_axpby_host) |
| 733 |
{ |
| 734 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 735 |
|
| 736 |
stk::mesh::Selector selectRule(*stkField1); |
| 737 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 738 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 739 |
|
| 740 |
double alpha = 2.0; |
| 741 |
double beta = 5.0; |
| 742 |
auto f_expected = [&](const double* coords) |
| 743 |
{ |
| 744 |
std::vector<double> vals1 = func1(coords); |
| 745 |
std::vector<double> vals2 = func2(coords); |
| 746 |
std::vector<double> result(vals1.size()); |
| 747 |
for (size_t i=0; i < vals1.size(); ++i) |
| 748 |
{ |
| 749 |
result[i] = alpha * vals1[i] + beta * vals2[i]; |
| 750 |
} |
| 751 |
|
| 752 |
return result; |
| 753 |
}; |
| 754 |
|
| 755 |
|
| 756 |
stk::mesh::field_axpby(get_bulk(), alpha, *stkField1, beta, *stkField2, selectRule, stk::ngp::HostExecSpace()); |
| 757 |
|
| 758 |
#ifdef STK_ENABLE_GPU |
| 759 |
EXPECT_TRUE(stkField2->need_sync_to_device()); |
| 760 |
#else |
| 761 |
EXPECT_TRUE(stkField2->need_sync_to_host()); |
| 762 |
#endif |
| 763 |
|
| 764 |
stkField2->sync_to_host(); |
| 765 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f_expected); |
| 766 |
} |
| 767 |
|
| 768 |
#else |
| 769 |
|
| 770 |
TEST_F(NgpFieldBLASNode, field_axpby_exec_space) |
| 771 |
{ |
| 772 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 773 |
|
| 774 |
stk::mesh::Selector selectRule(*stkField1); |
| 775 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 776 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 777 |
|
| 778 |
double alpha = 2.0; |
| 779 |
double beta = 5.0; |
| 780 |
auto f_expected = [&](const double* coords) |
| 781 |
{ |
| 782 |
std::vector<double> vals1 = func1(coords); |
| 783 |
std::vector<double> vals2 = func2(coords); |
| 784 |
std::vector<double> result(vals1.size()); |
| 785 |
for (size_t i=0; i < vals1.size(); ++i) |
| 786 |
{ |
| 787 |
result[i] = alpha * vals1[i] + beta * vals2[i]; |
| 788 |
} |
| 789 |
|
| 790 |
return result; |
| 791 |
}; |
| 792 |
|
| 793 |
|
| 794 |
stk::mesh::field_axpby(get_bulk(), alpha, *stkField1, beta, *stkField2, selectRule, stk::ngp::ExecSpace()); |
| 795 |
EXPECT_FALSE(stkField2->need_sync_to_host()); |
| 796 |
|
| 797 |
stkField2->sync_to_host(); |
| 798 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f_expected); |
| 799 |
} |
| 800 |
|
| 801 |
TEST_F(NgpFieldBLASNode, field_axpby_no_selector) |
| 802 |
{ |
| 803 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 804 |
|
| 805 |
stk::mesh::Selector selectRule(*stkField1); |
| 806 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 807 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 808 |
|
| 809 |
double alpha = 2.0; |
| 810 |
double beta = 5.0; |
| 811 |
auto f_expected = [&](const double* coords) |
| 812 |
{ |
| 813 |
std::vector<double> vals1 = func1(coords); |
| 814 |
std::vector<double> vals2 = func2(coords); |
| 815 |
std::vector<double> result(vals1.size()); |
| 816 |
for (size_t i=0; i < vals1.size(); ++i) |
| 817 |
{ |
| 818 |
result[i] = alpha * vals1[i] + beta * vals2[i]; |
| 819 |
} |
| 820 |
|
| 821 |
return result; |
| 822 |
}; |
| 823 |
|
| 824 |
|
| 825 |
stk::mesh::field_axpby(get_bulk(), alpha, *stkField1, beta, *stkField2, stk::ngp::ExecSpace()); |
| 826 |
EXPECT_FALSE(stkField2->need_sync_to_host()); |
| 827 |
|
| 828 |
stkField2->sync_to_host(); |
| 829 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f_expected); |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
#endif |
| 834 |
|
| 835 |
#ifdef STK_USE_DEVICE_MESH |
| 836 |
|
| 837 |
TEST_F(NgpFieldBLASNode, field_axpy_device) |
| 838 |
{ |
| 839 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 840 |
|
| 841 |
stk::mesh::Selector selectRule(*stkField1); |
| 842 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 843 |
|
| 844 |
double alpha = 2.0; |
| 845 |
auto f_expected = [&](const double* coords) |
| 846 |
{ |
| 847 |
std::vector<double> result = func1(coords); |
| 848 |
for (size_t i=0; i < result.size(); ++i) |
| 849 |
{ |
| 850 |
result[i] = alpha * result[i]; |
| 851 |
} |
| 852 |
|
| 853 |
return result; |
| 854 |
}; |
| 855 |
|
| 856 |
|
| 857 |
stk::mesh::field_axpy(get_bulk(), alpha, *stkField1, *stkField2, selectRule, stk::ngp::ExecSpace()); |
| 858 |
EXPECT_TRUE(stkField2->need_sync_to_host()); |
| 859 |
|
| 860 |
stkField2->sync_to_host(); |
| 861 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f_expected); |
| 862 |
} |
| 863 |
|
| 864 |
TEST_F(NgpFieldBLASNode, field_axpy_host) |
| 865 |
{ |
| 866 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 867 |
|
| 868 |
stk::mesh::Selector selectRule(*stkField1); |
| 869 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 870 |
|
| 871 |
double alpha = 2.0; |
| 872 |
auto f_expected = [&](const double* coords) |
| 873 |
{ |
| 874 |
std::vector<double> result = func1(coords); |
| 875 |
for (size_t i=0; i < result.size(); ++i) |
| 876 |
{ |
| 877 |
result[i] = alpha * result[i]; |
| 878 |
} |
| 879 |
|
| 880 |
return result; |
| 881 |
}; |
| 882 |
|
| 883 |
|
| 884 |
stk::mesh::field_axpy(get_bulk(), alpha, *stkField1, *stkField2, selectRule, stk::ngp::HostExecSpace()); |
| 885 |
|
| 886 |
#ifdef STK_ENABLE_GPU |
| 887 |
EXPECT_TRUE(stkField2->need_sync_to_device()); |
| 888 |
#else |
| 889 |
EXPECT_TRUE(stkField2->need_sync_to_host()); |
| 890 |
#endif |
| 891 |
|
| 892 |
stkField2->sync_to_host(); |
| 893 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f_expected); |
| 894 |
} |
| 895 |
|
| 896 |
#else |
| 897 |
|
| 898 |
TEST_F(NgpFieldBLASNode, field_axpy_exec_space) |
| 899 |
{ |
| 900 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 901 |
|
| 902 |
stk::mesh::Selector selectRule(*stkField1); |
| 903 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 904 |
|
| 905 |
double alpha = 2.0; |
| 906 |
auto f_expected = [&](const double* coords) |
| 907 |
{ |
| 908 |
std::vector<double> result = func1(coords); |
| 909 |
for (size_t i=0; i < result.size(); ++i) |
| 910 |
{ |
| 911 |
result[i] = alpha * result[i]; |
| 912 |
} |
| 913 |
|
| 914 |
return result; |
| 915 |
}; |
| 916 |
|
| 917 |
stk::mesh::field_axpy(get_bulk(), alpha, *stkField1, *stkField2, selectRule, stk::ngp::ExecSpace()); |
| 918 |
EXPECT_FALSE(stkField2->need_sync_to_host()); |
| 919 |
|
| 920 |
stkField2->sync_to_host(); |
| 921 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f_expected); |
| 922 |
} |
| 923 |
|
| 924 |
TEST_F(NgpFieldBLASNode, field_axpy_no_selector) |
| 925 |
{ |
| 926 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 927 |
|
| 928 |
stk::mesh::Selector selectRule(*stkField1); |
| 929 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 930 |
|
| 931 |
double alpha = 2.0; |
| 932 |
auto f_expected = [&](const double* coords) |
| 933 |
{ |
| 934 |
std::vector<double> result = func1(coords); |
| 935 |
for (size_t i=0; i < result.size(); ++i) |
| 936 |
{ |
| 937 |
result[i] = alpha * result[i]; |
| 938 |
} |
| 939 |
|
| 940 |
return result; |
| 941 |
}; |
| 942 |
|
| 943 |
stk::mesh::field_axpy(get_bulk(), alpha, *stkField1, *stkField2, stk::ngp::ExecSpace()); |
| 944 |
EXPECT_FALSE(stkField2->need_sync_to_host()); |
| 945 |
|
| 946 |
stkField2->sync_to_host(); |
| 947 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f_expected); |
| 948 |
} |
| 949 |
|
| 950 |
#endif |
| 951 |
|
| 952 |
#ifdef STK_USE_DEVICE_MESH |
| 953 |
|
| 954 |
TEST_F(NgpFieldBLASNode, field_product_device) |
| 955 |
{ |
| 956 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 957 |
|
| 958 |
stk::mesh::Selector selectRule(*stkField1); |
| 959 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 960 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 961 |
|
| 962 |
|
| 963 |
auto f_expected = [&](const double* coords) |
| 964 |
{ |
| 965 |
std::vector<double> vals1 = func1(coords); |
| 966 |
std::vector<double> vals2 = func2(coords); |
| 967 |
std::vector<double> result(vals1.size()); |
| 968 |
for (size_t i=0; i < vals1.size(); ++i) |
| 969 |
{ |
| 970 |
result[i] = vals1[i] * vals2[i]; |
| 971 |
} |
| 972 |
|
| 973 |
return result; |
| 974 |
}; |
| 975 |
|
| 976 |
|
| 977 |
stk::mesh::field_product(get_bulk(), *stkField1, *stkField2, *stkField3, selectRule, stk::ngp::ExecSpace()); |
| 978 |
EXPECT_TRUE(stkField3->need_sync_to_host()); |
| 979 |
|
| 980 |
stkField3->sync_to_host(); |
| 981 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField3, selectRule, {stkField1, stkField2}, f_expected); |
| 982 |
} |
| 983 |
|
| 984 |
TEST_F(NgpFieldBLASNode, field_product_host) |
| 985 |
{ |
| 986 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 987 |
|
| 988 |
stk::mesh::Selector selectRule(*stkField1); |
| 989 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 990 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 991 |
|
| 992 |
auto f_expected = [&](const double* coords) |
| 993 |
{ |
| 994 |
std::vector<double> vals1 = func1(coords); |
| 995 |
std::vector<double> vals2 = func2(coords); |
| 996 |
std::vector<double> result(vals1.size()); |
| 997 |
for (size_t i=0; i < vals1.size(); ++i) |
| 998 |
{ |
| 999 |
result[i] = vals1[i] * vals2[i]; |
| 1000 |
} |
| 1001 |
|
| 1002 |
return result; |
| 1003 |
}; |
| 1004 |
|
| 1005 |
|
| 1006 |
stk::mesh::field_product(get_bulk(), *stkField1, *stkField2, *stkField3, selectRule, stk::ngp::HostExecSpace()); |
| 1007 |
|
| 1008 |
#ifdef STK_ENABLE_GPU |
| 1009 |
EXPECT_TRUE(stkField3->need_sync_to_device()); |
| 1010 |
#else |
| 1011 |
EXPECT_TRUE(stkField3->need_sync_to_host()); |
| 1012 |
#endif |
| 1013 |
|
| 1014 |
stkField3->sync_to_host(); |
| 1015 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField3, selectRule, {stkField1, stkField2}, f_expected); |
| 1016 |
} |
| 1017 |
|
| 1018 |
#else |
| 1019 |
|
| 1020 |
TEST_F(NgpFieldBLASNode, field_product_exec_space) |
| 1021 |
{ |
| 1022 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 1023 |
|
| 1024 |
stk::mesh::Selector selectRule(*stkField1); |
| 1025 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1026 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 1027 |
|
| 1028 |
auto f_expected = [&](const double* coords) |
| 1029 |
{ |
| 1030 |
std::vector<double> vals1 = func1(coords); |
| 1031 |
std::vector<double> vals2 = func2(coords); |
| 1032 |
std::vector<double> result(vals1.size()); |
| 1033 |
for (size_t i=0; i < vals1.size(); ++i) |
| 1034 |
{ |
| 1035 |
result[i] = vals1[i] * vals2[i]; |
| 1036 |
} |
| 1037 |
|
| 1038 |
return result; |
| 1039 |
}; |
| 1040 |
|
| 1041 |
stk::mesh::field_product(get_bulk(), *stkField1, *stkField2, *stkField3, selectRule, stk::ngp::ExecSpace()); |
| 1042 |
EXPECT_FALSE(stkField3->need_sync_to_host()); |
| 1043 |
|
| 1044 |
stkField3->sync_to_host(); |
| 1045 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField3, selectRule, {stkField1, stkField2}, f_expected); |
| 1046 |
} |
| 1047 |
|
| 1048 |
TEST_F(NgpFieldBLASNode, field_product_no_selector) |
| 1049 |
{ |
| 1050 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 1051 |
|
| 1052 |
stk::mesh::Selector selectRule(*stkField1); |
| 1053 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1054 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 1055 |
|
| 1056 |
|
| 1057 |
auto f_expected = [&](const double* coords) |
| 1058 |
{ |
| 1059 |
std::vector<double> vals1 = func1(coords); |
| 1060 |
std::vector<double> vals2 = func2(coords); |
| 1061 |
std::vector<double> result(vals1.size()); |
| 1062 |
for (size_t i=0; i < vals1.size(); ++i) |
| 1063 |
{ |
| 1064 |
result[i] = vals1[i] * vals2[i]; |
| 1065 |
} |
| 1066 |
|
| 1067 |
return result; |
| 1068 |
}; |
| 1069 |
|
| 1070 |
stk::mesh::field_product(get_bulk(), *stkField1, *stkField2, *stkField3, stk::ngp::ExecSpace()); |
| 1071 |
EXPECT_FALSE(stkField3->need_sync_to_host()); |
| 1072 |
|
| 1073 |
stkField3->sync_to_host(); |
| 1074 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField3, selectRule, {stkField1, stkField2}, f_expected); |
| 1075 |
} |
| 1076 |
|
| 1077 |
TEST_F(NgpFieldBLAS, field_axpby) |
| 1078 |
{ |
| 1079 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 1080 |
|
| 1081 |
stk::mesh::field_fill(3.0, *stkField1, stk::ngp::ExecSpace()); |
| 1082 |
stk::mesh::field_fill(10.0, *stkField2, stk::ngp::ExecSpace()); |
| 1083 |
|
| 1084 |
double alpha = 2.0; |
| 1085 |
double beta = 5.0; |
| 1086 |
stk::mesh::Selector selectRule(*stkField1); |
| 1087 |
|
| 1088 |
stk::mesh::field_axpby(get_bulk(), alpha, *stkField1, beta, *stkField2, selectRule, stk::ngp::ExecSpace()); |
| 1089 |
|
| 1090 |
stkField2->sync_to_host(); |
| 1091 |
stk::mesh::Selector selector(*stkField2); |
| 1092 |
constexpr double expectedValue = 56.0; |
| 1093 |
ngp_field_test_utils::check_field_data_on_host(get_bulk(), *stkField2, selector, expectedValue); |
| 1094 |
} |
| 1095 |
#endif |
| 1096 |
|
| 1097 |
#ifdef STK_USE_DEVICE_MESH |
| 1098 |
|
| 1099 |
TEST_F(NgpFieldBLASNode, field_scale_device) |
| 1100 |
{ |
| 1101 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 1102 |
|
| 1103 |
stk::mesh::Selector selectRule(*stkField1); |
| 1104 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1105 |
|
| 1106 |
double alpha = 2.0; |
| 1107 |
auto f_expected = [&](const double* coords) |
| 1108 |
{ |
| 1109 |
std::vector<double> result = func1(coords); |
| 1110 |
for (size_t i=0; i < result.size(); ++i) |
| 1111 |
{ |
| 1112 |
result[i] = alpha * result[i]; |
| 1113 |
} |
| 1114 |
|
| 1115 |
return result; |
| 1116 |
}; |
| 1117 |
|
| 1118 |
|
| 1119 |
stk::mesh::field_scale(get_bulk(), alpha, *stkField1, selectRule, stk::ngp::ExecSpace()); |
| 1120 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 1121 |
|
| 1122 |
stkField1->sync_to_host(); |
| 1123 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField1, selectRule, {}, f_expected); |
| 1124 |
} |
| 1125 |
|
| 1126 |
TEST_F(NgpFieldBLASNode, field_scale_host) |
| 1127 |
{ |
| 1128 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 1129 |
|
| 1130 |
stk::mesh::Selector selectRule(*stkField1); |
| 1131 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1132 |
|
| 1133 |
double alpha = 2.0; |
| 1134 |
auto f_expected = [&](const double* coords) |
| 1135 |
{ |
| 1136 |
std::vector<double> result = func1(coords); |
| 1137 |
for (size_t i=0; i < result.size(); ++i) |
| 1138 |
{ |
| 1139 |
result[i] = alpha * result[i]; |
| 1140 |
} |
| 1141 |
|
| 1142 |
return result; |
| 1143 |
}; |
| 1144 |
|
| 1145 |
|
| 1146 |
stk::mesh::field_scale(get_bulk(), alpha, *stkField1, selectRule, stk::ngp::HostExecSpace()); |
| 1147 |
|
| 1148 |
#ifdef STK_ENABLE_GPU |
| 1149 |
EXPECT_TRUE(stkField1->need_sync_to_device()); |
| 1150 |
#else |
| 1151 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 1152 |
#endif |
| 1153 |
|
| 1154 |
stkField1->sync_to_host(); |
| 1155 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField1, selectRule, {}, f_expected); |
| 1156 |
} |
| 1157 |
|
| 1158 |
#else |
| 1159 |
|
| 1160 |
TEST_F(NgpFieldBLASNode, field_scale_exec_space) |
| 1161 |
{ |
| 1162 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 1163 |
|
| 1164 |
stk::mesh::Selector selectRule(*stkField1); |
| 1165 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1166 |
|
| 1167 |
double alpha = 2.0; |
| 1168 |
auto f_expected = [&](const double* coords) |
| 1169 |
{ |
| 1170 |
std::vector<double> result = func1(coords); |
| 1171 |
for (size_t i=0; i < result.size(); ++i) |
| 1172 |
{ |
| 1173 |
result[i] = alpha * result[i]; |
| 1174 |
} |
| 1175 |
|
| 1176 |
return result; |
| 1177 |
}; |
| 1178 |
|
| 1179 |
stk::mesh::field_scale(get_bulk(), alpha, *stkField1, selectRule, stk::ngp::ExecSpace()); |
| 1180 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 1181 |
|
| 1182 |
stkField1->sync_to_host(); |
| 1183 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField1, selectRule, {}, f_expected); |
| 1184 |
} |
| 1185 |
|
| 1186 |
TEST_F(NgpFieldBLASNode, field_scale_no_selector) |
| 1187 |
{ |
| 1188 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 1189 |
|
| 1190 |
stk::mesh::Selector selectRule(*stkField1); |
| 1191 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1192 |
|
| 1193 |
double alpha = 2.0; |
| 1194 |
auto f_expected = [&](const double* coords) |
| 1195 |
{ |
| 1196 |
std::vector<double> result = func1(coords); |
| 1197 |
for (size_t i=0; i < result.size(); ++i) |
| 1198 |
{ |
| 1199 |
result[i] = alpha * result[i]; |
| 1200 |
} |
| 1201 |
|
| 1202 |
return result; |
| 1203 |
}; |
| 1204 |
|
| 1205 |
stk::mesh::field_scale(get_bulk(), alpha, *stkField1, stk::ngp::ExecSpace()); |
| 1206 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 1207 |
|
| 1208 |
stkField1->sync_to_host(); |
| 1209 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField1, selectRule, {}, f_expected); |
| 1210 |
} |
| 1211 |
|
| 1212 |
#endif |
| 1213 |
|
| 1214 |
#ifdef STK_USE_DEVICE_MESH |
| 1215 |
|
| 1216 |
TEST_F(NgpFieldBLASNode, field_swap_device) |
| 1217 |
{ |
| 1218 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 1219 |
|
| 1220 |
stk::mesh::Selector selectRule(*stkField1); |
| 1221 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1222 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 1223 |
|
| 1224 |
auto f1_expected = [&](const double* coords) |
| 1225 |
{ |
| 1226 |
return func2(coords); |
| 1227 |
}; |
| 1228 |
|
| 1229 |
auto f2_expected = [&](const double* coords) |
| 1230 |
{ |
| 1231 |
return func1(coords); |
| 1232 |
}; |
| 1233 |
|
| 1234 |
stk::mesh::field_swap(get_bulk(), *stkField1, *stkField2, selectRule, stk::ngp::ExecSpace()); |
| 1235 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 1236 |
EXPECT_TRUE(stkField2->need_sync_to_host()); |
| 1237 |
|
| 1238 |
stkField1->sync_to_host(); |
| 1239 |
stkField2->sync_to_host(); |
| 1240 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField1, selectRule, {stkField2}, f1_expected); |
| 1241 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f2_expected); |
| 1242 |
} |
| 1243 |
|
| 1244 |
TEST_F(NgpFieldBLASNode, field_swap_host) |
| 1245 |
{ |
| 1246 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 1247 |
|
| 1248 |
stk::mesh::Selector selectRule(*stkField1); |
| 1249 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1250 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 1251 |
|
| 1252 |
auto f1_expected = [&](const double* coords) |
| 1253 |
{ |
| 1254 |
return func2(coords); |
| 1255 |
}; |
| 1256 |
|
| 1257 |
auto f2_expected = [&](const double* coords) |
| 1258 |
{ |
| 1259 |
return func1(coords); |
| 1260 |
}; |
| 1261 |
|
| 1262 |
|
| 1263 |
stk::mesh::field_swap(get_bulk(), *stkField1, *stkField2, selectRule, stk::ngp::HostExecSpace()); |
| 1264 |
|
| 1265 |
#ifdef STK_ENABLE_GPU |
| 1266 |
EXPECT_TRUE(stkField1->need_sync_to_device()); |
| 1267 |
EXPECT_TRUE(stkField2->need_sync_to_device()); |
| 1268 |
#else |
| 1269 |
EXPECT_TRUE(stkField1->need_sync_to_host()); |
| 1270 |
EXPECT_TRUE(stkField2->need_sync_to_host()); |
| 1271 |
#endif |
| 1272 |
|
| 1273 |
stkField1->sync_to_host(); |
| 1274 |
stkField2->sync_to_host(); |
| 1275 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField1, selectRule, {stkField2}, f1_expected); |
| 1276 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f2_expected); |
| 1277 |
} |
| 1278 |
|
| 1279 |
#else |
| 1280 |
|
| 1281 |
TEST_F(NgpFieldBLASNode, field_swap_exec_space) |
| 1282 |
{ |
| 1283 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 1284 |
|
| 1285 |
stk::mesh::Selector selectRule(*stkField1); |
| 1286 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1287 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 1288 |
|
| 1289 |
auto f1_expected = [&](const double* coords) |
| 1290 |
{ |
| 1291 |
return func2(coords); |
| 1292 |
}; |
| 1293 |
|
| 1294 |
auto f2_expected = [&](const double* coords) |
| 1295 |
{ |
| 1296 |
return func1(coords); |
| 1297 |
}; |
| 1298 |
|
| 1299 |
stk::mesh::field_swap(get_bulk(), *stkField1, *stkField2, selectRule, stk::ngp::ExecSpace()); |
| 1300 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 1301 |
EXPECT_FALSE(stkField2->need_sync_to_host()); |
| 1302 |
|
| 1303 |
stkField1->sync_to_host(); |
| 1304 |
stkField2->sync_to_host(); |
| 1305 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField1, selectRule, {stkField2}, f1_expected); |
| 1306 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f2_expected); |
| 1307 |
} |
| 1308 |
|
| 1309 |
TEST_F(NgpFieldBLASNode, field_swap_no_selector) |
| 1310 |
{ |
| 1311 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 1312 |
|
| 1313 |
stk::mesh::Selector selectRule(*stkField1); |
| 1314 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1315 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField2, selectRule, &func2); |
| 1316 |
|
| 1317 |
auto f1_expected = [&](const double* coords) |
| 1318 |
{ |
| 1319 |
return func2(coords); |
| 1320 |
}; |
| 1321 |
|
| 1322 |
auto f2_expected = [&](const double* coords) |
| 1323 |
{ |
| 1324 |
return func1(coords); |
| 1325 |
}; |
| 1326 |
|
| 1327 |
stk::mesh::field_swap(get_bulk(), *stkField1, *stkField2, stk::ngp::ExecSpace()); |
| 1328 |
EXPECT_FALSE(stkField1->need_sync_to_host()); |
| 1329 |
EXPECT_FALSE(stkField2->need_sync_to_host()); |
| 1330 |
|
| 1331 |
stkField1->sync_to_host(); |
| 1332 |
stkField2->sync_to_host(); |
| 1333 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField1, selectRule, {stkField2}, f1_expected); |
| 1334 |
ngp_field_test_utils::check_field_data_on_host_func(get_bulk(), *stkField2, selectRule, {stkField1}, f2_expected); |
| 1335 |
|
| 1336 |
} |
| 1337 |
|
| 1338 |
#endif |
| 1339 |
|
| 1340 |
#ifdef STK_USE_DEVICE_MESH |
| 1341 |
|
| 1342 |
TEST_F(NgpFieldBLASNode, field_amax_device) |
| 1343 |
{ |
| 1344 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 1345 |
|
| 1346 |
stk::mesh::Selector selectRule(*stkField1); |
| 1347 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1348 |
stkField1->sync_to_device(); |
| 1349 |
|
| 1350 |
double hostAMaxVal = 0.0; |
| 1351 |
|
| 1352 |
stk::mesh::EntityVector nodes; |
| 1353 |
get_bulk().get_entities(stk::topology::NODE_RANK, selectRule, nodes); |
| 1354 |
for (auto& n : nodes) { |
| 1355 |
double* myVal = static_cast<double*>(stk::mesh::field_data(*stkField1, n)); |
| 1356 |
const int numComponents = stk::mesh::field_scalars_per_entity(*stkField1, n); |
| 1357 |
for (int i = 0; i < numComponents; ++i) { |
| 1358 |
hostAMaxVal = std::max(hostAMaxVal, myVal[i]); |
| 1359 |
} |
| 1360 |
} |
| 1361 |
|
| 1362 |
double globalHostMax = hostAMaxVal; |
| 1363 |
stk::all_reduce_max(get_bulk().parallel(), &hostAMaxVal, &globalHostMax, 1u); |
| 1364 |
|
| 1365 |
double devAmaxVal = 0.0; |
| 1366 |
stk::mesh::field_amax(devAmaxVal, *stkField1, selectRule, stk::ngp::ExecSpace()); |
| 1367 |
|
| 1368 |
EXPECT_EQ(globalHostMax, devAmaxVal); |
| 1369 |
} |
| 1370 |
|
| 1371 |
TEST_F(NgpFieldBLASNode, field_amax_host) |
| 1372 |
{ |
| 1373 |
if (get_parallel_size() > 2) GTEST_SKIP(); |
| 1374 |
|
| 1375 |
stk::mesh::Selector selectRule(*stkField1); |
| 1376 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1377 |
|
| 1378 |
double hostAMaxVal = 0.0; |
| 1379 |
|
| 1380 |
stk::mesh::EntityVector nodes; |
| 1381 |
get_bulk().get_entities(stk::topology::NODE_RANK, selectRule, nodes); |
| 1382 |
for (auto& n : nodes) { |
| 1383 |
double* myVal = static_cast<double*>(stk::mesh::field_data(*stkField1, n)); |
| 1384 |
const int numComponents = stk::mesh::field_scalars_per_entity(*stkField1, n); |
| 1385 |
for (int i = 0; i < numComponents; ++i) { |
| 1386 |
hostAMaxVal = std::max(hostAMaxVal, myVal[i]); |
| 1387 |
} |
| 1388 |
} |
| 1389 |
|
| 1390 |
double globalHostMax = hostAMaxVal; |
| 1391 |
stk::all_reduce_max(get_bulk().parallel(), &hostAMaxVal, &globalHostMax, 1u); |
| 1392 |
|
| 1393 |
double devAmaxVal = 0.0; |
| 1394 |
stk::mesh::field_amax(devAmaxVal, *stkField1, selectRule, stk::ngp::HostExecSpace()); |
| 1395 |
|
| 1396 |
EXPECT_EQ(globalHostMax, devAmaxVal); |
| 1397 |
} |
| 1398 |
|
| 1399 |
#else |
| 1400 |
|
| 1401 |
TEST_F(NgpFieldBLASNode, field_amax_exec_space) |
| 1402 |
{ |
| 1403 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 1404 |
|
| 1405 |
stk::mesh::Selector selectRule(*stkField1); |
| 1406 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1407 |
|
| 1408 |
double hostAMaxVal = 0.0; |
| 1409 |
|
| 1410 |
stk::mesh::EntityVector nodes; |
| 1411 |
get_bulk().get_entities(stk::topology::NODE_RANK, selectRule, nodes); |
| 1412 |
for (auto& n : nodes) { |
| 1413 |
double* myVal = static_cast<double*>(stk::mesh::field_data(*stkField1, n)); |
| 1414 |
const int numComponents = stk::mesh::field_scalars_per_entity(*stkField1, n); |
| 1415 |
for (int i = 0; i < numComponents; ++i) { |
| 1416 |
hostAMaxVal = std::max(hostAMaxVal, myVal[i]); |
| 1417 |
} |
| 1418 |
} |
| 1419 |
|
| 1420 |
double devAmaxVal = 0.0; |
| 1421 |
stk::mesh::field_amax(devAmaxVal, *stkField1, selectRule, stk::ngp::ExecSpace()); |
| 1422 |
|
| 1423 |
EXPECT_EQ(hostAMaxVal, devAmaxVal); |
| 1424 |
} |
| 1425 |
|
| 1426 |
TEST_F(NgpFieldBLASNode, field_amax_no_selector) |
| 1427 |
{ |
| 1428 |
if (get_parallel_size() != 1) GTEST_SKIP(); |
| 1429 |
|
| 1430 |
stk::mesh::Selector selectRule(*stkField1); |
| 1431 |
ngp_field_test_utils::set_field_data_on_host(get_bulk(), *stkField1, selectRule, &func1); |
| 1432 |
|
| 1433 |
double hostAMaxVal = 0.0; |
| 1434 |
|
| 1435 |
stk::mesh::EntityVector nodes; |
| 1436 |
get_bulk().get_entities(stk::topology::NODE_RANK, selectRule, nodes); |
| 1437 |
for (auto& n : nodes) { |
| 1438 |
double* myVal = static_cast<double*>(stk::mesh::field_data(*stkField1, n)); |
| 1439 |
const int numComponents = stk::mesh::field_scalars_per_entity(*stkField1, n); |
| 1440 |
for (int i = 0; i < numComponents; ++i) { |
| 1441 |
hostAMaxVal = std::max(hostAMaxVal, myVal[i]); |
| 1442 |
} |
| 1443 |
} |
| 1444 |
|
| 1445 |
double devAmaxVal = 0.0; |
| 1446 |
stk::mesh::field_amax(devAmaxVal, *stkField1, stk::ngp::ExecSpace()); |
| 1447 |
|
| 1448 |
EXPECT_EQ(hostAMaxVal, devAmaxVal); |
| 1449 |
} |
| 1450 |
|
| 1451 |
#endif |
| 1452 |
} |
| 1453 |
|