From aee0ed8ee9f1d212a17108c65fdf9bfac94a4a1b Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Sun, 1 Jun 2025 22:35:41 -0400 Subject: [PATCH] Kokkos: test Tensor on device --- tests/matrix_free_kokkos/tensor_01.cc | 67 +++++++++++++++++++++++ tests/matrix_free_kokkos/tensor_01.output | 1 + 2 files changed, 68 insertions(+) create mode 100644 tests/matrix_free_kokkos/tensor_01.cc create mode 100644 tests/matrix_free_kokkos/tensor_01.output diff --git a/tests/matrix_free_kokkos/tensor_01.cc b/tests/matrix_free_kokkos/tensor_01.cc new file mode 100644 index 0000000000..c527f39582 --- /dev/null +++ b/tests/matrix_free_kokkos/tensor_01.cc @@ -0,0 +1,67 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2019 - 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +// check that Tensor works on device + +#include + +#include "deal.II/base/symmetric_tensor.h" +#include + +#include + +#include "../tests.h" + +DEAL_II_HOST_DEVICE +void +test_tensor() +{ + constexpr const int dim = 2; + + Tensor<2, dim> t1; + Tensor<2, dim> t2; + t1 = 0; + t2[0][1] = 1.0; + t1 += t2; + t1 *= 2.0; + Assert(t1.norm() == 2.0, ExcInternalError()); +} + +class Functor +{ +public: + DEAL_II_HOST_DEVICE void + operator()(const long n) const + { + test_tensor(); + } +}; + + + +int +main() +{ + initlog(); + + Kokkos::initialize(); + + Functor f; + Kokkos::parallel_for("test", 1, f); + + Kokkos::finalize(); + + return 0; +} diff --git a/tests/matrix_free_kokkos/tensor_01.output b/tests/matrix_free_kokkos/tensor_01.output new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/tests/matrix_free_kokkos/tensor_01.output @@ -0,0 +1 @@ + -- 2.39.5