Skip to content

Commit 8945db4

Browse files
committed
[CUDA] Update hint functions to only return warnings
- The UR spec was recently changed to guarantee that hint entryponts never return errors. This commit changes the CUDA adapter to be conformant with this change. - This commit also changes the type of PointerRangeSize which was causing a stack corruption.
1 parent 08ca4be commit 8945db4

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

source/adapters/cuda/enqueue.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ ur_result_t setCuMemAdvise(CUdeviceptr DevPtr, size_t Size,
121121

122122
for (auto &UnmappedFlag : UnmappedMemAdviceFlags) {
123123
if (URAdviceFlags & UnmappedFlag) {
124-
throw UR_RESULT_ERROR_INVALID_ENUMERATION;
124+
setErrorMessage("Memory advice ignored because the CUDA backend does not "
125+
"support some of the specified flags",
126+
UR_RESULT_SUCCESS);
127+
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
125128
}
126129
}
127130

@@ -1355,15 +1358,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
13551358
ur_queue_handle_t hQueue, const void *pMem, size_t size,
13561359
ur_usm_migration_flags_t flags, uint32_t numEventsInWaitList,
13571360
const ur_event_handle_t *phEventWaitList, ur_event_handle_t *phEvent) {
1358-
unsigned int PointerRangeSize = 0;
1361+
std::ignore = flags;
1362+
1363+
size_t PointerRangeSize = 0;
13591364
UR_CHECK_ERROR(cuPointerGetAttribute(
13601365
&PointerRangeSize, CU_POINTER_ATTRIBUTE_RANGE_SIZE, (CUdeviceptr)pMem));
13611366
UR_ASSERT(size <= PointerRangeSize, UR_RESULT_ERROR_INVALID_SIZE);
13621367
ur_device_handle_t Device = hQueue->getContext()->getDevice();
13631368

13641369
// Certain cuda devices and Windows do not have support for some Unified
13651370
// Memory features. cuMemPrefetchAsync requires concurrent memory access
1366-
// for managed memory. Therfore, ignore prefetch hint if concurrent managed
1371+
// for managed memory. Therefore, ignore prefetch hint if concurrent managed
13671372
// memory access is not available.
13681373
if (!getAttribute(Device, CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS)) {
13691374
setErrorMessage("Prefetch hint ignored as device does not support "
@@ -1381,10 +1386,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
13811386
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
13821387
}
13831388

1384-
// flags is currently unused so fail if set
1385-
if (flags != 0)
1386-
return UR_RESULT_ERROR_INVALID_VALUE;
1387-
13881389
ur_result_t Result = UR_RESULT_SUCCESS;
13891390
std::unique_ptr<ur_event_handle_t_> EventPtr{nullptr};
13901391

@@ -1415,7 +1416,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
14151416
UR_APIEXPORT ur_result_t UR_APICALL
14161417
urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
14171418
ur_usm_advice_flags_t advice, ur_event_handle_t *phEvent) {
1418-
unsigned int PointerRangeSize = 0;
1419+
size_t PointerRangeSize = 0;
14191420
UR_CHECK_ERROR(cuPointerGetAttribute(
14201421
&PointerRangeSize, CU_POINTER_ATTRIBUTE_RANGE_SIZE, (CUdeviceptr)pMem));
14211422
UR_ASSERT(size <= PointerRangeSize, UR_RESULT_ERROR_INVALID_SIZE);

0 commit comments

Comments
 (0)