Skip to content

Commit 172708b

Browse files
author
aidan.belton
committed
add mem_advise reset and managed mem check
1 parent ba5a126 commit 172708b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

sycl/include/CL/sycl/detail/pi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ typedef enum {
456456

457457
typedef enum {
458458
// Device-specific value opaque in PI API.
459-
PI_MEM_ADVICE_UNKNOWN,
459+
PI_MEM_ADVISE_RESET = 0,
460+
PI_MEM_ADVICE_UNKNOWN = 1,
460461
PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY = 101,
461462
PI_MEM_ADVICE_CUDA_UNSET_READ_MOSTLY = 102,
462463
PI_MEM_ADVICE_CUDA_SET_PREFERRED_LOCATION = 103,

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4803,6 +4803,13 @@ pi_result cuda_piextUSMEnqueueMemAdvise(pi_queue queue, const void *ptr,
48034803
pi_result result = PI_SUCCESS;
48044804
std::unique_ptr<_pi_event> event_ptr{nullptr};
48054805

4806+
// Ignore mem advice if memory is not managed
4807+
unsigned int is_managed;
4808+
PI_CHECK_ERROR(cuPointerGetAttribute(
4809+
&is_managed, CU_POINTER_ATTRIBUTE_IS_MANAGED, (CUdeviceptr)ptr));
4810+
if (!is_managed)
4811+
return PI_SUCCESS;
4812+
48064813
try {
48074814
ScopedContext active(queue->get_context());
48084815

@@ -4835,6 +4842,17 @@ pi_result cuda_piextUSMEnqueueMemAdvise(pi_queue queue, const void *ptr,
48354842
PI_MEM_ADVICE_CUDA_SET_PREFERRED_LOCATION)),
48364843
CU_DEVICE_CPU));
48374844
break;
4845+
case PI_MEM_ADVISE_RESET:
4846+
PI_CHECK_ERROR(cuMemAdvise((CUdeviceptr)ptr, length,
4847+
CU_MEM_ADVISE_UNSET_READ_MOSTLY,
4848+
queue->get_context()->get_device()->get()));
4849+
PI_CHECK_ERROR(cuMemAdvise((CUdeviceptr)ptr, length,
4850+
CU_MEM_ADVISE_UNSET_PREFERRED_LOCATION,
4851+
queue->get_context()->get_device()->get()));
4852+
PI_CHECK_ERROR(cuMemAdvise((CUdeviceptr)ptr, length,
4853+
CU_MEM_ADVISE_UNSET_ACCESSED_BY,
4854+
queue->get_context()->get_device()->get()));
4855+
break;
48384856
default:
48394857
cl::sycl::detail::pi::die("Unknown advice");
48404858
}

0 commit comments

Comments
 (0)