-
Notifications
You must be signed in to change notification settings - Fork 6
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
Introduce global setup/cleanup in APIs #220
base: main
Are you sure you want to change the base?
Changes from 6 commits
673b484
e0abd00
e9b3d8e
f92deb5
284a0fb
19bd963
2b59d12
7986dd2
fab2afb
a557b5a
45cc295
1d427ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,79 @@ | ||||||
// SPDX-FileCopyrightText: (C) The kokkos-fft development team, see COPYRIGHT.md file | ||||||
// | ||||||
// SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception | ||||||
|
||||||
#include <Kokkos_Core.hpp> | ||||||
#include "KokkosFFT_Core.hpp" | ||||||
#include "KokkosFFT_default_types.hpp" | ||||||
|
||||||
namespace { | ||||||
bool g_is_initialized = false; | ||||||
bool g_is_finalized = false; | ||||||
|
||||||
bool kokkosfft_initialize_was_called() { | ||||||
return KokkosFFT::is_initialized() || KokkosFFT::is_finalized(); | ||||||
} | ||||||
bool kokkosfft_finalize_was_called() { return KokkosFFT::is_finalized(); } | ||||||
|
||||||
void initialize_internal() { | ||||||
KokkosFFT::Impl::initialize_host(); | ||||||
KokkosFFT::Impl::initialize_device(); | ||||||
} | ||||||
|
||||||
void finalize_internal() { | ||||||
KokkosFFT::Impl::finalize_host(); | ||||||
KokkosFFT::Impl::finalize_device(); | ||||||
} | ||||||
} // namespace | ||||||
|
||||||
[[nodiscard]] bool KokkosFFT::is_initialized() noexcept { | ||||||
return g_is_initialized; | ||||||
} | ||||||
|
||||||
[[nodiscard]] bool KokkosFFT::is_finalized() noexcept { return g_is_finalized; } | ||||||
|
||||||
void KokkosFFT::initialize() { | ||||||
if (!(Kokkos::is_initialized() || Kokkos::is_finalized())) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Do we need to test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to exclude the situation after finalization, where |
||||||
Kokkos::abort( | ||||||
"Error: KokkosFFT::initialize() must not be called before initializing " | ||||||
"Kokkos.\n"); | ||||||
} | ||||||
if (Kokkos::is_finalized()) { | ||||||
Kokkos::abort( | ||||||
"Error: KokkosFFT::initialize() must not be called after finalizing " | ||||||
"Kokkos.\n"); | ||||||
} | ||||||
if (kokkosfft_initialize_was_called()) { | ||||||
Kokkos::abort( | ||||||
"Error: KokkosFFT::initialize() has already been called." | ||||||
" KokkosFFT can be initialized at most once.\n"); | ||||||
} | ||||||
initialize_internal(); | ||||||
g_is_initialized = true; | ||||||
} | ||||||
|
||||||
void KokkosFFT::finalize() { | ||||||
if (!(Kokkos::is_initialized() || Kokkos::is_finalized())) { | ||||||
Kokkos::abort( | ||||||
"Error: KokkosFFT::finalize() may only be called after Kokkos has been " | ||||||
"initialized.\n"); | ||||||
} | ||||||
if (Kokkos::is_finalized()) { | ||||||
Kokkos::abort( | ||||||
"Error: KokkosFFT::finalize() must be called before finalizing " | ||||||
"Kokkos.\n"); | ||||||
} | ||||||
|
||||||
if (!kokkosfft_initialize_was_called()) { | ||||||
Kokkos::abort( | ||||||
"Error: KokkosFFT::finalize() may only be called after KokkosFFT has " | ||||||
"been " | ||||||
"initialized.\n"); | ||||||
} | ||||||
if (kokkosfft_finalize_was_called()) { | ||||||
Kokkos::abort("Error: KokkosFFT::finalize() has already been called.\n"); | ||||||
} | ||||||
finalize_internal(); | ||||||
g_is_initialized = false; | ||||||
g_is_finalized = true; | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-FileCopyrightText: (C) The kokkos-fft development team, see COPYRIGHT.md file | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception | ||
|
||
#ifndef KOKKOSFFT_CORE_HPP | ||
#define KOKKOSFFT_CORE_HPP | ||
|
||
namespace KokkosFFT { | ||
void initialize(); | ||
|
||
[[nodiscard]] bool is_initialized() noexcept; | ||
[[nodiscard]] bool is_finalized() noexcept; | ||
|
||
void finalize(); | ||
} // namespace KokkosFFT | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not force it to be
STATIC
to allow people to useBUILD_SHARED_LIBS
, https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html.