Skip to content

[SYCL][UR] Update setErrorMessage to use int32_t instead of ur_result_t for the urAdapterGetLastError entry point #18264

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

Open
wants to merge 3 commits into
base: sycl
Choose a base branch
from
Open
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
12 changes: 1 addition & 11 deletions sycl/source/detail/adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,7 @@ class Adapter {
int32_t adapter_error = 0;
ur_result = call_nocheck<UrApiKind::urAdapterGetLastError>(
MAdapter, &message, &adapter_error);

// If the warning level is greater then 2 emit the message
if (message != nullptr &&
detail::SYCLConfig<detail::SYCL_RT_WARNING_LEVEL>::get() >= 2) {
std::clog << message << std::endl;
}

// If it is a warning do not throw code
if (ur_result == UR_RESULT_SUCCESS) {
return;
}
std::cerr << message << " (error code " << adapter_error << ")\n";
}
if (ur_result != UR_RESULT_SUCCESS) {
throw sycl::detail::set_ur_error(
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/interop_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ur_native_handle_t interop_handle::getNativeGraph() const {
}

auto Adapter = MQueue->getAdapter();
ur_native_handle_t Handle;
ur_native_handle_t Handle = 0;
Adapter->call<detail::UrApiKind::urCommandBufferGetNativeHandleExp>(Graph,
&Handle);
return Handle;
Expand Down
5 changes: 3 additions & 2 deletions unified-runtime/source/adapters/cuda/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterRelease(ur_adapter_handle_t) {
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
ur_adapter_handle_t, const char **ppMessage, int32_t * /*pError*/) {
ur_adapter_handle_t, const char **ppMessage, int32_t *pError) {
*ppMessage = ErrorMessage;
return ErrorMessageCode;
*pError = ErrorMessageCode;
return UR_RESULT_SUCCESS;
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
Expand Down
5 changes: 2 additions & 3 deletions unified-runtime/source/adapters/cuda/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,11 @@ std::string getCudaVersionString() {
}

// Global variables for ZER_EXT_RESULT_ADAPTER_SPECIFIC_ERROR
thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS;
thread_local int32_t ErrorMessageCode = UR_RESULT_SUCCESS;
thread_local char ErrorMessage[MaxMessageSize]{};

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *pMessage,
ur_result_t ErrorCode) {
[[maybe_unused]] void setErrorMessage(const char *pMessage, int32_t ErrorCode) {
assert(strlen(pMessage) < MaxMessageSize);
// Copy at most MaxMessageSize - 1 bytes to ensure the resultant string is
// always null terminated.
Expand Down
5 changes: 2 additions & 3 deletions unified-runtime/source/adapters/cuda/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ void checkErrorUR(ur_result_t Result, const char *Function, int Line,
std::string getCudaVersionString();

constexpr size_t MaxMessageSize = 256;
extern thread_local ur_result_t ErrorMessageCode;
extern thread_local int32_t ErrorMessageCode;
extern thread_local char ErrorMessage[MaxMessageSize];

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *pMessage,
ur_result_t ErrorCode);
[[maybe_unused]] void setErrorMessage(const char *pMessage, int32_t ErrorCode);

void setPluginSpecificMessage(CUresult cu_res);

Expand Down
12 changes: 2 additions & 10 deletions unified-runtime/source/adapters/hip/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,14 @@ hipError_t getHipVersionString(std::string &Version) {
}

// Global variables for UR_RESULT_ADAPTER_SPECIFIC_ERROR
thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS;
thread_local int32_t ErrorMessageCode = UR_RESULT_SUCCESS;
thread_local char ErrorMessage[MaxMessageSize]{};

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *pMessage,
ur_result_t ErrorCode) {
[[maybe_unused]] void setErrorMessage(const char *pMessage, int32_t ErrorCode) {
assert(strlen(pMessage) < MaxMessageSize);
// Copy at most MaxMessageSize - 1 bytes to ensure the resultant string is
// always null terminated.
strncpy(ErrorMessage, pMessage, MaxMessageSize - 1);
ErrorMessageCode = ErrorCode;
}

// Returns plugin specific error and warning messages; common implementation
// that can be shared between adapters
ur_result_t urGetLastResult(ur_platform_handle_t, const char **ppMessage) {
*ppMessage = &ErrorMessage[0];
return ErrorMessageCode;
}
5 changes: 2 additions & 3 deletions unified-runtime/source/adapters/hip/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ void checkErrorUR(ur_result_t Result, const char *Function, int Line,
hipError_t getHipVersionString(std::string &Version);

constexpr size_t MaxMessageSize = 256;
extern thread_local ur_result_t ErrorMessageCode;
extern thread_local int32_t ErrorMessageCode;
extern thread_local char ErrorMessage[MaxMessageSize];

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *Message,
ur_result_t ErrorCode);
[[maybe_unused]] void setErrorMessage(const char *Message, int32_t ErrorCode);

/// ------ Error handling, matching OpenCL plugin semantics.
namespace detail {
Expand Down
11 changes: 2 additions & 9 deletions unified-runtime/source/adapters/native_cpu/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,14 @@
#include "common.hpp"

// Global variables for UR_RESULT_ADAPTER_SPECIFIC_ERROR
// See urGetLastResult
thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS;
thread_local int32_t ErrorMessageCode;
thread_local char ErrorMessage[MaxMessageSize]{};

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *pMessage,
ur_result_t ErrorCode) {
[[maybe_unused]] void setErrorMessage(const char *pMessage, int32_t ErrorCode) {
assert(strlen(pMessage) < MaxMessageSize);
// Copy at most MaxMessageSize - 1 bytes to ensure the resultant string is
// always null terminated.
strncpy(ErrorMessage, pMessage, MaxMessageSize - 1);
ErrorMessageCode = ErrorCode;
}

ur_result_t urGetLastResult(ur_platform_handle_t, const char **ppMessage) {
*ppMessage = &ErrorMessage[0];
return ErrorMessageCode;
}
2 changes: 1 addition & 1 deletion unified-runtime/source/adapters/native_cpu/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

constexpr size_t MaxMessageSize = 256;

extern thread_local ur_result_t ErrorMessageCode;
extern thread_local int32_t ErrorMessageCode;
extern thread_local char ErrorMessage[MaxMessageSize];

#define DIE_NO_IMPLEMENTATION \
Expand Down
9 changes: 9 additions & 0 deletions unified-runtime/source/adapters/opencl/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ namespace cl_adapter {
thread_local int32_t ErrorMessageCode = 0;
thread_local char ErrorMessage[MaxMessageSize]{};

[[maybe_unused]] void setErrorMessage(const char *Message, int32_t ErrorCode) {
assert(strlen(Message) < cl_adapter::MaxMessageSize);
// Copy at most MaxMessageSize - 1 bytes to ensure the resultant string is
// always null terminated.
strncpy(cl_adapter::ErrorMessage, Message, MaxMessageSize - 1);

ErrorMessageCode = ErrorCode;
}

} // namespace cl_adapter

ur_result_t mapCLErrorToUR(cl_int Result) {
Expand Down
3 changes: 1 addition & 2 deletions unified-runtime/source/adapters/opencl/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ extern thread_local int32_t ErrorMessageCode;
extern thread_local char ErrorMessage[MaxMessageSize];

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *Message,
ur_result_t ErrorCode);
[[maybe_unused]] void setErrorMessage(const char *Message, int32_t ErrorCode);
} // namespace cl_adapter

namespace cl_ext {
Expand Down