Skip to content

Commit e0e7e91

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 89102ff commit e0e7e91

File tree

12 files changed

+45
-54
lines changed

12 files changed

+45
-54
lines changed

include/ur_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4781,7 +4781,7 @@ urKernelSetArgLocal(
47814781
/// @brief Get Kernel object information
47824782
typedef enum ur_kernel_info_t {
47834783
UR_KERNEL_INFO_FUNCTION_NAME = 0, ///< [char[]] Return null-terminated kernel function name.
4784-
UR_KERNEL_INFO_NUM_ARGS = 1, ///< [size_t] Return Kernel number of arguments.
4784+
UR_KERNEL_INFO_NUM_ARGS = 1, ///< [uint32_t] Return Kernel number of arguments.
47854785
UR_KERNEL_INFO_REFERENCE_COUNT = 2, ///< [uint32_t] Reference count of the kernel object.
47864786
///< The reference count returned should be considered immediately stale.
47874787
///< 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
@@ -7855,9 +7855,9 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_kernel_info
78557855
printPtr(os, tptr);
78567856
} break;
78577857
case UR_KERNEL_INFO_NUM_ARGS: {
7858-
const size_t *tptr = (const size_t *)ptr;
7859-
if (sizeof(size_t) > size) {
7860-
os << "invalid size (is: " << size << ", expected: >=" << sizeof(size_t) << ")";
7858+
const uint32_t *tptr = (const uint32_t *)ptr;
7859+
if (sizeof(uint32_t) > size) {
7860+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(uint32_t) << ")";
78617861
return UR_RESULT_ERROR_INVALID_SIZE;
78627862
}
78637863
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
@@ -204,7 +204,9 @@ struct ur_kernel_handle_t_ {
204204
/// Note this only returns the current known number of arguments, not the
205205
/// real one required by the kernel, since this cannot be queried from
206206
/// the CUDA Driver API
207-
size_t getNumArgs() const noexcept { return Args.Indices.size() - 1; }
207+
uint32_t getNumArgs() const noexcept {
208+
return static_cast<uint32_t>(Args.Indices.size() - 1);
209+
}
208210

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

source/adapters/opencl/kernel.cpp

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

10592
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
urKernelSetArgPointerNegativeTest.InvalidKernelArgumentIndex/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_

test/conformance/kernel/urKernelGetInfo.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,32 @@ TEST_P(urKernelGetInfoTest, InvalidEnumeration) {
6666
}
6767

6868
TEST_P(urKernelGetInfoTest, InvalidSizeZero) {
69-
size_t n_args = 0;
70-
ASSERT_EQ_RESULT(
71-
urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, &n_args, nullptr),
72-
UR_RESULT_ERROR_INVALID_SIZE);
69+
size_t query_size = 0;
70+
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, nullptr,
71+
&query_size));
72+
std::vector<char> query_data(query_size);
73+
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0,
74+
query_data.data(), nullptr),
75+
UR_RESULT_ERROR_INVALID_SIZE);
7376
}
7477

7578
TEST_P(urKernelGetInfoTest, InvalidSizeSmall) {
76-
size_t n_args = 0;
79+
size_t query_size = 0;
80+
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, nullptr,
81+
&query_size));
82+
std::vector<char> query_data(query_size);
7783
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS,
78-
sizeof(n_args) - 1, &n_args, nullptr),
84+
query_data.size() - 1, query_data.data(),
85+
nullptr),
7986
UR_RESULT_ERROR_INVALID_SIZE);
8087
}
8188

8289
TEST_P(urKernelGetInfoTest, InvalidNullPointerPropValue) {
83-
size_t n_args = 0;
90+
size_t query_size = 0;
91+
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, nullptr,
92+
&query_size));
8493
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS,
85-
sizeof(n_args), nullptr, nullptr),
94+
query_size, nullptr, nullptr),
8695
UR_RESULT_ERROR_INVALID_NULL_POINTER);
8796
}
8897

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)