Skip to content

Commit

Permalink
[UR][L0] Add support for urAdapterGetLastError in L0
Browse files Browse the repository at this point in the history
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
  • Loading branch information
Jaime Arteaga committed Nov 2, 2023
1 parent be53fb3 commit 60859e6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
11 changes: 5 additions & 6 deletions source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) {
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
ur_adapter_handle_t Adapter, ///< [in] handle of the platform instance
ur_adapter_handle_t AdapterHandle, ///< [in] handle of the platform instance
const char **Message, ///< [out] pointer to a C string where the adapter
///< specific error message will be stored.
int32_t *Error ///< [out] pointer to an integer where the adapter specific
///< error code will be stored.
) {
std::ignore = Adapter;
std::ignore = Message;
std::ignore = Error;
urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
AdapterHandle = &Adapter;
*Message = ErrorMessage;
Error = &ErrorAdapterNativeCode;
return ErrorMessageCode;
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
Expand Down
13 changes: 8 additions & 5 deletions source/adapters/level_zero/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,16 @@ template <> zes_structure_type_t getZesStructureType<zes_mem_properties_t>() {
// Global variables for ZER_EXT_RESULT_ADAPTER_SPECIFIC_ERROR
thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS;
thread_local char ErrorMessage[MaxMessageSize];
thread_local int32_t ErrorAdapterNativeCode;

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *message,
ur_result_t error_code) {
assert(strlen(message) <= MaxMessageSize);
strcpy(ErrorMessage, message);
ErrorMessageCode = error_code;
[[maybe_unused]] void setErrorMessage(const char *pMessage,
ur_result_t ErrorCode,
int32_t AdapterErrorCode) {
assert(strlen(pMessage) <= MaxMessageSize);
strcpy(ErrorMessage, pMessage);
ErrorMessageCode = ErrorCode;
ErrorAdapterNativeCode = AdapterErrorCode;
}

ur_result_t zerPluginGetLastError(char **message) {
Expand Down
6 changes: 4 additions & 2 deletions source/adapters/level_zero/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ constexpr char ZE_SUPPORTED_EXTENSIONS[] =
constexpr size_t MaxMessageSize = 256;
extern thread_local ur_result_t ErrorMessageCode;
extern thread_local char ErrorMessage[MaxMessageSize];
extern thread_local int32_t ErrorAdapterNativeCode;

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *message,
ur_result_t error_code);
[[maybe_unused]] void setErrorMessage(const char *pMessage,
ur_result_t ErrorCode,
int32_t AdapterErrorCode);
3 changes: 2 additions & 1 deletion source/adapters/level_zero/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
case UR_DEVICE_INFO_GLOBAL_MEM_FREE: {
if (getenv("ZES_ENABLE_SYSMAN") == nullptr) {
setErrorMessage("Set ZES_ENABLE_SYSMAN=1 to obtain free memory",
UR_RESULT_SUCCESS);
UR_RESULT_ERROR_UNINITIALIZED,
static_cast<int32_t>(ZE_RESULT_ERROR_UNINITIALIZED));
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
}
// Only report device memory which zeMemAllocDevice can allocate from.
Expand Down
10 changes: 6 additions & 4 deletions source/adapters/level_zero/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite(
(Program->ZeModule, Name, &GlobalVarSize, &GlobalVarPtr));
if (GlobalVarSize < Offset + Count) {
setErrorMessage("Write device global variable is out of range.",
UR_RESULT_ERROR_INVALID_VALUE);
return UR_RESULT_ERROR_UNKNOWN;
UR_RESULT_ERROR_INVALID_VALUE,
static_cast<int32_t>(ZE_RESULT_ERROR_INVALID_ARGUMENT));
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
}

// Copy engine is preferred only for host to device transfer.
Expand Down Expand Up @@ -333,8 +334,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead(
(Program->ZeModule, Name, &GlobalVarSize, &GlobalVarPtr));
if (GlobalVarSize < Offset + Count) {
setErrorMessage("Read from device global variable is out of range.",
UR_RESULT_ERROR_INVALID_VALUE);
return UR_RESULT_ERROR_UNKNOWN;
UR_RESULT_ERROR_INVALID_VALUE,
static_cast<int32_t>(ZE_RESULT_ERROR_INVALID_ARGUMENT));
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
}

// Copy engine is preferred only for host to device transfer.
Expand Down

0 comments on commit 60859e6

Please sign in to comment.