Skip to content

Commit 1e9b1b4

Browse files
authored
Merge pull request #805 from aarongreig/aaron/kernelSetArgIndirectionFix
Correct level of indirection used in KernelSetArgPointer calls.
2 parents a011f09 + d8500a3 commit 1e9b1b4

File tree

22 files changed

+44
-47
lines changed

22 files changed

+44
-47
lines changed

include/ur_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5023,8 +5023,8 @@ urKernelSetArgPointer(
50235023
ur_kernel_handle_t hKernel, ///< [in] handle of the kernel object
50245024
uint32_t argIndex, ///< [in] argument index in range [0, num args - 1]
50255025
const ur_kernel_arg_pointer_properties_t *pProperties, ///< [in][optional] pointer to USM pointer properties.
5026-
const void *pArgValue ///< [in][optional] USM pointer to memory location holding the argument
5027-
///< value. If null then argument value is considered null.
5026+
const void *pArgValue ///< [in][optional] Pointer obtained by USM allocation or virtual memory
5027+
///< mapping operation. If null then argument value is considered null.
50285028
);
50295029

50305030
///////////////////////////////////////////////////////////////////////////////

scripts/core/kernel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ params:
339339
desc: "[in][optional] pointer to USM pointer properties."
340340
- type: "const void*"
341341
name: pArgValue
342-
desc: "[in][optional] USM pointer to memory location holding the argument value. If null then argument value is considered null."
342+
desc: "[in][optional] Pointer obtained by USM allocation or virtual memory mapping operation. If null then argument value is considered null."
343343
returns:
344344
- $X_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX
345345
- $X_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE

source/adapters/cuda/kernel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ urKernelSetArgPointer(ur_kernel_handle_t hKernel, uint32_t argIndex,
287287
const ur_kernel_arg_pointer_properties_t *pProperties,
288288
const void *pArgValue) {
289289
std::ignore = pProperties;
290-
hKernel->setKernelArg(argIndex, sizeof(pArgValue), pArgValue);
290+
// setKernelArg is expecting a pointer to our argument
291+
hKernel->setKernelArg(argIndex, sizeof(pArgValue), &pArgValue);
291292
return UR_RESULT_SUCCESS;
292293
}
293294

source/adapters/hip/kernel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
275275
UR_APIEXPORT ur_result_t UR_APICALL urKernelSetArgPointer(
276276
ur_kernel_handle_t hKernel, uint32_t argIndex,
277277
const ur_kernel_arg_pointer_properties_t *, const void *pArgValue) {
278-
hKernel->setKernelArg(argIndex, sizeof(pArgValue), pArgValue);
278+
// setKernelArg is expecting a pointer to our argument
279+
hKernel->setKernelArg(argIndex, sizeof(pArgValue), &pArgValue);
279280
return UR_RESULT_SUCCESS;
280281
}
281282

source/adapters/level_zero/kernel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelSetArgPointer(
10041004
) {
10051005
std::ignore = Properties;
10061006

1007+
// KernelSetArgValue is expecting a pointer to the argument
10071008
UR_CALL(urKernelSetArgValue(Kernel, ArgIndex, sizeof(const void *), nullptr,
1008-
ArgValue));
1009+
&ArgValue));
10091010
return UR_RESULT_SUCCESS;
10101011
}
10111012

source/adapters/native_cpu/kernel.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ urKernelSetArgPointer(ur_kernel_handle_t hKernel, uint32_t argIndex,
213213
UR_ASSERT(hKernel, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
214214
UR_ASSERT(pArgValue, UR_RESULT_ERROR_INVALID_NULL_POINTER);
215215

216-
auto ptrToPtr = reinterpret_cast<const intptr_t *>(pArgValue);
217-
auto derefPtr = reinterpret_cast<void *>(*ptrToPtr);
218-
hKernel->_args.push_back(derefPtr);
216+
hKernel->_args.push_back(const_cast<void *>(pArgValue));
219217

220218
return UR_RESULT_SUCCESS;
221219
}

source/adapters/null/ur_nullddi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,8 +2446,8 @@ __urdlllocal ur_result_t UR_APICALL urKernelSetArgPointer(
24462446
const ur_kernel_arg_pointer_properties_t
24472447
*pProperties, ///< [in][optional] pointer to USM pointer properties.
24482448
const void *
2449-
pArgValue ///< [in][optional] USM pointer to memory location holding the argument
2450-
///< value. If null then argument value is considered null.
2449+
pArgValue ///< [in][optional] Pointer obtained by USM allocation or virtual memory
2450+
///< mapping operation. If null then argument value is considered null.
24512451
) try {
24522452
ur_result_t result = UR_RESULT_SUCCESS;
24532453

source/adapters/opencl/kernel.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelSetArgPointer(
359359
cl_ext::SetKernelArgMemPointerName, &FuncPtr));
360360

361361
if (FuncPtr) {
362-
/* OpenCL passes pointers by value not by reference. This means we need to
363-
* deref the arg to get the pointer value */
364-
auto PtrToPtr = reinterpret_cast<const intptr_t *>(pArgValue);
365-
auto DerefPtr = reinterpret_cast<void *>(*PtrToPtr);
366362
CL_RETURN_ON_FAILURE(FuncPtr(cl_adapter::cast<cl_kernel>(hKernel),
367363
cl_adapter::cast<cl_uint>(argIndex),
368-
DerefPtr));
364+
pArgValue));
369365
}
370366

371367
return UR_RESULT_SUCCESS;

source/loader/layers/sanitizer/asan_interceptor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ ur_result_t SanitizerInterceptor::prepareLaunch(
705705
char *ArgPointer = nullptr;
706706
UR_CALL(MemBuffer->getHandle(DeviceInfo->Handle, ArgPointer));
707707
ur_result_t URes = context.urDdiTable.Kernel.pfnSetArgPointer(
708-
Kernel, ArgIndex, nullptr, &ArgPointer);
708+
Kernel, ArgIndex, nullptr, ArgPointer);
709709
if (URes != UR_RESULT_SUCCESS) {
710710
context.logger.error(
711711
"Failed to set buffer {} as the {} arg to kernel {}: {}",
@@ -722,7 +722,7 @@ ur_result_t SanitizerInterceptor::prepareLaunch(
722722
(void *)LaunchInfo.Data, LaunchInfo.Data->NumLocalArgs,
723723
(void *)LaunchInfo.Data->LocalArgs);
724724
ur_result_t URes = context.urDdiTable.Kernel.pfnSetArgPointer(
725-
Kernel, ArgNums - 1, nullptr, &LaunchInfo.Data);
725+
Kernel, ArgNums - 1, nullptr, LaunchInfo.Data);
726726
if (URes != UR_RESULT_SUCCESS) {
727727
context.logger.error("Failed to set launch info: {}", URes);
728728
return URes;

source/loader/layers/tracing/ur_trcddi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,8 +3167,8 @@ __urdlllocal ur_result_t UR_APICALL urKernelSetArgPointer(
31673167
const ur_kernel_arg_pointer_properties_t
31683168
*pProperties, ///< [in][optional] pointer to USM pointer properties.
31693169
const void *
3170-
pArgValue ///< [in][optional] USM pointer to memory location holding the argument
3171-
///< value. If null then argument value is considered null.
3170+
pArgValue ///< [in][optional] Pointer obtained by USM allocation or virtual memory
3171+
///< mapping operation. If null then argument value is considered null.
31723172
) {
31733173
auto pfnSetArgPointer = context.urDdiTable.Kernel.pfnSetArgPointer;
31743174

0 commit comments

Comments
 (0)