libMesh
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
libMeshTest::KokkosTensorOracle Namespace Reference

Classes

struct  tensor_dim_case
 

Typedefs

using oracle_vector = libMesh::TypeVector< Real >
 
using oracle_tensor = libMesh::TypeTensor< Real >
 

Functions

oracle_vector make_host_vector (const Real x, const Real y=0, const Real z=0)
 
oracle_tensor make_host_tensor (const Real xx, const Real xy=0, const Real xz=0, const Real yx=0, const Real yy=0, const Real yz=0, const Real zx=0, const Real zy=0, const Real zz=0)
 
oracle_tensor build_identity_tensor (const unsigned int dim)
 
Real host_leading_determinant (const oracle_tensor &J, const unsigned int dim)
 
oracle_tensor host_leading_inverse (const oracle_tensor &J, const unsigned int dim)
 
template<typename StoragePolicy >
static int test_dim_ops ()
 
template<typename StoragePolicy >
static int test_tensor_ops ()
 
int test_tensor_host_only_ops ()
 
template<typename StoragePolicy >
static int test_linalg_foundation_storage_roundtrip ()
 
template<typename StoragePolicy >
static int test_mixed_representation_ops ()
 
int run_all_oracles ()
 

Variables

static constexpr double tol = 2.0e-13
 
static const tensor_dim_case dim_cases []
 

Typedef Documentation

◆ oracle_tensor

Definition at line 34 of file kokkos_tensor_ops_oracle_fixtures.h.

◆ oracle_vector

Definition at line 33 of file kokkos_tensor_ops_oracle_fixtures.h.

Function Documentation

◆ build_identity_tensor()

oracle_tensor libMeshTest::KokkosTensorOracle::build_identity_tensor ( const unsigned int  dim)
inline

Definition at line 119 of file kokkos_tensor_ops_oracle_fixtures.h.

120{
122 I.zero();
123 for (unsigned int i = 0; i < dim; ++i)
124 I(i, i) = Real(1);
125 return I;
126}
unsigned int dim
LIBMESH_DEVICE_INLINE void zero()
Set all entries of the tensor to 0.

References dim, and libMesh::TypeTensor< T >::zero().

Referenced by test_dim_ops().

◆ host_leading_determinant()

Real libMeshTest::KokkosTensorOracle::host_leading_determinant ( const oracle_tensor &  J,
const unsigned int  dim 
)
inline

Definition at line 134 of file kokkos_tensor_ops_oracle_fixtures.h.

135{
136 if (dim == 0)
137 return Real(1);
138 if (dim == 1)
139 return J(0, 0);
140 if (dim == 2)
141 return J(0, 0) * J(1, 1) - J(0, 1) * J(1, 0);
142#if LIBMESH_DIM > 2
143 return J.det();
144#else
145 return Real(0);
146#endif
147}

References libMesh::TypeTensor< T >::det(), and dim.

Referenced by host_leading_inverse(), test_dim_ops(), and test_mixed_representation_ops().

◆ host_leading_inverse()

oracle_tensor libMeshTest::KokkosTensorOracle::host_leading_inverse ( const oracle_tensor &  J,
const unsigned int  dim 
)
inline

Definition at line 150 of file kokkos_tensor_ops_oracle_fixtures.h.

151{
152 oracle_tensor inv;
153 inv.zero();
154
155 if (dim == 1)
156 {
157 inv(0, 0) = Real(1) / J(0, 0);
158 return inv;
159 }
160
161 if (dim == 2)
162 {
163 const Real det = host_leading_determinant(J, dim);
164 inv(0, 0) = J(1, 1) / det;
165 inv(0, 1) = -J(0, 1) / det;
166 inv(1, 0) = -J(1, 0) / det;
167 inv(1, 1) = J(0, 0) / det;
168 return inv;
169 }
170
171#if LIBMESH_DIM > 2
172 return oracle_tensor(J.inverse());
173#else
174 return inv;
175#endif
176}
TypeTensor< T > inverse() const

References dim, host_leading_determinant(), libMesh::TypeTensor< T >::inverse(), and libMesh::TypeTensor< T >::zero().

Referenced by test_dim_ops(), and test_mixed_representation_ops().

◆ make_host_tensor()

oracle_tensor libMeshTest::KokkosTensorOracle::make_host_tensor ( const Real  xx,
const Real  xy = 0,
const Real  xz = 0,
const Real  yx = 0,
const Real  yy = 0,
const Real  yz = 0,
const Real  zx = 0,
const Real  zy = 0,
const Real  zz = 0 
)
inline

Definition at line 56 of file kokkos_tensor_ops_oracle_fixtures.h.

65{
67 T.zero();
68 T(0, 0) = xx;
69#if LIBMESH_DIM > 1
70 T(0, 1) = xy;
71 T(1, 0) = yx;
72 T(1, 1) = yy;
73#endif
74#if LIBMESH_DIM > 2
75 T(0, 2) = xz;
76 T(1, 2) = yz;
77 T(2, 0) = zx;
78 T(2, 1) = zy;
79 T(2, 2) = zz;
80#endif
81 return T;
82}

References libMesh::TypeTensor< T >::zero().

Referenced by test_mixed_representation_ops(), and test_tensor_ops().

◆ make_host_vector()

oracle_vector libMeshTest::KokkosTensorOracle::make_host_vector ( const Real  x,
const Real  y = 0,
const Real  z = 0 
)
inline

Definition at line 41 of file kokkos_tensor_ops_oracle_fixtures.h.

42{
44 v.zero();
45 v(0) = x;
46#if LIBMESH_DIM > 1
47 v(1) = y;
48#endif
49#if LIBMESH_DIM > 2
50 v(2) = z;
51#endif
52 return v;
53}
LIBMESH_DEVICE_INLINE void zero()
Set all entries of the vector to 0.

References libMesh::TypeVector< T >::zero().

Referenced by test_mixed_representation_ops(), and test_tensor_ops().

◆ run_all_oracles()

int libMeshTest::KokkosTensorOracle::run_all_oracles ( )
inline

Definition at line 463 of file kokkos_tensor_ops_oracle_runners.h.

464{
465 int total_fail = 0;
466
467 const int dim_fail_left = test_dim_ops<libMesh::Kokkos::layout_left_storage_policy>();
468 std::printf("[tensor_dim_kernel_oracle] [%s] %s (%d failures)\n",
469 libMesh::Kokkos::storage_policy_name<libMesh::Kokkos::layout_left_storage_policy>(),
470 dim_fail_left ? "FAIL" : "PASS",
471 dim_fail_left);
472 total_fail += dim_fail_left;
473
474 const int dim_fail_right = test_dim_ops<libMesh::Kokkos::layout_right_storage_policy>();
475 std::printf("[tensor_dim_kernel_oracle] [%s] %s (%d failures)\n",
476 libMesh::Kokkos::storage_policy_name<libMesh::Kokkos::layout_right_storage_policy>(),
477 dim_fail_right ? "FAIL" : "PASS",
478 dim_fail_right);
479 total_fail += dim_fail_right;
480
481 const int tensor_fail_left = test_tensor_ops<libMesh::Kokkos::layout_left_storage_policy>();
482 std::printf("[tensor_ops_kernel_oracle] [%s] %s (%d failures)\n",
483 libMesh::Kokkos::storage_policy_name<libMesh::Kokkos::layout_left_storage_policy>(),
484 tensor_fail_left ? "FAIL" : "PASS",
485 tensor_fail_left);
486 total_fail += tensor_fail_left;
487
488 const int tensor_fail_right = test_tensor_ops<libMesh::Kokkos::layout_right_storage_policy>();
489 std::printf("[tensor_ops_kernel_oracle] [%s] %s (%d failures)\n",
490 libMesh::Kokkos::storage_policy_name<libMesh::Kokkos::layout_right_storage_policy>(),
491 tensor_fail_right ? "FAIL" : "PASS",
492 tensor_fail_right);
493 total_fail += tensor_fail_right;
494
495 const int host_fail = test_tensor_host_only_ops();
496 std::printf("[tensor_host_ops_oracle] %s (%d failures)\n",
497 host_fail ? "FAIL" : "PASS",
498 host_fail);
499 total_fail += host_fail;
500
501 const int foundation_fail_left =
502 test_linalg_foundation_storage_roundtrip<libMesh::Kokkos::layout_left_storage_policy>();
503 std::printf("[kokkos_linalg_foundation_oracle] [%s] %s (%d failures)\n",
504 libMesh::Kokkos::storage_policy_name<libMesh::Kokkos::layout_left_storage_policy>(),
505 foundation_fail_left ? "FAIL" : "PASS",
506 foundation_fail_left);
507 total_fail += foundation_fail_left;
508
509 const int foundation_fail_right =
510 test_linalg_foundation_storage_roundtrip<libMesh::Kokkos::layout_right_storage_policy>();
511 std::printf("[kokkos_linalg_foundation_oracle] [%s] %s (%d failures)\n",
512 libMesh::Kokkos::storage_policy_name<libMesh::Kokkos::layout_right_storage_policy>(),
513 foundation_fail_right ? "FAIL" : "PASS",
514 foundation_fail_right);
515 total_fail += foundation_fail_right;
516
517 const int mixed_fail_left = test_mixed_representation_ops<libMesh::Kokkos::layout_left_storage_policy>();
518 std::printf("[kokkos_linalg_mixed_representation_oracle] [%s] %s (%d failures)\n",
519 libMesh::Kokkos::storage_policy_name<libMesh::Kokkos::layout_left_storage_policy>(),
520 mixed_fail_left ? "FAIL" : "PASS",
521 mixed_fail_left);
522 total_fail += mixed_fail_left;
523
524 const int mixed_fail_right = test_mixed_representation_ops<libMesh::Kokkos::layout_right_storage_policy>();
525 std::printf("[kokkos_linalg_mixed_representation_oracle] [%s] %s (%d failures)\n",
526 libMesh::Kokkos::storage_policy_name<libMesh::Kokkos::layout_right_storage_policy>(),
527 mixed_fail_right ? "FAIL" : "PASS",
528 mixed_fail_right);
529 total_fail += mixed_fail_right;
530
531 return total_fail;
532}

References test_tensor_host_only_ops().

◆ test_dim_ops()

template<typename StoragePolicy >
static int libMeshTest::KokkosTensorOracle::test_dim_ops ( )
static

Definition at line 28 of file kokkos_tensor_ops_oracle_runners.h.

29{
30 const unsigned int ncases = sizeof(dim_cases) / sizeof(dim_cases[0]);
31
32 std::vector<oracle_tensor> J_values(ncases);
33 std::vector<unsigned int> dims(ncases);
34 std::vector<Real> ref_det(ncases);
35 std::vector<oracle_tensor> ref_inv(ncases);
36 std::vector<oracle_tensor> ref_I(ncases);
37 std::vector<oracle_tensor> ref_prod_left(ncases);
38 std::vector<oracle_tensor> ref_prod_right(ncases);
39
40 for (unsigned int c = 0; c < ncases; ++c)
41 {
42 const auto & info = dim_cases[c];
43 J_values[c] = info.J;
44 dims[c] = info.dim;
45
46 ref_det[c] = host_leading_determinant(info.J, info.dim);
47 ref_inv[c] = host_leading_inverse(info.J, info.dim);
48 ref_I[c] = build_identity_tensor(info.dim);
49 ref_prod_left[c] = info.J * ref_inv[c];
50 ref_prod_right[c] = ref_inv[c] * info.J;
51 }
52
53 auto d_J = libMesh::Kokkos::upload_tensor_storage<StoragePolicy>(J_values, "tensor_dim_ops_J");
54 auto d_dims = libMeshTest::KokkosOracle::upload_objects(dims, "tensor_dim_ops_dim");
55 ::Kokkos::View<double *> d_det("tensor_dim_ops_det", ncases);
56 auto d_inv = libMesh::Kokkos::make_tensor_storage<StoragePolicy>("tensor_dim_ops_inv", ncases);
57 auto d_I = libMesh::Kokkos::make_tensor_storage<StoragePolicy>("tensor_dim_ops_I", ncases);
58 auto d_prod_left = libMesh::Kokkos::make_tensor_storage<StoragePolicy>("tensor_dim_ops_prod_left", ncases);
59 auto d_prod_right = libMesh::Kokkos::make_tensor_storage<StoragePolicy>("tensor_dim_ops_prod_right", ncases);
60
61 ::Kokkos::parallel_for(
62 static_cast<int>(ncases),
63 KOKKOS_LAMBDA(int c) {
64 const auto J_ref = libMesh::Kokkos::make_tensor_ref(d_J, c);
65 const unsigned int dim = d_dims(c);
66 const Real det = J_ref.det(dim);
67 const auto inv = J_ref.inverse(dim);
68 const auto I = libMesh::Kokkos::tensor_identity<oracle_tensor>(dim);
69 const auto prod_left = J_ref * inv;
70 const auto prod_right = inv * J_ref;
71
72 d_det(c) = det;
73 libMesh::Kokkos::store_tensor(d_inv, c, inv);
75 libMesh::Kokkos::store_tensor(d_prod_left, c, prod_left);
76 libMesh::Kokkos::store_tensor(d_prod_right, c, prod_right);
77 });
78 ::Kokkos::fence();
79
80 return libMeshTest::KokkosOracle::compare_device_scalars(d_det, ref_det, tol) +
83 libMeshTest::KokkosOracle::compare_device_tensors(d_prod_left, ref_prod_left, tol) +
84 libMeshTest::KokkosOracle::compare_device_tensors(d_prod_right, ref_prod_right, tol);
85}
inline ::Kokkos::View< T * > upload_objects(const std::vector< T > &values, const char *label)
int compare_device_scalars(const ::Kokkos::View< double * > &d_values, const std::vector< Real > &ref_values, const double tol)
int compare_device_tensors(const ViewType &d_values, const std::vector< TensorType > &ref_values, const double tol)
oracle_tensor host_leading_inverse(const oracle_tensor &J, const unsigned int dim)
oracle_tensor build_identity_tensor(const unsigned int dim)
Real host_leading_determinant(const oracle_tensor &J, const unsigned int dim)
LIBMESH_DEVICE_INLINE tensor_ref< typename std::remove_reference< ViewType >::type > make_tensor_ref(ViewType &&view, const unsigned int index)
LIBMESH_DEVICE_INLINE void store_tensor(const ViewType &view, const unsigned int i, const TensorType &T)
Copies the components of the tensor T into entry i of the tensor view view, overwriting whatever that...

References build_identity_tensor(), libMeshTest::KokkosOracle::compare_device_scalars(), libMeshTest::KokkosOracle::compare_device_tensors(), dim, dim_cases, host_leading_determinant(), host_leading_inverse(), libMesh::Kokkos::make_tensor_ref(), libMesh::Kokkos::store_tensor(), tol, and libMeshTest::KokkosOracle::upload_objects().

◆ test_linalg_foundation_storage_roundtrip()

template<typename StoragePolicy >
static int libMeshTest::KokkosTensorOracle::test_linalg_foundation_storage_roundtrip ( )
static

Definition at line 264 of file kokkos_tensor_ops_oracle_runners.h.

265{
266 auto d_vector = libMesh::Kokkos::make_vector_storage<StoragePolicy>("foundation_vector", 1);
267 auto d_tensor = libMesh::Kokkos::make_tensor_storage<StoragePolicy>("foundation_tensor", 1);
268
269 {
270 auto h_vector = ::Kokkos::create_mirror_view(d_vector);
271 auto h_tensor = ::Kokkos::create_mirror_view(d_tensor);
272
273 for (unsigned int d = 0; d < LIBMESH_DIM; ++d)
274 h_vector(0, d) = Real(d + 1) * Real(0.5);
275
276 for (unsigned int row = 0; row < LIBMESH_DIM; ++row)
277 for (unsigned int col = 0; col < LIBMESH_DIM; ++col)
278 h_tensor(0, row, col) = Real(10 * row + col + 1) * Real(0.25);
279
280 ::Kokkos::deep_copy(d_vector, h_vector);
281 ::Kokkos::deep_copy(d_tensor, h_tensor);
282 }
283
284 auto d_vector_out = libMesh::Kokkos::make_vector_storage<StoragePolicy>("foundation_vector_out", 1);
285 auto d_tensor_out = libMesh::Kokkos::make_tensor_storage<StoragePolicy>("foundation_tensor_out", 1);
286 ::Kokkos::View<int> d_fail("foundation_fail");
287
288 ::Kokkos::parallel_for(
289 1,
290 KOKKOS_LAMBDA(int) {
291 int local_fail = 0;
292
293 const auto vector_in = libMesh::Kokkos::make_vector_ref(d_vector, 0);
294 const auto tensor_in = libMesh::Kokkos::make_tensor_ref(d_tensor, 0);
295
296 const auto as_point = libMesh::Kokkos::materialize_vector<libMesh::Point>(vector_in);
297 const auto as_vector_value =
298 libMesh::Kokkos::materialize_vector<libMesh::VectorValue<Real>>(vector_in);
299 const auto as_type_vector =
300 libMesh::Kokkos::materialize_vector<libMesh::TypeVector<Real>>(vector_in);
301
302 for (unsigned int d = 0; d < LIBMESH_DIM; ++d)
303 {
304 const Real expected = Real(d + 1) * Real(0.5);
305 local_fail += (std::fabs(as_point(d) - expected) <= tol) ? 0 : 1;
306 local_fail += (std::fabs(as_vector_value(d) - expected) <= tol) ? 0 : 1;
307 local_fail += (std::fabs(as_type_vector(d) - expected) <= tol) ? 0 : 1;
308 }
309
310 const auto as_tensor_value =
311 libMesh::Kokkos::materialize_tensor<libMesh::TensorValue<Real>>(tensor_in);
312 const auto as_type_tensor =
313 libMesh::Kokkos::materialize_tensor<libMesh::TypeTensor<Real>>(tensor_in);
314
315 for (unsigned int row = 0; row < LIBMESH_DIM; ++row)
316 for (unsigned int col = 0; col < LIBMESH_DIM; ++col)
317 {
318 const Real expected = Real(10 * row + col + 1) * Real(0.25);
319 local_fail += (std::fabs(as_tensor_value(row, col) - expected) <= tol) ? 0 : 1;
320 local_fail += (std::fabs(as_type_tensor(row, col) - expected) <= tol) ? 0 : 1;
321 }
322
323 auto vector_out = libMesh::Kokkos::make_vector_ref(d_vector_out, 0);
324 auto tensor_out = libMesh::Kokkos::make_tensor_ref(d_tensor_out, 0);
325
326 vector_out.zero();
327 vector_out.assign(as_vector_value);
328 vector_out.add_scaled(as_type_vector, Real(0));
329 vector_out.subtract_scaled(as_type_vector, Real(0));
330
331 tensor_out.zero();
332 tensor_out.assign(as_tensor_value);
333 tensor_out.add_scaled(as_type_tensor, Real(0));
334 tensor_out.subtract_scaled(as_type_tensor, Real(0));
335
336 d_fail() = local_fail;
337 });
338 ::Kokkos::fence();
339
340 int fail = 0;
341 ::Kokkos::deep_copy(fail, d_fail);
342
343 {
344 auto h_vector_out = ::Kokkos::create_mirror_view(d_vector_out);
345 auto h_tensor_out = ::Kokkos::create_mirror_view(d_tensor_out);
346 ::Kokkos::deep_copy(h_vector_out, d_vector_out);
347 ::Kokkos::deep_copy(h_tensor_out, d_tensor_out);
348
349 for (unsigned int d = 0; d < LIBMESH_DIM; ++d)
350 {
351 const Real expected = Real(d + 1) * Real(0.5);
352 fail += (std::fabs(h_vector_out(0, d) - expected) <= tol) ? 0 : 1;
353 }
354
355 for (unsigned int row = 0; row < LIBMESH_DIM; ++row)
356 for (unsigned int col = 0; col < LIBMESH_DIM; ++col)
357 {
358 const Real expected = Real(10 * row + col + 1) * Real(0.25);
359 fail += (std::fabs(h_tensor_out(0, row, col) - expected) <= tol) ? 0 : 1;
360 }
361 }
362
363 return fail;
364}
LIBMESH_DEVICE_INLINE ResultVector row(const TensorLike &T_in, const unsigned int row_index)
LIBMESH_DEVICE_INLINE vector_ref< typename std::remove_reference< ViewType >::type > make_vector_ref(ViewType &&view, const unsigned int index)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::Kokkos::make_tensor_ref(), libMesh::Kokkos::make_vector_ref(), and tol.

◆ test_mixed_representation_ops()

template<typename StoragePolicy >
static int libMeshTest::KokkosTensorOracle::test_mixed_representation_ops ( )
static

Definition at line 373 of file kokkos_tensor_ops_oracle_runners.h.

374{
375 int fail = 0;
376
377 const auto a = make_host_vector(2.0, 3.0, 4.0);
378 const auto b = make_host_vector(5.0, -6.0, 7.0);
379 const auto c = make_host_vector(1.25, -0.5, 2.0);
380 const auto A = make_host_tensor(1.1, -0.4, 0.7,
381 0.3, 1.9, -1.2,
382 -0.8, 0.5, 2.2);
383
384 auto d_a = libMesh::Kokkos::upload_vector_storage<StoragePolicy>(std::vector<oracle_vector>{a}, "mixed_ops_a");
385 auto d_A = libMesh::Kokkos::upload_tensor_storage<StoragePolicy>(std::vector<oracle_tensor>{A}, "mixed_ops_A");
386
387 ::Kokkos::View<double *> d_scalars("mixed_ops_scalars", 8);
388 auto d_vectors = libMesh::Kokkos::make_vector_storage<StoragePolicy>("mixed_ops_vectors", 5);
389 auto d_tensors = libMesh::Kokkos::make_tensor_storage<StoragePolicy>("mixed_ops_tensors", 4);
390
391 const auto ref_dot = a * b;
392 const auto ref_contract = A.contract(libMesh::outer_product(a, b));
393 const auto ref_det = host_leading_determinant(A, LIBMESH_DIM);
394 const auto ref_right = A * c;
395 const auto ref_left = A.left_multiply(c);
396 const auto ref_mix = a + b;
397 const auto ref_row0 = A.row(0);
398 const auto ref_col0 = A.column(0);
399 const auto ref_transpose = A.transpose();
400 const auto ref_inverse = host_leading_inverse(A, LIBMESH_DIM);
401 const auto ref_add = A + ref_transpose;
402 const auto ref_scaled = 0.5 * A;
403 const auto ref_trace = A.tr();
404
405 ::Kokkos::parallel_for(
406 1,
407 KOKKOS_LAMBDA(int) {
408 const auto a_ref = libMesh::Kokkos::make_vector_ref(d_a, 0);
409 const auto A_ref = libMesh::Kokkos::make_tensor_ref(d_A, 0);
410
411 const auto mix = a_ref + b;
412 const auto right = A_ref * c;
413 const auto left = A_ref.left_multiply(c);
414 const auto row0 = A_ref.row(0);
415 const auto col0 = A_ref.column(0);
416 const auto transpose = A_ref.transpose();
417 const auto inverse = A_ref.inverse();
418 const auto add = A_ref + ref_transpose;
419 const auto scaled = Real(0.5) * A_ref;
420 const auto outer = libMesh::Kokkos::outer_product<oracle_tensor>(a_ref, b);
421
422 d_scalars(0) = a_ref * b;
423 d_scalars(1) = A_ref.contract(outer);
424 d_scalars(2) = A_ref.det();
425 d_scalars(3) = (A_ref == A) ? 1.0 : 0.0;
426 d_scalars(4) = (A_ref != inverse) ? 1.0 : 0.0;
427 d_scalars(5) = (row0 == ref_row0) ? 1.0 : 0.0;
428 d_scalars(6) = (col0 == ref_col0) ? 1.0 : 0.0;
429 d_scalars(7) = A_ref.tr();
430
431 libMesh::Kokkos::store_vector(d_vectors, 0, right);
432 libMesh::Kokkos::store_vector(d_vectors, 1, left);
433 libMesh::Kokkos::store_vector(d_vectors, 2, mix);
434 libMesh::Kokkos::store_vector(d_vectors, 3, row0);
435 libMesh::Kokkos::store_vector(d_vectors, 4, col0);
436 libMesh::Kokkos::store_tensor(d_tensors, 0, transpose);
437 libMesh::Kokkos::store_tensor(d_tensors, 1, inverse);
438 libMesh::Kokkos::store_tensor(d_tensors, 2, add);
439 libMesh::Kokkos::store_tensor(d_tensors, 3, scaled);
440 });
441 ::Kokkos::fence();
442
444 d_scalars,
445 std::vector<Real>{ref_dot, ref_contract, ref_det, 1.0, 1.0, 1.0, 1.0, ref_trace},
446 tol);
448 d_vectors,
449 std::vector<oracle_vector>{ref_right, ref_left, ref_mix, ref_row0, ref_col0},
450 tol);
452 d_tensors,
453 std::vector<oracle_tensor>{ref_transpose, ref_inverse, ref_add, ref_scaled},
454 tol);
455
456 return fail;
457}
static const Real b
int compare_device_vectors(const ViewType &d_values, const std::vector< VectorType > &ref_values, const double tol)
oracle_vector make_host_vector(const Real x, const Real y=0, const Real z=0)
oracle_tensor make_host_tensor(const Real xx, const Real xy=0, const Real xz=0, const Real yx=0, const Real yy=0, const Real yz=0, const Real zx=0, const Real zy=0, const Real zz=0)
LIBMESH_DEVICE_INLINE void store_vector(const ViewType &view, const unsigned int i, const VectorType &v)
Copies the components of the vector v into entry i of the vector view view, overwriting whatever that...
LIBMESH_DEVICE_INLINE TypeTensor< typename CompareTypes< T, T2 >::supertype > outer_product(const TypeVector< T > &a, const TypeVector< T2 > &b)

References b, libMeshTest::KokkosOracle::compare_device_scalars(), libMeshTest::KokkosOracle::compare_device_tensors(), libMeshTest::KokkosOracle::compare_device_vectors(), host_leading_determinant(), host_leading_inverse(), make_host_tensor(), make_host_vector(), libMesh::Kokkos::make_tensor_ref(), libMesh::Kokkos::make_vector_ref(), libMesh::outer_product(), libMesh::Kokkos::store_tensor(), libMesh::Kokkos::store_vector(), and tol.

◆ test_tensor_host_only_ops()

int libMeshTest::KokkosTensorOracle::test_tensor_host_only_ops ( )
inline

Definition at line 191 of file kokkos_tensor_ops_oracle_runners.h.

192{
193 int fail = 0;
194
195#if LIBMESH_DIM > 2
196 {
197 libMesh::TensorValue<double> tensor(2., 1., 0.,
198 1., 2., 1.,
199 0., 1., 2.);
200 fail += tensor.is_hpd(/*rel_tol=*/0.) ? 0 : 1;
201 }
202
203 {
204 libMesh::TensorValue<double> tensor(1., 0., 0.,
205 0., 0., 1.,
206 0., 1., 0.);
207 fail += tensor.is_hpd() ? 1 : 0;
208 }
209
210 {
211 const libMesh::Point x(1., 0., 0.);
212 const auto R = libMesh::RealTensorValue::extrinsic_rotation_matrix(90., 0., 0.);
213 const auto rotated = R * x;
214 fail += (std::fabs(rotated(0)) <= tol) ? 0 : 1;
215 fail += (std::fabs(rotated(1) - 1.) <= tol) ? 0 : 1;
216 fail += (std::fabs(rotated(2)) <= tol) ? 0 : 1;
217
219 const auto unrotated = invR * rotated;
220 fail += (std::fabs(unrotated(0) - 1.) <= tol) ? 0 : 1;
221 fail += (std::fabs(unrotated(1)) <= tol) ? 0 : 1;
222 fail += (std::fabs(unrotated(2)) <= tol) ? 0 : 1;
223 }
224
225 {
226 const libMesh::Point x(1., 1., 1.);
227 const auto R = libMesh::RealTensorValue::extrinsic_rotation_matrix(90., 90., 90.);
228 const auto rotated = R * x;
229 fail += (std::fabs(rotated(0) - 1.) <= tol) ? 0 : 1;
230 fail += (std::fabs(rotated(1) + 1.) <= tol) ? 0 : 1;
231 fail += (std::fabs(rotated(2) - 1.) <= tol) ? 0 : 1;
232
234 const auto unrotated = invR * rotated;
235 fail += (std::fabs(unrotated(0) - 1.) <= tol) ? 0 : 1;
236 fail += (std::fabs(unrotated(1) - 1.) <= tol) ? 0 : 1;
237 fail += (std::fabs(unrotated(2) - 1.) <= tol) ? 0 : 1;
238 }
239#endif
240
241#ifdef LIBMESH_HAVE_METAPHYSICL
242 typedef typename MetaPhysicL::ReplaceAlgebraicType<
243 std::vector<libMesh::TypeTensor<double>>,
245 typename MetaPhysicL::ValueType<std::vector<libMesh::TypeTensor<double>>>::type>::type>::type
246 ReplacedType;
247 constexpr bool assertion =
248 std::is_same<ReplacedType, std::vector<libMesh::TypeNTensor<3, double>>>::value;
249 fail += assertion ? 0 : 1;
250#endif
251
252 return fail;
253}
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:41
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
static TensorValue< Real > extrinsic_rotation_matrix(Real angle1_deg, Real angle2_deg, Real angle3_deg)
Generate the extrinsic rotation matrix associated with the provided Euler angles.
static TensorValue< Real > inverse_extrinsic_rotation_matrix(Real angle1_deg, Real angle2_deg, Real angle3_deg)
Invert the rotation that would occur if the same angles were provided to extrinsic_rotation_matrix,...
static const bool value
Definition xdr_io.C:55

References libMesh::TensorValue< T >::extrinsic_rotation_matrix(), libMesh::TensorValue< T >::inverse_extrinsic_rotation_matrix(), libMesh::TypeTensor< T >::is_hpd(), tol, and value.

Referenced by run_all_oracles().

◆ test_tensor_ops()

template<typename StoragePolicy >
static int libMeshTest::KokkosTensorOracle::test_tensor_ops ( )
static

Definition at line 94 of file kokkos_tensor_ops_oracle_runners.h.

95{
96 const auto A = make_host_tensor(1.1, -0.4, 0.7,
97 0.3, 1.9, -1.2,
98 -0.8, 0.5, 2.2);
99 const auto a = make_host_vector(2.0, 3.0, 4.0);
100 const auto b = make_host_vector(5.0, -6.0, 7.0);
101 const auto c = make_host_vector(1.25, -0.5, 2.0);
102
103 const auto outer = libMesh::outer_product(a, b);
104 const auto transpose = A.transpose();
105 const auto mix = 1.5 * A - 0.25 * outer;
106 const auto right = A * c;
107 const auto left = c * A;
108 const Real contract = A.contract(outer);
109 const Real norm = A.norm();
110 const oracle_tensor zero; // Via default initialization
111
112 std::vector<oracle_tensor> ref_outer(1, outer);
113 std::vector<oracle_tensor> ref_transpose(1, transpose);
114 std::vector<oracle_tensor> ref_mix(1, mix);
115 std::vector<oracle_vector> ref_rows(LIBMESH_DIM);
116 std::vector<oracle_vector> ref_columns(LIBMESH_DIM);
117 for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
118 {
119 ref_rows[i] = A.row(i);
120 ref_columns[i] = A.column(i);
121 }
122 std::vector<oracle_vector> ref_right(1, right);
123 std::vector<oracle_vector> ref_left(1, left);
124 std::vector<Real> ref_scalars = {contract, norm, zero.is_zero() ? 1.0 : 0.0, A.is_zero() ? 1.0 : 0.0};
125
126 auto d_A = libMesh::Kokkos::upload_tensor_storage<StoragePolicy>(std::vector<oracle_tensor>{A}, "tensor_ops_A");
127 auto d_a = libMesh::Kokkos::upload_vector_storage<StoragePolicy>(std::vector<oracle_vector>{a}, "tensor_ops_a");
128 auto d_b = libMesh::Kokkos::upload_vector_storage<StoragePolicy>(std::vector<oracle_vector>{b}, "tensor_ops_b");
129 auto d_c = libMesh::Kokkos::upload_vector_storage<StoragePolicy>(std::vector<oracle_vector>{c}, "tensor_ops_c");
130 auto d_outer = libMesh::Kokkos::make_tensor_storage<StoragePolicy>("tensor_ops_outer", 1);
131 auto d_transpose = libMesh::Kokkos::make_tensor_storage<StoragePolicy>("tensor_ops_transpose", 1);
132 auto d_mix = libMesh::Kokkos::make_tensor_storage<StoragePolicy>("tensor_ops_mix", 1);
133 auto d_rows = libMesh::Kokkos::make_vector_storage<StoragePolicy>("tensor_ops_rows", LIBMESH_DIM);
134 auto d_columns = libMesh::Kokkos::make_vector_storage<StoragePolicy>("tensor_ops_columns", LIBMESH_DIM);
135 auto d_right = libMesh::Kokkos::make_vector_storage<StoragePolicy>("tensor_ops_right", 1);
136 auto d_left = libMesh::Kokkos::make_vector_storage<StoragePolicy>("tensor_ops_left", 1);
137 ::Kokkos::View<double *> d_scalars("tensor_ops_scalars", 4);
138
139 ::Kokkos::parallel_for(
140 1,
141 KOKKOS_LAMBDA(int) {
142 const auto A_ref = libMesh::Kokkos::make_tensor_ref(d_A, 0);
143 const auto a_ref = libMesh::Kokkos::make_vector_ref(d_a, 0);
144 const auto b_ref = libMesh::Kokkos::make_vector_ref(d_b, 0);
145 const auto c_ref = libMesh::Kokkos::make_vector_ref(d_c, 0);
146 const auto outer_d = libMesh::Kokkos::outer_product<oracle_tensor>(a_ref, b_ref);
147 const auto transpose_d = A_ref.transpose();
148 const auto mix_d = Real(1.5) * A_ref - Real(0.25) * outer_d;
149 const auto right_d = A_ref * c_ref;
150 const auto left_d = c_ref * A_ref;
151 const Real contract_d = A_ref.contract(outer_d);
152 const Real norm_d = A_ref.norm();
153 oracle_tensor default_tensor; // We don't default to uninitialized!
154 const bool zero_is_zero_d = default_tensor.is_zero();
155 const bool A_is_zero_d = A_ref.is_zero();
156
157 for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
158 {
159 libMesh::Kokkos::store_vector(d_rows, i, A_ref.row(i));
160 libMesh::Kokkos::store_vector(d_columns, i, A_ref.column(i));
161 }
162
163 libMesh::Kokkos::store_tensor(d_outer, 0, outer_d);
164 libMesh::Kokkos::store_tensor(d_transpose, 0, transpose_d);
165 libMesh::Kokkos::store_tensor(d_mix, 0, mix_d);
166 libMesh::Kokkos::store_vector(d_right, 0, right_d);
167 libMesh::Kokkos::store_vector(d_left, 0, left_d);
168 d_scalars(0) = contract_d;
169 d_scalars(1) = norm_d;
170 d_scalars(2) = zero_is_zero_d ? 1.0 : 0.0;
171 d_scalars(3) = A_is_zero_d ? 1.0 : 0.0;
172 });
173 ::Kokkos::fence();
174
175 return libMeshTest::KokkosOracle::compare_device_tensors(d_outer, ref_outer, tol) +
176 libMeshTest::KokkosOracle::compare_device_tensors(d_transpose, ref_transpose, tol) +
179 libMeshTest::KokkosOracle::compare_device_vectors(d_columns, ref_columns, tol) +
182 libMeshTest::KokkosOracle::compare_device_scalars(d_scalars, ref_scalars, tol);
183}
LIBMESH_DEVICE_INLINE bool is_zero() const

References b, libMeshTest::KokkosOracle::compare_device_scalars(), libMeshTest::KokkosOracle::compare_device_tensors(), libMeshTest::KokkosOracle::compare_device_vectors(), libMesh::TypeTensor< T >::is_zero(), make_host_tensor(), make_host_vector(), libMesh::Kokkos::make_tensor_ref(), libMesh::Kokkos::make_vector_ref(), libMesh::outer_product(), libMesh::Kokkos::store_tensor(), libMesh::Kokkos::store_vector(), and tol.

Variable Documentation

◆ dim_cases

const tensor_dim_case libMeshTest::KokkosTensorOracle::dim_cases[]
static
Initial value:
= {
{ make_host_tensor(1.7, -0.2, 0.5,
0.3, 1.1, -0.4,
-0.6, 0.8, 0.9),
1,
"leading_1d" },
#if LIBMESH_DIM > 1
{ make_host_tensor(2.5, -0.75, 0.4,
1.2, 1.8, -0.6,
-0.3, 0.9, 1.4),
2,
"leading_2d" },
#endif
#if LIBMESH_DIM > 2
{ make_host_tensor(9.08973348886179e-01, 3.36455579239923e-01, 5.16389236893863e-01,
9.44156071777472e-01, 1.35610910092516e-01, 1.49881119060538e-02,
1.15988384086146e-01, 6.79845197685518e-03, 3.77028969454745e-01),
3,
"leading_3d" }
#endif
}

Definition at line 96 of file kokkos_tensor_ops_oracle_fixtures.h.

96 {
97 { make_host_tensor(1.7, -0.2, 0.5,
98 0.3, 1.1, -0.4,
99 -0.6, 0.8, 0.9),
100 1,
101 "leading_1d" },
102#if LIBMESH_DIM > 1
103 { make_host_tensor(2.5, -0.75, 0.4,
104 1.2, 1.8, -0.6,
105 -0.3, 0.9, 1.4),
106 2,
107 "leading_2d" },
108#endif
109#if LIBMESH_DIM > 2
110 { make_host_tensor(9.08973348886179e-01, 3.36455579239923e-01, 5.16389236893863e-01,
111 9.44156071777472e-01, 1.35610910092516e-01, 1.49881119060538e-02,
112 1.15988384086146e-01, 6.79845197685518e-03, 3.77028969454745e-01),
113 3,
114 "leading_3d" }
115#endif
116};

Referenced by test_dim_ops().

◆ tol

constexpr double libMeshTest::KokkosTensorOracle::tol = 2.0e-13
staticconstexpr