Skip to content

Commit fe18839

Browse files
authored
[SYCL][CUDA] Add mem_advise reset and managed mem check (#5536)
This PR adds the mem_advise reset case and a managed memory check in cuda_piextUSMEnqueueMemAdvise. cuMemAdvise only works on managed memory and returns an error if host or device memory is passed. The SYCL-CTS tests mem_advise with host and device memory, which are not managed. This PR prevents an error from being thrown in the cts usm test. In addition, the sycl spec specifies for mem_advise `A value of 0 reverts the advice for ptr to the default behavior`, currently a value of 0 is treated as unknown and throws an error in the cts as well. This reset case is added to mem_advise. This patch along with #5446 resolves issue #5209 This change breaks the ABI
1 parent 3bf7d5c commit fe18839

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

sycl/include/sycl/detail/pi.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747
// 8.10 Added new optional device argument to piextQueueCreateWithNativeHandle
4848
// 9.11 Use values of OpenCL enums directly, rather than including `<CL/cl.h>`;
4949
// NOTE that this results in a changed API for `piProgramGetBuildInfo`.
50+
// 10.12 Change enum value PI_MEM_ADVICE_UNKNOWN from 0 to 999, and set enum
51+
// PI_MEM_ADVISE_RESET to 0.
5052

51-
#define _PI_H_VERSION_MAJOR 9
52-
#define _PI_H_VERSION_MINOR 11
53+
#define _PI_H_VERSION_MAJOR 10
54+
#define _PI_H_VERSION_MINOR 12
5355

5456
#define _PI_STRING_HELPER(a) #a
5557
#define _PI_CONCAT(a, b) _PI_STRING_HELPER(a.b)
@@ -404,7 +406,7 @@ typedef enum {
404406

405407
typedef enum {
406408
// Device-specific value opaque in PI API.
407-
PI_MEM_ADVICE_UNKNOWN,
409+
PI_MEM_ADVICE_RESET = 0,
408410
PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY = 101,
409411
PI_MEM_ADVICE_CUDA_UNSET_READ_MOSTLY = 102,
410412
PI_MEM_ADVICE_CUDA_SET_PREFERRED_LOCATION = 103,
@@ -415,6 +417,7 @@ typedef enum {
415417
PI_MEM_ADVICE_CUDA_UNSET_PREFERRED_LOCATION_HOST = 108,
416418
PI_MEM_ADVICE_CUDA_SET_ACCESSED_BY_HOST = 109,
417419
PI_MEM_ADVICE_CUDA_UNSET_ACCESSED_BY_HOST = 110,
420+
PI_MEM_ADVICE_UNKNOWN = 999,
418421
} _pi_mem_advice;
419422

420423
typedef enum {

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5099,7 +5099,8 @@ pi_result cuda_piextUSMEnqueueMemAdvise(pi_queue queue, const void *ptr,
50995099
if (advice == PI_MEM_ADVICE_CUDA_SET_PREFERRED_LOCATION ||
51005100
advice == PI_MEM_ADVICE_CUDA_UNSET_PREFERRED_LOCATION ||
51015101
advice == PI_MEM_ADVICE_CUDA_SET_ACCESSED_BY ||
5102-
advice == PI_MEM_ADVICE_CUDA_UNSET_ACCESSED_BY) {
5102+
advice == PI_MEM_ADVICE_CUDA_UNSET_ACCESSED_BY ||
5103+
advice == PI_MEM_ADVICE_RESET) {
51035104
pi_device device = queue->get_context()->get_device();
51045105
if (!getAttribute(device, CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS)) {
51055106
setErrorMessage("Mem advise ignored as device does not support "
@@ -5148,6 +5149,17 @@ pi_result cuda_piextUSMEnqueueMemAdvise(pi_queue queue, const void *ptr,
51485149
PI_MEM_ADVICE_CUDA_SET_PREFERRED_LOCATION)),
51495150
CU_DEVICE_CPU));
51505151
break;
5152+
case PI_MEM_ADVICE_RESET:
5153+
PI_CHECK_ERROR(cuMemAdvise((CUdeviceptr)ptr, length,
5154+
CU_MEM_ADVISE_UNSET_READ_MOSTLY,
5155+
queue->get_context()->get_device()->get()));
5156+
PI_CHECK_ERROR(cuMemAdvise((CUdeviceptr)ptr, length,
5157+
CU_MEM_ADVISE_UNSET_PREFERRED_LOCATION,
5158+
queue->get_context()->get_device()->get()));
5159+
PI_CHECK_ERROR(cuMemAdvise((CUdeviceptr)ptr, length,
5160+
CU_MEM_ADVISE_UNSET_ACCESSED_BY,
5161+
queue->get_context()->get_device()->get()));
5162+
break;
51515163
default:
51525164
cl::sycl::detail::pi::die("Unknown advice");
51535165
}

0 commit comments

Comments
 (0)