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);
40 for (
unsigned int c = 0; c < ncases; ++c)
49 ref_prod_left[c] = info.J * ref_inv[c];
50 ref_prod_right[c] = ref_inv[c] * info.J;
53 auto d_J = libMesh::Kokkos::upload_tensor_storage<StoragePolicy>(J_values,
"tensor_dim_ops_J");
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);
61 ::Kokkos::parallel_for(
62 static_cast<int>(ncases),
63 KOKKOS_LAMBDA(
int 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;
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();
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)
119 ref_rows[i] = A.row(i);
120 ref_columns[i] = A.column(i);
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};
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);
139 ::Kokkos::parallel_for(
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();
154 const bool zero_is_zero_d = default_tensor.
is_zero();
155 const bool A_is_zero_d = A_ref.is_zero();
157 for (
unsigned int i = 0; i < LIBMESH_DIM; ++i)
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;
200 fail += tensor.
is_hpd(0.) ? 0 : 1;
207 fail += tensor.
is_hpd() ? 1 : 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;
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;
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;
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;
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
247 constexpr bool assertion =
248 std::is_same<ReplacedType, std::vector<libMesh::TypeNTensor<3, double>>>
::value;
249 fail += assertion ? 0 : 1;
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);
270 auto h_vector = ::Kokkos::create_mirror_view(d_vector);
271 auto h_tensor = ::Kokkos::create_mirror_view(d_tensor);
273 for (
unsigned int d = 0; d < LIBMESH_DIM; ++d)
274 h_vector(0, d) = Real(d + 1) * Real(0.5);
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);
280 ::Kokkos::deep_copy(d_vector, h_vector);
281 ::Kokkos::deep_copy(d_tensor, h_tensor);
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");
288 ::Kokkos::parallel_for(
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);
302 for (
unsigned int d = 0; d < LIBMESH_DIM; ++d)
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;
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);
315 for (
unsigned int row = 0; row < LIBMESH_DIM; ++row)
316 for (
unsigned int col = 0; col < LIBMESH_DIM; ++col)
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;
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));
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));
336 d_fail() = local_fail;
341 ::Kokkos::deep_copy(fail, d_fail);
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);
349 for (
unsigned int d = 0; d < LIBMESH_DIM; ++d)
351 const Real expected = Real(d + 1) * Real(0.5);
352 fail += (std::fabs(h_vector_out(0, d) - expected) <=
tol) ? 0 : 1;
355 for (
unsigned int row = 0; row < LIBMESH_DIM; ++row)
356 for (
unsigned int col = 0; col < LIBMESH_DIM; ++col)
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;
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");
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);
391 const auto ref_dot = a *
b;
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();
401 const auto ref_add = A + ref_transpose;
402 const auto ref_scaled = 0.5 * A;
403 const auto ref_trace = A.tr();
405 ::Kokkos::parallel_for(
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);
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();
445 std::vector<Real>{ref_dot, ref_contract, ref_det, 1.0, 1.0, 1.0, 1.0, ref_trace},
449 std::vector<oracle_vector>{ref_right, ref_left, ref_mix, ref_row0, ref_col0},
453 std::vector<oracle_tensor>{ref_transpose, ref_inverse, ref_add, ref_scaled},
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",
472 total_fail += dim_fail_left;
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",
479 total_fail += dim_fail_right;
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",
486 total_fail += tensor_fail_left;
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",
493 total_fail += tensor_fail_right;
496 std::printf(
"[tensor_host_ops_oracle] %s (%d failures)\n",
497 host_fail ?
"FAIL" :
"PASS",
499 total_fail += host_fail;
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;
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;
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",
522 total_fail += mixed_fail_left;
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",
529 total_fail += mixed_fail_right;