@@ -125,80 +125,6 @@ void assertion(bool Condition, const char *pMessage = nullptr);
125
125
} // namespace ur
126
126
} // namespace detail
127
127
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
-
202
128
// Helper method to return a (non-null) pointer's attributes, or std::nullopt in
203
129
// the case that the pointer is unknown to the HIP subsystem.
204
130
inline static std::optional<hipPointerAttribute_t>
0 commit comments