Skip to content

Commit ce39639

Browse files
committed
Rework Offload API errors
1 parent 3fc3b50 commit ce39639

21 files changed

+380
-352
lines changed

offload/new-api/API/APIDefs.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ class AddHandleChecksToReturns<list<Param> Params, list<Return> Returns> {
106106
// Does the list of returns already contain ERROR_INVALID_NULL_HANDLE?
107107
bit returns_has_inv_handle = !foldl(
108108
0, Returns, HasErr, Ret,
109-
!or(HasErr, !eq(Ret.value, PREFIX#"_RESULT_ERROR_INVALID_NULL_HANDLE")));
109+
!or(HasErr, !eq(Ret.value, PREFIX#"_ERRC_INVALID_NULL_HANDLE")));
110110

111111
list<Return> returns_out = !if(returns_has_inv_handle,
112-
AppendConditionsToReturn<Returns, PREFIX # "_RESULT_ERROR_INVALID_NULL_HANDLE", handle_param_conds>.ret,
113-
!listconcat(Returns, [Return<PREFIX # "_RESULT_ERROR_INVALID_NULL_HANDLE", handle_param_conds>])
112+
AppendConditionsToReturn<Returns, PREFIX # "_ERRC_INVALID_NULL_HANDLE", handle_param_conds>.ret,
113+
!listconcat(Returns, [Return<PREFIX # "_ERRC_INVALID_NULL_HANDLE", handle_param_conds>])
114114
);
115115
}
116116

@@ -125,10 +125,10 @@ class AddPointerChecksToReturns<list<Param> Params, list<Return> Returns> {
125125
// Does the list of returns already contain ERROR_INVALID_NULL_POINTER?
126126
bit returns_has_inv_ptr = !foldl(
127127
0, Returns, HasErr, Ret,
128-
!or(HasErr, !eq(Ret.value, PREFIX#"_RESULT_ERROR_INVALID_NULL_POINTER")));
128+
!or(HasErr, !eq(Ret.value, PREFIX#"_ERROR_CODE_INVALID_NULL_POINTER")));
129129
list<Return> returns_out = !if(returns_has_inv_ptr,
130-
AppendConditionsToReturn<Returns, PREFIX # "_RESULT_ERROR_INVALID_NULL_POINTER", ptr_param_conds>.ret,
131-
!listconcat(Returns, [Return<PREFIX # "_RESULT_ERROR_INVALID_NULL_POINTER", ptr_param_conds>])
130+
AppendConditionsToReturn<Returns, PREFIX # "_ERROR_CODE_INVALID_NULL_POINTER", ptr_param_conds>.ret,
131+
!listconcat(Returns, [Return<PREFIX # "_ERROR_CODE_INVALID_NULL_POINTER", ptr_param_conds>])
132132
);
133133
}
134134

offload/new-api/API/Common.td

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,47 @@ def : Handle {
4545
}
4646

4747
def : Enum {
48-
let name = "offload_result_t";
48+
let name = "offload_errc_t";
4949
let desc = "Defines Return/Error codes";
5050
let etors =[
5151
Etor<"SUCCESS", "Success">,
52-
Etor<"ERROR_INVALID_VALUE", "Invalid Value">,
53-
Etor<"ERROR_INVALID_PLATFORM", "Invalid platform">,
54-
Etor<"ERROR_DEVICE_NOT_FOUND", "Device not found">,
55-
Etor<"ERROR_INVALID_DEVICE", "Invalid device">,
56-
Etor<"ERROR_DEVICE_LOST", "Device hung, reset, was removed, or driver update occurred">,
57-
Etor<"ERROR_UNINITIALIZED", "plugin is not initialized or specific entry-point is not implemented">,
58-
Etor<"ERROR_OUT_OF_RESOURCES", "Out of resources">,
59-
Etor<"ERROR_UNSUPPORTED_VERSION", "generic error code for unsupported versions">,
60-
Etor<"ERROR_UNSUPPORTED_FEATURE", "generic error code for unsupported features">,
61-
Etor<"ERROR_INVALID_ARGUMENT", "generic error code for invalid arguments">,
62-
Etor<"ERROR_INVALID_NULL_HANDLE", "handle argument is not valid">,
63-
Etor<"ERROR_INVALID_NULL_POINTER", "pointer argument may not be nullptr">,
64-
Etor<"ERROR_INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">,
65-
Etor<"ERROR_INVALID_ENUMERATION", "enumerator argument is not valid">,
66-
Etor<"ERROR_UNSUPPORTED_ENUMERATION", "enumerator argument is not supported by the device">,
67-
Etor<"ERROR_UNKNOWN", "Unknown or internal error">
52+
Etor<"INVALID_VALUE", "Invalid Value">,
53+
Etor<"INVALID_PLATFORM", "Invalid platform">,
54+
Etor<"DEVICE_NOT_FOUND", "Device not found">,
55+
Etor<"INVALID_DEVICE", "Invalid device">,
56+
Etor<"DEVICE_LOST", "Device hung, reset, was removed, or driver update occurred">,
57+
Etor<"UNINITIALIZED", "plugin is not initialized or specific entry-point is not implemented">,
58+
Etor<"OUT_OF_RESOURCES", "Out of resources">,
59+
Etor<"UNSUPPORTED_VERSION", "generic error code for unsupported versions">,
60+
Etor<"UNSUPPORTED_FEATURE", "generic error code for unsupported features">,
61+
Etor<"INVALID_ARGUMENT", "generic error code for invalid arguments">,
62+
Etor<"INVALID_NULL_HANDLE", "handle argument is not valid">,
63+
Etor<"INVALID_NULL_POINTER", "pointer argument may not be nullptr">,
64+
Etor<"INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">,
65+
Etor<"INVALID_ENUMERATION", "enumerator argument is not valid">,
66+
Etor<"UNSUPPORTED_ENUMERATION", "enumerator argument is not supported by the device">,
67+
Etor<"UNKNOWN", "Unknown or internal error">
6868
];
6969
}
7070

71-
def : Function {
72-
let name = "offloadGetErrorDetails";
73-
let desc = "Get a detailed error message for the last error that occurred on this thread, if it exists";
74-
let details = [
75-
"When an Offload API call returns a return value other than OFFLOAD_RESULT_SUCCESS, the implementation *may* set an additional error message.",
76-
"If a further Offload call (excluding this function) is made on the same thread without checking "
77-
"its detailed error message with this function, that message should be considered lost.",
78-
"The returned char* is only valid until the next Offload function call on the same thread (excluding further calls to this function.)"
79-
];
80-
let params = [
81-
Param<"size_t*", "SizeRet", "Pointer to return the size of the available error message. A size of 0 indicates no message.", PARAM_OUT_OPTIONAL>,
82-
Param<"const char**", "DetailStringRet", "Pointer to return the error message string.", PARAM_OUT_OPTIONAL>
71+
def : Struct {
72+
let name = "offload_error_struct_t";
73+
let desc = "Details of the error condition returned by an API call";
74+
let members = [
75+
StructMember<"offload_errc_t", "code", "The error code">,
76+
StructMember<"const char*", "details", "String containing error details">
8377
];
84-
let returns = []; // Only SUCCESS is expected
78+
}
79+
80+
def : Typedef {
81+
let name = "offload_result_t";
82+
let desc = "Result type returned by all entry points.";
83+
let value = "const offload_error_struct_t*";
84+
}
85+
86+
def : Macro {
87+
let name = "OFFLOAD_SUCCESS";
88+
let condition = "!defined(OFFLOAD_SUCCESS)";
89+
let desc = "Success condition";
90+
let value = "NULL";
8591
}

offload/new-api/API/Device.td

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def : Function {
4747
Param<"offload_platform_handle_t", "hPlatform", "handle of the platform instance", PARAM_IN>,
4848
Param<"offload_device_type_t", "DeviceType", "the type of the devices.", PARAM_IN>,
4949
Param<"uint32_t", "NumEntries", "the number of devices to be added to phDevices. "
50-
"If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZE "
50+
"If phDevices is not NULL, then NumEntries should be greater than zero. Otherwise OFFLOAD_ERRC_INVALID_SIZE "
5151
"will be returned.", PARAM_IN>,
5252
RangedParam<"offload_device_handle_t*", "phDevices", "Array of device handles. "
5353
"If NumEntries is less than the number of devices available, then platform shall only retrieve that number of devices.", PARAM_OUT_OPTIONAL,
@@ -56,13 +56,13 @@ def : Function {
5656
"pNumDevices will be updated with the total number of devices available.", PARAM_OUT_OPTIONAL>
5757
];
5858
let returns = [
59-
Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
59+
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
6060
"`NumEntries == 0 && phDevices != NULL`"
6161
]>,
62-
Return<"OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER", [
62+
Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
6363
"`NumEntries > 0 && phDevices == NULL`"
6464
]>,
65-
Return<"OFFLOAD_RESULT_ERROR_INVALID_VALUE">
65+
Return<"OFFLOAD_ERRC_INVALID_VALUE">
6666
];
6767
}
6868

@@ -78,24 +78,24 @@ def : Function {
7878
Param<"offload_device_info_t", "propName", "type of the info to retrieve", PARAM_IN>,
7979
Param<"size_t", "propSize", "the number of bytes pointed to by pPropValue.", PARAM_IN>,
8080
TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. If propSize is not equal to or greater than the real "
81-
"number of bytes needed to return the info then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and "
81+
"number of bytes needed to return the info then the OFFLOAD_ERRC_INVALID_SIZE error is returned and "
8282
"pPropValue is not used.", PARAM_OUT_OPTIONAL, TypeInfo<"propName" , "propSize">>,
8383
Param<"size_t*", "pPropSizeRet", "pointer to the actual size in bytes of the queried propName.", PARAM_OUT_OPTIONAL>
8484
];
8585
let returns = [
86-
Return<"OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION", [
86+
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
8787
"If `propName` is not supported by the adapter."
8888
]>,
89-
Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
89+
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
9090
"`propSize == 0 && pPropValue != NULL`",
9191
"If `propSize` is less than the real number of bytes needed to return the info."
9292
]>,
93-
Return<"OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER", [
93+
Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
9494
"`propSize != 0 && pPropValue == NULL`",
9595
"`pPropValue == NULL && pPropSizeRet == NULL`"
9696
]>,
97-
Return<"OFFLOAD_RESULT_ERROR_INVALID_DEVICE">,
98-
Return<"OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES">,
99-
Return<"OFFLOAD_RESULT_ERROR_OUT_OF_HOST_MEMORY">
97+
Return<"OFFLOAD_ERRC_INVALID_DEVICE">,
98+
Return<"OFFLOAD_ERRC_OUT_OF_RESOURCES">,
99+
Return<"OFFLOAD_ERRC_OUT_OF_HOST_MEMORY">
100100
];
101101
}

offload/new-api/API/Platform.td

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def : Function {
1818
let params = [
1919
Param<"uint32_t", "NumEntries",
2020
"The number of platforms to be added to phPlatforms. If phPlatforms is not NULL, then "
21-
"NumEntries should be greater than zero, otherwise OFFLOAD_RESULT_ERROR_INVALID_SIZE "
21+
"NumEntries should be greater than zero, otherwise OFFLOAD_ERRC_INVALID_SIZE "
2222
"will be returned.", PARAM_IN>,
2323
RangedParam<"offload_platform_handle_t*", "phPlatforms",
2424
"Array of handle of platforms. If NumEntries is less than the number of "
@@ -30,7 +30,7 @@ def : Function {
3030
PARAM_OUT_OPTIONAL>
3131
];
3232
let returns = [
33-
Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
33+
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
3434
"`NumEntries == 0 && phPlatforms != NULL`"
3535
]>
3636
];
@@ -71,24 +71,24 @@ def : Function {
7171
Param<"size_t", "propSize", "the number of bytes pointed to by pPlatformInfo.", PARAM_IN>,
7272
TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. "
7373
"If Size is not equal to or greater to the real number of bytes needed to return the info "
74-
"then the OFFLOAD_RESULT_ERROR_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT_OPTIONAL,
74+
"then the OFFLOAD_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT_OPTIONAL,
7575
TypeInfo<"propName" , "propSize">>,
7676
Param<"size_t*", "pPropSizeRet", "pointer to the actual number of bytes being queried by pPlatformInfo.", PARAM_OUT_OPTIONAL>
7777
];
7878
let returns = [
79-
Return<"OFFLOAD_RESULT_ERROR_UNSUPPORTED_ENUMERATION", [
79+
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
8080
"If `propName` is not supported by the platform."
8181
]>,
82-
Return<"OFFLOAD_RESULT_ERROR_INVALID_SIZE", [
82+
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
8383
"`propSize == 0 && pPropValue != NULL`",
8484
"If `propSize` is less than the real number of bytes needed to return the info."
8585
]>,
86-
Return<"OFFLOAD_RESULT_ERROR_INVALID_NULL_POINTER", [
86+
Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
8787
"`propSize != 0 && pPropValue == NULL`",
8888
"`pPropValue == NULL && pPropSizeRet == NULL`"
8989
]>,
90-
Return<"OFFLOAD_RESULT_ERROR_INVALID_PLATFORM">,
91-
Return<"OFFLOAD_RESULT_ERROR_OUT_OF_RESOURCES">,
92-
Return<"OFFLOAD_RESULT_ERROR_OUT_OF_HOST_MEMORY">
90+
Return<"OFFLOAD_ERRC_INVALID_PLATFORM">,
91+
Return<"OFFLOAD_ERRC_OUT_OF_RESOURCES">,
92+
Return<"OFFLOAD_ERRC_OUT_OF_HOST_MEMORY">
9393
];
9494
}

0 commit comments

Comments
 (0)