Skip to content

Commit 2b56ac9

Browse files
authored
[SYCL][CUDA] Implemented cuda_piextUSMEnqueueMemAdvise (#3365)
This PR implements the USM MemAdvise function for CUDA backend. The `PI_COMMAND_TYPE_MEMADVISE` enumerator is added, the value of which is derived from `CL_COMMAND_MEMADVISE_INTEL` constant as defined in the preview [USM extension specification](https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc).
1 parent 7324b3e commit 2b56ac9

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

sycl/plugins/cuda/pi_cuda.cpp

+26-3
Original file line numberDiff line numberDiff line change
@@ -4449,9 +4449,32 @@ pi_result cuda_piextUSMEnqueueMemAdvise(pi_queue queue, const void *ptr,
44494449
pi_event *event) {
44504450
assert(queue != nullptr);
44514451
assert(ptr != nullptr);
4452-
// TODO implement a mapping to cuMemAdvise once the expected behaviour
4453-
// of piextUSMEnqueueMemAdvise is detailed in the USM extension
4454-
return cuda_piEnqueueEventsWait(queue, 0, nullptr, event);
4452+
4453+
pi_result result = PI_SUCCESS;
4454+
std::unique_ptr<_pi_event> event_ptr{nullptr};
4455+
4456+
try {
4457+
ScopedContext active(queue->get_context());
4458+
4459+
if (event) {
4460+
event_ptr = std::unique_ptr<_pi_event>(
4461+
_pi_event::make_native(PI_COMMAND_TYPE_USER, queue));
4462+
event_ptr->start();
4463+
}
4464+
4465+
result = PI_CHECK_ERROR(
4466+
cuMemAdvise((CUdeviceptr)ptr, length, (CUmem_advise)advice,
4467+
queue->get_context()->get_device()->get()));
4468+
if (event) {
4469+
result = event_ptr->record();
4470+
*event = event_ptr.release();
4471+
}
4472+
} catch (pi_result err) {
4473+
result = err;
4474+
} catch (...) {
4475+
result = PI_ERROR_UNKNOWN;
4476+
}
4477+
return result;
44554478
}
44564479

44574480
/// API to query information about USM allocated pointers

0 commit comments

Comments
 (0)