Skip to content

Commit

Permalink
Add KokkosKernels::eager_initialize() to common
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-kelley committed Aug 27, 2024
1 parent d4c2511 commit 0ec7cfc
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cmake/KokkosKernels_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,12 @@
#define KOKKOSKERNELS_IMPL_COMPILE_LIBRARY false
#endif

/* Enabled components */
#cmakedefine KOKKOSKERNELS_ENABLE_COMPONENT_BATCHED
#cmakedefine KOKKOSKERNELS_ENABLE_COMPONENT_BLAS
#cmakedefine KOKKOSKERNELS_ENABLE_COMPONENT_LAPACK
#cmakedefine KOKKOSKERNELS_ENABLE_COMPONENT_SPARSE
#cmakedefine KOKKOSKERNELS_ENABLE_COMPONENT_GRAPH
#cmakedefine KOKKOSKERNELS_ENABLE_COMPONENT_ODE

#endif // KOKKOSKERNELS_CONFIG_H
11 changes: 10 additions & 1 deletion cmake/kokkoskernels_components.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,13 @@ IF ( KokkosKernels_ENABLE_COMPONENT_BATCHED
ELSE()
SET(KOKKOSKERNELS_ALL_COMPONENTS_ENABLED OFF CACHE BOOL "" FORCE)
ENDIF()
mark_as_advanced(FORCE KOKKOSKERNELS_ALL_COMPONENTS_ENABLED)
mark_as_advanced(FORCE KOKKOSKERNELS_ALL_COMPONENTS_ENABLED)
# Now that component enables are finalized, also set upper-case
# versions of component enables for the config.h
SET(KOKKOSKERNELS_ENABLE_COMPONENT_BATCHED KokkosKernels_ENABLE_COMPONENT_BATCHED)
SET(KOKKOSKERNELS_ENABLE_COMPONENT_BLAS KokkosKernels_ENABLE_COMPONENT_BLAS)
SET(KOKKOSKERNELS_ENABLE_COMPONENT_LAPACK KokkosKernels_ENABLE_COMPONENT_LAPACK)
SET(KOKKOSKERNELS_ENABLE_COMPONENT_GRAPH KokkosKernels_ENABLE_COMPONENT_GRAPH)
SET(KOKKOSKERNELS_ENABLE_COMPONENT_SPARSE KokkosKernels_ENABLE_COMPONENT_SPARSE)
SET(KOKKOSKERNELS_ENABLE_COMPONENT_ODE KokkosKernels_ENABLE_COMPONENT_ODE)

2 changes: 2 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
LIST(APPEND KK_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common/src)
LIST(APPEND KK_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common/impl)
LIST(APPEND KK_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common/unit_test)

LIST(APPEND SOURCES common/src/KokkosKernels_EagerInitialize.cpp)
83 changes: 83 additions & 0 deletions common/src/KokkosKernels_EagerInitialize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//@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

#include "KokkosKernels_EagerInitialize.hpp"
#include "KokkosKernels_config.h"
#include "Kokkos_Core.hpp"

// Include the minimal set of headers that declare all TPL singletons
#ifdef KOKKOSKERNELS_ENABLE_COMPONENT_BLAS
#include "KokkosBlas_tpl_spec.hpp" //cuBLAS, rocBLAS
#ifdef KOKKOSKERNELS_ENABLE_TPL_MAGMA
#include "KokkosBlas_Magma_tpl.hpp"
#endif
#endif

#ifdef KOKKOSKERNELS_ENABLE_COMPONENT_SPARSE
//note: this file declares both cuSPARSE and rocSPARSE singletons
#include "KokkosKernels_tpl_handles_decl.hpp"
#endif

#ifdef KOKKOSKERNELS_ENABLE_COMPONENT_LAPACK
#ifdef KOKKOSKERNELS_ENABLE_TPL_CUSOLVER
#include "KokkosLapack_cusolver.hpp"
#endif
#ifdef KOKKOSKERNELS_ENABLE_TPL_MAGMA
#include "KokkosLapack_magma.hpp"
#endif
#endif

namespace KokkosKernels
{
void eager_initialize()
{
if(!Kokkos::is_initialized())
{
throw std::runtime_error("Kokkos::intialize must be called before KokkosKernels::eager_initialize");
}
#ifdef KOKKOSKERNELS_ENABLE_COMPONENT_BLAS
#ifdef KOKKOSKERNELS_ENABLE_TPL_CUBLAS
(void) KokkosBlas::Impl::CudaBlasSingleton::singleton();
#endif
#ifdef KOKKOSKERNELS_ENABLE_TPL_ROCBLAS
(void) KokkosBlas::Impl::RocBlasSingleton::singleton();
#endif
#ifdef KOKKOSKERNELS_ENABLE_TPL_MAGMA
#include "KokkosBlas_Magma_tpl.hpp"
(void) KokkosBlas::Impl::MagmaSingleton::singleton();
#endif
#endif

#ifdef KOKKOSKERNELS_ENABLE_COMPONENT_SPARSE
#ifdef KOKKOSKERNELS_ENABLE_TPL_CUSPARSE
(void) KokkosKernels::Impl::CusparseSingleton::singleton();
#endif
#ifdef KOKKOSKERNELS_ENABLE_TPL_ROCSPARSE
(void) KokkosKernels::Impl::RocsparseSingleton::singleton();
#endif
#endif

#ifdef KOKKOSKERNELS_ENABLE_COMPONENT_LAPACK
#ifdef KOKKOSKERNELS_ENABLE_TPL_CUSOLVER
(void) KokkosLapack::Impl::CudaLapackSingleton::singleton();
#endif
#ifdef KOKKOSKERNELS_ENABLE_TPL_MAGMA
(void) KokkosLapack::Impl::MagmaSingleton::singleton();
#endif
#endif
}
}

40 changes: 40 additions & 0 deletions common/src/KokkosKernels_EagerInitialize.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//@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 KOKKOKERNELS_EAGER_INITIALIZE_HPP
#define KOKKOKERNELS_EAGER_INITIALIZE_HPP

namespace KokkosKernels
{
// \brief Eagerly initialize handles for all enabled TPLs, as well
// as any other globally shared resources that would otherwise be lazily initialized.
//
// Eagerly initializing a TPL means that it doesn't have to be
// lazily initialized when first calling a kernel that uses it.
// For example, \c eager_initialize() will call \c cusparseCreate() upfront
// so that the first call to \c KokkosSparse::spmv doesn't have to.
// This can add a significant amount of apparent runtime to that first kernel
// call, even though the added time isn't really spent in the kernel.
//
// Calling this before using any kernels/TPLs is optional.
// This function is idempotent (any calls after the first have no effect).
//
// \pre \c Kokkos::initialize() has been called.
void eager_initialize();
}

#endif

1 change: 1 addition & 0 deletions common/unit_test/Test_Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
#include <Test_Common_Iota.hpp>
#include <Test_Common_LowerBound.hpp>
#include <Test_Common_UpperBound.hpp>
#include <Test_Common_EagerInitialize.hpp>

#endif // TEST_COMMON_HPP
28 changes: 28 additions & 0 deletions common/unit_test/Test_Common_EagerInitialize.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@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 KK_EAGERINIT_TEST_HPP
#define KK_EAGERINIT_TEST_HPP

#include "KokkosKernels_EagerInitialize.hpp"

TEST_F(TestCategory, common_eager_initialize)
{
KokkosKernels::eager_initialize();
KokkosKernels::eager_initialize();
};

#endif

0 comments on commit 0ec7cfc

Please sign in to comment.