-
Notifications
You must be signed in to change notification settings - Fork 0
Initialization API
Kokkos::initialize();
Kokkos::initialize(const InitArguments&);
Kokkos::initialize(int& argc, char* argv[]);Initializes all enabled Kokkos backends.
This function should be called before calling any other Kokkos API functions,
including Kokkos object constructors.
Kokkos::finalize must be called after Kokkos::initialize.
Kokkos::finalize();Shuts down all enabled Kokkos backends and frees all associated resources.
This function should be called after calling all other Kokkos API functions,
including Kokkos object destructors.
Programs are ill-formed if they do not call this function after calling Kokkos::initialize.
ScopeGuard is a class introduced to ensure that Kokkos::initialize and
Kokkos::finalize are called correctly even in the presence of unhandled
exceptions and multiple libraries trying to "own" Kokkos initialization.
ScopeGuard calls Kokkos::initialize in its constructor only if
Kokkos::is_initialized() is false, and calls Kokkos::finalize in its
destructor only if it called Kokkos::initialize in its constructor.
ScopeGuard();
ScopeGuard(const InitArguments&);
ScopeGuard(int& argc, char* argv[]);Calls Kokkos::initialize only if
Kokkos::is_initialized() is false.
Arguments are passed directly to Kokkos::initialize if it is called.
~ScopeGuard();Calls Kokkos::finalize
only if the constructor of this object called Kokkos::initialize.
One common mistake is allowing Kokkos objects to live past Kokkos::finalize,
which is easy to do since all objects in the scope of main() live past that point.
Here is an example of this mistake:
int main(int argc, char** argv) {
Kokkos::initialize(argc, argv);
Kokkos::View<double*> my_view("my_view", 10);
Kokkos::finalize();
// my_view destructor called after Kokkos::finalize !
}Switching to Kokkos::ScopeGuard fixes it:
int main(int argc, char** argv) {
Kokkos::ScopeGuard kokkos(argc, argv);
Kokkos::View<double*> my_view("my_view", 10);
// my_view destructor called before Kokkos::finalize
// ScopeGuard destructor called, calls Kokkos::finalize
}Home:
- Introduction
- Machine Model
- Programming Model
- Compiling
- Initialization
- View
- Parallel Dispatch
- Hierarchical Parallelism
- Custom Reductions
- Atomic Operations
- Subviews
- Interoperability
- Kokkos and Virtual Functions
- Initialization and Finalization
- View
- Data Parallelism
- Execution Policies
- Spaces
- Task Parallelism
- Utilities
- STL Compatibility
- Numerics
- Detection Idiom