Skip to content

Commit 61bc8a4

Browse files
authored
[UR] Share generic error handling between adapters (#17576)
* `UR_ASSERT`: Remove redefinition in L0 adapter. * `die()`: Use `logger` and remover redefinitions in 4 adapters. * `UR_CALL*`: Move from L0 to shared `ur.hpp`, used in sanitizer layer and other adapters.
1 parent 5c5954e commit 61bc8a4

28 files changed

+234
-332
lines changed

Diff for: unified-runtime/source/adapters/cuda/command_buffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
6868
/// all the memory objects allocated for command_buffer managment
6969
ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
7070
// Release the memory allocated to the Context stored in the command_buffer
71-
UR_TRACE(urContextRelease(Context));
71+
UR_CALL_NOCHECK(urContextRelease(Context));
7272

7373
// Release the device
74-
UR_TRACE(urDeviceRelease(Device));
74+
UR_CALL_NOCHECK(urDeviceRelease(Device));
7575
}
7676

7777
// This may throw so it must be called from within a try...catch

Diff for: unified-runtime/source/adapters/cuda/command_buffer.hpp

-17
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,6 @@
1818
#include <memory>
1919
#include <unordered_set>
2020

21-
// Trace an internal UR call
22-
#define UR_TRACE(Call) \
23-
{ \
24-
ur_result_t Result; \
25-
UR_CALL(Call, Result); \
26-
}
27-
28-
// Trace an internal UR call and return the result to the user.
29-
#define UR_CALL(Call, Result) \
30-
{ \
31-
if (PrintTrace) \
32-
logger::always("UR ---> {}", #Call); \
33-
Result = (Call); \
34-
if (PrintTrace) \
35-
logger::always("UR <--- {}({})", #Call, Result); \
36-
}
37-
3821
enum class CommandType {
3922
Kernel,
4023
USMMemcpy,

Diff for: unified-runtime/source/adapters/cuda/common.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ std::string getCudaVersionString() {
9292
return stream.str();
9393
}
9494

95-
void detail::ur::die(const char *Message) {
96-
logger::always("ur_die:{}", Message);
97-
std::terminate();
98-
}
99-
10095
void detail::ur::assertion(bool Condition, const char *Message) {
10196
if (!Condition)
10297
die(Message);

Diff for: unified-runtime/source/adapters/cuda/common.hpp

-6
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ void setPluginSpecificMessage(CUresult cu_res);
5757
namespace detail {
5858
namespace ur {
5959

60-
// Report error and no return (keeps compiler from printing warnings).
61-
// TODO: Probably change that to throw a catchable exception,
62-
// but for now it is useful to see every failure.
63-
//
64-
[[noreturn]] void die(const char *Message);
65-
6660
// Reports error messages
6761
void cuPrint(const char *Message);
6862

Diff for: unified-runtime/source/adapters/cuda/enqueue.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ static size_t imageElementByteSize(CUDA_ARRAY_DESCRIPTOR ArrayDesc) {
11041104
case CU_AD_FORMAT_FLOAT:
11051105
return 4;
11061106
default:
1107-
detail::ur::die("Invalid image format.");
1107+
die("Invalid image format.");
11081108
return 0;
11091109
}
11101110
}

Diff for: unified-runtime/source/adapters/cuda/event.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ ur_result_t ur_event_handle_t_::record() {
113113
try {
114114
EventID = Queue->getNextEventID();
115115
if (EventID == 0) {
116-
detail::ur::die(
117-
"Unrecoverable program state reached in event identifier overflow");
116+
die("Unrecoverable program state reached in event identifier overflow");
118117
}
119118
UR_CHECK_ERROR(cuEventRecord(EvEnd, Stream));
120119
} catch (ur_result_t error) {

Diff for: unified-runtime/source/adapters/cuda/memory.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) {
118118
// error for which it is unclear if the function that reported it succeeded
119119
// or not. Either way, the state of the program is compromised and likely
120120
// unrecoverable.
121-
detail::ur::die("Unrecoverable program state reached in urMemRelease");
121+
die("Unrecoverable program state reached in urMemRelease");
122122
}
123123

124124
return UR_RESULT_SUCCESS;

Diff for: unified-runtime/source/adapters/cuda/queue.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
279279
else if (CuFlags == CU_STREAM_NON_BLOCKING)
280280
Flags = UR_QUEUE_FLAG_SYNC_WITH_DEFAULT_STREAM;
281281
else
282-
detail::ur::die("Unknown cuda stream");
282+
die("Unknown cuda stream");
283283

284284
std::vector<CUstream> ComputeCuStreams(1, CuStream);
285285
std::vector<CUstream> TransferCuStreams(0);

Diff for: unified-runtime/source/adapters/hip/command_buffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
3333
/// all the memory objects allocated for command_buffer managment
3434
ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
3535
// Release the memory allocated to the Context stored in the command_buffer
36-
UR_TRACE(urContextRelease(Context));
36+
UR_CALL_NOCHECK(urContextRelease(Context));
3737

3838
// Release the device
39-
UR_TRACE(urDeviceRelease(Device));
39+
UR_CALL_NOCHECK(urDeviceRelease(Device));
4040

4141
// Release the memory allocated to the HIPGraph
4242
(void)hipGraphDestroy(HIPGraph);

Diff for: unified-runtime/source/adapters/hip/command_buffer.hpp

-17
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@
1717
#include <memory>
1818
#include <unordered_set>
1919

20-
// Trace an internal UR call
21-
#define UR_TRACE(Call) \
22-
{ \
23-
ur_result_t Result; \
24-
UR_CALL(Call, Result); \
25-
}
26-
27-
// Trace an internal UR call and return the result to the user.
28-
#define UR_CALL(Call, Result) \
29-
{ \
30-
if (PrintTrace) \
31-
std::cerr << "UR ---> " << #Call << "\n"; \
32-
Result = (Call); \
33-
if (PrintTrace) \
34-
std::cerr << "UR <--- " << #Call << "(" << Result << ")\n"; \
35-
}
36-
3720
// Handle to a kernel command.
3821
//
3922
// Struct that stores all the information related to a kernel command in a

Diff for: unified-runtime/source/adapters/hip/common.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ hipError_t getHipVersionString(std::string &Version) {
156156
return Result;
157157
}
158158

159-
void detail::ur::die(const char *pMessage) {
160-
logger::always("ur_die: {}", pMessage);
161-
std::terminate();
162-
}
163-
164159
void detail::ur::assertion(bool Condition, const char *pMessage) {
165160
if (!Condition)
166161
die(pMessage);

Diff for: unified-runtime/source/adapters/hip/common.hpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ extern thread_local char ErrorMessage[MaxMessageSize];
117117
namespace detail {
118118
namespace ur {
119119

120-
// Report error and no return (keeps compiler from printing warnings).
121-
// TODO: Probably change that to throw a catchable exception,
122-
// but for now it is useful to see every failure.
123-
//
124-
[[noreturn]] void die(const char *pMessage);
125-
126120
// Reports error messages
127121
void hipPrint(const char *pMessage);
128122

@@ -187,7 +181,7 @@ template <typename T> class ReleaseGuard {
187181
// HIP error for which it is unclear if the function that reported it
188182
// succeeded or not. Either way, the state of the program is compromised
189183
// and likely unrecoverable.
190-
detail::ur::die("Unrecoverable program state reached in piMemRelease");
184+
die("Unrecoverable program state reached in piMemRelease");
191185
}
192186
}
193187
}

Diff for: unified-runtime/source/adapters/hip/event.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ ur_result_t ur_event_handle_t_::record() {
107107
try {
108108
EventId = Queue->getNextEventId();
109109
if (EventId == 0) {
110-
detail::ur::die(
111-
"Unrecoverable program state reached in event identifier overflow");
110+
die("Unrecoverable program state reached in event identifier overflow");
112111
}
113112
UR_CHECK_ERROR(hipEventRecord(EvEnd, Stream));
114113
Result = UR_RESULT_SUCCESS;

Diff for: unified-runtime/source/adapters/hip/kernel.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ urKernelSetArgMemObj(ur_kernel_handle_t hKernel, uint32_t argIndex,
328328
if (Format != HIP_AD_FORMAT_UNSIGNED_INT32 &&
329329
Format != HIP_AD_FORMAT_SIGNED_INT32 &&
330330
Format != HIP_AD_FORMAT_HALF && Format != HIP_AD_FORMAT_FLOAT) {
331-
detail::ur::die(
332-
"UR HIP kernels only support images with channel types int32, "
331+
die("UR HIP kernels only support images with channel types int32, "
333332
"uint32, float, and half.");
334333
}
335334
hipSurfaceObject_t hipSurf =

Diff for: unified-runtime/source/adapters/hip/memory.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ size_t imageElementByteSize(hipArray_Format ArrayFormat) {
2828
case HIP_AD_FORMAT_FLOAT:
2929
return 4;
3030
default:
31-
detail::ur::die("Invalid HIP format specifier");
31+
die("Invalid HIP format specifier");
3232
}
3333
return 0;
3434
}
@@ -82,7 +82,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) {
8282
// error for which it is unclear if the function that reported it succeeded
8383
// or not. Either way, the state of the program is compromised and likely
8484
// unrecoverable.
85-
detail::ur::die("Unrecoverable program state reached in urMemRelease");
85+
die("Unrecoverable program state reached in urMemRelease");
8686
}
8787

8888
return UR_RESULT_SUCCESS;
@@ -441,7 +441,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory,
441441
return UR_IMAGE_CHANNEL_TYPE_FLOAT;
442442

443443
default:
444-
detail::ur::die("Invalid Hip format specified.");
444+
die("Invalid Hip format specified.");
445445
}
446446
};
447447

Diff for: unified-runtime/source/adapters/hip/memory.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ struct SurfaceMem {
249249
break;
250250
default:
251251
// urMemImageCreate given unsupported image_channel_data_type
252-
detail::ur::die("Bad image format given to ur_image_ constructor");
252+
die("Bad image format given to ur_image_ constructor");
253253
}
254254
}
255255

Diff for: unified-runtime/source/adapters/hip/program.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ ur_result_t ur_program_handle_t_::getGlobalVariablePointer(
266266
UR_APIEXPORT ur_result_t UR_APICALL
267267
urProgramCreateWithIL(ur_context_handle_t, const void *, size_t,
268268
const ur_program_properties_t *, ur_program_handle_t *) {
269-
detail::ur::die("urProgramCreateWithIL not implemented for HIP adapter"
270-
" please use urProgramCreateWithBinary instead");
269+
die("urProgramCreateWithIL not implemented for HIP adapter"
270+
" please use urProgramCreateWithBinary instead");
271271
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
272272
}
273273

Diff for: unified-runtime/source/adapters/hip/queue.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
313313
else if (HIPFlags == hipStreamNonBlocking)
314314
Flags = UR_QUEUE_FLAG_SYNC_WITH_DEFAULT_STREAM;
315315
else
316-
detail::ur::die("Unknown hip stream");
316+
die("Unknown hip stream");
317317

318318
std::vector<hipStream_t> ComputeHIPStreams(1, HIPStream);
319319
std::vector<hipStream_t> TransferHIPStreams(0);

0 commit comments

Comments
 (0)