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

unified-runtime/source/adapters/cuda/command_buffer.cpp

Lines changed: 2 additions & 2 deletions
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

unified-runtime/source/adapters/cuda/command_buffer.hpp

Lines changed: 0 additions & 17 deletions
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,

unified-runtime/source/adapters/cuda/common.cpp

Lines changed: 0 additions & 5 deletions
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);

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

Lines changed: 0 additions & 6 deletions
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

unified-runtime/source/adapters/cuda/enqueue.cpp

Lines changed: 1 addition & 1 deletion
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
}

unified-runtime/source/adapters/cuda/event.cpp

Lines changed: 1 addition & 2 deletions
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) {

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

Lines changed: 1 addition & 1 deletion
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;

unified-runtime/source/adapters/cuda/queue.cpp

Lines changed: 1 addition & 1 deletion
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);

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

Lines changed: 2 additions & 2 deletions
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);

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

Lines changed: 0 additions & 17 deletions
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

0 commit comments

Comments
 (0)