@@ -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