Skip to content

Commit

Permalink
Fixes #600: Now only using underscore-suffixed field names in proxy c…
Browse files Browse the repository at this point in the history
…lasses
  • Loading branch information
eyalroz committed Mar 8, 2024
1 parent a69578a commit ad85c2f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
14 changes: 7 additions & 7 deletions src/cuda/api/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class device_t {
void cache_and_ensure_primary_context_activation() const {
if (primary_context_handle_ == context::detail_::none) {
primary_context_handle_ = device::primary_context::detail_::obtain_and_increase_refcount(id_);
holds_pc_refcount_unit = true;
holds_pc_refcount_unit_ = true;
}
}

Expand Down Expand Up @@ -597,7 +597,7 @@ class device_t {
protected:
void maybe_decrease_primary_context_refcount() const
{
if (holds_pc_refcount_unit) {
if (holds_pc_refcount_unit_) {
device::primary_context::detail_::decrease_refcount(id_);
}
}
Expand All @@ -608,15 +608,15 @@ class device_t {
{
::std::swap(lhs.id_, rhs.id_);
::std::swap(lhs.primary_context_handle_, rhs.primary_context_handle_);
::std::swap(lhs.holds_pc_refcount_unit, rhs.holds_pc_refcount_unit);
::std::swap(lhs.holds_pc_refcount_unit_, rhs.holds_pc_refcount_unit_);
}

~device_t() NOEXCEPT_IF_NDEBUG
{
#ifndef NDEBUG
maybe_decrease_primary_context_refcount();
#else
if (holds_pc_refcount_unit) {
if (holds_pc_refcount_unit_) {
device::primary_context::detail_::decrease_refcount_nothrow(id_);
// Swallow any error to avoid termination on throwing from a dtor
}
Expand All @@ -641,7 +641,7 @@ class device_t {
maybe_decrease_primary_context_refcount();
id_ = other.id_;
primary_context_handle_ = other.primary_context_handle_;
holds_pc_refcount_unit = false;
holds_pc_refcount_unit_ = false;
return *this;
}

Expand All @@ -664,7 +664,7 @@ class device_t {
:
id_(device_id),
primary_context_handle_(primary_context_handle),
holds_pc_refcount_unit(hold_primary_context_refcount_unit)
holds_pc_refcount_unit_(hold_primary_context_refcount_unit)
{
#ifndef NDEBUG
if (id_ < 0) {
Expand All @@ -684,7 +684,7 @@ class device_t {
mutable device::primary_context::handle_t primary_context_handle_ { context::detail_::none };
/// Most work involving a device actually occurs using its primary context; we cache the handle
/// to this context here - albeit not necessary on construction
mutable bool holds_pc_refcount_unit { false };
mutable bool holds_pc_refcount_unit_ {false };
/// Since we're allowed to cache the primary context handle on constant device_t's, we
/// also need to keep track of whether this object "owns" this reference.
};
Expand Down
26 changes: 13 additions & 13 deletions src/cuda/api/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ class event_t {
event::handle_t handle() const noexcept { return handle_; }

/// True if this wrapper is responsible for telling CUDA to destroy the event upon the wrapper's own destruction
bool is_owning() const noexcept { return owning; }
bool is_owning() const noexcept { return owning_; }

/// True if this wrapper has been associated with an increase of the device's primary context's reference count
bool holds_primary_context_reference() const noexcept { return holds_pc_refcount_unit; }
bool holds_primary_context_reference() const noexcept { return holds_pc_refcount_unit_; }

/// The device w.r.t. which the event is defined
device_t device() const;
Expand Down Expand Up @@ -231,8 +231,8 @@ class event_t {
device_id_(device_id),
context_handle_(context_handle),
handle_(event_handle),
owning(take_ownership),
holds_pc_refcount_unit(hold_pc_refcount_unit) { }
owning_(take_ownership),
holds_pc_refcount_unit_(hold_pc_refcount_unit) { }

public: // friendship

Expand All @@ -254,15 +254,15 @@ class event_t {
event_t(const event_t& other) = delete;

event_t(event_t&& other) noexcept : event_t(
other.device_id_, other.context_handle_, other.handle_, other.owning, other.holds_pc_refcount_unit)
other.device_id_, other.context_handle_, other.handle_, other.owning_, other.holds_pc_refcount_unit_)
{
other.owning = false;
other.holds_pc_refcount_unit = false;
other.owning_ = false;
other.holds_pc_refcount_unit_ = false;
};

~event_t() noexcept(false)
{
if (owning) {
if (owning_) {
#ifdef NDEBUG
cuEventDestroy(handle_);
// Note: "Swallowing" any potential error to avoid ::std::terminate(); also,
Expand All @@ -272,7 +272,7 @@ class event_t {
#endif
}
// TODO: DRY
if (holds_pc_refcount_unit) {
if (holds_pc_refcount_unit_) {
#ifdef NDEBUG
device::primary_context::detail_::decrease_refcount_nothrow(device_id_);
// Note: "Swallowing" any potential error to avoid ::std::terminate(); also,
Expand All @@ -291,19 +291,19 @@ class event_t {
::std::swap(device_id_, other.device_id_);
::std::swap(context_handle_, other.context_handle_);
::std::swap(handle_, other.handle_);
::std::swap(owning, other.owning);
::std::swap(holds_pc_refcount_unit, holds_pc_refcount_unit);
::std::swap(owning_, other.owning_);
::std::swap(holds_pc_refcount_unit_, holds_pc_refcount_unit_);
return *this;
}

protected: // data members
device::id_t device_id_;
context::handle_t context_handle_;
event::handle_t handle_;
bool owning;
bool owning_;
// this field is mutable only for enabling move construction; other
// than in that case it must not be altered
bool holds_pc_refcount_unit;
bool holds_pc_refcount_unit_;
// When context_handle_ is the handle of a primary context, this event may
// be "keeping that context alive" through the refcount - in which case
// it must release its refcount unit on destruction
Expand Down
12 changes: 6 additions & 6 deletions src/cuda/api/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class module_t {
bool holds_primary_context_refcount_unit)
noexcept
: device_id_(device_id), context_handle_(context), handle_(handle), owning_(owning),
holds_pc_refcount_unit(holds_primary_context_refcount_unit)
holds_pc_refcount_unit_(holds_primary_context_refcount_unit)
{ }

public: // friendship
Expand All @@ -165,10 +165,10 @@ class module_t {
other.context_handle_,
other.handle_,
other.owning_,
other.holds_pc_refcount_unit)
other.holds_pc_refcount_unit_)
{
other.owning_ = false;
other.holds_pc_refcount_unit = false;
other.holds_pc_refcount_unit_ = false;
};

// Note: It is up to the user of this class to ensure that it is destroyed _before_ the context
Expand All @@ -180,7 +180,7 @@ class module_t {
module::detail_::destroy(handle_, context_handle_, device_id_);
}
// TODO: DRY
if (holds_pc_refcount_unit) {
if (holds_pc_refcount_unit_) {
#ifdef NDEBUG
device::primary_context::detail_::decrease_refcount_nothrow(device_id_);
// Note: "Swallowing" any potential error to avoid ::std::terminate(); also,
Expand All @@ -200,7 +200,7 @@ class module_t {
::std::swap(context_handle_, other.context_handle_);
::std::swap(handle_, other.handle_);
::std::swap(owning_, other.owning_);
::std::swap(holds_pc_refcount_unit, holds_pc_refcount_unit);
::std::swap(holds_pc_refcount_unit_, holds_pc_refcount_unit_);
return *this;
}

Expand All @@ -211,7 +211,7 @@ class module_t {
bool owning_;
// this field is mutable only for enabling move construction; other
// than in that case it must not be altered
bool holds_pc_refcount_unit;
bool holds_pc_refcount_unit_;
// When context_handle_ is the handle of a primary context, this module
// may be "keeping that context alive" through the refcount - in which
// case it must release its refcount unit on destruction
Expand Down
24 changes: 12 additions & 12 deletions src/cuda/api/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class stream_t {
context_t context() const noexcept;

/// True if this wrapper is responsible for telling CUDA to destroy the stream upon the wrapper's own destruction
bool is_owning() const noexcept { return owning; }
bool is_owning() const noexcept { return owning_; }

public: // other non-mutators

Expand Down Expand Up @@ -797,8 +797,8 @@ class stream_t {
device_id_(device_id),
context_handle_(context_handle),
handle_(stream_handle),
owning(take_ownership),
holds_pc_refcount_unit(hold_primary_context_refcount_unit)
owning_(take_ownership),
holds_pc_refcount_unit_(hold_primary_context_refcount_unit)
{ }

public: // constructors and destructor
Expand All @@ -812,20 +812,20 @@ class stream_t {
stream_t(const stream_t& other) = delete;

stream_t(stream_t&& other) noexcept :
stream_t(other.device_id_, other.context_handle_, other.handle_, other.owning, other.holds_pc_refcount_unit)
stream_t(other.device_id_, other.context_handle_, other.handle_, other.owning_, other.holds_pc_refcount_unit_)
{
other.owning = false;
other.holds_pc_refcount_unit = false;
other.owning_ = false;
other.holds_pc_refcount_unit_ = false;
}

~stream_t() noexcept(false)
{
if (owning) {
if (owning_) {
CAW_SET_SCOPE_CONTEXT(context_handle_);
cuStreamDestroy(handle_);
}
// TODO: DRY
if (holds_pc_refcount_unit) {
if (holds_pc_refcount_unit_) {
#ifdef NDEBUG
device::primary_context::detail_::decrease_refcount_nothrow(device_id_);
// Note: "Swallowing" any potential error to avoid ::std::terminate(); also,
Expand All @@ -844,8 +844,8 @@ class stream_t {
::std::swap(device_id_, other.device_id_);
::std::swap(context_handle_, other.context_handle_);
::std::swap(handle_, other.handle_);
::std::swap(owning, other.owning);
::std::swap(holds_pc_refcount_unit, holds_pc_refcount_unit);
::std::swap(owning_, other.owning_);
::std::swap(holds_pc_refcount_unit_, holds_pc_refcount_unit_);
return *this;
}

Expand Down Expand Up @@ -877,8 +877,8 @@ class stream_t {
device::id_t device_id_;
context::handle_t context_handle_;
stream::handle_t handle_;
bool owning;
bool holds_pc_refcount_unit;
bool owning_;
bool holds_pc_refcount_unit_;
// When context_handle_ is the handle of a primary context, this event may
// be "keeping that context alive" through the refcount - in which case
// it must release its refcount unit on destruction
Expand Down

0 comments on commit ad85c2f

Please sign in to comment.