Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kokkos-kernels: fix singleton multiple definitions #12938

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
#include <Kokkos_Core.hpp>
#include <KokkosKernels_config.h>
#include <KokkosBlas_Cuda_tpl.hpp>
#include <KokkosBlas_Magma_tpl.hpp>
22 changes: 0 additions & 22 deletions packages/kokkos-kernels/blas/tpls/KokkosBlas_Cuda_tpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,4 @@ CudaBlasSingleton& CudaBlasSingleton::singleton() {
} // namespace KokkosBlas
#endif // defined (KOKKOSKERNELS_ENABLE_TPL_CUBLAS)

#if defined(KOKKOSKERNELS_ENABLE_TPL_MAGMA)
#include <KokkosBlas_tpl_spec.hpp>

namespace KokkosBlas {
namespace Impl {

MagmaSingleton::MagmaSingleton() {
magma_int_t stat = magma_init();
if (stat != MAGMA_SUCCESS) Kokkos::abort("MAGMA initialization failed\n");

Kokkos::push_finalize_hook([&]() { magma_finalize(); });
}

MagmaSingleton& MagmaSingleton::singleton() {
static MagmaSingleton s;
return s;
}

} // namespace Impl
} // namespace KokkosBlas
#endif // defined(KOKKOSKERNELS_ENABLE_TPL_MAGMA)

#endif // KOKKOSBLAS_CUDA_TPL_HPP_
41 changes: 41 additions & 0 deletions packages/kokkos-kernels/blas/tpls/KokkosBlas_Magma_tpl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
#ifndef KOKKOSBLAS_MAGMA_TPL_HPP_
#define KOKKOSBLAS_MAGMA_TPL_HPP_

#if defined(KOKKOSKERNELS_ENABLE_TPL_MAGMA)
#include <KokkosBlas_magma.hpp>

namespace KokkosBlas {
namespace Impl {

MagmaSingleton::MagmaSingleton() {
magma_int_t stat = magma_init();
if (stat != MAGMA_SUCCESS) Kokkos::abort("MAGMA initialization failed\n");

Kokkos::push_finalize_hook([&]() { magma_finalize(); });
}

MagmaSingleton& MagmaSingleton::singleton() {
static MagmaSingleton s;
return s;
}

} // namespace Impl
} // namespace KokkosBlas
#endif // defined(KOKKOSKERNELS_ENABLE_TPL_MAGMA)

#endif // KOKKOSBLAS_MAGMA_TPL_HPP_
37 changes: 37 additions & 0 deletions packages/kokkos-kernels/blas/tpls/KokkosBlas_magma.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER

#ifndef KOKKOSBLAS_MAGMA_HPP_
#define KOKKOSBLAS_MAGMA_HPP_

// If LAPACK TPL is enabled, it is preferred over magma's LAPACK
#ifdef KOKKOSKERNELS_ENABLE_TPL_MAGMA
#include "magma_v2.h"

namespace KokkosBlas {
namespace Impl {

struct MagmaSingleton {
MagmaSingleton();

static MagmaSingleton& singleton();
};

} // namespace Impl
} // namespace KokkosBlas
#endif // KOKKOSKERNELS_ENABLE_TPL_MAGMA

#endif // KOKKOSBLAS_MAGMA_HPP_
17 changes: 0 additions & 17 deletions packages/kokkos-kernels/blas/tpls/KokkosBlas_tpl_spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,4 @@ inline rocblas_operation trans_mode_kk_to_rocblas(const char kkMode[]) {

#endif // KOKKOSKERNELS_ENABLE_TPL_ROCBLAS

// If LAPACK TPL is enabled, it is preferred over magma's LAPACK
#ifdef KOKKOSKERNELS_ENABLE_TPL_MAGMA
#include "magma_v2.h"

namespace KokkosBlas {
namespace Impl {

struct MagmaSingleton {
MagmaSingleton();

static MagmaSingleton& singleton();
};

} // namespace Impl
} // namespace KokkosBlas
#endif // KOKKOSKERNELS_ENABLE_TPL_MAGMA

#endif // KOKKOSBLAS_TPL_SPEC_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
#include <Kokkos_Core.hpp>
#include <KokkosKernels_config.h>
#include <KokkosLapack_Cuda_tpl.hpp>
#include <KokkosLapack_Magma_tpl.hpp>
22 changes: 0 additions & 22 deletions packages/kokkos-kernels/lapack/tpls/KokkosLapack_Cuda_tpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,4 @@ CudaLapackSingleton& CudaLapackSingleton::singleton() {
} // namespace KokkosLapack
#endif // defined (KOKKOSKERNELS_ENABLE_TPL_CUSOLVER)

#if defined(KOKKOSKERNELS_ENABLE_TPL_MAGMA)
#include <KokkosLapack_magma.hpp>

namespace KokkosLapack {
namespace Impl {

MagmaSingleton::MagmaSingleton() {
magma_int_t stat = magma_init();
if (stat != MAGMA_SUCCESS) Kokkos::abort("MAGMA initialization failed\n");

Kokkos::push_finalize_hook([&]() { magma_finalize(); });
}

MagmaSingleton& MagmaSingleton::singleton() {
static MagmaSingleton s;
return s;
}

} // namespace Impl
} // namespace KokkosLapack
#endif // defined(KOKKOSKERNELS_ENABLE_TPL_MAGMA)

#endif // KOKKOSLAPACK_CUDA_TPL_HPP_
41 changes: 41 additions & 0 deletions packages/kokkos-kernels/lapack/tpls/KokkosLapack_Magma_tpl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
#ifndef KOKKOSLAPACK_MAGMA_TPL_HPP_
#define KOKKOSLAPACK_MAGMA_TPL_HPP_

#if defined(KOKKOSKERNELS_ENABLE_TPL_MAGMA)
#include <KokkosLapack_magma.hpp>

namespace KokkosLapack {
namespace Impl {

MagmaSingleton::MagmaSingleton() {
magma_int_t stat = magma_init();
if (stat != MAGMA_SUCCESS) Kokkos::abort("MAGMA initialization failed\n");

Kokkos::push_finalize_hook([&]() { magma_finalize(); });
}

MagmaSingleton& MagmaSingleton::singleton() {
static MagmaSingleton s;
return s;
}

} // namespace Impl
} // namespace KokkosLapack
#endif // defined(KOKKOSKERNELS_ENABLE_TPL_MAGMA)

#endif // KOKKOSLAPACK_MAGMA_TPL_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ KOKKOSLAPACK_GESV_LAPACK(Kokkos::complex<double>, Kokkos::LayoutLeft,

// MAGMA
#ifdef KOKKOSKERNELS_ENABLE_TPL_MAGMA
#include <KokkosLapack_Cuda_tpl.hpp>
#include <KokkosLapack_magma.hpp>

namespace KokkosLapack {
namespace Impl {
Expand Down
Loading