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