A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://kokkos.github.io/kokkos-core-wiki/API/core/initialize_finalize/ScopeGuard.html below:

ScopeGuard - Kokkos documentation

Toggle table of contents sidebar

ScopeGuard

Defined in header <Kokkos_Core.hpp>

Usage
Kokkos::ScopeGuard guard(argc, argv);
Kokkos::ScopeGuard guard(Kokkos::InitializationSettings()  // (since 3.7)
                            .set_map_device_id_by("random")
                            .set_num_threads(1));

ScopeGuard is a class to initialize and finalize Kokkos using RAII. It calls Kokkos::initialize with the provided arguments in the constructor and Kokkos::finalize in the destructor. For correct usage, it is mandatory to create a named instance of a ScopeGuard before any calls to Kokkos are issued.

Warning

Change of behavior in version 3.7 (see below). ScopeGuard will abort if either is_initialized() or is_finalized() return true.

Description
class ScopeGuard

A class calling Kokkos::initialize at the start of its lifetime and Kokkos::finalize at the end of its lifetime.

Constructors

ScopeGuard(int &argc, char *argv[]);
Parameters:
  • argc – number of command line arguments

  • argv – array of character pointers to null-terminated strings storing the command line arguments

ScopeGuard(InitArguments const &arguments = InitArguments());
Parameters:

argumentsstruct object with valid initialization arguments

template<class ...Args>
ScopeGuard(Args&&... args);
Parameters:

args

arguments to pass to Kokkos::initialize

Possible implementation:

template <class... Args> ScopeGuard(Args&&... args){ initialize(std::forward<Args>(args)...); }
~ScopeGuard();

Destructor

Possible implementation:

~ScopeGuard() { finalize(); }
ScopeGuard(ScopeGuard const&) = delete;

Copy constructor

ScopeGuard(ScopeGuard&&) = delete;

Move constructor

ScopeGuard &operator=(ScopeGuard const&) = delete;

Copy assignment operator

ScopeGuard &operator=(ScopeGuard&&) = delete;

Move assignment operator

Notes Example
int main(int argc, char* argv[]) {
    Kokkos::ScopeGuard guard(argc, argv);
    Kokkos::View<double*> my_view("my_view", 10);
    // my_view destructor called before Kokkos::finalize
    // ScopeGuard destructor called, calls Kokkos::finalize
}
See also

Kokkos::initialize, Kokkos::finalize


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4