Debian Codegraph @

packages/kokkos-kernels/lapack/tpls/KokkosLapack_Cuda_tpl.hpp

raw
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_CUDA_TPL_HPP_
17 #define KOKKOSLAPACK_CUDA_TPL_HPP_
18
19 #if defined(KOKKOSKERNELS_ENABLE_TPL_CUSOLVER)
20 #include "KokkosLapack_cusolver.hpp"
21
22 namespace KokkosLapack {
23 namespace Impl {
24
25 CudaLapackSingleton::CudaLapackSingleton() {
26 cusolverStatus_t stat = cusolverDnCreate(&handle);
27 if (stat != CUSOLVER_STATUS_SUCCESS) Kokkos::abort("CUSOLVER initialization failed\n");
28 }
29
30 CudaLapackSingleton& CudaLapackSingleton::singleton() {
31 std::unique_ptr<CudaLapackSingleton>& instance = get_instance();
32 if (!instance) {
33 instance = std::make_unique<CudaLapackSingleton>();
34 Kokkos::push_finalize_hook([&]() {
35 cusolverDnDestroy(instance->handle);
36 instance.reset();
37 });
38 }
39 return *instance;
40 }
41
42 bool CudaLapackSingleton::is_initialized() { return get_instance() != nullptr; }
43
44 std::unique_ptr<CudaLapackSingleton>& CudaLapackSingleton::get_instance() {
45 static std::unique_ptr<CudaLapackSingleton> s;
46 return s;
47 }
48
49 } // namespace Impl
50 } // namespace KokkosLapack
51 #endif // defined (KOKKOSKERNELS_ENABLE_TPL_CUSOLVER)
52
53 #endif // KOKKOSLAPACK_CUDA_TPL_HPP_