-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5738 from Rombur/refactor_openmp
Refactor OpenMP backend
- Loading branch information
Showing
9 changed files
with
337 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
//@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 KOKKOS_IMPL_PUBLIC_INCLUDE | ||
#define KOKKOS_IMPL_PUBLIC_INCLUDE | ||
#endif | ||
|
||
#include <OpenMP/Kokkos_OpenMP.hpp> | ||
#include <OpenMP/Kokkos_OpenMP_Instance.hpp> | ||
|
||
#include <impl/Kokkos_ExecSpaceManager.hpp> | ||
|
||
namespace Kokkos { | ||
|
||
OpenMP::OpenMP() | ||
: m_space_instance(&Impl::OpenMPInternal::singleton(), | ||
[](Impl::OpenMPInternal *) {}) { | ||
Impl::OpenMPInternal::singleton().verify_is_initialized( | ||
"OpenMP instance constructor"); | ||
} | ||
|
||
OpenMP::OpenMP(int pool_size) | ||
: m_space_instance(new Impl::OpenMPInternal(pool_size), | ||
[](Impl::OpenMPInternal *ptr) { | ||
ptr->finalize(); | ||
delete ptr; | ||
}) { | ||
Impl::OpenMPInternal::singleton().verify_is_initialized( | ||
"OpenMP instance constructor"); | ||
} | ||
|
||
int OpenMP::impl_get_current_max_threads() noexcept { | ||
return Impl::OpenMPInternal::get_current_max_threads(); | ||
} | ||
|
||
void OpenMP::impl_initialize(InitializationSettings const &settings) { | ||
Impl::OpenMPInternal::singleton().initialize( | ||
settings.has_num_threads() ? settings.get_num_threads() : -1); | ||
} | ||
|
||
void OpenMP::impl_finalize() { Impl::OpenMPInternal::singleton().finalize(); } | ||
|
||
void OpenMP::print_configuration(std::ostream &os, bool /*verbose*/) const { | ||
os << "Host Parallel Execution Space:\n"; | ||
os << " KOKKOS_ENABLE_OPENMP: yes\n"; | ||
|
||
os << "OpenMP Atomics:\n"; | ||
os << " KOKKOS_ENABLE_OPENMP_ATOMICS: "; | ||
#ifdef KOKKOS_ENABLE_OPENMP_ATOMICS | ||
os << "yes\n"; | ||
#else | ||
os << "no\n"; | ||
#endif | ||
|
||
os << "\nOpenMP Runtime Configuration:\n"; | ||
|
||
m_space_instance->print_configuration(os); | ||
} | ||
|
||
int OpenMP::concurrency(OpenMP const &instance) { | ||
return impl_thread_pool_size(instance); | ||
} | ||
|
||
void OpenMP::fence(const std::string &name) const { | ||
Kokkos::Tools::Experimental::Impl::profile_fence_event<Kokkos::OpenMP>( | ||
name, Kokkos::Tools::Experimental::Impl::DirectFenceIDHandle{1}, []() {}); | ||
} | ||
|
||
bool OpenMP::impl_is_initialized() noexcept { | ||
return Impl::OpenMPInternal::singleton().is_initialized(); | ||
} | ||
|
||
bool OpenMP::in_parallel(OpenMP const &exec_space) noexcept { | ||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3 | ||
return ( | ||
(exec_space.impl_internal_space_instance()->m_level < omp_get_level()) && | ||
(!Impl::t_openmp_instance || | ||
Impl::t_openmp_instance->m_level < omp_get_level())); | ||
#else | ||
return exec_space.impl_internal_space_instance()->m_level < omp_get_level(); | ||
#endif | ||
} | ||
|
||
int OpenMP::impl_thread_pool_size(OpenMP const &exec_space) noexcept { | ||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3 | ||
return OpenMP::in_parallel(exec_space) | ||
? omp_get_num_threads() | ||
: (Impl::t_openmp_instance | ||
? Impl::t_openmp_instance->m_pool_size | ||
: exec_space.impl_internal_space_instance()->m_pool_size); | ||
#else | ||
return OpenMP::in_parallel(exec_space) | ||
? omp_get_num_threads() | ||
: exec_space.impl_internal_space_instance()->m_pool_size; | ||
#endif | ||
} | ||
|
||
int OpenMP::impl_max_hardware_threads() noexcept { | ||
return Impl::g_openmp_hardware_max_threads; | ||
} | ||
|
||
namespace Impl { | ||
|
||
int g_openmp_space_factory_initialized = | ||
initialize_space_factory<OpenMP>("050_OpenMP"); | ||
|
||
} // namespace Impl | ||
|
||
} // namespace Kokkos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.