Skip to content

[UR] Share generic error handling between adapters #17576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions unified-runtime/source/adapters/cuda/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
/// all the memory objects allocated for command_buffer managment
ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
// Release the memory allocated to the Context stored in the command_buffer
UR_TRACE(urContextRelease(Context));
UR_CALL_NOCHECK(urContextRelease(Context));

// Release the device
UR_TRACE(urDeviceRelease(Device));
UR_CALL_NOCHECK(urDeviceRelease(Device));
}

// This may throw so it must be called from within a try...catch
Expand Down
17 changes: 0 additions & 17 deletions unified-runtime/source/adapters/cuda/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,6 @@
#include <memory>
#include <unordered_set>

// Trace an internal UR call
#define UR_TRACE(Call) \
{ \
ur_result_t Result; \
UR_CALL(Call, Result); \
}

// Trace an internal UR call and return the result to the user.
#define UR_CALL(Call, Result) \
{ \
if (PrintTrace) \
logger::always("UR ---> {}", #Call); \
Result = (Call); \
if (PrintTrace) \
logger::always("UR <--- {}({})", #Call, Result); \
}

enum class CommandType {
Kernel,
USMMemcpy,
Expand Down
5 changes: 0 additions & 5 deletions unified-runtime/source/adapters/cuda/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ std::string getCudaVersionString() {
return stream.str();
}

void detail::ur::die(const char *Message) {
logger::always("ur_die:{}", Message);
std::terminate();
}

void detail::ur::assertion(bool Condition, const char *Message) {
if (!Condition)
die(Message);
Expand Down
6 changes: 0 additions & 6 deletions unified-runtime/source/adapters/cuda/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ void setPluginSpecificMessage(CUresult cu_res);
namespace detail {
namespace ur {

// Report error and no return (keeps compiler from printing warnings).
// TODO: Probably change that to throw a catchable exception,
// but for now it is useful to see every failure.
//
[[noreturn]] void die(const char *Message);

// Reports error messages
void cuPrint(const char *Message);

Expand Down
2 changes: 1 addition & 1 deletion unified-runtime/source/adapters/cuda/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ static size_t imageElementByteSize(CUDA_ARRAY_DESCRIPTOR ArrayDesc) {
case CU_AD_FORMAT_FLOAT:
return 4;
default:
detail::ur::die("Invalid image format.");
die("Invalid image format.");
return 0;
}
}
Expand Down
3 changes: 1 addition & 2 deletions unified-runtime/source/adapters/cuda/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ ur_result_t ur_event_handle_t_::record() {
try {
EventID = Queue->getNextEventID();
if (EventID == 0) {
detail::ur::die(
"Unrecoverable program state reached in event identifier overflow");
die("Unrecoverable program state reached in event identifier overflow");
}
UR_CHECK_ERROR(cuEventRecord(EvEnd, Stream));
} catch (ur_result_t error) {
Expand Down
2 changes: 1 addition & 1 deletion unified-runtime/source/adapters/cuda/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) {
// error for which it is unclear if the function that reported it succeeded
// or not. Either way, the state of the program is compromised and likely
// unrecoverable.
detail::ur::die("Unrecoverable program state reached in urMemRelease");
die("Unrecoverable program state reached in urMemRelease");
}

return UR_RESULT_SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion unified-runtime/source/adapters/cuda/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
else if (CuFlags == CU_STREAM_NON_BLOCKING)
Flags = UR_QUEUE_FLAG_SYNC_WITH_DEFAULT_STREAM;
else
detail::ur::die("Unknown cuda stream");
die("Unknown cuda stream");

std::vector<CUstream> ComputeCuStreams(1, CuStream);
std::vector<CUstream> TransferCuStreams(0);
Expand Down
4 changes: 2 additions & 2 deletions unified-runtime/source/adapters/hip/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
/// all the memory objects allocated for command_buffer managment
ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
// Release the memory allocated to the Context stored in the command_buffer
UR_TRACE(urContextRelease(Context));
UR_CALL_NOCHECK(urContextRelease(Context));

// Release the device
UR_TRACE(urDeviceRelease(Device));
UR_CALL_NOCHECK(urDeviceRelease(Device));

// Release the memory allocated to the HIPGraph
(void)hipGraphDestroy(HIPGraph);
Expand Down
17 changes: 0 additions & 17 deletions unified-runtime/source/adapters/hip/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,6 @@
#include <memory>
#include <unordered_set>

// Trace an internal UR call
#define UR_TRACE(Call) \
{ \
ur_result_t Result; \
UR_CALL(Call, Result); \
}

// Trace an internal UR call and return the result to the user.
#define UR_CALL(Call, Result) \
{ \
if (PrintTrace) \
std::cerr << "UR ---> " << #Call << "\n"; \
Result = (Call); \
if (PrintTrace) \
std::cerr << "UR <--- " << #Call << "(" << Result << ")\n"; \
}

// Handle to a kernel command.
//
// Struct that stores all the information related to a kernel command in a
Expand Down
5 changes: 0 additions & 5 deletions unified-runtime/source/adapters/hip/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ hipError_t getHipVersionString(std::string &Version) {
return Result;
}

void detail::ur::die(const char *pMessage) {
logger::always("ur_die: {}", pMessage);
std::terminate();
}

void detail::ur::assertion(bool Condition, const char *pMessage) {
if (!Condition)
die(pMessage);
Expand Down
8 changes: 1 addition & 7 deletions unified-runtime/source/adapters/hip/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ extern thread_local char ErrorMessage[MaxMessageSize];
namespace detail {
namespace ur {

// Report error and no return (keeps compiler from printing warnings).
// TODO: Probably change that to throw a catchable exception,
// but for now it is useful to see every failure.
//
[[noreturn]] void die(const char *pMessage);

// Reports error messages
void hipPrint(const char *pMessage);

Expand Down Expand Up @@ -187,7 +181,7 @@ template <typename T> class ReleaseGuard {
// HIP error for which it is unclear if the function that reported it
// succeeded or not. Either way, the state of the program is compromised
// and likely unrecoverable.
detail::ur::die("Unrecoverable program state reached in piMemRelease");
die("Unrecoverable program state reached in piMemRelease");
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions unified-runtime/source/adapters/hip/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ ur_result_t ur_event_handle_t_::record() {
try {
EventId = Queue->getNextEventId();
if (EventId == 0) {
detail::ur::die(
"Unrecoverable program state reached in event identifier overflow");
die("Unrecoverable program state reached in event identifier overflow");
}
UR_CHECK_ERROR(hipEventRecord(EvEnd, Stream));
Result = UR_RESULT_SUCCESS;
Expand Down
3 changes: 1 addition & 2 deletions unified-runtime/source/adapters/hip/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ urKernelSetArgMemObj(ur_kernel_handle_t hKernel, uint32_t argIndex,
if (Format != HIP_AD_FORMAT_UNSIGNED_INT32 &&
Format != HIP_AD_FORMAT_SIGNED_INT32 &&
Format != HIP_AD_FORMAT_HALF && Format != HIP_AD_FORMAT_FLOAT) {
detail::ur::die(
"UR HIP kernels only support images with channel types int32, "
die("UR HIP kernels only support images with channel types int32, "
"uint32, float, and half.");
}
hipSurfaceObject_t hipSurf =
Expand Down
6 changes: 3 additions & 3 deletions unified-runtime/source/adapters/hip/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ size_t imageElementByteSize(hipArray_Format ArrayFormat) {
case HIP_AD_FORMAT_FLOAT:
return 4;
default:
detail::ur::die("Invalid HIP format specifier");
die("Invalid HIP format specifier");
}
return 0;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) {
// error for which it is unclear if the function that reported it succeeded
// or not. Either way, the state of the program is compromised and likely
// unrecoverable.
detail::ur::die("Unrecoverable program state reached in urMemRelease");
die("Unrecoverable program state reached in urMemRelease");
}

return UR_RESULT_SUCCESS;
Expand Down Expand Up @@ -441,7 +441,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory,
return UR_IMAGE_CHANNEL_TYPE_FLOAT;

default:
detail::ur::die("Invalid Hip format specified.");
die("Invalid Hip format specified.");
}
};

Expand Down
2 changes: 1 addition & 1 deletion unified-runtime/source/adapters/hip/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ struct SurfaceMem {
break;
default:
// urMemImageCreate given unsupported image_channel_data_type
detail::ur::die("Bad image format given to ur_image_ constructor");
die("Bad image format given to ur_image_ constructor");
}
}

Expand Down
4 changes: 2 additions & 2 deletions unified-runtime/source/adapters/hip/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ ur_result_t ur_program_handle_t_::getGlobalVariablePointer(
UR_APIEXPORT ur_result_t UR_APICALL
urProgramCreateWithIL(ur_context_handle_t, const void *, size_t,
const ur_program_properties_t *, ur_program_handle_t *) {
detail::ur::die("urProgramCreateWithIL not implemented for HIP adapter"
" please use urProgramCreateWithBinary instead");
die("urProgramCreateWithIL not implemented for HIP adapter"
" please use urProgramCreateWithBinary instead");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

Expand Down
2 changes: 1 addition & 1 deletion unified-runtime/source/adapters/hip/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle(
else if (HIPFlags == hipStreamNonBlocking)
Flags = UR_QUEUE_FLAG_SYNC_WITH_DEFAULT_STREAM;
else
detail::ur::die("Unknown hip stream");
die("Unknown hip stream");

std::vector<hipStream_t> ComputeHIPStreams(1, HIPStream);
std::vector<hipStream_t> TransferHIPStreams(0);
Expand Down
Loading