@@ -105,9 +105,10 @@ hip_device_get_name(hipDevice_t device)
105
105
return (xrt_core::device_query<xrt_core::query::rom_vbnv>((device_cache.get_or_error (device))->get_xrt_device ().get_handle ()));
106
106
}
107
107
108
- static hipDeviceProp_t
109
- hip_get_device_properties (hipDevice_t device)
108
+ static void
109
+ hip_get_device_properties (hipDeviceProp_t* props, hipDevice_t device)
110
110
{
111
+ throw_invalid_value_if (!props, " arg passed is nullptr" );
111
112
throw_invalid_device_if (check (device), " device requested is not available" );
112
113
113
114
throw std::runtime_error (" Not implemented" );
@@ -127,9 +128,10 @@ hip_device_get_uuid(hipDevice_t device)
127
128
return uid;
128
129
}
129
130
130
- static int
131
- hip_device_get_attribute (hipDeviceAttribute_t attr, int device)
131
+ static void
132
+ hip_device_get_attribute (int * pi, hipDeviceAttribute_t attr, int device)
132
133
{
134
+ throw_invalid_value_if (!pi, " arg passed is nullptr" );
133
135
throw_invalid_device_if (check (device), " device requested is not available" );
134
136
135
137
throw std::runtime_error (" Not implemented" );
@@ -156,62 +158,32 @@ hip_kernel_name_ref(const hipFunction_t f)
156
158
hipError_t
157
159
hipInit (unsigned int flags)
158
160
{
159
- try {
160
- xrt::core::hip::hip_init (flags);
161
- return hipSuccess;
162
- }
163
- catch (const xrt_core::system_error& ex) {
164
- xrt_core::send_exception_message (std::string (__func__) + " - " + ex.what ());
165
- return static_cast <hipError_t>(ex.value ());
166
- }
167
- catch (const std::exception& ex) {
168
- xrt_core::send_exception_message (ex.what ());
169
- }
170
- return hipErrorNotInitialized;
161
+ return handle_hip_func_error (__func__, hipErrorNotInitialized, [&] {
162
+ xrt::core::hip::hip_init (flags); });
171
163
}
172
164
173
165
hipError_t
174
166
hipGetDeviceCount (size_t * count)
175
167
{
176
- try {
168
+ return handle_hip_func_error (__func__, hipErrorUnknown, [&] {
177
169
throw_invalid_value_if (!count, " arg passed is nullptr" );
178
-
179
170
*count = xrt::core::hip::hip_get_device_count ();
180
- return hipSuccess;
181
- }
182
- catch (const xrt_core::system_error& ex) {
183
- xrt_core::send_exception_message (std::string (__func__) + " - " + ex.what ());
184
- return static_cast <hipError_t>(ex.value ());
185
- }
186
- catch (const std::exception& ex) {
187
- xrt_core::send_exception_message (ex.what ());
188
- }
189
- return hipErrorUnknown;
171
+ });
190
172
}
191
173
192
174
hipError_t
193
175
hipDeviceGet (hipDevice_t* device, int ordinal)
194
176
{
195
- try {
177
+ return handle_hip_func_error (__func__, hipErrorUnknown, [&] {
196
178
throw_invalid_value_if (!device, " device is nullptr" );
197
-
198
179
*device = xrt::core::hip::hip_device_get (ordinal);
199
- return hipSuccess;
200
- }
201
- catch (const xrt_core::system_error& ex) {
202
- xrt_core::send_exception_message (std::string (__func__) + " - " + ex.what ());
203
- return static_cast <hipError_t>(ex.value ());
204
- }
205
- catch (const std::exception& ex) {
206
- xrt_core::send_exception_message (ex.what ());
207
- }
208
- return hipErrorUnknown;
180
+ });
209
181
}
210
182
211
183
hipError_t
212
184
hipDeviceGetName (char * name, int len, hipDevice_t device)
213
185
{
214
- try {
186
+ return handle_hip_func_error (__func__, hipErrorUnknown, [&] {
215
187
throw_invalid_value_if ((!name || len <= 0 ), " invalid arg" );
216
188
217
189
auto name_str = xrt::core::hip::hip_device_get_name (device);
@@ -220,16 +192,7 @@ hipDeviceGetName(char* name, int len, hipDevice_t device)
220
192
auto cpy_size = (static_cast <size_t >(len) <= (name_str.length () + 1 ) ? (len - 1 ) : name_str.length ());
221
193
std::memcpy (name, name_str.c_str (), cpy_size);
222
194
name[cpy_size] = ' \0 ' ;
223
- return hipSuccess;
224
- }
225
- catch (const xrt_core::system_error& ex) {
226
- xrt_core::send_exception_message (std::string (__func__) + " - " + ex.what ());
227
- return static_cast <hipError_t>(ex.value ());
228
- }
229
- catch (const std::exception& ex) {
230
- xrt_core::send_exception_message (ex.what ());
231
- }
232
- return hipErrorUnknown;
195
+ });
233
196
}
234
197
235
198
#if HIP_VERSION >= 60000000
@@ -256,91 +219,47 @@ hipError_t
256
219
hipGetDeviceProperties (hipDeviceProp_t* props, hipDevice_t device)
257
220
#endif
258
221
{
259
- try {
260
- throw_invalid_value_if (!props, " arg passed is nullptr" );
261
-
262
- *props = xrt::core::hip::hip_get_device_properties (device);
263
- return hipSuccess;
264
- }
265
- catch (const xrt_core::system_error& ex) {
266
- xrt_core::send_exception_message (std::string (__func__) + " - " + ex.what ());
267
- return static_cast <hipError_t>(ex.value ());
268
- }
269
- catch (const std::exception& ex) {
270
- xrt_core::send_exception_message (ex.what ());
271
- }
272
- return hipErrorUnknown;
222
+ return handle_hip_func_error (__func__, hipErrorUnknown, [&] {
223
+ xrt::core::hip::hip_get_device_properties (props, device);
224
+ });
273
225
}
274
226
275
227
hipError_t
276
228
hipDeviceGetUuid (hipUUID* uuid, hipDevice_t device)
277
229
{
278
- try {
230
+ return handle_hip_func_error (__func__, hipErrorUnknown, [&] {
279
231
throw_invalid_value_if (!uuid, " arg passed is nullptr" );
280
-
281
232
*uuid = xrt::core::hip::hip_device_get_uuid (device);
282
- return hipSuccess;
283
- }
284
- catch (const xrt_core::system_error& ex) {
285
- xrt_core::send_exception_message (std::string (__func__) + " - " + ex.what ());
286
- return static_cast <hipError_t>(ex.value ());
287
- }
288
- catch (const std::exception& ex) {
289
- xrt_core::send_exception_message (ex.what ());
290
- }
291
- return hipErrorUnknown;
233
+ });
292
234
}
293
235
294
236
hipError_t
295
237
hipDeviceGetAttribute (int * pi, hipDeviceAttribute_t attr, int device)
296
238
{
297
- try {
298
- throw_invalid_value_if (!pi, " arg passed is nullptr" );
299
-
300
- *pi = xrt::core::hip::hip_device_get_attribute (attr, device);
301
- return hipSuccess;
302
- }
303
- catch (const xrt_core::system_error& ex) {
304
- xrt_core::send_exception_message (std::string (__func__) + " - " + ex.what ());
305
- return static_cast <hipError_t>(ex.value ());
306
- }
307
- catch (const std::exception& ex) {
308
- xrt_core::send_exception_message (ex.what ());
309
- }
310
- return hipErrorUnknown;
239
+ return handle_hip_func_error (__func__, hipErrorUnknown, [&] {
240
+ xrt::core::hip::hip_device_get_attribute (pi, attr, device);
241
+ });
311
242
}
312
243
313
244
hipError_t
314
245
hipSetDevice (int device)
315
246
{
316
- try {
247
+ return handle_hip_func_error (__func__, hipErrorUnknown, [&] {
317
248
xrt::core::hip::hip_set_device (device);
318
- return hipSuccess;
319
- }
320
- catch (const xrt_core::system_error& ex) {
321
- xrt_core::send_exception_message (std::string (__func__) + " - " + ex.what ());
322
- return static_cast <hipError_t>(ex.value ());
323
- }
324
- catch (const std::exception& ex) {
325
- xrt_core::send_exception_message (std::string (__func__) + " - " + ex.what ());
326
- }
327
- return hipErrorUnknown;
249
+ });
328
250
}
329
251
330
252
const char *
331
253
hipKernelNameRef (const hipFunction_t f)
332
254
{
333
- try {
255
+ const char * kname_ref = nullptr ;
256
+ hipError_t err = handle_hip_func_error (__func__, hipErrorInvalidValue, [&] {
334
257
throw_invalid_value_if (!f, " arg passed is nullptr" );
258
+ kname_ref = xrt::core::hip::hip_kernel_name_ref (f);
259
+ });
335
260
336
- return xrt::core::hip::hip_kernel_name_ref (f);
337
- }
338
- catch (const xrt_core::system_error& ex) {
339
- xrt_core::send_exception_message (std::string (__func__) + " - " + ex.what ());
261
+ if (err != hipSuccess)
340
262
return nullptr ;
341
- }
342
- catch (const std::exception& ex) {
343
- xrt_core::send_exception_message (ex.what ());
344
- }
345
- return nullptr ;
263
+
264
+ return kname_ref;
346
265
}
0 commit comments