Skip to content

Commit

Permalink
Fixes #620: context::current::scoped_override_t moved from `api/mul…
Browse files Browse the repository at this point in the history
…ti_wrapper_impls/context.hpp` up into `current_context.hpp` (with only some definitions remaining)
  • Loading branch information
eyalroz committed Mar 25, 2024
1 parent e13ef08 commit b3f05a9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
30 changes: 30 additions & 0 deletions src/cuda/api/current_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace cuda {
///@cond
class device_t;
class context_t;
namespace device {
class primary_context_t;
} // namespace device
///@endcond

namespace context {
Expand Down Expand Up @@ -188,6 +191,7 @@ class scoped_override_t {
};

///@cond

/*
* This macro is intended for use inside the cuda-api-wrappers implementation, to
* save us some typing; it's quite usable on the outside, but you probably want to
Expand Down Expand Up @@ -228,6 +232,32 @@ class scoped_ensurer_t {

} // namespace detail_

/**
* A RAII-based mechanism for pushing a context onto the context stack
* for what remains of the current (C++ language) scope - making it the
* current context - then popping it back when exiting the scope -
* restoring the stack and the current context to what they had been
* previously.
*
* @note if some other code pushes/pops from the context stack during
* the lifetime of this class, the pop-on-destruction may fail, or
* succeed but pop some other context handle than the one originally.
* pushed.
*
*/
class scoped_override_t : private detail_::scoped_override_t {
protected:
using parent = detail_::scoped_override_t;
public:

explicit scoped_override_t(device::primary_context_t&& primary_context);
explicit scoped_override_t(const context_t& context);
explicit scoped_override_t(context_t&& context);
~scoped_override_t() = default;
};



/**
* This macro will set the current device for the remainder of the scope in which it is
* invoked, and will change it back to the previous value when exiting the scope. Use
Expand Down
27 changes: 3 additions & 24 deletions src/cuda/api/multi_wrapper_impls/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,31 +168,10 @@ class scoped_existence_ensurer_t {

} // namespace detail_

/**
* A RAII-based mechanism for pushing a context onto the context stack
* for what remains of the current (C++ language) scope - making it the
* current context - then popping it back when exiting the scope -
* restoring the stack and the current context to what they had been
* previously.
*
* @note if some other code pushes/pops from the context stack during
* the lifetime of this class, the pop-on-destruction may fail, or
* succeed but pop some other context handle than the one originally.
* pushed.
*
*/
class scoped_override_t : private detail_::scoped_override_t {
protected:
using parent = detail_::scoped_override_t;
public:

explicit scoped_override_t(device::primary_context_t&& primary_context)
inline scoped_override_t::scoped_override_t(device::primary_context_t&& primary_context)
: parent(primary_context.is_owning(), primary_context.device_id(), primary_context.handle()) {}
explicit scoped_override_t(const context_t& context) : parent(context.handle()) {}
explicit scoped_override_t(context_t&& context) : parent(context.handle()) {}
~scoped_override_t() = default;
};

inline scoped_override_t::scoped_override_t(const context_t& context) : parent(context.handle()) {}
inline scoped_override_t::scoped_override_t(context_t&& context) : parent(context.handle()) {}

} // namespace current

Expand Down

0 comments on commit b3f05a9

Please sign in to comment.