Skip to content

Commit d829e84

Browse files
committed
Make UR_KERNEL_INFO_NUM_ARGS uint32_t instead of size_t.
This brings it in line with OpenCL, and with SYCL's expectations. Addresses #1038
1 parent 49da559 commit d829e84

File tree

12 files changed

+54
-60
lines changed

12 files changed

+54
-60
lines changed

include/ur_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4620,7 +4620,7 @@ urKernelSetArgLocal(
46204620
/// @brief Get Kernel object information
46214621
typedef enum ur_kernel_info_t {
46224622
UR_KERNEL_INFO_FUNCTION_NAME = 0, ///< [char[]] Return null-terminated kernel function name.
4623-
UR_KERNEL_INFO_NUM_ARGS = 1, ///< [size_t] Return Kernel number of arguments.
4623+
UR_KERNEL_INFO_NUM_ARGS = 1, ///< [uint32_t] Return Kernel number of arguments.
46244624
UR_KERNEL_INFO_REFERENCE_COUNT = 2, ///< [uint32_t] Reference count of the kernel object.
46254625
///< The reference count returned should be considered immediately stale.
46264626
///< It is unsuitable for general use in applications. This feature is

include/ur_print.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7477,9 +7477,9 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_kernel_info
74777477
printPtr(os, tptr);
74787478
} break;
74797479
case UR_KERNEL_INFO_NUM_ARGS: {
7480-
const size_t *tptr = (const size_t *)ptr;
7481-
if (sizeof(size_t) > size) {
7482-
os << "invalid size (is: " << size << ", expected: >=" << sizeof(size_t) << ")";
7480+
const uint32_t *tptr = (const uint32_t *)ptr;
7481+
if (sizeof(uint32_t) > size) {
7482+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(uint32_t) << ")";
74837483
return UR_RESULT_ERROR_INVALID_SIZE;
74847484
}
74857485
os << (const void *)(tptr) << " (";

scripts/core/kernel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ etors:
109109
- name: FUNCTION_NAME
110110
desc: "[char[]] Return null-terminated kernel function name."
111111
- name: NUM_ARGS
112-
desc: "[size_t] Return Kernel number of arguments."
112+
desc: "[uint32_t] Return Kernel number of arguments."
113113
- name: REFERENCE_COUNT
114114
desc: |
115115
[uint32_t] Reference count of the kernel object.

source/adapters/cuda/kernel.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ struct ur_kernel_handle_t_ {
182182
/// Note this only returns the current known number of arguments, not the
183183
/// real one required by the kernel, since this cannot be queried from
184184
/// the CUDA Driver API
185-
size_t getNumArgs() const noexcept { return Args.Indices.size() - 1; }
185+
uint32_t getNumArgs() const noexcept {
186+
return static_cast<uint32_t>(Args.Indices.size() - 1);
187+
}
186188

187189
void setKernelArg(int Index, size_t Size, const void *Arg) {
188190
Args.addArg(Index, Size, Arg);

source/adapters/opencl/kernel.cpp

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ static cl_int mapURKernelInfoToCL(ur_kernel_info_t URPropName) {
6060
return CL_KERNEL_PROGRAM;
6161
case UR_KERNEL_INFO_ATTRIBUTES:
6262
return CL_KERNEL_ATTRIBUTES;
63+
// NUM_REGS doesn't have a CL equivalent
6364
case UR_KERNEL_INFO_NUM_REGS:
64-
return CL_KERNEL_NUM_ARGS;
6565
default:
6666
return -1;
6767
}
@@ -72,33 +72,20 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
7272
size_t propSize,
7373
void *pPropValue,
7474
size_t *pPropSizeRet) {
75-
// We need this little bit of ugliness because the UR NUM_ARGS property is
76-
// size_t whereas the CL one is cl_uint. We should consider changing that see
77-
// #1038
78-
if (propName == UR_KERNEL_INFO_NUM_ARGS) {
79-
if (pPropSizeRet)
80-
*pPropSizeRet = sizeof(size_t);
81-
cl_uint NumArgs = 0;
82-
CL_RETURN_ON_FAILURE(clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
83-
mapURKernelInfoToCL(propName),
84-
sizeof(NumArgs), &NumArgs, nullptr));
85-
if (pPropValue) {
86-
if (propSize != sizeof(size_t))
87-
return UR_RESULT_ERROR_INVALID_SIZE;
88-
*static_cast<size_t *>(pPropValue) = static_cast<size_t>(NumArgs);
89-
}
90-
} else {
91-
size_t CheckPropSize = 0;
92-
cl_int ClResult = clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
93-
mapURKernelInfoToCL(propName), propSize,
94-
pPropValue, &CheckPropSize);
95-
if (pPropValue && CheckPropSize != propSize) {
96-
return UR_RESULT_ERROR_INVALID_SIZE;
97-
}
98-
CL_RETURN_ON_FAILURE(ClResult);
99-
if (pPropSizeRet) {
100-
*pPropSizeRet = CheckPropSize;
101-
}
75+
// OpenCL doesn't have a way to support this.
76+
if (propName == UR_KERNEL_INFO_NUM_REGS) {
77+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
78+
}
79+
size_t CheckPropSize = 0;
80+
cl_int ClResult = clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
81+
mapURKernelInfoToCL(propName), propSize,
82+
pPropValue, &CheckPropSize);
83+
if (pPropValue && CheckPropSize != propSize) {
84+
return UR_RESULT_ERROR_INVALID_SIZE;
85+
}
86+
CL_RETURN_ON_FAILURE(ClResult);
87+
if (pPropSizeRet) {
88+
*pPropSizeRet = CheckPropSize;
10289
}
10390

10491
return UR_RESULT_SUCCESS;

test/conformance/kernel/kernel_adapter_level_zero.match

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
urKernelGetInfoTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_KERNEL_INFO_NUM_REGS
2-
urKernelGetInfoTest.InvalidSizeSmall/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_KERNEL_INFO_FUNCTION_NAME
3-
urKernelGetInfoTest.InvalidSizeSmall/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_KERNEL_INFO_NUM_ARGS
4-
urKernelGetInfoTest.InvalidSizeSmall/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_KERNEL_INFO_REFERENCE_COUNT
5-
urKernelGetInfoTest.InvalidSizeSmall/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_KERNEL_INFO_CONTEXT
6-
urKernelGetInfoTest.InvalidSizeSmall/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_KERNEL_INFO_PROGRAM
7-
urKernelGetInfoTest.InvalidSizeSmall/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_KERNEL_INFO_ATTRIBUTES
8-
urKernelGetInfoTest.InvalidSizeSmall/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_KERNEL_INFO_NUM_REGS
92
urKernelSetArgLocalTest.InvalidKernelArgumentIndex/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
103
urKernelSetArgMemObjTest.InvalidKernelArgumentIndex/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
114
urKernelSetArgPointerTest.SuccessHost/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_

test/conformance/kernel/urKernelGetInfo.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ UUR_TEST_SUITE_P(
1818
TEST_P(urKernelGetInfoTest, Success) {
1919
auto property_name = getParam();
2020
size_t property_size = 0;
21-
std::vector<char> property_value;
22-
ASSERT_SUCCESS(
23-
urKernelGetInfo(kernel, property_name, 0, nullptr, &property_size));
24-
property_value.resize(property_size);
25-
ASSERT_SUCCESS(urKernelGetInfo(kernel, property_name, property_size,
26-
property_value.data(), nullptr));
21+
auto Err =
22+
urKernelGetInfo(kernel, property_name, 0, nullptr, &property_size);
23+
if (Err == UR_RESULT_SUCCESS) {
24+
std::vector<char> property_value(property_size);
25+
ASSERT_SUCCESS(urKernelGetInfo(kernel, property_name, property_size,
26+
property_value.data(), nullptr));
27+
} else {
28+
ASSERT_EQ_RESULT(Err, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION);
29+
}
2730
}
2831

2932
TEST_P(urKernelGetInfoTest, InvalidNullHandleKernel) {
@@ -41,23 +44,32 @@ TEST_P(urKernelGetInfoTest, InvalidEnumeration) {
4144
}
4245

4346
TEST_P(urKernelGetInfoTest, InvalidSizeZero) {
44-
size_t n_args = 0;
45-
ASSERT_EQ_RESULT(
46-
urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, &n_args, nullptr),
47-
UR_RESULT_ERROR_INVALID_SIZE);
47+
size_t query_size = 0;
48+
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, nullptr,
49+
&query_size));
50+
std::vector<char> query_data(query_size);
51+
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0,
52+
query_data.data(), nullptr),
53+
UR_RESULT_ERROR_INVALID_SIZE);
4854
}
4955

5056
TEST_P(urKernelGetInfoTest, InvalidSizeSmall) {
51-
size_t n_args = 0;
57+
size_t query_size = 0;
58+
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, nullptr,
59+
&query_size));
60+
std::vector<char> query_data(query_size);
5261
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS,
53-
sizeof(n_args) - 1, &n_args, nullptr),
62+
query_data.size() - 1, query_data.data(),
63+
nullptr),
5464
UR_RESULT_ERROR_INVALID_SIZE);
5565
}
5666

5767
TEST_P(urKernelGetInfoTest, InvalidNullPointerPropValue) {
58-
size_t n_args = 0;
68+
size_t query_size = 0;
69+
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, nullptr,
70+
&query_size));
5971
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS,
60-
sizeof(n_args), nullptr, nullptr),
72+
query_size, nullptr, nullptr),
6173
UR_RESULT_ERROR_INVALID_NULL_POINTER);
6274
}
6375

test/conformance/kernel/urKernelSetArgLocal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TEST_P(urKernelSetArgLocalTest, InvalidNullHandleKernel) {
2424
}
2525

2626
TEST_P(urKernelSetArgLocalTest, InvalidKernelArgumentIndex) {
27-
size_t num_kernel_args = 0;
27+
uint32_t num_kernel_args = 0;
2828
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS,
2929
sizeof(num_kernel_args), &num_kernel_args,
3030
nullptr));

test/conformance/kernel/urKernelSetArgMemObj.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TEST_P(urKernelSetArgMemObjTest, InvalidNullHandleKernel) {
3535
}
3636

3737
TEST_P(urKernelSetArgMemObjTest, InvalidKernelArgumentIndex) {
38-
size_t num_kernel_args = 0;
38+
uint32_t num_kernel_args = 0;
3939
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS,
4040
sizeof(num_kernel_args), &num_kernel_args,
4141
nullptr));

test/conformance/kernel/urKernelSetArgPointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ TEST_P(urKernelSetArgPointerNegativeTest, InvalidNullHandleKernel) {
142142
}
143143

144144
TEST_P(urKernelSetArgPointerNegativeTest, InvalidKernelArgumentIndex) {
145-
size_t num_kernel_args = 0;
145+
uint32_t num_kernel_args = 0;
146146
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS,
147147
sizeof(num_kernel_args), &num_kernel_args,
148148
nullptr));

0 commit comments

Comments
 (0)