Skip to content

Commit 78df0dc

Browse files
committed
Rework API to avoid multiple returns, add init/shutdown, general refactor
1 parent be7e5c0 commit 78df0dc

29 files changed

+1118
-386
lines changed

offload/new-api/API/APIDefs.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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#"_ERROR_CODE_INVALID_NULL_POINTER")));
128+
!or(HasErr, !eq(Ret.value, PREFIX#"_ERRC_INVALID_NULL_POINTER")));
129129
list<Return> returns_out = !if(returns_has_inv_ptr,
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>])
130+
AppendConditionsToReturn<Returns, PREFIX # "_ERRC_INVALID_NULL_POINTER", ptr_param_conds>.ret,
131+
!listconcat(Returns, [Return<PREFIX # "_ERRC_INVALID_NULL_POINTER", ptr_param_conds>])
132132
);
133133
}
134134

offload/new-api/API/Common.td

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ def : Typedef {
8484
}
8585

8686
def : Macro {
87-
let name = "OFFLOAD_SUCCESS";
88-
let condition = "!defined(OFFLOAD_SUCCESS)";
87+
let name = "OFFLOAD_RESULT_SUCCESS";
8988
let desc = "Success condition";
9089
let value = "NULL";
9190
}
@@ -100,3 +99,25 @@ def : Struct {
10099
StructMember<"uint32_t", "ColumnNumber", "Source code column number">
101100
];
102101
}
102+
103+
def : Function {
104+
let name = "offloadInit";
105+
let desc = "Perform initialization of the Offload library and plugins";
106+
let details = [
107+
"This must be the first API call made by a user of the Offload library",
108+
"Each call will increment an internal reference count that is decremented by `offloadShutDown`"
109+
];
110+
let params = [];
111+
let returns = [];
112+
}
113+
114+
def : Function {
115+
let name = "offloadShutDown";
116+
let desc = "Release the resources in use by Offload";
117+
let details = [
118+
"This decrements an internal reference count. When this reaches 0, all resources will be released",
119+
"Subsequent API calls made after this are not valid"
120+
];
121+
let params = [];
122+
let returns = [];
123+
}

offload/new-api/API/Device.td

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,41 +34,40 @@ def : Enum {
3434
];
3535
}
3636

37+
def : Function {
38+
let name = "offloadDeviceGetCount";
39+
let desc = "Retrieves the number of available devices within a platform";
40+
let params = [
41+
Param<"offload_platform_handle_t", "hPlatform", "handle of the platform instance", PARAM_IN>,
42+
Param<"uint32_t*", "pNumDevices", "pointer to the number of devices.", PARAM_OUT>
43+
];
44+
let returns = [];
45+
}
46+
3747
def : Function {
3848
let name = "offloadDeviceGet";
3949
let desc = "Retrieves devices within a platform";
4050
let details = [
4151
"Multiple calls to this function will return identical device handles, in the same order.",
42-
"The number and order of handles returned from this function can be affected by environment variables that filter devices exposed through API.",
43-
"The returned devices are taken a reference of and must be released with a subsequent call to olDeviceRelease.",
4452
"The application may call this function from simultaneous threads, the implementation must be thread-safe"
4553
];
4654
let params = [
4755
Param<"offload_platform_handle_t", "hPlatform", "handle of the platform instance", PARAM_IN>,
48-
Param<"offload_device_type_t", "DeviceType", "the type of the devices.", PARAM_IN>,
49-
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_ERRC_INVALID_SIZE "
51-
"will be returned.", PARAM_IN>,
56+
Param<"uint32_t", "NumEntries", "the number of devices to be added to phDevices, which must be greater than zero", PARAM_IN>,
5257
RangedParam<"offload_device_handle_t*", "phDevices", "Array of device handles. "
53-
"If NumEntries is less than the number of devices available, then platform shall only retrieve that number of devices.", PARAM_OUT_OPTIONAL,
54-
Range<"0", "NumEntries">>,
55-
Param<"uint32_t*", "pNumDevices", "pointer to the number of devices. "
56-
"pNumDevices will be updated with the total number of devices available.", PARAM_OUT_OPTIONAL>
58+
"If NumEntries is less than the number of devices available, then this function shall only retrieve that number of devices.", PARAM_OUT,
59+
Range<"0", "NumEntries">>
5760
];
5861
let returns = [
5962
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
60-
"`NumEntries == 0 && phDevices != NULL`"
61-
]>,
62-
Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
63-
"`NumEntries > 0 && phDevices == NULL`"
64-
]>,
65-
Return<"OFFLOAD_ERRC_INVALID_VALUE">
63+
"`NumEntries == 0`"
64+
]>
6665
];
6766
}
6867

6968
def : Function {
7069
let name = "offloadDeviceGetInfo";
71-
let desc = "Retrieves various information about device";
70+
let desc = "Queries the given property of the device";
7271
let details = [
7372
"The application may call this function from simultaneous threads.",
7473
"The implementation of this function should be lock-free."
@@ -79,23 +78,36 @@ def : Function {
7978
Param<"size_t", "propSize", "the number of bytes pointed to by pPropValue.", PARAM_IN>,
8079
TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. If propSize is not equal to or greater than the real "
8180
"number of bytes needed to return the info then the OFFLOAD_ERRC_INVALID_SIZE error is returned and "
82-
"pPropValue is not used.", PARAM_OUT_OPTIONAL, TypeInfo<"propName" , "propSize">>,
83-
Param<"size_t*", "pPropSizeRet", "pointer to the actual size in bytes of the queried propName.", PARAM_OUT_OPTIONAL>
81+
"pPropValue is not used.", PARAM_OUT, TypeInfo<"propName" , "propSize">>
8482
];
8583
let returns = [
8684
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
87-
"If `propName` is not supported by the adapter."
85+
"If `propName` is not supported by the device."
8886
]>,
8987
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
90-
"`propSize == 0 && pPropValue != NULL`",
88+
"`propSize == 0`",
9189
"If `propSize` is less than the real number of bytes needed to return the info."
9290
]>,
93-
Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
94-
"`propSize != 0 && pPropValue == NULL`",
95-
"`pPropValue == NULL && pPropSizeRet == NULL`"
91+
Return<"OFFLOAD_ERRC_INVALID_DEVICE">
92+
];
93+
}
94+
95+
def : Function {
96+
let name = "offloadDeviceGetInfoSize";
97+
let desc = "Returns the storage size of the given device query";
98+
let details = [
99+
"The application may call this function from simultaneous threads.",
100+
"The implementation of this function should be lock-free."
101+
];
102+
let params = [
103+
Param<"offload_device_handle_t", "hDevice", "handle of the device instance", PARAM_IN>,
104+
Param<"offload_device_info_t", "propName", "type of the info to retrieve", PARAM_IN>,
105+
Param<"size_t*", "pPropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
106+
];
107+
let returns = [
108+
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
109+
"If `propName` is not supported by the device."
96110
]>,
97-
Return<"OFFLOAD_ERRC_INVALID_DEVICE">,
98-
Return<"OFFLOAD_ERRC_OUT_OF_RESOURCES">,
99-
Return<"OFFLOAD_ERRC_OUT_OF_HOST_MEMORY">
111+
Return<"OFFLOAD_ERRC_INVALID_DEVICE">
100112
];
101113
}

offload/new-api/API/Platform.td

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,33 @@ def : Function {
1717
];
1818
let params = [
1919
Param<"uint32_t", "NumEntries",
20-
"The number of platforms to be added to phPlatforms. If phPlatforms is not NULL, then "
21-
"NumEntries should be greater than zero, otherwise OFFLOAD_ERRC_INVALID_SIZE "
22-
"will be returned.", PARAM_IN>,
20+
"The number of platforms to be added to phPlatforms. NumEntries must be "
21+
"greater than zero.",
22+
PARAM_IN>,
2323
RangedParam<"offload_platform_handle_t*", "phPlatforms",
2424
"Array of handle of platforms. If NumEntries is less than the number of "
2525
"platforms available, then offloadPlatformGet shall only retrieve that "
2626
"number of platforms.",
27-
PARAM_OUT_OPTIONAL, Range<"0", "NumEntries">>,
28-
Param<"uint32_t*",
29-
"pNumPlatforms", "returns the total number of platforms available.",
30-
PARAM_OUT_OPTIONAL>
27+
PARAM_OUT, Range<"0", "NumEntries">>
3128
];
3229
let returns = [
3330
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
34-
"`NumEntries == 0 && phPlatforms != NULL`"
31+
"`NumEntries == 0`"
3532
]>
3633
];
3734
}
3835

36+
def : Function {
37+
let name = "offloadPlatformGetCount";
38+
let desc = "Retrieves the number of available platforms";
39+
let params = [
40+
Param<"uint32_t*",
41+
"pNumPlatforms", "returns the total number of platforms available.",
42+
PARAM_OUT>
43+
];
44+
let returns = [];
45+
}
46+
3947
def : Enum {
4048
let name = "offload_platform_info_t";
4149
let desc = "Supported platform info";
@@ -60,8 +68,10 @@ def : Enum {
6068

6169
def : Function {
6270
let name = "offloadPlatformGetInfo";
63-
let desc = "Retrieves various information about platform";
71+
let desc = "Queries the given property of the platform";
6472
let details = [
73+
"`offloadPlatformGetInfoSize` can be used to query the storage size "
74+
"required for the given query."
6575
"The application may call this function from simultaneous threads.",
6676
"The implementation of this function should be lock-free."
6777
];
@@ -71,24 +81,37 @@ def : Function {
7181
Param<"size_t", "propSize", "the number of bytes pointed to by pPlatformInfo.", PARAM_IN>,
7282
TypeTaggedParam<"void*", "pPropValue", "array of bytes holding the info. "
7383
"If Size is not equal to or greater to the real number of bytes needed to return the info "
74-
"then the OFFLOAD_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT_OPTIONAL,
75-
TypeInfo<"propName" , "propSize">>,
76-
Param<"size_t*", "pPropSizeRet", "pointer to the actual number of bytes being queried by pPlatformInfo.", PARAM_OUT_OPTIONAL>
84+
"then the OFFLOAD_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT,
85+
TypeInfo<"propName" , "propSize">>
7786
];
7887
let returns = [
7988
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
8089
"If `propName` is not supported by the platform."
8190
]>,
8291
Return<"OFFLOAD_ERRC_INVALID_SIZE", [
83-
"`propSize == 0 && pPropValue != NULL`",
92+
"`propSize == 0`",
8493
"If `propSize` is less than the real number of bytes needed to return the info."
8594
]>,
86-
Return<"OFFLOAD_ERRC_INVALID_NULL_POINTER", [
87-
"`propSize != 0 && pPropValue == NULL`",
88-
"`pPropValue == NULL && pPropSizeRet == NULL`"
95+
Return<"OFFLOAD_ERRC_INVALID_PLATFORM">
96+
];
97+
}
98+
99+
def : Function {
100+
let name = "offloadPlatformGetInfoSize";
101+
let desc = "Returns the storage size of the given platform query";
102+
let details = [
103+
"The application may call this function from simultaneous threads.",
104+
"The implementation of this function should be lock-free."
105+
];
106+
let params = [
107+
Param<"offload_platform_handle_t", "hPlatform", "handle of the platform", PARAM_IN>,
108+
Param<"offload_platform_info_t", "propName", "type of the info to query", PARAM_IN>,
109+
Param<"size_t*", "pPropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
110+
];
111+
let returns = [
112+
Return<"OFFLOAD_ERRC_UNSUPPORTED_ENUMERATION", [
113+
"If `propName` is not supported by the platform."
89114
]>,
90-
Return<"OFFLOAD_ERRC_INVALID_PLATFORM">,
91-
Return<"OFFLOAD_ERRC_OUT_OF_RESOURCES">,
92-
Return<"OFFLOAD_ERRC_OUT_OF_HOST_MEMORY">
115+
Return<"OFFLOAD_ERRC_INVALID_PLATFORM">
93116
];
94117
}

0 commit comments

Comments
 (0)