| 1 |
//@HEADER |
| 2 |
// ************************************************************************ |
| 3 |
// |
| 4 |
// Kokkos v. 4.0 |
| 5 |
// Copyright (2022) National Technology & Engineering |
| 6 |
// Solutions of Sandia, LLC (NTESS). |
| 7 |
// |
| 8 |
// Under the terms of Contract DE-NA0003525 with NTESS, |
| 9 |
// the U.S. Government retains certain rights in this software. |
| 10 |
// |
| 11 |
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. |
| 12 |
// See https://kokkos.org/LICENSE for license information. |
| 13 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 14 |
// |
| 15 |
//@HEADER |
| 16 |
#ifndef KOKKOSLAPACK_MAGMA_TPL_HPP_ |
| 17 |
#define KOKKOSLAPACK_MAGMA_TPL_HPP_ |
| 18 |
|
| 19 |
#if defined(KOKKOSKERNELS_ENABLE_TPL_MAGMA) |
| 20 |
#include <KokkosLapack_magma.hpp> |
| 21 |
|
| 22 |
namespace KokkosLapack { |
| 23 |
namespace Impl { |
| 24 |
|
| 25 |
MagmaSingleton::MagmaSingleton() { |
| 26 |
magma_int_t stat = magma_init(); |
| 27 |
if (stat != MAGMA_SUCCESS) Kokkos::abort("MAGMA initialization failed\n"); |
| 28 |
} |
| 29 |
|
| 30 |
MagmaSingleton& MagmaSingleton::singleton() { |
| 31 |
std::unique_ptr<MagmaSingleton>& instance = get_instance(); |
| 32 |
if (!instance) { |
| 33 |
instance = std::make_unique<MagmaSingleton>(); |
| 34 |
Kokkos::push_finalize_hook([&]() { |
| 35 |
magma_finalize(); |
| 36 |
instance.reset(); |
| 37 |
}); |
| 38 |
} |
| 39 |
return *instance; |
| 40 |
} |
| 41 |
|
| 42 |
bool MagmaSingleton::is_initialized() { return get_instance() != nullptr; } |
| 43 |
|
| 44 |
std::unique_ptr<MagmaSingleton>& MagmaSingleton::get_instance() { |
| 45 |
static std::unique_ptr<MagmaSingleton> s; |
| 46 |
return s; |
| 47 |
} |
| 48 |
|
| 49 |
} // namespace Impl |
| 50 |
} // namespace KokkosLapack |
| 51 |
#endif // defined(KOKKOSKERNELS_ENABLE_TPL_MAGMA) |
| 52 |
|
| 53 |
#endif // KOKKOSLAPACK_MAGMA_TPL_HPP_ |