Skip to content

Commit

Permalink
Resolves multiple definition of Magma and Cuda singletons (#2178)
Browse files Browse the repository at this point in the history
Address issue #2175
  • Loading branch information
ndellingwood authored Apr 18, 2024
1 parent cb824ca commit 47a1849
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 62 deletions.
1 change: 1 addition & 0 deletions blas/tpls/KokkosBlas_Cuda_tpl.cpp
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 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 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 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 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_
1 change: 1 addition & 0 deletions lapack/tpls/KokkosLapack_Cuda_tpl.cpp
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 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 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_
2 changes: 1 addition & 1 deletion lapack/tpls/KokkosLapack_gesv_tpl_spec_decl.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

0 comments on commit 47a1849

Please sign in to comment.