Skip to content

Commit 5ce93be

Browse files
authored
[UR][HIP] Delete unnecessary ReleaseGuard (#18028)
Its only use is not needed because the `ur_mem_handle_t` constructor/destructor already retains/releases the buffer as needed.
1 parent eb1bc28 commit 5ce93be

File tree

2 files changed

+0
-77
lines changed

2 files changed

+0
-77
lines changed

unified-runtime/source/adapters/hip/common.hpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -125,80 +125,6 @@ void assertion(bool Condition, const char *pMessage = nullptr);
125125
} // namespace ur
126126
} // namespace detail
127127

128-
/// RAII object that calls the reference count release function on the held UR
129-
/// object on destruction.
130-
///
131-
/// The `dismiss` function stops the release from happening on destruction.
132-
template <typename T> class ReleaseGuard {
133-
private:
134-
T Captive;
135-
136-
static ur_result_t callRelease(ur_device_handle_t Captive) {
137-
return urDeviceRelease(Captive);
138-
}
139-
140-
static ur_result_t callRelease(ur_context_handle_t Captive) {
141-
return urContextRelease(Captive);
142-
}
143-
144-
static ur_result_t callRelease(ur_mem_handle_t Captive) {
145-
return urMemRelease(Captive);
146-
}
147-
148-
static ur_result_t callRelease(ur_program_handle_t Captive) {
149-
return urProgramRelease(Captive);
150-
}
151-
152-
static ur_result_t callRelease(ur_kernel_handle_t Captive) {
153-
return urKernelRelease(Captive);
154-
}
155-
156-
static ur_result_t callRelease(ur_queue_handle_t Captive) {
157-
return urQueueRelease(Captive);
158-
}
159-
160-
static ur_result_t callRelease(ur_event_handle_t Captive) {
161-
return urEventRelease(Captive);
162-
}
163-
164-
public:
165-
ReleaseGuard() = delete;
166-
/// Obj can be `nullptr`.
167-
explicit ReleaseGuard(T Obj) : Captive(Obj) {}
168-
ReleaseGuard(ReleaseGuard &&Other) noexcept : Captive(Other.Captive) {
169-
Other.Captive = nullptr;
170-
}
171-
172-
ReleaseGuard(const ReleaseGuard &) = delete;
173-
174-
/// Calls the related UR object release function if the object held is not
175-
/// `nullptr` or if `dismiss` has not been called.
176-
~ReleaseGuard() {
177-
if (Captive != nullptr) {
178-
ur_result_t ret = callRelease(Captive);
179-
if (ret != UR_RESULT_SUCCESS) {
180-
// A reported HIP error is either an implementation or an asynchronous
181-
// HIP error for which it is unclear if the function that reported it
182-
// succeeded or not. Either way, the state of the program is compromised
183-
// and likely unrecoverable.
184-
die("Unrecoverable program state reached in piMemRelease");
185-
}
186-
}
187-
}
188-
189-
ReleaseGuard &operator=(const ReleaseGuard &) = delete;
190-
191-
ReleaseGuard &operator=(ReleaseGuard &&Other) {
192-
Captive = Other.Captive;
193-
Other.Captive = nullptr;
194-
return *this;
195-
}
196-
197-
/// End the guard and do not release the reference count of the held
198-
/// UR object.
199-
void dismiss() { Captive = nullptr; }
200-
};
201-
202128
// Helper method to return a (non-null) pointer's attributes, or std::nullopt in
203129
// the case that the pointer is unknown to the HIP subsystem.
204130
inline static std::optional<hipPointerAttribute_t>

unified-runtime/source/adapters/hip/memory.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferPartition(
186186
// which is necessary before SubBuffer partition
187187
}
188188

189-
ReleaseGuard<ur_mem_handle_t> ReleaseGuard(hBuffer);
190-
191189
std::unique_ptr<ur_mem_handle_t_> RetMemObj{nullptr};
192190
try {
193191
RetMemObj = std::unique_ptr<ur_mem_handle_t_>{
@@ -203,7 +201,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferPartition(
203201
return UR_RESULT_ERROR_UNKNOWN;
204202
}
205203

206-
ReleaseGuard.dismiss();
207204
*phMem = RetMemObj.release();
208205
return UR_RESULT_SUCCESS;
209206
}

0 commit comments

Comments
 (0)