| 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_ROCM_TPL_HPP_ |
| 17 |
#define KOKKOSBLAS_ROCM_TPL_HPP_ |
| 18 |
|
| 19 |
#if defined(KOKKOSKERNELS_ENABLE_TPL_ROCBLAS) |
| 20 |
#include <KokkosBlas_tpl_spec.hpp> |
| 21 |
|
| 22 |
namespace KokkosBlas { |
| 23 |
namespace Impl { |
| 24 |
|
| 25 |
RocBlasSingleton::RocBlasSingleton() { KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_create_handle(&handle)); } |
| 26 |
|
| 27 |
RocBlasSingleton& RocBlasSingleton::singleton() { |
| 28 |
std::unique_ptr<RocBlasSingleton>& instance = get_instance(); |
| 29 |
if (!instance) { |
| 30 |
instance = std::make_unique<RocBlasSingleton>(); |
| 31 |
Kokkos::push_finalize_hook([&]() { |
| 32 |
KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_destroy_handle(instance->handle)); |
| 33 |
instance.reset(); |
| 34 |
}); |
| 35 |
} |
| 36 |
return *instance; |
| 37 |
} |
| 38 |
|
| 39 |
bool RocBlasSingleton::is_initialized() { return get_instance() != nullptr; } |
| 40 |
|
| 41 |
std::unique_ptr<RocBlasSingleton>& RocBlasSingleton::get_instance() { |
| 42 |
static std::unique_ptr<RocBlasSingleton> s; |
| 43 |
return s; |
| 44 |
} |
| 45 |
|
| 46 |
} // namespace Impl |
| 47 |
} // namespace KokkosBlas |
| 48 |
#endif // defined (KOKKOSKERNELS_ENABLE_TPL_ROCBLAS) |
| 49 |
|
| 50 |
#endif // KOKKOSBLAS_ROCM_TPL_HPP_ |